@quilted/rollup 0.1.8 → 0.1.10
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 +16 -0
- package/build/cjs/app.cjs +74 -13
- package/build/cjs/features/typescript.cjs +56 -0
- package/build/cjs/shared/rollup.cjs +39 -0
- package/build/esm/app.mjs +75 -14
- package/build/esm/features/typescript.mjs +34 -0
- package/build/esm/shared/rollup.mjs +20 -1
- package/build/esnext/app.esnext +75 -14
- package/build/esnext/features/typescript.esnext +34 -0
- package/build/esnext/shared/rollup.esnext +20 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts +6 -1
- package/build/typescript/app.d.ts.map +1 -1
- package/build/typescript/features/typescript.d.ts +4 -0
- package/build/typescript/features/typescript.d.ts.map +1 -0
- package/build/typescript/shared/rollup.d.ts +9 -3
- package/build/typescript/shared/rollup.d.ts.map +1 -1
- package/package.json +2 -1
- package/source/app.ts +99 -11
- package/source/features/typescript.ts +49 -0
- package/source/shared/rollup.ts +23 -1
package/build/esnext/app.esnext
CHANGED
|
@@ -1,27 +1,44 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import * as fs from 'node:fs/promises';
|
|
3
|
+
import { glob } from 'glob';
|
|
3
4
|
import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_REQUEST_ROUTER, MAGIC_MODULE_BROWSER_ASSETS } from './constants.esnext';
|
|
4
5
|
import { multiline } from './shared/strings.esnext';
|
|
5
|
-
import { getNodePlugins } from './shared/rollup.esnext';
|
|
6
|
+
import { getNodePlugins, removeBuildFiles } from './shared/rollup.esnext';
|
|
6
7
|
import { createMagicModulePlugin } from './shared/magic-module.esnext';
|
|
7
8
|
|
|
8
9
|
async function quiltAppBrowser({
|
|
9
10
|
app,
|
|
10
|
-
entry
|
|
11
|
+
entry,
|
|
11
12
|
env,
|
|
12
13
|
assets,
|
|
13
14
|
module,
|
|
14
15
|
graphql = true
|
|
15
16
|
} = {}) {
|
|
17
|
+
const root = process.cwd();
|
|
16
18
|
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
17
19
|
const minify = assets?.minify ?? mode === 'production';
|
|
18
20
|
const baseURL = assets?.baseURL ?? '/assets/';
|
|
21
|
+
const assetTargets = assets?.targets ?? {};
|
|
22
|
+
const targets = Array.isArray(assetTargets) ? {
|
|
23
|
+
browsers: assetTargets
|
|
24
|
+
} : assetTargets;
|
|
25
|
+
const targetBrowsers = targets.browsers ?? (await (async () => {
|
|
26
|
+
const {
|
|
27
|
+
default: browserslist
|
|
28
|
+
} = await import('browserslist');
|
|
29
|
+
const config = browserslist.findConfig(root);
|
|
30
|
+
if (config == null) return ['defaults'];
|
|
31
|
+
const targetName = targets.name ?? 'defaults';
|
|
32
|
+
return config[targetName] ?? ['defaults'];
|
|
33
|
+
})());
|
|
19
34
|
const [{
|
|
20
35
|
visualizer
|
|
21
36
|
}, {
|
|
22
37
|
assetManifest
|
|
23
38
|
}, {
|
|
24
39
|
sourceCode
|
|
40
|
+
}, {
|
|
41
|
+
createTSConfigAliasPlugin
|
|
25
42
|
}, {
|
|
26
43
|
css
|
|
27
44
|
}, {
|
|
@@ -29,18 +46,25 @@ async function quiltAppBrowser({
|
|
|
29
46
|
staticAssets
|
|
30
47
|
}, {
|
|
31
48
|
systemJS
|
|
32
|
-
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('@quilted/assets/rollup'), import('./features/source-code.esnext'), import('./features/css.esnext'), import('./features/assets.esnext'), import('./features/system-js.esnext'), getNodePlugins()]);
|
|
49
|
+
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('@quilted/assets/rollup'), import('./features/source-code.esnext'), import('./features/typescript.esnext'), import('./features/css.esnext'), import('./features/assets.esnext'), import('./features/system-js.esnext'), getNodePlugins()]);
|
|
33
50
|
const plugins = [...nodePlugins, systemJS({
|
|
34
51
|
minify
|
|
35
52
|
}), sourceCode({
|
|
36
|
-
mode
|
|
53
|
+
mode,
|
|
54
|
+
targets: targetBrowsers
|
|
37
55
|
}), css({
|
|
38
56
|
minify,
|
|
39
57
|
emit: true
|
|
40
58
|
}), rawAssets(), staticAssets({
|
|
41
59
|
baseURL,
|
|
42
60
|
emit: true
|
|
61
|
+
}), removeBuildFiles(['build/assets', 'build/manifests', 'build/reports'], {
|
|
62
|
+
root
|
|
43
63
|
})];
|
|
64
|
+
const tsconfigAliases = await createTSConfigAliasPlugin();
|
|
65
|
+
if (tsconfigAliases) {
|
|
66
|
+
plugins.push(tsconfigAliases);
|
|
67
|
+
}
|
|
44
68
|
if (env) {
|
|
45
69
|
const {
|
|
46
70
|
magicModuleEnv,
|
|
@@ -62,9 +86,14 @@ async function quiltAppBrowser({
|
|
|
62
86
|
}));
|
|
63
87
|
}
|
|
64
88
|
}
|
|
65
|
-
|
|
89
|
+
const appEntry = app ?? (await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
|
|
90
|
+
cwd: root,
|
|
91
|
+
nodir: true,
|
|
92
|
+
absolute: true
|
|
93
|
+
}).then(files => files[0]));
|
|
94
|
+
if (appEntry) {
|
|
66
95
|
plugins.push(magicModuleAppComponent({
|
|
67
|
-
entry:
|
|
96
|
+
entry: appEntry
|
|
68
97
|
}));
|
|
69
98
|
}
|
|
70
99
|
plugins.push(magicModuleAppBrowserEntry(module));
|
|
@@ -82,19 +111,31 @@ async function quiltAppBrowser({
|
|
|
82
111
|
} = await import('rollup-plugin-esbuild');
|
|
83
112
|
plugins.push(minify());
|
|
84
113
|
}
|
|
114
|
+
const cacheKey = targets.name ? {
|
|
115
|
+
browserTarget: targets.name
|
|
116
|
+
} : undefined;
|
|
117
|
+
const id = targets.name ? targets.name : undefined;
|
|
85
118
|
plugins.push(
|
|
86
119
|
// @ts-expect-error The plugin still depends on Rollup 3
|
|
87
120
|
assetManifest({
|
|
121
|
+
id,
|
|
122
|
+
cacheKey,
|
|
88
123
|
baseUrl: baseURL,
|
|
89
|
-
path: path.resolve(`build/manifests/assets.json`)
|
|
124
|
+
path: path.resolve(`build/manifests/assets.json`),
|
|
125
|
+
priority: assets?.priority
|
|
90
126
|
}), visualizer({
|
|
91
127
|
template: 'treemap',
|
|
92
128
|
open: false,
|
|
93
129
|
brotliSize: true,
|
|
94
130
|
filename: path.resolve(`build/reports/bundle-visualizer.html`)
|
|
95
131
|
}));
|
|
132
|
+
const finalEntry = entry ?? (await glob('{browser,client}.{ts,tsx,mjs,js,jsx}', {
|
|
133
|
+
cwd: root,
|
|
134
|
+
nodir: true,
|
|
135
|
+
absolute: true
|
|
136
|
+
}).then(files => files[0])) ?? MAGIC_MODULE_ENTRY;
|
|
96
137
|
return {
|
|
97
|
-
input:
|
|
138
|
+
input: finalEntry,
|
|
98
139
|
plugins,
|
|
99
140
|
onwarn(warning, defaultWarn) {
|
|
100
141
|
// Removes annoying warnings for React-focused libraries that
|
|
@@ -118,15 +159,18 @@ async function quiltAppBrowser({
|
|
|
118
159
|
async function quiltAppServer({
|
|
119
160
|
app,
|
|
120
161
|
env,
|
|
162
|
+
entry,
|
|
121
163
|
graphql = true,
|
|
122
|
-
entry = MAGIC_MODULE_ENTRY,
|
|
123
164
|
minify = false
|
|
124
165
|
} = {}) {
|
|
166
|
+
const root = process.cwd();
|
|
125
167
|
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
126
168
|
const [{
|
|
127
169
|
visualizer
|
|
128
170
|
}, {
|
|
129
171
|
sourceCode
|
|
172
|
+
}, {
|
|
173
|
+
createTSConfigAliasPlugin
|
|
130
174
|
}, {
|
|
131
175
|
css
|
|
132
176
|
}, {
|
|
@@ -134,15 +178,22 @@ async function quiltAppServer({
|
|
|
134
178
|
staticAssets
|
|
135
179
|
}, {
|
|
136
180
|
magicModuleRequestRouterEntry
|
|
137
|
-
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/source-code.esnext'), import('./features/css.esnext'), import('./features/assets.esnext'), import('./features/request-router.esnext'), getNodePlugins()]);
|
|
181
|
+
}, 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/request-router.esnext'), getNodePlugins()]);
|
|
138
182
|
const plugins = [...nodePlugins, sourceCode({
|
|
139
|
-
mode
|
|
183
|
+
mode,
|
|
184
|
+
targets: ['current node']
|
|
140
185
|
}), css({
|
|
141
186
|
emit: false,
|
|
142
187
|
minify
|
|
143
188
|
}), rawAssets(), staticAssets({
|
|
144
189
|
emit: false
|
|
190
|
+
}), removeBuildFiles(['build/server'], {
|
|
191
|
+
root
|
|
145
192
|
})];
|
|
193
|
+
const tsconfigAliases = await createTSConfigAliasPlugin();
|
|
194
|
+
if (tsconfigAliases) {
|
|
195
|
+
plugins.push(tsconfigAliases);
|
|
196
|
+
}
|
|
146
197
|
if (env) {
|
|
147
198
|
const {
|
|
148
199
|
magicModuleEnv,
|
|
@@ -164,9 +215,14 @@ async function quiltAppServer({
|
|
|
164
215
|
}));
|
|
165
216
|
}
|
|
166
217
|
}
|
|
167
|
-
|
|
218
|
+
const appEntry = app ?? (await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
|
|
219
|
+
cwd: root,
|
|
220
|
+
nodir: true,
|
|
221
|
+
absolute: true
|
|
222
|
+
}).then(files => files[0]));
|
|
223
|
+
if (appEntry) {
|
|
168
224
|
plugins.push(magicModuleAppComponent({
|
|
169
|
-
entry:
|
|
225
|
+
entry: appEntry
|
|
170
226
|
}));
|
|
171
227
|
}
|
|
172
228
|
plugins.push(magicModuleRequestRouterEntry());
|
|
@@ -194,8 +250,13 @@ async function quiltAppServer({
|
|
|
194
250
|
brotliSize: true,
|
|
195
251
|
filename: path.resolve(`build/reports/bundle-visualizer.html`)
|
|
196
252
|
}));
|
|
253
|
+
const finalEntry = entry ?? (await glob('{server,service,backend}.{ts,tsx,mjs,js,jsx}', {
|
|
254
|
+
cwd: root,
|
|
255
|
+
nodir: true,
|
|
256
|
+
absolute: true
|
|
257
|
+
}).then(files => files[0])) ?? MAGIC_MODULE_ENTRY;
|
|
197
258
|
return {
|
|
198
|
-
input:
|
|
259
|
+
input: finalEntry,
|
|
199
260
|
plugins,
|
|
200
261
|
onwarn(warning, defaultWarn) {
|
|
201
262
|
// Removes annoying warnings for React-focused libraries that
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
|
|
4
|
+
async function createTSConfigAliasPlugin({
|
|
5
|
+
root = process.cwd()
|
|
6
|
+
} = {}) {
|
|
7
|
+
const [{
|
|
8
|
+
default: alias
|
|
9
|
+
}, tsconfig] = await Promise.all([import('@rollup/plugin-alias'), getTSConfig(root)]);
|
|
10
|
+
const tsconfigPaths = tsconfig?.compilerOptions?.paths;
|
|
11
|
+
if (tsconfigPaths == null) return undefined;
|
|
12
|
+
return alias({
|
|
13
|
+
entries: Object.entries(tsconfigPaths).map(([name, aliases]) => {
|
|
14
|
+
return {
|
|
15
|
+
find: name.includes('*') ? new RegExp(`^${name.replace(/\*/, '(.*)')}$`) : name,
|
|
16
|
+
replacement: aliases[0].replace('*', '$1')
|
|
17
|
+
};
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async function getTSConfig(root) {
|
|
22
|
+
const tsconfigPath = path.join(root, 'tsconfig.json');
|
|
23
|
+
if (!fs.existsSync(tsconfigPath)) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const tsconfig = JSON.parse(await fs.promises.readFile(tsconfigPath, 'utf8'));
|
|
28
|
+
return tsconfig;
|
|
29
|
+
} catch {
|
|
30
|
+
// intentional noop
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { createTSConfigAliasPlugin };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import { glob } from 'glob';
|
|
1
3
|
import replace from '@rollup/plugin-replace';
|
|
2
4
|
|
|
3
5
|
function smartReplace(values, options) {
|
|
@@ -9,6 +11,23 @@ function smartReplace(values, options) {
|
|
|
9
11
|
values
|
|
10
12
|
});
|
|
11
13
|
}
|
|
14
|
+
function removeBuildFiles(patterns, {
|
|
15
|
+
root = process.cwd()
|
|
16
|
+
} = {}) {
|
|
17
|
+
return {
|
|
18
|
+
name: '@quilt/remove-build-files',
|
|
19
|
+
async buildStart() {
|
|
20
|
+
const matches = await glob(patterns, {
|
|
21
|
+
cwd: root,
|
|
22
|
+
absolute: true
|
|
23
|
+
});
|
|
24
|
+
await Promise.all(matches.map(file => fs.rm(file, {
|
|
25
|
+
recursive: true,
|
|
26
|
+
force: true
|
|
27
|
+
})));
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
12
31
|
async function getNodePlugins() {
|
|
13
32
|
const [{
|
|
14
33
|
default: commonjs
|
|
@@ -27,4 +46,4 @@ async function getNodePlugins() {
|
|
|
27
46
|
}), commonjs(), json()];
|
|
28
47
|
}
|
|
29
48
|
|
|
30
|
-
export { getNodePlugins, smartReplace };
|
|
49
|
+
export { getNodePlugins, removeBuildFiles, smartReplace };
|