From 6c878e1f88c76a2b2249e195229824fc45a1956c Mon Sep 17 00:00:00 2001 From: Muspi Merol Date: Tue, 24 Sep 2024 13:30:10 +0000 Subject: [PATCH] Refactor build process --- .github/workflows/publish.yml | 71 +++++++++++++++++++ src/js/emscripten-settings.ts | 10 --- src/js/package.json | 126 ++++------------------------------ src/js/pyodide.ts | 3 +- src/js/tsconfig.json | 1 - 5 files changed, 87 insertions(+), 124 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000000..feb04e4bd68 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,71 @@ +name: CI + +on: [push, pull_request, workflow_dispatch, release] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: oven-sh/setup-bun@v1 + + - name: Build package + working-directory: src/js + run: bun build pyodide.ts --outdir=dist --sourcemap=linked + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: build + path: src/js + + preview: + runs-on: ubuntu-latest + + needs: build + + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: build + path: . + + - name: Publish to pkg.pr.new + run: npx pkg-pr-new publish + + publish: + runs-on: ubuntu-latest + + needs: build + + permissions: + contents: write + id-token: write + + steps: + - uses: actions/setup-node@v4 + with: + node-version: latest + registry-url: https://registry.npmjs.org + + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: build + path: . + + - name: List files + run: tree -s -h + + - name: Publish to npm + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + if [ "${{ github.event_name }}" == "release" ]; then + npm publish --provenance --access public + else + npm publish --provenance --access public --dry-run + fi \ No newline at end of file diff --git a/src/js/emscripten-settings.ts b/src/js/emscripten-settings.ts index 9434e7de29c..a5bc6f20185 100644 --- a/src/js/emscripten-settings.ts +++ b/src/js/emscripten-settings.ts @@ -161,16 +161,6 @@ function getFileSystemInitializationFuncs(config: ConfigType): PreRunFunc[] { function getInstantiateWasmFunc( indexURL: string, ): EmscriptenSettings["instantiateWasm"] { - if (SOURCEMAP) { - // According to the docs: - // - // "Sanitizers or source map is currently not supported if overriding - // WebAssembly instantiation with Module.instantiateWasm." - // https://emscripten.org/docs/api_reference/module.html?highlight=instantiatewasm#Module.instantiateWasm - // - // I haven't checked if this is actually a problem in practice. - return; - } const { binary, response } = getBinaryResponse(indexURL + "pyodide.asm.wasm"); return function ( imports: { [key: string]: any }, diff --git a/src/js/package.json b/src/js/package.json index 305fdfdd9ce..181c2c938d2 100644 --- a/src/js/package.json +++ b/src/js/package.json @@ -1,5 +1,8 @@ { - "name": "pyodide", + "name": "@promplate/pyodide-bootstrap", + "publishConfig": { + "access": "public" + }, "version": "0.27.0-dev.0", "description": "The Pyodide JavaScript package", "keywords": [ @@ -15,122 +18,21 @@ "url": "https://github.com/pyodide/pyodide/issues" }, "license": "Apache-2.0", - "devDependencies": { - "@types/assert": "^1.5.6", - "@types/expect": "^24.3.0", - "@types/mocha": "^9.1.0", - "@types/node": "^20.8.4", - "@types/ws": "^8.5.3", - "chai": "^4.3.6", - "chai-as-promised": "^7.1.1", - "cross-env": "^7.0.3", - "dts-bundle-generator": "^8.1.1", - "esbuild": "^0.17.12", - "express": "^4.17.3", - "mocha": "^9.0.2", - "npm-run-all": "^4.1.5", - "nyc": "^15.1.0", - "prettier": "^2.2.1", - "sinon": "^18.0.0", - "ts-mocha": "^9.0.2", - "tsd": "^0.24.1", - "typedoc": "^0.25.1", - "typescript": "^4.6.4", - "wabt": "^1.0.32" - }, - "main": "pyodide.js", "exports": { ".": { - "require": "./pyodide.js", - "import": "./pyodide.mjs", - "types": "./pyodide.d.ts" - }, - "./ffi": { - "types": "./ffi.d.ts" - }, - "./pyodide.asm.wasm": "./pyodide.asm.wasm", - "./pyodide.asm.js": "./pyodide.asm.js", - "./python_stdlib.zip": "./python_stdlib.zip", - "./pyodide.mjs": "./pyodide.mjs", - "./pyodide.js": "./pyodide.js", - "./package.json": "./package.json", - "./pyodide-lock.json": "./pyodide-lock.json" + "import": "./dist/pyodide.js", + "types": "./pyodide.ts" + } }, "files": [ - "pyodide.asm.js", - "pyodide.asm.wasm", - "python_stdlib.zip", - "pyodide.mjs", - "pyodide.js.map", - "pyodide.mjs.map", - "pyodide.d.ts", - "ffi.d.ts", - "pyodide-lock.json", - "console.html" + "dist", + "pyodide.ts", + "api.ts", + "types.ts", + "emscripten-settings.ts", + "snapshot.ts" ], - "browser": { - "child_process": false, - "crypto": false, - "fs": false, - "fs/promises": false, - "path": false, - "url": false, - "vm": false, - "ws": false - }, - "scripts": { - "build-inner": "node esbuild.config.inner.mjs", - "build": "tsc --noEmit && node esbuild.config.outer.mjs", - "test": "npm-run-all test:*", - "test:unit": "cross-env TEST_NODE=1 ts-mocha --node-option=experimental-loader=./test/loader.mjs --node-option=experimental-wasm-stack-switching -p tsconfig.test.json \"test/unit/**\"", - "test:node": "cross-env TEST_NODE=1 mocha test/integration/**/*.test.js", - "test:browser": "mocha test/integration/**/*.test.js", - "tsc": "tsc --noEmit", - "coverage": "cross-env TEST_NODE=1 npm-run-all coverage:*", - "coverage:build": "nyc npm run test:node" - }, - "mocha": { - "bail": false, - "timeout": 30000, - "full-trace": true, - "inline-diffs": true, - "check-leaks": false, - "global": [ - "pyodide", - "page", - "chai" - ] - }, - "nyc": { - "reporter": [ - "html", - "text-summary" - ], - "include": [ - "*.ts" - ], - "all": true, - "clean": true, - "cache": false, - "instrument": false, - "checkCoverage": true, - "statements": 95, - "functions": 95, - "branches": 80, - "lines": 95 - }, - "tsd": { - "compilerOptions": { - "lib": [ - "ES2017", - "DOM" - ] - } - }, - "dependencies": { - "ws": "^8.5.0" - }, - "types": "./pyodide.d.ts", + "types": "./pyodide.ts", "engines": { "node": ">=18.0.0" } diff --git a/src/js/pyodide.ts b/src/js/pyodide.ts index d3affec5daa..198ac0f0476 100644 --- a/src/js/pyodide.ts +++ b/src/js/pyodide.ts @@ -29,7 +29,8 @@ declare function _createPyodideModule( // It is used to check that memory snapshots were generated by the same build of // the runtime that is trying to use them. Attempting to use a snapshot from a // different build will fail badly. See logic in snapshot.ts. -declare const BUILD_ID: string; +// Here we set BUILD_ID to an empty string so that the check is disabled. +const BUILD_ID = ""; /** * See documentation for loadPyodide. diff --git a/src/js/tsconfig.json b/src/js/tsconfig.json index 05082758958..42e49fc7ff1 100644 --- a/src/js/tsconfig.json +++ b/src/js/tsconfig.json @@ -11,7 +11,6 @@ "tsBuildInfoFile": "tsconfig.tsbuildinfo", "strict": true, "noUnusedLocals": false, - "types": ["node"], "experimentalDecorators": true, "lib": ["ES2022", "DOM"], "resolveJsonModule": true,