@gjsify/rolldown-plugin-gjsify 0.36.0 → 0.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,8 @@
1
1
  import type { Plugin } from 'rolldown';
2
2
  /**
3
- * Fast-path filter (superset of what `claimSpecifier` claims). Handler re-checks.
4
- *
3
+ * Fast-path filter — a superset of what the handler claims; the handler re-checks.
5
4
  * Exported so `napi-node-addon.spec.ts` can assert its Rust-compatibility (see
6
- * {@link BARE_SPECIFIER_RE}) — a JS-only construct here disables the plugin
7
- * entirely under `@gjsify/rolldown-native`, and no build-level test would see
8
- * it, because every addon gate drives the Node CLI entry.
5
+ * {@link BARE_SPECIFIER_RE}).
9
6
  */
10
7
  export declare const ADDON_FILTER_RE: RegExp;
11
8
  /** Options for {@link napiNodeAddonPlugin}. */
@@ -21,22 +18,15 @@ export declare class AddonNotBuiltError extends Error {
21
18
  constructor(pkgRoot: string);
22
19
  }
23
20
  /**
24
- * Locate the compiled `.node` for an addon package root, matching
25
- * node-gyp-build's probe order: `build/Release` → `build/Debug` →
26
- * `prebuilds/<platform>-<arch>/<best tag>`. Throws {@link AddonNotBuiltError}
27
- * when nothing is found.
28
- *
29
- * @param pkgRoot Absolute path to the addon package root (dir with package.json).
30
- * @param opts.warn Optional sink for a non-fatal warning (ambiguous build dir).
21
+ * Locate the compiled `.node` for an addon package root, matching node-gyp-build's
22
+ * probe order: `build/Release` → `build/Debug` →
23
+ * `prebuilds/<platform>-<arch>/<best tag>`. Throws {@link AddonNotBuiltError} when
24
+ * nothing is found. `opts.warn` sinks the non-fatal ambiguous-build-dir warning.
31
25
  */
32
26
  export declare function resolveAddonPath(pkgRoot: string, opts?: {
33
27
  warn?: (msg: string) => void;
34
28
  }): string;
35
- /**
36
- * Walk up from an importer file to the nearest `package.json` directory (the
37
- * addon package root). Returns null when none is found (should not happen for a
38
- * real node_modules dep).
39
- */
29
+ /** Nearest ancestor directory of `importerFile` holding a `package.json`. */
40
30
  export declare function nearestPackageRoot(importerFile: string): string | null;
41
31
  /** Direct `.node` import → the addon's exports (ESM default). */
42
32
  export declare function directNodeShim(addonPath: string): string;
@@ -46,12 +36,7 @@ export declare function nodeGypBuildShim(addonPath: string): string;
46
36
  export declare function bindingsShim(addonPath: string): string;
47
37
  /** napi-rs sibling → the raw native exports as the module value. */
48
38
  export declare function napiRsShim(addonPath: string): string;
