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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/cli/constants/index.js +0 -4
  3. package/dist/cjs/cli/prettyInstructions.js +3 -2
  4. package/dist/cjs/runtime/nestedRoutes.js +3 -1
  5. package/dist/cjs/runtime-node/index.js +0 -2
  6. package/dist/cjs/universal/constants.js +0 -4
  7. package/dist/esm/cli/constants/index.js +0 -1
  8. package/dist/esm/cli/prettyInstructions.js +3 -2
  9. package/dist/esm/runtime/nestedRoutes.js +3 -1
  10. package/dist/esm/runtime-node/index.js +0 -1
  11. package/dist/esm/universal/constants.js +0 -1
  12. package/dist/types/cli/constants/index.d.ts +0 -4
  13. package/dist/types/runtime/nestedRoutes.d.ts +6 -2
  14. package/dist/types/runtime-node/index.d.ts +1 -2
  15. package/dist/types/universal/constants.d.ts +1 -5
  16. package/package.json +4 -13
  17. package/dist/FileSizeReporter.d.ts +0 -16
  18. package/dist/FileSizeReporter.js +0 -162
  19. package/dist/alias.d.ts +0 -25
  20. package/dist/alias.js +0 -108
  21. package/dist/analyzeProject.d.ts +0 -2
  22. package/dist/analyzeProject.js +0 -71
  23. package/dist/applyOptionsChain.d.ts +0 -3
  24. package/dist/applyOptionsChain.js +0 -58
  25. package/dist/babel.d.ts +0 -3
  26. package/dist/babel.js +0 -136
  27. package/dist/chainId.d.ts +0 -244
  28. package/dist/chainId.js +0 -196
  29. package/dist/cjs/runtime-node/nestedRoutes.js +0 -28
  30. package/dist/clearConsole.d.ts +0 -1
  31. package/dist/clearConsole.js +0 -31
  32. package/dist/commands.d.ts +0 -4
  33. package/dist/commands.js +0 -48
  34. package/dist/compatRequire.d.ts +0 -13
  35. package/dist/compatRequire.js +0 -82
  36. package/dist/compiled.d.ts +0 -43
  37. package/dist/compiled.js +0 -142
  38. package/dist/constants.d.ts +0 -244
  39. package/dist/constants.js +0 -320
  40. package/dist/debug.d.ts +0 -6
  41. package/dist/debug.js +0 -28
  42. package/dist/emptyDir.d.ts +0 -1
  43. package/dist/emptyDir.js +0 -52
  44. package/dist/ensureAbsolutePath.d.ts +0 -7
  45. package/dist/ensureAbsolutePath.js +0 -38
  46. package/dist/ensureArray.d.ts +0 -1
  47. package/dist/ensureArray.js +0 -32
  48. package/dist/esm/runtime-node/nestedRoutes.js +0 -18
  49. package/dist/findExists.d.ts +0 -6
  50. package/dist/findExists.js +0 -45
  51. package/dist/generateMetaTags.d.ts +0 -16
  52. package/dist/generateMetaTags.js +0 -61
  53. package/dist/getBrowserslist.d.ts +0 -2
  54. package/dist/getBrowserslist.js +0 -31
  55. package/dist/getCoreJsVersion.d.ts +0 -1
  56. package/dist/getCoreJsVersion.js +0 -46
  57. package/dist/getEntryOptions.d.ts +0 -1
  58. package/dist/getEntryOptions.js +0 -54
  59. package/dist/getPackageManager.d.ts +0 -1
  60. package/dist/getPackageManager.js +0 -87
  61. package/dist/getPort.d.ts +0 -14
  62. package/dist/getPort.js +0 -112
  63. package/dist/getServerConfig.d.ts +0 -1
  64. package/dist/getServerConfig.js +0 -67
  65. package/dist/getTargetDir.d.ts +0 -1
  66. package/dist/getTargetDir.js +0 -41
  67. package/dist/import.d.ts +0 -5
  68. package/dist/import.js +0 -33
  69. package/dist/index.d.ts +0 -44
  70. package/dist/index.js +0 -60
  71. package/dist/is/index.d.ts +0 -58
  72. package/dist/is/index.js +0 -114
  73. package/dist/is/nodeEnv.d.ts +0 -8
  74. package/dist/is/nodeEnv.js +0 -39
  75. package/dist/is/platform.d.ts +0 -2
  76. package/dist/is/platform.js +0 -30
  77. package/dist/is/type.d.ts +0 -8
  78. package/dist/is/type.js +0 -64
  79. package/dist/logger.d.ts +0 -65
  80. package/dist/logger.js +0 -145
  81. package/dist/monorepo.d.ts +0 -11
  82. package/dist/monorepo.js +0 -137
  83. package/dist/nodeEnv.d.ts +0 -3
  84. package/dist/nodeEnv.js +0 -81
  85. package/dist/path.d.ts +0 -18
  86. package/dist/path.js +0 -92
  87. package/dist/pathSerializer.d.ts +0 -16
  88. package/dist/pathSerializer.js +0 -76
  89. package/dist/plugin.d.ts +0 -2
  90. package/dist/plugin.js +0 -46
  91. package/dist/prettyInstructions.d.ts +0 -9
  92. package/dist/prettyInstructions.js +0 -112
  93. package/dist/printBuildError.d.ts +0 -8
  94. package/dist/printBuildError.js +0 -57
  95. package/dist/react.d.ts +0 -1
  96. package/dist/react.js +0 -64
  97. package/dist/readTsConfig.d.ts +0 -2
  98. package/dist/readTsConfig.js +0 -47
  99. package/dist/removeSlash.d.ts +0 -3
  100. package/dist/removeSlash.js +0 -33
  101. package/dist/resolve.d.ts +0 -13
  102. package/dist/resolve.js +0 -63
  103. package/dist/routes.d.ts +0 -2
  104. package/dist/routes.js +0 -58
  105. package/dist/runtimeExports.d.ts +0 -4
  106. package/dist/runtimeExports.js +0 -73
  107. package/dist/ssr.d.ts +0 -8
  108. package/dist/ssr.js +0 -30
  109. package/dist/storage.d.ts +0 -5
  110. package/dist/storage.js +0 -75
  111. package/dist/testUtils.d.ts +0 -5
  112. package/dist/testUtils.js +0 -38
  113. package/dist/types/runtime-node/nestedRoutes.d.ts +0 -3
  114. package/dist/types.d.ts +0 -1
  115. package/dist/types.js +0 -15
  116. package/dist/universal/constants.d.ts +0 -9
  117. package/dist/universal/constants.js +0 -30
  118. package/dist/universal/formatWebpack.d.ts +0 -13
  119. package/dist/universal/formatWebpack.js +0 -100
  120. package/dist/universal/nestedRoutes.d.ts +0 -8
  121. package/dist/universal/nestedRoutes.js +0 -131
  122. package/dist/universal/remixRouter.d.ts +0 -1
  123. package/dist/universal/remixRouter.js +0 -17
  124. package/dist/universal/serialize.d.ts +0 -1
  125. package/dist/universal/serialize.js +0 -40
  126. package/dist/version.d.ts +0 -2
  127. package/dist/version.js +0 -92
  128. package/dist/wait.d.ts +0 -2
  129. package/dist/wait.js +0 -29
  130. package/dist/watch.d.ts +0 -8
  131. package/dist/watch.js +0 -90
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @modern-js/utils
2
2
 
