@modern-js/utils 2.21.1 → 2.22.1-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +11 -0
- package/dist/FileSizeReporter.d.ts +16 -0
- package/dist/FileSizeReporter.js +162 -0
- package/dist/alias.d.ts +25 -0
- package/dist/alias.js +108 -0
- package/dist/analyzeProject.d.ts +2 -0
- package/dist/analyzeProject.js +71 -0
- package/dist/applyOptionsChain.d.ts +3 -0
- package/dist/applyOptionsChain.js +58 -0
- package/dist/babel.d.ts +3 -0
- package/dist/babel.js +136 -0
- package/dist/chainId.d.ts +244 -0
- package/dist/chainId.js +196 -0
- package/dist/cjs/cli/alias.js +12 -4
- package/dist/cjs/cli/applyOptionsChain.js +3 -1
- package/dist/cjs/cli/babel.js +6 -2
- package/dist/cjs/cli/commands.js +12 -4
- package/dist/cjs/cli/common.js +9 -3
- package/dist/cjs/cli/constants/chainId.js +3 -1
- package/dist/cjs/cli/constants/index.js +93 -31
- package/dist/cjs/cli/ensure.js +6 -2
- package/dist/cjs/cli/fs.js +6 -2
- package/dist/cjs/cli/get/config.js +3 -1
- package/dist/cjs/cli/get/data.js +24 -8
- package/dist/cjs/cli/get/index.js +6 -2
- package/dist/cjs/cli/is/config.js +18 -6
- package/dist/cjs/cli/is/env.js +18 -6
- package/dist/cjs/cli/is/platform.js +6 -2
- package/dist/cjs/cli/is/project.js +21 -7
- package/dist/cjs/cli/is/type.js +27 -9
- package/dist/cjs/cli/logger.js +6 -2
- package/dist/cjs/cli/monorepo.js +21 -7
- package/dist/cjs/cli/package.js +12 -4
- package/dist/cjs/cli/path.js +39 -13
- package/dist/cjs/cli/pathSerializer.js +12 -4
- package/dist/cjs/cli/port.js +3 -1
- package/dist/cjs/cli/prettyInstructions.js +6 -2
- package/dist/cjs/cli/print.js +3 -1
- package/dist/cjs/cli/require.js +18 -6
- package/dist/cjs/cli/routes.js +3 -1
- package/dist/cjs/cli/runtimeExports.js +3 -1
- package/dist/cjs/cli/test.js +3 -1
- package/dist/cjs/cli/watch.js +6 -2
- package/dist/cjs/compiled.js +99 -33
- package/dist/cjs/import.js +6 -2
- package/dist/cjs/runtime/nestedRoutes.js +6 -2
- package/dist/cjs/runtime-browser/parsed.js +8 -2
- package/dist/cjs/runtime-node/index.js +9 -3
- package/dist/cjs/runtime-node/serialize.js +3 -1
- package/dist/cjs/runtime-node/storage.js +3 -1
- package/dist/cjs/universal/constants.js +6 -2
- package/dist/cjs/universal/formatWebpack.js +3 -1
- package/dist/cjs/universal/pluginDagSort.js +3 -1
- package/dist/clearConsole.d.ts +1 -0
- package/dist/clearConsole.js +31 -0
- package/dist/commands.d.ts +4 -0
- package/dist/commands.js +48 -0
- package/dist/compatRequire.d.ts +13 -0
- package/dist/compatRequire.js +82 -0
- package/dist/compiled.d.ts +43 -0
- package/dist/compiled.js +142 -0
- package/dist/constants.d.ts +244 -0
- package/dist/constants.js +320 -0
- package/dist/debug.d.ts +6 -0
- package/dist/debug.js +28 -0
- package/dist/emptyDir.d.ts +1 -0
- package/dist/emptyDir.js +52 -0
- package/dist/ensureAbsolutePath.d.ts +7 -0
- package/dist/ensureAbsolutePath.js +38 -0
- package/dist/ensureArray.d.ts +1 -0
- package/dist/ensureArray.js +32 -0
- package/dist/esm/runtime-browser/parsed.js +5 -1
- package/dist/findExists.d.ts +6 -0
- package/dist/findExists.js +45 -0
- package/dist/generateMetaTags.d.ts +16 -0
- package/dist/generateMetaTags.js +61 -0
- package/dist/getBrowserslist.d.ts +2 -0
- package/dist/getBrowserslist.js +31 -0
- package/dist/getCoreJsVersion.d.ts +1 -0
- package/dist/getCoreJsVersion.js +46 -0
- package/dist/getEntryOptions.d.ts +1 -0
- package/dist/getEntryOptions.js +54 -0
- package/dist/getPackageManager.d.ts +1 -0
- package/dist/getPackageManager.js +87 -0
- package/dist/getPort.d.ts +14 -0
- package/dist/getPort.js +112 -0
- package/dist/getServerConfig.d.ts +1 -0
- package/dist/getServerConfig.js +67 -0
- package/dist/getTargetDir.d.ts +1 -0
- package/dist/getTargetDir.js +41 -0
- package/dist/import.d.ts +5 -0
- package/dist/import.js +33 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +60 -0
- package/dist/is/index.d.ts +58 -0
- package/dist/is/index.js +114 -0
- package/dist/is/nodeEnv.d.ts +8 -0
- package/dist/is/nodeEnv.js +39 -0
- package/dist/is/platform.d.ts +2 -0
- package/dist/is/platform.js +30 -0
- package/dist/is/type.d.ts +8 -0
- package/dist/is/type.js +64 -0
- package/dist/logger.d.ts +65 -0
- package/dist/logger.js +145 -0
- package/dist/monorepo.d.ts +11 -0
- package/dist/monorepo.js +137 -0
- package/dist/nodeEnv.d.ts +3 -0
- package/dist/nodeEnv.js +81 -0
- package/dist/path.d.ts +18 -0
- package/dist/path.js +92 -0
- package/dist/pathSerializer.d.ts +16 -0
- package/dist/pathSerializer.js +76 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +46 -0
- package/dist/prettyInstructions.d.ts +9 -0
- package/dist/prettyInstructions.js +112 -0
- package/dist/printBuildError.d.ts +8 -0
- package/dist/printBuildError.js +57 -0
- package/dist/react.d.ts +1 -0
- package/dist/react.js +64 -0
- package/dist/readTsConfig.d.ts +2 -0
- package/dist/readTsConfig.js +47 -0
- package/dist/removeSlash.d.ts +3 -0
- package/dist/removeSlash.js +33 -0
- package/dist/resolve.d.ts +13 -0
- package/dist/resolve.js +63 -0
- package/dist/routes.d.ts +2 -0
- package/dist/routes.js +58 -0
- package/dist/runtimeExports.d.ts +4 -0
- package/dist/runtimeExports.js +73 -0
- package/dist/ssr.d.ts +8 -0
- package/dist/ssr.js +30 -0
- package/dist/storage.d.ts +5 -0
- package/dist/storage.js +75 -0
- package/dist/testUtils.d.ts +5 -0
- package/dist/testUtils.js +38 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.js +15 -0
- package/dist/universal/constants.d.ts +9 -0
- package/dist/universal/constants.js +30 -0
- package/dist/universal/formatWebpack.d.ts +13 -0
- package/dist/universal/formatWebpack.js +100 -0
- package/dist/universal/nestedRoutes.d.ts +8 -0
- package/dist/universal/nestedRoutes.js +131 -0
- package/dist/universal/remixRouter.d.ts +1 -0
- package/dist/universal/remixRouter.js +17 -0
- package/dist/universal/serialize.d.ts +1 -0
- package/dist/universal/serialize.js +40 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +92 -0
- package/dist/wait.d.ts +2 -0
- package/dist/wait.js +29 -0
- package/dist/watch.d.ts +8 -0
- package/dist/watch.js +90 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# @modern-js/utils
|
2
2
|
|
3
|
+
## 2.22.0
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 3d48836: chore(deps): fix all missing peer dependencies
|
8
|
+
|
9
|
+
chore(deps): 修复缺少的 peer dependencies
|
10
|
+
|
11
|
+
- 5050e8e: fix: browser should get last element that server insert to html for baseUrl
|
12
|
+
fix: 浏览器需要获取最后一个 Server 注入 HTML 的 baseUrl 数据
|
13
|
+
|
3
14
|
## 2.21.1
|
4
15
|
|
5
16
|
## 2.21.0
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2015-present, Facebook, Inc.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file at
|
6
|
+
* https://github.com/facebook/create-react-app/blob/master/LICENSE
|
7
|
+
*/
|
8
|
+
declare function printFileSizesAfterBuild(webpackStats: any, previousSizeMap: {
|
9
|
+
root: string;
|
10
|
+
sizes: Record<string, number[]>;
|
11
|
+
}, buildFolder: string, maxBundleGzipSize: number, maxChunkGzipSize: number): void;
|
12
|
+
declare function measureFileSizesBeforeBuild(buildFolder: string): Promise<{
|
13
|
+
root: string;
|
14
|
+
sizes: Record<string, number[]>;
|
15
|
+
}>;
|
16
|
+
export { measureFileSizesBeforeBuild, printFileSizesAfterBuild };
|
@@ -0,0 +1,162 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var FileSizeReporter_exports = {};
|
30
|
+
__export(FileSizeReporter_exports, {
|
31
|
+
measureFileSizesBeforeBuild: () => measureFileSizesBeforeBuild,
|
32
|
+
printFileSizesAfterBuild: () => printFileSizesAfterBuild
|
33
|
+
});
|
34
|
+
module.exports = __toCommonJS(FileSizeReporter_exports);
|
35
|
+
var import_fs = __toESM(require("fs"));
|
36
|
+
var import_path = __toESM(require("path"));
|
37
|
+
var import_compiled = require("./compiled");
|
38
|
+
var import_logger = require("./logger");
|
39
|
+
function canReadAsset(asset) {
|
40
|
+
return /\.(js|css)$/.test(asset) && !/service-worker\.js/.test(asset) && !/precache-manifest\.[0-9a-f]+\.js/.test(asset);
|
41
|
+
}
|
42
|
+
function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, maxBundleGzipSize, maxChunkGzipSize) {
|
43
|
+
var root = previousSizeMap.root;
|
44
|
+
var sizes = previousSizeMap.sizes;
|
45
|
+
var assets = (webpackStats.stats || [webpackStats]).map(
|
46
|
+
(stats) => stats.toJson({ all: false, assets: true }).assets.filter((asset) => canReadAsset(asset.name)).map((asset) => {
|
47
|
+
var fileContents = import_fs.default.readFileSync(import_path.default.join(root, asset.name));
|
48
|
+
var size = fileContents.length;
|
49
|
+
var gzippedSize = import_compiled.gzipSize.sync(fileContents);
|
50
|
+
var [previousSize, previousGzipSize] = sizes[removeFileNameHash(root, asset.name)] || [];
|
51
|
+
var sizeDifference = getDifferenceLabel(size, previousSize);
|
52
|
+
var gzipSizeDifference = getDifferenceLabel(
|
53
|
+
gzippedSize,
|
54
|
+
previousGzipSize
|
55
|
+
);
|
56
|
+
return {
|
57
|
+
folder: import_path.default.join(
|
58
|
+
import_path.default.basename(buildFolder),
|
59
|
+
import_path.default.dirname(asset.name)
|
60
|
+
),
|
61
|
+
name: import_path.default.basename(asset.name),
|
62
|
+
gzippedSize,
|
63
|
+
sizeLabel: (0, import_compiled.filesize)(size) + (sizeDifference ? " (" + sizeDifference + ")" : ""),
|
64
|
+
gzipSizeLabel: (0, import_compiled.filesize)(gzippedSize) + (gzipSizeDifference ? " (" + gzipSizeDifference + ")" : "")
|
65
|
+
};
|
66
|
+
})
|
67
|
+
).reduce((single, all) => all.concat(single), []);
|
68
|
+
assets.sort((a, b) => b.size - a.size);
|
69
|
+
var longestSizeLabelLength = Math.max.apply(
|
70
|
+
null,
|
71
|
+
assets.map((a) => (0, import_compiled.stripAnsi)(a.sizeLabel).length)
|
72
|
+
);
|
73
|
+
var longestFileNameLength = Math.max.apply(
|
74
|
+
null,
|
75
|
+
assets.map((a) => (0, import_compiled.stripAnsi)(a.folder + import_path.default.sep + a.name).length)
|
76
|
+
);
|
77
|
+
printFileSizesHeader(longestFileNameLength, longestSizeLabelLength);
|
78
|
+
var suggestBundleSplitting = false;
|
79
|
+
assets.forEach((asset) => {
|
80
|
+
var { folder, name, sizeLabel, gzipSizeLabel, gzippedSize } = asset;
|
81
|
+
var fileNameLength = (0, import_compiled.stripAnsi)(folder + import_path.default.sep + name).length;
|
82
|
+
var sizeLength = (0, import_compiled.stripAnsi)(sizeLabel).length;
|
83
|
+
if (sizeLength < longestSizeLabelLength) {
|
84
|
+
var rightPadding = " ".repeat(longestSizeLabelLength - sizeLength);
|
85
|
+
sizeLabel += rightPadding;
|
86
|
+
}
|
87
|
+
var fileNameLabel = import_compiled.chalk.dim(asset.folder + import_path.default.sep) + import_compiled.chalk.cyan(asset.name);
|
88
|
+
if (fileNameLength < longestFileNameLength) {
|
89
|
+
var rightPadding = " ".repeat(longestFileNameLength - fileNameLength);
|
90
|
+
fileNameLabel += rightPadding;
|
91
|
+
}
|
92
|
+
var isMainBundle = asset.name.indexOf("main.") === 0;
|
93
|
+
var maxRecommendedSize = isMainBundle ? maxBundleGzipSize : maxChunkGzipSize;
|
94
|
+
var isLarge = maxRecommendedSize && gzippedSize > maxRecommendedSize;
|
95
|
+
if (isLarge && import_path.default.extname(asset.name) === ".js") {
|
96
|
+
suggestBundleSplitting = true;
|
97
|
+
}
|
98
|
+
import_logger.logger.log(
|
99
|
+
" " + fileNameLabel + " " + sizeLabel + " " + (isLarge ? import_compiled.chalk.yellow(gzipSizeLabel) : gzipSizeLabel)
|
100
|
+
);
|
101
|
+
});
|
102
|
+
if (suggestBundleSplitting) {
|
103
|
+
import_logger.logger.log();
|
104
|
+
import_logger.logger.warn("The bundle size is significantly larger than recommended.");
|
105
|
+
}
|
106
|
+
}
|
107
|
+
function printFileSizesHeader(longestFileNameLength, longestSizeLabelLength) {
|
108
|
+
const longestLengths = [longestFileNameLength, longestSizeLabelLength];
|
109
|
+
const headerRow = ["File", "Size", "Gzipped"].reduce((prev, cur, index) => {
|
110
|
+
const length = longestLengths[index];
|
111
|
+
let curLabel = cur;
|
112
|
+
if (length) {
|
113
|
+
curLabel = cur.length < length ? cur + " ".repeat(length - cur.length) : cur;
|
114
|
+
}
|
115
|
+
return prev + curLabel + " ";
|
116
|
+
}, " ");
|
117
|
+
import_logger.logger.log(import_compiled.chalk.bold(import_compiled.chalk.blue(headerRow)));
|
118
|
+
}
|
119
|
+
function removeFileNameHash(buildFolder, fileName) {
|
120
|
+
return fileName.replace(buildFolder, "").replace(/\\/g, "/").replace(
|
121
|
+
/\/?(.*)(\.[0-9a-f]+)(\.chunk)?(\.js|\.css)/,
|
122
|
+
(match, p1, p2, p3, p4) => p1 + p4
|
123
|
+
);
|
124
|
+
}
|
125
|
+
function getDifferenceLabel(currentSize, previousSize) {
|
126
|
+
var FIFTY_KILOBYTES = 1024 * 50;
|
127
|
+
var difference = currentSize - previousSize;
|
128
|
+
var fileSize = !Number.isNaN(difference) ? (0, import_compiled.filesize)(difference) : 0;
|
129
|
+
if (difference >= FIFTY_KILOBYTES) {
|
130
|
+
return import_compiled.chalk.red("+" + fileSize);
|
131
|
+
} else if (difference < FIFTY_KILOBYTES && difference > 0) {
|
132
|
+
return import_compiled.chalk.yellow("+" + fileSize);
|
133
|
+
} else if (difference < 0) {
|
134
|
+
return import_compiled.chalk.green(fileSize);
|
135
|
+
} else {
|
136
|
+
return "";
|
137
|
+
}
|
138
|
+
}
|
139
|
+
function measureFileSizesBeforeBuild(buildFolder) {
|
140
|
+
return new Promise((resolve) => {
|
141
|
+
(0, import_compiled.recursiveReaddir)(buildFolder, (err, fileNames) => {
|
142
|
+
var sizes;
|
143
|
+
if (!err && fileNames) {
|
144
|
+
sizes = fileNames.filter(canReadAsset).reduce((memo, fileName) => {
|
145
|
+
var contents = import_fs.default.readFileSync(fileName);
|
146
|
+
var key = removeFileNameHash(buildFolder, fileName);
|
147
|
+
memo[key] = [contents.length, import_compiled.gzipSize.sync(contents)];
|
148
|
+
return memo;
|
149
|
+
}, {});
|
150
|
+
}
|
151
|
+
resolve({
|
152
|
+
root: buildFolder,
|
153
|
+
sizes: sizes || {}
|
154
|
+
});
|
155
|
+
});
|
156
|
+
});
|
157
|
+
}
|
158
|
+
// Annotate the CommonJS export names for ESM import in node:
|
159
|
+
0 && (module.exports = {
|
160
|
+
measureFileSizesBeforeBuild,
|
161
|
+
printFileSizesAfterBuild
|
162
|
+
});
|
package/dist/alias.d.ts
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
export type Alias = Record<string, string | string[]>;
|
2
|
+
export type AliasOption = Alias | ((aliases: Alias) => Alias | void);
|
3
|
+
interface NormalizedConfig {
|
4
|
+
source: {
|
5
|
+
alias?: AliasOption | Array<AliasOption>;
|
6
|
+
};
|
7
|
+
}
|
8
|
+
interface IAliasConfig {
|
9
|
+
absoluteBaseUrl: string;
|
10
|
+
paths?: Record<string, string | string[]>;
|
11
|
+
isTsPath?: boolean;
|
12
|
+
isTsProject?: boolean;
|
13
|
+
}
|
14
|
+
export declare const validAlias: <T extends NormalizedConfig>(modernConfig: T, {
|
15
|
+
tsconfigPath
|
16
|
+
}: {
|
17
|
+
tsconfigPath: string;
|
18
|
+
}) => string | null;
|
19
|
+
export declare const mergeAlias: (alias: NormalizedConfig['source']['alias']) => Alias;
|
20
|
+
export declare const getAliasConfig: (aliasOption: NormalizedConfig['source']['alias'], option: {
|
21
|
+
appDirectory: string;
|
22
|
+
tsconfigPath: string;
|
23
|
+
}) => IAliasConfig;
|
24
|
+
export declare const getUserAlias: (alias?: Record<string, string | string[]>) => Record<string, string | string[]>;
|
25
|
+
export {};
|
package/dist/alias.js
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
10
|
+
var __spreadValues = (a, b) => {
|
11
|
+
for (var prop in b || (b = {}))
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
14
|
+
if (__getOwnPropSymbols)
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
16
|
+
if (__propIsEnum.call(b, prop))
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
18
|
+
}
|
19
|
+
return a;
|
20
|
+
};
|
21
|
+
var __export = (target, all) => {
|
22
|
+
for (var name in all)
|
23
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
24
|
+
};
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
27
|
+
for (let key of __getOwnPropNames(from))
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
29
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
30
|
+
}
|
31
|
+
return to;
|
32
|
+
};
|
33
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
34
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
35
|
+
// file that has been converted to a CommonJS file using a Babel-
|
36
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
37
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
38
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
39
|
+
mod
|
40
|
+
));
|
41
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
42
|
+
var alias_exports = {};
|
43
|
+
__export(alias_exports, {
|
44
|
+
getAliasConfig: () => getAliasConfig,
|
45
|
+
getUserAlias: () => getUserAlias,
|
46
|
+
mergeAlias: () => mergeAlias,
|
47
|
+
validAlias: () => validAlias
|
48
|
+
});
|
49
|
+
module.exports = __toCommonJS(alias_exports);
|
50
|
+
var import_fs = __toESM(require("fs"));
|
51
|
+
var import_path = __toESM(require("path"));
|
52
|
+
var import_compiled = require("./compiled");
|
53
|
+
var import_readTsConfig = require("./readTsConfig");
|
54
|
+
var import_applyOptionsChain = require("./applyOptionsChain");
|
55
|
+
const validAlias = (modernConfig, { tsconfigPath }) => {
|
56
|
+
const {
|
57
|
+
source: { alias }
|
58
|
+
} = modernConfig;
|
59
|
+
if (!alias) {
|
60
|
+
return null;
|
61
|
+
}
|
62
|
+
const isTsProject = import_fs.default.existsSync(tsconfigPath);
|
63
|
+
if (!isTsProject) {
|
64
|
+
return null;
|
65
|
+
}
|
66
|
+
const userAlias = getUserAlias(alias);
|
67
|
+
if (Object.keys(userAlias).length > 0) {
|
68
|
+
return import_compiled.chalk.red(
|
69
|
+
'Note: Please use `compilerOptions.paths` in "tsconfig.json" file replace `source.alias` config in "modern.config.js/ts" when project is typescript'
|
70
|
+
);
|
71
|
+
}
|
72
|
+
return null;
|
73
|
+
};
|
74
|
+
const mergeAlias = (alias) => (0, import_applyOptionsChain.applyOptionsChain)({}, alias);
|
75
|
+
const getAliasConfig = (aliasOption, option) => {
|
76
|
+
var _a, _b;
|
77
|
+
const isTsProject = import_fs.default.existsSync(option.tsconfigPath);
|
78
|
+
const alias = mergeAlias(aliasOption);
|
79
|
+
if (!isTsProject) {
|
80
|
+
return {
|
81
|
+
absoluteBaseUrl: option.appDirectory,
|
82
|
+
paths: alias,
|
83
|
+
isTsPath: false,
|
84
|
+
isTsProject
|
85
|
+
};
|
86
|
+
}
|
87
|
+
const tsconfig = (0, import_readTsConfig.readTsConfigByFile)(option.tsconfigPath);
|
88
|
+
const baseUrl = (_a = tsconfig == null ? void 0 : tsconfig.compilerOptions) == null ? void 0 : _a.baseUrl;
|
89
|
+
return {
|
90
|
+
absoluteBaseUrl: baseUrl ? import_path.default.join(option.appDirectory, baseUrl) : option.appDirectory,
|
91
|
+
paths: __spreadValues(__spreadValues({}, alias), (_b = tsconfig == null ? void 0 : tsconfig.compilerOptions) == null ? void 0 : _b.paths),
|
92
|
+
isTsPath: true,
|
93
|
+
isTsProject
|
94
|
+
};
|
95
|
+
};
|
96
|
+
const getUserAlias = (alias = {}) => Object.keys(alias).reduce((o, k) => {
|
97
|
+
if (Array.isArray(alias[k])) {
|
98
|
+
o[k] = alias[k];
|
99
|
+
}
|
100
|
+
return o;
|
101
|
+
}, {});
|
102
|
+
// Annotate the CommonJS export names for ESM import in node:
|
103
|
+
0 && (module.exports = {
|
104
|
+
getAliasConfig,
|
105
|
+
getUserAlias,
|
106
|
+
mergeAlias,
|
107
|
+
validAlias
|
108
|
+
});
|
@@ -0,0 +1,71 @@
|
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
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 __async = (__this, __arguments, generator) => {
|
29
|
+
return new Promise((resolve, reject) => {
|
30
|
+
var fulfilled = (value) => {
|
31
|
+
try {
|
32
|
+
step(generator.next(value));
|
33
|
+
} catch (e) {
|
34
|
+
reject(e);
|
35
|
+
}
|
36
|
+
};
|
37
|
+
var rejected = (value) => {
|
38
|
+
try {
|
39
|
+
step(generator.throw(value));
|
40
|
+
} catch (e) {
|
41
|
+
reject(e);
|
42
|
+
}
|
43
|
+
};
|
44
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
45
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
46
|
+
});
|
47
|
+
};
|
48
|
+
var analyzeProject_exports = {};
|
49
|
+
__export(analyzeProject_exports, {
|
50
|
+
isApiOnly: () => isApiOnly,
|
51
|
+
isWebOnly: () => isWebOnly
|
52
|
+
});
|
53
|
+
module.exports = __toCommonJS(analyzeProject_exports);
|
54
|
+
var path = __toESM(require("path"));
|
55
|
+
var import_commands = require("./commands");
|
56
|
+
var import_compiled = require("./compiled");
|
57
|
+
const isApiOnly = (appDirectory, entryDir) => __async(void 0, null, function* () {
|
58
|
+
const srcDir = path.join(appDirectory, entryDir != null ? entryDir : "src");
|
59
|
+
const existSrc = yield import_compiled.fs.pathExists(srcDir);
|
60
|
+
const options = (0, import_compiled.minimist)((0, import_commands.getArgv)());
|
61
|
+
return !existSrc || Boolean(options["api-only"]);
|
62
|
+
});
|
63
|
+
const isWebOnly = () => __async(void 0, null, function* () {
|
64
|
+
const options = (0, import_compiled.minimist)((0, import_commands.getArgv)());
|
65
|
+
return Boolean(options["web-only"]);
|
66
|
+
});
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
68
|
+
0 && (module.exports = {
|
69
|
+
isApiOnly,
|
70
|
+
isWebOnly
|
71
|
+
});
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import type { Falsy } from './types';
|
2
|
+
export declare function applyOptionsChain<T, U>(defaults: T, options?: T | ((config: T, utils?: U) => T | void) | Array<T | ((config: T, utils?: U) => T | void)> | Falsy, utils?: U, mergeFn?: typeof Object.assign): T;
|
3
|
+
export declare function applyOptionsChain<T, U>(defaults: T, options: T | ((config: T, utils: U) => T | void) | Array<T | ((config: T, utils: U) => T | void)> | Falsy, utils: U, mergeFn?: typeof Object.assign): T;
|
@@ -0,0 +1,58 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5
|
+
var __export = (target, all) => {
|
6
|
+
for (var name in all)
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
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 applyOptionsChain_exports = {};
|
19
|
+
__export(applyOptionsChain_exports, {
|
20
|
+
applyOptionsChain: () => applyOptionsChain
|
21
|
+
});
|
22
|
+
module.exports = __toCommonJS(applyOptionsChain_exports);
|
23
|
+
var import_index = require("./index");
|
24
|
+
function applyOptionsChain(defaults, options, utils, mergeFn = Object.assign) {
|
25
|
+
if (!options) {
|
26
|
+
return defaults;
|
27
|
+
}
|
28
|
+
if ((0, import_index.isPlainObject)(options)) {
|
29
|
+
return mergeFn(defaults, options);
|
30
|
+
} else if ((0, import_index.isFunction)(options)) {
|
31
|
+
const ret = options(defaults, utils);
|
32
|
+
if (ret) {
|
33
|
+
if (!(0, import_index.isPlainObject)(ret)) {
|
34
|
+
import_index.logger.warn(
|
35
|
+
`${options.name}: Function should mutate the config and return nothing, Or return a cloned or merged version of config object.`
|
36
|
+
);
|
37
|
+
}
|
38
|
+
return ret;
|
39
|
+
}
|
40
|
+
} else if (Array.isArray(options)) {
|
41
|
+
return options.reduce(
|
42
|
+
(memo, cur) => applyOptionsChain(memo, cur, utils, mergeFn),
|
43
|
+
defaults
|
44
|
+
);
|
45
|
+
} else {
|
46
|
+
throw new Error(
|
47
|
+
`applyOptionsChain error:
|
48
|
+
default options is: ${JSON.stringify(
|
49
|
+
defaults
|
50
|
+
)}`
|
51
|
+
);
|
52
|
+
}
|
53
|
+
return defaults;
|
54
|
+
}
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
56
|
+
0 && (module.exports = {
|
57
|
+
applyOptionsChain
|
58
|
+
});
|
package/dist/babel.d.ts
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
import { BabelConfig, BabelConfigUtils, BabelTransformOptions } from '@modern-js/types';
|
2
|
+
export declare const getBabelUtils: (config: BabelTransformOptions) => BabelConfigUtils;
|
3
|
+
export declare const applyUserBabelConfig: (defaultOptions: BabelTransformOptions, userBabelConfig?: BabelConfig | BabelConfig[], extraBabelUtils?: Partial<BabelConfigUtils>) => BabelTransformOptions;
|
package/dist/babel.js
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
8
|
+
var __spreadValues = (a, b) => {
|
9
|
+
for (var prop in b || (b = {}))
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
12
|
+
if (__getOwnPropSymbols)
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
14
|
+
if (__propIsEnum.call(b, prop))
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
16
|
+
}
|
17
|
+
return a;
|
18
|
+
};
|
19
|
+
var __export = (target, all) => {
|
20
|
+
for (var name in all)
|
21
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
22
|
+
};
|
23
|
+
var __copyProps = (to, from, except, desc) => {
|
24
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
25
|
+
for (let key of __getOwnPropNames(from))
|
26
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
27
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
28
|
+
}
|
29
|
+
return to;
|
30
|
+
};
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
32
|
+
var babel_exports = {};
|
33
|
+
__export(babel_exports, {
|
34
|
+
applyUserBabelConfig: () => applyUserBabelConfig,
|
35
|
+
getBabelUtils: () => getBabelUtils
|
36
|
+
});
|
37
|
+
module.exports = __toCommonJS(babel_exports);
|
38
|
+
var import_path = require("path");
|
39
|
+
var import_applyOptionsChain = require("./applyOptionsChain");
|
40
|
+
var import_ensureArray = require("./ensureArray");
|
41
|
+
var import_path2 = require("./path");
|
42
|
+
const formatPath = (originPath) => {
|
43
|
+
if ((0, import_path.isAbsolute)(originPath)) {
|
44
|
+
return originPath.split(import_path.sep).join("/");
|
45
|
+
}
|
46
|
+
return originPath;
|
47
|
+
};
|
48
|
+
const getPluginItemName = (item) => {
|
49
|
+
if (typeof item === "string") {
|
50
|
+
return formatPath(item);
|
51
|
+
}
|
52
|
+
if (Array.isArray(item) && typeof item[0] === "string") {
|
53
|
+
return formatPath(item[0]);
|
54
|
+
}
|
55
|
+
return null;
|
56
|
+
};
|
57
|
+
const addPlugins = (plugins, config) => {
|
58
|
+
if (config.plugins) {
|
59
|
+
config.plugins.push(...plugins);
|
60
|
+
} else {
|
61
|
+
config.plugins = plugins;
|
62
|
+
}
|
63
|
+
};
|
64
|
+
const addPresets = (presets, config) => {
|
65
|
+
if (config.presets) {
|
66
|
+
config.presets.push(...presets);
|
67
|
+
} else {
|
68
|
+
config.presets = presets;
|
69
|
+
}
|
70
|
+
};
|
71
|
+
const removePlugins = (plugins, config) => {
|
72
|
+
if (!config.plugins) {
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
const removeList = (0, import_ensureArray.ensureArray)(plugins);
|
76
|
+
config.plugins = config.plugins.filter((item) => {
|
77
|
+
const name = getPluginItemName(item);
|
78
|
+
if (name) {
|
79
|
+
return !removeList.find((removeItem) => name.includes(removeItem));
|
80
|
+
}
|
81
|
+
return true;
|
82
|
+
});
|
83
|
+
};
|
84
|
+
const removePresets = (presets, config) => {
|
85
|
+
if (!config.presets) {
|
86
|
+
return;
|
87
|
+
}
|
88
|
+
const removeList = (0, import_ensureArray.ensureArray)(presets);
|
89
|
+
config.presets = config.presets.filter((item) => {
|
90
|
+
const name = getPluginItemName(item);
|
91
|
+
if (name) {
|
92
|
+
return !removeList.find((removeItem) => name.includes(removeItem));
|
93
|
+
}
|
94
|
+
return true;
|
95
|
+
});
|
96
|
+
};
|
97
|
+
const modifyPresetOptions = (presetName, options, presets = []) => {
|
98
|
+
presets.forEach((preset, index) => {
|
99
|
+
if (Array.isArray(preset)) {
|
100
|
+
if (typeof preset[0] === "string" && (0, import_path2.normalizeToPosixPath)(preset[0]).includes(presetName)) {
|
101
|
+
preset[1] = __spreadValues(__spreadValues({}, preset[1] || {}), options);
|
102
|
+
}
|
103
|
+
} else if (typeof preset === "string" && (0, import_path2.normalizeToPosixPath)(preset).includes(presetName)) {
|
104
|
+
presets[index] = [preset, options];
|
105
|
+
}
|
106
|
+
});
|
107
|
+
};
|
108
|
+
const getBabelUtils = (config) => {
|
109
|
+
const noop = () => {
|
110
|
+
};
|
111
|
+
return {
|
112
|
+
addPlugins: (plugins) => addPlugins(plugins, config),
|
113
|
+
addPresets: (presets) => addPresets(presets, config),
|
114
|
+
removePlugins: (plugins) => removePlugins(plugins, config),
|
115
|
+
removePresets: (presets) => removePresets(presets, config),
|
116
|
+
// `addIncludes` and `addExcludes` are noop functions by default,
|
117
|
+
// It can be overridden by `extraBabelUtils`.
|
118
|
+
addIncludes: noop,
|
119
|
+
addExcludes: noop,
|
120
|
+
// Compat `presetEnvOptions` and `presetReactOptions` in Eden.
|
121
|
+
modifyPresetEnvOptions: (options) => modifyPresetOptions("@babel/preset-env", options, config.presets || []),
|
122
|
+
modifyPresetReactOptions: (options) => modifyPresetOptions("@babel/preset-react", options, config.presets || [])
|
123
|
+
};
|
124
|
+
};
|
125
|
+
const applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils) => {
|
126
|
+
if (userBabelConfig) {
|
127
|
+
const babelUtils = __spreadValues(__spreadValues({}, getBabelUtils(defaultOptions)), extraBabelUtils);
|
128
|
+
return (0, import_applyOptionsChain.applyOptionsChain)(defaultOptions, userBabelConfig || {}, babelUtils);
|
129
|
+
}
|
130
|
+
return defaultOptions;
|
131
|
+
};
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
133
|
+
0 && (module.exports = {
|
134
|
+
applyUserBabelConfig,
|
135
|
+
getBabelUtils
|
136
|
+
});
|