@modern-js/utils 2.9.0 → 2.11.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.
package/dist/babel.js ADDED
@@ -0,0 +1,136 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, { get: all[name], enumerable: true });
22
+ };
23
+ var __copyProps = (to, from, except, desc) => {
24
+ if (from && typeof from === "object" || typeof from === "function") {
25
+ for (let key of __getOwnPropNames(from))
26
+ if (!__hasOwnProp.call(to, key) && key !== except)
27
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
28
+ }
29
+ return to;
30
+ };
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+ var babel_exports = {};
33
+ __export(babel_exports, {
34
+ applyUserBabelConfig: () => applyUserBabelConfig,
35
+ getBabelUtils: () => getBabelUtils
36
+ });
37
+ module.exports = __toCommonJS(babel_exports);
38
+ var import_path = require("path");
39
+ var import_applyOptionsChain = require("./applyOptionsChain");
40
+ var import_ensureArray = require("./ensureArray");
41
+ var import_path2 = require("./path");
42
+ const formatPath = (originPath) => {
43
+ if ((0, import_path.isAbsolute)(originPath)) {
44
+ return originPath.split(import_path.sep).join("/");
45
+ }
46
+ return originPath;
47
+ };
48
+ const getPluginItemName = (item) => {
49
+ if (typeof item === "string") {
50
+ return formatPath(item);
51
+ }
52
+ if (Array.isArray(item) && typeof item[0] === "string") {
53
+ return formatPath(item[0]);
54
+ }
55
+ return null;
56
+ };
57
+ const addPlugins = (plugins, config) => {
58
+ if (config.plugins) {
59
+ config.plugins.push(...plugins);
60
+ } else {
61
+ config.plugins = plugins;
62
+ }
63
+ };
64
+ const addPresets = (presets, config) => {
65
+ if (config.presets) {
66
+ config.presets.push(...presets);
67
+ } else {
68
+ config.presets = presets;
69
+ }
70
+ };
71
+ const removePlugins = (plugins, config) => {
72
+ if (!config.plugins) {
73
+ return;
74
+ }
75
+ const removeList = (0, import_ensureArray.ensureArray)(plugins);
76
+ config.plugins = config.plugins.filter((item) => {
77
+ const name = getPluginItemName(item);
78
+ if (name) {
79
+ return !removeList.find((removeItem) => name.includes(removeItem));
80
+ }
81
+ return true;
82
+ });
83
+ };
84
+ const removePresets = (presets, config) => {
85
+ if (!config.presets) {
86
+ return;
87
+ }
88
+ const removeList = (0, import_ensureArray.ensureArray)(presets);
89
+ config.presets = config.presets.filter((item) => {
90
+ const name = getPluginItemName(item);
91
+ if (name) {
92
+ return !removeList.find((removeItem) => name.includes(removeItem));
93
+ }
94
+ return true;
95
+ });
96
+ };
97
+ const modifyPresetOptions = (presetName, options, presets = []) => {
98
+ presets.forEach((preset, index) => {
99
+ if (Array.isArray(preset)) {
100
+ if (typeof preset[0] === "string" && (0, import_path2.normalizeToPosixPath)(preset[0]).includes(presetName)) {
101
+ preset[1] = __spreadValues(__spreadValues({}, preset[1] || {}), options);
102
+ }
103
+ } else if (typeof preset === "string" && (0, import_path2.normalizeToPosixPath)(preset).includes(presetName)) {
104
+ presets[index] = [preset, options];
105
+ }
106
+ });
107
+ };
108
+ const getBabelUtils = (config) => {
109
+ const noop = () => {
110
+ };
111
+ return {
112
+ addPlugins: (plugins) => addPlugins(plugins, config),
113
+ addPresets: (presets) => addPresets(presets, config),
114
+ removePlugins: (plugins) => removePlugins(plugins, config),
115
+ removePresets: (presets) => removePresets(presets, config),
116
+ // `addIncludes` and `addExcludes` are noop functions by default,
117
+ // It can be overridden by `extraBabelUtils`.
118
+ addIncludes: noop,
119
+ addExcludes: noop,
120
+ // Compat `presetEnvOptions` and `presetReactOptions` in Eden.
121
+ modifyPresetEnvOptions: (options) => modifyPresetOptions("@babel/preset-env", options, config.presets || []),
122
+ modifyPresetReactOptions: (options) => modifyPresetOptions("@babel/preset-react", options, config.presets || [])
123
+ };
124
+ };
125
+ const applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils) => {
126
+ if (userBabelConfig) {
127
+ const babelUtils = __spreadValues(__spreadValues({}, getBabelUtils(defaultOptions)), extraBabelUtils);
128
+ return (0, import_applyOptionsChain.applyOptionsChain)(defaultOptions, userBabelConfig || {}, babelUtils);
129
+ }
130
+ return defaultOptions;
131
+ };
132
+ // Annotate the CommonJS export names for ESM import in node:
133
+ 0 && (module.exports = {
134
+ applyUserBabelConfig,
135
+ getBabelUtils
136
+ });
package/dist/chainId.d.ts CHANGED
@@ -55,27 +55,10 @@ export declare const CHAIN_ID: {
55
55
  /** Predefined rule groups */
56
56
 
57
57
  readonly ONE_OF: {
58
- readonly JS: "js";
59
- readonly TS: "ts";
60
- readonly CSS: "css";
61
- readonly LESS: "less";
62
- readonly SASS: "sass";
63
- readonly YAML: "yml";
64
- readonly TOML: "toml";
65
- readonly FALLBACK: "fallback";
66
- readonly MARKDOWN: "markdown";
67
- readonly BFF_CLIENT: "bff-client";
68
- readonly CSS_MODULES: "css-modules";
69
- readonly LESS_MODULES: "less-modules";
70
- readonly SASS_MODULES: "sass-modules";
71
58
  readonly SVG: "svg";
72
59
  readonly SVG_URL: "svg-url";
73
60
  readonly SVG_ASSET: "svg-asset";
74
61
  readonly SVG_INLINE: "svg-inline";
75
- readonly ASSETS: "assets";
76
- readonly ASSETS_URL: "assets-url";
77
- readonly ASSETS_INLINE: "assets-inline";
78
- readonly IMAGE_COMPRESS: "image-compress";
79
62
  };
80
63
  /** Predefined loaders */
81
64
 
package/dist/chainId.js CHANGED
@@ -60,27 +60,10 @@ const CHAIN_ID = {
60
60
  },
61
61
  /** Predefined rule groups */
62
62
  ONE_OF: {
63
- JS: "js",
64
- TS: "ts",
65
- CSS: "css",
66
- LESS: "less",
67
- SASS: "sass",
68
- YAML: "yml",
69
- TOML: "toml",
70
- FALLBACK: "fallback",
71
- MARKDOWN: "markdown",
72
- BFF_CLIENT: "bff-client",
73
- CSS_MODULES: "css-modules",
74
- LESS_MODULES: "less-modules",
75
- SASS_MODULES: "sass-modules",
76
63
  SVG: "svg",
77
64
  SVG_URL: "svg-url",
78
65
  SVG_ASSET: "svg-asset",
79
- SVG_INLINE: "svg-inline",
80
- ASSETS: "assets",
81
- ASSETS_URL: "assets-url",
82
- ASSETS_INLINE: "assets-inline",
83
- IMAGE_COMPRESS: "image-compress"
66
+ SVG_INLINE: "svg-inline"
84
67
  },
85
68
  /** Predefined loaders */
86
69
  USE: {
@@ -1,2 +1,3 @@
1
+ export declare const getArgv: () => string[];
1
2
  export declare const getCommand: () => string;
2
3
  export declare const isDevCommand: () => boolean;
package/dist/commands.js CHANGED
@@ -17,12 +17,17 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var commands_exports = {};
19
19
  __export(commands_exports, {
20
+ getArgv: () => getArgv,
20
21
  getCommand: () => getCommand,
21
22
  isDevCommand: () => isDevCommand
22
23
  });
23
24
  module.exports = __toCommonJS(commands_exports);
25
+ const getArgv = () => {
26
+ var _a;
27
+ return (((_a = process.env.MODERN_ARGV) == null ? void 0 : _a.split(" ")) || process.argv).slice(2);
28
+ };
24
29
  const getCommand = () => {
25
- const args = process.argv.slice(2);
30
+ const args = getArgv();
26
31
  const command = args[0];
27
32
  return command;
28
33
  };
@@ -32,6 +37,7 @@ const isDevCommand = () => {
32
37
  };
33
38
  // Annotate the CommonJS export names for ESM import in node:
34
39
  0 && (module.exports = {
40
+ getArgv,
35
41
  getCommand,
36
42
  isDevCommand
37
43
  });
@@ -1,9 +1,4 @@
1
1
  import { InternalPlugins } from '@modern-js/types';
2
- /**
3
- * hmr socket connect path
4
- */
5
-
6
- export declare const HMR_SOCK_PATH = "/webpack-hmr";
7
2
  /**
8
3
  * route specification file
9
4
  */
@@ -71,12 +66,7 @@ export declare const DEFAULT_SERVER_CONFIG = "modern.server-runtime.config";
71
66
  * Routes manifest filename
72
67
  */
73
68
 
74
- export declare const ROUTE_MINIFEST_FILE = "routes-manifest.json";
75
- /**
76
- * Property mounted on window that describes route manifest
77
- */
78
-
79
- export declare const ROUTE_MANIFEST = "_MODERNJS_ROUTE_MANIFEST";
69
+ export declare const ROUTE_MANIFEST_FILE = "routes-manifest.json";
80
70
  /**
81
71
  * directory name for loader routes
82
72
  */
@@ -236,4 +226,19 @@ export declare const PLUGIN_SCHEMAS: {
236
226
  };
237
227
  }[];
238
228
  '@modern-js/plugin-nocode': never[];
229
+ };
230
+ /**
231
+ * The `@babel/preset-typescript` default options.
232
+ *
233
+ * for:
234
+ * - `@modern-js/builder-rspack-provider`
235
+ * - `@modern-js/babel-preset-base`
236
+ */
237
+
238
+ export declare const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS: {
239
+ allowNamespaces: boolean;
240
+ allExtensions: boolean;
241
+ allowDeclareFields: boolean;
242
+ optimizeConstEnums: boolean;
243
+ isTSX: boolean;
239
244
  };
