Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
327 changes: 168 additions & 159 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ xxhash-rust = "0.8.15"
zip = { version = "7.2", default-features = false, features = ["deflate-flate2-zlib-rs"] }

# oxc crates with the same version
oxc = { version = "0.149.0", features = [
oxc = { version = "0.150.0", features = [
"ast_visit",
"transformer",
"minifier",
Expand All @@ -331,17 +331,17 @@ oxc = { version = "0.149.0", features = [
"regular_expression",
"cfg",
] }
oxc_allocator = { version = "0.149.0", features = ["pool"] }
oxc_ast = "0.149.0"
oxc_ecmascript = "0.149.0"
oxc_parser = "0.149.0"
oxc_span = "0.149.0"
oxc_napi = "0.149.0"
oxc_str = "0.149.0"
oxc_minify_napi = "0.149.0"
oxc_parser_napi = "0.149.0"
oxc_transform_napi = "0.149.0"
oxc_traverse = "0.149.0"
oxc_allocator = { version = "0.150.0", features = ["pool"] }
oxc_ast = "0.150.0"
oxc_ecmascript = "0.150.0"
oxc_parser = "0.150.0"
oxc_span = "0.150.0"
oxc_napi = "0.150.0"
oxc_str = "0.150.0"
oxc_minify_napi = "0.150.0"
oxc_parser_napi = "0.150.0"
oxc_transform_napi = "0.150.0"
oxc_traverse = "0.150.0"

# oxc crates in their own repos
oxc_index = { version = "5", features = ["rayon", "serde"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ export default defineConfig({
"plugins": [
"oxc",
"typescript",
"unicorn",
"react"
"unicorn"
],
"categories": {
"correctness": "warn"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ export default defineConfig({
"plugins": [
"oxc",
"typescript",
"unicorn",
"react"
"unicorn"
],
"jsPlugins": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ export default defineConfig({
"plugins": [
"oxc",
"typescript",
"unicorn",
"react"
"unicorn"
],
"jsPlugins": [
"eslint-plugin-survives",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ export default defineConfig({
"plugins": [
"oxc",
"typescript",
"unicorn",
"react"
"unicorn"
],
"categories": {
"correctness": "warn"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ export default defineConfig({
"plugins": [
"oxc",
"typescript",
"unicorn",
"react"
"unicorn"
],
"categories": {
"correctness": "warn"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ export default defineConfig({
"plugins": [
"oxc",
"typescript",
"unicorn",
"react"
"unicorn"
],
"categories": {
"correctness": "warn"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export default defineConfig({
"plugins": [
"oxc",
"typescript",
"unicorn",
"react"
"unicorn"
],
"categories": {
"correctness": "warn"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ export default defineConfig({
"plugins": [
"oxc",
"typescript",
"unicorn",
"react"
"unicorn"
],
"categories": {
"correctness": "warn"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ export default defineConfig({
"plugins": [
"oxc",
"typescript",
"unicorn",
"react"
"unicorn"
],
"categories": {
"correctness": "warn"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default defineConfig({
},
fmt: {},
lint: {
plugins: ["oxc", "typescript", "unicorn", "react"],
plugins: ["oxc", "typescript", "unicorn"],
categories: {
correctness: "warn",
},
Expand Down Expand Up @@ -147,6 +147,7 @@ export default defineConfig({
},
],
},
plugins: ["react"],
env: {
es2020: true,
browser: true,
Expand Down
83 changes: 82 additions & 1 deletion packages/cli/binding/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

const { readFileSync } = require('fs');
let nativeBinding = null;
// Which artifact actually loaded. The WASI fallback chain overwrites it with
// the flavor it resolved; the late native retry below leaves it alone because
// it only runs while no WASI candidate has been loaded.
let __napiLoadedBindingTarget = 'native';
const loadErrors = [];

const isMusl = () => {
Expand Down Expand Up @@ -64,7 +68,16 @@ const isMuslFromChildProcess = () => {
function requireNative() {
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
try {
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
const overrideBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
// The override may be a generated WASI loader, which already reports its
// own flavor. Adopt it: `module.exports` aliases this object, so claiming
// 'native' would both misreport the artifact and overwrite the loader's
// marker through the alias.
__napiLoadedBindingTarget =
overrideBinding && typeof overrideBinding.__napiBindingTarget === 'string'
? overrideBinding.__napiBindingTarget
: 'native';
return overrideBinding;
} catch (err) {
loadErrors.push(err);
}
Expand Down Expand Up @@ -815,6 +828,7 @@ if (!nativeBinding || forceWasi) {
if (!candidateFailed) {
wasiBinding = require('./vite-plus.wasi.cjs');
nativeBinding = wasiBinding;
__napiLoadedBindingTarget = 'wasm32-wasi';
wasiBindingLoaded = true;
}
} catch (err) {
Expand Down Expand Up @@ -851,6 +865,7 @@ if (!nativeBinding || forceWasi) {
}
wasiBinding = require('@voidzero-dev/vite-plus-wasm32-wasi');
nativeBinding = wasiBinding;
__napiLoadedBindingTarget = 'wasm32-wasi';
wasiBindingLoaded = true;
}
} catch (err) {
Expand Down Expand Up @@ -891,6 +906,71 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`);
}

function __napiStampBindingTarget(exportsObject, target) {
if (Object.prototype.hasOwnProperty.call(exportsObject, '__napiBindingTarget')) {
if (exportsObject.__napiBindingTarget === target) {
// Already ours: the root entry aliases the object it loaded, so a WASI
// fallback candidate — or a `NAPI_RS_NATIVE_LIBRARY_PATH` override that
// is a generated loader — arrives already stamped with this same value.
return target;
}
const error = new Error(
'`__napiBindingTarget` is reserved by the generated binding loader, but the loaded binding already exports it. Rename the export, e.g. #[napi(js_name = "...")].',
);
error.code = 'ERR_NAPI_BINDING_TARGET_CONFLICT';
throw error;
}
if (!Object.isExtensible(exportsObject)) {
// A `#[napi(module_exports)]` hook may seal or freeze this object
// (`Object::seal` / `Object::freeze`). Reporting the artifact is metadata,
// never a reason to fail an otherwise successful load, so the stamp is
// skipped. What a consumer still sees then follows the entry point: the
// browser and deferred loaders declare `__napiBindingTarget` at module
// level and go on reporting it, while the CommonJS entries hand back this
// very object as `module.exports`, so there the value is absent.
return target;
}
try {
// [[Define]], not [[Set]]: an ordinary assignment walks the prototype
// chain, so an inherited accessor could swallow the value or throw and
// fail an otherwise successful load. The descriptor is what a successful
// assignment would have produced.
Object.defineProperty(exportsObject, '__napiBindingTarget', {
configurable: true,
enumerable: true,
value: target,
writable: true,
});
} catch {
// Same rule as the non-extensible skip above: reporting the artifact is
// metadata, never a reason to fail an otherwise successful load. An exotic
// object (a Proxy whose defineProperty trap refuses) is skipped, not
// thrown over.
}
// The CommonJS loaders assign this return value so `cjs-module-lexer` — and
// therefore Node's CJS -> ESM named export detection — can see
// `__napiBindingTarget` statically.
return target;
}
// Stamp before the alias, not after. The guard only reads `nativeBinding`
// (`hasOwnProperty` plus a comparison), which is safe against any addon
// accessor; an assignment is not, because a `#[napi(module_exports)]` hook can
// expose a getter reporting this very value and a setter that throws. So the
// assignment lands on the loader's own `module.exports`, still the original
// object here, and the alias below replaces it.
//
// The assignment is what keeps the marker a statically visible CommonJS export:
// `cjs-module-lexer` is Node's CJS -> ESM named export detection, it cannot see
// a bare call, and the later `module.exports = nativeBinding` does not undo the
// detection. The assignment itself always succeeds — its target is this
// loader's own, still extensible `module.exports` — and the alias below then
// discards the value it wrote. What a consumer reads is whatever the guard put
// on `nativeBinding`, so on a frozen binding, where the guard skips, the
// linked import resolves to `undefined`.
module.exports.__napiBindingTarget = __napiStampBindingTarget(
nativeBinding,
__napiLoadedBindingTarget,
);
module.exports = nativeBinding;
module.exports.LegalCommentsMode = nativeBinding.LegalCommentsMode;
module.exports.minify = nativeBinding.minify;
Expand Down Expand Up @@ -941,6 +1021,7 @@ module.exports.BindingWatcherEvent = nativeBinding.BindingWatcherEvent;
module.exports.ParallelJsPluginRegistry = nativeBinding.ParallelJsPluginRegistry;
module.exports.TraceSubscriberGuard = nativeBinding.TraceSubscriberGuard;
module.exports.TsconfigCache = nativeBinding.TsconfigCache;
module.exports.__internalForcePanic = nativeBinding.__internalForcePanic;
module.exports.BindingAttachDebugInfo = nativeBinding.BindingAttachDebugInfo;
module.exports.BindingBuiltinPluginName = nativeBinding.BindingBuiltinPluginName;
module.exports.BindingChunkModuleOrderBy = nativeBinding.BindingChunkModuleOrderBy;
Expand Down
34 changes: 34 additions & 0 deletions packages/cli/binding/index.d.cts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,39 @@ type VoidNullable<T = void> = T | null | undefined | void;
export type BindingStringOrRegex = string | RegExp;
export type BindingResult<T> = { errors: BindingError[]; isBindingErrors: boolean } | T;

/**
* Which binding artifact the generated loader actually loaded: `'native'` for
* a native addon, otherwise the `platformArchABI` of the WASI flavor. Every
* flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
* can point the loader at a WASI artifact this package does not build itself.
*/
export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1';

export interface CodegenOptions {
/**
* Remove whitespace.
*
* @default true
*/
removeWhitespace?: boolean;
/**
* Escape non-ASCII characters in string literals, untagged template literals, regular
* expression literals and identifier names.
*
* Uses `\uXXXX` for characters up to U+FFFF and `\u{...}` for higher code points.
* Regular expressions use escaped UTF-16 surrogate pairs for higher code points instead;
* escaping changes the observable `RegExp.prototype.source` value.
*
* Code point escapes (`\u{...}`) require ES2015 or later; this option does not provide
* ES5-compatible output.
*
* Non-ASCII characters are left unescaped in tagged template quasis (whose raw text is
* observable), JSX names and text, JSX attribute strings, hashbangs and preserved comments.
* JavaScript expressions inside tagged templates and JSX are escaped normally.
*
* @default false
*/
asciiOnly?: boolean;
/**
* How to handle legal comments (comments containing `@license`, `@preserve`, or starting with `//!`/`/*!`).
*
Expand Down Expand Up @@ -2026,6 +2052,13 @@ export declare class TsconfigCache {
size(): number;
}

/**
* Panics on purpose. CI calls this to check that a published binding can produce a
* symbolicated backtrace from its separately published debug info.
* See `scripts/misc/verify-debuginfo.mjs` and internal-docs/panic-symbolication/implementation.md
*/
export declare function __internalForcePanic(): void;

export interface AliasItem {
find: string;
replacements: Array<string | undefined | null>;
Expand Down Expand Up @@ -2104,6 +2137,7 @@ export interface BindingChecksOptions {
unresolvedEntry?: boolean;
unresolvedImport?: boolean;
filenameConflict?: boolean;
moduleLevelDirective?: boolean;
commonJsVariableInEsm?: boolean;
importIsUndefined?: boolean;
emptyImportMeta?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
},
"bundledVersions": {
"vite": "8.3.0",
"rolldown": "1.2.8",
"rolldown": "1.2.9",
"tsdown": "0.23.0"
}
}
2 changes: 1 addition & 1 deletion packages/tools/.upstream-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"rolldown": {
"repo": "https://github.com/rolldown/rolldown.git",
"branch": "main",
"hash": "9704b565076baf57b3703c98ebde973855506a68"
"hash": "5b4746e442989d770c606ce08d2737e6aafbd25d"
},
"vite": {
"repo": "https://github.com/vitejs/vite.git",
Expand Down
Loading
Loading