@utoo/pack-shared 0.0.6 → 0.0.8
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/README.md +19 -0
- package/cjs/config.d.ts +227 -0
- package/cjs/config.js +2 -0
- package/cjs/index.d.ts +3 -0
- package/cjs/index.js +17 -0
- package/cjs/utils.d.ts +20 -0
- package/cjs/utils.js +134 -0
- package/cjs/webpackCompat.d.ts +6 -0
- package/cjs/webpackCompat.js +413 -0
- package/esm/config.d.ts +227 -0
- package/esm/config.js +1 -0
- package/esm/index.d.ts +3 -0
- package/esm/index.js +6 -10
- package/esm/issue.js +8 -12
- package/esm/magicIdentifier.js +2 -6
- package/esm/styledString.js +8 -11
- package/esm/utils.d.ts +20 -0
- package/esm/utils.js +125 -0
- package/esm/webpackCompat.d.ts +6 -0
- package/esm/webpackCompat.js +410 -0
- package/package.json +12 -9
|
@@ -0,0 +1,413 @@
|
|
|
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
|
+
provider: compatFromWebpackPlugin(plugins, compatProvider),
|
|
19
|
+
stats: compatStats(stats),
|
|
20
|
+
html: compatFromWebpackPlugins(plugins, compatHtml),
|
|
21
|
+
},
|
|
22
|
+
buildId: webpackConfig.name,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function compatMode(webpackMode) {
|
|
26
|
+
return webpackMode
|
|
27
|
+
? webpackMode === "none"
|
|
28
|
+
? "production"
|
|
29
|
+
: webpackMode
|
|
30
|
+
: "production";
|
|
31
|
+
}
|
|
32
|
+
function compatEntry(webpackEntry) {
|
|
33
|
+
const entry = [];
|
|
34
|
+
switch (typeof webpackEntry) {
|
|
35
|
+
case "string":
|
|
36
|
+
entry.push({ import: webpackEntry });
|
|
37
|
+
break;
|
|
38
|
+
case "object":
|
|
39
|
+
if (Array.isArray(webpackEntry)) {
|
|
40
|
+
webpackEntry.forEach((e) => entry.push({
|
|
41
|
+
import: e,
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
Object.entries(webpackEntry).forEach(([k, v]) => {
|
|
46
|
+
var _a;
|
|
47
|
+
switch (typeof v) {
|
|
48
|
+
case "string":
|
|
49
|
+
entry.push({ name: k, import: v });
|
|
50
|
+
break;
|
|
51
|
+
case "object":
|
|
52
|
+
if (!Array.isArray(v)) {
|
|
53
|
+
switch (typeof v.import) {
|
|
54
|
+
case "string":
|
|
55
|
+
entry.push({
|
|
56
|
+
name: k,
|
|
57
|
+
import: v.import,
|
|
58
|
+
library: ((_a = v.library) === null || _a === void 0 ? void 0 : _a.type) === "umd"
|
|
59
|
+
? {
|
|
60
|
+
name: typeof v.library.name === "string"
|
|
61
|
+
? v.library.name
|
|
62
|
+
: undefined,
|
|
63
|
+
export: typeof v.library.export === "string"
|
|
64
|
+
? [v.library.export]
|
|
65
|
+
: v.library.export,
|
|
66
|
+
}
|
|
67
|
+
: undefined,
|
|
68
|
+
});
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
if (v.length === 0) {
|
|
76
|
+
throw "entry value items is empty";
|
|
77
|
+
}
|
|
78
|
+
else if (v.length === 1) {
|
|
79
|
+
entry.push({ name: k, import: v[0] });
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
throw "multi entry items for one entry not supported yet";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
default:
|
|
87
|
+
throw "non string and non object entry path not supported yet";
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
case "function":
|
|
93
|
+
throw "functional entry not supported yet";
|
|
94
|
+
default:
|
|
95
|
+
throw "entry config not compatible now";
|
|
96
|
+
}
|
|
97
|
+
return entry;
|
|
98
|
+
}
|
|
99
|
+
function compatFromWebpackPlugin(webpackPlugins, picker) {
|
|
100
|
+
const plugin = webpackPlugins === null || webpackPlugins === void 0 ? void 0 : webpackPlugins.find((p) => p && typeof p === "object" && p.constructor.name === picker.pluginName);
|
|
101
|
+
return picker(plugin);
|
|
102
|
+
}
|
|
103
|
+
function compatFromWebpackPlugins(webpackPlugins, picker) {
|
|
104
|
+
const plugins = webpackPlugins === null || webpackPlugins === void 0 ? void 0 : webpackPlugins.filter((p) => p && typeof p === "object" && p.constructor.name === picker.pluginName);
|
|
105
|
+
if (!plugins || plugins.length === 0) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
const results = plugins.map(picker).filter((r) => r !== undefined);
|
|
109
|
+
if (results.length === 0)
|
|
110
|
+
return undefined;
|
|
111
|
+
return results.length === 1 ? results[0] : results;
|
|
112
|
+
}
|
|
113
|
+
compatHtml.pluginName = "HtmlWebpackPlugin";
|
|
114
|
+
function compatHtml(maybeWebpackPluginInstance) {
|
|
115
|
+
if (!maybeWebpackPluginInstance) {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
return (maybeWebpackPluginInstance.userOptions ||
|
|
119
|
+
maybeWebpackPluginInstance.options);
|
|
120
|
+
}
|
|
121
|
+
compatDefine.pluginName = "DefinePlugin";
|
|
122
|
+
function compatDefine(maybeWebpackPluginInstance) {
|
|
123
|
+
const definitions = maybeWebpackPluginInstance === null || maybeWebpackPluginInstance === void 0 ? void 0 : maybeWebpackPluginInstance.definitions;
|
|
124
|
+
if (!definitions || typeof definitions !== "object") {
|
|
125
|
+
return definitions;
|
|
126
|
+
}
|
|
127
|
+
const processedDefinitions = {};
|
|
128
|
+
for (const [key, value] of Object.entries(definitions)) {
|
|
129
|
+
if (typeof value === "object" && value !== null) {
|
|
130
|
+
processedDefinitions[key] = JSON.stringify(value);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
processedDefinitions[key] = value;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return processedDefinitions;
|
|
137
|
+
}
|
|
138
|
+
compatProvider.pluginName = "ProvidePlugin";
|
|
139
|
+
function compatProvider(maybeWebpackPluginInstance) {
|
|
140
|
+
const definitions = maybeWebpackPluginInstance === null || maybeWebpackPluginInstance === void 0 ? void 0 : maybeWebpackPluginInstance.definitions;
|
|
141
|
+
if (!definitions || typeof definitions !== "object") {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
const provider = {};
|
|
145
|
+
for (const [key, value] of Object.entries(definitions)) {
|
|
146
|
+
if (typeof value === "string") {
|
|
147
|
+
// Simple module import: { $: 'jquery' }
|
|
148
|
+
provider[key] = value;
|
|
149
|
+
}
|
|
150
|
+
else if (Array.isArray(value)) {
|
|
151
|
+
if (value.length === 1) {
|
|
152
|
+
// e.g. { process: ['process/browser'] } for default import
|
|
153
|
+
provider[key] = value[0];
|
|
154
|
+
}
|
|
155
|
+
else if (value.length >= 2) {
|
|
156
|
+
// Named export import: { Buffer: ['buffer', 'Buffer'] }
|
|
157
|
+
provider[key] = [value[0], value[1]];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return Object.keys(provider).length > 0 ? provider : undefined;
|
|
162
|
+
}
|
|
163
|
+
function compatExternals(webpackExternals) {
|
|
164
|
+
if (!webpackExternals) {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
let externals = {};
|
|
168
|
+
switch (typeof webpackExternals) {
|
|
169
|
+
case "string": {
|
|
170
|
+
// Single string external: "lodash" -> { "lodash": "lodash" }
|
|
171
|
+
externals[webpackExternals] = webpackExternals;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case "object": {
|
|
175
|
+
if (Array.isArray(webpackExternals)) {
|
|
176
|
+
// Array of externals: ["lodash", "react"] -> { "lodash": "lodash", "react": "react" }
|
|
177
|
+
externals = webpackExternals.reduce((acc, external) => {
|
|
178
|
+
if (typeof external === "string") {
|
|
179
|
+
acc[external] = external;
|
|
180
|
+
}
|
|
181
|
+
else if (typeof external === "object" && external !== null) {
|
|
182
|
+
Object.assign(acc, compatExternals(external));
|
|
183
|
+
}
|
|
184
|
+
return acc;
|
|
185
|
+
}, {});
|
|
186
|
+
}
|
|
187
|
+
else if (webpackExternals instanceof RegExp) {
|
|
188
|
+
throw "regex external not supported yet";
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
if ("byLayer" in webpackExternals) {
|
|
192
|
+
throw "by layer external item not supported yet";
|
|
193
|
+
}
|
|
194
|
+
Object.entries(webpackExternals).forEach(([key, value]) => {
|
|
195
|
+
if (typeof value === "string") {
|
|
196
|
+
// Check if it's a script type with shorthand syntax: "global@https://example.com/script.js"
|
|
197
|
+
if (value.includes("@") &&
|
|
198
|
+
(value.startsWith("script ") || value.includes("://"))) {
|
|
199
|
+
const match = value.match(/^(?:script\s+)?(.+?)@(.+)$/);
|
|
200
|
+
if (match) {
|
|
201
|
+
const [, globalName, scriptUrl] = match;
|
|
202
|
+
// Use utoopack string format: "script globalName@url"
|
|
203
|
+
externals[key] = `script ${globalName}@${scriptUrl}`;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
externals[key] = value;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
// Simple string mapping: { "react": "React" }
|
|
211
|
+
externals[key] = value;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
else if (Array.isArray(value)) {
|
|
215
|
+
// Array format handling
|
|
216
|
+
if (value.length >= 2) {
|
|
217
|
+
const [first, second] = value;
|
|
218
|
+
// Check if it's a script type array: ["https://example.com/script.js", "GlobalName"]
|
|
219
|
+
if (typeof first === "string" &&
|
|
220
|
+
first.includes("://") &&
|
|
221
|
+
typeof second === "string") {
|
|
222
|
+
// Use utoopack object format for script
|
|
223
|
+
externals[key] = {
|
|
224
|
+
root: second,
|
|
225
|
+
type: "script",
|
|
226
|
+
script: first,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
else if (typeof first === "string" &&
|
|
230
|
+
typeof second === "string") {
|
|
231
|
+
// Handle type prefix formats
|
|
232
|
+
if (first.startsWith("commonjs")) {
|
|
233
|
+
externals[key] = `commonjs ${second}`;
|
|
234
|
+
}
|
|
235
|
+
else if (first === "module") {
|
|
236
|
+
externals[key] = `esm ${second}`;
|
|
237
|
+
}
|
|
238
|
+
else if (first === "var" ||
|
|
239
|
+
first === "global" ||
|
|
240
|
+
first === "window") {
|
|
241
|
+
externals[key] = second;
|
|
242
|
+
}
|
|
243
|
+
else if (first === "script") {
|
|
244
|
+
// Script type without URL in array format - treat as regular script prefix
|
|
245
|
+
externals[key] = `script ${second}`;
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
externals[key] = `${first} ${second}`;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
externals[key] = value[0] || key;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
externals[key] = value[0] || key;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
else if (typeof value === "object" && value !== null) {
|
|
260
|
+
// Object format: handle complex configurations
|
|
261
|
+
if ("root" in value || "commonjs" in value || "amd" in value) {
|
|
262
|
+
// Standard webpack externals object format
|
|
263
|
+
if (value.commonjs) {
|
|
264
|
+
externals[key] = `commonjs ${value.commonjs}`;
|
|
265
|
+
}
|
|
266
|
+
else if (value.root) {
|
|
267
|
+
externals[key] = value.root;
|
|
268
|
+
}
|
|
269
|
+
else if (value.amd) {
|
|
270
|
+
externals[key] = value.amd;
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
externals[key] = key;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
// Treat as utoopack specific configuration (might already be in correct format)
|
|
278
|
+
externals[key] = value;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
// Fallback to key name
|
|
283
|
+
externals[key] = key;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
case "function": {
|
|
290
|
+
throw "functional external not supported yet";
|
|
291
|
+
}
|
|
292
|
+
default:
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
return externals;
|
|
296
|
+
}
|
|
297
|
+
function compatModule(webpackModule) {
|
|
298
|
+
if (!Array.isArray(webpackModule === null || webpackModule === void 0 ? void 0 : webpackModule.rules)) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const moduleRules = {
|
|
302
|
+
rules: webpackModule.rules.reduce((acc, cur) => {
|
|
303
|
+
var _a, _b;
|
|
304
|
+
switch (typeof cur) {
|
|
305
|
+
case "object":
|
|
306
|
+
if (cur) {
|
|
307
|
+
let condition = (_b = (_a = cur.test) === null || _a === void 0 ? void 0 : _a.toString().match(/(\.\w+)/)) === null || _b === void 0 ? void 0 : _b[1];
|
|
308
|
+
if (condition) {
|
|
309
|
+
Object.assign(acc, {
|
|
310
|
+
["*" + condition]: {
|
|
311
|
+
loaders: typeof cur.use === "string"
|
|
312
|
+
? [cur.use]
|
|
313
|
+
: typeof (cur === null || cur === void 0 ? void 0 : cur.use) === "object"
|
|
314
|
+
? Array.isArray(cur.use)
|
|
315
|
+
? cur.use.map((use) => typeof use === "string"
|
|
316
|
+
? { loader: use, options: {} }
|
|
317
|
+
: {
|
|
318
|
+
loader: use.loader,
|
|
319
|
+
options: use.options || {},
|
|
320
|
+
})
|
|
321
|
+
: [
|
|
322
|
+
{
|
|
323
|
+
loader: cur.loader,
|
|
324
|
+
options: cur.options || {},
|
|
325
|
+
},
|
|
326
|
+
]
|
|
327
|
+
: [],
|
|
328
|
+
as: "*.js",
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
break;
|
|
334
|
+
default:
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
return acc;
|
|
338
|
+
}, {}),
|
|
339
|
+
};
|
|
340
|
+
return moduleRules;
|
|
341
|
+
}
|
|
342
|
+
function compatResolve(webpackResolve) {
|
|
343
|
+
if (!webpackResolve) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const { alias, extensions } = webpackResolve;
|
|
347
|
+
return {
|
|
348
|
+
alias: alias
|
|
349
|
+
? Array.isArray(alias)
|
|
350
|
+
? alias.reduce((acc, cur) => Object.assign(acc, { [cur.name]: cur.alias }), {})
|
|
351
|
+
: Object.entries(alias).reduce((acc, [k, v]) => {
|
|
352
|
+
if (typeof v === "string") {
|
|
353
|
+
// Handle alias keys ending with $ by removing the $
|
|
354
|
+
const aliasKey = k.endsWith("$") ? k.slice(0, -1) : k;
|
|
355
|
+
Object.assign(acc, { [aliasKey]: v });
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
throw "non string alias value not supported yet";
|
|
359
|
+
}
|
|
360
|
+
return acc;
|
|
361
|
+
}, {})
|
|
362
|
+
: undefined,
|
|
363
|
+
extensions,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function compatOutput(webpackOutput) {
|
|
367
|
+
if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename) && typeof webpackOutput.filename !== "string") {
|
|
368
|
+
throw "non string output filename not supported yet";
|
|
369
|
+
}
|
|
370
|
+
if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename) &&
|
|
371
|
+
typeof webpackOutput.chunkFilename !== "string") {
|
|
372
|
+
throw "non string output chunkFilename not supported yet";
|
|
373
|
+
}
|
|
374
|
+
if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.publicPath) &&
|
|
375
|
+
typeof webpackOutput.publicPath !== "string") {
|
|
376
|
+
throw "non string output publicPath not supported yet";
|
|
377
|
+
}
|
|
378
|
+
return {
|
|
379
|
+
path: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.path,
|
|
380
|
+
filename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename,
|
|
381
|
+
chunkFilename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename,
|
|
382
|
+
clean: !!(webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.clean),
|
|
383
|
+
publicPath: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.publicPath,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function compatTarget(webpackTarget) {
|
|
387
|
+
return webpackTarget
|
|
388
|
+
? Array.isArray(webpackTarget)
|
|
389
|
+
? webpackTarget.join(" ")
|
|
390
|
+
: webpackTarget
|
|
391
|
+
: undefined;
|
|
392
|
+
}
|
|
393
|
+
function compatSourceMaps(webpackSourceMaps) {
|
|
394
|
+
return !!webpackSourceMaps;
|
|
395
|
+
}
|
|
396
|
+
function compatOptimization(webpackOptimization) {
|
|
397
|
+
if (!webpackOptimization) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const { moduleIds, minimize, concatenateModules } = webpackOptimization;
|
|
401
|
+
return {
|
|
402
|
+
moduleIds: moduleIds === "named"
|
|
403
|
+
? "named"
|
|
404
|
+
: moduleIds === "deterministic"
|
|
405
|
+
? "deterministic"
|
|
406
|
+
: undefined,
|
|
407
|
+
minify: minimize,
|
|
408
|
+
concatenateModules,
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
function compatStats(webpackStats) {
|
|
412
|
+
return !!webpackStats;
|
|
413
|
+
}
|
package/esm/config.d.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
export interface EntryOptions {
|
|
2
|
+
name?: string;
|
|
3
|
+
import: string;
|
|
4
|
+
library?: LibraryOptions;
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for generating an HTML file for this entry point.
|
|
7
|
+
* When specified, an HTML file will be generated with the entry's assets injected.
|
|
8
|
+
*
|
|
9
|
+
* Similar to https://github.com/jantimon/html-webpack-plugin#options
|
|
10
|
+
*/
|
|
11
|
+
html?: HtmlConfig;
|
|
12
|
+
}
|
|
13
|
+
export interface LibraryOptions {
|
|
14
|
+
name?: string;
|
|
15
|
+
export?: Array<string>;
|
|
16
|
+
}
|
|
17
|
+
export interface DefineEnv {
|
|
18
|
+
client: RustifiedEnv;
|
|
19
|
+
edge: RustifiedEnv;
|
|
20
|
+
nodejs: RustifiedEnv;
|
|
21
|
+
}
|
|
22
|
+
export type RustifiedEnv = {
|
|
23
|
+
name: string;
|
|
24
|
+
value: string;
|
|
25
|
+
}[];
|
|
26
|
+
export interface ExperimentalConfig {
|
|
27
|
+
}
|
|
28
|
+
export type TurbopackRuleConfigItem = TurbopackRuleConfigItemOptions | {
|
|
29
|
+
[condition: string]: TurbopackRuleConfigItem;
|
|
30
|
+
} | false;
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use `TurbopackRuleConfigItem` instead.
|
|
33
|
+
*/
|
|
34
|
+
export type TurbopackLoaderItem = string | {
|
|
35
|
+
loader: string;
|
|
36
|
+
options: Record<string, JSONValue>;
|
|
37
|
+
};
|
|
38
|
+
export type TurbopackRuleConfigItemOrShortcut = TurbopackLoaderItem[] | TurbopackRuleConfigItem;
|
|
39
|
+
export type TurbopackRuleConfigItemOptions = {
|
|
40
|
+
loaders: TurbopackLoaderItem[];
|
|
41
|
+
as?: string;
|
|
42
|
+
};
|
|
43
|
+
export type TurbopackRuleCondition = {
|
|
44
|
+
path: string | RegExp;
|
|
45
|
+
};
|
|
46
|
+
export interface ModuleOptions {
|
|
47
|
+
rules?: Record<string, TurbopackRuleConfigItem>;
|
|
48
|
+
}
|
|
49
|
+
export interface ResolveOptions {
|
|
50
|
+
alias?: Record<string, string | string[] | Record<string, string | string[]>>;
|
|
51
|
+
extensions?: string[];
|
|
52
|
+
}
|
|
53
|
+
export type ExternalType = "script" | "commonjs" | "esm" | "global";
|
|
54
|
+
export interface ExternalAdvanced {
|
|
55
|
+
root: string;
|
|
56
|
+
type?: ExternalType;
|
|
57
|
+
script?: string;
|
|
58
|
+
}
|
|
59
|
+
export type ExternalConfig = string | ExternalAdvanced;
|
|
60
|
+
/**
|
|
61
|
+
* Provider configuration for automatic module imports.
|
|
62
|
+
* Similar to webpack's ProvidePlugin.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* provider: {
|
|
67
|
+
* // Provides `$` as `import $ from 'jquery'`
|
|
68
|
+
* $: 'jquery',
|
|
69
|
+
* // Provides `Buffer` as `import { Buffer } from 'buffer'`
|
|
70
|
+
* Buffer: ['buffer', 'Buffer'],
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export type ProviderConfig = Record<string, string | [string, string]>;
|
|
75
|
+
export interface ConfigComplete {
|
|
76
|
+
entry: EntryOptions[];
|
|
77
|
+
mode?: "production" | "development";
|
|
78
|
+
module?: ModuleOptions;
|
|
79
|
+
resolve?: ResolveOptions;
|
|
80
|
+
externals?: Record<string, ExternalConfig>;
|
|
81
|
+
output?: {
|
|
82
|
+
path?: string;
|
|
83
|
+
type?: "standalone" | "export";
|
|
84
|
+
filename?: string;
|
|
85
|
+
chunkFilename?: string;
|
|
86
|
+
clean?: boolean;
|
|
87
|
+
copy?: Array<{
|
|
88
|
+
from: string;
|
|
89
|
+
to?: string;
|
|
90
|
+
} | string>;
|
|
91
|
+
publicPath?: string;
|
|
92
|
+
};
|
|
93
|
+
target?: string;
|
|
94
|
+
sourceMaps?: boolean;
|
|
95
|
+
define?: Record<string, string>;
|
|
96
|
+
provider?: ProviderConfig;
|
|
97
|
+
optimization?: {
|
|
98
|
+
moduleIds?: "named" | "deterministic";
|
|
99
|
+
minify?: boolean;
|
|
100
|
+
treeShaking?: boolean;
|
|
101
|
+
splitChunks?: Record<"js" | "css", {
|
|
102
|
+
minChunkSize?: number;
|
|
103
|
+
maxChunkCountPerGroup?: number;
|
|
104
|
+
maxMergeChunkSize?: number;
|
|
105
|
+
}>;
|
|
106
|
+
modularizeImports?: Record<string, {
|
|
107
|
+
transform: string | Record<string, string>;
|
|
108
|
+
preventFullImport?: boolean;
|
|
109
|
+
skipDefaultConversion?: boolean;
|
|
110
|
+
handleDefaultImport?: boolean;
|
|
111
|
+
handleNamespaceImport?: boolean;
|
|
112
|
+
style?: string;
|
|
113
|
+
}>;
|
|
114
|
+
packageImports?: string[];
|
|
115
|
+
transpilePackages?: string[];
|
|
116
|
+
removeConsole?: boolean | {
|
|
117
|
+
exclude?: string[];
|
|
118
|
+
};
|
|
119
|
+
concatenateModules?: boolean;
|
|
120
|
+
removeUnusedExports?: boolean;
|
|
121
|
+
nestedAsyncChunking?: boolean;
|
|
122
|
+
wasmAsAsset?: boolean;
|
|
123
|
+
};
|
|
124
|
+
styles?: {
|
|
125
|
+
less?: {
|
|
126
|
+
implementation?: string;
|
|
127
|
+
[key: string]: any;
|
|
128
|
+
};
|
|
129
|
+
sass?: {
|
|
130
|
+
implementation?: string;
|
|
131
|
+
[key: string]: any;
|
|
132
|
+
};
|
|
133
|
+
inlineCss?: {
|
|
134
|
+
insert?: string;
|
|
135
|
+
injectType?: string;
|
|
136
|
+
};
|
|
137
|
+
styledJsx?: boolean | {
|
|
138
|
+
useLightningcss?: boolean;
|
|
139
|
+
};
|
|
140
|
+
styledComponents?: boolean | StyledComponentsConfig;
|
|
141
|
+
emotion?: boolean | EmotionConfig;
|
|
142
|
+
};
|
|
143
|
+
images?: {
|
|
144
|
+
inlineLimit?: number;
|
|
145
|
+
};
|
|
146
|
+
stats?: boolean;
|
|
147
|
+
persistentCaching?: boolean;
|
|
148
|
+
nodePolyfill?: boolean;
|
|
149
|
+
devServer?: {
|
|
150
|
+
hot: boolean;
|
|
151
|
+
};
|
|
152
|
+
cacheHandler?: string;
|
|
153
|
+
experimental?: ExperimentalConfig;
|
|
154
|
+
}
|
|
155
|
+
export interface HtmlConfig {
|
|
156
|
+
template?: string;
|
|
157
|
+
templateContent?: string;
|
|
158
|
+
filename?: string;
|
|
159
|
+
title?: string;
|
|
160
|
+
inject?: boolean | "body" | "head";
|
|
161
|
+
scriptLoading?: "blocking" | "defer" | "module";
|
|
162
|
+
meta?: Record<string, string | {
|
|
163
|
+
[key: string]: string;
|
|
164
|
+
}>;
|
|
165
|
+
}
|
|
166
|
+
export interface StyledComponentsConfig {
|
|
167
|
+
/**
|
|
168
|
+
* Enabled by default in development, disabled in production to reduce file size,
|
|
169
|
+
* setting this will override the default for all environments.
|
|
170
|
+
*/
|
|
171
|
+
displayName?: boolean;
|
|
172
|
+
topLevelImportPaths?: string[];
|
|
173
|
+
ssr?: boolean;
|
|
174
|
+
fileName?: boolean;
|
|
175
|
+
meaninglessFileNames?: string[];
|
|
176
|
+
minify?: boolean;
|
|
177
|
+
transpileTemplateLiterals?: boolean;
|
|
178
|
+
namespace?: string;
|
|
179
|
+
pure?: boolean;
|
|
180
|
+
cssProp?: boolean;
|
|
181
|
+
}
|
|
182
|
+
export interface EmotionConfig {
|
|
183
|
+
sourceMap?: boolean;
|
|
184
|
+
autoLabel?: "dev-only" | "always" | "never";
|
|
185
|
+
labelFormat?: string;
|
|
186
|
+
importMap?: {
|
|
187
|
+
[importName: string]: {
|
|
188
|
+
[exportName: string]: {
|
|
189
|
+
canonicalImport?: [string, string];
|
|
190
|
+
styledBaseImport?: [string, string];
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
export type JSONValue = string | number | boolean | JSONValue[] | {
|
|
196
|
+
[k: string]: JSONValue;
|
|
197
|
+
};
|
|
198
|
+
export interface BundleOptions {
|
|
199
|
+
/**
|
|
200
|
+
* The utoo pack configs.
|
|
201
|
+
*/
|
|
202
|
+
config: ConfigComplete;
|
|
203
|
+
/**
|
|
204
|
+
* A map of environment variables to use when compiling code.
|
|
205
|
+
*/
|
|
206
|
+
processEnv?: Record<string, string>;
|
|
207
|
+
defineEnv?: DefineEnv;
|
|
208
|
+
/**
|
|
209
|
+
* Whether to watch the filesystem for file changes.
|
|
210
|
+
*/
|
|
211
|
+
watch?: {
|
|
212
|
+
enable: boolean;
|
|
213
|
+
pollIntervalMs?: number;
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* The mode of utoopack.
|
|
217
|
+
*/
|
|
218
|
+
dev?: boolean;
|
|
219
|
+
/**
|
|
220
|
+
* The build id.
|
|
221
|
+
*/
|
|
222
|
+
buildId?: string;
|
|
223
|
+
/**
|
|
224
|
+
* Absolute path for `@utoo/pack`.
|
|
225
|
+
*/
|
|
226
|
+
packPath?: string;
|
|
227
|
+
}
|
package/esm/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export * from "./config";
|
|
1
2
|
export { formatIssue, handleIssues, Issue } from "./issue";
|
|
2
3
|
export { decodeMagicIdentifier } from "./magicIdentifier";
|
|
3
4
|
export { renderStyledStringToErrorAnsi } from "./styledString";
|
|
5
|
+
export * from "./utils";
|
|
6
|
+
export * from "./webpackCompat";
|
package/esm/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var magicIdentifier_1 = require("./magicIdentifier");
|
|
8
|
-
Object.defineProperty(exports, "decodeMagicIdentifier", { enumerable: true, get: function () { return magicIdentifier_1.decodeMagicIdentifier; } });
|
|
9
|
-
var styledString_1 = require("./styledString");
|
|
10
|
-
Object.defineProperty(exports, "renderStyledStringToErrorAnsi", { enumerable: true, get: function () { return styledString_1.renderStyledStringToErrorAnsi; } });
|
|
1
|
+
export * from "./config";
|
|
2
|
+
export { formatIssue, handleIssues } from "./issue";
|
|
3
|
+
export { decodeMagicIdentifier } from "./magicIdentifier";
|
|
4
|
+
export { renderStyledStringToErrorAnsi } from "./styledString";
|
|
5
|
+
export * from "./utils";
|
|
6
|
+
export * from "./webpackCompat";
|