Skip to content

Commit 72c8541

Browse files
committed
fix(plugin): generate correct keys in q-manifest.json
the keys are the paths to the js bundles, and using hard-coded names like for entries gave the old names.
1 parent 3da8b3c commit 72c8541

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

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

+35-5
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,17 @@ export function generateManifestFromBundles(
257257
},
258258
};
259259

260+
const buildPath = path.resolve(opts.rootDir, opts.outDir, 'build');
260261
// We need to find our QRL exports
261262
const qrlNames = new Set([...hooks.map((h) => h.name)]);
262-
for (const [fileName, outputBundle] of Object.entries(outputBundles)) {
263+
for (const outputBundle of Object.values(outputBundles)) {
263264
if (outputBundle.type !== 'chunk') {
264265
continue;
265266
}
266-
const bundleFileName = path.basename(fileName);
267+
const bundleFileName = path.relative(
268+
buildPath,
269+
path.resolve(opts.outDir, outputBundle.fileName)
270+
);
267271

268272
const buildDirName = path.dirname(outputBundle.fileName);
269273
const bundle: QwikBundle = {
@@ -282,21 +286,23 @@ export function generateManifestFromBundles(
282286

283287
const bundleImports = outputBundle.imports
284288
.filter((i) => path.dirname(i) === buildDirName)
285-
.map((i) => path.relative(buildDirName, i));
289+
.map((i) => path.relative(buildDirName, outputBundles[i].fileName));
286290
if (bundleImports.length > 0) {
287291
bundle.imports = bundleImports;
288292
}
289293

290294
const bundleDynamicImports = outputBundle.dynamicImports
291295
.filter((i) => path.dirname(i) === buildDirName)
292-
.map((i) => path.relative(buildDirName, i));
296+
.map((i) => path.relative(buildDirName, outputBundles[i].fileName));
293297
if (bundleDynamicImports.length > 0) {
294298
bundle.dynamicImports = bundleDynamicImports;
295299
}
296300

297301
// Rollup doesn't provide the moduleIds in the outputBundle but Vite does
298302
const ids = outputBundle.moduleIds || Object.keys(outputBundle.modules);
299-
const modulePaths = ids.filter((m) => !m.startsWith(`\u0000`));
303+
const modulePaths = ids
304+
.filter((m) => !m.startsWith(`\u0000`))
305+
.map((m) => path.relative(opts.rootDir, m));
300306
if (modulePaths.length > 0) {
301307
bundle.origins = modulePaths;
302308
}
@@ -324,6 +330,30 @@ export function generateManifestFromBundles(
324330
loc: hook.loc,
325331
};
326332
}
333+
// To inspect the bundles, uncomment the following lines
334+
// and temporarily add the writeFileSync import from fs
335+
// writeFileSync(
336+
// 'output-bundles.json',
337+
// JSON.stringify(
338+
// Object.entries(outputBundles).map(([n, b]) => [
339+
// n,
340+
// {
341+
// ...b,
342+
// code: '<removed>',
343+
// map: '<removed>',
344+
// source: '<removed>',
345+
// modules:
346+
// 'modules' in b
347+
// ? Object.fromEntries(
348+
// Object.entries(b.modules).map(([k, v]) => [k, { ...v, code: '<removed>' }])
349+
// )
350+
// : undefined,
351+
// },
352+
// ]),
353+
// null,
354+
// '\t'
355+
// )
356+
// );
327357

328358
return updateSortAndPriorities(manifest);
329359
}

0 commit comments

Comments
 (0)