@quilted/rollup 0.1.15 → 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 +6 -0
- package/build/cjs/app.cjs +18 -41
- package/build/cjs/index.cjs +2 -0
- package/build/cjs/module.cjs +155 -0
- package/build/cjs/shared/browserslist.cjs +25 -0
- package/build/esm/app.mjs +18 -41
- package/build/esm/index.mjs +1 -0
- package/build/esm/module.mjs +134 -0
- package/build/esm/shared/browserslist.mjs +23 -0
- package/build/esnext/app.esnext +18 -41
- package/build/esnext/index.esnext +1 -0
- package/build/esnext/module.esnext +134 -0
- 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/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/shared/browserslist.d.ts +11 -0
- package/build/typescript/shared/browserslist.d.ts.map +1 -0
- package/package.json +1 -1
- package/source/app.ts +18 -47
- package/source/index.ts +1 -0
- package/source/module.ts +223 -0
- package/source/shared/browserslist.ts +32 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
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
|
+
|
|
3
9
|
## 0.1.15
|
|
4
10
|
|
|
5
11
|
### 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,23 +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
|
|
52
|
+
}, {
|
|
53
|
+
magicModuleEnv,
|
|
54
|
+
replaceProcessEnv
|
|
62
55
|
}, {
|
|
63
56
|
sourceCode
|
|
64
57
|
}, {
|
|
@@ -71,12 +64,17 @@ async function quiltAppBrowser({
|
|
|
71
64
|
staticAssets
|
|
72
65
|
}, {
|
|
73
66
|
systemJS
|
|
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()]);
|
|
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()]);
|
|
75
68
|
const plugins = [...nodePlugins, systemJS({
|
|
76
69
|
minify
|
|
70
|
+
}), replaceProcessEnv({
|
|
71
|
+
mode
|
|
72
|
+
}), magicModuleEnv({
|
|
73
|
+
...env,
|
|
74
|
+
mode
|
|
77
75
|
}), sourceCode({
|
|
78
76
|
mode,
|
|
79
|
-
targets:
|
|
77
|
+
targets: browserTarget.browsers
|
|
80
78
|
}), css({
|
|
81
79
|
minify,
|
|
82
80
|
emit: true
|
|
@@ -90,27 +88,6 @@ async function quiltAppBrowser({
|
|
|
90
88
|
if (tsconfigAliases) {
|
|
91
89
|
plugins.push(tsconfigAliases);
|
|
92
90
|
}
|
|
93
|
-
if (env) {
|
|
94
|
-
const {
|
|
95
|
-
magicModuleEnv,
|
|
96
|
-
replaceProcessEnv
|
|
97
|
-
} = await Promise.resolve().then(function () { return require('./features/env.cjs'); });
|
|
98
|
-
if (typeof env === 'boolean') {
|
|
99
|
-
plugins.push(replaceProcessEnv({
|
|
100
|
-
mode
|
|
101
|
-
}));
|
|
102
|
-
plugins.push(magicModuleEnv({
|
|
103
|
-
mode
|
|
104
|
-
}));
|
|
105
|
-
} else {
|
|
106
|
-
plugins.push(replaceProcessEnv({
|
|
107
|
-
mode
|
|
108
|
-
}));
|
|
109
|
-
plugins.push(magicModuleEnv({
|
|
110
|
-
mode
|
|
111
|
-
}));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
91
|
const appEntry = app ?? (await glob.glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
|
|
115
92
|
cwd: root,
|
|
116
93
|
nodir: true,
|
|
@@ -136,10 +113,10 @@ async function quiltAppBrowser({
|
|
|
136
113
|
} = await import('rollup-plugin-esbuild');
|
|
137
114
|
plugins.push(minify());
|
|
138
115
|
}
|
|
139
|
-
const cacheKey =
|
|
140
|
-
browserTarget:
|
|
116
|
+
const cacheKey = browserTarget.name ? {
|
|
117
|
+
browserTarget: browserTarget.name
|
|
141
118
|
} : undefined;
|
|
142
|
-
const id =
|
|
119
|
+
const id = browserTarget.name ? browserTarget.name : undefined;
|
|
143
120
|
plugins.push(assetManifest({
|
|
144
121
|
id,
|
|
145
122
|
cacheKey,
|
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;
|
|
@@ -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,23 +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
|
|
30
|
+
}, {
|
|
31
|
+
magicModuleEnv,
|
|
32
|
+
replaceProcessEnv
|
|
40
33
|
}, {
|
|
41
34
|
sourceCode
|
|
42
35
|
}, {
|
|
@@ -49,12 +42,17 @@ async function quiltAppBrowser({
|
|
|
49
42
|
staticAssets
|
|
50
43
|
}, {
|
|
51
44
|
systemJS
|
|
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()]);
|
|
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()]);
|
|
53
46
|
const plugins = [...nodePlugins, systemJS({
|
|
54
47
|
minify
|
|
48
|
+
}), replaceProcessEnv({
|
|
49
|
+
mode
|
|
50
|
+
}), magicModuleEnv({
|
|
51
|
+
...env,
|
|
52
|
+
mode
|
|
55
53
|
}), sourceCode({
|
|
56
54
|
mode,
|
|
57
|
-
targets:
|
|
55
|
+
targets: browserTarget.browsers
|
|
58
56
|
}), css({
|
|
59
57
|
minify,
|
|
60
58
|
emit: true
|
|
@@ -68,27 +66,6 @@ async function quiltAppBrowser({
|
|
|
68
66
|
if (tsconfigAliases) {
|
|
69
67
|
plugins.push(tsconfigAliases);
|
|
70
68
|
}
|
|
71
|
-
if (env) {
|
|
72
|
-
const {
|
|
73
|
-
magicModuleEnv,
|
|
74
|
-
replaceProcessEnv
|
|
75
|
-
} = await import('./features/env.mjs');
|
|
76
|
-
if (typeof env === 'boolean') {
|
|
77
|
-
plugins.push(replaceProcessEnv({
|
|
78
|
-
mode
|
|
79
|
-
}));
|
|
80
|
-
plugins.push(magicModuleEnv({
|
|
81
|
-
mode
|
|
82
|
-
}));
|
|
83
|
-
} else {
|
|
84
|
-
plugins.push(replaceProcessEnv({
|
|
85
|
-
mode
|
|
86
|
-
}));
|
|
87
|
-
plugins.push(magicModuleEnv({
|
|
88
|
-
mode
|
|
89
|
-
}));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
69
|
const appEntry = app ?? (await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
|
|
93
70
|
cwd: root,
|
|
94
71
|
nodir: true,
|
|
@@ -114,10 +91,10 @@ async function quiltAppBrowser({
|
|
|
114
91
|
} = await import('rollup-plugin-esbuild');
|
|
115
92
|
plugins.push(minify());
|
|
116
93
|
}
|
|
117
|
-
const cacheKey =
|
|
118
|
-
browserTarget:
|
|
94
|
+
const cacheKey = browserTarget.name ? {
|
|
95
|
+
browserTarget: browserTarget.name
|
|
119
96
|
} : undefined;
|
|
120
|
-
const id =
|
|
97
|
+
const id = browserTarget.name ? browserTarget.name : undefined;
|
|
121
98
|
plugins.push(assetManifest({
|
|
122
99
|
id,
|
|
123
100
|
cacheKey,
|
package/build/esm/index.mjs
CHANGED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import { glob } from 'glob';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { getNodePlugins, removeBuildFiles } from './shared/rollup.mjs';
|
|
5
|
+
import { loadPackageJSON } from './shared/package-json.mjs';
|
|
6
|
+
import { getBrowserTargetDetails } from './shared/browserslist.mjs';
|
|
7
|
+
|
|
8
|
+
async function quiltModule({
|
|
9
|
+
root: rootPath = process.cwd(),
|
|
10
|
+
env,
|
|
11
|
+
assets,
|
|
12
|
+
graphql = true
|
|
13
|
+
} = {}) {
|
|
14
|
+
const root = typeof rootPath === 'string' ? rootPath : fileURLToPath(rootPath);
|
|
15
|
+
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
16
|
+
const outputDirectory = path.join(root, 'build/assets');
|
|
17
|
+
const minify = assets?.minify ?? true;
|
|
18
|
+
const hash = assets?.hash ?? true;
|
|
19
|
+
const hashFilenamePart = hash ? '.[hash]' : '';
|
|
20
|
+
const browserTarget = await getBrowserTargetDetails(assets?.targets, {
|
|
21
|
+
root
|
|
22
|
+
});
|
|
23
|
+
const targetFilenamePart = browserTarget.name ? `.${browserTarget.name}` : '';
|
|
24
|
+
const [{
|
|
25
|
+
visualizer
|
|
26
|
+
}, {
|
|
27
|
+
magicModuleEnv,
|
|
28
|
+
replaceProcessEnv
|
|
29
|
+
}, {
|
|
30
|
+
sourceCode
|
|
31
|
+
}, nodePlugins, packageJSON] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/env.mjs'), import('./features/source-code.mjs'), getNodePlugins(), loadPackageJSON(root)]);
|
|
32
|
+
const source = await sourceForPackage(root, packageJSON);
|
|
33
|
+
const plugins = [...nodePlugins, replaceProcessEnv({
|
|
34
|
+
mode
|
|
35
|
+
}), magicModuleEnv({
|
|
36
|
+
...env,
|
|
37
|
+
mode
|
|
38
|
+
}), sourceCode({
|
|
39
|
+
mode: 'production'
|
|
40
|
+
}), removeBuildFiles(['build/assets', 'build/reports'], {
|
|
41
|
+
root
|
|
42
|
+
})];
|
|
43
|
+
if (graphql) {
|
|
44
|
+
const {
|
|
45
|
+
graphql
|
|
46
|
+
} = await import('./features/graphql.mjs');
|
|
47
|
+
plugins.push(graphql({
|
|
48
|
+
manifest: false
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
if (minify) {
|
|
52
|
+
const {
|
|
53
|
+
minify
|
|
54
|
+
} = await import('rollup-plugin-esbuild');
|
|
55
|
+
plugins.push(minify());
|
|
56
|
+
}
|
|
57
|
+
plugins.push(visualizer({
|
|
58
|
+
template: 'treemap',
|
|
59
|
+
open: false,
|
|
60
|
+
brotliSize: true,
|
|
61
|
+
filename: path.resolve(root, `build/reports/bundle-visualizer${targetFilenamePart}.html`)
|
|
62
|
+
}));
|
|
63
|
+
return {
|
|
64
|
+
input: source.files,
|
|
65
|
+
plugins,
|
|
66
|
+
onwarn(warning, defaultWarn) {
|
|
67
|
+
// Removes annoying warnings for React-focused libraries that
|
|
68
|
+
// include 'use client' directives.
|
|
69
|
+
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
defaultWarn(warning);
|
|
73
|
+
},
|
|
74
|
+
output: {
|
|
75
|
+
format: 'esm',
|
|
76
|
+
dir: outputDirectory,
|
|
77
|
+
entryFileNames: `[name]${targetFilenamePart}${hashFilenamePart}.js`,
|
|
78
|
+
assetFileNames: `[name]${targetFilenamePart}${hashFilenamePart}.[ext]`
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
async function sourceForPackage(root, packageJSON) {
|
|
83
|
+
const [entries] = await Promise.all([sourceEntriesForPackage(root, packageJSON)]);
|
|
84
|
+
let sourceRoot = root;
|
|
85
|
+
const sourceEntryFiles = Object.values(entries);
|
|
86
|
+
for (const entry of sourceEntryFiles) {
|
|
87
|
+
if (!entry.startsWith(root)) continue;
|
|
88
|
+
sourceRoot = path.resolve(root, path.relative(root, entry).split(path.sep)[0] ?? '.');
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
root: sourceRoot,
|
|
93
|
+
files: sourceEntryFiles
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async function sourceEntriesForPackage(root, packageJSON) {
|
|
97
|
+
const {
|
|
98
|
+
main,
|
|
99
|
+
exports
|
|
100
|
+
} = packageJSON;
|
|
101
|
+
const entries = {};
|
|
102
|
+
if (typeof main === 'string') {
|
|
103
|
+
entries['.'] = await resolveTargetFileAsSource(main, root);
|
|
104
|
+
}
|
|
105
|
+
if (typeof exports === 'string') {
|
|
106
|
+
entries['.'] = await resolveTargetFileAsSource(exports, root);
|
|
107
|
+
return entries;
|
|
108
|
+
} else if (exports == null || typeof exports !== 'object') {
|
|
109
|
+
return entries;
|
|
110
|
+
}
|
|
111
|
+
for (const [exportPath, exportCondition] of Object.entries(exports)) {
|
|
112
|
+
let targetFile = null;
|
|
113
|
+
if (exportCondition == null) continue;
|
|
114
|
+
if (typeof exportCondition === 'string') {
|
|
115
|
+
targetFile = exportCondition;
|
|
116
|
+
} else {
|
|
117
|
+
targetFile ?? (targetFile = exportCondition['source'] ?? exportCondition['quilt:source'] ?? exportCondition['quilt:esnext'] ?? Object.values(exportCondition).find(condition => typeof condition === 'string' && condition.startsWith('./build/')));
|
|
118
|
+
}
|
|
119
|
+
if (targetFile == null) continue;
|
|
120
|
+
const sourceFile = await resolveTargetFileAsSource(targetFile, root);
|
|
121
|
+
entries[exportPath] = sourceFile;
|
|
122
|
+
}
|
|
123
|
+
return entries;
|
|
124
|
+
}
|
|
125
|
+
async function resolveTargetFileAsSource(file, root) {
|
|
126
|
+
const sourceFile = file.includes('/build/') ? (await glob(file.replace(/[/]build[/][^/]+[/]/, '/*/').replace(/(\.d\.ts|\.[\w]+)$/, '.*'), {
|
|
127
|
+
cwd: root,
|
|
128
|
+
absolute: true,
|
|
129
|
+
ignore: [path.resolve(root, file)]
|
|
130
|
+
}))[0] : path.resolve(root, file);
|
|
131
|
+
return sourceFile;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export { quiltModule };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
async function getBrowserTargetDetails(targetSelection = {}, {
|
|
2
|
+
root
|
|
3
|
+
} = {}) {
|
|
4
|
+
const targets = Array.isArray(targetSelection) ? {
|
|
5
|
+
browsers: targetSelection
|
|
6
|
+
} : targetSelection;
|
|
7
|
+
const targetBrowsers = targets.browsers ?? (await (async () => {
|
|
8
|
+
const {
|
|
9
|
+
default: browserslist
|
|
10
|
+
} = await import('browserslist');
|
|
11
|
+
const config = browserslist.findConfig(root);
|
|
12
|
+
if (config == null) return ['defaults'];
|
|
13
|
+
const targetName = targets.name ?? 'defaults';
|
|
14
|
+
return config[targetName] ?? ['defaults'];
|
|
15
|
+
})());
|
|
16
|
+
const name = targets.name === 'defaults' ? 'default' : targets.name;
|
|
17
|
+
return {
|
|
18
|
+
name,
|
|
19
|
+
browsers: targetBrowsers
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { getBrowserTargetDetails };
|
package/build/esnext/app.esnext
CHANGED
|
@@ -6,6 +6,7 @@ import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_REQUEST_RO
|
|
|
6
6
|
import { multiline } from './shared/strings.esnext';
|
|
7
7
|
import { getNodePlugins, removeBuildFiles } from './shared/rollup.esnext';
|
|
8
8
|
import { createMagicModulePlugin } from './shared/magic-module.esnext';
|
|
9
|
+
import { getBrowserTargetDetails } from './shared/browserslist.esnext';
|
|
9
10
|
|
|
10
11
|
async function quiltAppBrowser({
|
|
11
12
|
root: rootPath = process.cwd(),
|
|
@@ -20,23 +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
|
|
30
|
+
}, {
|
|
31
|
+
magicModuleEnv,
|
|
32
|
+
replaceProcessEnv
|
|
40
33
|
}, {
|
|
41
34
|
sourceCode
|
|
42
35
|
}, {
|
|
@@ -49,12 +42,17 @@ async function quiltAppBrowser({
|
|
|
49
42
|
staticAssets
|
|
50
43
|
}, {
|
|
51
44
|
systemJS
|
|
52
|
-
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/source-code.esnext'), import('./features/typescript.esnext'), import('./features/css.esnext'), import('./features/assets.esnext'), import('./features/system-js.esnext'), getNodePlugins()]);
|
|
45
|
+
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/env.esnext'), import('./features/source-code.esnext'), import('./features/typescript.esnext'), import('./features/css.esnext'), import('./features/assets.esnext'), import('./features/system-js.esnext'), getNodePlugins()]);
|
|
53
46
|
const plugins = [...nodePlugins, systemJS({
|
|
54
47
|
minify
|
|
48
|
+
}), replaceProcessEnv({
|
|
49
|
+
mode
|
|
50
|
+
}), magicModuleEnv({
|
|
51
|
+
...env,
|
|
52
|
+
mode
|
|
55
53
|
}), sourceCode({
|
|
56
54
|
mode,
|
|
57
|
-
targets:
|
|
55
|
+
targets: browserTarget.browsers
|
|
58
56
|
}), css({
|
|
59
57
|
minify,
|
|
60
58
|
emit: true
|
|
@@ -68,27 +66,6 @@ async function quiltAppBrowser({
|
|
|
68
66
|
if (tsconfigAliases) {
|
|
69
67
|
plugins.push(tsconfigAliases);
|
|
70
68
|
}
|
|
71
|
-
if (env) {
|
|
72
|
-
const {
|
|
73
|
-
magicModuleEnv,
|
|
74
|
-
replaceProcessEnv
|
|
75
|
-
} = await import('./features/env.esnext');
|
|
76
|
-
if (typeof env === 'boolean') {
|
|
77
|
-
plugins.push(replaceProcessEnv({
|
|
78
|
-
mode
|
|
79
|
-
}));
|
|
80
|
-
plugins.push(magicModuleEnv({
|
|
81
|
-
mode
|
|
82
|
-
}));
|
|
83
|
-
} else {
|
|
84
|
-
plugins.push(replaceProcessEnv({
|
|
85
|
-
mode
|
|
86
|
-
}));
|
|
87
|
-
plugins.push(magicModuleEnv({
|
|
88
|
-
mode
|
|
89
|
-
}));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
69
|
const appEntry = app ?? (await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
|
|
93
70
|
cwd: root,
|
|
94
71
|
nodir: true,
|
|
@@ -114,10 +91,10 @@ async function quiltAppBrowser({
|
|
|
114
91
|
} = await import('rollup-plugin-esbuild');
|
|
115
92
|
plugins.push(minify());
|
|
116
93
|
}
|
|
117
|
-
const cacheKey =
|
|
118
|
-
browserTarget:
|
|
94
|
+
const cacheKey = browserTarget.name ? {
|
|
95
|
+
browserTarget: browserTarget.name
|
|
119
96
|
} : undefined;
|
|
120
|
-
const id =
|
|
97
|
+
const id = browserTarget.name ? browserTarget.name : undefined;
|
|
121
98
|
plugins.push(assetManifest({
|
|
122
99
|
id,
|
|
123
100
|
cacheKey,
|