@quilted/rollup 0.1.14 → 0.1.16
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 +21 -47
- 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/index.cjs +2 -0
- package/build/cjs/module.cjs +155 -0
- package/build/cjs/package.cjs +20 -2
- package/build/cjs/shared/browserslist.cjs +25 -0
- package/build/esm/app.mjs +21 -47
- package/build/esm/features/assets.mjs +112 -4
- package/build/esm/features/source-code.mjs +1 -1
- package/build/esm/index.mjs +1 -0
- package/build/esm/module.mjs +134 -0
- package/build/esm/package.mjs +20 -2
- package/build/esm/shared/browserslist.mjs +23 -0
- package/build/esnext/app.esnext +21 -47
- package/build/esnext/features/assets.esnext +112 -4
- package/build/esnext/features/source-code.esnext +1 -1
- package/build/esnext/index.esnext +1 -0
- package/build/esnext/module.esnext +134 -0
- package/build/esnext/package.esnext +20 -2
- package/build/esnext/shared/browserslist.esnext +23 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts +4 -6
- 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/index.d.ts +1 -0
- package/build/typescript/index.d.ts.map +1 -1
- package/build/typescript/module.d.ts +45 -0
- package/build/typescript/module.d.ts.map +1 -0
- package/build/typescript/package.d.ts +8 -2
- package/build/typescript/package.d.ts.map +1 -1
- package/build/typescript/shared/browserslist.d.ts +11 -0
- package/build/typescript/shared/browserslist.d.ts.map +1 -0
- package/package.json +18 -5
- package/source/app.ts +21 -53
- package/source/features/assets.ts +152 -4
- package/source/features/source-code.ts +1 -1
- package/source/index.ts +1 -0
- package/source/module.ts +223 -0
- package/source/package.ts +19 -0
- package/source/shared/browserslist.ts +32 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Plugin } from 'rollup';
|
|
2
|
+
import { type BrowserTargetSelection } from './shared/browserslist.ts';
|
|
3
|
+
import type { MagicModuleEnvOptions } from './features/env.ts';
|
|
4
|
+
export interface ModuleOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The root directory containing the source code for your application.
|
|
7
|
+
*/
|
|
8
|
+
root?: string | URL;
|
|
9
|
+
/**
|
|
10
|
+
* Whether to include GraphQL-related code transformations.
|
|
11
|
+
*
|
|
12
|
+
* @default true
|
|
13
|
+
*/
|
|
14
|
+
graphql?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Customizes the behavior of environment variables for your module.
|
|
17
|
+
*/
|
|
18
|
+
env?: MagicModuleEnvOptions;
|
|
19
|
+
/**
|
|
20
|
+
* Customizes the assets created for your module.
|
|
21
|
+
*/
|
|
22
|
+
assets?: ModuleAssetsOptions;
|
|
23
|
+
}
|
|
24
|
+
export interface ModuleAssetsOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Whether to minify assets created for this module.
|
|
27
|
+
*
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
minify?: boolean;
|
|
31
|
+
hash?: boolean;
|
|
32
|
+
targets?: BrowserTargetSelection;
|
|
33
|
+
}
|
|
34
|
+
export declare function quiltModule({ root: rootPath, env, assets, graphql, }?: ModuleOptions): Promise<{
|
|
35
|
+
input: string[];
|
|
36
|
+
plugins: Plugin<any>[];
|
|
37
|
+
onwarn(warning: import("rollup").RollupLog, defaultWarn: import("rollup").LoggingFunction): void;
|
|
38
|
+
output: {
|
|
39
|
+
format: "esm";
|
|
40
|
+
dir: string;
|
|
41
|
+
entryFileNames: string;
|
|
42
|
+
assetFileNames: string;
|
|
43
|
+
};
|
|
44
|
+
}>;
|
|
45
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../source/module.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAqB,MAAM,QAAQ,CAAC;AAMlD,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,mBAAmB,CAAC;AAE7D,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAEpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,GAAG,CAAC,EAAE,qBAAqB,CAAC;IAE5B;;OAEG;IACH,MAAM,CAAC,EAAE,mBAAmB,CAAC;CAC9B;AAED,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,sBAAsB,CAAC;CAClC;AAED,wBAAsB,WAAW,CAAC,EAChC,IAAI,EAAE,QAAwB,EAC9B,GAAG,EACH,MAAM,EACN,OAAc,GACf,GAAE,aAAkB;;;;;;;;;;GAkFpB"}
|
|
@@ -4,8 +4,14 @@ export interface PackageOptions {
|
|
|
4
4
|
* The root directory containing the source code for your application.
|
|
5
5
|
*/
|
|
6
6
|
root?: string | URL;
|
|
7
|
+
/**
|
|
8
|
+
* Whether to include GraphQL-related code transformations.
|
|
9
|
+
*
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
12
|
+
graphql?: boolean;
|
|
7
13
|
}
|
|
8
|
-
export declare function quiltPackageESModules({ root: rootPath, }?: PackageOptions): Promise<{
|
|
14
|
+
export declare function quiltPackageESModules({ root: rootPath, graphql, }?: PackageOptions): Promise<{
|
|
9
15
|
input: string[];
|
|
10
16
|
plugins: Plugin<any>[];
|
|
11
17
|
onwarn(warning: import("rollup").RollupLog, defaultWarn: import("rollup").LoggingFunction): void;
|
|
@@ -18,7 +24,7 @@ export declare function quiltPackageESModules({ root: rootPath, }?: PackageOptio
|
|
|
18
24
|
assetFileNames: string;
|
|
19
25
|
};
|
|
20
26
|
}>;
|
|
21
|
-
export declare function quiltPackageESNext({ root: rootPath, }?: PackageOptions): Promise<{
|
|
27
|
+
export declare function quiltPackageESNext({ root: rootPath, graphql, }?: PackageOptions): Promise<{
|
|
22
28
|
input: string[];
|
|
23
29
|
plugins: Plugin<any>[];
|
|
24
30
|
onwarn(warning: import("rollup").RollupLog, defaultWarn: import("rollup").LoggingFunction): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../source/package.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAqB,MAAM,QAAQ,CAAC;AAOlD,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../source/package.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAqB,MAAM,QAAQ,CAAC;AAOlD,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAEpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAsB,qBAAqB,CAAC,EAC1C,IAAI,EAAE,QAAwB,EAC9B,OAAc,GACf,GAAE,cAAmB;;;;;;;;;;;;GAgDrB;AAED,wBAAsB,kBAAkB,CAAC,EACvC,IAAI,EAAE,QAAwB,EAC9B,OAAc,GACf,GAAE,cAAmB;;;;;;;;;;;;GAgDrB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type BrowserTargetSelection = string[] | {
|
|
2
|
+
name?: string;
|
|
3
|
+
browsers?: string[];
|
|
4
|
+
};
|
|
5
|
+
export declare function getBrowserTargetDetails(targetSelection?: BrowserTargetSelection, { root }?: {
|
|
6
|
+
root?: string;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
name: string | undefined;
|
|
9
|
+
browsers: string[];
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=browserslist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browserslist.d.ts","sourceRoot":"","sources":["../../../source/shared/browserslist.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAC9B,MAAM,EAAE,GACR;IACE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEN,wBAAsB,uBAAuB,CAC3C,eAAe,GAAE,sBAA2B,EAC5C,EAAC,IAAI,EAAC,GAAE;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAM;;;GAsB7B"}
|
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.16",
|
|
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
|
@@ -17,6 +17,10 @@ import type {MagicModuleEnvOptions} from './features/env.ts';
|
|
|
17
17
|
import {multiline} from './shared/strings.ts';
|
|
18
18
|
import {getNodePlugins, removeBuildFiles} from './shared/rollup.ts';
|
|
19
19
|
import {createMagicModulePlugin} from './shared/magic-module.ts';
|
|
20
|
+
import {
|
|
21
|
+
getBrowserTargetDetails,
|
|
22
|
+
type BrowserTargetSelection,
|
|
23
|
+
} from './shared/browserslist.ts';
|
|
20
24
|
|
|
21
25
|
export interface AppOptions {
|
|
22
26
|
/**
|
|
@@ -58,10 +62,10 @@ export interface AppBrowserOptions extends AppOptions {
|
|
|
58
62
|
/**
|
|
59
63
|
* The entry module for this browser. This should be an absolute path, or relative
|
|
60
64
|
* path from the root directory containing your project. This entry should be the
|
|
61
|
-
* browser entrypoint.
|
|
65
|
+
* browser entrypoint. If you don’t provide a module, Quilt will automatically pick
|
|
66
|
+
*
|
|
62
67
|
*
|
|
63
68
|
* @example './browser.tsx'
|
|
64
|
-
* @default 'quilt:module/entry'
|
|
65
69
|
*/
|
|
66
70
|
entry?: string;
|
|
67
71
|
|
|
@@ -102,12 +106,7 @@ export interface AppBrowserAssetsOptions {
|
|
|
102
106
|
minify?: boolean;
|
|
103
107
|
|
|
104
108
|
baseURL?: string;
|
|
105
|
-
targets?:
|
|
106
|
-
| string[]
|
|
107
|
-
| {
|
|
108
|
-
name?: string;
|
|
109
|
-
browsers?: string[];
|
|
110
|
-
};
|
|
109
|
+
targets?: BrowserTargetSelection;
|
|
111
110
|
priority?: number;
|
|
112
111
|
}
|
|
113
112
|
|
|
@@ -126,41 +125,21 @@ export async function quiltAppBrowser({
|
|
|
126
125
|
const minify = assets?.minify ?? mode === 'production';
|
|
127
126
|
const baseURL = assets?.baseURL ?? '/assets/';
|
|
128
127
|
|
|
129
|
-
const
|
|
130
|
-
const
|
|
131
|
-
? {
|
|
132
|
-
browsers: assetTargets,
|
|
133
|
-
}
|
|
134
|
-
: assetTargets;
|
|
135
|
-
const targetBrowsers =
|
|
136
|
-
targets.browsers ??
|
|
137
|
-
(await (async () => {
|
|
138
|
-
const {default: browserslist} = await import('browserslist');
|
|
139
|
-
const config = browserslist.findConfig(root);
|
|
140
|
-
|
|
141
|
-
if (config == null) return ['defaults'];
|
|
142
|
-
|
|
143
|
-
const targetName = targets.name ?? 'defaults';
|
|
144
|
-
return config[targetName] ?? ['defaults'];
|
|
145
|
-
})());
|
|
146
|
-
const normalizedTargetName =
|
|
147
|
-
targets.name === 'defaults' ? 'default' : targets.name;
|
|
148
|
-
const targetFilenamePart = normalizedTargetName
|
|
149
|
-
? `.${normalizedTargetName}`
|
|
150
|
-
: '';
|
|
128
|
+
const browserTarget = await getBrowserTargetDetails(assets?.targets, {root});
|
|
129
|
+
const targetFilenamePart = browserTarget.name ? `.${browserTarget.name}` : '';
|
|
151
130
|
|
|
152
131
|
const [
|
|
153
132
|
{visualizer},
|
|
154
|
-
{
|
|
133
|
+
{magicModuleEnv, replaceProcessEnv},
|
|
155
134
|
{sourceCode},
|
|
156
135
|
{createTSConfigAliasPlugin},
|
|
157
136
|
{css},
|
|
158
|
-
{rawAssets, staticAssets},
|
|
137
|
+
{assetManifest, rawAssets, staticAssets},
|
|
159
138
|
{systemJS},
|
|
160
139
|
nodePlugins,
|
|
161
140
|
] = await Promise.all([
|
|
162
141
|
import('rollup-plugin-visualizer'),
|
|
163
|
-
import('
|
|
142
|
+
import('./features/env.ts'),
|
|
164
143
|
import('./features/source-code.ts'),
|
|
165
144
|
import('./features/typescript.ts'),
|
|
166
145
|
import('./features/css.ts'),
|
|
@@ -172,7 +151,9 @@ export async function quiltAppBrowser({
|
|
|
172
151
|
const plugins: Plugin[] = [
|
|
173
152
|
...nodePlugins,
|
|
174
153
|
systemJS({minify}),
|
|
175
|
-
|
|
154
|
+
replaceProcessEnv({mode}),
|
|
155
|
+
magicModuleEnv({...env, mode}),
|
|
156
|
+
sourceCode({mode, targets: browserTarget.browsers}),
|
|
176
157
|
css({minify, emit: true}),
|
|
177
158
|
rawAssets(),
|
|
178
159
|
staticAssets({baseURL, emit: true}),
|
|
@@ -187,20 +168,6 @@ export async function quiltAppBrowser({
|
|
|
187
168
|
plugins.push(tsconfigAliases);
|
|
188
169
|
}
|
|
189
170
|
|
|
190
|
-
if (env) {
|
|
191
|
-
const {magicModuleEnv, replaceProcessEnv} = await import(
|
|
192
|
-
'./features/env.ts'
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
if (typeof env === 'boolean') {
|
|
196
|
-
plugins.push(replaceProcessEnv({mode}));
|
|
197
|
-
plugins.push(magicModuleEnv({mode}));
|
|
198
|
-
} else {
|
|
199
|
-
plugins.push(replaceProcessEnv({mode}));
|
|
200
|
-
plugins.push(magicModuleEnv({mode}));
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
171
|
const appEntry =
|
|
205
172
|
app ??
|
|
206
173
|
(await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
|
|
@@ -231,16 +198,17 @@ export async function quiltAppBrowser({
|
|
|
231
198
|
plugins.push(minify());
|
|
232
199
|
}
|
|
233
200
|
|
|
234
|
-
const cacheKey =
|
|
235
|
-
|
|
201
|
+
const cacheKey = browserTarget.name
|
|
202
|
+
? {browserTarget: browserTarget.name}
|
|
203
|
+
: undefined;
|
|
204
|
+
const id = browserTarget.name ? browserTarget.name : undefined;
|
|
236
205
|
|
|
237
206
|
plugins.push(
|
|
238
|
-
// @ts-expect-error The plugin still depends on Rollup 3
|
|
239
207
|
assetManifest({
|
|
240
208
|
id,
|
|
241
209
|
cacheKey,
|
|
242
|
-
|
|
243
|
-
|
|
210
|
+
baseURL,
|
|
211
|
+
file: path.resolve(`build/manifests/assets${targetFilenamePart}.json`),
|
|
244
212
|
priority: assets?.priority,
|
|
245
213
|
}),
|
|
246
214
|
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
|
|