@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
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"access": "public",
|
|
7
7
|
"@quilted/registry": "https://registry.npmjs.org"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.1.
|
|
9
|
+
"version": "0.1.15",
|
|
10
10
|
"engines": {
|
|
11
11
|
"node": ">=14.0.0"
|
|
12
12
|
},
|
|
@@ -22,9 +22,23 @@
|
|
|
22
22
|
"quilt:esnext": "./build/esnext/index.esnext",
|
|
23
23
|
"import": "./build/esm/index.mjs",
|
|
24
24
|
"require": "./build/cjs/index.cjs"
|
|
25
|
+
},
|
|
26
|
+
"./features/assets": {
|
|
27
|
+
"types": "./build/typescript/features/assets.d.ts",
|
|
28
|
+
"quilt:source": "./source/features/assets.ts",
|
|
29
|
+
"quilt:esnext": "./build/esnext/features/assets.esnext",
|
|
30
|
+
"import": "./build/esm/features/assets.mjs",
|
|
31
|
+
"require": "./build/cjs/features/assets.cjs"
|
|
25
32
|
}
|
|
26
33
|
},
|
|
27
34
|
"types": "./build/typescript/index.d.ts",
|
|
35
|
+
"typesVersions": {
|
|
36
|
+
"*": {
|
|
37
|
+
"features/assets": [
|
|
38
|
+
"./build/typescript/features/assets.d.ts"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
},
|
|
28
42
|
"sideEffects": false,
|
|
29
43
|
"dependencies": {
|
|
30
44
|
"@babel/core": "^7.23.0",
|
|
@@ -40,7 +54,7 @@
|
|
|
40
54
|
"@rollup/plugin-commonjs": "^25.0.5",
|
|
41
55
|
"@rollup/plugin-json": "^6.0.1",
|
|
42
56
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
43
|
-
"@quilted/assets": "^0.0.
|
|
57
|
+
"@quilted/assets": "^0.0.5",
|
|
44
58
|
"@quilted/graphql": "^2.0.0",
|
|
45
59
|
"@types/babel__preset-env": "^7.9.0",
|
|
46
60
|
"browserslist": "^4.22.1",
|
|
@@ -52,7 +66,7 @@
|
|
|
52
66
|
"mrmime": "^1.0.1",
|
|
53
67
|
"rollup-plugin-esbuild": "^6.1.0",
|
|
54
68
|
"rollup-plugin-node-externals": "^6.1.2",
|
|
55
|
-
"rollup-plugin-visualizer": "^5.9.
|
|
69
|
+
"rollup-plugin-visualizer": "^5.9.2",
|
|
56
70
|
"systemjs": "^6.14.2"
|
|
57
71
|
},
|
|
58
72
|
"peerDependencies": {
|
|
@@ -64,8 +78,7 @@
|
|
|
64
78
|
}
|
|
65
79
|
},
|
|
66
80
|
"devDependencies": {
|
|
67
|
-
"
|
|
68
|
-
"rollup": "^4.0.0"
|
|
81
|
+
"rollup": "^4.1.4"
|
|
69
82
|
},
|
|
70
83
|
"eslintConfig": {
|
|
71
84
|
"extends": [
|
package/source/app.ts
CHANGED
|
@@ -151,16 +151,14 @@ export async function quiltAppBrowser({
|
|
|
151
151
|
|
|
152
152
|
const [
|
|
153
153
|
{visualizer},
|
|
154
|
-
{assetManifest},
|
|
155
154
|
{sourceCode},
|
|
156
155
|
{createTSConfigAliasPlugin},
|
|
157
156
|
{css},
|
|
158
|
-
{rawAssets, staticAssets},
|
|
157
|
+
{assetManifest, rawAssets, staticAssets},
|
|
159
158
|
{systemJS},
|
|
160
159
|
nodePlugins,
|
|
161
160
|
] = await Promise.all([
|
|
162
161
|
import('rollup-plugin-visualizer'),
|
|
163
|
-
import('@quilted/assets/rollup'),
|
|
164
162
|
import('./features/source-code.ts'),
|
|
165
163
|
import('./features/typescript.ts'),
|
|
166
164
|
import('./features/css.ts'),
|
|
@@ -235,12 +233,11 @@ export async function quiltAppBrowser({
|
|
|
235
233
|
const id = targets.name ? targets.name : undefined;
|
|
236
234
|
|
|
237
235
|
plugins.push(
|
|
238
|
-
// @ts-expect-error The plugin still depends on Rollup 3
|
|
239
236
|
assetManifest({
|
|
240
237
|
id,
|
|
241
238
|
cacheKey,
|
|
242
|
-
|
|
243
|
-
|
|
239
|
+
baseURL,
|
|
240
|
+
file: path.resolve(`build/manifests/assets${targetFilenamePart}.json`),
|
|
244
241
|
priority: assets?.priority,
|
|
245
242
|
}),
|
|
246
243
|
visualizer({
|
|
@@ -1,10 +1,158 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
|
-
import
|
|
2
|
+
import * as fs from 'fs/promises';
|
|
3
3
|
import {createHash} from 'crypto';
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
NormalizedOutputOptions,
|
|
7
|
+
OutputBundle,
|
|
8
|
+
OutputChunk,
|
|
9
|
+
Plugin,
|
|
10
|
+
PluginContext,
|
|
11
|
+
} from 'rollup';
|
|
6
12
|
import * as mime from 'mrmime';
|
|
7
13
|
|
|
14
|
+
import type {
|
|
15
|
+
AssetsBuildManifest,
|
|
16
|
+
AssetsBuildManifestEntry,
|
|
17
|
+
} from '@quilted/assets';
|
|
18
|
+
|
|
19
|
+
export interface AssetManifestOptions {
|
|
20
|
+
id?: string;
|
|
21
|
+
file: string;
|
|
22
|
+
baseURL: string;
|
|
23
|
+
priority?: number;
|
|
24
|
+
cacheKey?: Record<string, any>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function assetManifest(manifestOptions: AssetManifestOptions): Plugin {
|
|
28
|
+
return {
|
|
29
|
+
name: '@quilted/asset-manifest',
|
|
30
|
+
async generateBundle(options, bundle) {
|
|
31
|
+
await writeManifestForBundle.call(this, bundle, manifestOptions, options);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function writeManifestForBundle(
|
|
37
|
+
this: PluginContext,
|
|
38
|
+
bundle: OutputBundle,
|
|
39
|
+
{id, file, baseURL, cacheKey, priority}: AssetManifestOptions,
|
|
40
|
+
{format}: NormalizedOutputOptions,
|
|
41
|
+
) {
|
|
42
|
+
const outputs = Object.values(bundle);
|
|
43
|
+
|
|
44
|
+
const entries = outputs.filter(
|
|
45
|
+
(output): output is OutputChunk =>
|
|
46
|
+
output.type === 'chunk' && output.isEntry,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
if (entries.length === 0) {
|
|
50
|
+
throw new Error(`Could not find any entries in your rollup bundle...`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// We assume the first entry is the "main" one. There can be
|
|
54
|
+
// more than one because each worker script is also listed as an
|
|
55
|
+
// entry (though, from a separate build).
|
|
56
|
+
const entryChunk = entries[0]!;
|
|
57
|
+
|
|
58
|
+
const dependencyMap = new Map<string, string[]>();
|
|
59
|
+
|
|
60
|
+
for (const output of outputs) {
|
|
61
|
+
if (output.type !== 'chunk') continue;
|
|
62
|
+
dependencyMap.set(output.fileName, output.imports);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const assets: string[] = [];
|
|
66
|
+
const assetIdMap = new Map<string, number>();
|
|
67
|
+
|
|
68
|
+
function getAssetId(file: string) {
|
|
69
|
+
let id = assetIdMap.get(file);
|
|
70
|
+
|
|
71
|
+
if (id == null) {
|
|
72
|
+
assets.push(`${baseURL}${file}`);
|
|
73
|
+
id = assets.length - 1;
|
|
74
|
+
assetIdMap.set(file, id);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return id;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const manifest: AssetsBuildManifest<any> = {
|
|
81
|
+
id,
|
|
82
|
+
priority,
|
|
83
|
+
cacheKey,
|
|
84
|
+
assets,
|
|
85
|
+
attributes: format === 'es' ? {scripts: {type: 'module'}} : undefined,
|
|
86
|
+
entries: {
|
|
87
|
+
default: createAssetsEntry([...entryChunk.imports, entryChunk.fileName], {
|
|
88
|
+
dependencyMap,
|
|
89
|
+
getAssetId,
|
|
90
|
+
}),
|
|
91
|
+
},
|
|
92
|
+
modules: {},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
for (const output of outputs) {
|
|
96
|
+
if (output.type !== 'chunk') continue;
|
|
97
|
+
|
|
98
|
+
const originalModuleId =
|
|
99
|
+
output.facadeModuleId ?? output.moduleIds[output.moduleIds.length - 1];
|
|
100
|
+
|
|
101
|
+
if (originalModuleId == null) continue;
|
|
102
|
+
|
|
103
|
+
// This metadata is added by the rollup plugin for @quilted/async
|
|
104
|
+
const moduleId = this.getModuleInfo(originalModuleId)?.meta.quilt?.moduleId;
|
|
105
|
+
|
|
106
|
+
if (moduleId == null) continue;
|
|
107
|
+
|
|
108
|
+
manifest.modules[moduleId] = createAssetsEntry(
|
|
109
|
+
[...output.imports, output.fileName],
|
|
110
|
+
{dependencyMap, getAssetId},
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
await fs.mkdir(path.dirname(file), {recursive: true});
|
|
115
|
+
await fs.writeFile(file, JSON.stringify(manifest, null, 2));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function createAssetsEntry(
|
|
119
|
+
files: string[],
|
|
120
|
+
{
|
|
121
|
+
dependencyMap,
|
|
122
|
+
getAssetId,
|
|
123
|
+
}: {
|
|
124
|
+
dependencyMap: Map<string, string[]>;
|
|
125
|
+
getAssetId(file: string): number;
|
|
126
|
+
},
|
|
127
|
+
): AssetsBuildManifestEntry {
|
|
128
|
+
const styles: number[] = [];
|
|
129
|
+
const scripts: number[] = [];
|
|
130
|
+
|
|
131
|
+
const allFiles = new Set<string>();
|
|
132
|
+
const addFile = (file: string) => {
|
|
133
|
+
if (allFiles.has(file)) return;
|
|
134
|
+
allFiles.add(file);
|
|
135
|
+
|
|
136
|
+
for (const dependency of dependencyMap.get(file) ?? []) {
|
|
137
|
+
addFile(dependency);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
for (const file of files) {
|
|
142
|
+
addFile(file);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
for (const file of allFiles) {
|
|
146
|
+
if (file.endsWith('.css')) {
|
|
147
|
+
styles.push(getAssetId(file));
|
|
148
|
+
} else {
|
|
149
|
+
scripts.push(getAssetId(file));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return {scripts, styles};
|
|
154
|
+
}
|
|
155
|
+
|
|
8
156
|
const QUERY_PATTERN = /\?.*$/s;
|
|
9
157
|
const HASH_PATTERN = /#.*$/s;
|
|
10
158
|
const RAW_PATTERN = /(\?|&)raw(?:&|$)/;
|
|
@@ -56,7 +204,7 @@ export function rawAssets(): Plugin {
|
|
|
56
204
|
|
|
57
205
|
this.addWatchFile(moduleId);
|
|
58
206
|
|
|
59
|
-
const file = await readFile(moduleId, {
|
|
207
|
+
const file = await fs.readFile(moduleId, {
|
|
60
208
|
encoding: 'utf-8',
|
|
61
209
|
});
|
|
62
210
|
|
|
@@ -103,7 +251,7 @@ export function staticAssets({
|
|
|
103
251
|
}
|
|
104
252
|
|
|
105
253
|
const file = cleanModuleIdentifier(id);
|
|
106
|
-
const content = await readFile(file);
|
|
254
|
+
const content = await fs.readFile(file);
|
|
107
255
|
|
|
108
256
|
let url: string;
|
|
109
257
|
|
package/source/package.ts
CHANGED
|
@@ -11,10 +11,18 @@ export interface PackageOptions {
|
|
|
11
11
|
* The root directory containing the source code for your application.
|
|
12
12
|
*/
|
|
13
13
|
root?: string | URL;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Whether to include GraphQL-related code transformations.
|
|
17
|
+
*
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
graphql?: boolean;
|
|
14
21
|
}
|
|
15
22
|
|
|
16
23
|
export async function quiltPackageESModules({
|
|
17
24
|
root: rootPath = process.cwd(),
|
|
25
|
+
graphql = true,
|
|
18
26
|
}: PackageOptions = {}) {
|
|
19
27
|
const root =
|
|
20
28
|
typeof rootPath === 'string' ? rootPath : fileURLToPath(rootPath);
|
|
@@ -34,6 +42,11 @@ export async function quiltPackageESModules({
|
|
|
34
42
|
removeBuildFiles(['build/esm'], {root}),
|
|
35
43
|
];
|
|
36
44
|
|
|
45
|
+
if (graphql) {
|
|
46
|
+
const {graphql} = await import('./features/graphql.ts');
|
|
47
|
+
plugins.push(graphql({manifest: false}));
|
|
48
|
+
}
|
|
49
|
+
|
|
37
50
|
return {
|
|
38
51
|
input: source.files,
|
|
39
52
|
plugins,
|
|
@@ -62,6 +75,7 @@ export async function quiltPackageESModules({
|
|
|
62
75
|
|
|
63
76
|
export async function quiltPackageESNext({
|
|
64
77
|
root: rootPath = process.cwd(),
|
|
78
|
+
graphql = true,
|
|
65
79
|
}: PackageOptions = {}) {
|
|
66
80
|
const root =
|
|
67
81
|
typeof rootPath === 'string' ? rootPath : fileURLToPath(rootPath);
|
|
@@ -81,6 +95,11 @@ export async function quiltPackageESNext({
|
|
|
81
95
|
removeBuildFiles(['build/esnext'], {root}),
|
|
82
96
|
];
|
|
83
97
|
|
|
98
|
+
if (graphql) {
|
|
99
|
+
const {graphql} = await import('./features/graphql.ts');
|
|
100
|
+
plugins.push(graphql({manifest: false}));
|
|
101
|
+
}
|
|
102
|
+
|
|
84
103
|
return {
|
|
85
104
|
input: source.files,
|
|
86
105
|
plugins,
|