@quilted/rollup 0.1.13 → 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 +19 -0
- package/build/cjs/app.cjs +5 -8
- package/build/cjs/features/assets.cjs +112 -2
- package/build/cjs/features/source-code.cjs +14 -2
- package/build/cjs/features/system-js.cjs +2 -1
- package/build/cjs/index.cjs +1 -0
- package/build/cjs/package.cjs +73 -11
- package/build/esm/app.mjs +5 -8
- package/build/esm/features/assets.mjs +112 -4
- package/build/esm/features/source-code.mjs +12 -1
- package/build/esm/index.mjs +1 -1
- package/build/esm/package.mjs +73 -12
- package/build/esnext/app.esnext +5 -8
- package/build/esnext/features/assets.esnext +112 -4
- package/build/esnext/features/source-code.esnext +12 -1
- package/build/esnext/index.esnext +1 -1
- package/build/esnext/package.esnext +73 -12
- 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/features/source-code.d.ts +2 -1
- package/build/typescript/features/source-code.d.ts.map +1 -1
- package/build/typescript/index.d.ts +1 -1
- package/build/typescript/index.d.ts.map +1 -1
- package/build/typescript/package.d.ts +20 -1
- 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 +13 -0
- package/source/index.ts +5 -1
- package/source/package.ts +90 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @quilted/rollup
|
|
2
2
|
|
|
3
|
+
## 0.1.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`750dd6b9`](https://github.com/lemonmade/quilt/commit/750dd6b9cb6a18648cc793f57579fb0b64cb23bc) Thanks [@lemonmade](https://github.com/lemonmade)! - Update Rollup dependencies
|
|
8
|
+
|
|
9
|
+
- [`750dd6b9`](https://github.com/lemonmade/quilt/commit/750dd6b9cb6a18648cc793f57579fb0b64cb23bc) Thanks [@lemonmade](https://github.com/lemonmade)! - Add GraphQL transforms to package rollup helpers
|
|
10
|
+
|
|
11
|
+
- [`750dd6b9`](https://github.com/lemonmade/quilt/commit/750dd6b9cb6a18648cc793f57579fb0b64cb23bc) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix invalid `esbuild` target
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`750dd6b9`](https://github.com/lemonmade/quilt/commit/750dd6b9cb6a18648cc793f57579fb0b64cb23bc)]:
|
|
14
|
+
- @quilted/assets@0.0.5
|
|
15
|
+
|
|
16
|
+
## 0.1.14
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- [`3c223309`](https://github.com/lemonmade/quilt/commit/3c22330964279610b544a26c5a30b9e2fc8c1272) Thanks [@lemonmade](https://github.com/lemonmade)! - Add ESNext plugin
|
|
21
|
+
|
|
3
22
|
## 0.1.13
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/build/cjs/app.cjs
CHANGED
|
@@ -59,8 +59,6 @@ async function quiltAppBrowser({
|
|
|
59
59
|
const targetFilenamePart = normalizedTargetName ? `.${normalizedTargetName}` : '';
|
|
60
60
|
const [{
|
|
61
61
|
visualizer
|
|
62
|
-
}, {
|
|
63
|
-
assetManifest
|
|
64
62
|
}, {
|
|
65
63
|
sourceCode
|
|
66
64
|
}, {
|
|
@@ -68,11 +66,12 @@ async function quiltAppBrowser({
|
|
|
68
66
|
}, {
|
|
69
67
|
css
|
|
70
68
|
}, {
|
|
69
|
+
assetManifest,
|
|
71
70
|
rawAssets,
|
|
72
71
|
staticAssets
|
|
73
72
|
}, {
|
|
74
73
|
systemJS
|
|
75
|
-
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'),
|
|
74
|
+
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), Promise.resolve().then(function () { return require('./features/source-code.cjs'); }), Promise.resolve().then(function () { return require('./features/typescript.cjs'); }), Promise.resolve().then(function () { return require('./features/css.cjs'); }), Promise.resolve().then(function () { return require('./features/assets.cjs'); }), Promise.resolve().then(function () { return require('./features/system-js.cjs'); }), rollup.getNodePlugins()]);
|
|
76
75
|
const plugins = [...nodePlugins, systemJS({
|
|
77
76
|
minify
|
|
78
77
|
}), sourceCode({
|
|
@@ -141,13 +140,11 @@ async function quiltAppBrowser({
|
|
|
141
140
|
browserTarget: targets.name
|
|
142
141
|
} : undefined;
|
|
143
142
|
const id = targets.name ? targets.name : undefined;
|
|
144
|
-
plugins.push(
|
|
145
|
-
// @ts-expect-error The plugin still depends on Rollup 3
|
|
146
|
-
assetManifest({
|
|
143
|
+
plugins.push(assetManifest({
|
|
147
144
|
id,
|
|
148
145
|
cacheKey,
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
baseURL,
|
|
147
|
+
file: path__namespace.resolve(`build/manifests/assets${targetFilenamePart}.json`),
|
|
151
148
|
priority: assets?.priority
|
|
152
149
|
}), visualizer({
|
|
153
150
|
template: 'treemap',
|
|
@@ -23,8 +23,117 @@ function _interopNamespaceDefault(e) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
26
|
+
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
26
27
|
var mime__namespace = /*#__PURE__*/_interopNamespaceDefault(mime);
|
|
27
28
|
|
|
29
|
+
function assetManifest(manifestOptions) {
|
|
30
|
+
return {
|
|
31
|
+
name: '@quilted/asset-manifest',
|
|
32
|
+
async generateBundle(options, bundle) {
|
|
33
|
+
await writeManifestForBundle.call(this, bundle, manifestOptions, options);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async function writeManifestForBundle(bundle, {
|
|
38
|
+
id,
|
|
39
|
+
file,
|
|
40
|
+
baseURL,
|
|
41
|
+
cacheKey,
|
|
42
|
+
priority
|
|
43
|
+
}, {
|
|
44
|
+
format
|
|
45
|
+
}) {
|
|
46
|
+
const outputs = Object.values(bundle);
|
|
47
|
+
const entries = outputs.filter(output => output.type === 'chunk' && output.isEntry);
|
|
48
|
+
if (entries.length === 0) {
|
|
49
|
+
throw new Error(`Could not find any entries in your rollup bundle...`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// We assume the first entry is the "main" one. There can be
|
|
53
|
+
// more than one because each worker script is also listed as an
|
|
54
|
+
// entry (though, from a separate build).
|
|
55
|
+
const entryChunk = entries[0];
|
|
56
|
+
const dependencyMap = new Map();
|
|
57
|
+
for (const output of outputs) {
|
|
58
|
+
if (output.type !== 'chunk') continue;
|
|
59
|
+
dependencyMap.set(output.fileName, output.imports);
|
|
60
|
+
}
|
|
61
|
+
const assets = [];
|
|
62
|
+
const assetIdMap = new Map();
|
|
63
|
+
function getAssetId(file) {
|
|
64
|
+
let id = assetIdMap.get(file);
|
|
65
|
+
if (id == null) {
|
|
66
|
+
assets.push(`${baseURL}${file}`);
|
|
67
|
+
id = assets.length - 1;
|
|
68
|
+
assetIdMap.set(file, id);
|
|
69
|
+
}
|
|
70
|
+
return id;
|
|
71
|
+
}
|
|
72
|
+
const manifest = {
|
|
73
|
+
id,
|
|
74
|
+
priority,
|
|
75
|
+
cacheKey,
|
|
76
|
+
assets,
|
|
77
|
+
attributes: format === 'es' ? {
|
|
78
|
+
scripts: {
|
|
79
|
+
type: 'module'
|
|
80
|
+
}
|
|
81
|
+
} : undefined,
|
|
82
|
+
entries: {
|
|
83
|
+
default: createAssetsEntry([...entryChunk.imports, entryChunk.fileName], {
|
|
84
|
+
dependencyMap,
|
|
85
|
+
getAssetId
|
|
86
|
+
})
|
|
87
|
+
},
|
|
88
|
+
modules: {}
|
|
89
|
+
};
|
|
90
|
+
for (const output of outputs) {
|
|
91
|
+
if (output.type !== 'chunk') continue;
|
|
92
|
+
const originalModuleId = output.facadeModuleId ?? output.moduleIds[output.moduleIds.length - 1];
|
|
93
|
+
if (originalModuleId == null) continue;
|
|
94
|
+
|
|
95
|
+
// This metadata is added by the rollup plugin for @quilted/async
|
|
96
|
+
const moduleId = this.getModuleInfo(originalModuleId)?.meta.quilt?.moduleId;
|
|
97
|
+
if (moduleId == null) continue;
|
|
98
|
+
manifest.modules[moduleId] = createAssetsEntry([...output.imports, output.fileName], {
|
|
99
|
+
dependencyMap,
|
|
100
|
+
getAssetId
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
await fs__namespace.mkdir(path__namespace.dirname(file), {
|
|
104
|
+
recursive: true
|
|
105
|
+
});
|
|
106
|
+
await fs__namespace.writeFile(file, JSON.stringify(manifest, null, 2));
|
|
107
|
+
}
|
|
108
|
+
function createAssetsEntry(files, {
|
|
109
|
+
dependencyMap,
|
|
110
|
+
getAssetId
|
|
111
|
+
}) {
|
|
112
|
+
const styles = [];
|
|
113
|
+
const scripts = [];
|
|
114
|
+
const allFiles = new Set();
|
|
115
|
+
const addFile = file => {
|
|
116
|
+
if (allFiles.has(file)) return;
|
|
117
|
+
allFiles.add(file);
|
|
118
|
+
for (const dependency of dependencyMap.get(file) ?? []) {
|
|
119
|
+
addFile(dependency);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
for (const file of files) {
|
|
123
|
+
addFile(file);
|
|
124
|
+
}
|
|
125
|
+
for (const file of allFiles) {
|
|
126
|
+
if (file.endsWith('.css')) {
|
|
127
|
+
styles.push(getAssetId(file));
|
|
128
|
+
} else {
|
|
129
|
+
scripts.push(getAssetId(file));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
scripts,
|
|
134
|
+
styles
|
|
135
|
+
};
|
|
136
|
+
}
|
|
28
137
|
const QUERY_PATTERN = /\?.*$/s;
|
|
29
138
|
const HASH_PATTERN = /#.*$/s;
|
|
30
139
|
const RAW_PATTERN = /(\?|&)raw(?:&|$)/;
|
|
@@ -48,7 +157,7 @@ function rawAssets() {
|
|
|
48
157
|
}
|
|
49
158
|
const moduleId = cleanModuleIdentifier(id);
|
|
50
159
|
this.addWatchFile(moduleId);
|
|
51
|
-
const file = await
|
|
160
|
+
const file = await fs__namespace.readFile(moduleId, {
|
|
52
161
|
encoding: 'utf-8'
|
|
53
162
|
});
|
|
54
163
|
return `export default ${JSON.stringify(file)}`;
|
|
@@ -75,7 +184,7 @@ function staticAssets({
|
|
|
75
184
|
return cached;
|
|
76
185
|
}
|
|
77
186
|
const file = cleanModuleIdentifier(id);
|
|
78
|
-
const content = await
|
|
187
|
+
const content = await fs__namespace.readFile(file);
|
|
79
188
|
let url;
|
|
80
189
|
if (!file.endsWith('.svg') && content.length < inlineLimit) {
|
|
81
190
|
// base64 inlined as a string
|
|
@@ -126,5 +235,6 @@ function cleanModuleIdentifier(url) {
|
|
|
126
235
|
return url.replace(HASH_PATTERN, '').replace(QUERY_PATTERN, '');
|
|
127
236
|
}
|
|
128
237
|
|
|
238
|
+
exports.assetManifest = assetManifest;
|
|
129
239
|
exports.rawAssets = rawAssets;
|
|
130
240
|
exports.staticAssets = staticAssets;
|
|
@@ -2,12 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
var node_module = require('node:module');
|
|
4
4
|
var babel = require('@rollup/plugin-babel');
|
|
5
|
+
var esbuild = require('rollup-plugin-esbuild');
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
8
|
+
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('features/source-code.cjs', document.baseURI).href)));
|
|
7
9
|
function sourceCode({
|
|
8
10
|
mode,
|
|
9
|
-
targets
|
|
11
|
+
targets,
|
|
12
|
+
babel: useBabel = true
|
|
10
13
|
}) {
|
|
14
|
+
if (!useBabel) {
|
|
15
|
+
return esbuild({
|
|
16
|
+
// Support very modern features
|
|
17
|
+
target: 'es2022',
|
|
18
|
+
jsx: 'automatic',
|
|
19
|
+
jsxImportSource: 'react',
|
|
20
|
+
exclude: 'node_modules/**'
|
|
21
|
+
});
|
|
22
|
+
}
|
|
11
23
|
return babel({
|
|
12
24
|
envName: mode,
|
|
13
25
|
configFile: false,
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var fs = require('node:fs/promises');
|
|
4
4
|
var node_module = require('node:module');
|
|
5
5
|
|
|
6
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
6
7
|
function systemJS({
|
|
7
8
|
minify = false
|
|
8
9
|
} = {}) {
|
|
@@ -10,7 +11,7 @@ function systemJS({
|
|
|
10
11
|
name: '@quilted/system-js',
|
|
11
12
|
async renderChunk(_, chunk, options) {
|
|
12
13
|
if (options.format !== 'system' || !chunk.isEntry) return null;
|
|
13
|
-
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (
|
|
14
|
+
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('features/system-js.cjs', document.baseURI).href)));
|
|
14
15
|
const systemjs = minify ? require$1.resolve('systemjs/dist/s.min.js') : require$1.resolve('systemjs/dist/s.js');
|
|
15
16
|
|
|
16
17
|
// We write the systemjs loader to a dedicated file, and we make it the
|
package/build/cjs/index.cjs
CHANGED
package/build/cjs/package.cjs
CHANGED
|
@@ -26,28 +26,30 @@ function _interopNamespaceDefault(e) {
|
|
|
26
26
|
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
27
27
|
|
|
28
28
|
async function quiltPackageESModules({
|
|
29
|
-
root: rootPath = process.cwd()
|
|
29
|
+
root: rootPath = process.cwd(),
|
|
30
|
+
graphql = true
|
|
30
31
|
} = {}) {
|
|
31
32
|
const root = typeof rootPath === 'string' ? rootPath : node_url.fileURLToPath(rootPath);
|
|
32
33
|
const outputDirectory = path__namespace.join(root, 'build/esm');
|
|
33
34
|
const [{
|
|
34
35
|
sourceCode
|
|
35
36
|
}, nodePlugins, packageJSON] = await Promise.all([Promise.resolve().then(function () { return require('./features/source-code.cjs'); }), rollup.getNodePlugins(), packageJson.loadPackageJSON(root)]);
|
|
36
|
-
const
|
|
37
|
-
let sourceRoot = root;
|
|
38
|
-
const sourceEntryFiles = Object.values(entries);
|
|
39
|
-
for (const entry of sourceEntryFiles) {
|
|
40
|
-
if (!entry.startsWith(root)) continue;
|
|
41
|
-
sourceRoot = path__namespace.resolve(root, path__namespace.relative(root, entry).split(path__namespace.sep)[0] ?? '.');
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
37
|
+
const source = await sourceForPackage(root, packageJSON);
|
|
44
38
|
const plugins = [...nodePlugins, sourceCode({
|
|
45
39
|
mode: 'production'
|
|
46
40
|
}), rollup.removeBuildFiles(['build/esm'], {
|
|
47
41
|
root
|
|
48
42
|
})];
|
|
43
|
+
if (graphql) {
|
|
44
|
+
const {
|
|
45
|
+
graphql
|
|
46
|
+
} = await Promise.resolve().then(function () { return require('./features/graphql.cjs'); });
|
|
47
|
+
plugins.push(graphql({
|
|
48
|
+
manifest: false
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
49
51
|
return {
|
|
50
|
-
input:
|
|
52
|
+
input: source.files,
|
|
51
53
|
plugins,
|
|
52
54
|
onwarn(warning, defaultWarn) {
|
|
53
55
|
// Removes annoying warnings for React-focused libraries that
|
|
@@ -59,7 +61,7 @@ async function quiltPackageESModules({
|
|
|
59
61
|
},
|
|
60
62
|
output: {
|
|
61
63
|
preserveModules: true,
|
|
62
|
-
preserveModulesRoot:
|
|
64
|
+
preserveModulesRoot: source.root,
|
|
63
65
|
format: 'esm',
|
|
64
66
|
dir: outputDirectory,
|
|
65
67
|
entryFileNames: `[name].mjs`,
|
|
@@ -67,6 +69,65 @@ async function quiltPackageESModules({
|
|
|
67
69
|
}
|
|
68
70
|
};
|
|
69
71
|
}
|
|
72
|
+
async function quiltPackageESNext({
|
|
73
|
+
root: rootPath = process.cwd(),
|
|
74
|
+
graphql = true
|
|
75
|
+
} = {}) {
|
|
76
|
+
const root = typeof rootPath === 'string' ? rootPath : node_url.fileURLToPath(rootPath);
|
|
77
|
+
const outputDirectory = path__namespace.join(root, 'build/esnext');
|
|
78
|
+
const [{
|
|
79
|
+
sourceCode
|
|
80
|
+
}, nodePlugins, packageJSON] = await Promise.all([Promise.resolve().then(function () { return require('./features/source-code.cjs'); }), rollup.getNodePlugins(), packageJson.loadPackageJSON(root)]);
|
|
81
|
+
const source = await sourceForPackage(root, packageJSON);
|
|
82
|
+
const plugins = [...nodePlugins, sourceCode({
|
|
83
|
+
mode: 'production',
|
|
84
|
+
babel: false
|
|
85
|
+
}), rollup.removeBuildFiles(['build/esnext'], {
|
|
86
|
+
root
|
|
87
|
+
})];
|
|
88
|
+
if (graphql) {
|
|
89
|
+
const {
|
|
90
|
+
graphql
|
|
91
|
+
} = await Promise.resolve().then(function () { return require('./features/graphql.cjs'); });
|
|
92
|
+
plugins.push(graphql({
|
|
93
|
+
manifest: false
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
input: source.files,
|
|
98
|
+
plugins,
|
|
99
|
+
onwarn(warning, defaultWarn) {
|
|
100
|
+
// Removes annoying warnings for React-focused libraries that
|
|
101
|
+
// include 'use client' directives.
|
|
102
|
+
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
defaultWarn(warning);
|
|
106
|
+
},
|
|
107
|
+
output: {
|
|
108
|
+
preserveModules: true,
|
|
109
|
+
preserveModulesRoot: source.root,
|
|
110
|
+
format: 'esm',
|
|
111
|
+
dir: outputDirectory,
|
|
112
|
+
entryFileNames: `[name].esnext`,
|
|
113
|
+
assetFileNames: `[name].[ext]`
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
async function sourceForPackage(root, packageJSON) {
|
|
118
|
+
const [entries] = await Promise.all([sourceEntriesForPackage(root, packageJSON)]);
|
|
119
|
+
let sourceRoot = root;
|
|
120
|
+
const sourceEntryFiles = Object.values(entries);
|
|
121
|
+
for (const entry of sourceEntryFiles) {
|
|
122
|
+
if (!entry.startsWith(root)) continue;
|
|
123
|
+
sourceRoot = path__namespace.resolve(root, path__namespace.relative(root, entry).split(path__namespace.sep)[0] ?? '.');
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
root: sourceRoot,
|
|
128
|
+
files: sourceEntryFiles
|
|
129
|
+
};
|
|
130
|
+
}
|
|
70
131
|
async function sourceEntriesForPackage(root, packageJSON) {
|
|
71
132
|
const {
|
|
72
133
|
main,
|
|
@@ -106,3 +167,4 @@ async function resolveTargetFileAsSource(file, root) {
|
|
|
106
167
|
}
|
|
107
168
|
|
|
108
169
|
exports.quiltPackageESModules = quiltPackageESModules;
|
|
170
|
+
exports.quiltPackageESNext = quiltPackageESNext;
|
package/build/esm/app.mjs
CHANGED
|
@@ -37,8 +37,6 @@ async function quiltAppBrowser({
|
|
|
37
37
|
const targetFilenamePart = normalizedTargetName ? `.${normalizedTargetName}` : '';
|
|
38
38
|
const [{
|
|
39
39
|
visualizer
|
|
40
|
-
}, {
|
|
41
|
-
assetManifest
|
|
42
40
|
}, {
|
|
43
41
|
sourceCode
|
|
44
42
|
}, {
|
|
@@ -46,11 +44,12 @@ async function quiltAppBrowser({
|
|
|
46
44
|
}, {
|
|
47
45
|
css
|
|
48
46
|
}, {
|
|
47
|
+
assetManifest,
|
|
49
48
|
rawAssets,
|
|
50
49
|
staticAssets
|
|
51
50
|
}, {
|
|
52
51
|
systemJS
|
|
53
|
-
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('
|
|
52
|
+
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/source-code.mjs'), import('./features/typescript.mjs'), import('./features/css.mjs'), import('./features/assets.mjs'), import('./features/system-js.mjs'), getNodePlugins()]);
|
|
54
53
|
const plugins = [...nodePlugins, systemJS({
|
|
55
54
|
minify
|
|
56
55
|
}), sourceCode({
|
|
@@ -119,13 +118,11 @@ async function quiltAppBrowser({
|
|
|
119
118
|
browserTarget: targets.name
|
|
120
119
|
} : undefined;
|
|
121
120
|
const id = targets.name ? targets.name : undefined;
|
|
122
|
-
plugins.push(
|
|
123
|
-
// @ts-expect-error The plugin still depends on Rollup 3
|
|
124
|
-
assetManifest({
|
|
121
|
+
plugins.push(assetManifest({
|
|
125
122
|
id,
|
|
126
123
|
cacheKey,
|
|
127
|
-
|
|
128
|
-
|
|
124
|
+
baseURL,
|
|
125
|
+
file: path.resolve(`build/manifests/assets${targetFilenamePart}.json`),
|
|
129
126
|
priority: assets?.priority
|
|
130
127
|
}), visualizer({
|
|
131
128
|
template: 'treemap',
|
|
@@ -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 };
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
import babel from '@rollup/plugin-babel';
|
|
3
|
+
import esbuild from 'rollup-plugin-esbuild';
|
|
3
4
|
|
|
4
5
|
const require = createRequire(import.meta.url);
|
|
5
6
|
function sourceCode({
|
|
6
7
|
mode,
|
|
7
|
-
targets
|
|
8
|
+
targets,
|
|
9
|
+
babel: useBabel = true
|
|
8
10
|
}) {
|
|
11
|
+
if (!useBabel) {
|
|
12
|
+
return esbuild({
|
|
13
|
+
// Support very modern features
|
|
14
|
+
target: 'es2022',
|
|
15
|
+
jsx: 'automatic',
|
|
16
|
+
jsxImportSource: 'react',
|
|
17
|
+
exclude: 'node_modules/**'
|
|
18
|
+
});
|
|
19
|
+
}
|
|
9
20
|
return babel({
|
|
10
21
|
envName: mode,
|
|
11
22
|
configFile: false,
|
package/build/esm/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { quiltAppBrowser, quiltAppServer } from './app.mjs';
|
|
2
|
-
export { quiltPackageESModules } from './package.mjs';
|
|
2
|
+
export { quiltPackageESModules, quiltPackageESNext } from './package.mjs';
|