@quilted/rollup 0.1.7 → 0.1.9
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 +94 -10
- package/build/cjs/features/typescript.cjs +56 -0
- package/build/esm/app.mjs +93 -11
- package/build/esm/features/typescript.mjs +34 -0
- package/build/esnext/app.esnext +93 -11
- package/build/esnext/features/typescript.esnext +34 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts +2 -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/package.json +1 -1
- package/source/app.ts +75 -8
- package/source/features/typescript.ts +49 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @quilted/rollup
|
|
2
2
|
|
|
3
|
+
## 0.1.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`afadefe6`](https://github.com/lemonmade/quilt/commit/afadefe6d6fc6b62c17bbc318f9c13c50ef50b7b) Thanks [@lemonmade](https://github.com/lemonmade)! - Add automatic detection of entrypoints
|
|
8
|
+
|
|
9
|
+
- [`36751497`](https://github.com/lemonmade/quilt/commit/36751497d36fd9bea227c2baf55a302d54468863) Thanks [@lemonmade](https://github.com/lemonmade)! - Add tsconfig aliases plugin
|
|
10
|
+
|
|
11
|
+
## 0.1.8
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`86430876`](https://github.com/lemonmade/quilt/commit/864308760c9105cfe4b403ea54916c314af0e50b) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix asset manifest plugins
|
|
16
|
+
|
|
17
|
+
- [`e2038611`](https://github.com/lemonmade/quilt/commit/e203861184c39bc008ed7358f541944aa7db1cdd) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix 'use client' directive in server builds
|
|
18
|
+
|
|
3
19
|
## 0.1.7
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/build/cjs/app.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var path = require('node:path');
|
|
4
|
+
var fs = require('node:fs/promises');
|
|
5
|
+
var glob = require('glob');
|
|
4
6
|
var constants = require('./constants.cjs');
|
|
5
7
|
var strings = require('./shared/strings.cjs');
|
|
6
8
|
var rollup = require('./shared/rollup.cjs');
|
|
@@ -24,15 +26,17 @@ function _interopNamespaceDefault(e) {
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
29
|
+
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
27
30
|
|
|
28
31
|
async function quiltAppBrowser({
|
|
29
32
|
app,
|
|
30
|
-
entry
|
|
33
|
+
entry,
|
|
31
34
|
env,
|
|
32
35
|
assets,
|
|
33
36
|
module,
|
|
34
37
|
graphql = true
|
|
35
38
|
} = {}) {
|
|
39
|
+
const root = process.cwd();
|
|
36
40
|
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
37
41
|
const minify = assets?.minify ?? mode === 'production';
|
|
38
42
|
const baseURL = assets?.baseURL ?? '/assets/';
|
|
@@ -42,6 +46,8 @@ async function quiltAppBrowser({
|
|
|
42
46
|
assetManifest
|
|
43
47
|
}, {
|
|
44
48
|
sourceCode
|
|
49
|
+
}, {
|
|
50
|
+
createTSConfigAliasPlugin
|
|
45
51
|
}, {
|
|
46
52
|
css
|
|
47
53
|
}, {
|
|
@@ -49,7 +55,7 @@ async function quiltAppBrowser({
|
|
|
49
55
|
staticAssets
|
|
50
56
|
}, {
|
|
51
57
|
systemJS
|
|
52
|
-
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('@quilted/assets/rollup'), Promise.resolve().then(function () { return require('./features/source-code.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()]);
|
|
58
|
+
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('@quilted/assets/rollup'), 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()]);
|
|
53
59
|
const plugins = [...nodePlugins, systemJS({
|
|
54
60
|
minify
|
|
55
61
|
}), sourceCode({
|
|
@@ -61,6 +67,10 @@ async function quiltAppBrowser({
|
|
|
61
67
|
baseURL,
|
|
62
68
|
emit: true
|
|
63
69
|
})];
|
|
70
|
+
const tsconfigAliases = await createTSConfigAliasPlugin();
|
|
71
|
+
if (tsconfigAliases) {
|
|
72
|
+
plugins.push(tsconfigAliases);
|
|
73
|
+
}
|
|
64
74
|
if (env) {
|
|
65
75
|
const {
|
|
66
76
|
magicModuleEnv,
|
|
@@ -82,9 +92,14 @@ async function quiltAppBrowser({
|
|
|
82
92
|
}));
|
|
83
93
|
}
|
|
84
94
|
}
|
|
85
|
-
|
|
95
|
+
const appEntry = app ?? (await glob.glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
|
|
96
|
+
cwd: root,
|
|
97
|
+
nodir: true,
|
|
98
|
+
absolute: true
|
|
99
|
+
}).then(files => files[0]));
|
|
100
|
+
if (appEntry) {
|
|
86
101
|
plugins.push(magicModuleAppComponent({
|
|
87
|
-
entry:
|
|
102
|
+
entry: appEntry
|
|
88
103
|
}));
|
|
89
104
|
}
|
|
90
105
|
plugins.push(magicModuleAppBrowserEntry(module));
|
|
@@ -113,8 +128,13 @@ async function quiltAppBrowser({
|
|
|
113
128
|
brotliSize: true,
|
|
114
129
|
filename: path__namespace.resolve(`build/reports/bundle-visualizer.html`)
|
|
115
130
|
}));
|
|
131
|
+
const finalEntry = entry ?? (await glob.glob('browser.{ts,tsx,mjs,js,jsx}', {
|
|
132
|
+
cwd: root,
|
|
133
|
+
nodir: true,
|
|
134
|
+
absolute: true
|
|
135
|
+
}).then(files => files[0])) ?? constants.MAGIC_MODULE_ENTRY;
|
|
116
136
|
return {
|
|
117
|
-
input:
|
|
137
|
+
input: finalEntry,
|
|
118
138
|
plugins,
|
|
119
139
|
onwarn(warning, defaultWarn) {
|
|
120
140
|
// Removes annoying warnings for React-focused libraries that
|
|
@@ -138,15 +158,18 @@ async function quiltAppBrowser({
|
|
|
138
158
|
async function quiltAppServer({
|
|
139
159
|
app,
|
|
140
160
|
env,
|
|
161
|
+
entry,
|
|
141
162
|
graphql = true,
|
|
142
|
-
entry = constants.MAGIC_MODULE_ENTRY,
|
|
143
163
|
minify = false
|
|
144
164
|
} = {}) {
|
|
165
|
+
const root = process.cwd();
|
|
145
166
|
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
146
167
|
const [{
|
|
147
168
|
visualizer
|
|
148
169
|
}, {
|
|
149
170
|
sourceCode
|
|
171
|
+
}, {
|
|
172
|
+
createTSConfigAliasPlugin
|
|
150
173
|
}, {
|
|
151
174
|
css
|
|
152
175
|
}, {
|
|
@@ -154,7 +177,7 @@ async function quiltAppServer({
|
|
|
154
177
|
staticAssets
|
|
155
178
|
}, {
|
|
156
179
|
magicModuleRequestRouterEntry
|
|
157
|
-
}, 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/css.cjs'); }), Promise.resolve().then(function () { return require('./features/assets.cjs'); }), Promise.resolve().then(function () { return require('./features/request-router.cjs'); }), rollup.getNodePlugins()]);
|
|
180
|
+
}, 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/request-router.cjs'); }), rollup.getNodePlugins()]);
|
|
158
181
|
const plugins = [...nodePlugins, sourceCode({
|
|
159
182
|
mode
|
|
160
183
|
}), css({
|
|
@@ -163,6 +186,10 @@ async function quiltAppServer({
|
|
|
163
186
|
}), rawAssets(), staticAssets({
|
|
164
187
|
emit: false
|
|
165
188
|
})];
|
|
189
|
+
const tsconfigAliases = await createTSConfigAliasPlugin();
|
|
190
|
+
if (tsconfigAliases) {
|
|
191
|
+
plugins.push(tsconfigAliases);
|
|
192
|
+
}
|
|
166
193
|
if (env) {
|
|
167
194
|
const {
|
|
168
195
|
magicModuleEnv,
|
|
@@ -184,15 +211,21 @@ async function quiltAppServer({
|
|
|
184
211
|
}));
|
|
185
212
|
}
|
|
186
213
|
}
|
|
187
|
-
|
|
214
|
+
const appEntry = app ?? (await glob.glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
|
|
215
|
+
cwd: root,
|
|
216
|
+
nodir: true,
|
|
217
|
+
absolute: true
|
|
218
|
+
}).then(files => files[0]));
|
|
219
|
+
if (appEntry) {
|
|
188
220
|
plugins.push(magicModuleAppComponent({
|
|
189
|
-
entry:
|
|
221
|
+
entry: appEntry
|
|
190
222
|
}));
|
|
191
223
|
}
|
|
192
224
|
plugins.push(magicModuleRequestRouterEntry());
|
|
193
225
|
plugins.push(magicModuleAppRequestRouter({
|
|
194
226
|
entry
|
|
195
227
|
}));
|
|
228
|
+
plugins.push(magicModuleAppAssetManifests());
|
|
196
229
|
if (graphql) {
|
|
197
230
|
const {
|
|
198
231
|
graphql
|
|
@@ -213,9 +246,22 @@ async function quiltAppServer({
|
|
|
213
246
|
brotliSize: true,
|
|
214
247
|
filename: path__namespace.resolve(`build/reports/bundle-visualizer.html`)
|
|
215
248
|
}));
|
|
249
|
+
const finalEntry = entry ?? (await glob.glob('server.{ts,tsx,mjs,js,jsx}', {
|
|
250
|
+
cwd: root,
|
|
251
|
+
nodir: true,
|
|
252
|
+
absolute: true
|
|
253
|
+
}).then(files => files[0])) ?? constants.MAGIC_MODULE_ENTRY;
|
|
216
254
|
return {
|
|
217
|
-
input:
|
|
255
|
+
input: finalEntry,
|
|
218
256
|
plugins,
|
|
257
|
+
onwarn(warning, defaultWarn) {
|
|
258
|
+
// Removes annoying warnings for React-focused libraries that
|
|
259
|
+
// include 'use client' directives.
|
|
260
|
+
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
defaultWarn(warning);
|
|
264
|
+
},
|
|
219
265
|
output: {
|
|
220
266
|
// format: isESM ? 'esm' : 'systemjs',
|
|
221
267
|
format: 'esm',
|
|
@@ -294,6 +340,43 @@ function magicModuleAppBrowserEntry({
|
|
|
294
340
|
}
|
|
295
341
|
});
|
|
296
342
|
}
|
|
343
|
+
function magicModuleAppAssetManifests() {
|
|
344
|
+
return magicModule.createMagicModulePlugin({
|
|
345
|
+
name: '@quilted/magic-module/asset-manifests',
|
|
346
|
+
module: constants.MAGIC_MODULE_BROWSER_ASSETS,
|
|
347
|
+
async source() {
|
|
348
|
+
const {
|
|
349
|
+
glob
|
|
350
|
+
} = await import('glob');
|
|
351
|
+
const manifestFiles = await glob('assets*.json', {
|
|
352
|
+
nodir: true,
|
|
353
|
+
absolute: true,
|
|
354
|
+
cwd: path__namespace.resolve(`build/manifests`)
|
|
355
|
+
});
|
|
356
|
+
const manifests = await Promise.all(manifestFiles.map(async file => JSON.parse(await fs__namespace.readFile(file, 'utf8'))));
|
|
357
|
+
manifests.sort((manifestA, manifestB) => (manifestA.priority ?? 0) - (manifestB.priority ?? 0));
|
|
358
|
+
return strings.multiline`
|
|
359
|
+
import {BrowserAssetsFromManifests} from '@quilted/quilt/server';
|
|
360
|
+
|
|
361
|
+
export class BrowserAssets extends BrowserAssetsFromManifests {
|
|
362
|
+
constructor() {
|
|
363
|
+
const manifests = JSON.parse(${JSON.stringify(JSON.stringify(manifests))});
|
|
364
|
+
|
|
365
|
+
// The default manifest is the last one, since it has the widest browser support.
|
|
366
|
+
const defaultManifest = manifests.at(-1);
|
|
367
|
+
|
|
368
|
+
super(manifests, {
|
|
369
|
+
defaultManifest,
|
|
370
|
+
cacheKey(request) {
|
|
371
|
+
return {};
|
|
372
|
+
},
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
`;
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|
|
297
380
|
const FRAMEWORK_CHUNK_NAME = 'framework';
|
|
298
381
|
const POLYFILLS_CHUNK_NAME = 'polyfills';
|
|
299
382
|
const VENDOR_CHUNK_NAME = 'vendor';
|
|
@@ -361,6 +444,7 @@ function createManualChunksSorter() {
|
|
|
361
444
|
};
|
|
362
445
|
}
|
|
363
446
|
|
|
447
|
+
exports.magicModuleAppAssetManifests = magicModuleAppAssetManifests;
|
|
364
448
|
exports.magicModuleAppBrowserEntry = magicModuleAppBrowserEntry;
|
|
365
449
|
exports.magicModuleAppComponent = magicModuleAppComponent;
|
|
366
450
|
exports.magicModuleAppRequestRouter = magicModuleAppRequestRouter;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('node:path');
|
|
4
|
+
var fs = require('node:fs');
|
|
5
|
+
|
|
6
|
+
function _interopNamespaceDefault(e) {
|
|
7
|
+
var n = Object.create(null);
|
|
8
|
+
if (e) {
|
|
9
|
+
Object.keys(e).forEach(function (k) {
|
|
10
|
+
if (k !== 'default') {
|
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
n["default"] = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
24
|
+
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
25
|
+
|
|
26
|
+
async function createTSConfigAliasPlugin({
|
|
27
|
+
root = process.cwd()
|
|
28
|
+
} = {}) {
|
|
29
|
+
const [{
|
|
30
|
+
default: alias
|
|
31
|
+
}, tsconfig] = await Promise.all([import('@rollup/plugin-alias'), getTSConfig(root)]);
|
|
32
|
+
const tsconfigPaths = tsconfig?.compilerOptions?.paths;
|
|
33
|
+
if (tsconfigPaths == null) return undefined;
|
|
34
|
+
return alias({
|
|
35
|
+
entries: Object.entries(tsconfigPaths).map(([name, aliases]) => {
|
|
36
|
+
return {
|
|
37
|
+
find: name.includes('*') ? new RegExp(`^${name.replace(/\*/, '(.*)')}$`) : name,
|
|
38
|
+
replacement: aliases[0].replace('*', '$1')
|
|
39
|
+
};
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async function getTSConfig(root) {
|
|
44
|
+
const tsconfigPath = path__namespace.join(root, 'tsconfig.json');
|
|
45
|
+
if (!fs__namespace.existsSync(tsconfigPath)) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const tsconfig = JSON.parse(await fs__namespace.promises.readFile(tsconfigPath, 'utf8'));
|
|
50
|
+
return tsconfig;
|
|
51
|
+
} catch {
|
|
52
|
+
// intentional noop
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exports.createTSConfigAliasPlugin = createTSConfigAliasPlugin;
|
package/build/esm/app.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
|
+
import * as fs from 'node:fs/promises';
|
|
3
|
+
import { glob } from 'glob';
|
|
2
4
|
import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_REQUEST_ROUTER, MAGIC_MODULE_BROWSER_ASSETS } from './constants.mjs';
|
|
3
5
|
import { multiline } from './shared/strings.mjs';
|
|
4
6
|
import { getNodePlugins } from './shared/rollup.mjs';
|
|
@@ -6,12 +8,13 @@ import { createMagicModulePlugin } from './shared/magic-module.mjs';
|
|
|
6
8
|
|
|
7
9
|
async function quiltAppBrowser({
|
|
8
10
|
app,
|
|
9
|
-
entry
|
|
11
|
+
entry,
|
|
10
12
|
env,
|
|
11
13
|
assets,
|
|
12
14
|
module,
|
|
13
15
|
graphql = true
|
|
14
16
|
} = {}) {
|
|
17
|
+
const root = process.cwd();
|
|
15
18
|
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
16
19
|
const minify = assets?.minify ?? mode === 'production';
|
|
17
20
|
const baseURL = assets?.baseURL ?? '/assets/';
|
|
@@ -21,6 +24,8 @@ async function quiltAppBrowser({
|
|
|
21
24
|
assetManifest
|
|
22
25
|
}, {
|
|
23
26
|
sourceCode
|
|
27
|
+
}, {
|
|
28
|
+
createTSConfigAliasPlugin
|
|
24
29
|
}, {
|
|
25
30
|
css
|
|
26
31
|
}, {
|
|
@@ -28,7 +33,7 @@ async function quiltAppBrowser({
|
|
|
28
33
|
staticAssets
|
|
29
34
|
}, {
|
|
30
35
|
systemJS
|
|
31
|
-
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('@quilted/assets/rollup'), import('./features/source-code.mjs'), import('./features/css.mjs'), import('./features/assets.mjs'), import('./features/system-js.mjs'), getNodePlugins()]);
|
|
36
|
+
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('@quilted/assets/rollup'), import('./features/source-code.mjs'), import('./features/typescript.mjs'), import('./features/css.mjs'), import('./features/assets.mjs'), import('./features/system-js.mjs'), getNodePlugins()]);
|
|
32
37
|
const plugins = [...nodePlugins, systemJS({
|
|
33
38
|
minify
|
|
34
39
|
}), sourceCode({
|
|
@@ -40,6 +45,10 @@ async function quiltAppBrowser({
|
|
|
40
45
|
baseURL,
|
|
41
46
|
emit: true
|
|
42
47
|
})];
|
|
48
|
+
const tsconfigAliases = await createTSConfigAliasPlugin();
|
|
49
|
+
if (tsconfigAliases) {
|
|
50
|
+
plugins.push(tsconfigAliases);
|
|
51
|
+
}
|
|
43
52
|
if (env) {
|
|
44
53
|
const {
|
|
45
54
|
magicModuleEnv,
|
|
@@ -61,9 +70,14 @@ async function quiltAppBrowser({
|
|
|
61
70
|
}));
|
|
62
71
|
}
|
|
63
72
|
}
|
|
64
|
-
|
|
73
|
+
const appEntry = app ?? (await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
|
|
74
|
+
cwd: root,
|
|
75
|
+
nodir: true,
|
|
76
|
+
absolute: true
|
|
77
|
+
}).then(files => files[0]));
|
|
78
|
+
if (appEntry) {
|
|
65
79
|
plugins.push(magicModuleAppComponent({
|
|
66
|
-
entry:
|
|
80
|
+
entry: appEntry
|
|
67
81
|
}));
|
|
68
82
|
}
|
|
69
83
|
plugins.push(magicModuleAppBrowserEntry(module));
|
|
@@ -92,8 +106,13 @@ async function quiltAppBrowser({
|
|
|
92
106
|
brotliSize: true,
|
|
93
107
|
filename: path.resolve(`build/reports/bundle-visualizer.html`)
|
|
94
108
|
}));
|
|
109
|
+
const finalEntry = entry ?? (await glob('browser.{ts,tsx,mjs,js,jsx}', {
|
|
110
|
+
cwd: root,
|
|
111
|
+
nodir: true,
|
|
112
|
+
absolute: true
|
|
113
|
+
}).then(files => files[0])) ?? MAGIC_MODULE_ENTRY;
|
|
95
114
|
return {
|
|
96
|
-
input:
|
|
115
|
+
input: finalEntry,
|
|
97
116
|
plugins,
|
|
98
117
|
onwarn(warning, defaultWarn) {
|
|
99
118
|
// Removes annoying warnings for React-focused libraries that
|
|
@@ -117,15 +136,18 @@ async function quiltAppBrowser({
|
|
|
117
136
|
async function quiltAppServer({
|
|
118
137
|
app,
|
|
119
138
|
env,
|
|
139
|
+
entry,
|
|
120
140
|
graphql = true,
|
|
121
|
-
entry = MAGIC_MODULE_ENTRY,
|
|
122
141
|
minify = false
|
|
123
142
|
} = {}) {
|
|
143
|
+
const root = process.cwd();
|
|
124
144
|
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
125
145
|
const [{
|
|
126
146
|
visualizer
|
|
127
147
|
}, {
|
|
128
148
|
sourceCode
|
|
149
|
+
}, {
|
|
150
|
+
createTSConfigAliasPlugin
|
|
129
151
|
}, {
|
|
130
152
|
css
|
|
131
153
|
}, {
|
|
@@ -133,7 +155,7 @@ async function quiltAppServer({
|
|
|
133
155
|
staticAssets
|
|
134
156
|
}, {
|
|
135
157
|
magicModuleRequestRouterEntry
|
|
136
|
-
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/source-code.mjs'), import('./features/css.mjs'), import('./features/assets.mjs'), import('./features/request-router.mjs'), getNodePlugins()]);
|
|
158
|
+
}, 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/request-router.mjs'), getNodePlugins()]);
|
|
137
159
|
const plugins = [...nodePlugins, sourceCode({
|
|
138
160
|
mode
|
|
139
161
|
}), css({
|
|
@@ -142,6 +164,10 @@ async function quiltAppServer({
|
|
|
142
164
|
}), rawAssets(), staticAssets({
|
|
143
165
|
emit: false
|
|
144
166
|
})];
|
|
167
|
+
const tsconfigAliases = await createTSConfigAliasPlugin();
|
|
168
|
+
if (tsconfigAliases) {
|
|
169
|
+
plugins.push(tsconfigAliases);
|
|
170
|
+
}
|
|
145
171
|
if (env) {
|
|
146
172
|
const {
|
|
147
173
|
magicModuleEnv,
|
|
@@ -163,15 +189,21 @@ async function quiltAppServer({
|
|
|
163
189
|
}));
|
|
164
190
|
}
|
|
165
191
|
}
|
|
166
|
-
|
|
192
|
+
const appEntry = app ?? (await glob('{App,app,input}.{ts,tsx,mjs,js,jsx}', {
|
|
193
|
+
cwd: root,
|
|
194
|
+
nodir: true,
|
|
195
|
+
absolute: true
|
|
196
|
+
}).then(files => files[0]));
|
|
197
|
+
if (appEntry) {
|
|
167
198
|
plugins.push(magicModuleAppComponent({
|
|
168
|
-
entry:
|
|
199
|
+
entry: appEntry
|
|
169
200
|
}));
|
|
170
201
|
}
|
|
171
202
|
plugins.push(magicModuleRequestRouterEntry());
|
|
172
203
|
plugins.push(magicModuleAppRequestRouter({
|
|
173
204
|
entry
|
|
174
205
|
}));
|
|
206
|
+
plugins.push(magicModuleAppAssetManifests());
|
|
175
207
|
if (graphql) {
|
|
176
208
|
const {
|
|
177
209
|
graphql
|
|
@@ -192,9 +224,22 @@ async function quiltAppServer({
|
|
|
192
224
|
brotliSize: true,
|
|
193
225
|
filename: path.resolve(`build/reports/bundle-visualizer.html`)
|
|
194
226
|
}));
|
|
227
|
+
const finalEntry = entry ?? (await glob('server.{ts,tsx,mjs,js,jsx}', {
|
|
228
|
+
cwd: root,
|
|
229
|
+
nodir: true,
|
|
230
|
+
absolute: true
|
|
231
|
+
}).then(files => files[0])) ?? MAGIC_MODULE_ENTRY;
|
|
195
232
|
return {
|
|
196
|
-
input:
|
|
233
|
+
input: finalEntry,
|
|
197
234
|
plugins,
|
|
235
|
+
onwarn(warning, defaultWarn) {
|
|
236
|
+
// Removes annoying warnings for React-focused libraries that
|
|
237
|
+
// include 'use client' directives.
|
|
238
|
+
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
defaultWarn(warning);
|
|
242
|
+
},
|
|
198
243
|
output: {
|
|
199
244
|
// format: isESM ? 'esm' : 'systemjs',
|
|
200
245
|
format: 'esm',
|
|
@@ -273,6 +318,43 @@ function magicModuleAppBrowserEntry({
|
|
|
273
318
|
}
|
|
274
319
|
});
|
|
275
320
|
}
|
|
321
|
+
function magicModuleAppAssetManifests() {
|
|
322
|
+
return createMagicModulePlugin({
|
|
323
|
+
name: '@quilted/magic-module/asset-manifests',
|
|
324
|
+
module: MAGIC_MODULE_BROWSER_ASSETS,
|
|
325
|
+
async source() {
|
|
326
|
+
const {
|
|
327
|
+
glob
|
|
328
|
+
} = await import('glob');
|
|
329
|
+
const manifestFiles = await glob('assets*.json', {
|
|
330
|
+
nodir: true,
|
|
331
|
+
absolute: true,
|
|
332
|
+
cwd: path.resolve(`build/manifests`)
|
|
333
|
+
});
|
|
334
|
+
const manifests = await Promise.all(manifestFiles.map(async file => JSON.parse(await fs.readFile(file, 'utf8'))));
|
|
335
|
+
manifests.sort((manifestA, manifestB) => (manifestA.priority ?? 0) - (manifestB.priority ?? 0));
|
|
336
|
+
return multiline`
|
|
337
|
+
import {BrowserAssetsFromManifests} from '@quilted/quilt/server';
|
|
338
|
+
|
|
339
|
+
export class BrowserAssets extends BrowserAssetsFromManifests {
|
|
340
|
+
constructor() {
|
|
341
|
+
const manifests = JSON.parse(${JSON.stringify(JSON.stringify(manifests))});
|
|
342
|
+
|
|
343
|
+
// The default manifest is the last one, since it has the widest browser support.
|
|
344
|
+
const defaultManifest = manifests.at(-1);
|
|
345
|
+
|
|
346
|
+
super(manifests, {
|
|
347
|
+
defaultManifest,
|
|
348
|
+
cacheKey(request) {
|
|
349
|
+
return {};
|
|
350
|
+
},
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
`;
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
}
|
|
276
358
|
const FRAMEWORK_CHUNK_NAME = 'framework';
|
|
277
359
|
const POLYFILLS_CHUNK_NAME = 'polyfills';
|
|
278
360
|
const VENDOR_CHUNK_NAME = 'vendor';
|
|
@@ -340,4 +422,4 @@ function createManualChunksSorter() {
|
|
|
340
422
|
};
|
|
341
423
|
}
|
|
342
424
|
|
|
343
|
-
export { magicModuleAppBrowserEntry, magicModuleAppComponent, magicModuleAppRequestRouter, quiltAppBrowser, quiltAppServer };
|
|
425
|
+
export { magicModuleAppAssetManifests, magicModuleAppBrowserEntry, magicModuleAppComponent, magicModuleAppRequestRouter, quiltAppBrowser, quiltAppServer };
|
|
@@ -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 };
|