@modern-js/utils 2.4.1-beta.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/dist/FileSizeReporter.d.ts +5 -5
  3. package/dist/FileSizeReporter.js +143 -136
  4. package/dist/alias.d.ts +14 -12
  5. package/dist/alias.js +94 -54
  6. package/dist/analyzeProject.d.ts +1 -1
  7. package/dist/analyzeProject.js +58 -33
  8. package/dist/applyOptionsChain.d.ts +1 -1
  9. package/dist/applyOptionsChain.js +55 -27
  10. package/dist/chainId.d.ts +256 -184
  11. package/dist/chainId.js +132 -187
  12. package/dist/clearConsole.d.ts +1 -1
  13. package/dist/clearConsole.js +29 -7
  14. package/dist/commands.d.ts +1 -1
  15. package/dist/commands.js +33 -10
  16. package/dist/compatRequire.d.ts +3 -3
  17. package/dist/compatRequire.js +74 -38
  18. package/dist/compiled.d.ts +2 -1
  19. package/dist/compiled.js +137 -72
  20. package/dist/constants.d.ts +127 -105
  21. package/dist/constants.js +298 -281
  22. package/dist/debug.d.ts +1 -1
  23. package/dist/debug.js +28 -11
  24. package/dist/emptyDir.d.ts +1 -1
  25. package/dist/emptyDir.js +51 -9
  26. package/dist/ensureAbsolutePath.d.ts +1 -1
  27. package/dist/ensureAbsolutePath.js +33 -14
  28. package/dist/ensureArray.d.ts +1 -1
  29. package/dist/ensureArray.js +30 -8
  30. package/dist/findExists.d.ts +1 -1
  31. package/dist/findExists.js +37 -17
  32. package/dist/format.d.ts +3 -3
  33. package/dist/format.js +93 -81
  34. package/dist/generateMetaTags.d.ts +3 -3
  35. package/dist/generateMetaTags.js +56 -43
  36. package/dist/getBrowserslist.d.ts +1 -1
  37. package/dist/getBrowserslist.js +31 -7
  38. package/dist/getCoreJsVersion.d.ts +1 -1
  39. package/dist/getCoreJsVersion.js +39 -35
  40. package/dist/getEntryOptions.d.ts +1 -1
  41. package/dist/getEntryOptions.js +51 -24
  42. package/dist/getPackageManager.d.ts +1 -1
  43. package/dist/getPackageManager.js +75 -28
  44. package/dist/getPort.d.ts +7 -4
  45. package/dist/getPort.js +104 -58
  46. package/dist/getServerConfig.d.ts +1 -1
  47. package/dist/getServerConfig.js +61 -32
  48. package/dist/import.d.ts +2 -2
  49. package/dist/import.js +31 -8
  50. package/dist/index.d.ts +1 -1
  51. package/dist/index.js +59 -59
  52. package/dist/is/index.d.ts +5 -1
  53. package/dist/is/index.js +81 -94
  54. package/dist/is/node-env.d.ts +1 -1
  55. package/dist/is/node-env.js +39 -17
  56. package/dist/is/platform.d.ts +1 -1
  57. package/dist/is/platform.js +30 -10
  58. package/dist/is/type.d.ts +1 -1
  59. package/dist/is/type.js +48 -22
  60. package/dist/logger.d.ts +48 -48
  61. package/dist/logger.js +127 -95
  62. package/dist/monorepo.d.ts +3 -3
  63. package/dist/monorepo.js +117 -74
  64. package/dist/nodeEnv.d.ts +1 -1
  65. package/dist/nodeEnv.js +72 -25
  66. package/dist/path.d.ts +3 -1
  67. package/dist/path.js +76 -59
  68. package/dist/pathSerializer.d.ts +6 -6
  69. package/dist/pathSerializer.js +65 -43
  70. package/dist/plugin.d.ts +1 -1
  71. package/dist/plugin.js +45 -26
  72. package/dist/prettyInstructions.d.ts +4 -4
  73. package/dist/prettyInstructions.js +107 -65
  74. package/dist/printBuildError.d.ts +1 -1
  75. package/dist/printBuildError.js +54 -40
  76. package/dist/react.d.ts +1 -1
  77. package/dist/react.js +57 -21
  78. package/dist/readTsConfig.d.ts +1 -1
  79. package/dist/readTsConfig.js +38 -12
  80. package/dist/removeSlash.d.ts +1 -1
  81. package/dist/removeSlash.js +33 -9
  82. package/dist/routes.d.ts +1 -1
  83. package/dist/routes.js +49 -22
  84. package/dist/runtimeExports.d.ts +3 -3
  85. package/dist/runtimeExports.js +59 -39
  86. package/dist/ssr.d.ts +2 -1
  87. package/dist/ssr.js +30 -7
  88. package/dist/storage.d.ts +3 -3
  89. package/dist/storage.js +65 -59
  90. package/dist/test-utils.d.ts +1 -1
  91. package/dist/test-utils.js +30 -24
  92. package/dist/tryResolve.d.ts +2 -1
  93. package/dist/tryResolve.js +45 -33
  94. package/dist/types.d.ts +1 -1
  95. package/dist/types.js +15 -2
  96. package/dist/version.d.ts +1 -1
  97. package/dist/version.js +83 -24
  98. package/dist/wait.d.ts +1 -1
  99. package/dist/wait.js +28 -6
  100. package/dist/watch.d.ts +3 -3
  101. package/dist/watch.js +82 -55
  102. package/package.json +7 -8
