@modern-js/utils 2.22.0 → 2.22.1-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. package/dist/FileSizeReporter.d.ts +16 -0
  2. package/dist/FileSizeReporter.js +162 -0
  3. package/dist/alias.d.ts +25 -0
  4. package/dist/alias.js +108 -0
  5. package/dist/analyzeProject.d.ts +2 -0
  6. package/dist/analyzeProject.js +71 -0
  7. package/dist/applyOptionsChain.d.ts +3 -0
  8. package/dist/applyOptionsChain.js +58 -0
  9. package/dist/babel.d.ts +3 -0
  10. package/dist/babel.js +136 -0
  11. package/dist/chainId.d.ts +244 -0
  12. package/dist/chainId.js +196 -0
  13. package/dist/cjs/cli/constants/index.js +4 -0
  14. package/dist/cjs/runtime-node/walk.js +1 -0
  15. package/dist/cjs/universal/constants.js +4 -0
  16. package/dist/clearConsole.d.ts +1 -0
  17. package/dist/clearConsole.js +31 -0
  18. package/dist/commands.d.ts +4 -0
  19. package/dist/commands.js +48 -0
  20. package/dist/compatRequire.d.ts +13 -0
  21. package/dist/compatRequire.js +82 -0
  22. package/dist/compiled.d.ts +43 -0
  23. package/dist/compiled.js +142 -0
  24. package/dist/constants.d.ts +244 -0
  25. package/dist/constants.js +320 -0
  26. package/dist/debug.d.ts +6 -0
  27. package/dist/debug.js +28 -0
  28. package/dist/emptyDir.d.ts +1 -0
  29. package/dist/emptyDir.js +52 -0
  30. package/dist/ensureAbsolutePath.d.ts +7 -0
  31. package/dist/ensureAbsolutePath.js +38 -0
  32. package/dist/ensureArray.d.ts +1 -0
  33. package/dist/ensureArray.js +32 -0
  34. package/dist/esm/cli/constants/index.js +1 -0
  35. package/dist/esm/runtime-node/walk.js +0 -0
  36. package/dist/esm/universal/constants.js +1 -0
  37. package/dist/findExists.d.ts +6 -0
  38. package/dist/findExists.js +45 -0
  39. package/dist/generateMetaTags.d.ts +16 -0
  40. package/dist/generateMetaTags.js +61 -0
  41. package/dist/getBrowserslist.d.ts +2 -0
  42. package/dist/getBrowserslist.js +31 -0
  43. package/dist/getCoreJsVersion.d.ts +1 -0
  44. package/dist/getCoreJsVersion.js +46 -0
  45. package/dist/getEntryOptions.d.ts +1 -0
  46. package/dist/getEntryOptions.js +54 -0
  47. package/dist/getPackageManager.d.ts +1 -0
  48. package/dist/getPackageManager.js +87 -0
  49. package/dist/getPort.d.ts +14 -0
  50. package/dist/getPort.js +112 -0
  51. package/dist/getServerConfig.d.ts +1 -0
  52. package/dist/getServerConfig.js +67 -0
  53. package/dist/getTargetDir.d.ts +1 -0
  54. package/dist/getTargetDir.js +41 -0
  55. package/dist/import.d.ts +5 -0
  56. package/dist/import.js +33 -0
  57. package/dist/index.d.ts +44 -0
  58. package/dist/index.js +60 -0
  59. package/dist/is/index.d.ts +58 -0
  60. package/dist/is/index.js +114 -0
  61. package/dist/is/nodeEnv.d.ts +8 -0
  62. package/dist/is/nodeEnv.js +39 -0
  63. package/dist/is/platform.d.ts +2 -0
  64. package/dist/is/platform.js +30 -0
  65. package/dist/is/type.d.ts +8 -0
  66. package/dist/is/type.js +64 -0
  67. package/dist/logger.d.ts +65 -0
  68. package/dist/logger.js +145 -0
  69. package/dist/monorepo.d.ts +11 -0
  70. package/dist/monorepo.js +137 -0
  71. package/dist/nodeEnv.d.ts +3 -0
  72. package/dist/nodeEnv.js +81 -0
  73. package/dist/path.d.ts +18 -0
  74. package/dist/path.js +92 -0
  75. package/dist/pathSerializer.d.ts +16 -0
  76. package/dist/pathSerializer.js +76 -0
  77. package/dist/plugin.d.ts +2 -0
  78. package/dist/plugin.js +46 -0
  79. package/dist/prettyInstructions.d.ts +9 -0
  80. package/dist/prettyInstructions.js +112 -0
  81. package/dist/printBuildError.d.ts +8 -0
  82. package/dist/printBuildError.js +57 -0
  83. package/dist/react.d.ts +1 -0
  84. package/dist/react.js +64 -0
  85. package/dist/readTsConfig.d.ts +2 -0
  86. package/dist/readTsConfig.js +47 -0
  87. package/dist/removeSlash.d.ts +3 -0
  88. package/dist/removeSlash.js +33 -0
  89. package/dist/resolve.d.ts +13 -0
  90. package/dist/resolve.js +63 -0
  91. package/dist/routes.d.ts +2 -0
  92. package/dist/routes.js +58 -0
  93. package/dist/runtimeExports.d.ts +4 -0
  94. package/dist/runtimeExports.js +73 -0
  95. package/dist/ssr.d.ts +8 -0
  96. package/dist/ssr.js +30 -0
  97. package/dist/storage.d.ts +5 -0
  98. package/dist/storage.js +75 -0
  99. package/dist/testUtils.d.ts +5 -0
  100. package/dist/testUtils.js +38 -0
  101. package/dist/types/cli/constants/index.d.ts +4 -0
  102. package/dist/types/runtime-node/walk.d.ts +0 -0
  103. package/dist/types/universal/constants.d.ts +5 -1
  104. package/dist/types.d.ts +1 -0
  105. package/dist/types.js +15 -0
  106. package/dist/universal/constants.d.ts +9 -0
  107. package/dist/universal/constants.js +30 -0
  108. package/dist/universal/formatWebpack.d.ts +13 -0
  109. package/dist/universal/formatWebpack.js +100 -0
  110. package/dist/universal/nestedRoutes.d.ts +8 -0
  111. package/dist/universal/nestedRoutes.js +131 -0
  112. package/dist/universal/remixRouter.d.ts +1 -0
  113. package/dist/universal/remixRouter.js +17 -0
  114. package/dist/universal/serialize.d.ts +1 -0
  115. package/dist/universal/serialize.js +40 -0
  116. package/dist/version.d.ts +2 -0
  117. package/dist/version.js +92 -0
  118. package/dist/wait.d.ts +2 -0
  119. package/dist/wait.js +29 -0
  120. package/dist/watch.d.ts +8 -0
  121. package/dist/watch.js +90 -0
  122. package/package.json +12 -3
