Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/angular/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"xxhash-wasm": "1.1.0"
},
"optionalDependencies": {
"@oxc-parser/binding-wasm32-wasi": "0.156.0",
Comment thread
alan-agius4 marked this conversation as resolved.
Resolved
"lmdb": "3.5.9"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/

import '../oxc/oxc-wasi-shim';
import { type DecodedSourceMap, type SourceMapInput } from '@ampproject/remapping';
import {
type ɵParsedTranslation,
Expand Down
1 change: 1 addition & 0 deletions packages/angular/build/src/tools/oxc/oxc-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/

import './oxc-wasi-shim';
import type { DecodedSourceMap } from '@ampproject/remapping';
import { needsLinking } from '@angular/compiler-cli/linker';
import type { BindingIdentifier, Class, Node } from '@oxc-project/types';
Expand Down
46 changes: 46 additions & 0 deletions packages/angular/build/src/tools/oxc/oxc-wasi-shim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

// Workaround for an upstream incompatibility in `@oxc-parser/binding-wasm32-wasi` when
// falling back to WebAssembly (e.g., inside WebContainers or StackBlitz).
//
// `@oxc-parser/binding-wasm32-wasi` declares a dependency on `@emnapi/core@2.0.0-alpha.6`,
// but depends on `@napi-rs/wasm-runtime@~1.2.6` which expects `@emnapi/core@>=2.0.0-beta.2`.
// In `@napi-rs/wasm-runtime@1.2.6`, the runtime attempts to assign `initWorker` to
// `emnapi_shared.addonModule`, which is undefined in `alpha.6` where the property was named
// `napiModule`. This results in `TypeError: Cannot set properties of undefined (setting 'initWorker')`,
// causing WASI binding initialization to fail and surface as a misleading "WASI binding not found" error
// or an `ERR_REQUIRE_CYCLE_MODULE` failure.
//
// Aliasing `addonModule` to `this.napiModule` on `Object.prototype` allows the WASI runtime to
// initialize successfully.
//
// See: https://github.com/oxc-project/oxc/issues/28717 and https://github.com/napi-rs/napi-rs/issues/3674
if (
(globalThis.process?.versions?.['webcontainer'] ||
globalThis.process?.env?.['NAPI_RS_FORCE_WASI'] === 'true') &&
Comment thread
alan-agius4 marked this conversation as resolved.
Resolved
!('addonModule' in Object.prototype)
) {
Object.defineProperty(Object.prototype, 'addonModule', {
get() {
return (this as { napiModule?: unknown }).napiModule;
},
set(value) {
if (this && (typeof this === 'object' || typeof this === 'function')) {
Object.defineProperty(this, 'addonModule', {
value,
writable: true,
configurable: true,
enumerable: true,
});
}
},
configurable: true,
enumerable: false,
});
Comment thread
alan-agius4 marked this conversation as resolved.
Resolved
}
1 change: 1 addition & 0 deletions packages/angular/build/src/tools/oxc/traversal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/

import './oxc-wasi-shim';
import type { Node } from '@oxc-project/types';
import { visitorKeys } from 'oxc-parser';

Expand Down
61 changes: 0 additions & 61 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions tests/e2e/tests/vite/wasi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import assert from 'node:assert';
import { getGlobalVariable } from '../../utils/env';
import { ngServe } from '../../utils/project';

export default async function () {
assert(
getGlobalVariable('argv')['esbuild'],
'This test should not be called in the Webpack suite.',
);

const originalForceWasi = process.env['NAPI_RS_FORCE_WASI'];
process.env['NAPI_RS_FORCE_WASI'] = 'true';
Comment thread
alan-agius4 marked this conversation as resolved.
Resolved

try {
const port = await ngServe();
const response = await fetch(`http://localhost:${port}/`);
Comment thread
alan-agius4 marked this conversation as resolved.
Resolved
assert(response.ok, 'Expected response to be ok');
const text = await response.text();
assert.match(text, /<app-root/);
} finally {
if (originalForceWasi === undefined) {
delete process.env['NAPI_RS_FORCE_WASI'];
} else {
process.env['NAPI_RS_FORCE_WASI'] = originalForceWasi;
}
}
}
Loading