package/CHANGELOG.md CHANGED
@@ -1,9 +1,15 @@
1
1
  # @modern-js/utils
2
2
 
3
- ## 2.4.1-beta.0
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
- root: string;
10
- sizes: Record<string, number[]>;
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
- root: string;
14
- sizes: Record<string, number[]>;
13
+ root: string;
14
+ sizes: Record<string, number[]>;
15
15
  }>;
16
- export { measureFileSizesBeforeBuild, printFileSizesAfterBuild };
16
+ export { measureFileSizesBeforeBuild, printFileSizesAfterBuild };
@@ -1,151 +1,158 @@
1
- /* eslint-disable eslint-comments/no-unlimited-disable */
2
- /* eslint-disable */
3
- /**
4
- * Copyright (c) 2015-present, Facebook, Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE file at
8
- * https://github.com/facebook/create-react-app/blob/master/LICENSE
9
- */
10
- // Modified by Chao Xu (xuchaobei)
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
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.printFileSizesAfterBuild = exports.measureFileSizesBeforeBuild = void 0;
17
- const fs_1 = __importDefault(require("fs"));
18
- const path_1 = __importDefault(require("path"));
19
- const compiled_1 = require("./compiled");
20
- const logger_1 = require("./logger");
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
- return (/\.(js|css)$/.test(asset) &&
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
- var root = previousSizeMap.root;
29
- var sizes = previousSizeMap.sizes;
30
- var assets = (webpackStats.stats || [webpackStats])
31
- .map((stats) => stats
32
- .toJson({ all: false, assets: true })
33
- .assets.filter((asset) => canReadAsset(asset.name))
34
- .map((asset) => {
35
- var fileContents = fs_1.default.readFileSync(path_1.default.join(root, asset.name));
36
- var size = fileContents.length;
37
- var gzippedSize = compiled_1.gzipSize.sync(fileContents);
38
- var [previousSize, previousGzipSize] = sizes[removeFileNameHash(root, asset.name)] || [];
39
- var sizeDifference = getDifferenceLabel(size, previousSize);
40
- var gzipSizeDifference = getDifferenceLabel(gzippedSize, previousGzipSize);
41
- return {
42
- folder: path_1.default.join(path_1.default.basename(buildFolder), path_1.default.dirname(asset.name)),
43
- name: path_1.default.basename(asset.name),
44
- gzippedSize: gzippedSize,
45
- sizeLabel: (0, compiled_1.filesize)(size) +
46
- (sizeDifference ? ' (' + sizeDifference + ')' : ''),
47
- gzipSizeLabel: (0, compiled_1.filesize)(gzippedSize) +
48
- (gzipSizeDifference ? ' (' + gzipSizeDifference + ')' : ''),
49
- };
50
- }))
51
- .reduce((single, all) => all.concat(single), []);
52
- assets.sort((a, b) => b.size - a.size);
53
- var longestSizeLabelLength = Math.max.apply(null, assets.map((a) => (0, compiled_1.stripAnsi)(a.sizeLabel).length));
54
- var longestFileNameLength = Math.max.apply(null, assets.map((a) => (0, compiled_1.stripAnsi)(a.folder + path_1.default.sep + a.name).length));
55
- printFileSizesHeader(longestFileNameLength, longestSizeLabelLength);
56
- var suggestBundleSplitting = false;
57
- assets.forEach((asset) => {
58
- var { folder, name, sizeLabel, gzipSizeLabel, gzippedSize } = asset;
59
- var fileNameLength = (0, compiled_1.stripAnsi)(folder + path_1.default.sep + name).length;
60
- var sizeLength = (0, compiled_1.stripAnsi)(sizeLabel).length;
61
- if (sizeLength < longestSizeLabelLength) {
62
- var rightPadding = ' '.repeat(longestSizeLabelLength - sizeLength);
63
- sizeLabel += rightPadding;
64
- }
65
- var fileNameLabel = compiled_1.chalk.dim(asset.folder + path_1.default.sep) + compiled_1.chalk.cyan(asset.name);
66
- if (fileNameLength < longestFileNameLength) {
67
- var rightPadding = ' '.repeat(longestFileNameLength - fileNameLength);
68
- fileNameLabel += rightPadding;
69
- }
70
- var isMainBundle = asset.name.indexOf('main.') === 0;
71
- var maxRecommendedSize = isMainBundle
72
- ? maxBundleGzipSize
73
- : maxChunkGzipSize;
74
- var isLarge = maxRecommendedSize && gzippedSize > maxRecommendedSize;
75
- if (isLarge && path_1.default.extname(asset.name) === '.js') {
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
- const longestLengths = [longestFileNameLength, longestSizeLabelLength];
93
- const headerRow = ['File', 'Size', 'Gzipped'].reduce((prev, cur, index) => {
94
- const length = longestLengths[index];
95
- let curLabel = cur;
96
- if (length) {
97
- curLabel =
98
- cur.length < length ? cur + ' '.repeat(length - cur.length) : cur;
99
- }
100
- return prev + curLabel + ' ';
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
- return fileName
106
- .replace(buildFolder, '')
107
- .replace(/\\/g, '/')
108
- .replace(/\/?(.*)(\.[0-9a-f]+)(\.chunk)?(\.js|\.css)/, (match, p1, p2, p3, p4) => p1 + p4);
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
- var FIFTY_KILOBYTES = 1024 * 50;
114
- var difference = currentSize - previousSize;
115
- var fileSize = !Number.isNaN(difference) ? (0, compiled_1.filesize)(difference) : 0;
116
- if (difference >= FIFTY_KILOBYTES) {
117
- return compiled_1.chalk.red('+' + fileSize);
118
- }
119
- else if (difference < FIFTY_KILOBYTES && difference > 0) {
120
- return compiled_1.chalk.yellow('+' + fileSize);
121
- }
122
- else if (difference < 0) {
123
- return compiled_1.chalk.green(fileSize);
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
- return new Promise(resolve => {
131
- (0, compiled_1.recursiveReaddir)(buildFolder, (err, fileNames) => {
132
- var sizes;
133
- if (!err && fileNames) {
134
- sizes = fileNames
135
- .filter(canReadAsset)
136
- .reduce((memo, fileName) => {
137
- var contents = fs_1.default.readFileSync(fileName);
138
- var key = removeFileNameHash(buildFolder, fileName);
139
- // save both the original size and gzip size
140
- memo[key] = [contents.length, compiled_1.gzipSize.sync(contents)];
141
- return memo;
142
- }, {});
143
- }
144
- resolve({
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
- exports.measureFileSizesBeforeBuild = measureFileSizesBeforeBuild;
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
1
  export type Alias = Record<string, string | string[]>;
2
2
  export type AliasOption = Alias | ((aliases: Alias) => Alias | void);
3
3
  interface NormalizedConfig {
4
- source: {
5
- alias?: AliasOption | Array<AliasOption>;
6
- };
4
+ source: {
5
+ alias?: AliasOption | Array<AliasOption>;
6
+ };
7
7
  }
8
8
  interface IAliasConfig {
9
- absoluteBaseUrl: string;
10
- paths?: Record<string, string | string[]>;
11
- isTsPath?: boolean;
12
- isTsProject?: boolean;
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, { tsconfigPath }: {
15
- tsconfigPath: string;
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
- appDirectory: string;
20
- tsconfigPath: string;
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
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getUserAlias = exports.getAliasConfig = exports.mergeAlias = exports.validAlias = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const compiled_1 = require("./compiled");
10
- const readTsConfig_1 = require("./readTsConfig");
11
- const applyOptionsChain_1 = require("./applyOptionsChain");
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
- const { source: { alias }, } = modernConfig;
14
- if (!alias) {
15
- return null;
16
- }
17
- const isTsProject = fs_1.default.existsSync(tsconfigPath);
18
- if (!isTsProject) {
19
- return null;
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
- exports.validAlias = validAlias;
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
- var _a, _b;
32
- const isTsProject = fs_1.default.existsSync(option.tsconfigPath);
33
- const alias = (0, exports.mergeAlias)(aliasOption);
34
- if (!isTsProject) {
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
- absoluteBaseUrl: baseUrl
46
- ? path_1.default.join(option.appDirectory, baseUrl)
47
- : option.appDirectory,
48
- paths: {
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
- if (Array.isArray(alias[k])) {
60
- o[k] = alias[k];
61
- }
62
- return o;
93
+ if (Array.isArray(alias[k])) {
94
+ o[k] = alias[k];
95
+ }
96
+ return o;
63
97
  }, {});
64
- exports.getUserAlias = getUserAlias;
98
+ // Annotate the CommonJS export names for ESM import in node:
99
+ 0 && (module.exports = {
100
+ getAliasConfig,
101
+ getUserAlias,
102
+ mergeAlias,
103
+ validAlias
104
+ });
@@ -1 +1 @@
1
- export declare const isApiOnly: (appDirectory: string, entryDir?: string) => Promise<boolean>;
1
+ export declare const isApiOnly: (appDirectory: string, entryDir?: string) => Promise<boolean>;
@@ -1,35 +1,60 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
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
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isApiOnly = void 0;
27
- const path = __importStar(require("path"));
28
- const compiled_1 = require("./compiled");
29
- const isApiOnly = async (appDirectory, entryDir) => {
30
- const srcDir = path.join(appDirectory, entryDir !== null && entryDir !== void 0 ? entryDir : 'src');
31
- const existSrc = await compiled_1.fs.pathExists(srcDir);
32
- const options = (0, compiled_1.minimist)(process.argv.slice(2));
33
- return !existSrc || Boolean(options['api-only']);
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
- exports.isApiOnly = isApiOnly;
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;