@@ -0,0 +1,33 @@
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 removeSlash_exports = {};
19
+ __export(removeSlash_exports, {
20
+ removeLeadingSlash: () => removeLeadingSlash,
21
+ removeSlash: () => removeSlash,
22
+ removeTailSlash: () => removeTailSlash
23
+ });
24
+ module.exports = __toCommonJS(removeSlash_exports);
25
+ const removeLeadingSlash = (s) => s.replace(/^\/+/, "");
26
+ const removeTailSlash = (s) => s.replace(/\/+$/, "");
27
+ const removeSlash = (s) => removeLeadingSlash(removeTailSlash(s));
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ removeLeadingSlash,
31
+ removeSlash,
32
+ removeTailSlash
33
+ });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Try to resolve npm package entry file path.
3
+ * @param name - Package name.
4
+ * @param resolvePath - Path to resolve dependencies.
5
+ * @returns Resolved file path.
6
+ */
7
+ export declare const tryResolve: (name: string, resolvePath: string) => string;
8
+ /**
9
+ * Try to resolve npm package, return true if package is installed.
10
+ */
11
+
12
+ export declare const isPackageInstalled: (name: string, resolvePaths: string | string[]) => boolean;
13
+ export declare const getAntdMajorVersion: (appDirectory: string) => number | null;
@@ -0,0 +1,63 @@
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 resolve_exports = {};
19
+ __export(resolve_exports, {
20
+ getAntdMajorVersion: () => getAntdMajorVersion,
21
+ isPackageInstalled: () => isPackageInstalled,
22
+ tryResolve: () => tryResolve
23
+ });
24
+ module.exports = __toCommonJS(resolve_exports);
25
+ var import_ensureArray = require("./ensureArray");
26
+ const tryResolve = (name, resolvePath) => {
27
+ let filePath = "";
28
+ try {
29
+ filePath = require.resolve(name, { paths: [resolvePath] });
30
+ delete require.cache[filePath];
31
+ } catch (err) {
32
+ if (err.code === "MODULE_NOT_FOUND") {
33
+ throw new Error(`Can not find module ${name}.`);
34
+ }
35
+ throw err;
36
+ }
37
+ return filePath;
38
+ };
39
+ const isPackageInstalled = (name, resolvePaths) => {
40
+ try {
41
+ require.resolve(name, { paths: (0, import_ensureArray.ensureArray)(resolvePaths) });
42
+ return true;
43
+ } catch (err) {
44
+ return false;
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
+ };
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ getAntdMajorVersion,
61
+ isPackageInstalled,
62
+ tryResolve
63
+ });
@@ -0,0 +1,2 @@
1
+ export declare const getPathWithoutExt: (filename: string) => string;
2
+ export declare const getRouteId: (componentPath: string, routesDir: string, entryName: string) => string;
package/dist/routes.js ADDED
@@ -0,0 +1,58 @@
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 routes_exports = {};
29
+ __export(routes_exports, {
30
+ getPathWithoutExt: () => getPathWithoutExt,
31
+ getRouteId: () => getRouteId
32
+ });
33
+ module.exports = __toCommonJS(routes_exports);
34
+ var import_path = __toESM(require("path"));
35
+ var import_path2 = require("./path");
36
+ var import_constants = require("./constants");
37
+ const getPathWithoutExt = (filename) => {
38
+ const extname = import_path.default.extname(filename);
39
+ return filename.slice(0, -extname.length);
40
+ };
41
+ const getRouteId = (componentPath, routesDir, entryName) => {
42
+ const relativePath = (0, import_path2.normalizeToPosixPath)(
43
+ import_path.default.relative(routesDir, componentPath)
44
+ );
45
+ const pathWithoutExt = getPathWithoutExt(relativePath);
46
+ let id = ``;
47
+ if (entryName === import_constants.MAIN_ENTRY_NAME) {
48
+ id = pathWithoutExt;
49
+ } else {
50
+ id = `${entryName}_${pathWithoutExt}`;
51
+ }
52
+ return id;
53
+ };
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ getPathWithoutExt,
57
+ getRouteId
58
+ });
@@ -0,0 +1,4 @@
1
+ export declare const createRuntimeExportsUtils: (pwd?: any, namespace?: any) => {
2
+ addExport: (statement: string) => void;
3
+ getPath: () => string;
4
+ };
@@ -0,0 +1,73 @@
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 runtimeExports_exports = {};
29
+ __export(runtimeExports_exports, {
30
+ createRuntimeExportsUtils: () => createRuntimeExportsUtils
31
+ });
32
+ module.exports = __toCommonJS(runtimeExports_exports);
33
+ var import_path = __toESM(require("path"));
34
+ var import_compiled = require("./compiled");
35
+ var import_path2 = require("./path");
36
+ const memo = (fn) => {
37
+ const cache = /* @__PURE__ */ new Map();
38
+ return (...params) => {
39
+ const stringifiedParams = JSON.stringify(params);
40
+ const cachedResult = cache.get(stringifiedParams);
41
+ if (cachedResult) {
42
+ return cachedResult;
43
+ }
44
+ const res = fn(...params);
45
+ cache.set(stringifiedParams, res);
46
+ return res;
47
+ };
48
+ };
49
+ const createRuntimeExportsUtils = memo(
50
+ (pwd = "", namespace = "index") => {
51
+ const entryExportFile = import_path.default.join(pwd, `.runtime-exports/${namespace}.js`);
52
+ const addExport = (statement) => {
53
+ statement = (0, import_path2.normalizeOutputPath)(statement);
54
+ try {
55
+ import_compiled.fs.ensureFileSync(entryExportFile);
56
+ if (!import_compiled.fs.readFileSync(entryExportFile, "utf8").includes(statement)) {
57
+ import_compiled.fs.appendFileSync(entryExportFile, `${statement}
58
+ `);
59
+ }
60
+ } catch (e) {
61
+ }
62
+ };
63
+ const getPath = () => entryExportFile;
64
+ return {
65
+ addExport,
66
+ getPath
67
+ };
68
+ }
69
+ );
70
+ // Annotate the CommonJS export names for ESM import in node:
71
+ 0 && (module.exports = {
72
+ createRuntimeExportsUtils
73
+ });
package/dist/ssr.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+
3
+ /**
4
+ * ssr helpers
5
+ */
6
+ import type { IncomingHttpHeaders } from 'http';
7
+ declare const run: <O>(context: IncomingHttpHeaders, cb: () => O | Promise<O>) => Promise<O>, useHeaders: () => IncomingHttpHeaders;
8
+ export { run, useHeaders };
package/dist/ssr.js ADDED
@@ -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 ssr_exports = {};
19
+ __export(ssr_exports, {
20
+ run: () => run,
21
+ useHeaders: () => useHeaders
22
+ });
23
+ module.exports = __toCommonJS(ssr_exports);
24
+ var import_storage = require("./storage");
25
+ const { run, useContext: useHeaders } = (0, import_storage.createStorage)();
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ run,
29
+ useHeaders
30
+ });
@@ -0,0 +1,5 @@
1
+ declare const createStorage: <T>() => {
2
+ run: <O>(context: T, cb: () => O | Promise<O>) => Promise<O>;
3
+ useContext: () => T;
4
+ };
5
+ export { createStorage };
@@ -0,0 +1,75 @@
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 storage_exports = {};
29
+ __export(storage_exports, {
30
+ createStorage: () => createStorage
31
+ });
32
+ module.exports = __toCommonJS(storage_exports);
33
+ var ah = __toESM(require("async_hooks"));
34
+ const createStorage = () => {
35
+ let storage;
36
+ if (typeof ah.AsyncLocalStorage !== "undefined") {
37
+ storage = new ah.AsyncLocalStorage();
38
+ }
39
+ const run = (context, cb) => {
40
+ if (!storage) {
41
+ throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
42
+ `);
43
+ }
44
+ return new Promise((resolve, reject) => {
45
+ storage.run(context, () => {
46
+ try {
47
+ return resolve(cb());
48
+ } catch (error) {
49
+ return reject(error);
50
+ }
51
+ });
52
+ });
53
+ };
54
+ const useContext = () => {
55
+ if (!storage) {
56
+ throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
57
+ `);
58
+ }
59
+ const context = storage.getStore();
60
+ if (!context) {
61
+ throw new Error(
62
+ `Can't call useContext out of scope, make sure @modern-js/utils is a single version in node_modules`
63
+ );
64
+ }
65
+ return context;
66
+ };
67
+ return {
68
+ run,
69
+ useContext
70
+ };
71
+ };
72
+ // Annotate the CommonJS export names for ESM import in node:
73
+ 0 && (module.exports = {
74
+ createStorage
75
+ });
@@ -0,0 +1,5 @@
1
+ /**
2
+ *
3
+ * remove the path before "modern.js"
4
+ */
5
+ export declare const initSnapshotSerializer: (root: string) => void;
@@ -0,0 +1,38 @@
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 testUtils_exports = {};
19
+ __export(testUtils_exports, {
20
+ initSnapshotSerializer: () => initSnapshotSerializer
21
+ });
22
+ module.exports = __toCommonJS(testUtils_exports);
23
+ const initSnapshotSerializer = (root) => {
24
+ expect.addSnapshotSerializer({
25
+ test: (val) => typeof val === "string" && (val.includes("modern.js") || val.includes("node_modules") || val.includes(root)),
26
+ print: (val) => (
27
+ // eslint-disable-next-line no-nested-ternary
28
+ typeof val === "string" ? (
29
+ // eslint-disable-next-line no-nested-ternary
30
+ val.includes("node_modules") ? `"${val.replace(/.+node_modules/, ``).replace(/\\/g, "/")}"` : val.includes("modern.js") ? `"${val.replace(/.+modern\.js/, ``).replace(/\\/g, "/")}"` : `"${val.replace(root, "").replace(/\\/g, "/")}"`
31
+ ) : val
32
+ )
33
+ });
34
+ };
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ initSnapshotSerializer
38
+ });
@@ -3,6 +3,10 @@ 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";
6
10
  /**
7
11
  * main entry name
8
12
  */
