From c53e229175e41c1cd3c81e9bb5014f493ee3f27e Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Mon, 12 Sep 2022 17:00:54 -0500 Subject: [PATCH] Fix webpack warnings and reenable webpack test (#3094) This uses sed to insert /* webpackIgnore: true */ comments into pyodide.js. This resolves #3087. I also enabled a check that a simple webpack config builds without warnings. In the future it would be good to add a test that it also runs without error. --- .circleci/config.yml | 16 ++++++++-------- Makefile | 4 ++++ docs/project/changelog.md | 5 +++++ src/js/compat.ts | 1 - 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 639f64b28..d37991936 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -369,14 +369,14 @@ jobs: npm link ../../dist npm run test-types npm test - # - run: - # name: check if webpack cli works well with load-pyodide.js - # command: | - # git clone https://github.com/pyodide/pyodide-webpack-example.git - # cd pyodide-webpack-example - # npm ci - # cp ../src/js/*.js node_modules/pyodide/ - # npx webpack + - run: + name: check if Pyodide works with Webpack + command: | + git clone https://github.com/pyodide/pyodide-webpack-example.git + export DEV_PYODIDE_PATH=`realpath dist` + cd pyodide-webpack-example + git checkout 164054a9c6fbd2176f386b6552ed8d079c6bcc04 + ./build.sh test-cmdline-runner: <<: *defaults diff --git a/Makefile b/Makefile index 28ee46187..f426eb243 100644 --- a/Makefile +++ b/Makefile @@ -74,6 +74,10 @@ node_modules/.installed : src/js/package.json src/js/package-lock.json dist/pyodide.js src/js/_pyodide.out.js: src/js/*.ts src/js/pyproxy.gen.ts src/js/error_handling.gen.ts node_modules/.installed npx rollup -c src/js/rollup.config.js + # Add /* webpackIgnore: true */ to each dynamic import in `pyodide.js`. + # Rollup strips comments so this can't be done via the source file. + # We use ! as the sed separator because the replacement text includes / + sed -i 's!await import(!await import(/* webpackIgnore: true */ !g' dist/pyodide.js dist/package.json : src/js/package.json cp $< $@ diff --git a/docs/project/changelog.md b/docs/project/changelog.md index 1c868f94f..22d5ba5b9 100644 --- a/docs/project/changelog.md +++ b/docs/project/changelog.md @@ -58,6 +58,11 @@ substitutions: - {{ Fix }} Add `url` to list of pollyfilled packages for webpack compatibility. {pr}`3080` +- {{ Fix }} Fixed warnings like + `Critical dependency: the request of a dependency is an expression.` + when using Pyodide with webpack. + {pr}`3080` + - {{ Fix }} Source maps are included in the distribution again (reverting {pr}`3015` included in 0.21.2) and if there is a variable in top level scope called `__dirname` we use that for the `indexURL`. diff --git a/src/js/compat.ts b/src/js/compat.ts index c94fb1075..0fe8b65b1 100644 --- a/src/js/compat.ts +++ b/src/js/compat.ts @@ -182,7 +182,6 @@ if (globalThis.document) { } else if (globalThis.importScripts) { // webworker loadScript = async (url) => { - // This is async only for consistency try { // use importScripts in classic web worker globalThis.importScripts(url);