@umijs/bundler-utoopack 4.6.57 → 4.6.59
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/dist/config.d.ts +4 -3
- package/dist/config.js +136 -30
- package/dist/index.js +31 -10
- package/package.json +4 -4
package/dist/config.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { IOpts as IConfigOpts } from '@umijs/bundler-webpack';
|
|
2
2
|
import type { BundleOptions } from '@utoo/pack';
|
|
3
3
|
import type { IOpts } from './types';
|
|
4
|
+
export declare function normalizeUtoopackPath(path: string): string;
|
|
4
5
|
export declare function mergeExtraPostcssPlugins(postcssConfig: any, extraPlugins?: any[]): any;
|
|
5
|
-
export declare function getProdUtooPackConfig(
|
|
6
|
-
export declare function getSSRUtooPackConfig(
|
|
6
|
+
export declare function getProdUtooPackConfig(rawOpts: IOpts): Promise<BundleOptions>;
|
|
7
|
+
export declare function getSSRUtooPackConfig(rawOpts: IOpts & {
|
|
7
8
|
serverBuildPath: string;
|
|
8
9
|
useHash?: boolean;
|
|
9
10
|
isDev?: boolean;
|
|
@@ -36,4 +37,4 @@ export declare type IDevOpts = {
|
|
|
36
37
|
disableCopy?: boolean;
|
|
37
38
|
clean?: boolean;
|
|
38
39
|
} & Pick<IConfigOpts, 'cache' | 'pkg' | 'staticPathPrefix'>;
|
|
39
|
-
export declare function getDevUtooPackConfig(
|
|
40
|
+
export declare function getDevUtooPackConfig(rawOpts: IDevOpts): Promise<BundleOptions>;
|
package/dist/config.js
CHANGED
|
@@ -32,7 +32,8 @@ __export(config_exports, {
|
|
|
32
32
|
getDevUtooPackConfig: () => getDevUtooPackConfig,
|
|
33
33
|
getProdUtooPackConfig: () => getProdUtooPackConfig,
|
|
34
34
|
getSSRUtooPackConfig: () => getSSRUtooPackConfig,
|
|
35
|
-
mergeExtraPostcssPlugins: () => mergeExtraPostcssPlugins
|
|
35
|
+
mergeExtraPostcssPlugins: () => mergeExtraPostcssPlugins,
|
|
36
|
+
normalizeUtoopackPath: () => normalizeUtoopackPath
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(config_exports);
|
|
38
39
|
var import_bundler_webpack = require("@umijs/bundler-webpack");
|
|
@@ -203,6 +204,31 @@ function getExtraBabelModuleRules(opts) {
|
|
|
203
204
|
function normalizeUtoopackPath(path) {
|
|
204
205
|
return path.replace(/\\/g, "/");
|
|
205
206
|
}
|
|
207
|
+
function normalizeUtoopackEntry(entry) {
|
|
208
|
+
if (typeof entry === "string") {
|
|
209
|
+
return normalizeUtoopackPath(entry);
|
|
210
|
+
}
|
|
211
|
+
if (Array.isArray(entry)) {
|
|
212
|
+
return entry.map(normalizeUtoopackEntry);
|
|
213
|
+
}
|
|
214
|
+
if (entry && typeof entry === "object") {
|
|
215
|
+
return Object.fromEntries(
|
|
216
|
+
Object.entries(entry).map(([key, value]) => [
|
|
217
|
+
key,
|
|
218
|
+
normalizeUtoopackEntry(value)
|
|
219
|
+
])
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
return entry;
|
|
223
|
+
}
|
|
224
|
+
function normalizeUtoopackOpts(opts) {
|
|
225
|
+
return {
|
|
226
|
+
...opts,
|
|
227
|
+
cwd: normalizeUtoopackPath(opts.cwd),
|
|
228
|
+
rootDir: normalizeUtoopackPath(opts.rootDir),
|
|
229
|
+
entry: normalizeUtoopackEntry(opts.entry)
|
|
230
|
+
};
|
|
231
|
+
}
|
|
206
232
|
function getNormalizedAlias(alias, rootDir) {
|
|
207
233
|
const newAlias = Object.fromEntries(
|
|
208
234
|
Object.entries(alias || {}).map(([key, value]) => [
|
|
@@ -238,37 +264,113 @@ function getNormalizedAlias(alias, rootDir) {
|
|
|
238
264
|
newAlias[`${normalizedRootDir}/*`] = `${normalizedRootDir}/*`;
|
|
239
265
|
return newAlias;
|
|
240
266
|
}
|
|
267
|
+
function normalizeExternalValue(v) {
|
|
268
|
+
if (Array.isArray(v)) {
|
|
269
|
+
const [url, ...members] = v;
|
|
270
|
+
const scriptPrefix = /^script\s+/.exec(url);
|
|
271
|
+
const script = scriptPrefix ? url.slice(scriptPrefix[0].length) : url;
|
|
272
|
+
if (scriptPrefix) {
|
|
273
|
+
return {
|
|
274
|
+
// ['antd', 'Button'] => `antd.Button`
|
|
275
|
+
root: members.join("."),
|
|
276
|
+
type: "script",
|
|
277
|
+
// `script https://example.com/lib/script.js` => `https://example.com/lib/script.js`
|
|
278
|
+
script
|
|
279
|
+
};
|
|
280
|
+
} else if (url === "promise" && typeof members[0] === "string") {
|
|
281
|
+
return `promise ${members[0]}`;
|
|
282
|
+
} else {
|
|
283
|
+
return {
|
|
284
|
+
root: members.join("."),
|
|
285
|
+
script
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
} else if (typeof v === "string") {
|
|
289
|
+
return v.replace(/^window(\s+|\.)/, "");
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function toWildcardExternalConfig(value) {
|
|
293
|
+
const normalized = normalizeExternalValue(value);
|
|
294
|
+
if (typeof normalized === "string") {
|
|
295
|
+
const externalType = /^(commonjs|esm|promise)\s+/.exec(normalized);
|
|
296
|
+
if (externalType) {
|
|
297
|
+
return {
|
|
298
|
+
root: normalized.slice(externalType[0].length),
|
|
299
|
+
type: externalType[1]
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
root: normalized
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
function getExternalSubPathGlob(externalKey) {
|
|
308
|
+
if (!externalKey.includes("*")) return;
|
|
309
|
+
const parts = externalKey.split("/");
|
|
310
|
+
const packageName = externalKey.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
311
|
+
const subPathGlob = externalKey.slice(packageName.length);
|
|
312
|
+
if (!packageName || !subPathGlob.startsWith("/")) return;
|
|
313
|
+
return {
|
|
314
|
+
packageName,
|
|
315
|
+
subPathGlob
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
function escapeRegexChar(char) {
|
|
319
|
+
return /[|\\{}()[\]^$+?.]/.test(char) ? `\\${char}` : char;
|
|
320
|
+
}
|
|
321
|
+
function globToSubPathRegex(glob) {
|
|
322
|
+
let regex = "^";
|
|
323
|
+
for (const char of glob) {
|
|
324
|
+
if (char === "*") {
|
|
325
|
+
regex += ".+";
|
|
326
|
+
} else if (char === "/") {
|
|
327
|
+
regex += "\\/";
|
|
328
|
+
} else {
|
|
329
|
+
regex += escapeRegexChar(char);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return `/${regex}$/`;
|
|
333
|
+
}
|
|
334
|
+
function addWildcardSubPath(config, subPathGlob) {
|
|
335
|
+
var _a;
|
|
336
|
+
return {
|
|
337
|
+
...config,
|
|
338
|
+
subPath: {
|
|
339
|
+
...config.subPath || {},
|
|
340
|
+
rules: [
|
|
341
|
+
...((_a = config.subPath) == null ? void 0 : _a.rules) || [],
|
|
342
|
+
{
|
|
343
|
+
regex: globToSubPathRegex(subPathGlob),
|
|
344
|
+
target: ""
|
|
345
|
+
}
|
|
346
|
+
]
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
}
|
|
241
350
|
function getNormalizedExternals(externals) {
|
|
242
|
-
|
|
243
|
-
(
|
|
244
|
-
if (
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (scriptPrefix) {
|
|
249
|
-
ret[k] = {
|
|
250
|
-
// ['antd', 'Button'] => `antd.Button`
|
|
251
|
-
root: members.join("."),
|
|
252
|
-
type: "script",
|
|
253
|
-
// `script https://example.com/lib/script.js` => `https://example.com/lib/script.js`
|
|
254
|
-
script
|
|
255
|
-
};
|
|
256
|
-
} else if (url === "promise" && typeof members[0] === "string") {
|
|
257
|
-
ret[k] = `promise ${members[0]}`;
|
|
258
|
-
} else {
|
|
259
|
-
ret[k] = {
|
|
260
|
-
root: members.join("."),
|
|
261
|
-
script
|
|
262
|
-
};
|
|
351
|
+
const ret = Object.entries(externals || {}).reduce(
|
|
352
|
+
(memo, [k, v]) => {
|
|
353
|
+
if (!getExternalSubPathGlob(k)) {
|
|
354
|
+
const normalized = normalizeExternalValue(v);
|
|
355
|
+
if (normalized !== void 0) {
|
|
356
|
+
memo[k] = normalized;
|
|
263
357
|
}
|
|
264
|
-
} else if (typeof v === "string") {
|
|
265
|
-
ret[k] = v.replace(/^window(\s+|\.)/, "");
|
|
266
|
-
} else {
|
|
267
358
|
}
|
|
268
|
-
return
|
|
359
|
+
return memo;
|
|
269
360
|
},
|
|
270
361
|
{}
|
|
271
362
|
);
|
|
363
|
+
Object.entries(externals || {}).forEach(([k, v]) => {
|
|
364
|
+
const externalSubPathGlob = getExternalSubPathGlob(k);
|
|
365
|
+
if (!externalSubPathGlob) return;
|
|
366
|
+
const normalized = toWildcardExternalConfig(v);
|
|
367
|
+
if (!normalized) return;
|
|
368
|
+
ret[externalSubPathGlob.packageName] = addWildcardSubPath(
|
|
369
|
+
ret[externalSubPathGlob.packageName] && typeof ret[externalSubPathGlob.packageName] === "object" ? ret[externalSubPathGlob.packageName] : normalized,
|
|
370
|
+
externalSubPathGlob.subPathGlob
|
|
371
|
+
);
|
|
372
|
+
});
|
|
373
|
+
return ret;
|
|
272
374
|
}
|
|
273
375
|
function getSvgModuleRules(opts) {
|
|
274
376
|
const { svgr, svgo = {} } = opts;
|
|
@@ -369,8 +471,9 @@ function getUserUtoopackConfig(utoopackConfig = {}) {
|
|
|
369
471
|
function getDefaultPersistentCaching() {
|
|
370
472
|
return process.platform !== "win32";
|
|
371
473
|
}
|
|
372
|
-
async function getProdUtooPackConfig(
|
|
474
|
+
async function getProdUtooPackConfig(rawOpts) {
|
|
373
475
|
var _a;
|
|
476
|
+
const opts = normalizeUtoopackOpts(rawOpts);
|
|
374
477
|
const webpackConfig = await (0, import_bundler_webpack.getConfig)({
|
|
375
478
|
cwd: opts.cwd,
|
|
376
479
|
rootDir: opts.rootDir,
|
|
@@ -462,7 +565,8 @@ async function getProdUtooPackConfig(opts) {
|
|
|
462
565
|
};
|
|
463
566
|
return utooBundlerOpts;
|
|
464
567
|
}
|
|
465
|
-
async function getSSRUtooPackConfig(
|
|
568
|
+
async function getSSRUtooPackConfig(rawOpts) {
|
|
569
|
+
const opts = normalizeUtoopackOpts(rawOpts);
|
|
466
570
|
const utooBundlerOpts = await getProdUtooPackConfig({
|
|
467
571
|
...opts,
|
|
468
572
|
clean: false,
|
|
@@ -501,8 +605,9 @@ async function getSSRUtooPackConfig(opts) {
|
|
|
501
605
|
};
|
|
502
606
|
return utooBundlerOpts;
|
|
503
607
|
}
|
|
504
|
-
async function getDevUtooPackConfig(
|
|
608
|
+
async function getDevUtooPackConfig(rawOpts) {
|
|
505
609
|
var _a;
|
|
610
|
+
const opts = normalizeUtoopackOpts(rawOpts);
|
|
506
611
|
let webpackConfig = await (0, import_bundler_webpack.getConfig)({
|
|
507
612
|
cwd: opts.cwd,
|
|
508
613
|
rootDir: opts.rootDir,
|
|
@@ -621,5 +726,6 @@ async function getDevUtooPackConfig(opts) {
|
|
|
621
726
|
getDevUtooPackConfig,
|
|
622
727
|
getProdUtooPackConfig,
|
|
623
728
|
getSSRUtooPackConfig,
|
|
624
|
-
mergeExtraPostcssPlugins
|
|
729
|
+
mergeExtraPostcssPlugins,
|
|
730
|
+
normalizeUtoopackPath
|
|
625
731
|
});
|
package/dist/index.js
CHANGED
|
@@ -48,23 +48,32 @@ var import_util = require("./util");
|
|
|
48
48
|
var import_pack = require("@utoo/pack");
|
|
49
49
|
__reExport(src_exports, require("./config"), module.exports);
|
|
50
50
|
function getUtoopackRootDir(cwd, utoopackConfig, findRootDir2) {
|
|
51
|
+
const normalizedCwd = (0, import_config.normalizeUtoopackPath)(cwd);
|
|
51
52
|
if (typeof (utoopackConfig == null ? void 0 : utoopackConfig.root) === "string") {
|
|
52
|
-
return
|
|
53
|
+
return (0, import_config.normalizeUtoopackPath)(
|
|
54
|
+
import_path.default.resolve(normalizedCwd, utoopackConfig.root)
|
|
55
|
+
);
|
|
53
56
|
}
|
|
54
|
-
return findRootDir2(
|
|
57
|
+
return (0, import_config.normalizeUtoopackPath)(findRootDir2(normalizedCwd));
|
|
55
58
|
}
|
|
56
59
|
async function build(opts) {
|
|
57
60
|
var _a, _b, _c;
|
|
58
61
|
const { cwd, onBuildComplete } = opts;
|
|
62
|
+
const normalizedCwd = (0, import_config.normalizeUtoopackPath)(cwd);
|
|
59
63
|
const buildStartTime = Date.now();
|
|
60
64
|
const { build: utooPackBuild, findRootDir: findRootDir2 } = require("@utoo/pack");
|
|
61
|
-
const rootDir = getUtoopackRootDir(
|
|
65
|
+
const rootDir = getUtoopackRootDir(
|
|
66
|
+
normalizedCwd,
|
|
67
|
+
opts.config.utoopack,
|
|
68
|
+
findRootDir2
|
|
69
|
+
);
|
|
62
70
|
const utooPackConfig = await (0, import_config.getProdUtooPackConfig)({
|
|
63
71
|
...opts,
|
|
72
|
+
cwd: normalizedCwd,
|
|
64
73
|
rootDir
|
|
65
74
|
});
|
|
66
75
|
try {
|
|
67
|
-
await utooPackBuild(utooPackConfig,
|
|
76
|
+
await utooPackBuild(utooPackConfig, normalizedCwd, rootDir);
|
|
68
77
|
} catch (e) {
|
|
69
78
|
console.error(e.message);
|
|
70
79
|
const err = new Error("Build with utoopack failed.");
|
|
@@ -94,14 +103,14 @@ async function build(opts) {
|
|
|
94
103
|
isFirstCompile: true
|
|
95
104
|
}));
|
|
96
105
|
const absOutputPath = import_path.default.resolve(
|
|
97
|
-
|
|
106
|
+
normalizedCwd,
|
|
98
107
|
((_b = utooPackConfig.config.output) == null ? void 0 : _b.path) || "dist"
|
|
99
108
|
);
|
|
100
109
|
console.log(
|
|
101
110
|
(0, import_util.getBuildBanner)({
|
|
102
111
|
packVersion: process.env.UTOOPACK_VERSION,
|
|
103
112
|
duration: time,
|
|
104
|
-
outputPath: import_path.default.relative(
|
|
113
|
+
outputPath: import_path.default.relative(normalizedCwd, absOutputPath) || ".",
|
|
105
114
|
assetCount: (_c = stats.assets) == null ? void 0 : _c.length
|
|
106
115
|
})
|
|
107
116
|
);
|
|
@@ -110,15 +119,21 @@ async function build(opts) {
|
|
|
110
119
|
async function buildSSR(opts) {
|
|
111
120
|
var _a;
|
|
112
121
|
const { cwd } = opts;
|
|
122
|
+
const normalizedCwd = (0, import_config.normalizeUtoopackPath)(cwd);
|
|
113
123
|
const buildStartTime = Date.now();
|
|
114
124
|
const { build: utooPackBuild, findRootDir: findRootDir2 } = require("@utoo/pack");
|
|
115
|
-
const rootDir = getUtoopackRootDir(
|
|
125
|
+
const rootDir = getUtoopackRootDir(
|
|
126
|
+
normalizedCwd,
|
|
127
|
+
opts.config.utoopack,
|
|
128
|
+
findRootDir2
|
|
129
|
+
);
|
|
116
130
|
const utooPackConfig = await (0, import_config.getSSRUtooPackConfig)({
|
|
117
131
|
...opts,
|
|
132
|
+
cwd: normalizedCwd,
|
|
118
133
|
rootDir
|
|
119
134
|
});
|
|
120
135
|
try {
|
|
121
|
-
await utooPackBuild(utooPackConfig,
|
|
136
|
+
await utooPackBuild(utooPackConfig, normalizedCwd, rootDir);
|
|
122
137
|
} catch (e) {
|
|
123
138
|
console.error(e.message);
|
|
124
139
|
const err = new Error("Build SSR with utoopack failed.");
|
|
@@ -147,15 +162,21 @@ async function buildSSR(opts) {
|
|
|
147
162
|
}
|
|
148
163
|
async function dev(opts) {
|
|
149
164
|
const { cwd, onDevCompileDone } = opts;
|
|
165
|
+
const normalizedCwd = (0, import_config.normalizeUtoopackPath)(cwd);
|
|
150
166
|
if (!opts) {
|
|
151
167
|
throw new Error("opts should be supplied");
|
|
152
168
|
}
|
|
153
169
|
const devStartTime = Date.now();
|
|
154
170
|
const protocol = opts.config.https ? "https:" : "http:";
|
|
155
171
|
const { findRootDir: findRootDir2, serve: utooPackServe } = require("@utoo/pack");
|
|
156
|
-
const rootDir = getUtoopackRootDir(
|
|
172
|
+
const rootDir = getUtoopackRootDir(
|
|
173
|
+
normalizedCwd,
|
|
174
|
+
opts.config.utoopack,
|
|
175
|
+
findRootDir2
|
|
176
|
+
);
|
|
157
177
|
const utooPackConfig = await (0, import_config.getDevUtooPackConfig)({
|
|
158
178
|
...opts,
|
|
179
|
+
cwd: normalizedCwd,
|
|
159
180
|
rootDir
|
|
160
181
|
});
|
|
161
182
|
const app = (0, import_express.default)();
|
|
@@ -279,7 +300,7 @@ async function dev(opts) {
|
|
|
279
300
|
try {
|
|
280
301
|
await Promise.all([
|
|
281
302
|
serverReady,
|
|
282
|
-
utooPackServe(utooPackConfig,
|
|
303
|
+
utooPackServe(utooPackConfig, normalizedCwd, rootDir, {
|
|
283
304
|
port: utooServePort,
|
|
284
305
|
hostname: "127.0.0.1",
|
|
285
306
|
logServerInfo: false
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/bundler-utoopack",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.59",
|
|
4
4
|
"description": "@umijs/bundler-utoopack",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@utoo/pack": "1.4.
|
|
11
|
+
"@utoo/pack": "1.4.11",
|
|
12
12
|
"compression": "^1.7.4",
|
|
13
13
|
"connect-history-api-fallback": "^2.0.0",
|
|
14
14
|
"cors": "^2.8.5",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"resolve-url-loader": "5.0.0",
|
|
21
21
|
"sass": "1.54.0",
|
|
22
22
|
"sass-loader": "13.2.0",
|
|
23
|
-
"@umijs/bundler-webpack": "4.6.
|
|
24
|
-
"@umijs/bundler-utils": "4.6.
|
|
23
|
+
"@umijs/bundler-webpack": "4.6.59",
|
|
24
|
+
"@umijs/bundler-utils": "4.6.59"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"father": "4.1.5"
|