@quilted/rollup 0.2.4 → 0.2.5
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/esm/app.mjs +60 -71
- 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/project.mjs +100 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts +5 -5
- package/build/typescript/app.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/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/project.d.ts +33 -0
- package/build/typescript/shared/project.d.ts.map +1 -0
- package/package.json +10 -1
- package/source/app.ts +73 -80
- 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/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
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {realpathSync} from 'fs';
|
|
2
|
+
|
|
3
|
+
import {Project, sourceEntriesForProject} from '../shared/project.ts';
|
|
4
|
+
|
|
5
|
+
export async function monorepoPackageAliases({
|
|
6
|
+
root = process.cwd(),
|
|
7
|
+
}: {root?: string} = {}) {
|
|
8
|
+
const project = Project.load(root);
|
|
9
|
+
const seenDependencies = new Set<string>();
|
|
10
|
+
const seenProjects = new Set<Project>();
|
|
11
|
+
|
|
12
|
+
function processProject(project: Project) {
|
|
13
|
+
const {dependencies, devDependencies} = project.packageJSON.raw;
|
|
14
|
+
|
|
15
|
+
for (const pkg of Object.keys({...dependencies, ...devDependencies})) {
|
|
16
|
+
if (seenDependencies.has(pkg)) continue;
|
|
17
|
+
|
|
18
|
+
seenDependencies.add(pkg);
|
|
19
|
+
|
|
20
|
+
let packageRoot: string | undefined;
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
packageRoot = realpathSync(project.resolve('node_modules', pkg));
|
|
24
|
+
} catch {
|
|
25
|
+
// intentional noop
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (
|
|
29
|
+
packageRoot == null ||
|
|
30
|
+
packageRoot.includes('node_modules') ||
|
|
31
|
+
packageRoot === root
|
|
32
|
+
) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const packageProject = Project.load(packageRoot);
|
|
37
|
+
if (seenProjects.has(packageProject)) continue;
|
|
38
|
+
|
|
39
|
+
seenProjects.add(packageProject);
|
|
40
|
+
processProject(packageProject);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
processProject(project);
|
|
45
|
+
|
|
46
|
+
const [{default: alias}, projectsWithEntries] = await Promise.all([
|
|
47
|
+
import('@rollup/plugin-alias'),
|
|
48
|
+
Promise.all(
|
|
49
|
+
Array.from(seenProjects, async (project) => {
|
|
50
|
+
const entries = await sourceEntriesForProject(project);
|
|
51
|
+
return {project, entries};
|
|
52
|
+
}),
|
|
53
|
+
),
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
const aliases: import('@rollup/plugin-alias').Alias[] = [];
|
|
57
|
+
|
|
58
|
+
for (const {project, entries} of projectsWithEntries) {
|
|
59
|
+
const {name} = project;
|
|
60
|
+
|
|
61
|
+
for (const [entry, source] of Object.entries(entries)) {
|
|
62
|
+
const entryName = entry === '.' ? name : `${name}/${entry}`;
|
|
63
|
+
|
|
64
|
+
aliases.push({
|
|
65
|
+
find: new RegExp(`^${entryName}$`),
|
|
66
|
+
replacement: source,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return alias({
|
|
72
|
+
entries: aliases,
|
|
73
|
+
});
|
|
74
|
+
}
|
package/source/module.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
1
|
import {type InputPluginOption, type RollupOptions} from 'rollup';
|
|
3
|
-
import {glob} from 'glob';
|
|
4
2
|
|
|
5
|
-
import {
|
|
3
|
+
import {Project} from './shared/project.ts';
|
|
6
4
|
import {
|
|
7
5
|
RollupNodePluginOptions,
|
|
8
6
|
getNodePlugins,
|
|
9
7
|
removeBuildFiles,
|
|
10
8
|
} from './shared/rollup.ts';
|
|
11
|
-
import {loadPackageJSON, type PackageJSON} from './shared/package-json.ts';
|
|
12
9
|
import {
|
|
13
10
|
getBrowserGroupTargetDetails,
|
|
14
11
|
rollupGenerateOptionsForBrowsers,
|
|
@@ -63,22 +60,22 @@ export interface ModuleAssetsOptions
|
|
|
63
60
|
}
|
|
64
61
|
|
|
65
62
|
export async function quiltModule({
|
|
66
|
-
root
|
|
63
|
+
root = process.cwd(),
|
|
67
64
|
entry,
|
|
68
65
|
env,
|
|
69
66
|
assets,
|
|
70
67
|
graphql = true,
|
|
71
68
|
}: ModuleOptions = {}) {
|
|
72
|
-
const
|
|
69
|
+
const project = Project.load(root);
|
|
73
70
|
const mode = (typeof env === 'object' ? env?.mode : env) ?? 'production';
|
|
74
|
-
const outputDirectory =
|
|
71
|
+
const outputDirectory = project.resolve('build/assets');
|
|
75
72
|
|
|
76
73
|
const minify = assets?.minify ?? true;
|
|
77
74
|
const hash = assets?.hash ?? 'async-only';
|
|
78
75
|
const bundle = assets?.bundle ?? true;
|
|
79
76
|
|
|
80
77
|
const browserGroup = await getBrowserGroupTargetDetails(assets?.targets, {
|
|
81
|
-
root,
|
|
78
|
+
root: project.root,
|
|
82
79
|
});
|
|
83
80
|
const targetFilenamePart = browserGroup.name ? `.${browserGroup.name}` : '';
|
|
84
81
|
|
|
@@ -87,34 +84,33 @@ export async function quiltModule({
|
|
|
87
84
|
{magicModuleEnv, replaceProcessEnv},
|
|
88
85
|
{sourceCode},
|
|
89
86
|
{tsconfigAliases},
|
|
87
|
+
{monorepoPackageAliases},
|
|
90
88
|
{react},
|
|
91
89
|
{esnext},
|
|
92
90
|
nodePlugins,
|
|
93
|
-
packageJSON,
|
|
94
91
|
] = await Promise.all([
|
|
95
92
|
import('rollup-plugin-visualizer'),
|
|
96
93
|
import('./features/env.ts'),
|
|
97
94
|
import('./features/source-code.ts'),
|
|
98
95
|
import('./features/typescript.ts'),
|
|
96
|
+
import('./features/node.ts'),
|
|
99
97
|
import('./features/react.ts'),
|
|
100
98
|
import('./features/esnext.ts'),
|
|
101
99
|
getNodePlugins({bundle}),
|
|
102
|
-
loadPackageJSON(root),
|
|
103
100
|
]);
|
|
104
101
|
|
|
105
|
-
const finalEntry = entry
|
|
106
|
-
? path.resolve(root, entry)
|
|
107
|
-
: await sourceForModule(root, packageJSON);
|
|
102
|
+
const finalEntry = await resolveModuleEntry(entry, project);
|
|
108
103
|
|
|
109
104
|
const plugins: InputPluginOption[] = [
|
|
110
105
|
...nodePlugins,
|
|
111
106
|
replaceProcessEnv({mode}),
|
|
112
107
|
magicModuleEnv({...resolveEnvOption(env), mode}),
|
|
113
108
|
sourceCode({mode, targets: browserGroup.browsers}),
|
|
114
|
-
tsconfigAliases({root}),
|
|
109
|
+
tsconfigAliases({root: project.root}),
|
|
110
|
+
monorepoPackageAliases({root: project.root}),
|
|
115
111
|
esnext({mode, targets: browserGroup.browsers}),
|
|
116
112
|
react(),
|
|
117
|
-
removeBuildFiles(['build/assets', 'build/reports'], {root}),
|
|
113
|
+
removeBuildFiles(['build/assets', 'build/reports'], {root: project.root}),
|
|
118
114
|
];
|
|
119
115
|
|
|
120
116
|
if (graphql) {
|
|
@@ -132,8 +128,7 @@ export async function quiltModule({
|
|
|
132
128
|
template: 'treemap',
|
|
133
129
|
open: false,
|
|
134
130
|
brotliSize: true,
|
|
135
|
-
filename:
|
|
136
|
-
root,
|
|
131
|
+
filename: project.resolve(
|
|
137
132
|
`build/reports/bundle-visualizer${targetFilenamePart}.html`,
|
|
138
133
|
),
|
|
139
134
|
}),
|
|
@@ -161,19 +156,22 @@ export async function quiltModule({
|
|
|
161
156
|
} satisfies RollupOptions;
|
|
162
157
|
}
|
|
163
158
|
|
|
164
|
-
async function
|
|
165
|
-
|
|
159
|
+
async function resolveModuleEntry(entry: string | undefined, project: Project) {
|
|
160
|
+
if (entry) {
|
|
161
|
+
return project.resolve(entry);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const {main, exports} = project.packageJSON.raw;
|
|
166
165
|
|
|
167
166
|
const entryFromPackageJSON = main ?? (exports as any)?.['.'];
|
|
168
167
|
|
|
169
168
|
if (entryFromPackageJSON) {
|
|
170
|
-
return
|
|
169
|
+
return project.resolve(entryFromPackageJSON);
|
|
171
170
|
}
|
|
172
171
|
|
|
173
|
-
const possibleSourceFiles = await glob(
|
|
172
|
+
const possibleSourceFiles = await project.glob(
|
|
174
173
|
'{index,module,entry,input}.{ts,tsx,mjs,js,jsx}',
|
|
175
174
|
{
|
|
176
|
-
cwd: root,
|
|
177
175
|
nodir: true,
|
|
178
176
|
absolute: true,
|
|
179
177
|
},
|
package/source/package.ts
CHANGED
|
@@ -4,16 +4,14 @@ import {exec as execCommand} from 'child_process';
|
|
|
4
4
|
import {promisify} from 'util';
|
|
5
5
|
|
|
6
6
|
import {Plugin, type RollupOptions, type OutputOptions} from 'rollup';
|
|
7
|
-
import {glob} from 'glob';
|
|
8
7
|
|
|
9
8
|
import {multiline} from './shared/strings.ts';
|
|
10
|
-
import {
|
|
9
|
+
import {Project, sourceEntriesForProject} from './shared/project.ts';
|
|
11
10
|
import {
|
|
12
11
|
getNodePlugins,
|
|
13
12
|
removeBuildFiles,
|
|
14
13
|
type RollupNodePluginOptions,
|
|
15
14
|
} from './shared/rollup.ts';
|
|
16
|
-
import {loadPackageJSON, type PackageJSON} from './shared/package-json.ts';
|
|
17
15
|
import {
|
|
18
16
|
getBrowserGroupTargetDetails,
|
|
19
17
|
rollupGenerateOptionsForBrowsers,
|
|
@@ -128,7 +126,7 @@ export interface PackageOptions extends PackageESModuleOptions {
|
|
|
128
126
|
}
|
|
129
127
|
|
|
130
128
|
export async function quiltPackage({
|
|
131
|
-
root
|
|
129
|
+
root = process.cwd(),
|
|
132
130
|
commonjs = false,
|
|
133
131
|
esnext: explicitESNext,
|
|
134
132
|
entries,
|
|
@@ -138,10 +136,8 @@ export async function quiltPackage({
|
|
|
138
136
|
graphql = true,
|
|
139
137
|
customize,
|
|
140
138
|
}: PackageOptions = {}) {
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const resolvedEntries =
|
|
144
|
-
entries ?? (await sourceEntriesForPackage(root, packageJSON));
|
|
139
|
+
const project = Project.load(root);
|
|
140
|
+
const resolvedEntries = entries ?? (await sourceEntriesForProject(project));
|
|
145
141
|
|
|
146
142
|
const includeESNext =
|
|
147
143
|
explicitESNext ?? Object.keys(resolvedEntries).length > 0;
|
|
@@ -173,37 +169,39 @@ export async function quiltPackage({
|
|
|
173
169
|
}
|
|
174
170
|
|
|
175
171
|
export async function quiltPackageESModules({
|
|
176
|
-
root
|
|
172
|
+
root = process.cwd(),
|
|
177
173
|
commonjs = false,
|
|
178
174
|
entries,
|
|
179
175
|
executable = {},
|
|
180
|
-
react,
|
|
176
|
+
react: useReact,
|
|
181
177
|
bundle,
|
|
182
178
|
graphql = true,
|
|
183
179
|
customize,
|
|
184
180
|
}: PackageESModuleOptions = {}) {
|
|
185
|
-
const
|
|
186
|
-
const outputDirectory =
|
|
181
|
+
const project = Project.load(root);
|
|
182
|
+
const outputDirectory = project.resolve('build/esm');
|
|
187
183
|
const hasExecutables = Object.keys(executable).length > 0;
|
|
188
184
|
|
|
189
|
-
const [{sourceCode}, {esnext}, nodePlugins,
|
|
185
|
+
const [{sourceCode}, {react}, {esnext}, nodePlugins, browserGroup] =
|
|
190
186
|
await Promise.all([
|
|
191
187
|
import('./features/source-code.ts'),
|
|
188
|
+
import('./features/react.ts'),
|
|
192
189
|
import('./features/esnext.ts'),
|
|
193
190
|
getNodePlugins({bundle}),
|
|
194
|
-
|
|
195
|
-
getBrowserGroupTargetDetails({name: 'default'}, {root}),
|
|
191
|
+
getBrowserGroupTargetDetails({name: 'default'}, {root: project.root}),
|
|
196
192
|
]);
|
|
197
193
|
|
|
198
|
-
const resolvedEntries =
|
|
199
|
-
entries ?? (await sourceEntriesForPackage(root, packageJSON));
|
|
194
|
+
const resolvedEntries = entries ?? (await sourceEntriesForProject(project));
|
|
200
195
|
const hasEntries = Object.keys(resolvedEntries).length > 0;
|
|
201
196
|
|
|
202
|
-
const source = sourceForEntries(
|
|
197
|
+
const source = sourceForEntries(
|
|
198
|
+
{...resolvedEntries, ...executable},
|
|
199
|
+
{root: project.root},
|
|
200
|
+
);
|
|
203
201
|
|
|
204
202
|
const plugins: Plugin[] = [
|
|
205
203
|
...nodePlugins,
|
|
206
|
-
sourceCode({mode: 'production', react}),
|
|
204
|
+
sourceCode({mode: 'production', react: useReact}),
|
|
207
205
|
esnext({mode: 'production', babel: false}),
|
|
208
206
|
removeBuildFiles(
|
|
209
207
|
[
|
|
@@ -211,12 +209,16 @@ export async function quiltPackageESModules({
|
|
|
211
209
|
...(commonjs ? ['build/cjs'] : []),
|
|
212
210
|
...(hasExecutables ? ['bin'] : []),
|
|
213
211
|
],
|
|
214
|
-
{root},
|
|
212
|
+
{root: project.root},
|
|
215
213
|
),
|
|
216
214
|
];
|
|
217
215
|
|
|
216
|
+
if (useReact) {
|
|
217
|
+
plugins.push(react());
|
|
218
|
+
}
|
|
219
|
+
|
|
218
220
|
if (hasExecutables) {
|
|
219
|
-
plugins.push(packageExecutables(executable, {root}));
|
|
221
|
+
plugins.push(packageExecutables(executable, {root: project.root}));
|
|
220
222
|
}
|
|
221
223
|
|
|
222
224
|
if (graphql) {
|
|
@@ -261,18 +263,6 @@ export async function quiltPackageESModules({
|
|
|
261
263
|
const options = {
|
|
262
264
|
input: source.files,
|
|
263
265
|
plugins,
|
|
264
|
-
onwarn(warning, defaultWarn) {
|
|
265
|
-
// Removes annoying warnings for React-focused libraries that
|
|
266
|
-
// include 'use client' directives.
|
|
267
|
-
if (
|
|
268
|
-
warning.code === 'MODULE_LEVEL_DIRECTIVE' &&
|
|
269
|
-
/['"]use client['"]/.test(warning.message)
|
|
270
|
-
) {
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
defaultWarn(warning);
|
|
275
|
-
},
|
|
276
266
|
output,
|
|
277
267
|
} satisfies RollupOptions;
|
|
278
268
|
|
|
@@ -319,35 +309,38 @@ export async function quiltPackageESModules({
|
|
|
319
309
|
* ```
|
|
320
310
|
*/
|
|
321
311
|
export async function quiltPackageESNext({
|
|
322
|
-
root
|
|
323
|
-
react,
|
|
312
|
+
root = process.cwd(),
|
|
313
|
+
react: useReact,
|
|
324
314
|
graphql = true,
|
|
325
315
|
entries,
|
|
326
316
|
bundle,
|
|
327
317
|
customize,
|
|
328
318
|
}: PackageBaseOptions = {}) {
|
|
329
|
-
const
|
|
330
|
-
const outputDirectory =
|
|
319
|
+
const project = Project.load(root);
|
|
320
|
+
const outputDirectory = project.resolve('build/esnext');
|
|
331
321
|
|
|
332
|
-
const [{sourceCode}, {esnext}, nodePlugins
|
|
322
|
+
const [{sourceCode}, {react}, {esnext}, nodePlugins] = await Promise.all([
|
|
333
323
|
import('./features/source-code.ts'),
|
|
324
|
+
import('./features/react.ts'),
|
|
334
325
|
import('./features/esnext.ts'),
|
|
335
326
|
getNodePlugins({bundle}),
|
|
336
|
-
loadPackageJSON(root),
|
|
337
327
|
]);
|
|
338
328
|
|
|
339
|
-
const resolvedEntries =
|
|
340
|
-
entries ?? (await sourceEntriesForPackage(root, packageJSON));
|
|
329
|
+
const resolvedEntries = entries ?? (await sourceEntriesForProject(project));
|
|
341
330
|
|
|
342
|
-
const source = sourceForEntries(resolvedEntries, {root});
|
|
331
|
+
const source = sourceForEntries(resolvedEntries, {root: project.root});
|
|
343
332
|
|
|
344
333
|
const plugins: Plugin[] = [
|
|
345
334
|
...nodePlugins,
|
|
346
|
-
sourceCode({mode: 'production', babel: false, react}),
|
|
335
|
+
sourceCode({mode: 'production', babel: false, react: useReact}),
|
|
347
336
|
esnext({mode: 'production', babel: false}),
|
|
348
|
-
removeBuildFiles(['build/esnext'], {root}),
|
|
337
|
+
removeBuildFiles(['build/esnext'], {root: project.root}),
|
|
349
338
|
];
|
|
350
339
|
|
|
340
|
+
if (useReact) {
|
|
341
|
+
plugins.push(react());
|
|
342
|
+
}
|
|
343
|
+
|
|
351
344
|
if (graphql) {
|
|
352
345
|
const {graphql} = await import('./features/graphql.ts');
|
|
353
346
|
plugins.push(graphql({manifest: false}));
|
|
@@ -505,68 +498,3 @@ function sourceForEntries(
|
|
|
505
498
|
|
|
506
499
|
return {root: sourceRoot, files: sourceEntryFiles};
|
|
507
500
|
}
|
|
508
|
-
|
|
509
|
-
async function sourceEntriesForPackage(root: string, packageJSON: PackageJSON) {
|
|
510
|
-
const {main, exports} = packageJSON;
|
|
511
|
-
|
|
512
|
-
const entries: Record<string, string> = {};
|
|
513
|
-
|
|
514
|
-
if (typeof main === 'string') {
|
|
515
|
-
entries['.'] = await resolveTargetFileAsSource(main, root);
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
if (typeof exports === 'string') {
|
|
519
|
-
entries['.'] = await resolveTargetFileAsSource(exports, root);
|
|
520
|
-
return entries;
|
|
521
|
-
} else if (exports == null || typeof exports !== 'object') {
|
|
522
|
-
return entries;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
for (const [exportPath, exportCondition] of Object.entries(
|
|
526
|
-
exports as Record<string, null | string | Record<string, string>>,
|
|
527
|
-
)) {
|
|
528
|
-
let targetFile: string | null | undefined = null;
|
|
529
|
-
|
|
530
|
-
if (exportCondition == null) continue;
|
|
531
|
-
|
|
532
|
-
if (typeof exportCondition === 'string') {
|
|
533
|
-
targetFile = exportCondition;
|
|
534
|
-
} else {
|
|
535
|
-
targetFile ??=
|
|
536
|
-
exportCondition['source'] ??
|
|
537
|
-
exportCondition['quilt:source'] ??
|
|
538
|
-
exportCondition['quilt:esnext'] ??
|
|
539
|
-
Object.values(exportCondition).find(
|
|
540
|
-
(condition) =>
|
|
541
|
-
typeof condition === 'string' && condition.startsWith('./build/'),
|
|
542
|
-
);
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
if (targetFile == null) continue;
|
|
546
|
-
|
|
547
|
-
const sourceFile = await resolveTargetFileAsSource(targetFile, root);
|
|
548
|
-
|
|
549
|
-
entries[exportPath] = sourceFile;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
return entries;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
async function resolveTargetFileAsSource(file: string, root: string) {
|
|
556
|
-
const sourceFile = file.includes('/build/')
|
|
557
|
-
? (
|
|
558
|
-
await glob(
|
|
559
|
-
file
|
|
560
|
-
.replace(/[/]build[/][^/]+[/]/, '/*/')
|
|
561
|
-
.replace(/(\.d\.ts|\.[\w]+)$/, '.*'),
|
|
562
|
-
{
|
|
563
|
-
cwd: root,
|
|
564
|
-
absolute: true,
|
|
565
|
-
ignore: [path.resolve(root, file)],
|
|
566
|
-
},
|
|
567
|
-
)
|
|
568
|
-
)[0]!
|
|
569
|
-
: path.resolve(root, file);
|
|
570
|
-
|
|
571
|
-
return sourceFile;
|
|
572
|
-
}
|
package/source/server.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
1
|
import {type InputPluginOption, type RollupOptions} from 'rollup';
|
|
3
|
-
import {glob} from 'glob';
|
|
4
2
|
|
|
3
|
+
import {Project} from './shared/project.ts';
|
|
5
4
|
import {
|
|
6
5
|
RollupNodePluginOptions,
|
|
7
6
|
getNodePlugins,
|
|
8
7
|
removeBuildFiles,
|
|
9
8
|
} from './shared/rollup.ts';
|
|
10
|
-
|
|
11
|
-
import {loadPackageJSON, type PackageJSON} from './shared/package-json.ts';
|
|
9
|
+
|
|
12
10
|
import {magicModuleRequestRouterEntry} from './features/request-router.ts';
|
|
13
11
|
import {resolveEnvOption, type MagicModuleEnvOptions} from './features/env.ts';
|
|
14
12
|
import {MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER} from './constants.ts';
|
|
@@ -119,10 +117,10 @@ export async function quiltServer({
|
|
|
119
117
|
port,
|
|
120
118
|
host,
|
|
121
119
|
}: ServerOptions = {}) {
|
|
122
|
-
const
|
|
120
|
+
const project = Project.load(rootPath);
|
|
123
121
|
const mode =
|
|
124
122
|
(typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
125
|
-
const outputDirectory =
|
|
123
|
+
const outputDirectory = project.resolve('build/server');
|
|
126
124
|
|
|
127
125
|
const minify = output?.minify ?? false;
|
|
128
126
|
const bundle = output?.bundle;
|
|
@@ -134,24 +132,24 @@ export async function quiltServer({
|
|
|
134
132
|
{magicModuleEnv, replaceProcessEnv},
|
|
135
133
|
{sourceCode},
|
|
136
134
|
{tsconfigAliases},
|
|
135
|
+
{monorepoPackageAliases},
|
|
137
136
|
{react},
|
|
138
137
|
{esnext},
|
|
139
138
|
nodePlugins,
|
|
140
|
-
packageJSON,
|
|
141
139
|
] = await Promise.all([
|
|
142
140
|
import('rollup-plugin-visualizer'),
|
|
143
141
|
import('./features/env.ts'),
|
|
144
142
|
import('./features/source-code.ts'),
|
|
145
143
|
import('./features/typescript.ts'),
|
|
144
|
+
import('./features/node.ts'),
|
|
146
145
|
import('./features/react.ts'),
|
|
147
146
|
import('./features/esnext.ts'),
|
|
148
147
|
getNodePlugins({bundle}),
|
|
149
|
-
loadPackageJSON(root),
|
|
150
148
|
]);
|
|
151
149
|
|
|
152
150
|
const serverEntry = entry
|
|
153
|
-
?
|
|
154
|
-
: await sourceForServer(
|
|
151
|
+
? project.resolve(entry)
|
|
152
|
+
: await sourceForServer(project);
|
|
155
153
|
|
|
156
154
|
const finalEntry =
|
|
157
155
|
format === 'request-router'
|
|
@@ -163,10 +161,11 @@ export async function quiltServer({
|
|
|
163
161
|
replaceProcessEnv({mode}),
|
|
164
162
|
magicModuleEnv({...resolveEnvOption(env), mode}),
|
|
165
163
|
sourceCode({mode, targets: ['current node']}),
|
|
166
|
-
tsconfigAliases({root}),
|
|
164
|
+
tsconfigAliases({root: project.root}),
|
|
165
|
+
monorepoPackageAliases({root: project.root}),
|
|
167
166
|
react(),
|
|
168
167
|
esnext({mode, targets: ['current node']}),
|
|
169
|
-
removeBuildFiles(['build/server', 'build/reports'], {root}),
|
|
168
|
+
removeBuildFiles(['build/server', 'build/reports'], {root: project.root}),
|
|
170
169
|
];
|
|
171
170
|
|
|
172
171
|
if (format === 'request-router') {
|
|
@@ -198,7 +197,7 @@ export async function quiltServer({
|
|
|
198
197
|
template: 'treemap',
|
|
199
198
|
open: false,
|
|
200
199
|
brotliSize: true,
|
|
201
|
-
filename:
|
|
200
|
+
filename: project.resolve(`build/reports/bundle-visualizer.html`),
|
|
202
201
|
}),
|
|
203
202
|
);
|
|
204
203
|
|
|
@@ -206,18 +205,6 @@ export async function quiltServer({
|
|
|
206
205
|
input:
|
|
207
206
|
finalEntry === MAGIC_MODULE_ENTRY ? {server: finalEntry} : finalEntry,
|
|
208
207
|
plugins,
|
|
209
|
-
onwarn(warning, defaultWarn) {
|
|
210
|
-
// Removes annoying warnings for React-focused libraries that
|
|
211
|
-
// include 'use client' directives.
|
|
212
|
-
if (
|
|
213
|
-
warning.code === 'MODULE_LEVEL_DIRECTIVE' &&
|
|
214
|
-
/['"]use client['"]/.test(warning.message)
|
|
215
|
-
) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
defaultWarn(warning);
|
|
220
|
-
},
|
|
221
208
|
output: {
|
|
222
209
|
format:
|
|
223
210
|
outputFormat === 'commonjs' || outputFormat === 'cjs' ? 'cjs' : 'esm',
|
|
@@ -232,19 +219,18 @@ export async function quiltServer({
|
|
|
232
219
|
} satisfies RollupOptions;
|
|
233
220
|
}
|
|
234
221
|
|
|
235
|
-
async function sourceForServer(
|
|
236
|
-
const {main, exports} = packageJSON;
|
|
222
|
+
async function sourceForServer(project: Project) {
|
|
223
|
+
const {main, exports} = project.packageJSON.raw;
|
|
237
224
|
|
|
238
225
|
const entryFromPackageJSON = main ?? (exports as any)?.['.'];
|
|
239
226
|
|
|
240
227
|
if (entryFromPackageJSON) {
|
|
241
|
-
return
|
|
228
|
+
return project.resolve(entryFromPackageJSON);
|
|
242
229
|
}
|
|
243
230
|
|
|
244
|
-
const possibleSourceFiles = await glob(
|
|
231
|
+
const possibleSourceFiles = await project.glob(
|
|
245
232
|
'{index,server,service,backend,entry,input}.{ts,tsx,mjs,js,jsx}',
|
|
246
233
|
{
|
|
247
|
-
cwd: root,
|
|
248
234
|
nodir: true,
|
|
249
235
|
absolute: true,
|
|
250
236
|
},
|