@gjsify/rolldown-plugin-pnp 0.4.36 → 0.4.37
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.
- package/lib/index.js +32 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -87,6 +87,38 @@ export async function pnpPlugin(opts = {}) {
|
|
|
87
87
|
// `@girs/*` packages don't list `gi:` as a dep).
|
|
88
88
|
if (source.startsWith('gi://'))
|
|
89
89
|
return { id: source, external: true };
|
|
90
|
+
// `node:`-prefixed specifiers (`node:fs`, `node:path`, etc.)
|
|
91
|
+
// are a Node-resolver concept Yarn PnP does NOT understand —
|
|
92
|
+
// `pnpApi.resolveRequest('node:fs', issuer)` throws
|
|
93
|
+
// `UNDECLARED_DEPENDENCY` because PnP treats `node:fs` as an
|
|
94
|
+
// ordinary specifier requiring an explicit declaration in the
|
|
95
|
+
// consumer's package.json.
|
|
96
|
+
//
|
|
97
|
+
// Returning `null` here is NOT enough under Rolldown: when
|
|
98
|
+
// `process.versions.pnp` is truthy, Rolldown's `bindingifyResolve`
|
|
99
|
+
// (see `node_modules/rolldown/dist/shared/bindingify-input-options-*.mjs`)
|
|
100
|
+
// unconditionally enables `yarnPnp: true` in the Rust resolver.
|
|
101
|
+
// That makes the native resolver run PnP for every unresolved
|
|
102
|
+
// bare specifier after the plugin `pre`-order chain returns null
|
|
103
|
+
// — including `node:fs` — and surface the exact
|
|
104
|
+
// `non-Node resolution context` error PnP throws for builtins.
|
|
105
|
+
// The user-facing `resolve` options have no knob to disable that.
|
|
106
|
+
//
|
|
107
|
+
// Instead we MUST actively intercept `node:*` here and route
|
|
108
|
+
// it through the rest of the plugin chain via `this.resolve()`
|
|
109
|
+
// (`skipSelf: true` keeps us out of the recursion). The gjsify
|
|
110
|
+
// alias plugin maps `node:<X>` → `@gjsify/<X>` and the
|
|
111
|
+
// re-resolved `@gjsify/<X>` specifier flows back through this
|
|
112
|
+
// hook in the next pass, where PnP resolves it cleanly via the
|
|
113
|
+
// polyfill-package relay below. Without this carve-out, every
|
|
114
|
+
// external PnP consumer importing `node:fs` etc. hits
|
|
115
|
+
// `[RESOLVE_ERROR] Could not resolve 'node:fs'` — exactly the
|
|
116
|
+
// failure mode surfaced by `tests/e2e/cli-only-pnp/` after the
|
|
117
|
+
// toolchain-hardening landed.
|
|
118
|
+
if (source.startsWith('node:')) {
|
|
119
|
+
const resolved = await this.resolve(source, importer, { skipSelf: true });
|
|
120
|
+
return resolved;
|
|
121
|
+
}
|
|
90
122
|
if (!importer)
|
|
91
123
|
return null;
|
|
92
124
|
// Importer may be a file URL string or an absolute path.
|