Skip to content

Commit 8a8a419

Browse files
committed
feat: add assets to q-manifest
this allows knowing all the needed files for offline apps
1 parent dd220fc commit 8a8a419

File tree

8 files changed

+138
-9
lines changed

8 files changed

+138
-9
lines changed

.changeset/real-cities-fold.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@builder.io/qwik': patch
3+
---
4+
5+
FEAT: q-manifest.json now also includes the generated assets

packages/docs/src/routes/api/qwik-optimizer/api.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,20 @@
385385
"content": "",
386386
"mdFile": "qwik.experimentalfeatures.preventnavigate.md"
387387
},
388+
{
389+
"name": "QwikAsset",
390+
"id": "qwikasset",
391+
"hierarchy": [
392+
{
393+
"name": "QwikAsset",
394+
"id": "qwikasset"
395+
}
396+
],
397+
"kind": "Interface",
398+
"content": "```typescript\nexport interface QwikAsset \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\n[name](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring \\| undefined\n\n\n</td><td>\n\nName of the asset\n\n\n</td></tr>\n<tr><td>\n\n[size](#)\n\n\n</td><td>\n\n\n</td><td>\n\nnumber\n\n\n</td><td>\n\nSize of the asset\n\n\n</td></tr>\n</tbody></table>",
399+
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/optimizer/src/types.ts",
400+
"mdFile": "qwik.qwikasset.md"
401+
},
388402
{
389403
"name": "QwikBuildMode",
390404
"id": "qwikbuildmode",
@@ -451,7 +465,7 @@
451465
}
452466
],
453467
"kind": "Interface",
454-
"content": "The metadata of the build. One of its uses is storing where QRL symbols are located.\n\n\n```typescript\nexport interface QwikManifest \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\n[bundleGraph?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[QwikBundleGraph](#qwikbundlegraph)\n\n\n</td><td>\n\n_(Optional)_ All bundles in a compact graph format with probabilities\n\n\n</td></tr>\n<tr><td>\n\n[bundleGraphPath?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n_(Optional)_ The bundle graph fileName\n\n\n</td></tr>\n<tr><td>\n\n[bundles](#)\n\n\n</td><td>\n\n\n</td><td>\n\n{ \\[fileName: string\\]: [QwikBundle](#qwikbundle)<!-- -->; }\n\n\n</td><td>\n\nAll code bundles, used to know the import graph\n\n\n</td></tr>\n<tr><td>\n\n[core?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n_(Optional)_ The Qwik core bundle fileName\n\n\n</td></tr>\n<tr><td>\n\n[injections?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[GlobalInjections](#globalinjections)<!-- -->\\[\\]\n\n\n</td><td>\n\n_(Optional)_ CSS etc to inject in the document head\n\n\n</td></tr>\n<tr><td>\n\n[manifestHash](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\nContent hash of the manifest, if this changes, the code changed\n\n\n</td></tr>\n<tr><td>\n\n[mapping](#)\n\n\n</td><td>\n\n\n</td><td>\n\n{ \\[symbolName: string\\]: string; }\n\n\n</td><td>\n\nWhere QRLs are located\n\n\n</td></tr>\n<tr><td>\n\n[options?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n{ target?: string; buildMode?: string; entryStrategy?: { type: [EntryStrategy](#entrystrategy)<!-- -->\\['type'\\]; }; }\n\n\n</td><td>\n\n_(Optional)_ The options used to build the manifest\n\n\n</td></tr>\n<tr><td>\n\n[platform?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n{ \\[name: string\\]: string; }\n\n\n</td><td>\n\n_(Optional)_ The platform used to build the manifest\n\n\n</td></tr>\n<tr><td>\n\n[preloader?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n_(Optional)_ The preloader bundle fileName\n\n\n</td></tr>\n<tr><td>\n\n[symbols](#)\n\n\n</td><td>\n\n\n</td><td>\n\n{ \\[symbolName: string\\]: [QwikSymbol](#qwiksymbol)<!-- -->; }\n\n\n</td><td>\n\nQRL symbols\n\n\n</td></tr>\n<tr><td>\n\n[version](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\nThe version of the manifest\n\n\n</td></tr>\n</tbody></table>",
468+
"content": "The metadata of the build. One of its uses is storing where QRL symbols are located.\n\n\n```typescript\nexport interface QwikManifest \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\n[assets?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n{ \\[fileName: string\\]: [QwikAsset](#qwikasset)<!-- -->; }\n\n\n</td><td>\n\n_(Optional)_ All assets\n\n\n</td></tr>\n<tr><td>\n\n[bundleGraph?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[QwikBundleGraph](#qwikbundlegraph)\n\n\n</td><td>\n\n_(Optional)_ All bundles in a compact graph format with probabilities\n\n\n</td></tr>\n<tr><td>\n\n[bundleGraphPath?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n_(Optional)_ The bundle graph fileName\n\n\n</td></tr>\n<tr><td>\n\n[bundles](#)\n\n\n</td><td>\n\n\n</td><td>\n\n{ \\[fileName: string\\]: [QwikBundle](#qwikbundle)<!-- -->; }\n\n\n</td><td>\n\nAll code bundles, used to know the import graph\n\n\n</td></tr>\n<tr><td>\n\n[core?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n_(Optional)_ The Qwik core bundle fileName\n\n\n</td></tr>\n<tr><td>\n\n[injections?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[GlobalInjections](#globalinjections)<!-- -->\\[\\]\n\n\n</td><td>\n\n_(Optional)_ CSS etc to inject in the document head\n\n\n</td></tr>\n<tr><td>\n\n[manifestHash](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\nContent hash of the manifest, if this changes, the code changed\n\n\n</td></tr>\n<tr><td>\n\n[mapping](#)\n\n\n</td><td>\n\n\n</td><td>\n\n{ \\[symbolName: string\\]: string; }\n\n\n</td><td>\n\nWhere QRLs are located\n\n\n</td></tr>\n<tr><td>\n\n[options?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n{ target?: string; buildMode?: string; entryStrategy?: { type: [EntryStrategy](#entrystrategy)<!-- -->\\['type'\\]; }; }\n\n\n</td><td>\n\n_(Optional)_ The options used to build the manifest\n\n\n</td></tr>\n<tr><td>\n\n[platform?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n{ \\[name: string\\]: string; }\n\n\n</td><td>\n\n_(Optional)_ The platform used to build the manifest\n\n\n</td></tr>\n<tr><td>\n\n[preloader?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n_(Optional)_ The preloader bundle fileName\n\n\n</td></tr>\n<tr><td>\n\n[symbols](#)\n\n\n</td><td>\n\n\n</td><td>\n\n{ \\[symbolName: string\\]: [QwikSymbol](#qwiksymbol)<!-- -->; }\n\n\n</td><td>\n\nQRL symbols\n\n\n</td></tr>\n<tr><td>\n\n[version](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\nThe version of the manifest\n\n\n</td></tr>\n</tbody></table>",
455469
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/optimizer/src/types.ts",
456470
"mdFile": "qwik.qwikmanifest.md"
457471
},

