You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AB6005: also refuse bare createRequire/require/import.meta.resolve loads in compiled modules #591
Follow-up from the #588 self-review (reviewer finding 1, dismissed for that PR as out of scope).
AB6005 (packages/agent-bundle/src/build/validate-artifact-modules.ts, module-imports.ts) walks the ES-module import graph: static imports, literal dynamic import(), and import.meta. It does not read require("pkg"), createRequire(import.meta.url)("pkg") (or a bound loader), require.resolve, or import.meta.resolve("pkg") with a bare non-built-in specifier. Rspack leaves those calls in the emitted bundle, so a compiled module — in a host pack or, since #588, in the package build's dist — can still load a package from the consumer's node_modules through one of them without an AB6005 finding. The prepack gate (pack-dependencies.ts) already reads exactly those forms as AB7014 evidence, so the two gates agree today (such a package must be declared under dependencies), but the artifact is not fully self-contained in the sense the "Generated plugin output" rule intends.
Confirmed on #588's tree: es-module-lexer reports only node:module and import.meta for const load = createRequire(import.meta.url); load("left-pad") and for import.meta.resolve("right-pad").
Proposed: teach the AB6005 walk the same literal require / createRequire / import.meta.resolve semantics pack-dependencies.ts already implements (move the scanner to a leaf module both import — config/conventional-entry.ts pattern — do not copy it), applied to compiled modules only (prebuilt payloads stay opaque), with a relative target resolved inside the tree and a bare non-built-in reported as AB6005. This changes host-pack validation too, so it needs its own decision and changeset (pre-1.0 minor), fixtures for literal and computed require, createRequire (direct and bound, aliased), and import.meta.resolve, and a check that no generated code (cli-bins.ts, entry-shell.ts, install bins) uses these forms for a bare package today.
Docs to update with it: AGENTS.md "Generated plugin output", docs/diagnostics.md (AB60xx, AB7014 evidence paragraph), website/docs/{en,zh}/guide/distribution/validation.mdx, the AB7014 recovery string in pack-inventory.ts.
One more concrete route through the gap, noted while narrowing #588's prose: a tools.rspack hatch with externalsType: 'node-commonjs' (or 'commonjs' on a CJS-shaped surface) makes Rspack emit an external as createRequire(import.meta.url)("pkg") rather than an import, so an externalized dependency then passes AB6005 in both a host pack and dist. The fix proposed above closes this too, since it reads the call form regardless of who wrote it.
Architecture alignment with #592: extend the existing common self-containment scanner as proposed; do not create a second scanner for package output. The long-term home of this policy is common Artifact IR validation applied uniformly to all compiled executable surfaces. The proposed shared leaf scanner with pack-dependencies.ts is consistent with that direction.
Superseded by #619: self-containment is proven from the Rspack module graph / external report and the Artifact IR, and the generated-JS load scanners (this issue's proposal and #602's implementation) are deleted rather than extended. Owner decision, 2026-09-05.
Activity
docs: AB6005 walks import specifiers; require/createRequire/import.me…
ScriptedAlchemy commentedon Sep 5, 2026
One more concrete route through the gap, noted while narrowing #588's prose: a
tools.rspackhatch withexternalsType: 'node-commonjs'(or'commonjs'on a CJS-shaped surface) makes Rspack emit an external ascreateRequire(import.meta.url)("pkg")rather than animport, so an externalized dependency then passesAB6005in both a host pack anddist. The fix proposed above closes this too, since it reads the call form regardless of who wrote it.ScriptedAlchemy commentedon Sep 5, 2026
Architecture alignment with #592: extend the existing common self-containment scanner as proposed; do not create a second scanner for package output. The long-term home of this policy is common Artifact IR validation applied uniformly to all compiled executable surfaces. The proposed shared leaf scanner with
pack-dependencies.tsis consistent with that direction.feat(build): hold the package build's dist bundles to AB6005 (#588)
ScriptedAlchemy commentedon Sep 5, 2026
Superseded by #619: self-containment is proven from the Rspack module graph / external report and the Artifact IR, and the generated-JS load scanners (this issue's proposal and #602's implementation) are deleted rather than extended. Owner decision, 2026-09-05.