mirror of
https://github.com/discourse/discourse.git
synced 2026-08-08 17:53:55 +08:00
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.
|
||
|---|---|---|
| .. | ||
| assets | ||
| controllers | ||
| helpers | ||
| jobs | ||
| mailers | ||
| models | ||
| queries/reports | ||
| serializers | ||
| services | ||
| views | ||