@modern-js/utils 2.26.0 → 2.27.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 (86) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/universal/formatWebpack.js +0 -4
  3. package/dist/esm/cli/alias.js +26 -22
  4. package/dist/esm/cli/applyOptionsChain.js +8 -6
  5. package/dist/esm/cli/babel.js +50 -35
  6. package/dist/esm/cli/commands.js +7 -7
  7. package/dist/esm/cli/common.js +10 -5
  8. package/dist/esm/cli/constants/chainId.js +1 -1
  9. package/dist/esm/cli/constants/index.js +33 -37
  10. package/dist/esm/cli/ensure.js +4 -2
  11. package/dist/esm/cli/fs.js +56 -9
  12. package/dist/esm/cli/get/config.js +7 -7
  13. package/dist/esm/cli/get/data.js +93 -55
  14. package/dist/esm/cli/get/index.js +21 -6
  15. package/dist/esm/cli/is/config.js +33 -14
  16. package/dist/esm/cli/is/env.js +18 -6
  17. package/dist/esm/cli/is/platform.js +6 -2
  18. package/dist/esm/cli/is/project.js +73 -36
  19. package/dist/esm/cli/is/type.js +3 -1
  20. package/dist/esm/cli/logger.js +49 -38
  21. package/dist/esm/cli/monorepo.js +49 -36
  22. package/dist/esm/cli/package.js +156 -38
  23. package/dist/esm/cli/path.js +44 -20
  24. package/dist/esm/cli/pathSerializer.js +29 -15
  25. package/dist/esm/cli/port.js +89 -40
  26. package/dist/esm/cli/prettyInstructions.js +42 -31
  27. package/dist/esm/cli/require.js +21 -16
  28. package/dist/esm/cli/runtimeExports.js +21 -15
  29. package/dist/esm/cli/watch.js +94 -27
  30. package/dist/esm/compiled.js +3 -3
  31. package/dist/esm/import.js +4 -4
  32. package/dist/esm/runtime/nestedRoutes.js +42 -29
  33. package/dist/esm/runtime-browser/parsed.js +5 -5
  34. package/dist/esm/runtime-node/index.js +1 -1
  35. package/dist/esm/runtime-node/nestedRoutes.js +6 -4
  36. package/dist/esm/runtime-node/serialize.js +1 -1
  37. package/dist/esm/runtime-node/storage.js +12 -14
  38. package/dist/esm/universal/constants.js +3 -3
  39. package/dist/esm/universal/formatWebpack.js +20 -26
  40. package/dist/esm/universal/pluginDagSort.js +49 -26
  41. package/dist/esm-node/cli/alias.js +51 -0
  42. package/dist/esm-node/cli/applyOptionsChain.js +24 -0
  43. package/dist/esm-node/cli/babel.js +103 -0
  44. package/dist/esm-node/cli/commands.js +16 -0
  45. package/dist/esm-node/cli/common.js +10 -0
  46. package/dist/esm-node/cli/constants/chainId.js +180 -0
  47. package/dist/esm-node/cli/constants/index.js +103 -0
  48. package/dist/esm-node/cli/ensure.js +10 -0
  49. package/dist/esm-node/cli/fs.js +14 -0
  50. package/dist/esm-node/cli/get/config.js +16 -0
  51. package/dist/esm-node/cli/get/data.js +86 -0
  52. package/dist/esm-node/cli/get/index.js +13 -0
  53. package/dist/esm-node/cli/index.js +20 -0
  54. package/dist/esm-node/cli/is/config.js +40 -0
  55. package/dist/esm-node/cli/is/env.js +6 -0
  56. package/dist/esm-node/cli/is/index.js +5 -0
  57. package/dist/esm-node/cli/is/platform.js +2 -0
  58. package/dist/esm-node/cli/is/project.js +73 -0
  59. package/dist/esm-node/cli/is/type.js +25 -0
  60. package/dist/esm-node/cli/logger.js +103 -0
  61. package/dist/esm-node/cli/monorepo.js +70 -0
  62. package/dist/esm-node/cli/package.js +43 -0
  63. package/dist/esm-node/cli/path.js +49 -0
  64. package/dist/esm-node/cli/pathSerializer.js +46 -0
  65. package/dist/esm-node/cli/port.js +44 -0
  66. package/dist/esm-node/cli/prettyInstructions.js +77 -0
  67. package/dist/esm-node/cli/require.js +52 -0
  68. package/dist/esm-node/cli/runtimeExports.js +35 -0
  69. package/dist/esm-node/cli/watch.js +41 -0
  70. package/dist/esm-node/compiled.js +33 -0
  71. package/dist/esm-node/import.js +8 -0
  72. package/dist/esm-node/index.js +3 -0
  73. package/dist/esm-node/runtime/nestedRoutes.js +112 -0
  74. package/dist/esm-node/runtime/remixRouter.js +1 -0
  75. package/dist/esm-node/runtime/router.js +1 -0
  76. package/dist/esm-node/runtime-browser/index.js +1 -0
  77. package/dist/esm-node/runtime-browser/parsed.js +17 -0
  78. package/dist/esm-node/runtime-node/index.js +5 -0
  79. package/dist/esm-node/runtime-node/nestedRoutes.js +18 -0
  80. package/dist/esm-node/runtime-node/router.js +1 -0
  81. package/dist/esm-node/runtime-node/serialize.js +6 -0
  82. package/dist/esm-node/runtime-node/storage.js +38 -0
  83. package/dist/esm-node/universal/constants.js +3 -0
  84. package/dist/esm-node/universal/formatWebpack.js +61 -0
  85. package/dist/esm-node/universal/pluginDagSort.js +50 -0
  86. package/package.json +4 -4