49
- /**
50
- * Classify a specifier for interception. Pure decision logic (no filesystem
51
- * probing beyond what `resolveAddonPath` does via the importer) — exported for
52
- * the unit tests. Returns the shim kind + the package root to probe, or the
53
- * literal `.node` path for the direct case.
54
- */
39
+ /** Classify a specifier for interception — pure decision logic, no filesystem. */
55
40
  export declare function classifySpecifier(source: string): {
56
41
  kind: 'node-gyp-build' | 'bindings';
57
42
  } | {
@@ -73,89 +58,67 @@ export interface AddonPackageJson {
73
58
  /**
74
59
  * Is this manifest a gjsify NATIVE BRIDGE whose prebuilds live in per-target
75
60
  * sibling packages (ADR 0017) — `@gjsify/webgl` + `@gjsify/webgl-darwin-x64`, …?
61
+ * Such a bridge ships a GI typelib plus a `.so`/`.dylib`/`.dll` loaded through
62
+ * `gi://`, NEVER a Node-API `.node`, so it must never reach `loadAddon()`.
76
63
  *
77
- * Such a bridge ships a GObject-Introspection typelib plus a `.so`/`.dylib`/`.dll`
78
- * loaded through `gi://`, NEVER a Node-API `.node` addon, so it must never be
79
- * routed through `loadAddon()`.
80
- *
81
- * It has to be excluded EXPLICITLY because the two conventions are
82
- * indistinguishable by name: ADR 0017 spells a target `<os>-<arch>` and names the
83
- * package `<self>-<os>-<arch>` in `optionalDependencies` — which is exactly
84
- * napi-rs' `<self>-<triple>` sibling scheme whenever the target happens to be a
85
- * name napi-rs also uses. On Linux the two vocabularies differ by the libc token
86
- * (`linux-x64` vs napi-rs' `linux-x64-gnu`), so `hostNapiRsTriple()` never matched
87
- * and nothing fired; on macOS napi-rs' triple IS `darwin-x64` / `darwin-arm64`,
88
- * so every split bridge looked like a napi-rs package to
89
- * {@link isNapiRsPackageJson} and {@link resolveNapiRsEntryAddon} then probed
90
- * `ctx.resolve('@gjsify/webgl-darwin-x64')` — an artifact-only package with no JS
91
- * entry at all. That probe does not return null: the `unresolved-workspace-import`
92
- * guard (correctly) treats an unresolvable bare `@gjsify/*` as FATAL, so
93
- * `gjsify build --app gjs` of any consumer of any split bridge died on darwin with
94
- * "cannot resolve the workspace package" — invisible to every Linux CI job.
64
+ * The exclusion must be EXPLICIT because the two conventions are indistinguishable
65
+ * by name: ADR 0017's `<self>-<os>-<arch>` optionalDependency is exactly napi-rs'
66
+ * `<self>-<triple>` scheme wherever the vocabularies agree. On Linux they differ by
67
+ * the libc token (`linux-x64` vs `linux-x64-gnu`) so nothing fired, but on macOS
68
+ * napi-rs' triple IS `darwin-arm64`: every split bridge looked like a napi-rs
69
+ * package, {@link resolveNapiRsEntryAddon} probed an artifact-only package with no
70
+ * JS entry, and the `unresolved-workspace-import` guard (correctly) made that
71
+ * unresolvable bare `@gjsify/*` FATAL — so `--app gjs` of any consumer of any split
72
+ * bridge died on darwin, invisible to every Linux CI job.
95
73
  *
96
- * `gjsify.platforms` is the right discriminator: it is the OS-axis declaration
97
- * every native bridge carries (§ Runtime & platform model) and no napi-rs package
98
- * has any reason to declare it.
99
- *
100
- * Exported for the unit tests.
74
+ * `gjsify.platforms` is the right discriminator: the OS-axis declaration every
75
+ * native bridge carries (§ Runtime & platform model), which no napi-rs package has
76
+ * reason to declare.
101
77
  */
102
78
  export declare function isGjsifyNativeBridge(pkg: AddonPackageJson): boolean;
103
79
  /**
104
- * A package.json describes a napi-rs generated-loader package when EITHER
105
- * signal holds — both are package.json-level (not source sniffing):
80
+ * A package.json describes a napi-rs generated-loader package when EITHER signal
81
+ * holds:
106
82
  *
107
83
  * (a) a top-level `napi` config OBJECT (`{ binaryName, targets, … }`) — the
108
- * napi-rs CLI's own build block. An ordinary npm package never declares a
109
- * `napi` object at the manifest root.
110
- * (b) at least one `optionalDependencies` entry that is a platform SIBLING
111
- * (see {@link isNapiRsSibling}) — the napi-rs prebuilt-binary convention,
112
- * under either naming scheme: `<self>-<triple>` (`@node-rs/argon2` ships
113
- * `@node-rs/argon2-linux-x64-gnu`) or `<napi.packageName>-<triple>`
114
- * (`rolldown` ships `@rolldown/binding-linux-x64-gnu`). The key MUST
115
- * carry a known prefix AND end in a platform triple, so a normal optional
116
- * dep (`fsevents`) can't match.
84
+ * napi-rs CLI's build block, which no ordinary npm package declares.
85
+ * (b) an `optionalDependencies` entry that is a platform SIBLING (see
86
+ * {@link isNapiRsSibling}) — the key must carry a known prefix AND end in a
87
+ * platform triple, so a normal optional dep (`fsevents`) can't match.
117
88
  *
118
- * Neither fires on a normal package, so pairing this with the "resolved file IS
119
- * the package's own native main entry" check (see {@link detectNapiRsEntry})
120
- * makes entry-replacement safe. Exported for the unit tests.
89
+ * Neither fires on a normal package, so pairing this with the "resolved file IS the
90
+ * package's own native main entry" check ({@link detectNapiRsEntry}) makes
91
+ * entry-replacement safe.
121
92
  */
122
93
  export declare function isNapiRsPackageJson(pkg: AddonPackageJson): boolean;
123
94
  /**
124
- * Decide whether an absolute file path is the NATIVE generated-loader entry of a
125
- * napi-rs package. Returns the package root + parsed manifest when it is, else
126
- * null. "Native entry" = the package's `main` (default `index.js`) — NOT its
127
- * `browser`/wasm fallback and NOT a deep file — so we only ever replace the one
128
- * generated loader, never an unrelated module. Filesystem-based (reads the
129
- * nearest package.json); the plugin memoizes calls. Exported for the unit tests.
95
+ * Is this absolute file path the NATIVE generated-loader entry of a napi-rs package?
96
+ * Returns the package root + parsed manifest, else null. "Native entry" = a path the
97
+ * manifest names as its entry — NOT its `browser`/wasm fallback and NOT a deep file
98
+ * — so only the one generated loader is ever replaced. Reads the nearest
99
+ * package.json; the plugin memoizes calls.
130
100
  */
131
101
  export declare function detectNapiRsEntry(entryFile: string): {
132
102
  pkgRoot: string;
133
103
  pkg: AddonPackageJson;
134
104
  } | null;
135
105
  /**
136
- * Is `dep` a platform sibling of `pkg` — `<prefix>-<triple>` for one of the
137
- * prefixes above? Both halves must hold: a bare prefix match would claim an
138
- * ordinary dependency, and a bare triple match would claim an unrelated
139
- * package's binaries. Exported for the unit tests.
106
+ * Is `dep` a platform sibling of `pkg` — `<prefix>-<triple>` for one of the prefixes
107
+ * above? Both halves must hold: a bare prefix match would claim an ordinary
108
+ * dependency, a bare triple match an unrelated package's binaries.
140
109
  */
141
110
  export declare function isNapiRsSibling(pkg: AddonPackageJson, dep: string): boolean;
142
111
  /**
143
112
  * The napi-rs short platform triple for the CURRENT host (`linux-x64-gnu`,
144
- * `darwin-arm64`, `win32-x64-msvc`, …) — the tail napi-rs stamps into a sibling
145
- * package name (`@node-rs/argon2-linux-x64-gnu`) and a local binary
146
- * (`argon2.linux-x64-gnu.node`). Selects BOTH the sibling package and the
147
- * local-file fallback — see `resolveNapiRsEntryAddon` for why the sibling path
148
- * cannot just take whatever resolves. Returns null for a host napi-rs doesn't
149
- * name, and the caller then widens rather than guessing.
113
+ * `darwin-arm64`, …) — the tail napi-rs stamps into a sibling package name and a
114
+ * local binary, and the selector for both. Returns null for a host napi-rs does not
115
+ * name; the caller then widens rather than guessing.
150
116
  */
151
117
  export declare function hostNapiRsTriple(): string | null;
152
118
  /**
153
- * Transparent `.node`-addon loader for `gjsify build --app gjs`.
154
- *
155
- * resolveId (`order: 'pre'`, importer-aware) intercepts a native-addon
156
- * acquisition and rewrites it to a virtual module whose value is
157
- * `loadAddon('<abs .node>')`. Inert unless such a specifier is in the graph —
158
- * every other id returns null. Register ONLY for `--app gjs` (the C-ABI runs
159
- * under `@gjsify/napi`); never for node/browser/nativescript.
119
+ * Transparent `.node`-addon loader for `gjsify build --app gjs`: resolveId
120
+ * (`order: 'pre'`, importer-aware) rewrites a native-addon acquisition to a virtual
121
+ * module whose value is `loadAddon('<abs .node>')`, and returns null for everything
122
+ * else. Register ONLY for `--app gjs` — the C-ABI runs under `@gjsify/napi`.
160
123
  */
161
124
  export declare function napiNodeAddonPlugin(options?: NapiNodeAddonPluginOptions): Plugin;