@quilted/rollup 0.2.4 → 0.2.6
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 +12 -0
- package/build/esm/app.mjs +130 -125
- package/build/esm/features/node.mjs +57 -0
- package/build/esm/module.mjs +21 -22
- package/build/esm/package.mjs +36 -79
- package/build/esm/server.mjs +16 -25
- package/build/esm/shared/magic-module.mjs +5 -3
- package/build/esm/shared/project.mjs +100 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts +23 -18
- package/build/typescript/app.d.ts.map +1 -1
- package/build/typescript/features/env.d.ts +3 -5
- package/build/typescript/features/env.d.ts.map +1 -1
- package/build/typescript/features/node.d.ts +4 -0
- package/build/typescript/features/node.d.ts.map +1 -0
- package/build/typescript/features/request-router.d.ts +2 -2
- package/build/typescript/module.d.ts +1 -1
- package/build/typescript/module.d.ts.map +1 -1
- package/build/typescript/package.d.ts +3 -5
- package/build/typescript/package.d.ts.map +1 -1
- package/build/typescript/server.d.ts +0 -1
- package/build/typescript/server.d.ts.map +1 -1
- package/build/typescript/shared/magic-module.d.ts +3 -3
- package/build/typescript/shared/magic-module.d.ts.map +1 -1
- package/build/typescript/shared/project.d.ts +33 -0
- package/build/typescript/shared/project.d.ts.map +1 -0
- package/package.json +19 -1
- package/source/app.ts +158 -154
- package/source/features/node.ts +74 -0
- package/source/module.ts +20 -22
- package/source/package.ts +37 -109
- package/source/server.ts +16 -30
- package/source/shared/magic-module.ts +10 -4
- package/source/shared/project.ts +150 -0
- package/build/esm/shared/package-json.mjs +0 -16
- package/build/esm/shared/path.mjs +0 -7
- package/source/shared/package-json.ts +0 -20
- package/source/shared/path.ts +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @quilted/rollup
|
|
2
2
|
|
|
3
|
+
## 0.2.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`e77a644c`](https://github.com/lemonmade/quilt/commit/e77a644cfaf528cd635f4bc26814c7ccb654e515) Thanks [@lemonmade](https://github.com/lemonmade)! - Add more development features to Vite plugin
|
|
8
|
+
|
|
9
|
+
## 0.2.5
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`465883e1`](https://github.com/lemonmade/quilt/commit/465883e12571bee9d6e8c8d517ebf6da384687b2) Thanks [@lemonmade](https://github.com/lemonmade)! - Add support for automatic in-repo source aliases
|
|
14
|
+
|
|
3
15
|
## 0.2.4
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/build/esm/app.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import * as fs from 'node:fs/promises';
|
|
3
|
-
import { glob } from 'glob';
|
|
4
3
|
import { createRequire } from 'node:module';
|
|
5
4
|
import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_REQUEST_ROUTER, MAGIC_MODULE_BROWSER_ASSETS } from './constants.mjs';
|
|
6
5
|
import { resolveEnvOption } from './features/env.mjs';
|
|
@@ -8,12 +7,11 @@ import { multiline } from './shared/strings.mjs';
|
|
|
8
7
|
import { getNodePlugins, removeBuildFiles, normalizeRollupInput } from './shared/rollup.mjs';
|
|
9
8
|
import { createMagicModulePlugin } from './shared/magic-module.mjs';
|
|
10
9
|
import { getBrowserGroups, getBrowserGroupTargetDetails, targetsSupportModules, rollupGenerateOptionsForBrowsers, getBrowserGroupRegularExpressions } from './shared/browserslist.mjs';
|
|
11
|
-
import {
|
|
12
|
-
import { resolveRoot } from './shared/path.mjs';
|
|
10
|
+
import { Project } from './shared/project.mjs';
|
|
13
11
|
|
|
14
12
|
const require = createRequire(import.meta.url);
|
|
15
13
|
async function quiltAppOptions({
|
|
16
|
-
root
|
|
14
|
+
root = process.cwd(),
|
|
17
15
|
app,
|
|
18
16
|
env,
|
|
19
17
|
graphql,
|
|
@@ -21,15 +19,15 @@ async function quiltAppOptions({
|
|
|
21
19
|
browser: browserOptions,
|
|
22
20
|
server: serverOptions
|
|
23
21
|
} = {}) {
|
|
24
|
-
const
|
|
25
|
-
const browserGroups = await getBrowserGroups({ root });
|
|
22
|
+
const project = Project.load(root);
|
|
23
|
+
const browserGroups = await getBrowserGroups({ root: project.root });
|
|
26
24
|
const browserGroupEntries = Object.entries(browserGroups);
|
|
27
25
|
const hasMultipleBrowserGroups = browserGroupEntries.length > 1;
|
|
28
26
|
const optionPromises = [];
|
|
29
27
|
browserGroupEntries.forEach(([name, browsers], index) => {
|
|
30
28
|
optionPromises.push(
|
|
31
29
|
quiltAppBrowserOptions({
|
|
32
|
-
root,
|
|
30
|
+
root: project.root,
|
|
33
31
|
app,
|
|
34
32
|
graphql,
|
|
35
33
|
...browserOptions,
|
|
@@ -51,7 +49,7 @@ async function quiltAppOptions({
|
|
|
51
49
|
});
|
|
52
50
|
optionPromises.push(
|
|
53
51
|
quiltAppServerOptions({
|
|
54
|
-
root,
|
|
52
|
+
root: project.root,
|
|
55
53
|
app,
|
|
56
54
|
graphql,
|
|
57
55
|
...serverOptions,
|
|
@@ -65,12 +63,12 @@ async function quiltAppOptions({
|
|
|
65
63
|
return Promise.all(optionPromises);
|
|
66
64
|
}
|
|
67
65
|
async function quiltAppBrowserOptions(options = {}) {
|
|
68
|
-
const { root
|
|
69
|
-
const
|
|
66
|
+
const { root = process.cwd(), assets } = options;
|
|
67
|
+
const project = Project.load(root);
|
|
70
68
|
const [plugins, browserGroup] = await Promise.all([
|
|
71
69
|
quiltAppBrowser(options),
|
|
72
70
|
getBrowserGroupTargetDetails(assets?.targets, {
|
|
73
|
-
root
|
|
71
|
+
root: project.root
|
|
74
72
|
})
|
|
75
73
|
]);
|
|
76
74
|
const targetFilenamePart = browserGroup.name ? `.${browserGroup.name}` : "";
|
|
@@ -82,7 +80,7 @@ async function quiltAppBrowserOptions(options = {}) {
|
|
|
82
80
|
plugins,
|
|
83
81
|
output: {
|
|
84
82
|
format: isESM ? "esm" : "systemjs",
|
|
85
|
-
dir:
|
|
83
|
+
dir: project.resolve(`build/assets`),
|
|
86
84
|
entryFileNames: `[name]${targetFilenamePart}.[hash].js`,
|
|
87
85
|
assetFileNames: `[name]${targetFilenamePart}.[hash].[ext]`,
|
|
88
86
|
chunkFileNames: `[name]${targetFilenamePart}.[hash].js`,
|
|
@@ -92,7 +90,7 @@ async function quiltAppBrowserOptions(options = {}) {
|
|
|
92
90
|
};
|
|
93
91
|
}
|
|
94
92
|
async function quiltAppBrowser({
|
|
95
|
-
root
|
|
93
|
+
root = process.cwd(),
|
|
96
94
|
app,
|
|
97
95
|
entry,
|
|
98
96
|
env,
|
|
@@ -100,13 +98,13 @@ async function quiltAppBrowser({
|
|
|
100
98
|
module,
|
|
101
99
|
graphql = true
|
|
102
100
|
} = {}) {
|
|
103
|
-
const
|
|
101
|
+
const project = Project.load(root);
|
|
104
102
|
const mode = (typeof env === "object" ? env?.mode : env) ?? "production";
|
|
105
103
|
const minify = assets?.minify ?? mode === "production";
|
|
106
104
|
const baseURL = assets?.baseURL ?? "/assets/";
|
|
107
105
|
const assetsInline = assets?.inline ?? true;
|
|
108
106
|
const browserGroup = await getBrowserGroupTargetDetails(assets?.targets, {
|
|
109
|
-
root
|
|
107
|
+
root: project.root
|
|
110
108
|
});
|
|
111
109
|
const targetFilenamePart = browserGroup.name ? `.${browserGroup.name}` : "";
|
|
112
110
|
const [
|
|
@@ -114,6 +112,7 @@ async function quiltAppBrowser({
|
|
|
114
112
|
{ magicModuleEnv, replaceProcessEnv },
|
|
115
113
|
{ sourceCode },
|
|
116
114
|
{ tsconfigAliases },
|
|
115
|
+
{ monorepoPackageAliases },
|
|
117
116
|
{ react },
|
|
118
117
|
{ css },
|
|
119
118
|
{ assetManifest, rawAssets, staticAssets },
|
|
@@ -121,13 +120,13 @@ async function quiltAppBrowser({
|
|
|
121
120
|
{ systemJS },
|
|
122
121
|
{ workers },
|
|
123
122
|
{ esnext },
|
|
124
|
-
nodePlugins
|
|
125
|
-
packageJSON
|
|
123
|
+
nodePlugins
|
|
126
124
|
] = await Promise.all([
|
|
127
125
|
import('rollup-plugin-visualizer'),
|
|
128
126
|
import('./features/env.mjs'),
|
|
129
127
|
import('./features/source-code.mjs'),
|
|
130
128
|
import('./features/typescript.mjs'),
|
|
129
|
+
import('./features/node.mjs'),
|
|
131
130
|
import('./features/react.mjs'),
|
|
132
131
|
import('./features/css.mjs'),
|
|
133
132
|
import('./features/assets.mjs'),
|
|
@@ -135,15 +134,16 @@ async function quiltAppBrowser({
|
|
|
135
134
|
import('./features/system-js.mjs'),
|
|
136
135
|
import('./features/workers.mjs'),
|
|
137
136
|
import('./features/esnext.mjs'),
|
|
138
|
-
getNodePlugins({ bundle: true })
|
|
139
|
-
loadPackageJSON(root)
|
|
137
|
+
getNodePlugins({ bundle: true })
|
|
140
138
|
]);
|
|
141
139
|
const plugins = [
|
|
142
|
-
quiltAppBrowserInput({ root, entry }),
|
|
140
|
+
quiltAppBrowserInput({ root: project.root, entry }),
|
|
143
141
|
...nodePlugins,
|
|
144
142
|
systemJS({ minify }),
|
|
145
143
|
replaceProcessEnv({ mode }),
|
|
146
144
|
magicModuleEnv({ ...resolveEnvOption(env), mode }),
|
|
145
|
+
magicModuleAppComponent({ entry: app, root: project.root }),
|
|
146
|
+
magicModuleAppBrowserEntry(module),
|
|
147
147
|
sourceCode({
|
|
148
148
|
mode,
|
|
149
149
|
targets: browserGroup.browsers,
|
|
@@ -176,39 +176,34 @@ async function quiltAppBrowser({
|
|
|
176
176
|
asyncModules({
|
|
177
177
|
baseURL,
|
|
178
178
|
preload: true,
|
|
179
|
-
moduleID: ({ imported }) => path.relative(root, imported)
|
|
179
|
+
moduleID: ({ imported }) => path.relative(project.root, imported)
|
|
180
180
|
}),
|
|
181
181
|
workers({
|
|
182
182
|
baseURL,
|
|
183
183
|
outputOptions: {
|
|
184
184
|
format: "iife",
|
|
185
185
|
inlineDynamicImports: true,
|
|
186
|
-
dir:
|
|
186
|
+
dir: project.resolve(`build/assets`),
|
|
187
187
|
entryFileNames: `[name]${targetFilenamePart}.[hash].js`,
|
|
188
188
|
assetFileNames: `[name]${targetFilenamePart}.[hash].[ext]`,
|
|
189
189
|
chunkFileNames: `[name]${targetFilenamePart}.[hash].js`
|
|
190
190
|
}
|
|
191
191
|
}),
|
|
192
|
-
tsconfigAliases({ root })
|
|
192
|
+
tsconfigAliases({ root: project.root }),
|
|
193
|
+
monorepoPackageAliases({ root: project.root })
|
|
193
194
|
];
|
|
194
195
|
if (assets?.clean ?? true) {
|
|
195
196
|
plugins.push(
|
|
196
197
|
removeBuildFiles(["build/assets", "build/manifests", "build/reports"], {
|
|
197
|
-
root
|
|
198
|
+
root: project.root
|
|
198
199
|
})
|
|
199
200
|
);
|
|
200
201
|
}
|
|
201
|
-
const appEntry = await resolveAppEntry(app, { root, packageJSON });
|
|
202
|
-
if (appEntry) {
|
|
203
|
-
plugins.push(magicModuleAppComponent({ entry: appEntry }));
|
|
204
|
-
}
|
|
205
|
-
plugins.push(magicModuleAppBrowserEntry(module));
|
|
206
202
|
if (graphql) {
|
|
207
203
|
const { graphql: graphql2 } = await import('./features/graphql.mjs');
|
|
208
204
|
plugins.push(
|
|
209
205
|
graphql2({
|
|
210
|
-
manifest:
|
|
211
|
-
root,
|
|
206
|
+
manifest: project.resolve(
|
|
212
207
|
`build/manifests/graphql${targetFilenamePart}.json`
|
|
213
208
|
)
|
|
214
209
|
})
|
|
@@ -226,18 +221,14 @@ async function quiltAppBrowser({
|
|
|
226
221
|
assetManifest({
|
|
227
222
|
baseURL,
|
|
228
223
|
cacheKey,
|
|
229
|
-
file:
|
|
230
|
-
root,
|
|
231
|
-
`build/manifests/assets${targetFilenamePart}.json`
|
|
232
|
-
),
|
|
224
|
+
file: project.resolve(`build/manifests/assets${targetFilenamePart}.json`),
|
|
233
225
|
priority: assets?.priority
|
|
234
226
|
}),
|
|
235
227
|
visualizer({
|
|
236
228
|
template: "treemap",
|
|
237
229
|
open: false,
|
|
238
230
|
brotliSize: true,
|
|
239
|
-
filename:
|
|
240
|
-
root,
|
|
231
|
+
filename: project.resolve(
|
|
241
232
|
`build/reports/bundle-visualizer${targetFilenamePart}.html`
|
|
242
233
|
)
|
|
243
234
|
})
|
|
@@ -245,18 +236,13 @@ async function quiltAppBrowser({
|
|
|
245
236
|
return plugins;
|
|
246
237
|
}
|
|
247
238
|
function quiltAppBrowserInput({
|
|
248
|
-
root
|
|
239
|
+
root,
|
|
249
240
|
entry
|
|
250
241
|
} = {}) {
|
|
251
|
-
const root = resolveRoot(rootPath);
|
|
252
242
|
return {
|
|
253
243
|
name: "@quilted/app-browser/input",
|
|
254
244
|
async options(options) {
|
|
255
|
-
const finalEntry = normalizeRollupInput(options.input) ?? (entry
|
|
256
|
-
cwd: root,
|
|
257
|
-
nodir: true,
|
|
258
|
-
absolute: true
|
|
259
|
-
}).then((files) => files[0])) ?? MAGIC_MODULE_ENTRY;
|
|
245
|
+
const finalEntry = normalizeRollupInput(options.input) ?? await sourceForAppBrowser({ entry, root }) ?? MAGIC_MODULE_ENTRY;
|
|
260
246
|
return {
|
|
261
247
|
...options,
|
|
262
248
|
// If we are using the "magic entry", give it an explicit name of `browser`.
|
|
@@ -267,8 +253,8 @@ function quiltAppBrowserInput({
|
|
|
267
253
|
};
|
|
268
254
|
}
|
|
269
255
|
async function quiltAppServerOptions(options = {}) {
|
|
270
|
-
const { root
|
|
271
|
-
const
|
|
256
|
+
const { root = process.cwd(), output } = options;
|
|
257
|
+
const project = Project.load(root);
|
|
272
258
|
const hash = output?.hash ?? "async-only";
|
|
273
259
|
const outputFormat = output?.format ?? "esmodules";
|
|
274
260
|
const plugins = await quiltAppServer(options);
|
|
@@ -276,7 +262,7 @@ async function quiltAppServerOptions(options = {}) {
|
|
|
276
262
|
plugins,
|
|
277
263
|
output: {
|
|
278
264
|
format: outputFormat === "commonjs" || outputFormat === "cjs" ? "cjs" : "esm",
|
|
279
|
-
dir:
|
|
265
|
+
dir: project.resolve(`build/server`),
|
|
280
266
|
entryFileNames: `[name]${hash === true ? `.[hash]` : ""}.js`,
|
|
281
267
|
chunkFileNames: `[name]${hash === true || hash === "async-only" ? `.[hash]` : ""}.js`,
|
|
282
268
|
assetFileNames: `[name]${hash === true ? `.[hash]` : ""}.[ext]`,
|
|
@@ -285,7 +271,7 @@ async function quiltAppServerOptions(options = {}) {
|
|
|
285
271
|
};
|
|
286
272
|
}
|
|
287
273
|
async function quiltAppServer({
|
|
288
|
-
root
|
|
274
|
+
root = process.cwd(),
|
|
289
275
|
app,
|
|
290
276
|
env,
|
|
291
277
|
entry,
|
|
@@ -294,7 +280,7 @@ async function quiltAppServer({
|
|
|
294
280
|
assets,
|
|
295
281
|
output
|
|
296
282
|
} = {}) {
|
|
297
|
-
const
|
|
283
|
+
const project = Project.load(root);
|
|
298
284
|
const mode = (typeof env === "object" ? env?.mode : env) ?? "production";
|
|
299
285
|
const baseURL = assets?.baseURL ?? "/assets/";
|
|
300
286
|
const assetsInline = assets?.inline ?? true;
|
|
@@ -306,30 +292,36 @@ async function quiltAppServer({
|
|
|
306
292
|
{ sourceCode },
|
|
307
293
|
{ react },
|
|
308
294
|
{ tsconfigAliases },
|
|
295
|
+
{ monorepoPackageAliases },
|
|
309
296
|
{ css },
|
|
310
297
|
{ rawAssets, staticAssets },
|
|
311
298
|
{ asyncModules },
|
|
312
299
|
{ esnext },
|
|
313
|
-
nodePlugins
|
|
314
|
-
packageJSON
|
|
300
|
+
nodePlugins
|
|
315
301
|
] = await Promise.all([
|
|
316
302
|
import('rollup-plugin-visualizer'),
|
|
317
303
|
import('./features/env.mjs'),
|
|
318
304
|
import('./features/source-code.mjs'),
|
|
319
305
|
import('./features/react.mjs'),
|
|
320
306
|
import('./features/typescript.mjs'),
|
|
307
|
+
import('./features/node.mjs'),
|
|
321
308
|
import('./features/css.mjs'),
|
|
322
309
|
import('./features/assets.mjs'),
|
|
323
310
|
import('./features/async.mjs'),
|
|
324
311
|
import('./features/esnext.mjs'),
|
|
325
|
-
getNodePlugins({ bundle })
|
|
326
|
-
loadPackageJSON(root)
|
|
312
|
+
getNodePlugins({ bundle })
|
|
327
313
|
]);
|
|
328
314
|
const plugins = [
|
|
329
|
-
quiltAppServerInput({ root, entry, format }),
|
|
315
|
+
quiltAppServerInput({ root: project.root, entry, format }),
|
|
330
316
|
...nodePlugins,
|
|
331
317
|
replaceProcessEnv({ mode }),
|
|
332
318
|
magicModuleEnv({ ...resolveEnvOption(env), mode }),
|
|
319
|
+
magicModuleAppComponent({ entry: app, root: project.root }),
|
|
320
|
+
magicModuleAppServerEntry({
|
|
321
|
+
assets: { baseURL }
|
|
322
|
+
}),
|
|
323
|
+
magicModuleAppRequestRouter({ entry, root: project.root }),
|
|
324
|
+
magicModuleAppAssetManifests(),
|
|
333
325
|
sourceCode({
|
|
334
326
|
mode,
|
|
335
327
|
targets: ["current node"],
|
|
@@ -361,27 +353,12 @@ async function quiltAppServer({
|
|
|
361
353
|
asyncModules({
|
|
362
354
|
baseURL,
|
|
363
355
|
preload: false,
|
|
364
|
-
moduleID: ({ imported }) => path.relative(root, imported)
|
|
356
|
+
moduleID: ({ imported }) => path.relative(project.root, imported)
|
|
365
357
|
}),
|
|
366
|
-
removeBuildFiles(["build/server"], { root }),
|
|
367
|
-
tsconfigAliases({ root })
|
|
358
|
+
removeBuildFiles(["build/server"], { root: project.root }),
|
|
359
|
+
tsconfigAliases({ root: project.root }),
|
|
360
|
+
monorepoPackageAliases({ root: project.root })
|
|
368
361
|
];
|
|
369
|
-
const appEntry = await resolveAppEntry(app, { root, packageJSON });
|
|
370
|
-
if (appEntry) {
|
|
371
|
-
plugins.push(magicModuleAppComponent({ entry: appEntry }));
|
|
372
|
-
}
|
|
373
|
-
const serverEntry = entry ? path.resolve(root, entry) : await glob("{server,service,backend}.{ts,tsx,mjs,js,jsx}", {
|
|
374
|
-
cwd: root,
|
|
375
|
-
nodir: true,
|
|
376
|
-
absolute: true
|
|
377
|
-
}).then((files) => files[0]);
|
|
378
|
-
plugins.push(
|
|
379
|
-
magicModuleAppServerEntry({
|
|
380
|
-
assets: { baseURL }
|
|
381
|
-
}),
|
|
382
|
-
magicModuleAppRequestRouter({ entry: serverEntry }),
|
|
383
|
-
magicModuleAppAssetManifests()
|
|
384
|
-
);
|
|
385
362
|
if (graphql) {
|
|
386
363
|
const { graphql: graphql2 } = await import('./features/graphql.mjs');
|
|
387
364
|
plugins.push(graphql2({ manifest: false }));
|
|
@@ -395,27 +372,23 @@ async function quiltAppServer({
|
|
|
395
372
|
template: "treemap",
|
|
396
373
|
open: false,
|
|
397
374
|
brotliSize: false,
|
|
398
|
-
filename:
|
|
399
|
-
root,
|
|
400
|
-
`build/reports/bundle-visualizer.server.html`
|
|
401
|
-
)
|
|
375
|
+
filename: project.resolve(`build/reports/bundle-visualizer.server.html`)
|
|
402
376
|
})
|
|
403
377
|
);
|
|
404
378
|
return plugins;
|
|
405
379
|
}
|
|
406
380
|
function quiltAppServerInput({
|
|
407
|
-
root
|
|
381
|
+
root = process.cwd(),
|
|
408
382
|
entry,
|
|
409
383
|
format = "request-router"
|
|
410
384
|
} = {}) {
|
|
411
|
-
const
|
|
385
|
+
const project = Project.load(root);
|
|
412
386
|
return {
|
|
413
387
|
name: "@quilted/app-server/input",
|
|
414
388
|
async options(options) {
|
|
415
389
|
let finalEntry = normalizeRollupInput(options.input);
|
|
416
390
|
if (!finalEntry) {
|
|
417
|
-
const serverEntry = entry ?
|
|
418
|
-
cwd: root,
|
|
391
|
+
const serverEntry = entry ? project.resolve(entry) : await project.glob("{server,service,backend}.{ts,tsx,mjs,js,jsx}", {
|
|
419
392
|
nodir: true,
|
|
420
393
|
absolute: true
|
|
421
394
|
}).then((files) => files[0]);
|
|
@@ -430,48 +403,80 @@ function quiltAppServerInput({
|
|
|
430
403
|
}
|
|
431
404
|
};
|
|
432
405
|
}
|
|
433
|
-
function magicModuleAppComponent({
|
|
406
|
+
function magicModuleAppComponent({
|
|
407
|
+
entry,
|
|
408
|
+
root = process.cwd()
|
|
409
|
+
}) {
|
|
434
410
|
return createMagicModulePlugin({
|
|
435
411
|
name: "@quilted/magic-module/app",
|
|
436
412
|
module: MAGIC_MODULE_APP_COMPONENT,
|
|
437
|
-
alias: entry
|
|
413
|
+
alias: entry ?? async function magicModuleApp() {
|
|
414
|
+
const project = Project.load(root);
|
|
415
|
+
const { packageJSON } = project;
|
|
416
|
+
if (typeof packageJSON.raw.main === "string") {
|
|
417
|
+
return project.resolve(packageJSON.raw.main);
|
|
418
|
+
}
|
|
419
|
+
const rootEntry = packageJSON.raw.exports?.["."];
|
|
420
|
+
if (typeof rootEntry === "string") {
|
|
421
|
+
return project.resolve(rootEntry);
|
|
422
|
+
}
|
|
423
|
+
const globbed = await project.glob(
|
|
424
|
+
"{App,app,index}.{ts,tsx,mjs,js,jsx}",
|
|
425
|
+
{
|
|
426
|
+
nodir: true,
|
|
427
|
+
absolute: true
|
|
428
|
+
}
|
|
429
|
+
);
|
|
430
|
+
return globbed[0];
|
|
431
|
+
}
|
|
438
432
|
});
|
|
439
433
|
}
|
|
440
434
|
function magicModuleAppRequestRouter({
|
|
441
|
-
entry
|
|
435
|
+
entry,
|
|
436
|
+
root = process.cwd()
|
|
442
437
|
} = {}) {
|
|
443
438
|
return createMagicModulePlugin({
|
|
444
439
|
name: "@quilted/magic-module/app-request-router",
|
|
445
440
|
module: MAGIC_MODULE_REQUEST_ROUTER,
|
|
446
|
-
alias: entry
|
|
447
|
-
|
|
441
|
+
alias: entry ?? async function magicModuleRequestRouter() {
|
|
442
|
+
const project = Project.load(root);
|
|
443
|
+
const globbed = await project.glob(
|
|
444
|
+
"{server,service,backend}.{ts,tsx,mjs,js,jsx}",
|
|
445
|
+
{
|
|
446
|
+
nodir: true,
|
|
447
|
+
absolute: true
|
|
448
|
+
}
|
|
449
|
+
);
|
|
450
|
+
return globbed[0];
|
|
451
|
+
},
|
|
452
|
+
async source() {
|
|
448
453
|
return multiline`
|
|
449
|
-
|
|
454
|
+
import '@quilted/quilt/globals';
|
|
450
455
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
456
|
+
import {jsx} from 'react/jsx-runtime';
|
|
457
|
+
import {RequestRouter} from '@quilted/quilt/request-router';
|
|
458
|
+
import {renderToResponse} from '@quilted/quilt/server';
|
|
454
459
|
|
|
455
|
-
|
|
456
|
-
|
|
460
|
+
import App from ${JSON.stringify(MAGIC_MODULE_APP_COMPONENT)};
|
|
461
|
+
import {BrowserAssets} from ${JSON.stringify(
|
|
457
462
|
MAGIC_MODULE_BROWSER_ASSETS
|
|
458
463
|
)};
|
|
459
464
|
|
|
460
|
-
|
|
461
|
-
|
|
465
|
+
const router = new RequestRouter();
|
|
466
|
+
const assets = new BrowserAssets();
|
|
462
467
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
468
|
+
// For all GET requests, render our React application.
|
|
469
|
+
router.get(async (request) => {
|
|
470
|
+
const response = await renderToResponse(jsx(App), {
|
|
471
|
+
request,
|
|
472
|
+
assets,
|
|
473
|
+
});
|
|
469
474
|
|
|
470
|
-
|
|
471
|
-
|
|
475
|
+
return response;
|
|
476
|
+
});
|
|
472
477
|
|
|
473
|
-
|
|
474
|
-
|
|
478
|
+
export default router;
|
|
479
|
+
`;
|
|
475
480
|
}
|
|
476
481
|
});
|
|
477
482
|
}
|
|
@@ -549,8 +554,8 @@ function magicModuleAppAssetManifests() {
|
|
|
549
554
|
name: "@quilted/magic-module/asset-manifests",
|
|
550
555
|
module: MAGIC_MODULE_BROWSER_ASSETS,
|
|
551
556
|
async source() {
|
|
552
|
-
const { glob
|
|
553
|
-
const manifestFiles = await
|
|
557
|
+
const { glob } = await import('glob');
|
|
558
|
+
const manifestFiles = await glob("assets*.json", {
|
|
554
559
|
nodir: true,
|
|
555
560
|
absolute: true,
|
|
556
561
|
cwd: path.resolve(`build/manifests`)
|
|
@@ -604,6 +609,24 @@ function magicModuleAppAssetManifests() {
|
|
|
604
609
|
}
|
|
605
610
|
});
|
|
606
611
|
}
|
|
612
|
+
async function sourceForAppBrowser({
|
|
613
|
+
entry,
|
|
614
|
+
root = process.cwd()
|
|
615
|
+
}) {
|
|
616
|
+
const project = Project.load(root);
|
|
617
|
+
if (entry) {
|
|
618
|
+
return project.resolve(entry);
|
|
619
|
+
} else {
|
|
620
|
+
const files = await project.glob(
|
|
621
|
+
"{browser,client,web}.{ts,tsx,mjs,js,jsx}",
|
|
622
|
+
{
|
|
623
|
+
nodir: true,
|
|
624
|
+
absolute: true
|
|
625
|
+
}
|
|
626
|
+
);
|
|
627
|
+
return files[0];
|
|
628
|
+
}
|
|
629
|
+
}
|
|
607
630
|
const FRAMEWORK_CHUNK_NAME = "framework";
|
|
608
631
|
const POLYFILLS_CHUNK_NAME = "polyfills";
|
|
609
632
|
const VENDOR_CHUNK_NAME = "vendor";
|
|
@@ -679,23 +702,5 @@ function createManualChunksSorter() {
|
|
|
679
702
|
return `${bundleBaseName}-${relativeId.split(path.sep)[0]?.split(".")[0]}`;
|
|
680
703
|
};
|
|
681
704
|
}
|
|
682
|
-
async function resolveAppEntry(entry, { root, packageJSON }) {
|
|
683
|
-
if (entry) {
|
|
684
|
-
return path.resolve(root, entry);
|
|
685
|
-
}
|
|
686
|
-
if (typeof packageJSON.main === "string") {
|
|
687
|
-
return path.resolve(root, packageJSON.main);
|
|
688
|
-
}
|
|
689
|
-
const rootEntry = packageJSON.exports?.["."];
|
|
690
|
-
if (typeof rootEntry === "string") {
|
|
691
|
-
return path.resolve(root, rootEntry);
|
|
692
|
-
}
|
|
693
|
-
const globbed = await glob("{App,app,index}.{ts,tsx,mjs,js,jsx}", {
|
|
694
|
-
cwd: root,
|
|
695
|
-
nodir: true,
|
|
696
|
-
absolute: true
|
|
697
|
-
});
|
|
698
|
-
return globbed[0];
|
|
699
|
-
}
|
|
700
705
|
|
|
701
|
-
export { MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_BROWSER_ASSETS, MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER, magicModuleAppAssetManifests, magicModuleAppBrowserEntry, magicModuleAppComponent, magicModuleAppRequestRouter, magicModuleAppServerEntry, quiltAppBrowser, quiltAppBrowserInput, quiltAppBrowserOptions, quiltAppOptions, quiltAppServer, quiltAppServerInput, quiltAppServerOptions };
|
|
706
|
+
export { MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_BROWSER_ASSETS, MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER, magicModuleAppAssetManifests, magicModuleAppBrowserEntry, magicModuleAppComponent, magicModuleAppRequestRouter, magicModuleAppServerEntry, quiltAppBrowser, quiltAppBrowserInput, quiltAppBrowserOptions, quiltAppOptions, quiltAppServer, quiltAppServerInput, quiltAppServerOptions, sourceForAppBrowser };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { realpathSync } from 'node:fs';
|
|
2
|
+
import { Project, sourceEntriesForProject } from '../shared/project.mjs';
|
|
3
|
+
|
|
4
|
+
async function monorepoPackageAliases({
|
|
5
|
+
root = process.cwd()
|
|
6
|
+
} = {}) {
|
|
7
|
+
const project = Project.load(root);
|
|
8
|
+
const seenDependencies = /* @__PURE__ */ new Set();
|
|
9
|
+
const seenProjects = /* @__PURE__ */ new Set();
|
|
10
|
+
function processProject(project2) {
|
|
11
|
+
const { dependencies, devDependencies } = project2.packageJSON.raw;
|
|
12
|
+
for (const pkg of Object.keys({ ...dependencies, ...devDependencies })) {
|
|
13
|
+
if (seenDependencies.has(pkg))
|
|
14
|
+
continue;
|
|
15
|
+
seenDependencies.add(pkg);
|
|
16
|
+
let packageRoot;
|
|
17
|
+
try {
|
|
18
|
+
packageRoot = realpathSync(project2.resolve("node_modules", pkg));
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
if (packageRoot == null || packageRoot.includes("node_modules") || packageRoot === root) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const packageProject = Project.load(packageRoot);
|
|
25
|
+
if (seenProjects.has(packageProject))
|
|
26
|
+
continue;
|
|
27
|
+
seenProjects.add(packageProject);
|
|
28
|
+
processProject(packageProject);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
processProject(project);
|
|
32
|
+
const [{ default: alias }, projectsWithEntries] = await Promise.all([
|
|
33
|
+
import('@rollup/plugin-alias'),
|
|
34
|
+
Promise.all(
|
|
35
|
+
Array.from(seenProjects, async (project2) => {
|
|
36
|
+
const entries = await sourceEntriesForProject(project2);
|
|
37
|
+
return { project: project2, entries };
|
|
38
|
+
})
|
|
39
|
+
)
|
|
40
|
+
]);
|
|
41
|
+
const aliases = [];
|
|
42
|
+
for (const { project: project2, entries } of projectsWithEntries) {
|
|
43
|
+
const { name } = project2;
|
|
44
|
+
for (const [entry, source] of Object.entries(entries)) {
|
|
45
|
+
const entryName = entry === "." ? name : `${name}/${entry}`;
|
|
46
|
+
aliases.push({
|
|
47
|
+
find: new RegExp(`^${entryName}$`),
|
|
48
|
+
replacement: source
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return alias({
|
|
53
|
+
entries: aliases
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { monorepoPackageAliases };
|