3
+ ## 2.22.1
4
+
5
+ ### Patch Changes
6
+
7
+ - e2848a2: fix: support nonce in streaming SSR
8
+ fix: 在 streaming SSR 中支持 nonce
9
+ - d4045ed: fix(builder): print https URLs when devServer.https is true
10
+
11
+ fix(builder): 当 devServer.https 为 true 时,输出 https 的 URLs
12
+
3
13
  ## 2.22.0
4
14
 
5
15
  ### Patch Changes
@@ -13,9 +13,6 @@ _export(exports, {
13
13
  ROUTE_SPEC_FILE: function() {
14
14
  return ROUTE_SPEC_FILE;
15
15
  },
16
- NESTED_ROUTE_SPEC_FILE: function() {
17
- return NESTED_ROUTE_SPEC_FILE;
18
- },
19
16
  MAIN_ENTRY_NAME: function() {
20
17
  return MAIN_ENTRY_NAME;
21
18
  },
@@ -110,7 +107,6 @@ _export(exports, {
110
107
  const _export_star = require("@swc/helpers/_/_export_star");
111
108
  _export_star._(require("./chainId"), exports);
112
109
  const ROUTE_SPEC_FILE = "route.json";
113
- const NESTED_ROUTE_SPEC_FILE = "nestedRoutes.json";
114
110
  const MAIN_ENTRY_NAME = "main";
115
111
  const SERVER_BUNDLE_DIRECTORY = "bundles";
116
112
  const SERVER_WORKER_BUNDLE_DIRECTORY = "worker";
@@ -67,9 +67,10 @@ const getAddressUrls = (protocol = "http", port, host) => {
67
67
  }, []);
68
68
  };
69
69
  const prettyInstructions = (appContext, config) => {
70
- var _config_dev;
70
+ var _appContext_builder_context_devServer, _appContext_builder, _config_dev;
71
71
  const { entrypoints, serverRoutes, port, apiOnly, checkedEntries } = appContext;
72
- const urls = getAddressUrls(config.dev.https && (0, _is.isDev)() ? "https" : "http", port, (_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : _config_dev.host);
72
+ const isHttps = (0, _is.isDev)() && ((_appContext_builder_context_devServer = (_appContext_builder = appContext.builder) === null || _appContext_builder === void 0 ? void 0 : _appContext_builder.context.devServer) === null || _appContext_builder_context_devServer === void 0 ? void 0 : _appContext_builder_context_devServer.https);
73
+ const urls = getAddressUrls(isHttps ? "https" : "http", port, (_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : _config_dev.host);
73
74
  const routes = !apiOnly ? serverRoutes.filter((route) => route.entryName) : serverRoutes;
74
75
  let message = "App running at:\n\n";
75
76
  if ((0, _is.isSingleEntry)(entrypoints) || apiOnly) {
@@ -72,7 +72,9 @@ const renderNestedRoute = (nestedRoute, options = {}) => {
72
72
  /* @__PURE__ */ (0, _jsxruntime.jsx)(Component, {
73
73
  ...props
74
74
  }),
75
- typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ (0, _jsxruntime.jsx)(DeferredDataComponent, {})
75
+ typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ (0, _jsxruntime.jsx)(DeferredDataComponent, {
76
+ nonce: props === null || props === void 0 ? void 0 : props.nonce
77
+ })
76
78
  ]
77
79
  });
78
80
  } else if (lazyImport) {
@@ -20,8 +20,6 @@ _export(exports, {
20
20
  return _serialize.serializeJson;
21
21
  }
22
22
  });
23
- const _export_star = require("@swc/helpers/_/_export_star");
24
23
  const _storage = require("./storage");
25
24
  const _serialize = require("./serialize");
26
- _export_star._(require("./nestedRoutes"), exports);
27
25
  const { run, useContext: useHeaders } = (0, _storage.createStorage)();
@@ -15,11 +15,7 @@ _export(exports, {
15
15
  },
16
16
  HMR_SOCK_PATH: function() {
17
17
  return HMR_SOCK_PATH;
18
- },
19
- HTML_CHUNKSMAP_SEPARATOR: function() {
20
- return HTML_CHUNKSMAP_SEPARATOR;
21
18
  }
22
19
  });
23
20
  const ROUTE_MANIFEST = `_MODERNJS_ROUTE_MANIFEST`;
24
21
  const HMR_SOCK_PATH = "/webpack-hmr";
25
- const HTML_CHUNKSMAP_SEPARATOR = "<!--<?- chunksMap.js ?>-->";
@@ -1,5 +1,4 @@
1
1
  export const ROUTE_SPEC_FILE = "route.json";
2
- export const NESTED_ROUTE_SPEC_FILE = "nestedRoutes.json";
3
2
  export const MAIN_ENTRY_NAME = "main";
4
3
  export const SERVER_BUNDLE_DIRECTORY = "bundles";
5
4
  export const SERVER_WORKER_BUNDLE_DIRECTORY = "worker";
@@ -47,9 +47,10 @@ export const getAddressUrls = (protocol = "http", port, host) => {
47
47
  }, []);
48
48
  };
