@gjsify/rolldown-plugin-gjsify 0.22.0 → 0.24.1

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.
@@ -0,0 +1,120 @@
1
+ import type { Plugin } from 'rolldown';
2
+ /**
3
+ * Fast-path filter (superset of what `claimSpecifier` claims). Handler re-checks.
4
+ *
5
+ * 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.
9
+ */
10
+ export declare const ADDON_FILTER_RE: RegExp;
11
+ /** Options for {@link napiNodeAddonPlugin}. */
12
+ export interface NapiNodeAddonPluginOptions {
13
+ /**
14
+ * Emit a one-line warning when a native addon is intercepted but
15
+ * `@gjsify/napi` is not resolvable in the consumer graph. Default `true`.
16
+ */
17
+ warnOnMissingNapi?: boolean;
18
+ }
19
+ /** A native addon package root has no resolvable compiled `.node`. */
20
+ export declare class AddonNotBuiltError extends Error {
21
+ constructor(pkgRoot: string);
22
+ }
23
+ /**
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).
31
+ */
32
+ export declare function resolveAddonPath(pkgRoot: string, opts?: {
33
+ warn?: (msg: string) => void;
34
+ }): 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
+ */
40
+ export declare function nearestPackageRoot(importerFile: string): string | null;
41
+ /** Direct `.node` import → the addon's exports (ESM default). */
42
+ export declare function directNodeShim(addonPath: string): string;
43
+ /** `node-gyp-build` replacement — a callable `load(dir)` carrying `.path()`. */
44
+ export declare function nodeGypBuildShim(addonPath: string): string;
45
+ /** `bindings` replacement — a callable `bindings(name)` returning the addon. */
46
+ export declare function bindingsShim(addonPath: string): string;
47
+ /** napi-rs sibling → the raw native exports as the module value. */
48
+ 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
+ */
55
+ export declare function classifySpecifier(source: string): {
56
+ kind: 'node-gyp-build' | 'bindings';
57
+ } | {
58
+ kind: 'direct-node';
59
+ } | {
60
+ kind: 'napi-rs-candidate';
61
+ } | null;
62
+ /** Minimal package.json shape read for napi-rs detection. */
63
+ export interface AddonPackageJson {
64
+ name?: string;
65
+ main?: string;
66
+ module?: string;
67
+ exports?: unknown;
68
+ browser?: string;
69
+ napi?: unknown;
70
+ optionalDependencies?: Record<string, string>;
71
+ }
72
+ /**
73
+ * A package.json describes a napi-rs generated-loader package when EITHER
74
+ * signal holds — both are package.json-level (not source sniffing):
75
+ *
76
+ * (a) a top-level `napi` config OBJECT (`{ binaryName, targets, … }`) — the
77
+ * napi-rs CLI's own build block. An ordinary npm package never declares a
78
+ * `napi` object at the manifest root.
79
+ * (b) at least one `optionalDependencies` entry that is a platform SIBLING
80
+ * (see {@link isNapiRsSibling}) — the napi-rs prebuilt-binary convention,
81
+ * under either naming scheme: `<self>-<triple>` (`@node-rs/argon2` ships
82
+ * `@node-rs/argon2-linux-x64-gnu`) or `<napi.packageName>-<triple>`
83
+ * (`rolldown` ships `@rolldown/binding-linux-x64-gnu`). The key MUST
84
+ * carry a known prefix AND end in a platform triple, so a normal optional
85
+ * dep (`fsevents`) can't match.
86
+ *
87
+ * Neither fires on a normal package, so pairing this with the "resolved file IS
88
+ * the package's own native main entry" check (see {@link detectNapiRsEntry})
89
+ * makes entry-replacement safe. Exported for the unit tests.
90
+ */
91
+ export declare function isNapiRsPackageJson(pkg: AddonPackageJson): boolean;
92
+ /**
93
+ * Decide whether an absolute file path is the NATIVE generated-loader entry of a
94
+ * napi-rs package. Returns the package root + parsed manifest when it is, else
95
+ * null. "Native entry" = the package's `main` (default `index.js`) — NOT its
96
+ * `browser`/wasm fallback and NOT a deep file — so we only ever replace the one
97
+ * generated loader, never an unrelated module. Filesystem-based (reads the
98
+ * nearest package.json); the plugin memoizes calls. Exported for the unit tests.
99
+ */
100
+ export declare function detectNapiRsEntry(entryFile: string): {
101
+ pkgRoot: string;
102
+ pkg: AddonPackageJson;
103
+ } | null;
104
+ /**
105
+ * Is `dep` a platform sibling of `pkg` — `<prefix>-<triple>` for one of the
106
+ * prefixes above? Both halves must hold: a bare prefix match would claim an
107
+ * ordinary dependency, and a bare triple match would claim an unrelated
108
+ * package's binaries. Exported for the unit tests.
109
+ */
110
+ export declare function isNapiRsSibling(pkg: AddonPackageJson, dep: string): boolean;
111
+ /**
112
+ * Transparent `.node`-addon loader for `gjsify build --app gjs`.
113
+ *
114
+ * resolveId (`order: 'pre'`, importer-aware) intercepts a native-addon
115
+ * acquisition and rewrites it to a virtual module whose value is
116
+ * `loadAddon('<abs .node>')`. Inert unless such a specifier is in the graph —
117
+ * every other id returns null. Register ONLY for `--app gjs` (the C-ABI runs
118
+ * under `@gjsify/napi`); never for node/browser/nativescript.
119
+ */
120
+ export declare function napiNodeAddonPlugin(options?: NapiNodeAddonPluginOptions): Plugin;