@@ -1,14 +1,17 @@
1
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
1
2
  import os from "os";
2
3
  import { chalk } from "../compiled";
3
4
  import { isDev, isSingleEntry } from "./is";
4
5
  import { DEFAULT_DEV_HOST } from "./constants";
5
- const normalizeUrl = (url) => url.replace(/([^:]\/)\/+/g, "$1");
6
- const getIpv4Interfaces = () => {
7
- const interfaces = os.networkInterfaces();
8
- const ipv4Interfaces = [];
9
- Object.keys(interfaces).forEach((key) => {
10
- interfaces[key].forEach((detail) => {
11
- const familyV4Value = typeof detail.family === "string" ? "IPv4" : 4;
6
+ var normalizeUrl = function(url) {
7
+ return url.replace(/([^:]\/)\/+/g, "$1");
8
+ };
9
+ var getIpv4Interfaces = function() {
10
+ var interfaces = os.networkInterfaces();
11
+ var ipv4Interfaces = [];
12
+ Object.keys(interfaces).forEach(function(key) {
13
+ interfaces[key].forEach(function(detail) {
14
+ var familyV4Value = typeof detail.family === "string" ? "IPv4" : 4;
12
15
  if (detail.family === familyV4Value) {
13
16
  ipv4Interfaces.push(detail);
14
17
  }
@@ -16,57 +19,65 @@ const getIpv4Interfaces = () => {
16
19
  });
17
20
  return ipv4Interfaces;
18
21
  };
19
- export const getAddressUrls = (protocol = "http", port, host) => {
20
- const LOCAL_LABEL = "Local: ";
21
- const NETWORK_LABEL = "Network: ";
22
- const isLocalhost = (url) => {
22
+ export var getAddressUrls = function() {
23
+ var protocol = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "http", port = arguments.length > 1 ? arguments[1] : void 0, host = arguments.length > 2 ? arguments[2] : void 0;
24
+ var LOCAL_LABEL = "Local: ";
25
+ var NETWORK_LABEL = "Network: ";
26
+ var isLocalhost = function(url) {
23
27
  return url === null || url === void 0 ? void 0 : url.includes("localhost");
24
28
  };
25
29
  if (host && host !== DEFAULT_DEV_HOST) {
26
30
  return [
27
31
  {
28
32
  label: isLocalhost(host) ? LOCAL_LABEL : NETWORK_LABEL,
29
- url: `${protocol}://${host}:${port}`
33
+ url: "".concat(protocol, "://").concat(host, ":").concat(port)
30
34
  }
31
35
  ];
32
36
  }
33
- const ipv4Interfaces = getIpv4Interfaces();
34
- return ipv4Interfaces.reduce((memo, detail) => {
37
+ var ipv4Interfaces = getIpv4Interfaces();
38
+ return ipv4Interfaces.reduce(function(memo, detail) {
35
39
  if (isLocalhost(detail.address) || detail.internal) {
36
40
  memo.push({
37
41
  label: LOCAL_LABEL,
38
- url: `${protocol}://localhost:${port}`
42
+ url: "".concat(protocol, "://localhost:").concat(port)
39
43
  });
40
44
  } else {
41
45
  memo.push({
42
46
  label: NETWORK_LABEL,
43
- url: `${protocol}://${detail.address}:${port}`
47
+ url: "".concat(protocol, "://").concat(detail.address, ":").concat(port)
44
48
  });
45
49
  }
46
50
  return memo;
47
51
  }, []);
48
52
  };
49
- export const prettyInstructions = (appContext, config) => {
53
+ export var prettyInstructions = function(appContext, config) {
50
54
  var _appContext_builder_context_devServer, _appContext_builder, _config_dev;
51
- const { entrypoints, serverRoutes, port, apiOnly, checkedEntries } = appContext;
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);
54
- const routes = !apiOnly ? serverRoutes.filter((route) => route.entryName) : serverRoutes;
55
- let message = "App running at:\n\n";
55
+ var entrypoints = appContext.entrypoints, serverRoutes = appContext.serverRoutes, port = appContext.port, apiOnly = appContext.apiOnly, checkedEntries = appContext.checkedEntries;
56
+ var 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);
57
+ var urls = getAddressUrls(isHttps ? "https" : "http", port, (_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : _config_dev.host);
58
+ var routes = !apiOnly ? serverRoutes.filter(function(route) {
59
+ return route.entryName;
60
+ }) : serverRoutes;
61
+ var message = "App running at:\n\n";
56
62
  if (isSingleEntry(entrypoints) || apiOnly) {
57
- message += urls.map(({ label, url }) => ` ${chalk.bold(`> ${label.padEnd(10)}`)}${chalk.cyanBright(normalizeUrl(`${url}/${routes[0].urlPath}`))}
58
- `).join("");
63
+ message += urls.map(function(param) {
64
+ var label = param.label, url = param.url;
65
+ return " ".concat(chalk.bold("> ".concat(label.padEnd(10)))).concat(chalk.cyanBright(normalizeUrl("".concat(url, "/").concat(routes[0].urlPath))), "\n");
66
+ }).join("");
59
67
  } else {
60
- const maxNameLength = Math.max(...routes.map((r) => r.entryName.length));
61
- urls.forEach(({ label, url }) => {
62
- message += ` ${chalk.bold(`> ${label}`)}
63
- `;
64
- routes.forEach(({ entryName, urlPath, isSSR }) => {
68
+ var _Math;
69
+ var maxNameLength = (_Math = Math).max.apply(_Math, _to_consumable_array(routes.map(function(r) {
70
+ return r.entryName.length;
71
+ })));
72
+ urls.forEach(function(param) {
73
+ var label = param.label, url = param.url;
74
+ message += " ".concat(chalk.bold("> ".concat(label)), "\n");
75
+ routes.forEach(function(param2) {
76
+ var entryName = param2.entryName, urlPath = param2.urlPath, isSSR = param2.isSSR;
65
77
  if (!checkedEntries.includes(entryName)) {
66
78
  return;
67
79
  }
68
- message += ` ${chalk.yellowBright(isSSR ? "λ" : "○")} ${chalk.yellowBright(entryName.padEnd(maxNameLength + 8))}${chalk.cyanBright(normalizeUrl(`${url}/${urlPath}`))}
69
- `;
80
+ message += " ".concat(chalk.yellowBright(isSSR ? "λ" : "○"), " ").concat(chalk.yellowBright(entryName.padEnd(maxNameLength + 8))).concat(chalk.cyanBright(normalizeUrl("".concat(url, "/").concat(urlPath))), "\n");
70
81
  });
71
82
  });
72
83
  message += "\n";
@@ -1,27 +1,30 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
1
2
  import { findExists } from "./fs";
2
- export const compatRequire = (filePath, interop = true) => {
3
- const mod = require(filePath);
4
- const rtnESMDefault = interop && (mod === null || mod === void 0 ? void 0 : mod.__esModule);
3
+ export var compatRequire = function(filePath) {
4
+ var interop = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
5
+ var mod = require(filePath);
6
+ var rtnESMDefault = interop && (mod === null || mod === void 0 ? void 0 : mod.__esModule);
5
7
  return rtnESMDefault ? mod.default : mod;
6
8
  };
7
- export const dynamicImport = new Function("modulePath", "return import(modulePath)");
8
- export const requireExistModule = (filename, opt) => {
9
- const final = {
9
+ export var dynamicImport = new Function("modulePath", "return import(modulePath)");
10
+ export var requireExistModule = function(filename, opt) {
11
+ var final = _object_spread({
10
12
  extensions: [
11
13
  ".ts",
12
14
  ".js"
13
15
  ],
14
- interop: true,
15
- ...opt
16
- };
17
- const exist = findExists(final.extensions.map((ext) => `${filename}${ext}`));
16
+ interop: true
17
+ }, opt);
18
+ var exist = findExists(final.extensions.map(function(ext) {
19
+ return "".concat(filename).concat(ext);
20
+ }));
18
21
  if (!exist) {
19
22
  return null;
20
23
  }
21
24
  return compatRequire(exist, final.interop);
22
25
  };
23
- export const cleanRequireCache = (filelist) => {
24
- filelist.forEach((filepath) => {
26
+ export var cleanRequireCache = function(filelist) {
27
+ filelist.forEach(function(filepath) {
25
28
  delete require.cache[filepath];
26
29
  });
27
30
  };
@@ -30,11 +33,13 @@ export function deleteRequireCache(path) {
30
33
  delete require.cache[path];
31
34
  }
32
35
  if (module.children) {
33
- module.children = module.children.filter((item) => item.filename !== path);
36
+ module.children = module.children.filter(function(item) {
37
+ return item.filename !== path;
38
+ });
34
39
  }
35
40
  }
36
- export const tryResolve = (name, resolvePath) => {
37
- let filePath = "";
41
+ export var tryResolve = function(name, resolvePath) {
42
+ var filePath = "";
38
43
  try {
39
44
  filePath = require.resolve(name, {
40
45
  paths: [
@@ -44,7 +49,7 @@ export const tryResolve = (name, resolvePath) => {
44
49
  delete require.cache[filePath];
45
50
  } catch (err) {
46
51
  if (err.code === "MODULE_NOT_FOUND") {
47
- throw new Error(`Can not find module ${name}.`);
52
+ throw new Error("Can not find module ".concat(name, "."));
48
53
  }
49
54
  throw err;
50
55
  }
@@ -1,35 +1,41 @@
1
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
1
2
  import path from "path";
2
3
  import { fs } from "../compiled";
3
4
  import { normalizeOutputPath } from "./path";
4
- const memo = (fn) => {
5
- const cache = /* @__PURE__ */ new Map();
6
- return (...params) => {
7
- const stringifiedParams = JSON.stringify(params);
8
- const cachedResult = cache.get(stringifiedParams);
5
+ var memo = function(fn) {
6
+ var cache = /* @__PURE__ */ new Map();
7
+ return function() {
8
+ for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
9
+ params[_key] = arguments[_key];
10
+ }
11
+ var stringifiedParams = JSON.stringify(params);
12
+ var cachedResult = cache.get(stringifiedParams);
9
13
  if (cachedResult) {
10
14
  return cachedResult;
11
15
  }
12
- const res = fn(...params);
16
+ var res = fn.apply(void 0, _to_consumable_array(params));
13
17
  cache.set(stringifiedParams, res);
14
18
  return res;
15
19
  };
16
20
  };
17
- export const createRuntimeExportsUtils = memo((pwd = "", namespace = "index") => {
18
- const entryExportFile = path.join(pwd, `.runtime-exports/${namespace}.js`);
19
- const addExport = (statement) => {
21
+ export var createRuntimeExportsUtils = memo(function() {
22
+ var pwd = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "", namespace = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "index";
23
+ var entryExportFile = path.join(pwd, ".runtime-exports/".concat(namespace, ".js"));
24
+ var addExport = function(statement) {
20
25
  statement = normalizeOutputPath(statement);
21
26
  try {
22
27
  fs.ensureFileSync(entryExportFile);
23
28
  if (!fs.readFileSync(entryExportFile, "utf8").includes(statement)) {
24
- fs.appendFileSync(entryExportFile, `${statement}
25
- `);
29
+ fs.appendFileSync(entryExportFile, "".concat(statement, "\n"));
26
30
  }
27
- } catch {
31
+ } catch (e) {
28
32
  }
29
33
  };
30
- const getPath = () => entryExportFile;
34
+ var getPath = function() {
35
+ return entryExportFile;
36
+ };
31
37
  return {
32
- addExport,
33
- getPath
38
+ addExport: addExport,
39
+ getPath: getPath
34
40
  };
35
41
  });
@@ -1,40 +1,107 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
1
3
  import path from "path";
2
4
  import { chokidar } from "../compiled";
3
- export const WatchChangeType = {
5
+ export var WatchChangeType = {
4
6
  ADD: "add",
5
7
  UNLINK: "unlink",
6
8
  CHANGE: "change"
7
9
  };
8
- export const watch = (watchDir, runTask, ignored = []) => {
9
- let ready = false;
10
- const watcher = chokidar.watch(watchDir, {
11
- ignored
10
+ export var watch = function(watchDir, runTask) {
11
+ var ignored = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
12
+ var ready = false;
13
+ var watcher = chokidar.watch(watchDir, {
14
+ ignored: ignored
12
15
  });
13
- watcher.on("ready", () => ready = true);
14
- watcher.on("change", async (filePath) => {
15
- const changedFilePath = path.resolve(filePath);
16
- await runTask({
17
- changedFilePath,
18
- changeType: WatchChangeType.CHANGE
19
- });
16
+ watcher.on("ready", function() {
17
+ return ready = true;
20
18
  });
21
- watcher.on("add", async (filePath) => {
22
- const changedFilePath = path.resolve(filePath);
23
- if (ready) {
24
- await runTask({
25
- changedFilePath,
26
- changeType: WatchChangeType.ADD
19
+ watcher.on("change", function() {
20
+ var _ref = _async_to_generator(function(filePath) {
21
+ var changedFilePath;
22
+ return _ts_generator(this, function(_state) {
23
+ switch (_state.label) {
24
+ case 0:
25
+ changedFilePath = path.resolve(filePath);
26
+ return [
27
+ 4,
28
+ runTask({
29
+ changedFilePath: changedFilePath,
30
+ changeType: WatchChangeType.CHANGE
31
+ })
32
+ ];
33
+ case 1:
34
+ _state.sent();
35
+ return [
36
+ 2
37
+ ];
38
+ }
27
39
  });
28
- }
29
- });
30
- watcher.on("unlink", async (filePath) => {
31
- const changedFilePath = path.resolve(filePath);
32
- await runTask({
33
- changedFilePath,
34
- changeType: WatchChangeType.UNLINK
35
40
  });
36
- });
37
- watcher.on("error", (err) => {
41
+ return function(filePath) {
42
+ return _ref.apply(this, arguments);
43
+ };
44
+ }());
45
+ watcher.on("add", function() {
46
+ var _ref = _async_to_generator(function(filePath) {
47
+ var changedFilePath;
48
+ return _ts_generator(this, function(_state) {
49
+ switch (_state.label) {
50
+ case 0:
51
+ changedFilePath = path.resolve(filePath);
52
+ if (!ready)
53
+ return [
54
+ 3,
55
+ 2
56
+ ];
57
+ return [
58
+ 4,
59
+ runTask({
60
+ changedFilePath: changedFilePath,
61
+ changeType: WatchChangeType.ADD
62
+ })
63
+ ];
64
+ case 1:
65
+ _state.sent();
66
+ _state.label = 2;
67
+ case 2:
68
+ return [
69
+ 2
70
+ ];
71
+ }
72
+ });
73
+ });
74
+ return function(filePath) {
75
+ return _ref.apply(this, arguments);
76
+ };
77
+ }());
78
+ watcher.on("unlink", function() {
79
+ var _ref = _async_to_generator(function(filePath) {
80
+ var changedFilePath;
81
+ return _ts_generator(this, function(_state) {
82
+ switch (_state.label) {
83
+ case 0:
84
+ changedFilePath = path.resolve(filePath);
85
+ return [
86
+ 4,
87
+ runTask({
88
+ changedFilePath: changedFilePath,
89
+ changeType: WatchChangeType.UNLINK
90
+ })
91
+ ];
92
+ case 1:
93
+ _state.sent();
94
+ return [
95
+ 2
96
+ ];
97
+ }
98
+ });
99
+ });
100
+ return function(filePath) {
101
+ return _ref.apply(this, arguments);
102
+ };
103
+ }());
104
+ watcher.on("error", function(err) {
38
105
  throw err;
39
106
  });
40
107
  return watcher;
@@ -28,6 +28,6 @@ export { default as browserslist } from "../compiled/browserslist";
28
28
  export { default as recursiveReaddir } from "../compiled/recursive-readdir";
29
29
  export { program, Command } from "../compiled/commander";
30
30
  export { Signale } from "../compiled/signale";
31
- export const mime = Import.lazy("../compiled/mime-types", require);
32
- export const chokidar = Import.lazy("../compiled/chokidar", require);
33
- export const inquirer = Import.lazy("../compiled/inquirer", require);
31
+ export var mime = Import.lazy("../compiled/mime-types", require);
32
+ export var chokidar = Import.lazy("../compiled/chokidar", require);
33
+ export var inquirer = Import.lazy("../compiled/inquirer", require);
@@ -1,8 +1,8 @@
1
- const lazy = (moduleName, requireFn) => {
2
- const importLazyLocal = require("../compiled/import-lazy")(requireFn);
1
+ var lazy = function(moduleName, requireFn) {
2
+ var importLazyLocal = require("../compiled/import-lazy")(requireFn);
3
3
  return importLazyLocal(moduleName);
4
4
  };
5
5
  export { lazy as lazyImport };
6
- export const Import = {
7
- lazy
6
+ export var Import = {
7
+ lazy: lazy
8
8
  };
@@ -1,19 +1,39 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
+ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
1
3
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
4
  import { Suspense } from "react";
3
5
  import { createRoutesFromElements, Route } from "react-router-dom";
4
- export const transformNestedRoutes = (routes) => {
5
- const routeElements = [];
6
- for (const route of routes) {
7
- const routeElement = renderNestedRoute(route);
8
- routeElements.push(routeElement);
6
+ export var transformNestedRoutes = function(routes) {
7
+ var routeElements = [];
8
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
9
+ try {
10
+ for (var _iterator = routes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
11
+ var route = _step.value;
12
+ var routeElement = renderNestedRoute(route);
13
+ routeElements.push(routeElement);
14
+ }
15
+ } catch (err) {
16
+ _didIteratorError = true;
17
+ _iteratorError = err;
18
+ } finally {
19
+ try {
20
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
21
+ _iterator.return();
22
+ }
23
+ } finally {
24
+ if (_didIteratorError) {
25
+ throw _iteratorError;
26
+ }
27
+ }
9
28
  }
10
29
  return createRoutesFromElements(routeElements);
11
30
  };
12
- export const renderNestedRoute = (nestedRoute, options = {}) => {
13
- const { children, index, id, component, isRoot, lazyImport, config, handle } = nestedRoute;
14
- const Component = component;
15
- const { parent, DeferredDataComponent, props = {} } = options;
16
- const routeProps = {
31
+ export var renderNestedRoute = function(nestedRoute) {
32
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
33
+ var children = nestedRoute.children, index = nestedRoute.index, id = nestedRoute.id, component = nestedRoute.component, isRoot = nestedRoute.isRoot, lazyImport = nestedRoute.lazyImport, config = nestedRoute.config, handle = nestedRoute.handle;
34
+ var Component = component;
35
+ var parent = options.parent, DeferredDataComponent = options.DeferredDataComponent, _options_props = options.props, props = _options_props === void 0 ? {} : _options_props;
36
+ var routeProps = {
17
37
  caseSensitive: nestedRoute.caseSensitive,
18
38
  path: nestedRoute.path,
19
39
  id: nestedRoute.id,
@@ -21,22 +41,19 @@ export const renderNestedRoute = (nestedRoute, options = {}) => {
21
41
  action: nestedRoute.action,
22
42
  hasErrorBoundary: nestedRoute.hasErrorBoundary,
23
43
  shouldRevalidate: nestedRoute.shouldRevalidate,
24
- handle: {
25
- ...handle,
26
- ...typeof config === "object" ? config === null || config === void 0 ? void 0 : config.handle : {}
27
- },
44
+ handle: _object_spread({}, handle, typeof config === "object" ? config === null || config === void 0 ? void 0 : config.handle : {}),
28
45
  index: nestedRoute.index,
29
46
  element: nestedRoute.element,
30
47
  errorElement: nestedRoute.errorElement
31
48
  };
32
49
  if (nestedRoute.error) {
33
- const errorElement = /* @__PURE__ */ _jsx(nestedRoute.error, {});
50
+ var errorElement = /* @__PURE__ */ _jsx(nestedRoute.error, {});
34
51
  routeProps.errorElement = errorElement;
35
52
  }
36
- let element;
53
+ var element;
37
54
  if (Component) {
38
55
  if ((parent === null || parent === void 0 ? void 0 : parent.loading) && lazyImport) {
39
- const Loading = parent.loading;
56
+ var Loading = parent.loading;
40
57
  if (isLoadableComponent(Component)) {
41
58
  element = /* @__PURE__ */ _jsx(Component, {
42
59
  fallback: /* @__PURE__ */ _jsx(Loading, {})
@@ -52,9 +69,7 @@ export const renderNestedRoute = (nestedRoute, options = {}) => {
52
69
  } else if (isRoot) {
53
70
  element = /* @__PURE__ */ _jsxs(_Fragment, {
54
71
  children: [
55
- /* @__PURE__ */ _jsx(Component, {
56
- ...props
57
- }),
72
+ /* @__PURE__ */ _jsx(Component, _object_spread({}, props)),
58
73
  typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ _jsx(DeferredDataComponent, {
59
74
  nonce: props === null || props === void 0 ? void 0 : props.nonce
60
75
  })
@@ -74,32 +89,30 @@ export const renderNestedRoute = (nestedRoute, options = {}) => {
74
89
  if (element) {
75
90
  routeProps.element = element;
76
91
  }
77
- const childElements = children === null || children === void 0 ? void 0 : children.map((childRoute) => {
92
+ var childElements = children === null || children === void 0 ? void 0 : children.map(function(childRoute) {
78
93
  return renderNestedRoute(childRoute, {
79
94
  parent: nestedRoute
80
95
  });
81
96
  });
82
- const routeElement = index ? /* @__PURE__ */ _jsx(Route, {
83
- ...routeProps,
97
+ var routeElement = index ? /* @__PURE__ */ _jsx(Route, _object_spread_props(_object_spread({}, routeProps), {
84
98
  index: true
85
- }, id) : /* @__PURE__ */ _jsx(Route, {
86
- ...routeProps,
99
+ }), id) : /* @__PURE__ */ _jsx(Route, _object_spread_props(_object_spread({}, routeProps), {
87
100
  index: false,
88
101
  children: childElements
89
- }, id);
102
+ }), id);
90
103
  return routeElement;
91
104
  };
92
105
  function createLoader(route) {
93
- const { loader } = route;
106
+ var loader = route.loader;
94
107
  if (loader) {
95
- return (args) => {
108
+ return function(args) {
96
109
  if (typeof route.lazyImport === "function") {
97
110
  route.lazyImport();
98
111
  }
99
112
  return loader(args);
100
113
  };
101
114
  } else {
102
- return () => {
115
+ return function() {
103
116
  if (typeof route.lazyImport === "function") {
104
117
  route.lazyImport();
105
118
  }
@@ -1,15 +1,15 @@
1
- export const parsedJSONFromElement = (id) => {
2
- const elements = document.querySelectorAll(`#${id}`);
1
+ export var parsedJSONFromElement = function(id) {
2
+ var elements = document.querySelectorAll("#".concat(id));
3
3
  if (elements.length === 0) {
4
4
  return void 0;
5
5
  }
6
- const element = elements[elements.length - 1];
6
+ var element = elements[elements.length - 1];
7
7
  if (element) {
8
8
  try {
9
- const parsed = JSON.parse((element === null || element === void 0 ? void 0 : element.textContent) || "");
9
+ var parsed = JSON.parse((element === null || element === void 0 ? void 0 : element.textContent) || "");
10
10
  return parsed;
11
11
  } catch (e) {
12
- console.error(`parse ${id} error`, e);
12
+ console.error("parse ".concat(id, " error"), e);
13
13
  return void 0;
14
14
  }
15
15
  }
@@ -1,5 +1,5 @@
1
1
  import { createStorage } from "./storage";
2
- const { run, useContext: useHeaders } = createStorage();
2
+ var _createStorage = createStorage(), run = _createStorage.run, useHeaders = _createStorage.useContext;
3
3
  export { run, useHeaders };
4
4
  export { serializeJson } from "./serialize";
5
5
  export * from "./nestedRoutes";
@@ -1,7 +1,7 @@
1
1
  function sortByUrlPath(entries) {
2
2
  entries.sort(function(a, b) {
3
- const length1 = a.urlPath.length;
4
- const length2 = b.urlPath.length;
3
+ var length1 = a.urlPath.length;
4
+ var length2 = b.urlPath.length;
5
5
  if (length1 < length2) {
6
6
  return 1;
7
7
  }
@@ -12,7 +12,9 @@ function sortByUrlPath(entries) {
12
12
  });
13
13
  return entries;
14
14
  }
15
- export const matchEntry = (pathname, entries) => {
15
+ export var matchEntry = function(pathname, entries) {
16
16
  sortByUrlPath(entries);
17
- return entries.find((entry) => pathname.startsWith(entry.urlPath));
17
+ return entries.find(function(entry) {
18
+ return pathname.startsWith(entry.urlPath);
19
+ });
18
20
  };
@@ -1,5 +1,5 @@
1
1
  import serialize from "serialize-javascript";
2
- export const serializeJson = (data) => {
2
+ export var serializeJson = function(data) {
3
3
  return serialize(data, {
4
4
  isJSON: true
5
5
  });
@@ -1,16 +1,15 @@
1
1
  import * as ah from "async_hooks";
2
- const createStorage = () => {
3
- let storage;
2
+ var createStorage = function() {
3
+ var storage;
4
4
  if (typeof ah.AsyncLocalStorage !== "undefined") {
5
5
  storage = new ah.AsyncLocalStorage();
6
6
  }
7
- const run = (context, cb) => {
7
+ var run = function(context, cb) {
8
8
  if (!storage) {
9
- throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
10
- `);
9
+ throw new Error("Unable to use async_hook, please confirm the node version >= 12.17\n ");
11
10
  }
12
- return new Promise((resolve, reject) => {
13
- storage.run(context, () => {
11
+ return new Promise(function(resolve, reject) {
12
+ storage.run(context, function() {
14
13
  try {
15
14
  return resolve(cb());
16
15
  } catch (error) {
@@ -19,20 +18,19 @@ const createStorage = () => {
19
18
  });
20
19
  });
21
20
  };
22
- const useContext = () => {
21
+ var useContext = function() {
23
22
  if (!storage) {
24
- throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
25
- `);
23
+ throw new Error("Unable to use async_hook, please confirm the node version >= 12.17\n ");
26
24
  }
27
- const context = storage.getStore();
25
+ var context = storage.getStore();
28
26
  if (!context) {
29
- throw new Error(`Can't call useContext out of scope, make sure @modern-js/utils is a single version in node_modules`);
27
+ throw new Error("Can't call useContext out of scope, make sure @modern-js/utils is a single version in node_modules");
30
28
  }
31
29
  return context;
32
30
  };
33
31
  return {
34
- run,
35
- useContext
32
+ run: run,
33
+ useContext: useContext
36
34
  };
37
35
  };
38
36
  export { createStorage };
@@ -1,3 +1,3 @@
1
- export const ROUTE_MANIFEST = `_MODERNJS_ROUTE_MANIFEST`;
2
- export const HMR_SOCK_PATH = "/webpack-hmr";
3
- export const HTML_CHUNKSMAP_SEPARATOR = "<!--<?- chunksMap.js ?>-->";
1
+ export var ROUTE_MANIFEST = "_MODERNJS_ROUTE_MANIFEST";
2
+ export var HMR_SOCK_PATH = "/webpack-hmr";
3
+ export var HTML_CHUNKSMAP_SEPARATOR = "<!--<?- chunksMap.js ?>-->";