@quilted/rollup 0.1.18 → 0.2.0
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 +25 -0
- package/build/esm/app.mjs +442 -233
- package/build/esm/constants.mjs +5 -5
- package/build/esm/features/assets.mjs +93 -81
- package/build/esm/features/async.mjs +186 -0
- package/build/esm/features/css.mjs +26 -39
- package/build/esm/features/env.mjs +47 -44
- package/build/esm/features/esnext.mjs +57 -0
- package/build/esm/features/graphql/transform.mjs +60 -56
- package/build/esm/features/graphql.mjs +65 -47
- package/build/esm/features/request-router.mjs +6 -4
- package/build/esm/features/source-code.mjs +54 -28
- package/build/esm/features/system-js.mjs +13 -18
- package/build/esm/features/typescript.mjs +13 -10
- package/build/esm/features/workers.mjs +173 -0
- package/build/esm/index.mjs +3 -2
- package/build/esm/module.mjs +69 -62
- package/build/esm/package.mjs +275 -84
- package/build/esm/server.mjs +118 -0
- package/build/esm/shared/browserslist.mjs +141 -16
- package/build/esm/shared/magic-module.mjs +9 -7
- package/build/esm/shared/package-json.mjs +7 -1
- package/build/esm/shared/path.mjs +7 -0
- package/build/esm/shared/rollup.mjs +89 -25
- package/build/esm/shared/strings.mjs +7 -6
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts +126 -27
- package/build/typescript/app.d.ts.map +1 -1
- package/build/typescript/features/assets.d.ts +1 -2
- package/build/typescript/features/assets.d.ts.map +1 -1
- package/build/typescript/features/async.d.ts +10 -0
- package/build/typescript/features/async.d.ts.map +1 -0
- package/build/typescript/features/css.d.ts +2 -1
- package/build/typescript/features/css.d.ts.map +1 -1
- package/build/typescript/features/env.d.ts +1 -0
- package/build/typescript/features/env.d.ts.map +1 -1
- package/build/typescript/features/esnext.d.ts +9 -0
- package/build/typescript/features/esnext.d.ts.map +1 -0
- package/build/typescript/features/graphql.d.ts +2 -2
- package/build/typescript/features/graphql.d.ts.map +1 -1
- package/build/typescript/features/source-code.d.ts +9 -3
- package/build/typescript/features/source-code.d.ts.map +1 -1
- package/build/typescript/features/workers.d.ts +52 -0
- package/build/typescript/features/workers.d.ts.map +1 -0
- package/build/typescript/index.d.ts +3 -2
- package/build/typescript/index.d.ts.map +1 -1
- package/build/typescript/module.d.ts +24 -6
- package/build/typescript/module.d.ts.map +1 -1
- package/build/typescript/package.d.ts +196 -4
- package/build/typescript/package.d.ts.map +1 -1
- package/build/typescript/server.d.ts +98 -0
- package/build/typescript/server.d.ts.map +1 -0
- package/build/typescript/shared/browserslist.d.ts +20 -3
- package/build/typescript/shared/browserslist.d.ts.map +1 -1
- package/build/typescript/shared/path.d.ts +2 -0
- package/build/typescript/shared/path.d.ts.map +1 -0
- package/build/typescript/shared/rollup.d.ts +27 -1
- package/build/typescript/shared/rollup.d.ts.map +1 -1
- package/configuration/rollup.config.js +40 -0
- package/package.json +61 -8
- package/source/app.ts +472 -109
- package/source/features/assets.ts +5 -7
- package/source/features/async.ts +249 -0
- package/source/features/css.ts +4 -2
- package/source/features/env.ts +6 -0
- package/source/features/esnext.ts +70 -0
- package/source/features/graphql.ts +4 -2
- package/source/features/source-code.ts +26 -8
- package/source/features/workers.ts +292 -0
- package/source/index.ts +4 -0
- package/source/module.ts +45 -19
- package/source/package.ts +394 -36
- package/source/server.ts +245 -0
- package/source/shared/browserslist.ts +208 -18
- package/source/shared/path.ts +5 -0
- package/source/shared/rollup.ts +102 -4
- package/tsconfig.json +6 -2
- package/build/cjs/app.cjs +0 -456
- package/build/cjs/constants.cjs +0 -13
- package/build/cjs/features/assets.cjs +0 -240
- package/build/cjs/features/css.cjs +0 -71
- package/build/cjs/features/env.cjs +0 -135
- package/build/cjs/features/graphql/transform.cjs +0 -186
- package/build/cjs/features/graphql.cjs +0 -86
- package/build/cjs/features/request-router.cjs +0 -31
- package/build/cjs/features/source-code.cjs +0 -54
- package/build/cjs/features/system-js.cjs +0 -36
- package/build/cjs/features/typescript.cjs +0 -56
- package/build/cjs/index.cjs +0 -13
- package/build/cjs/module.cjs +0 -121
- package/build/cjs/package.cjs +0 -170
- package/build/cjs/shared/browserslist.cjs +0 -25
- package/build/cjs/shared/magic-module.cjs +0 -32
- package/build/cjs/shared/package-json.cjs +0 -31
- package/build/cjs/shared/rollup.cjs +0 -72
- package/build/cjs/shared/strings.cjs +0 -16
- package/build/esnext/app.esnext +0 -429
- package/build/esnext/constants.esnext +0 -7
- package/build/esnext/features/assets.esnext +0 -215
- package/build/esnext/features/css.esnext +0 -69
- package/build/esnext/features/env.esnext +0 -112
- package/build/esnext/features/graphql/transform.esnext +0 -181
- package/build/esnext/features/graphql.esnext +0 -84
- package/build/esnext/features/request-router.esnext +0 -29
- package/build/esnext/features/source-code.esnext +0 -51
- package/build/esnext/features/system-js.esnext +0 -33
- package/build/esnext/features/typescript.esnext +0 -34
- package/build/esnext/index.esnext +0 -3
- package/build/esnext/module.esnext +0 -100
- package/build/esnext/package.esnext +0 -148
- package/build/esnext/shared/browserslist.esnext +0 -23
- package/build/esnext/shared/magic-module.esnext +0 -30
- package/build/esnext/shared/package-json.esnext +0 -10
- package/build/esnext/shared/rollup.esnext +0 -49
- package/build/esnext/shared/strings.esnext +0 -14
- package/build/typescript/env.d.ts +0 -55
- package/build/typescript/env.d.ts.map +0 -1
- package/build/typescript/graphql/transform.d.ts +0 -17
- package/build/typescript/graphql/transform.d.ts.map +0 -1
- package/build/typescript/graphql.d.ts +0 -6
- package/build/typescript/graphql.d.ts.map +0 -1
- package/build/typescript/request-router.d.ts +0 -15
- package/build/typescript/request-router.d.ts.map +0 -1
- package/build/typescript/shared/source-code.d.ts +0 -5
- package/build/typescript/shared/source-code.d.ts.map +0 -1
- package/quilt.project.ts +0 -5
package/build/esm/package.mjs
CHANGED
|
@@ -1,84 +1,185 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
|
+
import * as fs from 'node:fs/promises';
|
|
3
|
+
import { exec as exec$1 } from 'node:child_process';
|
|
4
|
+
import { promisify } from 'node:util';
|
|
2
5
|
import { glob } from 'glob';
|
|
3
|
-
import {
|
|
6
|
+
import { multiline } from './shared/strings.mjs';
|
|
7
|
+
import { resolveRoot } from './shared/path.mjs';
|
|
4
8
|
import { getNodePlugins, removeBuildFiles } from './shared/rollup.mjs';
|
|
5
9
|
import { loadPackageJSON } from './shared/package-json.mjs';
|
|
10
|
+
import { getBrowserGroupTargetDetails, rollupGenerateOptionsForBrowsers } from './shared/browserslist.mjs';
|
|
6
11
|
|
|
12
|
+
async function quiltPackage({
|
|
13
|
+
root: rootPath = process.cwd(),
|
|
14
|
+
commonjs = false,
|
|
15
|
+
esnext: explicitESNext,
|
|
16
|
+
entries,
|
|
17
|
+
executable,
|
|
18
|
+
bundle,
|
|
19
|
+
react,
|
|
20
|
+
graphql = true,
|
|
21
|
+
customize
|
|
22
|
+
} = {}) {
|
|
23
|
+
const root = resolveRoot(rootPath);
|
|
24
|
+
const packageJSON = await loadPackageJSON(root);
|
|
25
|
+
const resolvedEntries = entries ?? await sourceEntriesForPackage(root, packageJSON);
|
|
26
|
+
const includeESNext = explicitESNext ?? Object.keys(resolvedEntries).length > 0;
|
|
27
|
+
const [esm, esnext] = await Promise.all([
|
|
28
|
+
quiltPackageESModules({
|
|
29
|
+
root,
|
|
30
|
+
react,
|
|
31
|
+
graphql,
|
|
32
|
+
entries: resolvedEntries,
|
|
33
|
+
executable,
|
|
34
|
+
bundle,
|
|
35
|
+
commonjs,
|
|
36
|
+
customize
|
|
37
|
+
}),
|
|
38
|
+
includeESNext ? quiltPackageESNext({
|
|
39
|
+
root,
|
|
40
|
+
react,
|
|
41
|
+
graphql,
|
|
42
|
+
entries: resolvedEntries,
|
|
43
|
+
bundle,
|
|
44
|
+
customize
|
|
45
|
+
}) : Promise.resolve(void 0)
|
|
46
|
+
]);
|
|
47
|
+
return esnext ? [esm, esnext] : [esm];
|
|
48
|
+
}
|
|
7
49
|
async function quiltPackageESModules({
|
|
8
50
|
root: rootPath = process.cwd(),
|
|
9
|
-
|
|
51
|
+
commonjs = false,
|
|
52
|
+
entries,
|
|
53
|
+
executable = {},
|
|
54
|
+
react,
|
|
55
|
+
bundle,
|
|
56
|
+
graphql = true,
|
|
57
|
+
customize
|
|
10
58
|
} = {}) {
|
|
11
|
-
const root =
|
|
12
|
-
const outputDirectory = path.
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
59
|
+
const root = resolveRoot(rootPath);
|
|
60
|
+
const outputDirectory = path.resolve(root, "build/esm");
|
|
61
|
+
const hasExecutables = Object.keys(executable).length > 0;
|
|
62
|
+
const [{ sourceCode }, { esnext }, nodePlugins, packageJSON, browserGroup] = await Promise.all([
|
|
63
|
+
import('./features/source-code.mjs'),
|
|
64
|
+
import('./features/esnext.mjs'),
|
|
65
|
+
getNodePlugins({ bundle }),
|
|
66
|
+
loadPackageJSON(root),
|
|
67
|
+
getBrowserGroupTargetDetails({ name: "default" }, { root })
|
|
68
|
+
]);
|
|
69
|
+
const resolvedEntries = entries ?? await sourceEntriesForPackage(root, packageJSON);
|
|
70
|
+
const hasEntries = Object.keys(resolvedEntries).length > 0;
|
|
71
|
+
const source = sourceForEntries({ ...resolvedEntries, ...executable }, { root });
|
|
72
|
+
const plugins = [
|
|
73
|
+
...nodePlugins,
|
|
74
|
+
sourceCode({ mode: "production", react }),
|
|
75
|
+
esnext({ mode: "production", babel: false }),
|
|
76
|
+
removeBuildFiles(
|
|
77
|
+
[
|
|
78
|
+
"build/esm",
|
|
79
|
+
...commonjs ? ["build/cjs"] : [],
|
|
80
|
+
...hasExecutables ? ["bin"] : []
|
|
81
|
+
],
|
|
82
|
+
{ root }
|
|
83
|
+
)
|
|
84
|
+
];
|
|
85
|
+
if (hasExecutables) {
|
|
86
|
+
plugins.push(packageExecutables(executable, { root }));
|
|
87
|
+
}
|
|
22
88
|
if (graphql) {
|
|
23
|
-
const {
|
|
24
|
-
|
|
25
|
-
} = await import('./features/graphql.mjs');
|
|
26
|
-
plugins.push(graphql({
|
|
27
|
-
manifest: false
|
|
28
|
-
}));
|
|
89
|
+
const { graphql: graphql2 } = await import('./features/graphql.mjs');
|
|
90
|
+
plugins.push(graphql2({ manifest: false }));
|
|
29
91
|
}
|
|
30
|
-
|
|
92
|
+
const generatedCode = await rollupGenerateOptionsForBrowsers(
|
|
93
|
+
browserGroup.browsers
|
|
94
|
+
);
|
|
95
|
+
const output = [
|
|
96
|
+
{
|
|
97
|
+
format: "esm",
|
|
98
|
+
dir: outputDirectory,
|
|
99
|
+
entryFileNames: `[name].mjs`,
|
|
100
|
+
assetFileNames: `[name].[ext]`,
|
|
101
|
+
generatedCode,
|
|
102
|
+
// We only want to preserve the original directory structure if there
|
|
103
|
+
// are actual package entries.
|
|
104
|
+
...hasEntries ? {
|
|
105
|
+
preserveModules: true,
|
|
106
|
+
preserveModulesRoot: source.root
|
|
107
|
+
} : {}
|
|
108
|
+
}
|
|
109
|
+
];
|
|
110
|
+
if (commonjs) {
|
|
111
|
+
output.push({
|
|
112
|
+
format: "commonjs",
|
|
113
|
+
dir: path.resolve(outputDirectory, "../cjs"),
|
|
114
|
+
entryFileNames: `[name].cjs`,
|
|
115
|
+
assetFileNames: `[name].[ext]`,
|
|
116
|
+
preserveModules: true,
|
|
117
|
+
preserveModulesRoot: source.root,
|
|
118
|
+
generatedCode
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
const options = {
|
|
31
122
|
input: source.files,
|
|
32
123
|
plugins,
|
|
33
124
|
onwarn(warning, defaultWarn) {
|
|
34
|
-
|
|
35
|
-
// include 'use client' directives.
|
|
36
|
-
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
|
|
125
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && /['"]use client['"]/.test(warning.message)) {
|
|
37
126
|
return;
|
|
38
127
|
}
|
|
39
128
|
defaultWarn(warning);
|
|
40
129
|
},
|
|
41
|
-
output
|
|
42
|
-
preserveModules: true,
|
|
43
|
-
preserveModulesRoot: source.root,
|
|
44
|
-
format: 'esm',
|
|
45
|
-
dir: outputDirectory,
|
|
46
|
-
entryFileNames: `[name].mjs`,
|
|
47
|
-
assetFileNames: `[name].[ext]`
|
|
48
|
-
}
|
|
130
|
+
output
|
|
49
131
|
};
|
|
132
|
+
if (customize) {
|
|
133
|
+
if (typeof customize === "function") {
|
|
134
|
+
return await customize(options);
|
|
135
|
+
} else {
|
|
136
|
+
const customizedPlugins = await customize.plugins;
|
|
137
|
+
return {
|
|
138
|
+
...options,
|
|
139
|
+
...customize,
|
|
140
|
+
plugins: [
|
|
141
|
+
...options.plugins,
|
|
142
|
+
...Array.isArray(customizedPlugins) ? customizedPlugins : [customizedPlugins]
|
|
143
|
+
]
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
return options;
|
|
148
|
+
}
|
|
50
149
|
}
|
|
51
150
|
async function quiltPackageESNext({
|
|
52
151
|
root: rootPath = process.cwd(),
|
|
53
|
-
|
|
152
|
+
react,
|
|
153
|
+
graphql = true,
|
|
154
|
+
entries,
|
|
155
|
+
bundle,
|
|
156
|
+
customize
|
|
54
157
|
} = {}) {
|
|
55
|
-
const root =
|
|
56
|
-
const outputDirectory = path.join(root,
|
|
57
|
-
const [{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
158
|
+
const root = resolveRoot(rootPath);
|
|
159
|
+
const outputDirectory = path.join(root, "build/esnext");
|
|
160
|
+
const [{ sourceCode }, { esnext }, nodePlugins, packageJSON] = await Promise.all([
|
|
161
|
+
import('./features/source-code.mjs'),
|
|
162
|
+
import('./features/esnext.mjs'),
|
|
163
|
+
getNodePlugins({ bundle }),
|
|
164
|
+
loadPackageJSON(root)
|
|
165
|
+
]);
|
|
166
|
+
const resolvedEntries = entries ?? await sourceEntriesForPackage(root, packageJSON);
|
|
167
|
+
const source = sourceForEntries(resolvedEntries, { root });
|
|
168
|
+
const plugins = [
|
|
169
|
+
...nodePlugins,
|
|
170
|
+
sourceCode({ mode: "production", babel: false, react }),
|
|
171
|
+
esnext({ mode: "production", babel: false }),
|
|
172
|
+
removeBuildFiles(["build/esnext"], { root })
|
|
173
|
+
];
|
|
67
174
|
if (graphql) {
|
|
68
|
-
const {
|
|
69
|
-
|
|
70
|
-
} = await import('./features/graphql.mjs');
|
|
71
|
-
plugins.push(graphql({
|
|
72
|
-
manifest: false
|
|
73
|
-
}));
|
|
175
|
+
const { graphql: graphql2 } = await import('./features/graphql.mjs');
|
|
176
|
+
plugins.push(graphql2({ manifest: false }));
|
|
74
177
|
}
|
|
75
|
-
|
|
178
|
+
const options = {
|
|
76
179
|
input: source.files,
|
|
77
180
|
plugins,
|
|
78
181
|
onwarn(warning, defaultWarn) {
|
|
79
|
-
|
|
80
|
-
// include 'use client' directives.
|
|
81
|
-
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
|
|
182
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && /['"]use client['"]/.test(warning.message)) {
|
|
82
183
|
return;
|
|
83
184
|
}
|
|
84
185
|
defaultWarn(warning);
|
|
@@ -86,63 +187,153 @@ async function quiltPackageESNext({
|
|
|
86
187
|
output: {
|
|
87
188
|
preserveModules: true,
|
|
88
189
|
preserveModulesRoot: source.root,
|
|
89
|
-
format:
|
|
190
|
+
format: "esm",
|
|
90
191
|
dir: outputDirectory,
|
|
91
192
|
entryFileNames: `[name].esnext`,
|
|
92
|
-
assetFileNames: `[name].[ext]
|
|
193
|
+
assetFileNames: `[name].[ext]`,
|
|
194
|
+
generatedCode: "es2015"
|
|
93
195
|
}
|
|
94
196
|
};
|
|
197
|
+
if (customize) {
|
|
198
|
+
if (typeof customize === "function") {
|
|
199
|
+
return await customize(options);
|
|
200
|
+
} else {
|
|
201
|
+
const customizedPlugins = await customize.plugins;
|
|
202
|
+
return {
|
|
203
|
+
...options,
|
|
204
|
+
...customize,
|
|
205
|
+
plugins: [
|
|
206
|
+
...options.plugins,
|
|
207
|
+
...Array.isArray(customizedPlugins) ? customizedPlugins : [customizedPlugins]
|
|
208
|
+
]
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
return options;
|
|
213
|
+
}
|
|
95
214
|
}
|
|
96
|
-
|
|
97
|
-
|
|
215
|
+
const exec = promisify(exec$1);
|
|
216
|
+
function packageExecutables(executables, { root, nodeOptions = [] }) {
|
|
217
|
+
return {
|
|
218
|
+
name: "@quilted/package-executables",
|
|
219
|
+
async generateBundle() {
|
|
220
|
+
await Promise.all(
|
|
221
|
+
Object.entries(executables).map(async ([name, source]) => {
|
|
222
|
+
await writeExecutable(name, source);
|
|
223
|
+
})
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
async function writeExecutable(name, source) {
|
|
228
|
+
const sourceExtension = path.extname(source);
|
|
229
|
+
let buildFileForSource = source.replace("source", "build/esm");
|
|
230
|
+
buildFileForSource = path.join(
|
|
231
|
+
path.dirname(buildFileForSource),
|
|
232
|
+
`${path.basename(buildFileForSource, sourceExtension)}.mjs`
|
|
233
|
+
);
|
|
234
|
+
const executableFile = path.resolve(
|
|
235
|
+
root,
|
|
236
|
+
"bin",
|
|
237
|
+
// Node needs a .mjs extension to parse the file as ESM
|
|
238
|
+
name.endsWith(".mjs") ? name : `${name}.mjs`
|
|
239
|
+
);
|
|
240
|
+
const relativeFromExecutable = normalizedRelative(
|
|
241
|
+
path.dirname(executableFile),
|
|
242
|
+
path.resolve(root, buildFileForSource)
|
|
243
|
+
);
|
|
244
|
+
const executableContent = nodeOptions.length > 0 ? multiline`
|
|
245
|
+
#!/usr/bin/env node
|
|
246
|
+
|
|
247
|
+
import {spawn} from 'child_process';
|
|
248
|
+
import {fileURLToPath} from 'url';
|
|
249
|
+
import {dirname, resolve} from 'path';
|
|
250
|
+
|
|
251
|
+
const executableFile = resolve(
|
|
252
|
+
dirname(fileURLToPath(import.meta.url)),
|
|
253
|
+
${JSON.stringify(relativeFromExecutable)},
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
spawn(
|
|
257
|
+
process.execPath,
|
|
258
|
+
[
|
|
259
|
+
${nodeOptions.map((option) => ` ${JSON.stringify(option)},`).join("\n")}
|
|
260
|
+
...process.execArgv,
|
|
261
|
+
executableFile,
|
|
262
|
+
...process.argv.slice(2),
|
|
263
|
+
],
|
|
264
|
+
{stdio: 'inherit'},
|
|
265
|
+
).on('exit', (code) => {
|
|
266
|
+
process.exit(code == null ? 1 : code);
|
|
267
|
+
});
|
|
268
|
+
` : multiline`
|
|
269
|
+
#!/usr/bin/env node
|
|
270
|
+
import ${JSON.stringify(relativeFromExecutable)};
|
|
271
|
+
`;
|
|
272
|
+
await fs.mkdir(path.dirname(executableFile), { recursive: true });
|
|
273
|
+
await fs.writeFile(executableFile, executableContent, "utf8");
|
|
274
|
+
await exec(`chmod +x ${executableFile}`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function normalizedRelative(from, to) {
|
|
278
|
+
const rel = path.relative(from, to);
|
|
279
|
+
return rel.startsWith(".") ? rel : `./${rel}`;
|
|
280
|
+
}
|
|
281
|
+
function sourceForEntries(entries, { root }) {
|
|
98
282
|
let sourceRoot = root;
|
|
99
283
|
const sourceEntryFiles = Object.values(entries);
|
|
100
284
|
for (const entry of sourceEntryFiles) {
|
|
101
|
-
if (!entry.startsWith(root))
|
|
102
|
-
|
|
285
|
+
if (!entry.startsWith(root))
|
|
286
|
+
continue;
|
|
287
|
+
sourceRoot = path.resolve(
|
|
288
|
+
root,
|
|
289
|
+
path.relative(root, entry).split(path.sep)[0] ?? "."
|
|
290
|
+
);
|
|
103
291
|
break;
|
|
104
292
|
}
|
|
105
|
-
return {
|
|
106
|
-
root: sourceRoot,
|
|
107
|
-
files: sourceEntryFiles
|
|
108
|
-
};
|
|
293
|
+
return { root: sourceRoot, files: sourceEntryFiles };
|
|
109
294
|
}
|
|
110
295
|
async function sourceEntriesForPackage(root, packageJSON) {
|
|
111
|
-
const {
|
|
112
|
-
main,
|
|
113
|
-
exports
|
|
114
|
-
} = packageJSON;
|
|
296
|
+
const { main, exports } = packageJSON;
|
|
115
297
|
const entries = {};
|
|
116
|
-
if (typeof main ===
|
|
117
|
-
entries[
|
|
298
|
+
if (typeof main === "string") {
|
|
299
|
+
entries["."] = await resolveTargetFileAsSource(main, root);
|
|
118
300
|
}
|
|
119
|
-
if (typeof exports ===
|
|
120
|
-
entries[
|
|
301
|
+
if (typeof exports === "string") {
|
|
302
|
+
entries["."] = await resolveTargetFileAsSource(exports, root);
|
|
121
303
|
return entries;
|
|
122
|
-
} else if (exports == null || typeof exports !==
|
|
304
|
+
} else if (exports == null || typeof exports !== "object") {
|
|
123
305
|
return entries;
|
|
124
306
|
}
|
|
125
|
-
for (const [exportPath, exportCondition] of Object.entries(
|
|
307
|
+
for (const [exportPath, exportCondition] of Object.entries(
|
|
308
|
+
exports
|
|
309
|
+
)) {
|
|
126
310
|
let targetFile = null;
|
|
127
|
-
if (exportCondition == null)
|
|
128
|
-
|
|
311
|
+
if (exportCondition == null)
|
|
312
|
+
continue;
|
|
313
|
+
if (typeof exportCondition === "string") {
|
|
129
314
|
targetFile = exportCondition;
|
|
130
315
|
} else {
|
|
131
|
-
targetFile
|
|
316
|
+
targetFile ??= exportCondition["source"] ?? exportCondition["quilt:source"] ?? exportCondition["quilt:esnext"] ?? Object.values(exportCondition).find(
|
|
317
|
+
(condition) => typeof condition === "string" && condition.startsWith("./build/")
|
|
318
|
+
);
|
|
132
319
|
}
|
|
133
|
-
if (targetFile == null)
|
|
320
|
+
if (targetFile == null)
|
|
321
|
+
continue;
|
|
134
322
|
const sourceFile = await resolveTargetFileAsSource(targetFile, root);
|
|
135
323
|
entries[exportPath] = sourceFile;
|
|
136
324
|
}
|
|
137
325
|
return entries;
|
|
138
326
|
}
|
|
139
327
|
async function resolveTargetFileAsSource(file, root) {
|
|
140
|
-
const sourceFile = file.includes(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
328
|
+
const sourceFile = file.includes("/build/") ? (await glob(
|
|
329
|
+
file.replace(/[/]build[/][^/]+[/]/, "/*/").replace(/(\.d\.ts|\.[\w]+)$/, ".*"),
|
|
330
|
+
{
|
|
331
|
+
cwd: root,
|
|
332
|
+
absolute: true,
|
|
333
|
+
ignore: [path.resolve(root, file)]
|
|
334
|
+
}
|
|
335
|
+
))[0] : path.resolve(root, file);
|
|
145
336
|
return sourceFile;
|
|
146
337
|
}
|
|
147
338
|
|
|
148
|
-
export { quiltPackageESModules, quiltPackageESNext };
|
|
339
|
+
export { packageExecutables, quiltPackage, quiltPackageESModules, quiltPackageESNext };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import { glob } from 'glob';
|
|
3
|
+
import { getNodePlugins, removeBuildFiles } from './shared/rollup.mjs';
|
|
4
|
+
import { resolveRoot } from './shared/path.mjs';
|
|
5
|
+
import { loadPackageJSON } from './shared/package-json.mjs';
|
|
6
|
+
import { magicModuleRequestRouterEntry } from './features/request-router.mjs';
|
|
7
|
+
import { resolveEnvOption } from './features/env.mjs';
|
|
8
|
+
import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER } from './constants.mjs';
|
|
9
|
+
import { createMagicModulePlugin } from './shared/magic-module.mjs';
|
|
10
|
+
|
|
11
|
+
async function quiltServer({
|
|
12
|
+
root: rootPath = process.cwd(),
|
|
13
|
+
entry,
|
|
14
|
+
format = "request-router",
|
|
15
|
+
env,
|
|
16
|
+
graphql = true,
|
|
17
|
+
output,
|
|
18
|
+
port,
|
|
19
|
+
host
|
|
20
|
+
} = {}) {
|
|
21
|
+
const root = resolveRoot(rootPath);
|
|
22
|
+
const mode = (typeof env === "object" ? env?.mode : void 0) ?? "production";
|
|
23
|
+
const outputDirectory = path.join(root, "build/server");
|
|
24
|
+
const minify = output?.minify ?? false;
|
|
25
|
+
const bundle = output?.bundle;
|
|
26
|
+
const hash = output?.hash ?? "async-only";
|
|
27
|
+
const outputFormat = output?.format ?? "esmodules";
|
|
28
|
+
const [
|
|
29
|
+
{ visualizer },
|
|
30
|
+
{ magicModuleEnv, replaceProcessEnv },
|
|
31
|
+
{ sourceCode },
|
|
32
|
+
{ esnext },
|
|
33
|
+
nodePlugins,
|
|
34
|
+
packageJSON
|
|
35
|
+
] = await Promise.all([
|
|
36
|
+
import('rollup-plugin-visualizer'),
|
|
37
|
+
import('./features/env.mjs'),
|
|
38
|
+
import('./features/source-code.mjs'),
|
|
39
|
+
import('./features/esnext.mjs'),
|
|
40
|
+
getNodePlugins({ bundle }),
|
|
41
|
+
loadPackageJSON(root)
|
|
42
|
+
]);
|
|
43
|
+
const serverEntry = entry ? path.resolve(root, entry) : await sourceForServer(root, packageJSON);
|
|
44
|
+
const finalEntry = format === "request-router" ? MAGIC_MODULE_ENTRY : serverEntry ?? MAGIC_MODULE_ENTRY;
|
|
45
|
+
const plugins = [
|
|
46
|
+
...nodePlugins,
|
|
47
|
+
replaceProcessEnv({ mode }),
|
|
48
|
+
magicModuleEnv({ ...resolveEnvOption(env), mode }),
|
|
49
|
+
sourceCode({ mode, targets: ["current node"] }),
|
|
50
|
+
esnext({ mode, targets: ["current node"] }),
|
|
51
|
+
removeBuildFiles(["build/server", "build/reports"], { root })
|
|
52
|
+
];
|
|
53
|
+
if (format === "request-router") {
|
|
54
|
+
plugins.push(
|
|
55
|
+
createMagicModulePlugin({
|
|
56
|
+
name: "@quilted/magic-module/server-request-router",
|
|
57
|
+
module: MAGIC_MODULE_REQUEST_ROUTER,
|
|
58
|
+
alias: serverEntry
|
|
59
|
+
}),
|
|
60
|
+
magicModuleRequestRouterEntry({
|
|
61
|
+
host,
|
|
62
|
+
port: typeof port === "string" ? Number.parseInt(port, 10) : port
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
if (graphql) {
|
|
67
|
+
const { graphql: graphql2 } = await import('./features/graphql.mjs');
|
|
68
|
+
plugins.push(graphql2({ manifest: false }));
|
|
69
|
+
}
|
|
70
|
+
if (minify) {
|
|
71
|
+
const { minify: minify2 } = await import('rollup-plugin-esbuild');
|
|
72
|
+
plugins.push(minify2());
|
|
73
|
+
}
|
|
74
|
+
plugins.push(
|
|
75
|
+
visualizer({
|
|
76
|
+
template: "treemap",
|
|
77
|
+
open: false,
|
|
78
|
+
brotliSize: true,
|
|
79
|
+
filename: path.resolve(root, `build/reports/bundle-visualizer.html`)
|
|
80
|
+
})
|
|
81
|
+
);
|
|
82
|
+
return {
|
|
83
|
+
input: finalEntry,
|
|
84
|
+
plugins,
|
|
85
|
+
onwarn(warning, defaultWarn) {
|
|
86
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && /['"]use client['"]/.test(warning.message)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
defaultWarn(warning);
|
|
90
|
+
},
|
|
91
|
+
output: {
|
|
92
|
+
format: outputFormat === "commonjs" || outputFormat === "cjs" ? "cjs" : "esm",
|
|
93
|
+
dir: outputDirectory,
|
|
94
|
+
entryFileNames: `server${hash === true ? `.[hash]` : ""}.js`,
|
|
95
|
+
chunkFileNames: `[name]${hash === true || hash === "async-only" ? `.[hash]` : ""}.js`,
|
|
96
|
+
assetFileNames: `[name]${hash === true ? `.[hash]` : ""}.[ext]`,
|
|
97
|
+
generatedCode: "es2015"
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async function sourceForServer(root, packageJSON) {
|
|
102
|
+
const { main, exports } = packageJSON;
|
|
103
|
+
const entryFromPackageJSON = main ?? exports?.["."];
|
|
104
|
+
if (entryFromPackageJSON) {
|
|
105
|
+
return path.resolve(root, entryFromPackageJSON);
|
|
106
|
+
}
|
|
107
|
+
const possibleSourceFiles = await glob(
|
|
108
|
+
"{index,server,service,backend,entry,input}.{ts,tsx,mjs,js,jsx}",
|
|
109
|
+
{
|
|
110
|
+
cwd: root,
|
|
111
|
+
nodir: true,
|
|
112
|
+
absolute: true
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
return possibleSourceFiles[0];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export { quiltServer };
|