@modern-js/utils 2.22.1-alpha.3 → 2.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/cjs/cli/constants/index.js +0 -215
  3. package/dist/cjs/cli/index.js +0 -1
  4. package/dist/cjs/cli/is/project.js +7 -4
  5. package/dist/cjs/cli/logger.js +0 -5
  6. package/dist/cjs/cli/prettyInstructions.js +3 -2
  7. package/dist/cjs/runtime/nestedRoutes.js +3 -1
  8. package/dist/esm/cli/constants/index.js +0 -212
  9. package/dist/esm/cli/index.js +0 -1
  10. package/dist/esm/cli/is/project.js +7 -4
  11. package/dist/esm/cli/logger.js +0 -5
  12. package/dist/esm/cli/prettyInstructions.js +3 -2
  13. package/dist/esm/runtime/nestedRoutes.js +3 -1
  14. package/dist/types/cli/constants/index.d.ts +0 -121
  15. package/dist/types/cli/index.d.ts +0 -1
  16. package/dist/types/cli/is/project.d.ts +11 -1
  17. package/dist/types/runtime/nestedRoutes.d.ts +6 -2
  18. package/package.json +6 -11
  19. package/dist/FileSizeReporter.d.ts +0 -16
  20. package/dist/FileSizeReporter.js +0 -162
  21. package/dist/alias.d.ts +0 -25
  22. package/dist/alias.js +0 -108
  23. package/dist/analyzeProject.d.ts +0 -2
  24. package/dist/analyzeProject.js +0 -71
  25. package/dist/applyOptionsChain.d.ts +0 -3
  26. package/dist/applyOptionsChain.js +0 -58
  27. package/dist/babel.d.ts +0 -3
  28. package/dist/babel.js +0 -136
  29. package/dist/chainId.d.ts +0 -244
  30. package/dist/chainId.js +0 -196
  31. package/dist/cjs/cli/test.js +0 -19
  32. package/dist/clearConsole.d.ts +0 -1
  33. package/dist/clearConsole.js +0 -31
  34. package/dist/commands.d.ts +0 -4
  35. package/dist/commands.js +0 -48
  36. package/dist/compatRequire.d.ts +0 -13
  37. package/dist/compatRequire.js +0 -82
  38. package/dist/compiled.d.ts +0 -43
  39. package/dist/compiled.js +0 -142
  40. package/dist/constants.d.ts +0 -244
  41. package/dist/constants.js +0 -320
  42. package/dist/debug.d.ts +0 -6
  43. package/dist/debug.js +0 -28
  44. package/dist/emptyDir.d.ts +0 -1
  45. package/dist/emptyDir.js +0 -52
  46. package/dist/ensureAbsolutePath.d.ts +0 -7
  47. package/dist/ensureAbsolutePath.js +0 -38
  48. package/dist/ensureArray.d.ts +0 -1
  49. package/dist/ensureArray.js +0 -32
  50. package/dist/esm/cli/test.js +0 -9
  51. package/dist/findExists.d.ts +0 -6
  52. package/dist/findExists.js +0 -45
  53. package/dist/generateMetaTags.d.ts +0 -16
  54. package/dist/generateMetaTags.js +0 -61
  55. package/dist/getBrowserslist.d.ts +0 -2
  56. package/dist/getBrowserslist.js +0 -31
  57. package/dist/getCoreJsVersion.d.ts +0 -1
  58. package/dist/getCoreJsVersion.js +0 -46
  59. package/dist/getEntryOptions.d.ts +0 -1
  60. package/dist/getEntryOptions.js +0 -54
  61. package/dist/getPackageManager.d.ts +0 -1
  62. package/dist/getPackageManager.js +0 -87
  63. package/dist/getPort.d.ts +0 -14
  64. package/dist/getPort.js +0 -112
  65. package/dist/getServerConfig.d.ts +0 -1
  66. package/dist/getServerConfig.js +0 -67
  67. package/dist/getTargetDir.d.ts +0 -1
  68. package/dist/getTargetDir.js +0 -41
  69. package/dist/import.d.ts +0 -5
  70. package/dist/import.js +0 -33
  71. package/dist/index.d.ts +0 -44
  72. package/dist/index.js +0 -60
  73. package/dist/is/index.d.ts +0 -58
  74. package/dist/is/index.js +0 -114
  75. package/dist/is/nodeEnv.d.ts +0 -8
  76. package/dist/is/nodeEnv.js +0 -39
  77. package/dist/is/platform.d.ts +0 -2
  78. package/dist/is/platform.js +0 -30
  79. package/dist/is/type.d.ts +0 -8
  80. package/dist/is/type.js +0 -64
  81. package/dist/logger.d.ts +0 -65
  82. package/dist/logger.js +0 -145
  83. package/dist/monorepo.d.ts +0 -11
  84. package/dist/monorepo.js +0 -137
  85. package/dist/nodeEnv.d.ts +0 -3
  86. package/dist/nodeEnv.js +0 -81
  87. package/dist/path.d.ts +0 -18
  88. package/dist/path.js +0 -92
  89. package/dist/pathSerializer.d.ts +0 -16
  90. package/dist/pathSerializer.js +0 -76
  91. package/dist/plugin.d.ts +0 -2
  92. package/dist/plugin.js +0 -46
  93. package/dist/prettyInstructions.d.ts +0 -9
  94. package/dist/prettyInstructions.js +0 -112
  95. package/dist/printBuildError.d.ts +0 -8
  96. package/dist/printBuildError.js +0 -57
  97. package/dist/react.d.ts +0 -1
  98. package/dist/react.js +0 -64
  99. package/dist/readTsConfig.d.ts +0 -2
  100. package/dist/readTsConfig.js +0 -47
  101. package/dist/removeSlash.d.ts +0 -3
  102. package/dist/removeSlash.js +0 -33
  103. package/dist/resolve.d.ts +0 -13
  104. package/dist/resolve.js +0 -63
  105. package/dist/routes.d.ts +0 -2
  106. package/dist/routes.js +0 -58
  107. package/dist/runtimeExports.d.ts +0 -4
  108. package/dist/runtimeExports.js +0 -73
  109. package/dist/ssr.d.ts +0 -8
  110. package/dist/ssr.js +0 -30
  111. package/dist/storage.d.ts +0 -5
  112. package/dist/storage.js +0 -75
  113. package/dist/testUtils.d.ts +0 -5
  114. package/dist/testUtils.js +0 -38
  115. package/dist/types/cli/test.d.ts +0 -5
  116. package/dist/types.d.ts +0 -1
  117. package/dist/types.js +0 -15
  118. package/dist/universal/constants.d.ts +0 -9
  119. package/dist/universal/constants.js +0 -30
  120. package/dist/universal/formatWebpack.d.ts +0 -13
  121. package/dist/universal/formatWebpack.js +0 -100
  122. package/dist/universal/nestedRoutes.d.ts +0 -8
  123. package/dist/universal/nestedRoutes.js +0 -131
  124. package/dist/universal/remixRouter.d.ts +0 -1
  125. package/dist/universal/remixRouter.js +0 -17
  126. package/dist/universal/serialize.d.ts +0 -1
  127. package/dist/universal/serialize.js +0 -40
  128. package/dist/version.d.ts +0 -2
  129. package/dist/version.js +0 -92
  130. package/dist/wait.d.ts +0 -2
  131. package/dist/wait.js +0 -29
  132. package/dist/watch.d.ts +0 -8
  133. package/dist/watch.js +0 -90