package/dist/constants.js CHANGED
@@ -20,10 +20,10 @@ __export(constants_exports, {
20
20
  API_DIR: () => API_DIR,
21
21
  CONFIG_CACHE_DIR: () => CONFIG_CACHE_DIR,
22
22
  CONFIG_FILE_EXTENSIONS: () => CONFIG_FILE_EXTENSIONS,
23
+ DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS: () => DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS,
23
24
  DEFAULT_DEV_HOST: () => DEFAULT_DEV_HOST,
24
25
  DEFAULT_SERVER_CONFIG: () => DEFAULT_SERVER_CONFIG,
25
26
  ENTRY_NAME_PATTERN: () => ENTRY_NAME_PATTERN,
26
- HMR_SOCK_PATH: () => HMR_SOCK_PATH,
27
27
  INTERNAL_APP_TOOLS_PLUGINS: () => INTERNAL_APP_TOOLS_PLUGINS,
28
28
  INTERNAL_APP_TOOLS_RUNTIME_PLUGINS: () => INTERNAL_APP_TOOLS_RUNTIME_PLUGINS,
29
29
  INTERNAL_CLI_PLUGINS: () => INTERNAL_CLI_PLUGINS,
@@ -37,8 +37,7 @@ __export(constants_exports, {
37
37
  MAIN_ENTRY_NAME: () => MAIN_ENTRY_NAME,
38
38
  OUTPUT_CONFIG_FILE: () => OUTPUT_CONFIG_FILE,
39
39
  PLUGIN_SCHEMAS: () => PLUGIN_SCHEMAS,
40
- ROUTE_MANIFEST: () => ROUTE_MANIFEST,
41
- ROUTE_MINIFEST_FILE: () => ROUTE_MINIFEST_FILE,
40
+ ROUTE_MANIFEST_FILE: () => ROUTE_MANIFEST_FILE,
42
41
  ROUTE_SPEC_FILE: () => ROUTE_SPEC_FILE,
43
42
  SERVER_BUNDLE_DIRECTORY: () => SERVER_BUNDLE_DIRECTORY,
44
43
  SERVER_DIR: () => SERVER_DIR,
@@ -54,7 +53,6 @@ __export(constants_exports, {
54
53
  SHARED_DIR: () => SHARED_DIR
55
54
  });
56
55
  module.exports = __toCommonJS(constants_exports);
57
- const HMR_SOCK_PATH = "/webpack-hmr";
58
56
  const ROUTE_SPEC_FILE = "route.json";
59
57
  const MAIN_ENTRY_NAME = "main";
60
58
  const LAUNCH_EDITOR_ENDPOINT = "/__open-stack-frame-in-editor";
@@ -70,8 +68,7 @@ const CONFIG_CACHE_DIR = "./node_modules/.cache/node-bundle-require";
70
68
  const CONFIG_FILE_EXTENSIONS = [".js", ".ts", ".mjs"];
71
69
  const OUTPUT_CONFIG_FILE = "modern.config.json";
72
70
  const DEFAULT_SERVER_CONFIG = "modern.server-runtime.config";
73
- const ROUTE_MINIFEST_FILE = "routes-manifest.json";
74
- const ROUTE_MANIFEST = `_MODERNJS_ROUTE_MANIFEST`;
71
+ const ROUTE_MANIFEST_FILE = "routes-manifest.json";
75
72
  const LOADER_ROUTES_DIR = `loader-routes`;
76
73
  const DEFAULT_DEV_HOST = "0.0.0.0";
77
74
  const INTERNAL_APP_TOOLS_PLUGINS = {
@@ -275,15 +272,24 @@ const PLUGIN_SCHEMAS = {
275
272
  ],
276
273
  "@modern-js/plugin-nocode": []
277
274
  };
275
+ const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
276
+ allowNamespaces: true,
277
+ allExtensions: true,
278
+ allowDeclareFields: true,
279
+ // aligns Babel's behavior with TypeScript's default behavior.
280
+ // https://babeljs.io/docs/en/babel-preset-typescript#optimizeconstenums
281
+ optimizeConstEnums: true,
282
+ isTSX: true
283
+ };
278
284
  // Annotate the CommonJS export names for ESM import in node:
279
285
  0 && (module.exports = {
280
286
  API_DIR,
281
287
  CONFIG_CACHE_DIR,
282
288
  CONFIG_FILE_EXTENSIONS,
289
+ DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS,
283
290
  DEFAULT_DEV_HOST,
284
291
  DEFAULT_SERVER_CONFIG,
285
292
  ENTRY_NAME_PATTERN,
286
- HMR_SOCK_PATH,
287
293
  INTERNAL_APP_TOOLS_PLUGINS,
288
294
  INTERNAL_APP_TOOLS_RUNTIME_PLUGINS,
289
295
  INTERNAL_CLI_PLUGINS,
@@ -297,8 +303,7 @@ const PLUGIN_SCHEMAS = {
297
303
  MAIN_ENTRY_NAME,
298
304
  OUTPUT_CONFIG_FILE,
299
305
  PLUGIN_SCHEMAS,
300
- ROUTE_MANIFEST,
301
- ROUTE_MINIFEST_FILE,
306
+ ROUTE_MANIFEST_FILE,
302
307
  ROUTE_SPEC_FILE,
303
308
  SERVER_BUNDLE_DIRECTORY,
304
309
  SERVER_DIR,
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from './compiled';
2
2
  export * from './commands';
3
- export * from './format';
4
3
  export * from './FileSizeReporter';
5
4
  export * from './printBuildError';
6
5
  export * from './debug';
@@ -32,7 +31,7 @@ export * from './nodeEnv';
32
31
  export * from './wait';
33
32
  export * from './emptyDir';
34
33
  export * from './getServerConfig';
35
- export * from './tryResolve';
34
+ export * from './resolve';
36
35
  export * from './analyzeProject';
37
36
  export * from './chainId';
38
37
  export * from './version';
@@ -41,4 +40,5 @@ export * from './routes';
41
40
  export * from './testUtils';
42
41
  export * from './getCoreJsVersion';
43
42
  export * from './react';
44
- export * from './getTargetDir';
43
+ export * from './getTargetDir';
44
+ export * from './babel';
package/dist/index.js CHANGED
@@ -16,7 +16,6 @@ var src_exports = {};
16
16
  module.exports = __toCommonJS(src_exports);
17
17
  __reExport(src_exports, require("./compiled"), module.exports);
18
18
  __reExport(src_exports, require("./commands"), module.exports);
19
- __reExport(src_exports, require("./format"), module.exports);
20
19
  __reExport(src_exports, require("./FileSizeReporter"), module.exports);
21
20
  __reExport(src_exports, require("./printBuildError"), module.exports);
22
21
  __reExport(src_exports, require("./debug"), module.exports);
@@ -48,7 +47,7 @@ __reExport(src_exports, require("./nodeEnv"), module.exports);
48
47
  __reExport(src_exports, require("./wait"), module.exports);
49
48
  __reExport(src_exports, require("./emptyDir"), module.exports);
50
49
  __reExport(src_exports, require("./getServerConfig"), module.exports);
51
- __reExport(src_exports, require("./tryResolve"), module.exports);
50
+ __reExport(src_exports, require("./resolve"), module.exports);
52
51
  __reExport(src_exports, require("./analyzeProject"), module.exports);
53
52
  __reExport(src_exports, require("./chainId"), module.exports);
54
53
  __reExport(src_exports, require("./version"), module.exports);
@@ -58,3 +57,4 @@ __reExport(src_exports, require("./testUtils"), module.exports);
58
57
  __reExport(src_exports, require("./getCoreJsVersion"), module.exports);
59
58
  __reExport(src_exports, require("./react"), module.exports);
60
59
  __reExport(src_exports, require("./getTargetDir"), module.exports);
60
+ __reExport(src_exports, require("./babel"), module.exports);
@@ -9,4 +9,5 @@ export declare const tryResolve: (name: string, resolvePath: string) => string;
9
9
  * Try to resolve npm package, return true if package is installed.
10
10
  */
11
11
 
12
- export declare const isPackageInstalled: (name: string, resolvePaths: string | string[]) => boolean;
12
+ export declare const isPackageInstalled: (name: string, resolvePaths: string | string[]) => boolean;
13
+ export declare const getAntdMajorVersion: (appDirectory: string) => number | null;
@@ -15,12 +15,13 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var tryResolve_exports = {};
19
- __export(tryResolve_exports, {
18
+ var resolve_exports = {};
19
+ __export(resolve_exports, {
20
+ getAntdMajorVersion: () => getAntdMajorVersion,
20
21
  isPackageInstalled: () => isPackageInstalled,
21
22
  tryResolve: () => tryResolve
22
23
  });
23
- module.exports = __toCommonJS(tryResolve_exports);
24
+ module.exports = __toCommonJS(resolve_exports);
24
25
  var import_ensureArray = require("./ensureArray");
25
26
  const tryResolve = (name, resolvePath) => {
26
27
  let filePath = "";
@@ -43,8 +44,20 @@ const isPackageInstalled = (name, resolvePaths) => {
43
44
  return false;
44
45
  }
45
46
  };
47
+ const getAntdMajorVersion = (appDirectory) => {
48
+ try {
49
+ const pkgJsonPath = require.resolve("antd/package.json", {
50
+ paths: [appDirectory]
51
+ });
52
+ const { version } = require(pkgJsonPath);
53
+ return Number(version.split(".")[0]);
54
+ } catch (err) {
55
+ return null;
56
+ }
57
+ };
46
58
  // Annotate the CommonJS export names for ESM import in node:
47
59
  0 && (module.exports = {
60
+ getAntdMajorVersion,
48
61
  isPackageInstalled,
49
62
  tryResolve
50
63
  });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Property mounted on window that describes route manifest
3
+ */
4
+ export declare const ROUTE_MANIFEST = "_MODERNJS_ROUTE_MANIFEST";
5
+ /**
6
+ * hmr socket connect path
7
+ */
8
+
9
+ export declare const HMR_SOCK_PATH = "/webpack-hmr";
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var constants_exports = {};
19
+ __export(constants_exports, {
20
+ HMR_SOCK_PATH: () => HMR_SOCK_PATH,
21
+ ROUTE_MANIFEST: () => ROUTE_MANIFEST
22
+ });
23
+ module.exports = __toCommonJS(constants_exports);
24
+ const ROUTE_MANIFEST = `_MODERNJS_ROUTE_MANIFEST`;
25
+ const HMR_SOCK_PATH = "/webpack-hmr";
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ HMR_SOCK_PATH,
29
+ ROUTE_MANIFEST
30
+ });
@@ -15,11 +15,11 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var format_exports = {};
19
- __export(format_exports, {
18
+ var formatWebpack_exports = {};
19
+ __export(formatWebpack_exports, {
20
20
  formatWebpackMessages: () => formatWebpackMessages
21
21
  });
22
- module.exports = __toCommonJS(format_exports);
22
+ module.exports = __toCommonJS(formatWebpack_exports);
23
23
  const friendlySyntaxErrorLabel = "SyntaxError:";
24
24
  function isLikelyASyntaxError(message) {
25
25
  return message.includes(friendlySyntaxErrorLabel);
@@ -30,7 +30,7 @@ function formatMessage(stats) {
30
30
  if (typeof stats === "object") {
31
31
  const fileName = stats.moduleName ? `File: ${stats.moduleName}
32
32
  ` : "";
33
- const mainMessage = stats.message;
33
+ const mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
34
34
  const details = stats.details ? `
35
35
  Details: ${stats.details}
36
36
  ` : "";
@@ -1,11 +1,8 @@
1
1
  /// <reference types="react" />
2
-
3
- /**
4
- * runtime utils for nested routes generating
5
- */
6
2
  import type { NestedRoute } from '@modern-js/types';
7
3
  export declare const transformNestedRoutes: (routes: NestedRoute[]) => import("react-router-dom").RouteObject[];
8
4
  export declare const renderNestedRoute: (nestedRoute: NestedRoute, options?: {
9
5
  parent?: NestedRoute;
10
6
  DeferredDataComponent?: () => JSX.Element | null;
7
+ props?: Record<string, any>;
11
8
  }) => JSX.Element;
@@ -50,9 +50,9 @@ const transformNestedRoutes = (routes) => {
50
50
  return (0, import_react_router_dom.createRoutesFromElements)(routeElements);
51
51
  };
52
52
  const renderNestedRoute = (nestedRoute, options = {}) => {
53
- const { children, index, id, component, isRoot } = nestedRoute;
53
+ const { children, index, id, component, isRoot, lazyImport } = nestedRoute;
54
54
  const Component = component;
55
- const { parent, DeferredDataComponent } = options;
55
+ const { parent, DeferredDataComponent, props = {} } = options;
56
56
  const routeProps = {
57
57
  caseSensitive: nestedRoute.caseSensitive,
58
58
  path: nestedRoute.path,
@@ -72,22 +72,24 @@ const renderNestedRoute = (nestedRoute, options = {}) => {
72
72
  }
73
73
  let element;
74
74
  if (Component) {
75
- if (parent == null ? void 0 : parent.loading) {
75
+ if ((parent == null ? void 0 : parent.loading) && lazyImport) {
76
76
  const Loading = parent.loading;
77
77
  if (isLoadableComponent(Component)) {
78
78
  element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Loading, {}) });
79
79
  } else {
80
80
  element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Loading, {}), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}) });
81
81
  }
82
- } else if (isLoadableComponent(Component)) {
82
+ } else if (isLoadableComponent(Component) && lazyImport) {
83
83
  element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {});
84
84
  } else if (isRoot) {
85
85
  element = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
86
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}),
86
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, __spreadValues({}, props)),
87
87
  typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DeferredDataComponent, {})
88
88
  ] });
89
- } else {
89
+ } else if (lazyImport) {
90
90
  element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}) });
91
+ } else {
92
+ element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {});
91
93
  }
92
94
  } else {
93
95
  nestedRoute.loading = parent == null ? void 0 : parent.loading;
@@ -12,6 +12,6 @@ var __copyProps = (to, from, except, desc) => {
12
12
  };
13
13
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
14
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var remix_router_exports = {};
16
- module.exports = __toCommonJS(remix_router_exports);
17
- __reExport(remix_router_exports, require("@remix-run/router"), module.exports);
15
+ var remixRouter_exports = {};
16
+ module.exports = __toCommonJS(remixRouter_exports);
17
+ __reExport(remixRouter_exports, require("@remix-run/router"), module.exports);