packages/docs/src/routes/api/qwik-optimizer/index.mdx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,63 @@ Description
12311231

12321232
## preventNavigate
12331233

1234+
## QwikAsset
1235+
1236+
```typescript
1237+
export interface QwikAsset
1238+
```
1239+
1240+
<table><thead><tr><th>
1241+
1242+
Property
1243+
1244+
</th><th>
1245+
1246+
Modifiers
1247+
1248+
</th><th>
1249+
1250+
Type
1251+
1252+
</th><th>
1253+
1254+
Description
1255+
1256+
</th></tr></thead>
1257+
<tbody><tr><td>
1258+
1259+
[name](#)
1260+
1261+
</td><td>
1262+
1263+
</td><td>
1264+
1265+
string \| undefined
1266+
1267+
</td><td>
1268+
1269+
Name of the asset
1270+
1271+
</td></tr>
1272+
<tr><td>
1273+
1274+
[size](#)
1275+
1276+
</td><td>
1277+
1278+
</td><td>
1279+
1280+
number
1281+
1282+
</td><td>
1283+
1284+
Size of the asset
1285+
1286+
</td></tr>
1287+
</tbody></table>
1288+
1289+
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/optimizer/src/types.ts)
1290+
12341291
## QwikBuildMode
12351292

12361293
```typescript
@@ -1418,6 +1475,21 @@ Description
14181475
</th></tr></thead>
14191476
<tbody><tr><td>
14201477

1478+
[assets?](#)
1479+
1480+
</td><td>
1481+
1482+
</td><td>
1483+
1484+
\{ [fileName: string]: [QwikAsset](#qwikasset); }
1485+
1486+
</td><td>
1487+
1488+
_(Optional)_ All assets
1489+
1490+
</td></tr>
1491+
<tr><td>
1492+
14211493
[bundleGraph?](#)
14221494

14231495
</td><td>

packages/qwik/src/optimizer/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type {
1515
OptimizerOptions,
1616
OptimizerSystem,
1717
Path,
18+
QwikAsset,
1819
QwikBundle,
1920
QwikBundleGraph,
2021
QwikManifest,

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,19 +397,25 @@ export function generateManifestFromBundles(
397397
debug: (...args: any[]) => void,
398398
canonPath: (p: string) => string
399399
) {
400+
// Note that this will be the order of the JSON file
400401
const manifest: QwikManifest = {
401-
manifestHash: '',
402-
symbols: {},
403-
mapping: {},
404-
bundles: {},
405-
injections,
406402
version: '1',
403+
manifestHash: '',
407404
options: {
408405
target: opts.target,
409406
buildMode: opts.buildMode,
410407
// don't copy the insights stuff
411408
entryStrategy: opts.entryStrategy && { type: opts.entryStrategy.type },
412409
},
410+
core: undefined,
411+
preloader: undefined,
412+
bundleGraphPath: undefined,
413+
injections,
414+
mapping: {},
415+
bundles: {},
416+
assets: {},
417+
symbols: {},
418+
bundleGraph: undefined,
413419
};
414420

415421
const getBundleName = (name: string) => {
@@ -424,7 +430,14 @@ export function generateManifestFromBundles(
424430
// We need to find our QRL exports
425431
const qrlNames = new Set(segments.map((h) => h.name));
426432
for (const outputBundle of Object.values(outputBundles)) {
427-
if (outputBundle.type !== 'chunk') {
433+
if (outputBundle.type === 'asset') {
434+
// we don't record map files as assets
435+
if (!outputBundle.fileName.endsWith('js.map')) {
436+
manifest.assets![outputBundle.fileName] = {
437+
name: outputBundle.names[0],
438+
size: outputBundle.source.length,
439+
};
440+
}
428441
continue;
429442
}
430443
const bundleFileName = canonPath(outputBundle.fileName);
@@ -488,14 +501,14 @@ export function generateManifestFromBundles(
488501
}
489502
(manifest.bundles[bundle].symbols ||= []).push(symbol);
490503
manifest.symbols[symbol] = {
491-
origin: segment.origin,
492504
displayName: segment.displayName,
493-
canonicalFilename: segment.canonicalFilename,
494505
hash: segment.hash,
495506
ctxKind: segment.ctxKind,
496507
ctxName: segment.ctxName,
497508
captures: segment.captures,
509+
canonicalFilename: segment.canonicalFilename,
498510
parent: segment.parent,
511+
origin: segment.origin,
499512
loc: segment.loc,
500513
};
501514
}

packages/qwik/src/optimizer/src/plugins/plugin.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,11 @@ export const manifest = ${JSON.stringify(serverManifest)};\n`;
970970
});
971971
manifest.bundleGraphPath = outputAnalyzer.canonPath(ctx.getFileName(bgAsset));
972972
manifest.bundleGraph = bundleGraph;
973+
// we already generated the assets list so we need to update it
974+
manifest.assets![manifest.bundleGraphPath] = {
975+
name: 'bundle-graph.json',
976+
size: bundleGraph.length,
977+
};
973978