@@ -89,127 +89,6 @@ export declare const SERVER_PLUGIN_KOA = "@modern-js/plugin-koa";
89
89
  export declare const SERVER_PLUGIN_SERVER = "@modern-js/plugin-server";
90
90
  export declare const SERVER_PLUGIN_POLYFILL = "@modern-js/plugin-polyfill";
91
91
  export declare const INTERNAL_SERVER_PLUGINS: InternalPlugins;
92
- /**
93
- * The schema registered in the plugin.
94
- */
95
- export declare const PLUGIN_SCHEMAS: {
96
- '@modern-js/runtime': ({
97
- target: string;
98
- schema: {
99
- type: string;
100
- additionalProperties: boolean;
101
- patternProperties?: undefined;
102
- };
103
- } | {
104
- target: string;
105
- schema: {
106
- type: string;
107
- patternProperties: {
108
- "^[a-zA-Z0-9_-]+$": {
109
- type: string;
110
- };
111
- };
112
- additionalProperties: boolean;
113
- };
114
- })[];
115
- '@modern-js/plugin-swc': {
116
- target: string;
117
- schema: {
118
- typeof: string[];
119
- };
120
- }[];
121
- '@modern-js/plugin-bff': {
122
- target: string;
123
- schema: {
124
- type: string;
125
- properties: {
126
- prefix: {
127
- type: string[];
128
- items: {
129
- type: string;
130
- };
131
- };
132
- fetcher: {
133
- type: string;
134
- };
135
- proxy: {
136
- type: string;
137
- };
138
- requestCreator: {
139
- type: string;
140
- };
141
- };
142
- };
143
- }[];
144
- '@modern-js/plugin-tailwindcss': {
145
- target: string;
146
- schema: {
147
- typeof: string[];
148
- };
149
- }[];
150
- '@modern-js/plugin-proxy': {
151
- target: string;
152
- schema: {
153
- typeof: string[];
154
- };
155
- }[];
156
- '@modern-js/plugin-ssg': {
157
- target: string;
158
- schema: {
159
- oneOf: ({
160
- type: string;
161
- instanceof?: undefined;
162
- } | {
163
- instanceof: string;
164
- type?: undefined;
165
- })[];
166
- };
167
- }[];
168
- '@modern-js/plugin-state': {
169
- target: string;
170
- schema: {
171
- type: string[];
172
- };
173
- }[];
174
- '@modern-js/plugin-design-token': ({
175
- target: string;
176
- schema: {
177
- typeof: string[];
178
- type?: undefined;
179
- };
180
- } | {
181
- target: string;
182
- schema: {
183
- type: string[];
184
- typeof?: undefined;
185
- };
186
- })[];
187
- '@modern-js/plugin-router': {
188
- target: string;
189
- schema: {
190
- type: string[];
191
- };
192
- }[];
193
- '@modern-js/plugin-testing': {
194
- target: string;
195
- schema: {
196
- typeof: string[];
197
- };
198
- }[];
199
- '@modern-js/plugin-garfish': {
200
- target: string;
201
- schema: {
202
- type: string[];
203
- };
204
- }[];
205
- '@modern-js/plugin-nocode': never[];
206
- '@modern-js/plugin-worker': {
207
- target: string;
208
- schema: {
209
- type: string[];
210
- };
211
- }[];
212
- };
213
92
  /**
214
93
  * The `@babel/preset-typescript` default options.
215
94
  *
@@ -19,5 +19,4 @@ export * from './print';
19
19
  export * from './require';
20
20
  export * from './routes';
21
21
  export * from './runtimeExports';
22
- export * from './test';
23
22
  export * from './watch';
@@ -10,7 +10,17 @@ export declare const isDepExists: (appDirectory: string, name: string) => boolea
10
10
  * Try to resolve npm package, return true if package is installed.
11
11
  */
