@quilted/rollup 0.1.14 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/build/cjs/app.cjs +5 -8
- package/build/cjs/features/assets.cjs +112 -2
- package/build/cjs/features/source-code.cjs +3 -2
- package/build/cjs/features/system-js.cjs +2 -1
- package/build/cjs/package.cjs +20 -2
- package/build/esm/app.mjs +5 -8
- package/build/esm/features/assets.mjs +112 -4
- package/build/esm/features/source-code.mjs +1 -1
- package/build/esm/package.mjs +20 -2
- package/build/esnext/app.esnext +5 -8
- package/build/esnext/features/assets.esnext +112 -4
- package/build/esnext/features/source-code.esnext +1 -1
- package/build/esnext/package.esnext +20 -2
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts.map +1 -1
- package/build/typescript/features/assets.d.ts +10 -2
- package/build/typescript/features/assets.d.ts.map +1 -1
- package/build/typescript/package.d.ts +8 -2
- package/build/typescript/package.d.ts.map +1 -1
- package/package.json +18 -5
- package/source/app.ts +3 -6
- package/source/features/assets.ts +152 -4
- package/source/features/source-code.ts +1 -1
- package/source/package.ts +19 -0
|
@@ -1,8 +1,116 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
|
-
import
|
|
2
|
+
import * as fs from 'node:fs/promises';
|
|
3
3
|
import { createHash } from 'node:crypto';
|
|
4
4
|
import * as mime from 'mrmime';
|
|
5
5
|
|
|
6
|
+
function assetManifest(manifestOptions) {
|
|
7
|
+
return {
|
|
8
|
+
name: '@quilted/asset-manifest',
|
|
9
|
+
async generateBundle(options, bundle) {
|
|
10
|
+
await writeManifestForBundle.call(this, bundle, manifestOptions, options);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
async function writeManifestForBundle(bundle, {
|
|
15
|
+
id,
|
|
16
|
+
file,
|
|
17
|
+
baseURL,
|
|
18
|
+
cacheKey,
|
|
19
|
+
priority
|
|
20
|
+
}, {
|
|
21
|
+
format
|
|
22
|
+
}) {
|
|
23
|
+
const outputs = Object.values(bundle);
|
|
24
|
+
const entries = outputs.filter(output => output.type === 'chunk' && output.isEntry);
|
|
25
|
+
if (entries.length === 0) {
|
|
26
|
+
throw new Error(`Could not find any entries in your rollup bundle...`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// We assume the first entry is the "main" one. There can be
|
|
30
|
+
// more than one because each worker script is also listed as an
|
|
31
|
+
// entry (though, from a separate build).
|
|
32
|
+
const entryChunk = entries[0];
|
|
33
|
+
const dependencyMap = new Map();
|
|
34
|
+
for (const output of outputs) {
|
|
35
|
+
if (output.type !== 'chunk') continue;
|
|
36
|
+
dependencyMap.set(output.fileName, output.imports);
|
|
37
|
+
}
|
|
38
|
+
const assets = [];
|
|
39
|
+
const assetIdMap = new Map();
|
|
40
|
+
function getAssetId(file) {
|
|
41
|
+
let id = assetIdMap.get(file);
|
|
42
|
+
if (id == null) {
|
|
43
|
+
assets.push(`${baseURL}${file}`);
|
|
44
|
+
id = assets.length - 1;
|
|
45
|
+
assetIdMap.set(file, id);
|
|
46
|
+
}
|
|
47
|
+
return id;
|
|
48
|
+
}
|
|
49
|
+
const manifest = {
|
|
50
|
+
id,
|
|
51
|
+
priority,
|
|
52
|
+
cacheKey,
|
|
53
|
+
assets,
|
|
54
|
+
attributes: format === 'es' ? {
|
|
55
|
+
scripts: {
|
|
56
|
+
type: 'module'
|
|
57
|
+
}
|
|
58
|
+
} : undefined,
|
|
59
|
+
entries: {
|
|
60
|
+
default: createAssetsEntry([...entryChunk.imports, entryChunk.fileName], {
|
|
61
|
+
dependencyMap,
|
|
62
|
+
getAssetId
|
|
63
|
+
})
|
|
64
|
+
},
|
|
65
|
+
modules: {}
|
|
66
|
+
};
|
|
67
|
+
for (const output of outputs) {
|
|
68
|
+
if (output.type !== 'chunk') continue;
|
|
69
|
+
const originalModuleId = output.facadeModuleId ?? output.moduleIds[output.moduleIds.length - 1];
|
|
70
|
+
if (originalModuleId == null) continue;
|
|
71
|
+
|
|
72
|
+
// This metadata is added by the rollup plugin for @quilted/async
|
|
73
|
+
const moduleId = this.getModuleInfo(originalModuleId)?.meta.quilt?.moduleId;
|
|
74
|
+
if (moduleId == null) continue;
|
|
75
|
+
manifest.modules[moduleId] = createAssetsEntry([...output.imports, output.fileName], {
|
|
76
|
+
dependencyMap,
|
|
77
|
+
getAssetId
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
await fs.mkdir(path.dirname(file), {
|
|
81
|
+
recursive: true
|
|
82
|
+
});
|
|
83
|
+
await fs.writeFile(file, JSON.stringify(manifest, null, 2));
|
|
84
|
+
}
|
|
85
|
+
function createAssetsEntry(files, {
|
|
86
|
+
dependencyMap,
|
|
87
|
+
getAssetId
|
|
88
|
+
}) {
|
|
89
|
+
const styles = [];
|
|
90
|
+
const scripts = [];
|
|
91
|
+
const allFiles = new Set();
|
|
92
|
+
const addFile = file => {
|
|
93
|
+
if (allFiles.has(file)) return;
|
|
94
|
+
allFiles.add(file);
|
|
95
|
+
for (const dependency of dependencyMap.get(file) ?? []) {
|
|
96
|
+
addFile(dependency);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
for (const file of files) {
|
|
100
|
+
addFile(file);
|
|
101
|
+
}
|
|
102
|
+
for (const file of allFiles) {
|
|
103
|
+
if (file.endsWith('.css')) {
|
|
104
|
+
styles.push(getAssetId(file));
|
|
105
|
+
} else {
|
|
106
|
+
scripts.push(getAssetId(file));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
scripts,
|
|
111
|
+
styles
|
|
112
|
+
};
|
|
113
|
+
}
|
|
6
114
|
const QUERY_PATTERN = /\?.*$/s;
|
|
7
115
|
const HASH_PATTERN = /#.*$/s;
|
|
8
116
|
const RAW_PATTERN = /(\?|&)raw(?:&|$)/;
|
|
@@ -26,7 +134,7 @@ function rawAssets() {
|
|
|
26
134
|
}
|
|
27
135
|
const moduleId = cleanModuleIdentifier(id);
|
|
28
136
|
this.addWatchFile(moduleId);
|
|
29
|
-
const file = await readFile(moduleId, {
|
|
137
|
+
const file = await fs.readFile(moduleId, {
|
|
30
138
|
encoding: 'utf-8'
|
|
31
139
|
});
|
|
32
140
|
return `export default ${JSON.stringify(file)}`;
|
|
@@ -53,7 +161,7 @@ function staticAssets({
|
|
|
53
161
|
return cached;
|
|
54
162
|
}
|
|
55
163
|
const file = cleanModuleIdentifier(id);
|
|
56
|
-
const content = await readFile(file);
|
|
164
|
+
const content = await fs.readFile(file);
|
|
57
165
|
let url;
|
|
58
166
|
if (!file.endsWith('.svg') && content.length < inlineLimit) {
|
|
59
167
|
// base64 inlined as a string
|
|
@@ -104,4 +212,4 @@ function cleanModuleIdentifier(url) {
|
|
|
104
212
|
return url.replace(HASH_PATTERN, '').replace(QUERY_PATTERN, '');
|
|
105
213
|
}
|
|
106
214
|
|
|
107
|
-
export { rawAssets, staticAssets };
|
|
215
|
+
export { assetManifest, rawAssets, staticAssets };
|
|
@@ -5,7 +5,8 @@ import { getNodePlugins, removeBuildFiles } from './shared/rollup.esnext';
|
|
|
5
5
|
import { loadPackageJSON } from './shared/package-json.esnext';
|
|
6
6
|
|
|
7
7
|
async function quiltPackageESModules({
|
|
8
|
-
root: rootPath = process.cwd()
|
|
8
|
+
root: rootPath = process.cwd(),
|
|
9
|
+
graphql = true
|
|
9
10
|
} = {}) {
|
|
10
11
|
const root = typeof rootPath === 'string' ? rootPath : fileURLToPath(rootPath);
|
|
11
12
|
const outputDirectory = path.join(root, 'build/esm');
|
|
@@ -18,6 +19,14 @@ async function quiltPackageESModules({
|
|
|
18
19
|
}), removeBuildFiles(['build/esm'], {
|
|
19
20
|
root
|
|
20
21
|
})];
|
|
22
|
+
if (graphql) {
|
|
23
|
+
const {
|
|
24
|
+
graphql
|
|
25
|
+
} = await import('./features/graphql.esnext');
|
|
26
|
+
plugins.push(graphql({
|
|
27
|
+
manifest: false
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
21
30
|
return {
|
|
22
31
|
input: source.files,
|
|
23
32
|
plugins,
|
|
@@ -40,7 +49,8 @@ async function quiltPackageESModules({
|
|
|
40
49
|
};
|
|
41
50
|
}
|
|
42
51
|
async function quiltPackageESNext({
|
|
43
|
-
root: rootPath = process.cwd()
|
|
52
|
+
root: rootPath = process.cwd(),
|
|
53
|
+
graphql = true
|
|
44
54
|
} = {}) {
|
|
45
55
|
const root = typeof rootPath === 'string' ? rootPath : fileURLToPath(rootPath);
|
|
46
56
|
const outputDirectory = path.join(root, 'build/esnext');
|
|
@@ -54,6 +64,14 @@ async function quiltPackageESNext({
|
|
|
54
64
|
}), removeBuildFiles(['build/esnext'], {
|
|
55
65
|
root
|
|
56
66
|
})];
|
|
67
|
+
if (graphql) {
|
|
68
|
+
const {
|
|
69
|
+
graphql
|
|
70
|
+
} = await import('./features/graphql.esnext');
|
|
71
|
+
plugins.push(graphql({
|
|
72
|
+
manifest: false
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
57
75
|
return {
|
|
58
76
|
input: source.files,
|
|
59
77
|
plugins,
|