@modern-js/utils 2.4.1-beta.0 → 2.5.0-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +7 -1
- package/dist/FileSizeReporter.d.ts +5 -5
- package/dist/FileSizeReporter.js +143 -136
- package/dist/alias.d.ts +16 -14
- package/dist/alias.js +94 -54
- package/dist/analyzeProject.d.ts +1 -1
- package/dist/analyzeProject.js +58 -33
- package/dist/applyOptionsChain.d.ts +1 -1
- package/dist/applyOptionsChain.js +55 -27
- package/dist/chainId.d.ts +256 -184
- package/dist/chainId.js +132 -187
- package/dist/clearConsole.d.ts +1 -1
- package/dist/clearConsole.js +29 -7
- package/dist/commands.d.ts +1 -1
- package/dist/commands.js +33 -10
- package/dist/compatRequire.d.ts +3 -3
- package/dist/compatRequire.js +74 -38
- package/dist/compiled.d.ts +2 -1
- package/dist/compiled.js +137 -72
- package/dist/constants.d.ts +127 -105
- package/dist/constants.js +298 -281
- package/dist/debug.d.ts +1 -1
- package/dist/debug.js +28 -11
- package/dist/emptyDir.d.ts +1 -1
- package/dist/emptyDir.js +51 -9
- package/dist/ensureAbsolutePath.d.ts +1 -1
- package/dist/ensureAbsolutePath.js +33 -14
- package/dist/ensureArray.d.ts +1 -1
- package/dist/ensureArray.js +30 -8
- package/dist/findExists.d.ts +1 -1
- package/dist/findExists.js +37 -17
- package/dist/format.d.ts +3 -3
- package/dist/format.js +93 -81
- package/dist/generateMetaTags.d.ts +4 -4
- package/dist/generateMetaTags.js +56 -43
- package/dist/getBrowserslist.d.ts +1 -1
- package/dist/getBrowserslist.js +31 -7
- package/dist/getCoreJsVersion.d.ts +1 -1
- package/dist/getCoreJsVersion.js +39 -35
- package/dist/getEntryOptions.d.ts +1 -1
- package/dist/getEntryOptions.js +51 -24
- package/dist/getPackageManager.d.ts +1 -1
- package/dist/getPackageManager.js +75 -28
- package/dist/getPort.d.ts +7 -4
- package/dist/getPort.js +104 -58
- package/dist/getServerConfig.d.ts +1 -1
- package/dist/getServerConfig.js +61 -32
- package/dist/import.d.ts +2 -2
- package/dist/import.js +31 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +61 -59
- package/dist/is/index.d.ts +5 -1
- package/dist/is/index.js +81 -94
- package/dist/is/node-env.d.ts +1 -1
- package/dist/is/node-env.js +39 -17
- package/dist/is/platform.d.ts +1 -1
- package/dist/is/platform.js +30 -10
- package/dist/is/type.d.ts +1 -1
- package/dist/is/type.js +48 -22
- package/dist/logger.d.ts +51 -51
- package/dist/logger.js +127 -95
- package/dist/monorepo.d.ts +3 -3
- package/dist/monorepo.js +117 -74
- package/dist/nestedRoutes.d.ts +9 -0
- package/dist/nestedRoutes.js +144 -0
- package/dist/nodeEnv.d.ts +1 -1
- package/dist/nodeEnv.js +72 -25
- package/dist/path.d.ts +3 -1
- package/dist/path.js +76 -59
- package/dist/pathSerializer.d.ts +7 -7
- package/dist/pathSerializer.js +65 -43
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +45 -26
- package/dist/prettyInstructions.d.ts +4 -4
- package/dist/prettyInstructions.js +107 -65
- package/dist/printBuildError.d.ts +1 -1
- package/dist/printBuildError.js +54 -40
- package/dist/react.d.ts +1 -1
- package/dist/react.js +57 -21
- package/dist/readTsConfig.d.ts +1 -1
- package/dist/readTsConfig.js +38 -12
- package/dist/remix-router.d.ts +1 -0
- package/dist/remix-router.js +17 -0
- package/dist/removeSlash.d.ts +1 -1
- package/dist/removeSlash.js +33 -9
- package/dist/routes.d.ts +1 -1
- package/dist/routes.js +49 -22
- package/dist/runtimeExports.d.ts +3 -3
- package/dist/runtimeExports.js +59 -39
- package/dist/serialize.d.ts +1 -0
- package/dist/serialize.js +36 -0
- package/dist/ssr.d.ts +2 -1
- package/dist/ssr.js +30 -7
- package/dist/storage.d.ts +3 -3
- package/dist/storage.js +65 -59
- package/dist/test-utils.d.ts +1 -1
- package/dist/test-utils.js +30 -24
- package/dist/tryResolve.d.ts +2 -1
- package/dist/tryResolve.js +45 -33
- package/dist/types.d.ts +1 -1
- package/dist/types.js +15 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +83 -24
- package/dist/wait.d.ts +1 -1
- package/dist/wait.js +28 -6
- package/dist/watch.d.ts +5 -5
- package/dist/watch.js +82 -55
- package/package.json +31 -9
package/CHANGELOG.md
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
# @modern-js/utils
|
2
2
|
|
3
|
-
## 2.
|
3
|
+
## 2.5.0
|
4
4
|
|
5
5
|
### Patch Changes
|
6
6
|
|
7
|
+
- 30614fa: chore: modify package.json entry fields and build config
|
8
|
+
chore: 更改 package.json entry 字段以及构建配置
|
9
|
+
- 1b0ce87: chore: bump caniuse-lite to latest version
|
10
|
+
|
11
|
+
chore: 升级 caniuse-lite 到最新版
|
12
|
+
|
7
13
|
- 11c053b: feat: ssr support deploy worker
|
8
14
|
|
9
15
|
feat: ssr 支持边缘部署
|
@@ -6,11 +6,11 @@
|
|
6
6
|
* https://github.com/facebook/create-react-app/blob/master/LICENSE
|
7
7
|
*/
|
8
8
|
declare function printFileSizesAfterBuild(webpackStats: any, previousSizeMap: {
|
9
|
-
|
10
|
-
|
9
|
+
root: string;
|
10
|
+
sizes: Record<string, number[]>;
|
11
11
|
}, buildFolder: string, maxBundleGzipSize: number, maxChunkGzipSize: number): void;
|
12
12
|
declare function measureFileSizesBeforeBuild(buildFolder: string): Promise<{
|
13
|
-
|
14
|
-
|
13
|
+
root: string;
|
14
|
+
sizes: Record<string, number[]>;
|
15
15
|
}>;
|
16
|
-
export { measureFileSizesBeforeBuild, printFileSizesAfterBuild };
|
16
|
+
export { measureFileSizesBeforeBuild, printFileSizesAfterBuild };
|
package/dist/FileSizeReporter.js
CHANGED
@@ -1,151 +1,158 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
'use strict';
|
12
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
13
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
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 });
|
14
11
|
};
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
22
|
+
mod
|
23
|
+
));
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
25
|
+
var FileSizeReporter_exports = {};
|
26
|
+
__export(FileSizeReporter_exports, {
|
27
|
+
measureFileSizesBeforeBuild: () => measureFileSizesBeforeBuild,
|
28
|
+
printFileSizesAfterBuild: () => printFileSizesAfterBuild
|
29
|
+
});
|
30
|
+
module.exports = __toCommonJS(FileSizeReporter_exports);
|
31
|
+
var import_fs = __toESM(require("fs"));
|
32
|
+
var import_path = __toESM(require("path"));
|
33
|
+
var import_compiled = require("./compiled");
|
34
|
+
var import_logger = require("./logger");
|
21
35
|
function canReadAsset(asset) {
|
22
|
-
|
23
|
-
!/service-worker\.js/.test(asset) &&
|
24
|
-
!/precache-manifest\.[0-9a-f]+\.js/.test(asset));
|
36
|
+
return /\.(js|css)$/.test(asset) && !/service-worker\.js/.test(asset) && !/precache-manifest\.[0-9a-f]+\.js/.test(asset);
|
25
37
|
}
|
26
|
-
// Prints a detailed summary of build files.
|
27
38
|
function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, maxBundleGzipSize, maxChunkGzipSize) {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
suggestBundleSplitting = true;
|
77
|
-
}
|
78
|
-
logger_1.logger.log(' ' +
|
79
|
-
fileNameLabel +
|
80
|
-
' ' +
|
81
|
-
sizeLabel +
|
82
|
-
' ' +
|
83
|
-
(isLarge ? compiled_1.chalk.yellow(gzipSizeLabel) : gzipSizeLabel));
|
84
|
-
});
|
85
|
-
if (suggestBundleSplitting) {
|
86
|
-
logger_1.logger.log();
|
87
|
-
logger_1.logger.warn('The bundle size is significantly larger than recommended.');
|
39
|
+
var root = previousSizeMap.root;
|
40
|
+
var sizes = previousSizeMap.sizes;
|
41
|
+
var assets = (webpackStats.stats || [webpackStats]).map(
|
42
|
+
(stats) => stats.toJson({ all: false, assets: true }).assets.filter((asset) => canReadAsset(asset.name)).map((asset) => {
|
43
|
+
var fileContents = import_fs.default.readFileSync(import_path.default.join(root, asset.name));
|
44
|
+
var size = fileContents.length;
|
45
|
+
var gzippedSize = import_compiled.gzipSize.sync(fileContents);
|
46
|
+
var [previousSize, previousGzipSize] = sizes[removeFileNameHash(root, asset.name)] || [];
|
47
|
+
var sizeDifference = getDifferenceLabel(size, previousSize);
|
48
|
+
var gzipSizeDifference = getDifferenceLabel(
|
49
|
+
gzippedSize,
|
50
|
+
previousGzipSize
|
51
|
+
);
|
52
|
+
return {
|
53
|
+
folder: import_path.default.join(
|
54
|
+
import_path.default.basename(buildFolder),
|
55
|
+
import_path.default.dirname(asset.name)
|
56
|
+
),
|
57
|
+
name: import_path.default.basename(asset.name),
|
58
|
+
gzippedSize,
|
59
|
+
sizeLabel: (0, import_compiled.filesize)(size) + (sizeDifference ? " (" + sizeDifference + ")" : ""),
|
60
|
+
gzipSizeLabel: (0, import_compiled.filesize)(gzippedSize) + (gzipSizeDifference ? " (" + gzipSizeDifference + ")" : "")
|
61
|
+
};
|
62
|
+
})
|
63
|
+
).reduce((single, all) => all.concat(single), []);
|
64
|
+
assets.sort((a, b) => b.size - a.size);
|
65
|
+
var longestSizeLabelLength = Math.max.apply(
|
66
|
+
null,
|
67
|
+
assets.map((a) => (0, import_compiled.stripAnsi)(a.sizeLabel).length)
|
68
|
+
);
|
69
|
+
var longestFileNameLength = Math.max.apply(
|
70
|
+
null,
|
71
|
+
assets.map((a) => (0, import_compiled.stripAnsi)(a.folder + import_path.default.sep + a.name).length)
|
72
|
+
);
|
73
|
+
printFileSizesHeader(longestFileNameLength, longestSizeLabelLength);
|
74
|
+
var suggestBundleSplitting = false;
|
75
|
+
assets.forEach((asset) => {
|
76
|
+
var { folder, name, sizeLabel, gzipSizeLabel, gzippedSize } = asset;
|
77
|
+
var fileNameLength = (0, import_compiled.stripAnsi)(folder + import_path.default.sep + name).length;
|
78
|
+
var sizeLength = (0, import_compiled.stripAnsi)(sizeLabel).length;
|
79
|
+
if (sizeLength < longestSizeLabelLength) {
|
80
|
+
var rightPadding = " ".repeat(longestSizeLabelLength - sizeLength);
|
81
|
+
sizeLabel += rightPadding;
|
82
|
+
}
|
83
|
+
var fileNameLabel = import_compiled.chalk.dim(asset.folder + import_path.default.sep) + import_compiled.chalk.cyan(asset.name);
|
84
|
+
if (fileNameLength < longestFileNameLength) {
|
85
|
+
var rightPadding = " ".repeat(longestFileNameLength - fileNameLength);
|
86
|
+
fileNameLabel += rightPadding;
|
88
87
|
}
|
88
|
+
var isMainBundle = asset.name.indexOf("main.") === 0;
|
89
|
+
var maxRecommendedSize = isMainBundle ? maxBundleGzipSize : maxChunkGzipSize;
|
90
|
+
var isLarge = maxRecommendedSize && gzippedSize > maxRecommendedSize;
|
91
|
+
if (isLarge && import_path.default.extname(asset.name) === ".js") {
|
92
|
+
suggestBundleSplitting = true;
|
93
|
+
}
|
94
|
+
import_logger.logger.log(
|
95
|
+
" " + fileNameLabel + " " + sizeLabel + " " + (isLarge ? import_compiled.chalk.yellow(gzipSizeLabel) : gzipSizeLabel)
|
96
|
+
);
|
97
|
+
});
|
98
|
+
if (suggestBundleSplitting) {
|
99
|
+
import_logger.logger.log();
|
100
|
+
import_logger.logger.warn("The bundle size is significantly larger than recommended.");
|
101
|
+
}
|
89
102
|
}
|
90
|
-
exports.printFileSizesAfterBuild = printFileSizesAfterBuild;
|
91
103
|
function printFileSizesHeader(longestFileNameLength, longestSizeLabelLength) {
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
logger_1.logger.log(compiled_1.chalk.bold(compiled_1.chalk.blue(headerRow)));
|
104
|
+
const longestLengths = [longestFileNameLength, longestSizeLabelLength];
|
105
|
+
const headerRow = ["File", "Size", "Gzipped"].reduce((prev, cur, index) => {
|
106
|
+
const length = longestLengths[index];
|
107
|
+
let curLabel = cur;
|
108
|
+
if (length) {
|
109
|
+
curLabel = cur.length < length ? cur + " ".repeat(length - cur.length) : cur;
|
110
|
+
}
|
111
|
+
return prev + curLabel + " ";
|
112
|
+
}, " ");
|
113
|
+
import_logger.logger.log(import_compiled.chalk.bold(import_compiled.chalk.blue(headerRow)));
|
103
114
|
}
|
104
115
|
function removeFileNameHash(buildFolder, fileName) {
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
116
|
+
return fileName.replace(buildFolder, "").replace(/\\/g, "/").replace(
|
117
|
+
/\/?(.*)(\.[0-9a-f]+)(\.chunk)?(\.js|\.css)/,
|
118
|
+
(match, p1, p2, p3, p4) => p1 + p4
|
119
|
+
);
|
109
120
|
}
|
110
|
-
// Input: 1024, 2048
|
111
|
-
// Output: "(+1 KB)"
|
112
121
|
function getDifferenceLabel(currentSize, previousSize) {
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
else {
|
126
|
-
return '';
|
127
|
-
}
|
122
|
+
var FIFTY_KILOBYTES = 1024 * 50;
|
123
|
+
var difference = currentSize - previousSize;
|
124
|
+
var fileSize = !Number.isNaN(difference) ? (0, import_compiled.filesize)(difference) : 0;
|
125
|
+
if (difference >= FIFTY_KILOBYTES) {
|
126
|
+
return import_compiled.chalk.red("+" + fileSize);
|
127
|
+
} else if (difference < FIFTY_KILOBYTES && difference > 0) {
|
128
|
+
return import_compiled.chalk.yellow("+" + fileSize);
|
129
|
+
} else if (difference < 0) {
|
130
|
+
return import_compiled.chalk.green(fileSize);
|
131
|
+
} else {
|
132
|
+
return "";
|
133
|
+
}
|
128
134
|
}
|
129
135
|
function measureFileSizesBeforeBuild(buildFolder) {
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
root: buildFolder,
|
146
|
-
sizes: sizes || {},
|
147
|
-
});
|
148
|
-
});
|
136
|
+
return new Promise((resolve) => {
|
137
|
+
(0, import_compiled.recursiveReaddir)(buildFolder, (err, fileNames) => {
|
138
|
+
var sizes;
|
139
|
+
if (!err && fileNames) {
|
140
|
+
sizes = fileNames.filter(canReadAsset).reduce((memo, fileName) => {
|
141
|
+
var contents = import_fs.default.readFileSync(fileName);
|
142
|
+
var key = removeFileNameHash(buildFolder, fileName);
|
143
|
+
memo[key] = [contents.length, import_compiled.gzipSize.sync(contents)];
|
144
|
+
return memo;
|
145
|
+
}, {});
|
146
|
+
}
|
147
|
+
resolve({
|
148
|
+
root: buildFolder,
|
149
|
+
sizes: sizes || {}
|
150
|
+
});
|
149
151
|
});
|
152
|
+
});
|
150
153
|
}
|
151
|
-
|
154
|
+
// Annotate the CommonJS export names for ESM import in node:
|
155
|
+
0 && (module.exports = {
|
156
|
+
measureFileSizesBeforeBuild,
|
157
|
+
printFileSizesAfterBuild
|
158
|
+
});
|
package/dist/alias.d.ts
CHANGED
@@ -1,23 +1,25 @@
|
|
1
|
-
export type Alias = Record<string, string | string[]>;
|
2
|
-
export type AliasOption = Alias | ((aliases: Alias) => Alias | void);
|
1
|
+
export declare type Alias = Record<string, string | string[]>;
|
2
|
+
export declare type AliasOption = Alias | ((aliases: Alias) => Alias | void);
|
3
3
|
interface NormalizedConfig {
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
source: {
|
5
|
+
alias?: AliasOption | Array<AliasOption>;
|
6
|
+
};
|
7
7
|
}
|
8
8
|
interface IAliasConfig {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
absoluteBaseUrl: string;
|
10
|
+
paths?: Record<string, string | string[]>;
|
11
|
+
isTsPath?: boolean;
|
12
|
+
isTsProject?: boolean;
|
13
13
|
}
|
14
|
-
export declare const validAlias: <T extends NormalizedConfig>(modernConfig: T, {
|
15
|
-
|
14
|
+
export declare const validAlias: <T extends NormalizedConfig>(modernConfig: T, {
|
15
|
+
tsconfigPath
|
16
|
+
}: {
|
17
|
+
tsconfigPath: string;
|
16
18
|
}) => string | null;
|
17
19
|
export declare const mergeAlias: (alias: NormalizedConfig['source']['alias']) => Alias;
|
18
20
|
export declare const getAliasConfig: (aliasOption: NormalizedConfig['source']['alias'], option: {
|
19
|
-
|
20
|
-
|
21
|
+
appDirectory: string;
|
22
|
+
tsconfigPath: string;
|
21
23
|
}) => IAliasConfig;
|
22
24
|
export declare const getUserAlias: (alias?: Record<string, string | string[]>) => Record<string, string | string[]>;
|
23
|
-
export {};
|
25
|
+
export {};
|
package/dist/alias.js
CHANGED
@@ -1,64 +1,104 @@
|
|
1
|
-
|
2
|
-
var
|
3
|
-
|
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;
|
4
32
|
};
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
33
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
35
|
+
mod
|
36
|
+
));
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
38
|
+
var alias_exports = {};
|
39
|
+
__export(alias_exports, {
|
40
|
+
getAliasConfig: () => getAliasConfig,
|
41
|
+
getUserAlias: () => getUserAlias,
|
42
|
+
mergeAlias: () => mergeAlias,
|
43
|
+
validAlias: () => validAlias
|
44
|
+
});
|
45
|
+
module.exports = __toCommonJS(alias_exports);
|
46
|
+
var import_fs = __toESM(require("fs"));
|
47
|
+
var import_path = __toESM(require("path"));
|
48
|
+
var import_compiled = require("./compiled");
|
49
|
+
var import_readTsConfig = require("./readTsConfig");
|
50
|
+
var import_applyOptionsChain = require("./applyOptionsChain");
|
12
51
|
const validAlias = (modernConfig, { tsconfigPath }) => {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
const userAlias = (0, exports.getUserAlias)(alias);
|
22
|
-
if (Object.keys(userAlias).length > 0) {
|
23
|
-
return compiled_1.chalk.red('Note: Please use `compilerOptions.paths` in "tsconfig.json" file replace `source.alias` config in "modern.config.js/ts" when project is typescript');
|
24
|
-
}
|
52
|
+
const {
|
53
|
+
source: { alias }
|
54
|
+
} = modernConfig;
|
55
|
+
if (!alias) {
|
56
|
+
return null;
|
57
|
+
}
|
58
|
+
const isTsProject = import_fs.default.existsSync(tsconfigPath);
|
59
|
+
if (!isTsProject) {
|
25
60
|
return null;
|
61
|
+
}
|
62
|
+
const userAlias = getUserAlias(alias);
|
63
|
+
if (Object.keys(userAlias).length > 0) {
|
64
|
+
return import_compiled.chalk.red(
|
65
|
+
'Note: Please use `compilerOptions.paths` in "tsconfig.json" file replace `source.alias` config in "modern.config.js/ts" when project is typescript'
|
66
|
+
);
|
67
|
+
}
|
68
|
+
return null;
|
26
69
|
};
|
27
|
-
|
28
|
-
const mergeAlias = (alias) => (0, applyOptionsChain_1.applyOptionsChain)({}, alias);
|
29
|
-
exports.mergeAlias = mergeAlias;
|
70
|
+
const mergeAlias = (alias) => (0, import_applyOptionsChain.applyOptionsChain)({}, alias);
|
30
71
|
const getAliasConfig = (aliasOption, option) => {
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
return {
|
36
|
-
absoluteBaseUrl: option.appDirectory,
|
37
|
-
paths: alias,
|
38
|
-
isTsPath: false,
|
39
|
-
isTsProject,
|
40
|
-
};
|
41
|
-
}
|
42
|
-
const tsconfig = (0, readTsConfig_1.readTsConfigByFile)(option.tsconfigPath);
|
43
|
-
const baseUrl = (_a = tsconfig === null || tsconfig === void 0 ? void 0 : tsconfig.compilerOptions) === null || _a === void 0 ? void 0 : _a.baseUrl;
|
72
|
+
var _a, _b;
|
73
|
+
const isTsProject = import_fs.default.existsSync(option.tsconfigPath);
|
74
|
+
const alias = mergeAlias(aliasOption);
|
75
|
+
if (!isTsProject) {
|
44
76
|
return {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
...alias,
|
50
|
-
...(_b = tsconfig === null || tsconfig === void 0 ? void 0 : tsconfig.compilerOptions) === null || _b === void 0 ? void 0 : _b.paths,
|
51
|
-
},
|
52
|
-
isTsPath: true,
|
53
|
-
isTsProject,
|
77
|
+
absoluteBaseUrl: option.appDirectory,
|
78
|
+
paths: alias,
|
79
|
+
isTsPath: false,
|
80
|
+
isTsProject
|
54
81
|
};
|
82
|
+
}
|
83
|
+
const tsconfig = (0, import_readTsConfig.readTsConfigByFile)(option.tsconfigPath);
|
84
|
+
const baseUrl = (_a = tsconfig == null ? void 0 : tsconfig.compilerOptions) == null ? void 0 : _a.baseUrl;
|
85
|
+
return {
|
86
|
+
absoluteBaseUrl: baseUrl ? import_path.default.join(option.appDirectory, baseUrl) : option.appDirectory,
|
87
|
+
paths: __spreadValues(__spreadValues({}, alias), (_b = tsconfig == null ? void 0 : tsconfig.compilerOptions) == null ? void 0 : _b.paths),
|
88
|
+
isTsPath: true,
|
89
|
+
isTsProject
|
90
|
+
};
|
55
91
|
};
|
56
|
-
exports.getAliasConfig = getAliasConfig;
|
57
|
-
// filter invalid ts paths that are not array
|
58
92
|
const getUserAlias = (alias = {}) => Object.keys(alias).reduce((o, k) => {
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
93
|
+
if (Array.isArray(alias[k])) {
|
94
|
+
o[k] = alias[k];
|
95
|
+
}
|
96
|
+
return o;
|
63
97
|
}, {});
|
64
|
-
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
99
|
+
0 && (module.exports = {
|
100
|
+
getAliasConfig,
|
101
|
+
getUserAlias,
|
102
|
+
mergeAlias,
|
103
|
+
validAlias
|
104
|
+
});
|
package/dist/analyzeProject.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export declare const isApiOnly: (appDirectory: string, entryDir?: string) => Promise<boolean>;
|
1
|
+
export declare const isApiOnly: (appDirectory: string, entryDir?: string) => Promise<boolean>;
|
package/dist/analyzeProject.js
CHANGED
@@ -1,35 +1,60 @@
|
|
1
|
-
|
2
|
-
var
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
-
if (mod && mod.__esModule) return mod;
|
20
|
-
var result = {};
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
-
__setModuleDefault(result, mod);
|
23
|
-
return result;
|
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;
|
24
18
|
};
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
21
|
+
mod
|
22
|
+
));
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
24
|
+
var __async = (__this, __arguments, generator) => {
|
25
|
+
return new Promise((resolve, reject) => {
|
26
|
+
var fulfilled = (value) => {
|
27
|
+
try {
|
28
|
+
step(generator.next(value));
|
29
|
+
} catch (e) {
|
30
|
+
reject(e);
|
31
|
+
}
|
32
|
+
};
|
33
|
+
var rejected = (value) => {
|
34
|
+
try {
|
35
|
+
step(generator.throw(value));
|
36
|
+
} catch (e) {
|
37
|
+
reject(e);
|
38
|
+
}
|
39
|
+
};
|
40
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
41
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
42
|
+
});
|
34
43
|
};
|
35
|
-
|
44
|
+
var analyzeProject_exports = {};
|
45
|
+
__export(analyzeProject_exports, {
|
46
|
+
isApiOnly: () => isApiOnly
|
47
|
+
});
|
48
|
+
module.exports = __toCommonJS(analyzeProject_exports);
|
49
|
+
var path = __toESM(require("path"));
|
50
|
+
var import_compiled = require("./compiled");
|
51
|
+
const isApiOnly = (appDirectory, entryDir) => __async(void 0, null, function* () {
|
52
|
+
const srcDir = path.join(appDirectory, entryDir != null ? entryDir : "src");
|
53
|
+
const existSrc = yield import_compiled.fs.pathExists(srcDir);
|
54
|
+
const options = (0, import_compiled.minimist)(process.argv.slice(2));
|
55
|
+
return !existSrc || Boolean(options["api-only"]);
|
56
|
+
});
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
58
|
+
0 && (module.exports = {
|
59
|
+
isApiOnly
|
60
|
+
});
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import type { Falsy } from './types';
|
2
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;
|
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;
|