Skip to content

Commit 6c7a4e1

Browse files
committed
fix(core plugin): better manifest regexes
1 parent 9a010fe commit 6c7a4e1

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

packages/docs/src/repl/bundler/rollup-plugins.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ export const replResolver = (
3535
return srcInputs.find((i) => i.path === id)?.path;
3636
};
3737

38-
const getQwik = (id: string, external?: true) => {
38+
const resolveQwik = (id: string, external?: true) => {
3939
const path = deps[QWIK_PKG_NAME_V1][id];
4040
if (!path) {
4141
throw new Error(`Unknown Qwik path: ${id}`);
4242
}
4343
return {
44-
id: `\0@qwik${id}`,
44+
// Make sure this matches the regexes in manifest.ts
45+
id: `/node_modules/@qwik.dev/core${id}`,
4546
sideEffects: false,
4647
// It would be nice to load qwik as external, but
4748
// we import core and core/build so we need processing
@@ -58,30 +59,30 @@ export const replResolver = (
5859
if (id.startsWith('http')) {
5960
return { id, external: true };
6061
}
61-
if (id.startsWith('\0@qwik/')) {
62+
if (id.startsWith('/node_modules/@qwik.dev/core/')) {
6263
return id;
6364
}
6465
const match = id.match(/(@builder\.io\/qwik|@qwik\.dev\/core)(.*)/);
6566
if (match) {
6667
const pkgName = match[2];
6768

6869
if (pkgName === '/build') {
69-
return `\0@qwik/build`;
70+
return `/node_modules/@qwik.dev/core/build`;
7071
}
7172
if (!pkgName || pkgName === '/jsx-runtime' || pkgName === '/jsx-dev-runtime') {
72-
return getQwik('/dist/core.mjs');
73+
return resolveQwik('/dist/core.mjs');
7374
}
7475
if (pkgName === '/server') {
75-
return getQwik('/dist/server.mjs');
76+
return resolveQwik('/dist/server.mjs');
7677
}
7778
if (pkgName.includes('/preloader')) {
78-
return getQwik('/dist/preloader.mjs');
79+
return resolveQwik('/dist/preloader.mjs');
7980
}
8081
if (pkgName.includes('/qwikloader')) {
81-
return getQwik('/dist/qwikloader.js');
82+
return resolveQwik('/dist/qwikloader.js');
8283
}
8384
if (pkgName.includes('/handlers')) {
84-
return getQwik('/handlers.mjs');
85+
return resolveQwik('/handlers.mjs');
8586
}
8687
}
8788
// Simple relative file resolution
@@ -107,8 +108,8 @@ export const replResolver = (
107108
if (input && typeof input.code === 'string') {
108109
return input.code;
109110
}
110-
if (id.startsWith('\0@qwik/')) {
111-
const path = id.slice('\0@qwik'.length);
111+
if (id.startsWith('/node_modules/@qwik.dev/core/')) {
112+
const path = id.slice('/node_modules/@qwik.dev/core'.length);
112113
if (path === '/build') {
113114
// Virtual module for Qwik build
114115
const isDev = options.buildMode === 'development';

packages/qwik/src/optimizer/src/manifest.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,14 @@ export function computeTotals(graph: QwikManifest['bundles']): void {
392392
}
393393
}
394394

395-
const preloaderRegex = /[/\\](core|qwik)[/\\]dist[/\\]preloader\.[cm]js$/;
396-
const coreRegex = /[/\\](core|qwik)[/\\]dist[/\\]core(\.min|\.prod)?\.[cm]js$/;
395+
const preloaderRegex = /[/\\](core|qwik)[/\\]dist[/\\]preloader\.(|c|m)js$/;
396+
const coreRegex = /[/\\](core|qwik)[/\\]dist[/\\]core(\.min|\.prod)?\.(|c|m)js$/;
397397
const qwikLoaderRegex = /[/\\](core|qwik)[/\\](dist[/\\])?qwikloader(\.debug)?\.[^/]*js$/;
398-
const handlersRegex = /[/\\](core|qwik)[/\\]handlers\.[cm]js$/;
398+
const handlersRegex = /[/\\](core|qwik)[/\\]handlers\.(|c|m)js$/;
399+
/**
400+
* Generates the Qwik build manifest from the Rollup output bundles. It also figures out the bundle
401+
* files for the preloader, core, qwikloader and handlers. This information is used during SSR.
402+
*/
399403
export function generateManifestFromBundles(
400404
path: Path,
401405
segments: SegmentAnalysis[],
@@ -492,6 +496,8 @@ export function generateManifestFromBundles(
492496
manifest.core = bundleFileName;
493497
} else if (qwikLoaderRegex.test(outputBundle.facadeModuleId)) {
494498
manifest.qwikLoader = bundleFileName;
499+
} else if (handlersRegex.test(outputBundle.facadeModuleId)) {
500+
qwikHandlersName = bundleFileName;
495501
}
496502
}
497503
// Rollup doesn't provide the moduleIds in the outputBundle but Vite does

0 commit comments

Comments
 (0)