Skip to content

Commit

Permalink
feature/self contained desktop package (#439)
Browse files Browse the repository at this point in the history
* Bundle yargs and fs-extra into desktop/bin/dump_artifacts.js but leave pyodide and node-fetch as externals because they must be necessarily installed at runtime anyway as the Wasm files shipped with pyodide are used at runtime and node-fetch is one of the dependencies of the pyodide package

* Create scripts/build_bin.js
  • Loading branch information
whitphx authored Dec 15, 2022
1 parent 0b5d07f commit fb863f1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"start:electron": "tsc -p electron -w",
"build:electron": "tsc -p electron",
"build:pyodide": "curl -L https://github.com/pyodide/pyodide/releases/download/0.21.3/pyodide-build-0.21.3.tar.bz2 | tar xj -C ./build --files-from=./pyodide-files.txt",
"build:bin": "esbuild ./bin/dump_artifacts.ts --bundle --minify --platform=node --external:@stlite/kernel --external:node-fetch --external:pyodide --external:yargs --external:fs-extra --outfile=./bin/dump_artifacts.js && sed -i'' -e '1 s/^#!.*$/#!\\/usr\\/bin\\/env node/' ./bin/*.js",
"build:bin": "./scripts/build_bin.js && sed -i'' -e '1 s/^#!.*$/#!\\/usr\\/bin\\/env node/' ./bin/*.js",
"typecheck": "yarn tsc --noEmit -p electron",
"start": "concurrently \"cross-env BROWSER=none yarn start:web\" \"wait-on http://localhost:3000 && yarn start:electron\" \"wait-on http://localhost:3000 && tsc -p electron && cross-env NODE_ENV=\"development\" electron .\"",
"build:app": "yarn build:web && yarn build:electron && yarn build:pyodide",
Expand Down Expand Up @@ -48,6 +48,11 @@
"last 1 electron version"
]
},
"//": "The packages not bundled with bin/dump_artifacts.js must be specified here as the runtime dependencies. See `scripts/build_bin.js` for the details.",
"dependencies": {
"node-fetch": "2",
"pyodide": "^0.21.3"
},
"devDependencies": {
"@craco/craco": "^6.1.2",
"@stlite/common": "^0.20.0",
Expand All @@ -74,7 +79,7 @@
"typescript": "^4.6.3",
"yargs": "^17.5.1"
},
"//": "build.productName is necessary because electron-builder uses the package name for its purpose but the scoped name including '@' makes a problem: https://github.com/electron-userland/electron-builder/issues/3230",
"///": "build.productName is necessary because electron-builder uses the package name for its purpose but the scoped name including '@' makes a problem: https://github.com/electron-userland/electron-builder/issues/3230",
"build": {
"appId": "your.id",
"mac": {
Expand Down
19 changes: 19 additions & 0 deletions packages/desktop/scripts/build_bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env node

// Build script using esbuild like https://esbuild.github.io/getting-started/#build-scripts

require("esbuild")
.build({
entryPoints: ["./bin/dump_artifacts.ts"],
bundle: true,
minify: true,
platform: "node",
external: [
"@stlite/kernel", // Don't touch `require.resolve("@stlite/kernel") at the bundle time.
"pyodide", // The `pyodide` package must be installed at runtime for the included Wasm files, so there is no reason to bundle it here.
"node-fetch", // `node-fetch` will be installed at runtime anyway because it is one dependency of the `pyodide` package, so there is no reason to bundle it here.
],
outfile: "./bin/dump_artifacts.js",
logLevel: "info",
})
.catch(() => process.exit(1));

0 comments on commit fb863f1

Please sign in to comment.