Skip to content

Commit

Permalink
fix import brython
Browse files Browse the repository at this point in the history
  • Loading branch information
user committed Dec 20, 2024
1 parent f36f79e commit 7683c6a
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 38 deletions.
88 changes: 57 additions & 31 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";
import inlineWorkerPlugin from 'esbuild-plugin-inline-worker';
import fs from 'fs/promises';

const banner =
`/*
Expand All @@ -17,40 +18,65 @@ export default {
const prod = (process.argv[2] === "production");


function replacePlugin(replace_map) {
return {
name: "replace-plugin",
setup(build) {
build.onEnd(async (result) => {
if (result.errors.length > 0) {
return;
}
let contents = await fs.readFile("main.js", "utf8");
for (const [search, replacement] of Object.entries(replace_map)) {
contents = contents.replace(search, replacement);
}
await fs.writeFile("main.js", contents, "utf8");
});
},
};
}


const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ["./src/main.ts"],
bundle: true,
plugins: [inlineWorkerPlugin()],
external: [
"obsidian",
"electron",
"@codemirror/autocomplete",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/search",
"@codemirror/state",
"@codemirror/view",
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtins],
format: "cjs",
target: "es2021",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "main.js",
minify: prod,
banner: {
js: banner,
},
entryPoints: ["./src/main.ts"],
bundle: true,
plugins: [
inlineWorkerPlugin(),
replacePlugin({
'&&e.print(">",T.src.source.trim())': "",
"_b_.print(result)\n": "_b_.print(_b_.repr(result))\n",
})
],
external: [
"obsidian",
"electron",
"@codemirror/autocomplete",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/search",
"@codemirror/state",
"@codemirror/view",
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtins],
format: "cjs",
target: "es2021",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "main.js",
minify: prod,
});

if (prod) {
await context.rebuild();
process.exit(0);
await context.rebuild();
process.exit(0);
} else {
await context.watch();
await context.watch();
}
9 changes: 8 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"typescript": "4.7.4"
},
"dependencies": {
"brython": "^3.13.0",
"esbuild-plugin-inline-worker": "^0.1.1"
}
}
1 change: 0 additions & 1 deletion src/brython.min.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/brython_stdlib.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/pyworker.worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as brython_min from "brython.min.js";
import * as brython_stdlib from "brython_stdlib.js";
import * as brython_min from "brython/brython.min.js";
import * as brython_stdlib from "brython/brython_stdlib.js";

export {}

Expand Down

0 comments on commit 7683c6a

Please sign in to comment.