File without changes
@@ -5,4 +5,8 @@ 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";
8
+ export declare const HMR_SOCK_PATH = "/webpack-hmr";
9
+ /**
10
+ * html placeholder
11
+ */
12
+ export declare const HTML_CHUNKSMAP_SEPARATOR = "<!--<?- chunksMap.js ?>-->";
@@ -0,0 +1 @@
1
+ export type Falsy = false | null | undefined | 0 | '';
package/dist/types.js ADDED
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var types_exports = {};
15
+ module.exports = __toCommonJS(types_exports);
@@ -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
+ });
@@ -0,0 +1,13 @@
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
+ import type { StatsCompilation } from 'webpack';
9
+ declare function formatWebpackMessages(json?: Pick<StatsCompilation, 'errors' | 'warnings'>): {
10
+ errors: string[];
11
+ warnings: string[];
12
+ };
13
+ export { formatWebpackMessages };
@@ -0,0 +1,100 @@
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 formatWebpack_exports = {};
19
+ __export(formatWebpack_exports, {
20
+ formatWebpackMessages: () => formatWebpackMessages
21
+ });
22
+ module.exports = __toCommonJS(formatWebpack_exports);
23
+ const friendlySyntaxErrorLabel = "SyntaxError:";
24
+ function isLikelyASyntaxError(message) {
25
+ return message.includes(friendlySyntaxErrorLabel);
26
+ }
27
+ function formatMessage(stats) {
28
+ let lines = [];
29
+ let message;
30
+ if (typeof stats === "object") {
31
+ const fileName = stats.moduleName ? `File: ${stats.moduleName}
32
+ ` : "";
33
+ const mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
34
+ const details = stats.details ? `
35
+ Details: ${stats.details}
36
+ ` : "";
37
+ const stack = stats.stack ? `
38
+ ${stats.stack}` : "";
39
+ message = `${fileName}${mainMessage}${details}${stack}`;
40
+ } else {
41
+ message = stats;
42
+ }
43
+ lines = message.split("\n");
44
+ lines = lines.map((line) => {
45
+ const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(
46
+ line
47
+ );
48
+ if (!parsingError) {
49
+ return line;
50
+ }
51
+ const [, errorLine, errorColumn, errorMessage] = parsingError;
52
+ return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
53
+ });
54
+ message = lines.join("\n");
55
+ message = message.replace(
56
+ /SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g,
57
+ `${friendlySyntaxErrorLabel} $3 ($1:$2)
58
+ `
59
+ );
60
+ lines = message.split("\n");
61
+ if (lines.length > 2 && lines[1].trim() === "") {
62
+ lines.splice(1, 1);
63
+ }
64
+ lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, "$1");
65
+ if (lines[1] && lines[1].indexOf("Module not found:") !== -1) {
66
+ lines[1] = lines[1].replace("Error: ", "");
67
+ }
68
+ message = lines.join("\n");
69
+ message = message.replace(
70
+ /^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm,
71
+ ""
72
+ );
73
+ message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, "");
74
+ lines = message.split("\n");
75
+ lines = lines.filter(
76
+ (line, index, arr) => index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim()
77
+ );
78
+ message = lines.join("\n");
79
+ return message.trim();
80
+ }
81
+ function formatWebpackMessages(json) {
82
+ var _a, _b, _c;
83
+ const formattedErrors = (_a = json == null ? void 0 : json.errors) == null ? void 0 : _a.map(formatMessage);
84
+ const formattedWarnings = (_b = json == null ? void 0 : json.warnings) == null ? void 0 : _b.map(formatMessage);
85
+ const result = {
86
+ errors: formattedErrors || [],
87
+ warnings: formattedWarnings || []
88
+ };
89
+ if ((_c = result.errors) == null ? void 0 : _c.some(isLikelyASyntaxError)) {
90
+ result.errors = result.errors.filter(isLikelyASyntaxError);
91
+ }
92
+ if (result.errors.length > 1) {
93
+ result.errors.length = 1;
94
+ }
95
+ return result;
96
+ }
97
+ // Annotate the CommonJS export names for ESM import in node:
98
+ 0 && (module.exports = {
99
+ formatWebpackMessages
100
+ });
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import type { NestedRoute } from '@modern-js/types';
3
+ export declare const transformNestedRoutes: (routes: NestedRoute[]) => import("react-router-dom").RouteObject[];
4
+ export declare const renderNestedRoute: (nestedRoute: NestedRoute, options?: {
5
+ parent?: NestedRoute;
6
+ DeferredDataComponent?: () => JSX.Element | null;
7
+ props?: Record<string, any>;
8
+ }) => JSX.Element;