Skip to content

Commit f49c6c8

Browse files
1 parent 2d34bed commit f49c6c8

1 file changed

Lines changed: 55 additions & 22 deletions

File tree

astro.config.ts

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,38 +1293,71 @@ export default defineConfig({
12931293
plugins: [
12941294
(await import("vite-plugin-top-level-await")).default(),
12951295

1296-
// Stub `Source/Workbench/Bundled/<Variant>/Entry.ts` for every
1297-
// variant NOT in the active `Pack` env var.
1296+
// Short-circuit Rollup's walk into Bundled/<Variant> module
1297+
// graphs the active `Pack` does not select.
12981298
//
1299-
// Astro auto-discovers `pages/Bundled/<Variant>.astro` as page
1300-
// routes; each page's component graph references the matching
1301-
// `Workbench/Bundled/<Variant>/Layout.astro`, whose `<script>` block
1302-
// statically `await import("./Entry.js")`s. Rollup follows
1303-
// `await import(<literal>)` to build a separate chunk
1304-
// regardless of any surrounding runtime conditional, so even
1305-
// pages we never render still pull every variant's Entry into
1299+
// Each `Workbench/Bundled/<Variant>/Layout.astro` carries a
1300+
// `<script>` block whose static `await import("./Entry.js")`
1301+
// pulls a VS Code workbench entry from `@codeeditorland/output`.
1302+
// Rollup follows literal-string `await import()` to build a
1303+
// chunk regardless of any surrounding runtime conditional, so
1304+
// even pages we never render pull every variant's Entry into
13061305
// the module graph - at which point the Browser variant's
13071306
// `vs/code/browser/workbench/workbench.js` walks into the
13081307
// gulp-only `workbench.web.main.internal.js`, the Electron
1309-
// variant's `workbench.js` walks into `workbench.desktop.main.js`,
1310-
// and Output's release `out-build/` tree (mangled,
1311-
// telemetry-stripped) cannot satisfy the unmangled gulp-only
1312-
// imports.
1308+
// variant's `workbench.js` walks into `workbench.desktop.main.js`
1309+
// (whose StaticToDynamicImport-rewritten body is then 3000+
1310+
// literal-string `await import()`s into excluded paths), and
1311+
// Output's release `out-build/` tree (mangled, telemetry-
1312+
// stripped) cannot satisfy the unmangled gulp-only imports.
13131313
//
1314-
// Replacing inactive Entry modules with an empty stub at
1315-
// `load()` time short-circuits the walk entirely - Rollup sees
1316-
// `export default {};`, has nothing to follow, and emits a
1317-
// trivial chunk for the inactive route. The active variant's
1318-
// real Entry is left untouched and bundled normally through
1319-
// `BundledInputs`. `enforce: "pre"` runs the stub before any
1320-
// other plugin parses the file, so transform plugins targeting
1321-
// `vs/**` never get a chance to walk into it.
1314+
// `resolveId` rewrites the inactive Layout's `./Entry.js`
1315+
// import to a virtual module that `load` answers with an empty
1316+
// `export default {};`. Rollup never opens the real Entry.ts,
1317+
// has nothing to follow, and emits a trivial chunk for the
1318+
// inactive route. The active variant's real Entry is left
1319+
// untouched and bundled normally through `BundledInputs`.
1320+
// Operating at `resolveId` (with `enforce: "pre"`) guarantees
1321+
// every downstream plugin - Astro's TS loader, OXC mangler,
1322+
// Output transforms - sees the virtual ID instead of the on-
1323+
// disk file, regardless of which Vite phase (SSR / client)
1324+
// is processing the page.
13221325
{
13231326
name: "BundledEntryStubInactive",
13241327
enforce: "pre",
1328+
resolveId(Source: string, Importer: string | undefined) {
1329+
if (!Importer) return null;
1330+
if (
1331+
!Source.endsWith("/Entry.js") &&
1332+
!Source.endsWith("/Entry.ts") &&
1333+
Source !== "./Entry.js" &&
1334+
Source !== "./Entry.ts"
1335+
) {
1336+
return null;
1337+
}
1338+
const ImporterNormalised = Importer.replace(/\\/g, "/");
1339+
const Match = ImporterNormalised.match(
1340+
/\/Workbench\/Bundled\/(\w+)\/Layout\.astro/,
1341+
);
1342+
if (!Match) return null;
1343+
if (BundledList.includes(Match[1]!.toLowerCase())) {
1344+
return null;
1345+
}
1346+
return `\0BundledEntryStub:${Match[1]!.toLowerCase()}`;
1347+
},
13251348
load(Identifier: string) {
1349+
if (Identifier.startsWith("\0BundledEntryStub:")) {
1350+
return "export default {};";
1351+
}
1352+
// Belt-and-suspenders: if Astro/Vite somehow resolves the
1353+
// real Entry.ts path before our `resolveId` runs (e.g.,
1354+
// through the page input map for a future profile, or a
1355+
// hoisted-script virtual ID we did not anticipate), still
1356+
// stub the file when its variant is inactive. The default
1357+
// `resolveId` chain produces an absolute on-disk path so
1358+
// the regex matches with or without a leading slash.
13261359
const Match = Identifier.replace(/\\/g, "/").match(
1327-
/\/Source\/Workbench\/Bundled\/(\w+)\/Entry\.(?:ts|js)$/,
1360+
/(?:^|\/)Source\/Workbench\/Bundled\/(\w+)\/Entry\.(?:ts|js)$/,
13281361
);
13291362
if (!Match) return null;
13301363
if (BundledList.includes(Match[1]!.toLowerCase())) {

0 commit comments

Comments
 (0)