@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @quilted/rollup
|
|
2
2
|
|
|
3
|
+
## 0.1.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`ddd42cdd`](https://github.com/lemonmade/quilt/commit/ddd42cdd8c3e15a511579b327bde31c0234f4c16) Thanks [@lemonmade](https://github.com/lemonmade)! - Add module rollup plugin
|
|
8
|
+
|
|
9
|
+
## 0.1.15
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`750dd6b9`](https://github.com/lemonmade/quilt/commit/750dd6b9cb6a18648cc793f57579fb0b64cb23bc) Thanks [@lemonmade](https://github.com/lemonmade)! - Update Rollup dependencies
|
|
14
|
+
|
|
15
|
+
- [`750dd6b9`](https://github.com/lemonmade/quilt/commit/750dd6b9cb6a18648cc793f57579fb0b64cb23bc) Thanks [@lemonmade](https://github.com/lemonmade)! - Add GraphQL transforms to package rollup helpers
|
|
16
|
+
|
|
17
|
+
- [`750dd6b9`](https://github.com/lemonmade/quilt/commit/750dd6b9cb6a18648cc793f57579fb0b64cb23bc) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix invalid `esbuild` target
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`750dd6b9`](https://github.com/lemonmade/quilt/commit/750dd6b9cb6a18648cc793f57579fb0b64cb23bc)]:
|
|
20
|
+
- @quilted/assets@0.0.5
|
|
21
|
+
|
|
3
22
|
## 0.1.14
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/build/cjs/app.cjs
CHANGED
|
@@ -8,6 +8,7 @@ var constants = require('./constants.cjs');
|
|
|
8
8
|
var strings = require('./shared/strings.cjs');
|
|
9
9
|
var rollup = require('./shared/rollup.cjs');
|
|
10
10
|
var magicModule = require('./shared/magic-module.cjs');
|
|
11
|
+
var browserslist = require('./shared/browserslist.cjs');
|
|
11
12
|
|
|
12
13
|
function _interopNamespaceDefault(e) {
|
|
13
14
|
var n = Object.create(null);
|
|
@@ -42,25 +43,15 @@ async function quiltAppBrowser({
|
|
|
42
43
|
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
43
44
|
const minify = assets?.minify ?? mode === 'production';
|
|
44
45
|
const baseURL = assets?.baseURL ?? '/assets/';
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} :
|
|
49
|
-
const targetBrowsers = targets.browsers ?? (await (async () => {
|
|
50
|
-
const {
|
|
51
|
-
default: browserslist
|
|
52
|
-
} = await import('browserslist');
|
|
53
|
-
const config = browserslist.findConfig(root);
|
|
54
|
-
if (config == null) return ['defaults'];
|
|
55
|
-
const targetName = targets.name ?? 'defaults';
|
|
56
|
-
return config[targetName] ?? ['defaults'];
|
|
57
|
-
})());
|
|
58
|
-
const normalizedTargetName = targets.name === 'defaults' ? 'default' : targets.name;
|
|
59
|
-
const targetFilenamePart = normalizedTargetName ? `.${normalizedTargetName}` : '';
|
|
46
|
+
const browserTarget = await browserslist.getBrowserTargetDetails(assets?.targets, {
|
|
47
|
+
root
|
|
48
|
+
});
|
|
49
|
+
const targetFilenamePart = browserTarget.name ? `.${browserTarget.name}` : '';
|
|
60
50
|
const [{
|
|
61
51
|
visualizer
|
|
62
52
|
}, {
|
|
63
|
-
|
|
53
|
+
magicModuleEnv,
|
|
54
|
+
replaceProcessEnv
|
|
64
55
|
}, {
|
|
65
56
|
sourceCode
|
|
66
57
|
}, {
|
|
@@ -68,16 +59,22 @@ async function quiltAppBrowser({
|
|
|
68
59
|
}, {
|
|
69
60
|
css
|
|
70
61
|
}, {
|
|
62
|
+
assetManifest,
|
|
71
63
|
rawAssets,
|
|
72
64
|
staticAssets
|
|
73
65
|
}, {
|
|
74
66
|
systemJS
|
|
75
|
-
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'),
|
|
67
|
+
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), Promise.resolve().then(function () { return require('./features/env.cjs'); }), 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
68
|
const plugins = [...nodePlugins, systemJS({
|
|
77
69
|
minify
|
|
70
|
+
}), replaceProcessEnv({
|
|
71
|
+
mode
|
|
72
|
+
}), magicModuleEnv({
|
|
73
|
+
...env,
|
|
74
|
+
mode
|
|
78
75
|
}), sourceCode({
|
|
79
76
|
mode,
|
|
80
|
-
targets:
|
|
77
|
+
targets: browserTarget.browsers
|
|
81
78
|
}), css({
|
|
82
79
|
minify,
|
|
83
80
|
emit: true
|
|
@@ -91,27 +88,6 @@ async function quiltAppBrowser({
|
|
|
91
88
|
if (tsconfigAliases) {
|
|
92
89
|
plugins.push(tsconfigAliases);
|
|
93
90
|
}
|
|
94
|
-
if (env) {
|
|
95
|
-
const {
|
|
96
|
-
magicModuleEnv,
|
|
97
|
-
replaceProcessEnv
|
|
98
|
-
} = await Promise.resolve().then(function () { return require('./features/env.cjs'); });
|
|
99
|
-
if (typeof env === 'boolean') {
|
|
100
|
-
plugins.push(replaceProcessEnv({
|
|
101
|
-
mode
|
|
102
|
-
}));
|
|
103
|
-
plugins.push(magicModuleEnv({
|
|
104
|
-
mode
|
|
105
|
-
}));
|
|
106
|
-
} else {
|
|
107
|
-
plugins.push(replaceProcessEnv({
|
|
108
|
-
mode
|
|
109
|
-
}));
|
|
110
|
-
plugins.push(magicModuleEnv({
|
|
111
|
-
mode
|
|
112
|
-
}));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
91
|
const appEntry = app ?? (await glob.glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
|
|
116
92
|
cwd: root,
|
|
117
93
|
nodir: true,
|
|
@@ -137,17 +113,15 @@ async function quiltAppBrowser({
|
|
|
137
113
|
} = await import('rollup-plugin-esbuild');
|
|
138
114
|
plugins.push(minify());
|
|
139
115
|
}
|
|
140
|
-
const cacheKey =
|
|
141
|
-
browserTarget:
|
|
116
|
+
const cacheKey = browserTarget.name ? {
|
|
117
|
+
browserTarget: browserTarget.name
|
|
142
118
|
} : undefined;
|
|
143
|
-
const id =
|
|
144
|
-
plugins.push(
|
|
145
|
-
// @ts-expect-error The plugin still depends on Rollup 3
|
|
146
|
-
assetManifest({
|
|
119
|
+
const id = browserTarget.name ? browserTarget.name : undefined;
|
|
120
|
+
plugins.push(assetManifest({
|
|
147
121
|
id,
|
|
148
122
|
cacheKey,
|
|
149
|
-
|
|
150
|
-
|
|
123
|
+
baseURL,
|
|
124
|
+
file: path__namespace.resolve(`build/manifests/assets${targetFilenamePart}.json`),
|
|
151
125
|
priority: assets?.priority
|
|
152
126
|
}), visualizer({
|
|
153
127
|
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;
|
|
@@ -4,7 +4,8 @@ var node_module = require('node:module');
|
|
|
4
4
|
var babel = require('@rollup/plugin-babel');
|
|
5
5
|
var esbuild = require('rollup-plugin-esbuild');
|
|
6
6
|
|
|
7
|
-
|
|
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)));
|
|
8
9
|
function sourceCode({
|
|
9
10
|
mode,
|
|
10
11
|
targets,
|
|
@@ -13,7 +14,7 @@ function sourceCode({
|
|
|
13
14
|
if (!useBabel) {
|
|
14
15
|
return esbuild({
|
|
15
16
|
// Support very modern features
|
|
16
|
-
target: '
|
|
17
|
+
target: 'es2022',
|
|
17
18
|
jsx: 'automatic',
|
|
18
19
|
jsxImportSource: 'react',
|
|
19
20
|
exclude: 'node_modules/**'
|
|
@@ -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
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var app = require('./app.cjs');
|
|
4
|
+
var module$1 = require('./module.cjs');
|
|
4
5
|
var _package = require('./package.cjs');
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
exports.quiltAppBrowser = app.quiltAppBrowser;
|
|
9
10
|
exports.quiltAppServer = app.quiltAppServer;
|
|
11
|
+
exports.quiltModule = module$1.quiltModule;
|
|
10
12
|
exports.quiltPackageESModules = _package.quiltPackageESModules;
|
|
11
13
|
exports.quiltPackageESNext = _package.quiltPackageESNext;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('node:path');
|
|
4
|
+
var glob = require('glob');
|
|
5
|
+
var node_url = require('node:url');
|
|
6
|
+
var rollup = require('./shared/rollup.cjs');
|
|
7
|
+
var packageJson = require('./shared/package-json.cjs');
|
|
8
|
+
var browserslist = require('./shared/browserslist.cjs');
|
|
9
|
+
|
|
10
|
+
function _interopNamespaceDefault(e) {
|
|
11
|
+
var n = Object.create(null);
|
|
12
|
+
if (e) {
|
|
13
|
+
Object.keys(e).forEach(function (k) {
|
|
14
|
+
if (k !== 'default') {
|
|
15
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return e[k]; }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
n["default"] = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
28
|
+
|
|
29
|
+
async function quiltModule({
|
|
30
|
+
root: rootPath = process.cwd(),
|
|
31
|
+
env,
|
|
32
|
+
assets,
|
|
33
|
+
graphql = true
|
|
34
|
+
} = {}) {
|
|
35
|
+
const root = typeof rootPath === 'string' ? rootPath : node_url.fileURLToPath(rootPath);
|
|
36
|
+
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
37
|
+
const outputDirectory = path__namespace.join(root, 'build/assets');
|
|
38
|
+
const minify = assets?.minify ?? true;
|
|
39
|
+
const hash = assets?.hash ?? true;
|
|
40
|
+
const hashFilenamePart = hash ? '.[hash]' : '';
|
|
41
|
+
const browserTarget = await browserslist.getBrowserTargetDetails(assets?.targets, {
|
|
42
|
+
root
|
|
43
|
+
});
|
|
44
|
+
const targetFilenamePart = browserTarget.name ? `.${browserTarget.name}` : '';
|
|
45
|
+
const [{
|
|
46
|
+
visualizer
|
|
47
|
+
}, {
|
|
48
|
+
magicModuleEnv,
|
|
49
|
+
replaceProcessEnv
|
|
50
|
+
}, {
|
|
51
|
+
sourceCode
|
|
52
|
+
}, nodePlugins, packageJSON] = await Promise.all([import('rollup-plugin-visualizer'), Promise.resolve().then(function () { return require('./features/env.cjs'); }), Promise.resolve().then(function () { return require('./features/source-code.cjs'); }), rollup.getNodePlugins(), packageJson.loadPackageJSON(root)]);
|
|
53
|
+
const source = await sourceForPackage(root, packageJSON);
|
|
54
|
+
const plugins = [...nodePlugins, replaceProcessEnv({
|
|
55
|
+
mode
|
|
56
|
+
}), magicModuleEnv({
|
|
57
|
+
...env,
|
|
58
|
+
mode
|
|
59
|
+
}), sourceCode({
|
|
60
|
+
mode: 'production'
|
|
61
|
+
}), rollup.removeBuildFiles(['build/assets', 'build/reports'], {
|
|
62
|
+
root
|
|
63
|
+
})];
|
|
64
|
+
if (graphql) {
|
|
65
|
+
const {
|
|
66
|
+
graphql
|
|
67
|
+
} = await Promise.resolve().then(function () { return require('./features/graphql.cjs'); });
|
|
68
|
+
plugins.push(graphql({
|
|
69
|
+
manifest: false
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
if (minify) {
|
|
73
|
+
const {
|
|
74
|
+
minify
|
|
75
|
+
} = await import('rollup-plugin-esbuild');
|
|
76
|
+
plugins.push(minify());
|
|
77
|
+
}
|
|
78
|
+
plugins.push(visualizer({
|
|
79
|
+
template: 'treemap',
|
|
80
|
+
open: false,
|
|
81
|
+
brotliSize: true,
|
|
82
|
+
filename: path__namespace.resolve(root, `build/reports/bundle-visualizer${targetFilenamePart}.html`)
|
|
83
|
+
}));
|
|
84
|
+
return {
|
|
85
|
+
input: source.files,
|
|
86
|
+
plugins,
|
|
87
|
+
onwarn(warning, defaultWarn) {
|
|
88
|
+
// Removes annoying warnings for React-focused libraries that
|
|
89
|
+
// include 'use client' directives.
|
|
90
|
+
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
defaultWarn(warning);
|
|
94
|
+
},
|
|
95
|
+
output: {
|
|
96
|
+
format: 'esm',
|
|
97
|
+
dir: outputDirectory,
|
|
98
|
+
entryFileNames: `[name]${targetFilenamePart}${hashFilenamePart}.js`,
|
|
99
|
+
assetFileNames: `[name]${targetFilenamePart}${hashFilenamePart}.[ext]`
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
async function sourceForPackage(root, packageJSON) {
|
|
104
|
+
const [entries] = await Promise.all([sourceEntriesForPackage(root, packageJSON)]);
|
|
105
|
+
let sourceRoot = root;
|
|
106
|
+
const sourceEntryFiles = Object.values(entries);
|
|
107
|
+
for (const entry of sourceEntryFiles) {
|
|
108
|
+
if (!entry.startsWith(root)) continue;
|
|
109
|
+
sourceRoot = path__namespace.resolve(root, path__namespace.relative(root, entry).split(path__namespace.sep)[0] ?? '.');
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
root: sourceRoot,
|
|
114
|
+
files: sourceEntryFiles
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
async function sourceEntriesForPackage(root, packageJSON) {
|
|
118
|
+
const {
|
|
119
|
+
main,
|
|
120
|
+
exports
|
|
121
|
+
} = packageJSON;
|
|
122
|
+
const entries = {};
|
|
123
|
+
if (typeof main === 'string') {
|
|
124
|
+
entries['.'] = await resolveTargetFileAsSource(main, root);
|
|
125
|
+
}
|
|
126
|
+
if (typeof exports === 'string') {
|
|
127
|
+
entries['.'] = await resolveTargetFileAsSource(exports, root);
|
|
128
|
+
return entries;
|
|
129
|
+
} else if (exports == null || typeof exports !== 'object') {
|
|
130
|
+
return entries;
|
|
131
|
+
}
|
|
132
|
+
for (const [exportPath, exportCondition] of Object.entries(exports)) {
|
|
133
|
+
let targetFile = null;
|
|
134
|
+
if (exportCondition == null) continue;
|
|
135
|
+
if (typeof exportCondition === 'string') {
|
|
136
|
+
targetFile = exportCondition;
|
|
137
|
+
} else {
|
|
138
|
+
targetFile ?? (targetFile = exportCondition['source'] ?? exportCondition['quilt:source'] ?? exportCondition['quilt:esnext'] ?? Object.values(exportCondition).find(condition => typeof condition === 'string' && condition.startsWith('./build/')));
|
|
139
|
+
}
|
|
140
|
+
if (targetFile == null) continue;
|
|
141
|
+
const sourceFile = await resolveTargetFileAsSource(targetFile, root);
|
|
142
|
+
entries[exportPath] = sourceFile;
|
|
143
|
+
}
|
|
144
|
+
return entries;
|
|
145
|
+
}
|
|
146
|
+
async function resolveTargetFileAsSource(file, root) {
|
|
147
|
+
const sourceFile = file.includes('/build/') ? (await glob.glob(file.replace(/[/]build[/][^/]+[/]/, '/*/').replace(/(\.d\.ts|\.[\w]+)$/, '.*'), {
|
|
148
|
+
cwd: root,
|
|
149
|
+
absolute: true,
|
|
150
|
+
ignore: [path__namespace.resolve(root, file)]
|
|
151
|
+
}))[0] : path__namespace.resolve(root, file);
|
|
152
|
+
return sourceFile;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
exports.quiltModule = quiltModule;
|
package/build/cjs/package.cjs
CHANGED
|
@@ -26,7 +26,8 @@ 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');
|
|
@@ -39,6 +40,14 @@ async function quiltPackageESModules({
|
|
|
39
40
|
}), rollup.removeBuildFiles(['build/esm'], {
|
|
40
41
|
root
|
|
41
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
|
+
}
|
|
42
51
|
return {
|
|
43
52
|
input: source.files,
|
|
44
53
|
plugins,
|
|
@@ -61,7 +70,8 @@ async function quiltPackageESModules({
|
|
|
61
70
|
};
|
|
62
71
|
}
|
|
63
72
|
async function quiltPackageESNext({
|
|
64
|
-
root: rootPath = process.cwd()
|
|
73
|
+
root: rootPath = process.cwd(),
|
|
74
|
+
graphql = true
|
|
65
75
|
} = {}) {
|
|
66
76
|
const root = typeof rootPath === 'string' ? rootPath : node_url.fileURLToPath(rootPath);
|
|
67
77
|
const outputDirectory = path__namespace.join(root, 'build/esnext');
|
|
@@ -75,6 +85,14 @@ async function quiltPackageESNext({
|
|
|
75
85
|
}), rollup.removeBuildFiles(['build/esnext'], {
|
|
76
86
|
root
|
|
77
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
|
+
}
|
|
78
96
|
return {
|
|
79
97
|
input: source.files,
|
|
80
98
|
plugins,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
async function getBrowserTargetDetails(targetSelection = {}, {
|
|
4
|
+
root
|
|
5
|
+
} = {}) {
|
|
6
|
+
const targets = Array.isArray(targetSelection) ? {
|
|
7
|
+
browsers: targetSelection
|
|
8
|
+
} : targetSelection;
|
|
9
|
+
const targetBrowsers = targets.browsers ?? (await (async () => {
|
|
10
|
+
const {
|
|
11
|
+
default: browserslist
|
|
12
|
+
} = await import('browserslist');
|
|
13
|
+
const config = browserslist.findConfig(root);
|
|
14
|
+
if (config == null) return ['defaults'];
|
|
15
|
+
const targetName = targets.name ?? 'defaults';
|
|
16
|
+
return config[targetName] ?? ['defaults'];
|
|
17
|
+
})());
|
|
18
|
+
const name = targets.name === 'defaults' ? 'default' : targets.name;
|
|
19
|
+
return {
|
|
20
|
+
name,
|
|
21
|
+
browsers: targetBrowsers
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.getBrowserTargetDetails = getBrowserTargetDetails;
|
package/build/esm/app.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_REQUEST_RO
|
|
|
6
6
|
import { multiline } from './shared/strings.mjs';
|
|
7
7
|
import { getNodePlugins, removeBuildFiles } from './shared/rollup.mjs';
|
|
8
8
|
import { createMagicModulePlugin } from './shared/magic-module.mjs';
|
|
9
|
+
import { getBrowserTargetDetails } from './shared/browserslist.mjs';
|
|
9
10
|
|
|
10
11
|
async function quiltAppBrowser({
|
|
11
12
|
root: rootPath = process.cwd(),
|
|
@@ -20,25 +21,15 @@ async function quiltAppBrowser({
|
|
|
20
21
|
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
21
22
|
const minify = assets?.minify ?? mode === 'production';
|
|
22
23
|
const baseURL = assets?.baseURL ?? '/assets/';
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} :
|
|
27
|
-
const targetBrowsers = targets.browsers ?? (await (async () => {
|
|
28
|
-
const {
|
|
29
|
-
default: browserslist
|
|
30
|
-
} = await import('browserslist');
|
|
31
|
-
const config = browserslist.findConfig(root);
|
|
32
|
-
if (config == null) return ['defaults'];
|
|
33
|
-
const targetName = targets.name ?? 'defaults';
|
|
34
|
-
return config[targetName] ?? ['defaults'];
|
|
35
|
-
})());
|
|
36
|
-
const normalizedTargetName = targets.name === 'defaults' ? 'default' : targets.name;
|
|
37
|
-
const targetFilenamePart = normalizedTargetName ? `.${normalizedTargetName}` : '';
|
|
24
|
+
const browserTarget = await getBrowserTargetDetails(assets?.targets, {
|
|
25
|
+
root
|
|
26
|
+
});
|
|
27
|
+
const targetFilenamePart = browserTarget.name ? `.${browserTarget.name}` : '';
|
|
38
28
|
const [{
|
|
39
29
|
visualizer
|
|
40
30
|
}, {
|
|
41
|
-
|
|
31
|
+
magicModuleEnv,
|
|
32
|
+
replaceProcessEnv
|
|
42
33
|
}, {
|
|
43
34
|
sourceCode
|
|
44
35
|
}, {
|
|
@@ -46,16 +37,22 @@ async function quiltAppBrowser({
|
|
|
46
37
|
}, {
|
|
47
38
|
css
|
|
48
39
|
}, {
|
|
40
|
+
assetManifest,
|
|
49
41
|
rawAssets,
|
|
50
42
|
staticAssets
|
|
51
43
|
}, {
|
|
52
44
|
systemJS
|
|
53
|
-
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('
|
|
45
|
+
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/env.mjs'), import('./features/source-code.mjs'), import('./features/typescript.mjs'), import('./features/css.mjs'), import('./features/assets.mjs'), import('./features/system-js.mjs'), getNodePlugins()]);
|
|
54
46
|
const plugins = [...nodePlugins, systemJS({
|
|
55
47
|
minify
|
|
48
|
+
}), replaceProcessEnv({
|
|
49
|
+
mode
|
|
50
|
+
}), magicModuleEnv({
|
|
51
|
+
...env,
|
|
52
|
+
mode
|
|
56
53
|
}), sourceCode({
|
|
57
54
|
mode,
|
|
58
|
-
targets:
|
|
55
|
+
targets: browserTarget.browsers
|
|
59
56
|
}), css({
|
|
60
57
|
minify,
|
|
61
58
|
emit: true
|
|
@@ -69,27 +66,6 @@ async function quiltAppBrowser({
|
|
|
69
66
|
if (tsconfigAliases) {
|
|
70
67
|
plugins.push(tsconfigAliases);
|
|
71
68
|
}
|
|
72
|
-
if (env) {
|
|
73
|
-
const {
|
|
74
|
-
magicModuleEnv,
|
|
75
|
-
replaceProcessEnv
|
|
76
|
-
} = await import('./features/env.mjs');
|
|
77
|
-
if (typeof env === 'boolean') {
|
|
78
|
-
plugins.push(replaceProcessEnv({
|
|
79
|
-
mode
|
|
80
|
-
}));
|
|
81
|
-
plugins.push(magicModuleEnv({
|
|
82
|
-
mode
|
|
83
|
-
}));
|
|
84
|
-
} else {
|
|
85
|
-
plugins.push(replaceProcessEnv({
|
|
86
|
-
mode
|
|
87
|
-
}));
|
|
88
|
-
plugins.push(magicModuleEnv({
|
|
89
|
-
mode
|
|
90
|
-
}));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
69
|
const appEntry = app ?? (await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
|
|
94
70
|
cwd: root,
|
|
95
71
|
nodir: true,
|
|
@@ -115,17 +91,15 @@ async function quiltAppBrowser({
|
|
|
115
91
|
} = await import('rollup-plugin-esbuild');
|
|
116
92
|
plugins.push(minify());
|
|
117
93
|
}
|
|
118
|
-
const cacheKey =
|
|
119
|
-
browserTarget:
|
|
94
|
+
const cacheKey = browserTarget.name ? {
|
|
95
|
+
browserTarget: browserTarget.name
|
|
120
96
|
} : undefined;
|
|
121
|
-
const id =
|
|
122
|
-
plugins.push(
|
|
123
|
-
// @ts-expect-error The plugin still depends on Rollup 3
|
|
124
|
-
assetManifest({
|
|
97
|
+
const id = browserTarget.name ? browserTarget.name : undefined;
|
|
98
|
+
plugins.push(assetManifest({
|
|
125
99
|
id,
|
|
126
100
|
cacheKey,
|
|
127
|
-
|
|
128
|
-
|
|
101
|
+
baseURL,
|
|
102
|
+
file: path.resolve(`build/manifests/assets${targetFilenamePart}.json`),
|
|
129
103
|
priority: assets?.priority
|
|
130
104
|
}), visualizer({
|
|
131
105
|
template: 'treemap',
|