49
49
  export const prettyInstructions = (appContext, config) => {
50
- var _config_dev;
50
+ var _appContext_builder_context_devServer, _appContext_builder, _config_dev;
51
51
  const { entrypoints, serverRoutes, port, apiOnly, checkedEntries } = appContext;
52
- const urls = getAddressUrls(config.dev.https && isDev() ? "https" : "http", port, (_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : _config_dev.host);
52
+ const isHttps = isDev() && ((_appContext_builder_context_devServer = (_appContext_builder = appContext.builder) === null || _appContext_builder === void 0 ? void 0 : _appContext_builder.context.devServer) === null || _appContext_builder_context_devServer === void 0 ? void 0 : _appContext_builder_context_devServer.https);
53
+ const urls = getAddressUrls(isHttps ? "https" : "http", port, (_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : _config_dev.host);
53
54
  const routes = !apiOnly ? serverRoutes.filter((route) => route.entryName) : serverRoutes;
54
55
  let message = "App running at:\n\n";
55
56
  if (isSingleEntry(entrypoints) || apiOnly) {
@@ -52,7 +52,9 @@ export const renderNestedRoute = (nestedRoute, options = {}) => {
52
52
  /* @__PURE__ */ _jsx(Component, {
53
53
  ...props
54
54
  }),
55
- typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ _jsx(DeferredDataComponent, {})
55
+ typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ _jsx(DeferredDataComponent, {
56
+ nonce: props === null || props === void 0 ? void 0 : props.nonce
57
+ })
56
58
  ]
57
59
  });
58
60
  } else if (lazyImport) {
@@ -2,4 +2,3 @@ import { createStorage } from "./storage";
2
2
  const { run, useContext: useHeaders } = createStorage();
3
3
  export { run, useHeaders };
4
4
  export { serializeJson } from "./serialize";
5
- export * from "./nestedRoutes";
@@ -1,3 +1,2 @@
1
1
  export const ROUTE_MANIFEST = `_MODERNJS_ROUTE_MANIFEST`;
2
2
  export const HMR_SOCK_PATH = "/webpack-hmr";
3
- export const HTML_CHUNKSMAP_SEPARATOR = "<!--<?- chunksMap.js ?>-->";
@@ -3,10 +3,6 @@ import { InternalPlugins } from '@modern-js/types';
3
3
  * route specification file
4
4
  */
5
5
  export declare const ROUTE_SPEC_FILE = "route.json";
6
- /**
7
- * Front-end routing metadata
8
- */
9
- export declare const NESTED_ROUTE_SPEC_FILE = "nestedRoutes.json";
10
6
  /**
11
7
  * main entry name
12
8
  */
@@ -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 {};
@@ -5,5 +5,4 @@
5
5
  import type { IncomingHttpHeaders } from 'http';
6
6
  declare const run: <O>(context: IncomingHttpHeaders, cb: () => O | Promise<O>) => Promise<O>, useHeaders: () => IncomingHttpHeaders;
7
7
  export { run, useHeaders };
8
- export { serializeJson } from './serialize';
9
- export * from './nestedRoutes';
8
+ export { serializeJson } from './serialize';
@@ -5,8 +5,4 @@ export declare const ROUTE_MANIFEST = "_MODERNJS_ROUTE_MANIFEST";
5
5
  /**
6
6
  * hmr socket connect path
7
7
  */
8
- export declare const HMR_SOCK_PATH = "/webpack-hmr";
9
- /**
10
- * html placeholder
11
- */
12
- export declare const HTML_CHUNKSMAP_SEPARATOR = "<!--<?- chunksMap.js ?>-->";
8
+ export declare const HMR_SOCK_PATH = "/webpack-hmr";
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.22.1",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -36,50 +36,41 @@
36
36
  },
37
37
  "./runtime/router": {
38
38
  "types": "./dist/types/runtime/router.d.ts",
39
- "require": "./dist/cjs/runtime/router.js",
40
39
  "default": "./dist/esm/runtime/router.js"
41
40
  },
42
41
  "./runtime/remix-router": {
43
42
  "types": "./dist/types/runtime/remixRouter.d.ts",
44
- "require": "./dist/cjs/runtime/remixRouter.js",
45
43
  "default": "./dist/esm/runtime/remixRouter.js"
46
44
  },
47
45
  "./runtime/nested-routes": {
48
46
  "types": "./dist/types/runtime/nestedRoutes.d.ts",
49
- "require": "./dist/cjs/runtime/nestedRoutes.js",
50
47
  "default": "./dist/esm/runtime/nestedRoutes.js"
51
48
  },
52
49
  "./runtime-browser": {
53
50
  "jsnext:source": "./src/runtime-browser/index.d.ts",
54
- "require": "./dist/cjs/runtime-browser/index.js",
55
51
  "default": "./dist/esm/runtime-browser/index.js"
56
52
  },
57
53
  "./runtime-node": {
58
54
  "types": "./dist/types/runtime-node/index.d.ts",
59
- "require": "./dist/cjs/runtime-node/index.js",
60
55
  "default": "./dist/esm/runtime-node/index.js"
61
56
  },
62
57
  "./runtime-node/router": {
63
58
  "types": "./dist/types/runtime-node/router.d.ts",
64
- "require": "./dist/cjs/runtime-node/router.js",
65
59
  "default": "./dist/esm/runtime-node/router.js"
66
60
  },
67
61
  "./universal/constants": {
68
62
  "types": "./dist/types/universal/constants.d.ts",
69
63
  "import": "./dist/esm/universal/constants.js",
70
- "require": "./dist/cjs/universal/constants.js",
71
64
  "default": "./dist/cjs/universal/constants.js"
72
65
  },
73
66
  "./universal/format-webpack": {
74
67
  "types": "./dist/types/universal/format-webpack.d.ts",
75
68
  "import": "./dist/esm/universal/formatWebpack.js",
76
- "require": "./dist/cjs/universal/formatWebpack.js",
77
69
  "default": "./dist/cjs/universal/formatWebpack.js"
78
70
  },
79
71
  "./universal/plugin-dag-sort": {
80
72
  "types": "./dist/types/universal/pluginDagSort.d.ts",
81
73
  "import": "./dist/esm/universal/pluginDagSort.js",
82
- "require": "./dist/cjs/universal/pluginDagSort.js",
83
74
  "default": "./dist/cjs/universal/pluginDagSort.js"
84
75
  },
85
76
  "./ajv": "./dist/compiled/ajv/index.js",
@@ -240,9 +231,9 @@
240
231
  "typescript": "^5",
241
232
  "webpack": "^5.82.1",
242
233
  "@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"
234
+ "@modern-js/types": "2.22.1",
235
+ "@scripts/build": "2.22.1",
236
+ "@scripts/jest-config": "2.22.1"
246
237
  },
247
238
  "sideEffects": false,
248
239
  "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;