@utoo/pack 0.0.1-alpha.2 → 0.0.1-alpha.20
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/cjs/binding.d.ts +11 -9
- package/cjs/build.d.ts +4 -2
- package/cjs/build.js +18 -11
- package/cjs/dev.d.ts +44 -0
- package/cjs/dev.js +362 -0
- package/cjs/{hotReloader.d.ts → hmr.d.ts} +4 -11
- package/cjs/{hotReloader.js → hmr.js} +14 -61
- package/cjs/index.d.ts +13 -14
- package/cjs/index.js +6 -4
- package/cjs/mkcert.d.ts +7 -0
- package/cjs/mkcert.js +183 -0
- package/cjs/project.d.ts +4 -4
- package/cjs/project.js +0 -2
- package/cjs/types.d.ts +22 -9
- package/cjs/util.d.ts +1 -1
- package/cjs/util.js +1 -1
- package/cjs/webpackCompat.d.ts +6 -0
- package/cjs/webpackCompat.js +341 -0
- package/esm/binding.d.ts +11 -9
- package/esm/build.d.ts +4 -2
- package/esm/build.js +18 -11
- package/esm/dev.d.ts +44 -0
- package/esm/dev.js +346 -0
- package/esm/{hotReloader.d.ts → hmr.d.ts} +4 -11
- package/esm/{hotReloader.js → hmr.js} +14 -60
- package/esm/index.d.ts +13 -14
- package/esm/index.js +6 -2
- package/esm/mkcert.d.ts +7 -0
- package/esm/mkcert.js +176 -0
- package/esm/project.d.ts +4 -4
- package/esm/project.js +0 -2
- package/esm/types.d.ts +22 -9
- package/esm/util.d.ts +1 -1
- package/esm/util.js +1 -1
- package/esm/webpackCompat.d.ts +6 -0
- package/esm/webpackCompat.js +338 -0
- package/package.json +15 -10
- package/cjs/sourceMap.d.ts +0 -21
- package/cjs/sourceMap.js +0 -2
- package/cjs/watch.d.ts +0 -2
- package/cjs/watch.js +0 -14
- package/esm/sourceMap.d.ts +0 -21
- package/esm/sourceMap.js +0 -1
- package/esm/watch.d.ts +0 -2
- package/esm/watch.js +0 -11
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compatOptionsFromWebpack = compatOptionsFromWebpack;
|
|
4
|
+
function compatOptionsFromWebpack(webpackConfig) {
|
|
5
|
+
const { entry, mode, module, resolve, externals, output, target, devtool, optimization, plugins, stats, } = webpackConfig;
|
|
6
|
+
return {
|
|
7
|
+
config: {
|
|
8
|
+
entry: compatEntry(entry),
|
|
9
|
+
mode: compatMode(mode),
|
|
10
|
+
module: compatModule(module),
|
|
11
|
+
resolve: compatResolve(resolve),
|
|
12
|
+
externals: compatExternals(externals),
|
|
13
|
+
output: compatOutput(output),
|
|
14
|
+
target: compatTarget(target),
|
|
15
|
+
sourceMaps: compatSourceMaps(devtool),
|
|
16
|
+
optimization: compatOptimization(optimization),
|
|
17
|
+
define: compatFromWebpackPlugin(plugins, compatDefine),
|
|
18
|
+
stats: compatStats(stats),
|
|
19
|
+
},
|
|
20
|
+
buildId: webpackConfig.name,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function compatMode(webpackMode) {
|
|
24
|
+
return webpackMode
|
|
25
|
+
? webpackMode === "none"
|
|
26
|
+
? "production"
|
|
27
|
+
: webpackMode
|
|
28
|
+
: "production";
|
|
29
|
+
}
|
|
30
|
+
function compatEntry(webpackEntry) {
|
|
31
|
+
const entry = [];
|
|
32
|
+
switch (typeof webpackEntry) {
|
|
33
|
+
case "string":
|
|
34
|
+
entry.push({ import: webpackEntry });
|
|
35
|
+
break;
|
|
36
|
+
case "object":
|
|
37
|
+
if (Array.isArray(webpackEntry)) {
|
|
38
|
+
webpackEntry.forEach((e) => entry.push({
|
|
39
|
+
import: e,
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
Object.entries(webpackEntry).forEach(([k, v]) => {
|
|
44
|
+
var _a;
|
|
45
|
+
switch (typeof v) {
|
|
46
|
+
case "string":
|
|
47
|
+
entry.push({ name: k, import: v });
|
|
48
|
+
break;
|
|
49
|
+
case "object":
|
|
50
|
+
if (!Array.isArray(v)) {
|
|
51
|
+
switch (typeof v.import) {
|
|
52
|
+
case "string":
|
|
53
|
+
entry.push({
|
|
54
|
+
name: k,
|
|
55
|
+
import: v.import,
|
|
56
|
+
library: ((_a = v.library) === null || _a === void 0 ? void 0 : _a.type) === "umd"
|
|
57
|
+
? {
|
|
58
|
+
name: typeof v.library.name === "string"
|
|
59
|
+
? v.library.name
|
|
60
|
+
: undefined,
|
|
61
|
+
export: typeof v.library.export === "string"
|
|
62
|
+
? [v.library.export]
|
|
63
|
+
: v.library.export,
|
|
64
|
+
}
|
|
65
|
+
: undefined,
|
|
66
|
+
});
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw "multi entry items for one entry not supported yet";
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
throw "non string and non object entry path not supported yet";
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
case "function":
|
|
83
|
+
throw "functional entry not supported yet";
|
|
84
|
+
default:
|
|
85
|
+
throw "entry config not compatible now";
|
|
86
|
+
}
|
|
87
|
+
return entry;
|
|
88
|
+
}
|
|
89
|
+
function compatFromWebpackPlugin(webpackPlugins, picker) {
|
|
90
|
+
const plugin = webpackPlugins === null || webpackPlugins === void 0 ? void 0 : webpackPlugins.find((p) => p && typeof p === "object" && p.constructor.name === picker.pluginName);
|
|
91
|
+
return picker(plugin);
|
|
92
|
+
}
|
|
93
|
+
compatDefine.pluginName = "DefinePlugin";
|
|
94
|
+
function compatDefine(maybeWebpackPluginInstance) {
|
|
95
|
+
return maybeWebpackPluginInstance === null || maybeWebpackPluginInstance === void 0 ? void 0 : maybeWebpackPluginInstance.definitions;
|
|
96
|
+
}
|
|
97
|
+
function compatExternals(webpackExternals) {
|
|
98
|
+
if (!webpackExternals) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
let externals = {};
|
|
102
|
+
switch (typeof webpackExternals) {
|
|
103
|
+
case "string": {
|
|
104
|
+
// Single string external: "lodash" -> { "lodash": "lodash" }
|
|
105
|
+
externals[webpackExternals] = webpackExternals;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
case "object": {
|
|
109
|
+
if (Array.isArray(webpackExternals)) {
|
|
110
|
+
// Array of externals: ["lodash", "react"] -> { "lodash": "lodash", "react": "react" }
|
|
111
|
+
externals = webpackExternals.reduce((acc, external) => {
|
|
112
|
+
if (typeof external === "string") {
|
|
113
|
+
acc[external] = external;
|
|
114
|
+
}
|
|
115
|
+
else if (typeof external === "object" && external !== null) {
|
|
116
|
+
Object.assign(acc, compatExternals(external));
|
|
117
|
+
}
|
|
118
|
+
return acc;
|
|
119
|
+
}, {});
|
|
120
|
+
}
|
|
121
|
+
else if (webpackExternals instanceof RegExp) {
|
|
122
|
+
throw "regex external not supported yet";
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
if ("byLayer" in webpackExternals) {
|
|
126
|
+
throw "by layer external item not supported yet";
|
|
127
|
+
}
|
|
128
|
+
Object.entries(webpackExternals).forEach(([key, value]) => {
|
|
129
|
+
if (typeof value === "string") {
|
|
130
|
+
// Check if it's a script type with shorthand syntax: "global@https://example.com/script.js"
|
|
131
|
+
if (value.includes("@") &&
|
|
132
|
+
(value.startsWith("script ") || value.includes("://"))) {
|
|
133
|
+
const match = value.match(/^(?:script\s+)?(.+?)@(.+)$/);
|
|
134
|
+
if (match) {
|
|
135
|
+
const [, globalName, scriptUrl] = match;
|
|
136
|
+
// Use utoo-pack string format: "script globalName@url"
|
|
137
|
+
externals[key] = `script ${globalName}@${scriptUrl}`;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
externals[key] = value;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
// Simple string mapping: { "react": "React" }
|
|
145
|
+
externals[key] = value;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else if (Array.isArray(value)) {
|
|
149
|
+
// Array format handling
|
|
150
|
+
if (value.length >= 2) {
|
|
151
|
+
const [first, second] = value;
|
|
152
|
+
// Check if it's a script type array: ["https://example.com/script.js", "GlobalName"]
|
|
153
|
+
if (typeof first === "string" &&
|
|
154
|
+
first.includes("://") &&
|
|
155
|
+
typeof second === "string") {
|
|
156
|
+
// Use utoo-pack object format for script
|
|
157
|
+
externals[key] = {
|
|
158
|
+
root: second,
|
|
159
|
+
type: "script",
|
|
160
|
+
script: first,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
else if (typeof first === "string" &&
|
|
164
|
+
typeof second === "string") {
|
|
165
|
+
// Handle type prefix formats
|
|
166
|
+
if (first.startsWith("commonjs")) {
|
|
167
|
+
externals[key] = `commonjs ${second}`;
|
|
168
|
+
}
|
|
169
|
+
else if (first === "module") {
|
|
170
|
+
externals[key] = `esm ${second}`;
|
|
171
|
+
}
|
|
172
|
+
else if (first === "var" ||
|
|
173
|
+
first === "global" ||
|
|
174
|
+
first === "window") {
|
|
175
|
+
externals[key] = second;
|
|
176
|
+
}
|
|
177
|
+
else if (first === "script") {
|
|
178
|
+
// Script type without URL in array format - treat as regular script prefix
|
|
179
|
+
externals[key] = `script ${second}`;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
externals[key] = `${first} ${second}`;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
externals[key] = value[0] || key;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
externals[key] = value[0] || key;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else if (typeof value === "object" && value !== null) {
|
|
194
|
+
// Object format: handle complex configurations
|
|
195
|
+
if ("root" in value || "commonjs" in value || "amd" in value) {
|
|
196
|
+
// Standard webpack externals object format
|
|
197
|
+
if (value.commonjs) {
|
|
198
|
+
externals[key] = `commonjs ${value.commonjs}`;
|
|
199
|
+
}
|
|
200
|
+
else if (value.root) {
|
|
201
|
+
externals[key] = value.root;
|
|
202
|
+
}
|
|
203
|
+
else if (value.amd) {
|
|
204
|
+
externals[key] = value.amd;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
externals[key] = key;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
// Treat as utoo-pack specific configuration (might already be in correct format)
|
|
212
|
+
externals[key] = value;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
// Fallback to key name
|
|
217
|
+
externals[key] = key;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
case "function": {
|
|
224
|
+
throw "functional external not supported yet";
|
|
225
|
+
}
|
|
226
|
+
default:
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
return externals;
|
|
230
|
+
}
|
|
231
|
+
function compatModule(webpackModule) {
|
|
232
|
+
if (!Array.isArray(webpackModule === null || webpackModule === void 0 ? void 0 : webpackModule.rules)) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const moduleRules = {
|
|
236
|
+
rules: webpackModule.rules.reduce((acc, cur) => {
|
|
237
|
+
var _a, _b;
|
|
238
|
+
switch (typeof cur) {
|
|
239
|
+
case "object":
|
|
240
|
+
if (cur) {
|
|
241
|
+
let condition = (_b = (_a = cur.test) === null || _a === void 0 ? void 0 : _a.toString().match(/(\.\w+)/)) === null || _b === void 0 ? void 0 : _b[1];
|
|
242
|
+
if (condition) {
|
|
243
|
+
Object.assign(acc, {
|
|
244
|
+
["*" + condition]: {
|
|
245
|
+
loaders: typeof cur.use === "string"
|
|
246
|
+
? [cur.use]
|
|
247
|
+
: typeof (cur === null || cur === void 0 ? void 0 : cur.use) === "object"
|
|
248
|
+
? Array.isArray(cur.use)
|
|
249
|
+
? cur.use.map((use) => typeof use === "string"
|
|
250
|
+
? { loader: use, options: {} }
|
|
251
|
+
: {
|
|
252
|
+
loader: use.loader,
|
|
253
|
+
options: use.options || {},
|
|
254
|
+
})
|
|
255
|
+
: [
|
|
256
|
+
{
|
|
257
|
+
loader: cur.loader,
|
|
258
|
+
options: cur.options || {},
|
|
259
|
+
},
|
|
260
|
+
]
|
|
261
|
+
: [],
|
|
262
|
+
as: "*.js",
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
break;
|
|
268
|
+
default:
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
return acc;
|
|
272
|
+
}, {}),
|
|
273
|
+
};
|
|
274
|
+
return moduleRules;
|
|
275
|
+
}
|
|
276
|
+
function compatResolve(webpackResolve) {
|
|
277
|
+
if (!webpackResolve) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const { alias, extensions } = webpackResolve;
|
|
281
|
+
return {
|
|
282
|
+
alias: alias
|
|
283
|
+
? Array.isArray(alias)
|
|
284
|
+
? alias.reduce((acc, cur) => Object.assign(acc, { [cur.name]: cur.alias }), {})
|
|
285
|
+
: Object.entries(alias).reduce((acc, [k, v]) => {
|
|
286
|
+
if (typeof v === "string") {
|
|
287
|
+
Object.assign(acc, { [k]: v });
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
throw "non string alias value not supported yet";
|
|
291
|
+
}
|
|
292
|
+
return acc;
|
|
293
|
+
}, {})
|
|
294
|
+
: undefined,
|
|
295
|
+
extensions,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function compatOutput(webpackOutput) {
|
|
299
|
+
if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename) && typeof webpackOutput.filename !== "string") {
|
|
300
|
+
throw "non string output filename not supported yet";
|
|
301
|
+
}
|
|
302
|
+
if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename) &&
|
|
303
|
+
typeof webpackOutput.chunkFilename !== "string") {
|
|
304
|
+
throw "non string output chunkFilename not supported yet";
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
path: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.path,
|
|
308
|
+
filename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename,
|
|
309
|
+
chunkFilename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename,
|
|
310
|
+
clean: !!(webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.clean),
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function compatTarget(webpackTarget) {
|
|
314
|
+
return webpackTarget
|
|
315
|
+
? Array.isArray(webpackTarget)
|
|
316
|
+
? webpackTarget.join(" ")
|
|
317
|
+
: webpackTarget
|
|
318
|
+
: undefined;
|
|
319
|
+
}
|
|
320
|
+
function compatSourceMaps(webpackSourceMaps) {
|
|
321
|
+
return !!webpackSourceMaps;
|
|
322
|
+
}
|
|
323
|
+
function compatOptimization(webpackOptimization) {
|
|
324
|
+
if (!webpackOptimization) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const { moduleIds, minimize,
|
|
328
|
+
// TODO: concatenateModules to be supported, need to upgrade to next.js@15.4
|
|
329
|
+
} = webpackOptimization;
|
|
330
|
+
return {
|
|
331
|
+
moduleIds: moduleIds === "named"
|
|
332
|
+
? "named"
|
|
333
|
+
: moduleIds === "deterministic"
|
|
334
|
+
? "deterministic"
|
|
335
|
+
: undefined,
|
|
336
|
+
minify: minimize,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
function compatStats(webpackStats) {
|
|
340
|
+
return !!webpackStats;
|
|
341
|
+
}
|
package/esm/binding.d.ts
CHANGED
|
@@ -63,7 +63,7 @@ export interface NapiProjectOptions {
|
|
|
63
63
|
* A map of environment variables which should get injected at compile
|
|
64
64
|
* time.
|
|
65
65
|
*/
|
|
66
|
-
|
|
66
|
+
defineEnv: NapiDefineEnv
|
|
67
67
|
/** The mode in which Next.js is running. */
|
|
68
68
|
dev: boolean
|
|
69
69
|
/** The build id. */
|
|
@@ -88,7 +88,7 @@ export interface NapiPartialProjectOptions {
|
|
|
88
88
|
* A map of environment variables which should get injected at compile
|
|
89
89
|
* time.
|
|
90
90
|
*/
|
|
91
|
-
|
|
91
|
+
defineEnv?: NapiDefineEnv
|
|
92
92
|
/** The mode in which Next.js is running. */
|
|
93
93
|
dev?: boolean
|
|
94
94
|
/** The build id. */
|
|
@@ -136,7 +136,7 @@ export interface NapiEntrypoints {
|
|
|
136
136
|
}
|
|
137
137
|
export declare function projectWriteAllEntrypointsToDisk(project: { __napiType: "Project" }): Promise<TurbopackResult>
|
|
138
138
|
export declare function projectEntrypointsSubscribe(project: { __napiType: "Project" }, func: (...args: any[]) => any): { __napiType: "RootTask" }
|
|
139
|
-
export declare function projectHmrEvents(project: { __napiType: "Project" }, identifier:
|
|
139
|
+
export declare function projectHmrEvents(project: { __napiType: "Project" }, identifier: RcStr, func: (...args: any[]) => any): { __napiType: "RootTask" }
|
|
140
140
|
export interface HmrIdentifiers {
|
|
141
141
|
identifiers: Array<string>
|
|
142
142
|
}
|
|
@@ -166,16 +166,18 @@ export declare function projectUpdateInfoSubscribe(project: { __napiType: "Proje
|
|
|
166
166
|
export interface StackFrame {
|
|
167
167
|
isServer: boolean
|
|
168
168
|
isInternal?: boolean
|
|
169
|
-
originalFile?:
|
|
170
|
-
file:
|
|
169
|
+
originalFile?: RcStr
|
|
170
|
+
file: RcStr
|
|
171
|
+
/** 1-indexed, unlike source map tokens */
|
|
171
172
|
line?: number
|
|
173
|
+
/** 1-indexed, unlike source map tokens */
|
|
172
174
|
column?: number
|
|
173
|
-
methodName?:
|
|
175
|
+
methodName?: RcStr
|
|
174
176
|
}
|
|
175
177
|
export declare function projectTraceSource(project: { __napiType: "Project" }, frame: StackFrame, currentDirectoryFileUrl: string): Promise<StackFrame | null>
|
|
176
178
|
export declare function projectGetSourceForAsset(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
|
|
177
|
-
export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath:
|
|
178
|
-
export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath:
|
|
179
|
+
export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath: RcStr): Promise<string | null>
|
|
180
|
+
export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath: RcStr): string | null
|
|
179
181
|
export declare function rootTaskDispose(rootTask: { __napiType: "RootTask" }): void
|
|
180
182
|
export interface NapiIssue {
|
|
181
183
|
severity: string
|
|
@@ -186,7 +188,7 @@ export interface NapiIssue {
|
|
|
186
188
|
detail?: any
|
|
187
189
|
source?: NapiIssueSource
|
|
188
190
|
documentationLink: string
|
|
189
|
-
|
|
191
|
+
importTraces: any
|
|
190
192
|
}
|
|
191
193
|
export interface NapiIssueSource {
|
|
192
194
|
source: NapiSource
|
package/esm/build.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { BundleOptions } from "./types";
|
|
2
|
+
import { WebpackConfig } from "./webpackCompat";
|
|
3
|
+
export declare function build(bundleOptions: BundleOptions, projectPath?: string, rootPath?: string): Promise<void>;
|
|
4
|
+
export declare function build(webpackConfig: WebpackConfig, projectPath?: string, rootPath?: string): Promise<void>;
|
package/esm/build.js
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
import { nanoid } from "nanoid";
|
|
2
2
|
import { projectFactory } from "./project";
|
|
3
3
|
import { blockStdout, createDefineEnv, formatIssue, isRelevantWarning, } from "./util";
|
|
4
|
+
import { compatOptionsFromWebpack } from "./webpackCompat";
|
|
4
5
|
import { xcodeProfilingReady } from "./xcodeProfile";
|
|
5
|
-
export
|
|
6
|
-
|
|
6
|
+
export function build(options, projectPath, rootPath) {
|
|
7
|
+
const bundleOptions = options.compatMode
|
|
8
|
+
? compatOptionsFromWebpack(options)
|
|
9
|
+
: options;
|
|
10
|
+
return buildInternal(bundleOptions, projectPath, rootPath);
|
|
11
|
+
}
|
|
12
|
+
async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
13
|
+
var _a, _b, _c;
|
|
7
14
|
blockStdout();
|
|
8
15
|
if (process.env.XCODE_PROFILE) {
|
|
9
16
|
await xcodeProfilingReady();
|
|
10
17
|
}
|
|
11
18
|
const createProject = projectFactory();
|
|
12
19
|
const project = await createProject({
|
|
13
|
-
processEnv: (_a =
|
|
14
|
-
|
|
15
|
-
config:
|
|
16
|
-
dev: (_b =
|
|
17
|
-
optionDefineEnv:
|
|
20
|
+
processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
|
|
21
|
+
defineEnv: createDefineEnv({
|
|
22
|
+
config: bundleOptions.config,
|
|
23
|
+
dev: (_b = bundleOptions.dev) !== null && _b !== void 0 ? _b : false,
|
|
24
|
+
optionDefineEnv: bundleOptions.defineEnv,
|
|
18
25
|
}),
|
|
19
|
-
watch:
|
|
26
|
+
watch: {
|
|
20
27
|
enable: false,
|
|
21
28
|
},
|
|
22
|
-
dev: (
|
|
23
|
-
buildId: nanoid(),
|
|
24
|
-
config:
|
|
29
|
+
dev: (_c = bundleOptions.dev) !== null && _c !== void 0 ? _c : false,
|
|
30
|
+
buildId: bundleOptions.buildId || nanoid(),
|
|
31
|
+
config: bundleOptions.config,
|
|
25
32
|
projectPath: projectPath || process.cwd(),
|
|
26
33
|
rootPath: rootPath || projectPath || process.cwd(),
|
|
27
34
|
}, {
|
package/esm/dev.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from "http";
|
|
2
|
+
import send from "send";
|
|
3
|
+
import { Duplex, Writable } from "stream";
|
|
4
|
+
import { BundleOptions } from "./types";
|
|
5
|
+
import { WebpackConfig } from "./webpackCompat";
|
|
6
|
+
export declare function serve(bundleOptions: BundleOptions, projectPath?: string, rootPath?: string, serverOptions?: StartServerOptions): Promise<void>;
|
|
7
|
+
export declare function serve(webpackConfig: WebpackConfig, projectPath?: string, rootPath?: string, serverOptions?: StartServerOptions): Promise<void>;
|
|
8
|
+
export interface SelfSignedCertificate {
|
|
9
|
+
key: string;
|
|
10
|
+
cert: string;
|
|
11
|
+
rootCA?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface StartServerOptions {
|
|
14
|
+
port: number;
|
|
15
|
+
https?: boolean;
|
|
16
|
+
hostname?: string;
|
|
17
|
+
selfSignedCertificate?: SelfSignedCertificate;
|
|
18
|
+
}
|
|
19
|
+
export type RequestHandler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
20
|
+
export type UpgradeHandler = (req: IncomingMessage, socket: Duplex, head: Buffer) => Promise<void>;
|
|
21
|
+
export type ServerInitResult = {
|
|
22
|
+
requestHandler: RequestHandler;
|
|
23
|
+
upgradeHandler: UpgradeHandler;
|
|
24
|
+
closeUpgraded: () => void;
|
|
25
|
+
};
|
|
26
|
+
export declare function startServer(serverOptions: StartServerOptions, bundleOptions: BundleOptions, projectPath: string, rootPath?: string): Promise<void>;
|
|
27
|
+
export declare function initialize(bundleOptions: BundleOptions, projectPath: string, rootPath?: string): Promise<ServerInitResult>;
|
|
28
|
+
export declare function pipeToNodeResponse(readable: ReadableStream<Uint8Array>, res: ServerResponse, waitUntilForEnd?: Promise<unknown>): Promise<void>;
|
|
29
|
+
export declare function createAbortController(response: Writable): AbortController;
|
|
30
|
+
export declare function isAbortError(e: any): e is Error & {
|
|
31
|
+
name: "AbortError";
|
|
32
|
+
};
|
|
33
|
+
export declare const ResponseAbortedName = "ResponseAborted";
|
|
34
|
+
export declare class ResponseAborted extends Error {
|
|
35
|
+
readonly name = "ResponseAborted";
|
|
36
|
+
}
|
|
37
|
+
export declare class DetachedPromise<T = any> {
|
|
38
|
+
readonly resolve: (value: T | PromiseLike<T>) => void;
|
|
39
|
+
readonly reject: (reason: any) => void;
|
|
40
|
+
readonly promise: Promise<T>;
|
|
41
|
+
constructor();
|
|
42
|
+
}
|
|
43
|
+
export declare function serveStatic(req: IncomingMessage, res: ServerResponse, path: string, opts?: Parameters<typeof send>[2]): Promise<void>;
|
|
44
|
+
export declare function formatHostname(hostname: string): string;
|