12
12
  export declare const isPackageInstalled: (name: string, resolvePaths: string | string[]) => boolean;
13
- export declare const isApiOnly: (appDirectory: string, entryDir?: string) => Promise<boolean>;
13
+ /**
14
+ * Check is api only project
15
+ * 1. env --api-only
16
+ * 2. exist ${apiDir}/ && not exist ${entryDir}/
17
+ *
18
+ * @param appDirectory
19
+ * @param entryDir default 'src'
20
+ * @param apiDir default 'api'
21
+ * @returns boolean
22
+ */
23
+ export declare const isApiOnly: (appDirectory: string, entryDir?: string, apiDir?: string) => Promise<boolean>;
14
24
  export declare const isWebOnly: () => Promise<boolean>;
15
25
  export declare const isBeyondReact17: (cwd: string) => boolean;
16
26
  export declare const isReact18: (cwd: string) => boolean;
@@ -1,8 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import type { NestedRoute } from '@modern-js/types';
3
3
  export declare const transformNestedRoutes: (routes: NestedRoute[]) => import("react-router-dom").RouteObject[];
4
+ type DeferredDataComponentType = (props?: {
5
+ nonce?: string;
6
+ }) => JSX.Element | null;
4
7
  export declare const renderNestedRoute: (nestedRoute: NestedRoute, options?: {
5
8
  parent?: NestedRoute;
6
- DeferredDataComponent?: () => JSX.Element | null;
9
+ DeferredDataComponent?: DeferredDataComponentType;
7
10
  props?: Record<string, any>;
8
- }) => JSX.Element;
11
+ }) => JSX.Element;
12
+ export {};
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.22.1-alpha.3",
18
+ "version": "2.23.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -41,17 +41,14 @@
41
41
  },
