@modern-js/utils 2.15.1-alpha.0 → 2.16.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/FileSizeReporter.js +69 -92
- package/dist/cjs/alias.js +34 -58
- package/dist/cjs/analyzeProject.js +58 -41
- package/dist/cjs/applyOptionsChain.js +15 -42
- package/dist/cjs/babel.js +28 -39
- package/dist/cjs/chainId.js +7 -25
- package/dist/cjs/clearConsole.js +7 -25
- package/dist/cjs/commands.js +14 -29
- package/dist/cjs/compatRequire.js +22 -38
- package/dist/cjs/compiled.js +120 -139
- package/dist/cjs/constants.js +143 -98
- package/dist/cjs/debug.js +8 -26
- package/dist/cjs/emptyDir.js +10 -28
- package/dist/cjs/ensureAbsolutePath.js +13 -36
- package/dist/cjs/ensureArray.js +10 -26
- package/dist/cjs/findExists.js +14 -37
- package/dist/cjs/generateMetaTags.js +12 -31
- package/dist/cjs/getBrowserslist.js +20 -27
- package/dist/cjs/getCoreJsVersion.js +49 -37
- package/dist/cjs/getEntryOptions.js +14 -29
- package/dist/cjs/getPackageManager.js +23 -46
- package/dist/cjs/getPort.js +26 -61
- package/dist/cjs/getServerConfig.js +51 -43
- package/dist/cjs/getTargetDir.js +50 -38
- package/dist/cjs/import.js +16 -27
- package/dist/cjs/index.js +61 -60
- package/dist/cjs/is/index.js +53 -68
- package/dist/cjs/is/nodeEnv.js +13 -29
- package/dist/cjs/is/platform.js +13 -26
- package/dist/cjs/is/type.js +14 -33
- package/dist/cjs/logger.js +54 -50
- package/dist/cjs/monorepo.js +47 -78
- package/dist/cjs/nodeEnv.js +29 -31
- package/dist/cjs/path.js +42 -63
- package/dist/cjs/pathSerializer.js +43 -51
- package/dist/cjs/plugin.js +11 -29
- package/dist/cjs/prettyInstructions.js +35 -68
- package/dist/cjs/printBuildError.js +15 -37
- package/dist/cjs/react.js +18 -41
- package/dist/cjs/readTsConfig.js +21 -39
- package/dist/cjs/removeSlash.js +13 -27
- package/dist/cjs/resolve.js +25 -31
- package/dist/cjs/routes.js +22 -42
- package/dist/cjs/runtime/index.js +18 -17
- package/dist/cjs/runtime/parsed.js +8 -26
- package/dist/cjs/runtimeExports.js +31 -56
- package/dist/cjs/ssr.js +13 -26
- package/dist/cjs/storage.js +51 -41
- package/dist/cjs/testUtils.js +8 -29
- package/dist/cjs/types.js +4 -15
- package/dist/cjs/universal/constants.js +13 -26
- package/dist/cjs/universal/formatWebpack.js +16 -44
- package/dist/cjs/universal/nestedRoutes.js +94 -46
- package/dist/cjs/universal/pluginDagSort.js +58 -0
- package/dist/cjs/universal/remixRouter.js +18 -17
- package/dist/cjs/universal/serialize.js +16 -37
- package/dist/cjs/version.js +25 -41
- package/dist/cjs/wait.js +7 -25
- package/dist/cjs/watch.js +69 -43
- package/dist/esm/FileSizeReporter.js +40 -52
- package/dist/esm/alias.js +9 -19
- package/dist/esm/analyzeProject.js +3 -7
- package/dist/esm/applyOptionsChain.js +5 -17
- package/dist/esm/babel.js +6 -8
- package/dist/esm/chainId.js +1 -4
- package/dist/esm/clearConsole.js +1 -4
- package/dist/esm/commands.js +6 -12
- package/dist/esm/compatRequire.js +10 -17
- package/dist/esm/compiled.js +32 -76
- package/dist/esm/constants.js +143 -89
- package/dist/esm/debug.js +1 -4
- package/dist/esm/emptyDir.js +1 -4
- package/dist/esm/ensureAbsolutePath.js +1 -4
- package/dist/esm/ensureArray.js +4 -5
- package/dist/esm/findExists.js +1 -4
- package/dist/esm/generateMetaTags.js +6 -10
- package/dist/esm/getBrowserslist.js +8 -6
- package/dist/esm/getCoreJsVersion.js +1 -4
- package/dist/esm/getEntryOptions.js +5 -5
- package/dist/esm/getPackageManager.js +1 -4
- package/dist/esm/getPort.js +10 -25
- package/dist/esm/getServerConfig.js +2 -9
- package/dist/esm/getTargetDir.js +1 -4
- package/dist/esm/import.js +3 -4
- package/dist/esm/is/index.js +18 -30
- package/dist/esm/is/nodeEnv.js +5 -12
- package/dist/esm/is/platform.js +2 -6
- package/dist/esm/is/type.js +8 -18
- package/dist/esm/logger.js +37 -17
- package/dist/esm/monorepo.js +21 -38
- package/dist/esm/nodeEnv.js +18 -11
- package/dist/esm/path.js +16 -23
- package/dist/esm/pathSerializer.js +21 -21
- package/dist/esm/plugin.js +1 -4
- package/dist/esm/prettyInstructions.js +13 -32
- package/dist/esm/printBuildError.js +4 -11
- package/dist/esm/react.js +1 -4
- package/dist/esm/readTsConfig.js +2 -6
- package/dist/esm/removeSlash.js +3 -8
- package/dist/esm/resolve.js +14 -11
- package/dist/esm/routes.js +3 -9
- package/dist/esm/runtime/parsed.js +2 -5
- package/dist/esm/runtimeExports.js +17 -22
- package/dist/esm/ssr.js +1 -4
- package/dist/esm/storage.js +2 -6
- package/dist/esm/testUtils.js +2 -8
- package/dist/esm/types.js +1 -0
- package/dist/esm/universal/constants.js +2 -6
- package/dist/esm/universal/formatWebpack.js +10 -22
- package/dist/esm/universal/nestedRoutes.js +41 -27
- package/dist/esm/universal/pluginDagSort.js +50 -0
- package/dist/esm/universal/serialize.js +4 -5
- package/dist/esm/version.js +5 -7
- package/dist/esm/wait.js +1 -3
- package/dist/esm/watch.js +14 -9
- package/dist/types/universal/pluginDagSort.d.ts +1 -0
- package/package.json +17 -5
@@ -0,0 +1,58 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "pluginDagSort", {
|
6
|
+
enumerable: true,
|
7
|
+
get: () => pluginDagSort
|
8
|
+
});
|
9
|
+
const pluginDagSort = (plugins, key = "name", preKey = "pre", postKey = "post") => {
|
10
|
+
let allLines = [];
|
11
|
+
function getPluginByAny(q) {
|
12
|
+
const target = plugins.find((item) => typeof q === "string" ? item[key] === q : item[key] === q[key]);
|
13
|
+
if (!target) {
|
14
|
+
throw new Error(`plugin ${q} not existed`);
|
15
|
+
}
|
16
|
+
return target;
|
17
|
+
}
|
18
|
+
plugins.forEach((item) => {
|
19
|
+
var _item_preKey, _item_postKey;
|
20
|
+
(_item_preKey = item[preKey]) === null || _item_preKey === void 0 ? void 0 : _item_preKey.forEach((p) => {
|
21
|
+
if (plugins.find((ap) => ap.name === p)) {
|
22
|
+
allLines.push([
|
23
|
+
getPluginByAny(p)[key],
|
24
|
+
getPluginByAny(item)[key]
|
25
|
+
]);
|
26
|
+
}
|
27
|
+
});
|
28
|
+
(_item_postKey = item[postKey]) === null || _item_postKey === void 0 ? void 0 : _item_postKey.forEach((pt) => {
|
29
|
+
if (plugins.find((ap) => ap.name === pt)) {
|
30
|
+
allLines.push([
|
31
|
+
getPluginByAny(item)[key],
|
32
|
+
getPluginByAny(pt)[key]
|
33
|
+
]);
|
34
|
+
}
|
35
|
+
});
|
36
|
+
});
|
37
|
+
let zeroEndPoints = plugins.filter((item) => !allLines.find((l) => l[1] === item[key]));
|
38
|
+
const sortedPoint = [];
|
39
|
+
while (zeroEndPoints.length) {
|
40
|
+
const zep = zeroEndPoints.shift();
|
41
|
+
sortedPoint.push(getPluginByAny(zep));
|
42
|
+
allLines = allLines.filter((l) => l[0] !== getPluginByAny(zep)[key]);
|
43
|
+
const restPoints = plugins.filter((item) => !sortedPoint.find((sp) => sp[key] === item[key]));
|
44
|
+
zeroEndPoints = restPoints.filter(
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
46
|
+
(item) => !allLines.find((l) => l[1] === item[key])
|
47
|
+
);
|
48
|
+
}
|
49
|
+
if (allLines.length) {
|
50
|
+
const restInRingPoints = {};
|
51
|
+
allLines.forEach((l) => {
|
52
|
+
restInRingPoints[l[0]] = true;
|
53
|
+
restInRingPoints[l[1]] = true;
|
54
|
+
});
|
55
|
+
throw new Error(`plugins dependences has loop: ${Object.keys(restInRingPoints).join(",")}`);
|
56
|
+
}
|
57
|
+
return sortedPoint;
|
58
|
+
};
|
@@ -1,17 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
_export_star(require("@remix-run/router"), exports);
|
6
|
+
function _export_star(from, to) {
|
7
|
+
Object.keys(from).forEach(function(k) {
|
8
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
9
|
+
Object.defineProperty(to, k, {
|
10
|
+
enumerable: true,
|
11
|
+
get: function() {
|
12
|
+
return from[k];
|
13
|
+
}
|
14
|
+
});
|
15
|
+
}
|
16
|
+
});
|
17
|
+
return from;
|
18
|
+
}
|
@@ -1,40 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
-
var __export = (target, all) => {
|
8
|
-
for (var name in all)
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
10
|
-
};
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
13
|
-
for (let key of __getOwnPropNames(from))
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
-
}
|
17
|
-
return to;
|
18
|
-
};
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
-
mod
|
26
|
-
));
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
-
var serialize_exports = {};
|
29
|
-
__export(serialize_exports, {
|
30
|
-
serializeJson: () => serializeJson
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
31
4
|
});
|
32
|
-
|
33
|
-
|
5
|
+
Object.defineProperty(exports, "serializeJson", {
|
6
|
+
enumerable: true,
|
7
|
+
get: () => serializeJson
|
8
|
+
});
|
9
|
+
const _serializejavascript = /* @__PURE__ */ _interop_require_default(require("serialize-javascript"));
|
10
|
+
function _interop_require_default(obj) {
|
11
|
+
return obj && obj.__esModule ? obj : {
|
12
|
+
default: obj
|
13
|
+
};
|
14
|
+
}
|
34
15
|
const serializeJson = (data) => {
|
35
|
-
return (0,
|
16
|
+
return (0, _serializejavascript.default)(data, {
|
17
|
+
isJSON: true
|
18
|
+
});
|
36
19
|
};
|
37
|
-
// Annotate the CommonJS export names for ESM import in node:
|
38
|
-
0 && (module.exports = {
|
39
|
-
serializeJson
|
40
|
-
});
|
package/dist/cjs/version.js
CHANGED
@@ -1,48 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
-
var __export = (target, all) => {
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
8
6
|
for (var name in all)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
-
}
|
17
|
-
return to;
|
18
|
-
};
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
-
mod
|
26
|
-
));
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
-
var version_exports = {};
|
29
|
-
__export(version_exports, {
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
30
13
|
getPnpmVersion: () => getPnpmVersion,
|
31
14
|
isReact18: () => isReact18
|
32
15
|
});
|
33
|
-
|
34
|
-
|
35
|
-
|
16
|
+
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
17
|
+
const _compiled = require("./compiled");
|
18
|
+
function _interop_require_default(obj) {
|
19
|
+
return obj && obj.__esModule ? obj : {
|
20
|
+
default: obj
|
21
|
+
};
|
22
|
+
}
|
36
23
|
async function getPnpmVersion() {
|
37
|
-
const { stdout } = await (0,
|
24
|
+
const { stdout } = await (0, _compiled.execa)("pnpm", [
|
25
|
+
"--version"
|
26
|
+
]);
|
38
27
|
return stdout;
|
39
28
|
}
|
40
29
|
const isReact18 = (cwd) => {
|
41
|
-
const pkgPath =
|
42
|
-
if (!
|
30
|
+
const pkgPath = _path.default.join(cwd, "package.json");
|
31
|
+
if (!_compiled.fs.existsSync(pkgPath)) {
|
43
32
|
return false;
|
44
33
|
}
|
45
|
-
const pkgInfo = JSON.parse(
|
34
|
+
const pkgInfo = JSON.parse(_compiled.fs.readFileSync(pkgPath, "utf8"));
|
46
35
|
const deps = {
|
47
36
|
...pkgInfo.devDependencies,
|
48
37
|
...pkgInfo.dependencies
|
@@ -50,10 +39,5 @@ const isReact18 = (cwd) => {
|
|
50
39
|
if (typeof deps.react !== "string") {
|
51
40
|
return false;
|
52
41
|
}
|
53
|
-
return
|
42
|
+
return _compiled.semver.satisfies(_compiled.semver.minVersion(deps.react), ">=18.0.0");
|
54
43
|
};
|
55
|
-
// Annotate the CommonJS export names for ESM import in node:
|
56
|
-
0 && (module.exports = {
|
57
|
-
getPnpmVersion,
|
58
|
-
isReact18
|
59
|
-
});
|
package/dist/cjs/wait.js
CHANGED
@@ -1,29 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
};
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
-
for (let key of __getOwnPropNames(from))
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
-
}
|
15
|
-
return to;
|
16
|
-
};
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
-
var wait_exports = {};
|
19
|
-
__export(wait_exports, {
|
20
|
-
wait: () => wait
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "wait", {
|
6
|
+
enumerable: true,
|
7
|
+
get: () => wait
|
21
8
|
});
|
22
|
-
module.exports = __toCommonJS(wait_exports);
|
23
9
|
const wait = (time = 0) => new Promise((resolve) => {
|
24
10
|
setTimeout(resolve, time);
|
25
11
|
});
|
26
|
-
// Annotate the CommonJS export names for ESM import in node:
|
27
|
-
0 && (module.exports = {
|
28
|
-
wait
|
29
|
-
});
|
package/dist/cjs/watch.js
CHANGED
@@ -1,38 +1,60 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
-
var __export = (target, all) => {
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
8
6
|
for (var name in all)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
-
}
|
17
|
-
return to;
|
18
|
-
};
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
-
mod
|
26
|
-
));
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
-
var watch_exports = {};
|
29
|
-
__export(watch_exports, {
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
30
13
|
WatchChangeType: () => WatchChangeType,
|
31
14
|
watch: () => watch
|
32
15
|
});
|
33
|
-
|
34
|
-
|
35
|
-
|
16
|
+
const _path = /* @__PURE__ */ _interop_require_wildcard(require("path"));
|
17
|
+
const _compiled = require("./compiled");
|
18
|
+
function _getRequireWildcardCache(nodeInterop) {
|
19
|
+
if (typeof WeakMap !== "function")
|
20
|
+
return null;
|
21
|
+
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
|
22
|
+
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
|
23
|
+
return (_getRequireWildcardCache = function(nodeInterop2) {
|
24
|
+
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
|
25
|
+
})(nodeInterop);
|
26
|
+
}
|
27
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
28
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
29
|
+
return obj;
|
30
|
+
}
|
31
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
32
|
+
return {
|
33
|
+
default: obj
|
34
|
+
};
|
35
|
+
}
|
36
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
37
|
+
if (cache && cache.has(obj)) {
|
38
|
+
return cache.get(obj);
|
39
|
+
}
|
40
|
+
var newObj = {};
|
41
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
42
|
+
for (var key in obj) {
|
43
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
44
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
45
|
+
if (desc && (desc.get || desc.set)) {
|
46
|
+
Object.defineProperty(newObj, key, desc);
|
47
|
+
} else {
|
48
|
+
newObj[key] = obj[key];
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
newObj.default = obj;
|
53
|
+
if (cache) {
|
54
|
+
cache.set(obj, newObj);
|
55
|
+
}
|
56
|
+
return newObj;
|
57
|
+
}
|
36
58
|
const WatchChangeType = {
|
37
59
|
ADD: "add",
|
38
60
|
UNLINK: "unlink",
|
@@ -40,31 +62,35 @@ const WatchChangeType = {
|
|
40
62
|
};
|
41
63
|
const watch = (watchDir, runTask, ignored = []) => {
|
42
64
|
let ready = false;
|
43
|
-
const watcher =
|
65
|
+
const watcher = _compiled.chokidar.watch(watchDir, {
|
44
66
|
ignored
|
45
67
|
});
|
46
68
|
watcher.on("ready", () => ready = true);
|
47
69
|
watcher.on("change", async (filePath) => {
|
48
|
-
const changedFilePath =
|
49
|
-
await runTask({
|
70
|
+
const changedFilePath = _path.resolve(filePath);
|
71
|
+
await runTask({
|
72
|
+
changedFilePath,
|
73
|
+
changeType: WatchChangeType.CHANGE
|
74
|
+
});
|
50
75
|
});
|
51
76
|
watcher.on("add", async (filePath) => {
|
52
|
-
const changedFilePath =
|
77
|
+
const changedFilePath = _path.resolve(filePath);
|
53
78
|
if (ready) {
|
54
|
-
await runTask({
|
79
|
+
await runTask({
|
80
|
+
changedFilePath,
|
81
|
+
changeType: WatchChangeType.ADD
|
82
|
+
});
|
55
83
|
}
|
56
84
|
});
|
57
85
|
watcher.on("unlink", async (filePath) => {
|
58
|
-
const changedFilePath =
|
59
|
-
await runTask({
|
86
|
+
const changedFilePath = _path.resolve(filePath);
|
87
|
+
await runTask({
|
88
|
+
changedFilePath,
|
89
|
+
changeType: WatchChangeType.UNLINK
|
90
|
+
});
|
60
91
|
});
|
61
92
|
watcher.on("error", (err) => {
|
62
93
|
throw err;
|
63
94
|
});
|
64
95
|
return watcher;
|
65
96
|
};
|
66
|
-
// Annotate the CommonJS export names for ESM import in node:
|
67
|
-
0 && (module.exports = {
|
68
|
-
WatchChangeType,
|
69
|
-
watch
|
70
|
-
});
|
@@ -1,12 +1,7 @@
|
|
1
|
+
"use strict";
|
1
2
|
import fs from "fs";
|
2
3
|
import path from "path";
|
3
|
-
import {
|
4
|
-
chalk,
|
5
|
-
filesize,
|
6
|
-
stripAnsi,
|
7
|
-
gzipSize,
|
8
|
-
recursiveReaddir
|
9
|
-
} from "./compiled";
|
4
|
+
import { chalk, filesize, stripAnsi, gzipSize, recursiveReaddir } from "./compiled";
|
10
5
|
import { logger } from "./logger";
|
11
6
|
function canReadAsset(asset) {
|
12
7
|
return /\.(js|css)$/.test(asset) && !/service-worker\.js/.test(asset) && !/precache-manifest\.[0-9a-f]+\.js/.test(asset);
|
@@ -14,38 +9,29 @@ function canReadAsset(asset) {
|
|
14
9
|
function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, maxBundleGzipSize, maxChunkGzipSize) {
|
15
10
|
var root = previousSizeMap.root;
|
16
11
|
var sizes = previousSizeMap.sizes;
|
17
|
-
var assets = (webpackStats.stats || [
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
};
|
38
|
-
})
|
39
|
-
).reduce((single, all) => all.concat(single), []);
|
12
|
+
var assets = (webpackStats.stats || [
|
13
|
+
webpackStats
|
14
|
+
]).map((stats) => stats.toJson({
|
15
|
+
all: false,
|
16
|
+
assets: true
|
17
|
+
}).assets.filter((asset) => canReadAsset(asset.name)).map((asset) => {
|
18
|
+
var fileContents = fs.readFileSync(path.join(root, asset.name));
|
19
|
+
var size = fileContents.length;
|
20
|
+
var gzippedSize = gzipSize.sync(fileContents);
|
21
|
+
var [previousSize, previousGzipSize] = sizes[removeFileNameHash(root, asset.name)] || [];
|
22
|
+
var sizeDifference = getDifferenceLabel(size, previousSize);
|
23
|
+
var gzipSizeDifference = getDifferenceLabel(gzippedSize, previousGzipSize);
|
24
|
+
return {
|
25
|
+
folder: path.join(path.basename(buildFolder), path.dirname(asset.name)),
|
26
|
+
name: path.basename(asset.name),
|
27
|
+
gzippedSize,
|
28
|
+
sizeLabel: filesize(size) + (sizeDifference ? " (" + sizeDifference + ")" : ""),
|
29
|
+
gzipSizeLabel: filesize(gzippedSize) + (gzipSizeDifference ? " (" + gzipSizeDifference + ")" : "")
|
30
|
+
};
|
31
|
+
})).reduce((single, all) => all.concat(single), []);
|
40
32
|
assets.sort((a, b) => b.size - a.size);
|
41
|
-
var longestSizeLabelLength = Math.max.apply(
|
42
|
-
|
43
|
-
assets.map((a) => stripAnsi(a.sizeLabel).length)
|
44
|
-
);
|
45
|
-
var longestFileNameLength = Math.max.apply(
|
46
|
-
null,
|
47
|
-
assets.map((a) => stripAnsi(a.folder + path.sep + a.name).length)
|
48
|
-
);
|
33
|
+
var longestSizeLabelLength = Math.max.apply(null, assets.map((a) => stripAnsi(a.sizeLabel).length));
|
34
|
+
var longestFileNameLength = Math.max.apply(null, assets.map((a) => stripAnsi(a.folder + path.sep + a.name).length));
|
49
35
|
printFileSizesHeader(longestFileNameLength, longestSizeLabelLength);
|
50
36
|
var suggestBundleSplitting = false;
|
51
37
|
assets.forEach((asset) => {
|
@@ -67,9 +53,7 @@ function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, ma
|
|
67
53
|
if (isLarge && path.extname(asset.name) === ".js") {
|
68
54
|
suggestBundleSplitting = true;
|
69
55
|
}
|
70
|
-
logger.log(
|
71
|
-
" " + fileNameLabel + " " + sizeLabel + " " + (isLarge ? chalk.yellow(gzipSizeLabel) : gzipSizeLabel)
|
72
|
-
);
|
56
|
+
logger.log(" " + fileNameLabel + " " + sizeLabel + " " + (isLarge ? chalk.yellow(gzipSizeLabel) : gzipSizeLabel));
|
73
57
|
});
|
74
58
|
if (suggestBundleSplitting) {
|
75
59
|
logger.log();
|
@@ -77,8 +61,15 @@ function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, ma
|
|
77
61
|
}
|
78
62
|
}
|
79
63
|
function printFileSizesHeader(longestFileNameLength, longestSizeLabelLength) {
|
80
|
-
const longestLengths = [
|
81
|
-
|
64
|
+
const longestLengths = [
|
65
|
+
longestFileNameLength,
|
66
|
+
longestSizeLabelLength
|
67
|
+
];
|
68
|
+
const headerRow = [
|
69
|
+
"File",
|
70
|
+
"Size",
|
71
|
+
"Gzipped"
|
72
|
+
].reduce((prev, cur, index) => {
|
82
73
|
const length = longestLengths[index];
|
83
74
|
let curLabel = cur;
|
84
75
|
if (length) {
|
@@ -89,10 +80,7 @@ function printFileSizesHeader(longestFileNameLength, longestSizeLabelLength) {
|
|
89
80
|
logger.log(chalk.bold(chalk.blue(headerRow)));
|
90
81
|
}
|
91
82
|
function removeFileNameHash(buildFolder, fileName) {
|
92
|
-
return fileName.replace(buildFolder, "").replace(/\\/g, "/").replace(
|
93
|
-
/\/?(.*)(\.[0-9a-f]+)(\.chunk)?(\.js|\.css)/,
|
94
|
-
(match, p1, p2, p3, p4) => p1 + p4
|
95
|
-
);
|
83
|
+
return fileName.replace(buildFolder, "").replace(/\\/g, "/").replace(/\/?(.*)(\.[0-9a-f]+)(\.chunk)?(\.js|\.css)/, (match, p1, p2, p3, p4) => p1 + p4);
|
96
84
|
}
|
97
85
|
function getDifferenceLabel(currentSize, previousSize) {
|
98
86
|
var FIFTY_KILOBYTES = 1024 * 50;
|
@@ -116,7 +104,10 @@ function measureFileSizesBeforeBuild(buildFolder) {
|
|
116
104
|
sizes = fileNames.filter(canReadAsset).reduce((memo, fileName) => {
|
117
105
|
var contents = fs.readFileSync(fileName);
|
118
106
|
var key = removeFileNameHash(buildFolder, fileName);
|
119
|
-
memo[key] = [
|
107
|
+
memo[key] = [
|
108
|
+
contents.length,
|
109
|
+
gzipSize.sync(contents)
|
110
|
+
];
|
120
111
|
return memo;
|
121
112
|
}, {});
|
122
113
|
}
|
@@ -127,7 +118,4 @@ function measureFileSizesBeforeBuild(buildFolder) {
|
|
127
118
|
});
|
128
119
|
});
|
129
120
|
}
|
130
|
-
export {
|
131
|
-
measureFileSizesBeforeBuild,
|
132
|
-
printFileSizesAfterBuild
|
133
|
-
};
|
121
|
+
export { measureFileSizesBeforeBuild, printFileSizesAfterBuild };
|
package/dist/esm/alias.js
CHANGED
@@ -3,10 +3,8 @@ import path from "path";
|
|
3
3
|
import { chalk } from "./compiled";
|
4
4
|
import { readTsConfigByFile } from "./readTsConfig";
|
5
5
|
import { applyOptionsChain } from "./applyOptionsChain";
|
6
|
-
const validAlias = (modernConfig, { tsconfigPath }) => {
|
7
|
-
const {
|
8
|
-
source: { alias }
|
9
|
-
} = modernConfig;
|
6
|
+
export const validAlias = (modernConfig, { tsconfigPath }) => {
|
7
|
+
const { source: { alias } } = modernConfig;
|
10
8
|
if (!alias) {
|
11
9
|
return null;
|
12
10
|
}
|
@@ -16,15 +14,13 @@ const validAlias = (modernConfig, { tsconfigPath }) => {
|
|
16
14
|
}
|
17
15
|
const userAlias = getUserAlias(alias);
|
18
16
|
if (Object.keys(userAlias).length > 0) {
|
19
|
-
return chalk.red(
|
20
|
-
'Note: Please use `compilerOptions.paths` in "tsconfig.json" file replace `source.alias` config in "modern.config.js/ts" when project is typescript'
|
21
|
-
);
|
17
|
+
return chalk.red('Note: Please use `compilerOptions.paths` in "tsconfig.json" file replace `source.alias` config in "modern.config.js/ts" when project is typescript');
|
22
18
|
}
|
23
19
|
return null;
|
24
20
|
};
|
25
|
-
const mergeAlias = (alias) => applyOptionsChain({}, alias);
|
26
|
-
const getAliasConfig = (aliasOption, option) => {
|
27
|
-
var
|
21
|
+
export const mergeAlias = (alias) => applyOptionsChain({}, alias);
|
22
|
+
export const getAliasConfig = (aliasOption, option) => {
|
23
|
+
var _tsconfig_compilerOptions, _tsconfig_compilerOptions1;
|
28
24
|
const isTsProject = fs.existsSync(option.tsconfigPath);
|
29
25
|
const alias = mergeAlias(aliasOption);
|
30
26
|
if (!isTsProject) {
|
@@ -36,26 +32,20 @@ const getAliasConfig = (aliasOption, option) => {
|
|
36
32
|
};
|
37
33
|
}
|
38
34
|
const tsconfig = readTsConfigByFile(option.tsconfigPath);
|
39
|
-
const baseUrl =
|
35
|
+
const baseUrl = tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions === void 0 ? void 0 : _tsconfig_compilerOptions.baseUrl;
|
40
36
|
return {
|
41
37
|
absoluteBaseUrl: baseUrl ? path.join(option.appDirectory, baseUrl) : option.appDirectory,
|
42
38
|
paths: {
|
43
39
|
...alias,
|
44
|
-
...
|
40
|
+
...tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions1 = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions1 === void 0 ? void 0 : _tsconfig_compilerOptions1.paths
|
45
41
|
},
|
46
42
|
isTsPath: true,
|
47
43
|
isTsProject
|
48
44
|
};
|
49
45
|
};
|
50
|
-
const getUserAlias = (alias = {}) => Object.keys(alias).reduce((o, k) => {
|
46
|
+
export const getUserAlias = (alias = {}) => Object.keys(alias).reduce((o, k) => {
|
51
47
|
if (Array.isArray(alias[k])) {
|
52
48
|
o[k] = alias[k];
|
53
49
|
}
|
54
50
|
return o;
|
55
51
|
}, {});
|
56
|
-
export {
|
57
|
-
getAliasConfig,
|
58
|
-
getUserAlias,
|
59
|
-
mergeAlias,
|
60
|
-
validAlias
|
61
|
-
};
|
@@ -1,17 +1,13 @@
|
|
1
1
|
import * as path from "path";
|
2
2
|
import { getArgv } from "./commands";
|
3
3
|
import { fs, minimist } from "./compiled";
|
4
|
-
const isApiOnly = async (appDirectory, entryDir) => {
|
5
|
-
const srcDir = path.join(appDirectory, entryDir
|
4
|
+
export const isApiOnly = async (appDirectory, entryDir) => {
|
5
|
+
const srcDir = path.join(appDirectory, entryDir !== null && entryDir !== void 0 ? entryDir : "src");
|
6
6
|
const existSrc = await fs.pathExists(srcDir);
|
7
7
|
const options = minimist(getArgv());
|
8
8
|
return !existSrc || Boolean(options["api-only"]);
|
9
9
|
};
|
10
|
-
const isWebOnly = async () => {
|
10
|
+
export const isWebOnly = async () => {
|
11
11
|
const options = minimist(getArgv());
|
12
12
|
return Boolean(options["web-only"]);
|
13
13
|
};
|
14
|
-
export {
|
15
|
-
isApiOnly,
|
16
|
-
isWebOnly
|
17
|
-
};
|