0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-09 21:45:25 +08:00
discourse/frontend/asset-processor
David Taylor de4c1da901 DEV: Let cross-plugin imports opt into being required via with { discoursePlugin: "required" }
Cross-plugin imports (`discourse/plugins/<name>/...`) resolve to `null` when the target plugin isn't installed. That's the right default for soft dependencies, but it silently hides genuine hard dependencies. This adds a `discoursePlugin` import attribute so a bundle can opt a specific import into being required: `import X from "discourse/plugins/<name>/..." with { discoursePlugin: "required" }`. Omitting the attribute (or passing `discoursePlugin: "optional"`) keeps the existing optional behaviour.

`discourse-external-loader` inspects the attribute in `resolveId` and, for everything except `discoursePlugin: "required"`, tags the external id with an `?optional` marker, so the optionality travels through rollup's module graph (and therefore `chunk.imports`) without a side channel. `babel-resolve-plugin-imports` reads the marker back off the import source and consolidates each plugin import to `discourse/plugins/<name>?` (optional) or `discourse/plugins/<name>` (required), keeping the existing live-binding use-site rewrite that the cross-plugin import loops rely on.

The import map then resolves both specifiers. For a loaded plugin, `discourse/plugins/<name>?` is aliased to the plugin's real module (the required `discourse/plugins/<name>` already maps to it). For a missing plugin, `discourse/plugins/<name>?` points at a null-returning stub, and `discourse/plugins/<name>` points at a module that declares a default export (so the importer still links) and then throws on evaluation with a helpful message, surfacing the missing hard dependency at boot instead of a cryptic module-resolution error. Generation is pinned to `importAttributesKey: "with"` so rollup emits modern import-attribute syntax.

Spike scope: because optional is the default, the cross-plugin call sites the parent commit converted keep working unchanged, and only genuine hard dependencies need the new attribute. Ruby specs for the import-map behaviour and a full mini_racer build verification are still outstanding.
2026-06-23 10:44:16 +00:00
..
rollup-plugins DEV: Let cross-plugin imports opt into being required via with { discoursePlugin: "required" } 2026-06-23 10:44:16 +00:00
add-theme-globals.js
add-theme-globals.test.mjs
babel-resolve-core-imports.js DEV: Improve cross-plugin/theme import handling 2026-06-16 23:51:05 +01:00
babel-resolve-core-imports.test.mjs DEV: Improve cross-plugin/theme import handling 2026-06-16 23:51:05 +01:00
babel-resolve-plugin-imports.js DEV: Let cross-plugin imports opt into being required via with { discoursePlugin: "required" } 2026-06-23 10:44:16 +00:00
babel-resolve-plugin-imports.test.mjs DEV: Let cross-plugin imports opt into being required via with { discoursePlugin: "required" } 2026-06-23 10:44:16 +00:00
build.mjs DEV: Replace esbuild with rolldown for asset-processor build (#40447) 2026-06-01 14:49:16 +01:00
content-tag.js
noop.js
os-shim.js DEV: Bump babel plugin in asset-processor and stub workerpool (#40438) 2026-06-01 10:54:43 +01:00
package.json DEPS: Bump @rollup/browser from 4.61.0 to 4.61.1 (#40812) 2026-06-16 10:28:46 +02:00
postcss-variable-prefixer.js
postcss.js Revert "FEATURE: discourse-workflows (#39704)" (#40366) 2026-05-28 13:59:42 +01:00
rollup-virtual-imports.js DEV: Improve cross-plugin/theme import handling 2026-06-16 23:51:05 +01:00
shims.js
theme-hbs-ast-transforms.js
theme-rollup.js DEV: Let cross-plugin imports opt into being required via with { discoursePlugin: "required" } 2026-06-23 10:44:16 +00:00
transform-action-syntax.js DEV: Remove (again) the old non-rollup plugin compiler (#39419) 2026-04-21 21:07:46 +02:00
transpiler.js
url-polyfill.js
virtual-fs.js DEV: Replace memfs with a in-repo fs helper (#39571) 2026-04-27 11:00:54 +02:00
workerpool-shim.js DEV: Bump babel plugin in asset-processor and stub workerpool (#40438) 2026-06-01 10:54:43 +01:00