42
42
  "./runtime/remix-router": {
43
43
  "types": "./dist/types/runtime/remixRouter.d.ts",
44
- "require": "./dist/cjs/runtime/remixRouter.js",
45
44
  "default": "./dist/esm/runtime/remixRouter.js"
46
45
  },
47
46
  "./runtime/nested-routes": {
48
47
  "types": "./dist/types/runtime/nestedRoutes.d.ts",
49
- "require": "./dist/cjs/runtime/nestedRoutes.js",
50
48
  "default": "./dist/esm/runtime/nestedRoutes.js"
51
49
  },
52
50
  "./runtime-browser": {
53
51
  "jsnext:source": "./src/runtime-browser/index.d.ts",
54
- "require": "./dist/cjs/runtime-browser/index.js",
55
52
  "default": "./dist/esm/runtime-browser/index.js"
56
53
  },
57
54
  "./runtime-node": {
@@ -67,19 +64,16 @@
67
64
  "./universal/constants": {
68
65
  "types": "./dist/types/universal/constants.d.ts",
69
66
  "import": "./dist/esm/universal/constants.js",
70
- "require": "./dist/cjs/universal/constants.js",
71
67
  "default": "./dist/cjs/universal/constants.js"
72
68
  },
73
69
  "./universal/format-webpack": {
74
70
  "types": "./dist/types/universal/format-webpack.d.ts",
75
71
  "import": "./dist/esm/universal/formatWebpack.js",
76
- "require": "./dist/cjs/universal/formatWebpack.js",
77
72
  "default": "./dist/cjs/universal/formatWebpack.js"
78
73
  },
79
74
  "./universal/plugin-dag-sort": {
80
75
  "types": "./dist/types/universal/pluginDagSort.d.ts",
81
76
  "import": "./dist/esm/universal/pluginDagSort.js",
82
- "require": "./dist/cjs/universal/pluginDagSort.js",
83
77
  "default": "./dist/cjs/universal/pluginDagSort.js"
84
78
  },
85
79
  "./ajv": "./dist/compiled/ajv/index.js",
@@ -106,7 +100,8 @@
106
100
  },
107
101
  "publishConfig": {
108
102
  "registry": "https://registry.npmjs.org/",
109
- "access": "public"
103
+ "access": "public",
104
+ "provenance": true
110
105
  },
111
106
  "typesVersions": {
112
107
  "*": {
@@ -240,9 +235,9 @@
240
235
  "typescript": "^5",
241
236
  "webpack": "^5.82.1",
242
237
  "@types/serialize-javascript": "^5.0.1",
243
- "@modern-js/types": "2.22.0",
244
- "@scripts/jest-config": "2.22.0",
245
- "@scripts/build": "2.22.0"
238
+ "@modern-js/types": "2.23.0",
239
+ "@scripts/build": "2.23.0",
240
+ "@scripts/jest-config": "2.23.0"
246
241
  },
247
242
  "sideEffects": false,
248
243
  "scripts": {
@@ -1,16 +0,0 @@
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 };
@@ -1,162 +0,0 @@
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 DELETED
@@ -1,25 +0,0 @@
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 DELETED
@@ -1,108 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- export declare const isApiOnly: (appDirectory: string, entryDir?: string) => Promise<boolean>;
2
- export declare const isWebOnly: () => Promise<boolean>;
@@ -1,71 +0,0 @@
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
- });
@@ -1,3 +0,0 @@
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;