974979
const manifestStr = JSON.stringify(manifest, null, '\t');
975980
ctx.emitFile({

packages/qwik/src/optimizer/src/qwik.optimizer.api.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ export interface Path {
160160
readonly win32: null;
161161
}
162162

163+
// @public (undocumented)
164+
export interface QwikAsset {
165+
name: string | undefined;
166+
size: number;
167+
}
168+
163169
// @public (undocumented)
164170
export type QwikBuildMode = 'production' | 'development';
165171

@@ -182,6 +188,9 @@ export type QwikBundleGraph = Array<string | number>;
182188

183189
// @public
184190
export interface QwikManifest {
191+
assets?: {
192+
[fileName: string]: QwikAsset;
193+
};
185194
bundleGraph?: QwikBundleGraph;
186195
bundleGraphPath?: string;
187196
bundles: {

packages/qwik/src/optimizer/src/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ export interface QwikManifest {
223223
mapping: { [symbolName: string]: string };
224224
/** All code bundles, used to know the import graph */
225225
bundles: { [fileName: string]: QwikBundle };
226+
/** All assets */
227+
assets?: { [fileName: string]: QwikAsset };
226228
/** All bundles in a compact graph format with probabilities */
227229
bundleGraph?: QwikBundleGraph;
228230
/** The bundle graph fileName */
@@ -311,6 +313,14 @@ export interface QwikBundle {
311313
origins?: string[];
312314
}
313315

316+
/** @public */
317+
export interface QwikAsset {
318+
/** Name of the asset */
319+
name: string | undefined;
320+
/** Size of the asset */
321+
size: number;
322+
}
323+
314324
/** @public */
315325
export interface GlobalInjections {
316326
tag: string;

0 commit comments

Comments
 (0)