mirror of https://github.com/pyodide/pyodide.git
Revert "Using esbuild instead of rollup (#3679)"
This reverts commit be12f07ed9
.
This commit is contained in:
parent
0a1d87d45f
commit
bce105bd69
|
@ -89,7 +89,7 @@ repos:
|
|||
"--ignore-words-list",
|
||||
"ags,aray,asend,ba,classs,crate,falsy,feld,inflight,lits,nd,slowy,te",
|
||||
]
|
||||
exclude: ^(benchmark/benchmarks/pystone_benchmarks/pystone\.py|src/js/package-lock\.json)$
|
||||
exclude: ^benchmark/benchmarks/pystone_benchmarks/pystone\.py$
|
||||
|
||||
ci:
|
||||
autoupdate_schedule: "quarterly"
|
||||
|
|
2
Makefile
2
Makefile
|
@ -124,7 +124,7 @@ node_modules/.installed : src/js/package.json src/js/package-lock.json
|
|||
touch node_modules/.installed
|
||||
|
||||
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
|
||||
cd src/js && npm run tsc && node esbuild.config.mjs && cd -
|
||||
npx rollup -c src/js/rollup.config.mjs
|
||||
|
||||
dist/package.json : src/js/package.json
|
||||
cp $< $@
|
||||
|
|
|
@ -1,91 +0,0 @@
|
|||
import { dirname, join } from "node:path";
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
|
||||
import { build } from "esbuild";
|
||||
|
||||
const DEBUG = !!process.env.PYODIDE_DEBUG_JS;
|
||||
|
||||
const __dirname = dirname(new URL(import.meta.url).pathname);
|
||||
|
||||
const outputs = [
|
||||
{
|
||||
input: "pyodide",
|
||||
output: "dist/pyodide.mjs",
|
||||
format: "esm",
|
||||
},
|
||||
{
|
||||
input: "pyodide.umd",
|
||||
output: "dist/pyodide.js",
|
||||
format: "iife",
|
||||
name: "loadPyodide",
|
||||
},
|
||||
{
|
||||
input: "api",
|
||||
output: "src/js/_pyodide.out.js",
|
||||
format: "iife",
|
||||
},
|
||||
];
|
||||
|
||||
const dest = (output) => join(__dirname, "..", "..", output);
|
||||
|
||||
const config = ({ input, output, format, name: globalName }) => ({
|
||||
entryPoints: [join(__dirname, input + ".ts")],
|
||||
outfile: dest(output),
|
||||
external: [
|
||||
"child_process",
|
||||
"crypto",
|
||||
"fs",
|
||||
"fs/promises",
|
||||
"node-fetch",
|
||||
"path",
|
||||
"tty",
|
||||
"url",
|
||||
"vm",
|
||||
"ws",
|
||||
],
|
||||
minify: !DEBUG,
|
||||
keepNames: true,
|
||||
sourcemap: true,
|
||||
bundle: true,
|
||||
format,
|
||||
globalName,
|
||||
});
|
||||
|
||||
const builds = [];
|
||||
for (const output of outputs) {
|
||||
builds.push(build(config(output)));
|
||||
}
|
||||
|
||||
try {
|
||||
await Promise.all(builds);
|
||||
for (const { input, name, output } of outputs) {
|
||||
const outfile = dest(output);
|
||||
|
||||
let content = readFileSync(outfile).toString();
|
||||
|
||||
const isUMD = input.endsWith(".umd");
|
||||
const hasDEBUG = /\bDEBUG\b/.test(content);
|
||||
|
||||
// append the DEBUG flag if used in the output
|
||||
if (hasDEBUG) {
|
||||
content = content.replace(
|
||||
"//# sourceMappingURL",
|
||||
`const DEBUG=${DEBUG};\n//# sourceMappingURL`,
|
||||
);
|
||||
}
|
||||
|
||||
// simplify the umd dance for CommonJS by trying to set info on `exports`
|
||||
if (isUMD) {
|
||||
content = content.replace(
|
||||
"//# sourceMappingURL",
|
||||
`try{Object.assign(exports,${name})}catch(_){}\nglobalThis.${name}=${name}.${name};\n//# sourceMappingURL`,
|
||||
);
|
||||
}
|
||||
|
||||
if (hasDEBUG || isUMD) {
|
||||
writeFileSync(outfile, content);
|
||||
}
|
||||
}
|
||||
} catch ({ message }) {
|
||||
console.error(message);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -16,6 +16,8 @@
|
|||
},
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^21.0.1",
|
||||
"@rollup/plugin-node-resolve": "^13.1.3",
|
||||
"@types/assert": "^1.5.6",
|
||||
"@types/emscripten": "^1.39.5",
|
||||
"@types/expect": "^24.3.0",
|
||||
|
@ -28,12 +30,15 @@
|
|||
"cross-env": "^7.0.3",
|
||||
"dts-bundle-generator": "^6.7.0",
|
||||
"error-stack-parser": "^2.1.4",
|
||||
"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",
|
||||
"rollup": "^2.48.0",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"rollup-plugin-ts": "^2.0.5",
|
||||
"terser": "^5.7.0",
|
||||
"ts-mocha": "^9.0.2",
|
||||
"tsd": "^0.24.1",
|
||||
"typedoc": "^0.22.15",
|
||||
|
@ -79,7 +84,6 @@
|
|||
"test:unit": "cross-env TEST_NODE=1 ts-mocha -p tsconfig.test.json test/unit/**/*.test.ts",
|
||||
"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"
|
||||
},
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
import commonjs from "@rollup/plugin-commonjs";
|
||||
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
||||
import { terser } from "rollup-plugin-terser";
|
||||
import ts from "rollup-plugin-ts";
|
||||
|
||||
const DEBUG = !!process.env.PYODIDE_DEBUG_JS;
|
||||
|
||||
function config({ input, output, name, format, minify }) {
|
||||
return {
|
||||
input: `./src/js/${input}.ts`,
|
||||
output: {
|
||||
file: output,
|
||||
name,
|
||||
format,
|
||||
sourcemap: true,
|
||||
},
|
||||
external: [
|
||||
"path",
|
||||
"fs/promises",
|
||||
"node-fetch",
|
||||
"vm",
|
||||
"fs",
|
||||
"crypto",
|
||||
"ws",
|
||||
"child_process",
|
||||
],
|
||||
plugins: [
|
||||
commonjs(),
|
||||
ts({
|
||||
tsconfig: "src/js/tsconfig.json",
|
||||
}),
|
||||
// The nodeResolve plugin allows us to import packages from node_modules.
|
||||
// We need to include node-only packages in `external` to ensure they
|
||||
// aren't bundled for use in browser.
|
||||
nodeResolve(),
|
||||
minify
|
||||
? terser({
|
||||
compress: {
|
||||
defaults: !DEBUG,
|
||||
dead_code: true,
|
||||
global_defs: {
|
||||
DEBUG,
|
||||
},
|
||||
},
|
||||
mangle: false,
|
||||
format: {
|
||||
beautify: DEBUG,
|
||||
comments: /^\s*webpackIgnore/,
|
||||
},
|
||||
})
|
||||
: undefined,
|
||||
].filter(Boolean),
|
||||
};
|
||||
}
|
||||
|
||||
export default [
|
||||
{
|
||||
input: "pyodide",
|
||||
output: "dist/pyodide.mjs",
|
||||
format: "esm",
|
||||
minify: true,
|
||||
},
|
||||
{
|
||||
input: "pyodide.umd",
|
||||
output: "dist/pyodide.js",
|
||||
format: "umd",
|
||||
name: "loadPyodide",
|
||||
minify: true,
|
||||
},
|
||||
{
|
||||
input: "api",
|
||||
output: "src/js/_pyodide.out.js",
|
||||
format: "iife",
|
||||
minify: true,
|
||||
},
|
||||
].map(config);
|
|
@ -3,7 +3,7 @@
|
|||
"compilerOptions": {
|
||||
"outDir": "../../dist",
|
||||
"esModuleInterop": true,
|
||||
"target": "ES2018",
|
||||
"target": "ES2017",
|
||||
"module": "ES2020",
|
||||
"moduleResolution": "node",
|
||||
"composite": true,
|
||||
|
|
Loading…
Reference in New Issue