-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: isomorphic wasi (again) and patched wasi-js (#1584)
This PR reintroduces #1571 with 3 additional changes to avoid [the last regression](#1578): - `patch-package` is used to mess with wasi-js, to remove the preinstall script from their package.json. The patching is performed during packaging, where it's actually effective (for downstream consumers). - wasi-js is included as a bundled dep for winglang to ensure that the patched `package.json` is appropriately patched in time to avoid any hooks. Normally this isn't needed with patch package, but due to the particular mutation I'm not sure this is avoidable - Added checks to hangar to ensure we avoid introducing script hooks. I verified that these tests pass with the latest version of the repo but fail the version noted in the regression. The changes from the original PR are untouched. *By submitting this pull request, I confirm that my contribution is made under the terms of the [Monada Contribution License](https://docs.winglang.io/terms-and-policies/contribution-license.html)*.
- Loading branch information
1 parent
5332d6e
commit e8e8860
Showing
16 changed files
with
166,324 additions
and
5,963 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,40 @@ | ||
// idk how many of these are actually needed | ||
import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill"; | ||
import { NodeModulesPolyfillPlugin } from "@esbuild-plugins/node-modules-polyfill"; | ||
import rollupNodePolyFill from "rollup-plugin-node-polyfills"; | ||
import { nodePolyfills } from "vite-plugin-node-polyfills"; | ||
|
||
/** @type {import('vite').UserConfig} */ | ||
export default { | ||
resolve: { | ||
preserveSymlinks: true, | ||
alias: { | ||
process: "rollup-plugin-node-polyfills/polyfills/process-es6", | ||
buffer: "rollup-plugin-node-polyfills/polyfills/buffer-es6", | ||
"wasi-js/dist/bindings/node": "wasi-js/dist/bindings/browser", | ||
}, | ||
}, | ||
plugins: [nodePolyfills()], | ||
worker: { | ||
format: "es", | ||
plugins: [nodePolyfills()], | ||
rollupOptions: { | ||
preserveSymlinks: true, | ||
}, | ||
}, | ||
build: { | ||
target: "esnext", | ||
rollupOptions: { | ||
plugins: [rollupNodePolyFill()], | ||
target: "es2022", | ||
commonjsOptions: { | ||
// This is needed because winglang is symlinked | ||
include: [/winglang/, /node_modules/], | ||
}, | ||
}, | ||
server: { | ||
fs: { | ||
allow: [".."], | ||
}, | ||
}, | ||
optimizeDeps: { | ||
include: ["winglang"], | ||
esbuildOptions: { | ||
define: { | ||
global: "globalThis", | ||
}, | ||
plugins: [ | ||
NodeGlobalsPolyfillPlugin({ | ||
process: true, | ||
buffer: true, | ||
}), | ||
NodeModulesPolyfillPlugin(), | ||
], | ||
target: "es2022", | ||
preserveSymlinks: true, | ||
}, | ||
force: true, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
// Only certain builds and versions of Node support WASI. | ||
// We first assume this script is loaded in the correct runtime environment, and | ||
// if not, we try to load it in a WASI-compatible runtime environment by running | ||
// the same script (self) over a new Node process with the correct flags passed. | ||
// package.json warns if user npm installs this for a non-compatible runtime. | ||
|
||
try { | ||
require.resolve("wasi"); | ||
} catch (err) { | ||
if (err.code === "MODULE_NOT_FOUND") { | ||
const { spawnSync } = require("child_process"); | ||
const { env, execPath, execArgv, argv } = process; | ||
env.NODE_OPTIONS = [ | ||
...new Set((env.NODE_OPTIONS ?? "").split(" ")) | ||
.add("--experimental-wasi-unstable-preview1") | ||
.add("--no-warnings"), | ||
].join(" "); | ||
|
||
const { status } = spawnSync(execPath, execArgv.concat(argv.slice(1)), { | ||
env, | ||
stdio: "inherit", | ||
}); | ||
process.exit(status ?? 1); | ||
} else { | ||
console.error('Unable to load "wasi" module', err); | ||
process.exit(1); | ||
} | ||
} | ||
require("../dist/index.js"); | ||
require("../dist/cli.js"); |
Oops, something went wrong.