@modern-js/utils 2.4.0 → 2.5.0-alpha.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 (108) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/FileSizeReporter.d.ts +5 -5
  3. package/dist/FileSizeReporter.js +143 -136
  4. package/dist/alias.d.ts +16 -14
  5. package/dist/alias.js +94 -54
  6. package/dist/analyzeProject.d.ts +1 -1
  7. package/dist/analyzeProject.js +58 -33
  8. package/dist/applyOptionsChain.d.ts +1 -1
  9. package/dist/applyOptionsChain.js +55 -27
  10. package/dist/chainId.d.ts +256 -184
  11. package/dist/chainId.js +132 -187
  12. package/dist/clearConsole.d.ts +1 -1
  13. package/dist/clearConsole.js +29 -7
  14. package/dist/commands.d.ts +1 -1
  15. package/dist/commands.js +33 -10
  16. package/dist/compatRequire.d.ts +3 -3
  17. package/dist/compatRequire.js +74 -38
  18. package/dist/compiled.d.ts +2 -1
  19. package/dist/compiled.js +137 -72
  20. package/dist/constants.d.ts +131 -105
  21. package/dist/constants.js +298 -277
  22. package/dist/debug.d.ts +1 -1
  23. package/dist/debug.js +28 -11
  24. package/dist/emptyDir.d.ts +1 -1
  25. package/dist/emptyDir.js +51 -9
  26. package/dist/ensureAbsolutePath.d.ts +1 -1
  27. package/dist/ensureAbsolutePath.js +33 -14
  28. package/dist/ensureArray.d.ts +1 -1
  29. package/dist/ensureArray.js +30 -8
  30. package/dist/findExists.d.ts +1 -1
  31. package/dist/findExists.js +37 -17
  32. package/dist/format.d.ts +3 -3
  33. package/dist/format.js +93 -81
  34. package/dist/generateMetaTags.d.ts +4 -4
  35. package/dist/generateMetaTags.js +56 -43
  36. package/dist/getBrowserslist.d.ts +1 -1
  37. package/dist/getBrowserslist.js +31 -7
  38. package/dist/getCoreJsVersion.d.ts +1 -1
  39. package/dist/getCoreJsVersion.js +39 -35
  40. package/dist/getEntryOptions.d.ts +1 -1
  41. package/dist/getEntryOptions.js +51 -24
  42. package/dist/getPackageManager.d.ts +1 -1
  43. package/dist/getPackageManager.js +75 -28
  44. package/dist/getPort.d.ts +7 -4
  45. package/dist/getPort.js +104 -58
  46. package/dist/getServerConfig.d.ts +1 -1
  47. package/dist/getServerConfig.js +61 -32
  48. package/dist/import.d.ts +2 -2
  49. package/dist/import.js +31 -8
  50. package/dist/index.d.ts +2 -0
  51. package/dist/index.js +61 -59
  52. package/dist/is/index.d.ts +12 -1
  53. package/dist/is/index.js +83 -82
  54. package/dist/is/node-env.d.ts +1 -1
  55. package/dist/is/node-env.js +39 -17
  56. package/dist/is/platform.d.ts +1 -1
  57. package/dist/is/platform.js +30 -10
  58. package/dist/is/type.d.ts +1 -1
  59. package/dist/is/type.js +48 -22
  60. package/dist/logger.d.ts +51 -51
  61. package/dist/logger.js +127 -95
  62. package/dist/monorepo.d.ts +3 -3
  63. package/dist/monorepo.js +117 -74
  64. package/dist/nestedRoutes.d.ts +9 -0
  65. package/dist/nestedRoutes.js +144 -0
  66. package/dist/nodeEnv.d.ts +1 -1
  67. package/dist/nodeEnv.js +72 -25
  68. package/dist/path.d.ts +3 -1
  69. package/dist/path.js +76 -59
  70. package/dist/pathSerializer.d.ts +7 -7
  71. package/dist/pathSerializer.js +65 -43
  72. package/dist/plugin.d.ts +1 -1
  73. package/dist/plugin.js +45 -26
  74. package/dist/prettyInstructions.d.ts +4 -4
  75. package/dist/prettyInstructions.js +107 -65
  76. package/dist/printBuildError.d.ts +1 -1
  77. package/dist/printBuildError.js +54 -40
  78. package/dist/react.d.ts +1 -1
  79. package/dist/react.js +57 -21
  80. package/dist/readTsConfig.d.ts +1 -1
  81. package/dist/readTsConfig.js +38 -12
  82. package/dist/remix-router.d.ts +1 -0
  83. package/dist/remix-router.js +17 -0
  84. package/dist/removeSlash.d.ts +1 -1
  85. package/dist/removeSlash.js +33 -9
  86. package/dist/routes.d.ts +1 -1
  87. package/dist/routes.js +49 -22
  88. package/dist/runtimeExports.d.ts +3 -3
  89. package/dist/runtimeExports.js +59 -39
  90. package/dist/serialize.d.ts +1 -0
  91. package/dist/serialize.js +36 -0
  92. package/dist/ssr.d.ts +2 -1
  93. package/dist/ssr.js +30 -7
  94. package/dist/storage.d.ts +3 -3
  95. package/dist/storage.js +65 -59
  96. package/dist/test-utils.d.ts +1 -1
  97. package/dist/test-utils.js +30 -24
  98. package/dist/tryResolve.d.ts +2 -1
  99. package/dist/tryResolve.js +45 -33
  100. package/dist/types.d.ts +1 -1
  101. package/dist/types.js +15 -2
  102. package/dist/version.d.ts +1 -1
  103. package/dist/version.js +83 -24
  104. package/dist/wait.d.ts +1 -1
  105. package/dist/wait.js +28 -6
  106. package/dist/watch.d.ts +5 -5
  107. package/dist/watch.js +82 -55
  108. package/package.json +31 -9
package/dist/wait.js CHANGED
@@ -1,7 +1,29 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wait = void 0;
4
- const wait = (time = 0) => new Promise(resolve => {
5
- setTimeout(resolve, time);
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 wait_exports = {};
19
+ __export(wait_exports, {
20
+ wait: () => wait
21
+ });
22
+ module.exports = __toCommonJS(wait_exports);
23
+ const wait = (time = 0) => new Promise((resolve) => {
24
+ setTimeout(resolve, time);
25
+ });
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ wait
6
29
  });
7
- exports.wait = wait;
package/dist/watch.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export type WatchChangeTypeValueT = 'add' | 'unlink' | 'change';
1
+ export declare type WatchChangeTypeValueT = 'add' | 'unlink' | 'change';
2
2
  export declare const WatchChangeType: Record<'ADD' | 'UNLINK' | 'CHANGE', WatchChangeTypeValueT>;
3
- type RunTaskType = (option: {
4
- changedFilePath: string;
5
- changeType: WatchChangeTypeValueT;
3
+ declare type RunTaskType = (option: {
4
+ changedFilePath: string;
5
+ changeType: WatchChangeTypeValueT;
6
6
  }) => void | Promise<void>;
7
7
  export declare const watch: (watchDir: string | string[], runTask: RunTaskType, ignored?: string[]) => import("./compiled").FSWatcher;
8
- export {};
8
+ export {};
package/dist/watch.js CHANGED
@@ -1,59 +1,86 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
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 });
24
10
  };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.watch = exports.WatchChangeType = void 0;
27
- const path = __importStar(require("path"));
28
- const compiled_1 = require("./compiled");
29
- exports.WatchChangeType = {
30
- ADD: 'add',
31
- UNLINK: 'unlink',
32
- CHANGE: 'change',
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
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var __async = (__this, __arguments, generator) => {
25
+ return new Promise((resolve, reject) => {
26
+ var fulfilled = (value) => {
27
+ try {
28
+ step(generator.next(value));
29
+ } catch (e) {
30
+ reject(e);
31
+ }
32
+ };
33
+ var rejected = (value) => {
34
+ try {
35
+ step(generator.throw(value));
36
+ } catch (e) {
37
+ reject(e);
38
+ }
39
+ };
40
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
41
+ step((generator = generator.apply(__this, __arguments)).next());
42
+ });
43
+ };
44
+ var watch_exports = {};
45
+ __export(watch_exports, {
46
+ WatchChangeType: () => WatchChangeType,
47
+ watch: () => watch
48
+ });
49
+ module.exports = __toCommonJS(watch_exports);
50
+ var path = __toESM(require("path"));
51
+ var import_compiled = require("./compiled");
52
+ const WatchChangeType = {
53
+ ADD: "add",
54
+ UNLINK: "unlink",
55
+ CHANGE: "change"
33
56
  };
34
57
  const watch = (watchDir, runTask, ignored = []) => {
35
- let ready = false;
36
- const watcher = compiled_1.chokidar.watch(watchDir, {
37
- ignored,
38
- });
39
- watcher.on('ready', () => (ready = true));
40
- watcher.on('change', async (filePath) => {
41
- const changedFilePath = path.resolve(filePath);
42
- await runTask({ changedFilePath, changeType: exports.WatchChangeType.CHANGE });
43
- });
44
- watcher.on('add', async (filePath) => {
45
- const changedFilePath = path.resolve(filePath);
46
- if (ready) {
47
- await runTask({ changedFilePath, changeType: exports.WatchChangeType.ADD });
48
- }
49
- });
50
- watcher.on('unlink', async (filePath) => {
51
- const changedFilePath = path.resolve(filePath);
52
- await runTask({ changedFilePath, changeType: exports.WatchChangeType.UNLINK });
53
- });
54
- watcher.on('error', err => {
55
- throw err;
56
- });
57
- return watcher;
58
+ let ready = false;
59
+ const watcher = import_compiled.chokidar.watch(watchDir, {
60
+ ignored
61
+ });
62
+ watcher.on("ready", () => ready = true);
63
+ watcher.on("change", (filePath) => __async(void 0, null, function* () {
64
+ const changedFilePath = path.resolve(filePath);
65
+ yield runTask({ changedFilePath, changeType: WatchChangeType.CHANGE });
66
+ }));
67
+ watcher.on("add", (filePath) => __async(void 0, null, function* () {
68
+ const changedFilePath = path.resolve(filePath);
69
+ if (ready) {
70
+ yield runTask({ changedFilePath, changeType: WatchChangeType.ADD });
71
+ }
72
+ }));
73
+ watcher.on("unlink", (filePath) => __async(void 0, null, function* () {
74
+ const changedFilePath = path.resolve(filePath);
75
+ yield runTask({ changedFilePath, changeType: WatchChangeType.UNLINK });
76
+ }));
77
+ watcher.on("error", (err) => {
78
+ throw err;
79
+ });
80
+ return watcher;
58
81
  };
59
- exports.watch = watch;
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ WatchChangeType,
85
+ watch
86
+ });
package/package.json CHANGED
@@ -11,12 +11,11 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.4.0",
14
+ "version": "2.5.0-alpha.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/index.d.ts",
17
17
  "main": "./dist/index.js",
18
18
  "module": "./dist/index.js",
19
- "jsnext:modern": "./dist/index.js",
20
19
  "_comment": "Provide ESM and CJS exports, ESM is used by runtime package, for treeshaking",
21
20
  "exports": {
22
21
  ".": "./dist/index.js",
@@ -24,6 +23,9 @@
24
23
  "./format": "./dist/format.js",
25
24
  "./logger": "./dist/logger.js",
26
25
  "./constants": "./dist/constants.js",
26
+ "./serialize": "./dist/serialize.js",
27
+ "./nestedRoutes": "./dist/nestedRoutes.js",
28
+ "./remix-router": "./dist/remix-router.js",
27
29
  "./ajv": "./compiled/ajv/index.js",
28
30
  "./glob": "./compiled/glob/index.js",
29
31
  "./chalk": "./compiled/chalk/index.js",
@@ -62,6 +64,12 @@
62
64
  "constants": [
63
65
  "./dist/constants.d.ts"
64
66
  ],
67
+ "serialize": [
68
+ "./dist/serialize.d.ts"
69
+ ],
70
+ "nestedRoutes": [
71
+ "./dist/nestedRoutes.d.ts"
72
+ ],
65
73
  "ajv": [
66
74
  "./compiled/ajv/types/ajv.d.ts"
67
75
  ],
@@ -121,28 +129,42 @@
121
129
  ],
122
130
  "chain-id": [
123
131
  "./dist/chainId.d.ts"
132
+ ],
133
+ "remix-router": [
134
+ "./dist/remix-router.d.ts"
124
135
  ]
125
136
  }
126
137
  },
127
138
  "dependencies": {
128
- "caniuse-lite": "^1.0.30001332",
129
- "lodash": "^4.17.21"
139
+ "caniuse-lite": "^1.0.30001451",
140
+ "lodash": "^4.17.21",
141
+ "serialize-javascript": "^6.0.0",
142
+ "@remix-run/router": "^1.3.2"
143
+ },
144
+ "peerDependencies": {
145
+ "react": ">=17.0.0",
146
+ "react-dom": ">=17.0.0",
147
+ "react-router-dom": "^6.8.1"
130
148
  },
131
149
  "devDependencies": {
150
+ "react": ">=17.0.0",
151
+ "react-dom": ">=17.0.0",
152
+ "react-router-dom": "^6.8.1",
132
153
  "@types/jest": "^27",
133
154
  "@types/node": "^14",
134
155
  "jest": "^27",
135
156
  "typescript": "^4",
136
157
  "webpack": "^5.75.0",
137
- "@modern-js/types": "2.4.0",
138
- "@scripts/jest-config": "2.4.0",
139
- "@scripts/build": "2.4.0"
158
+ "@types/serialize-javascript": "^5.0.1",
159
+ "@modern-js/types": "2.5.0",
160
+ "@scripts/build": "2.5.0",
161
+ "@scripts/jest-config": "2.5.0"
140
162
  },
141
163
  "sideEffects": false,
142
164
  "scripts": {
143
165
  "new": "modern-lib new",
144
- "dev": "tsc --watch",
145
- "build": "tsc",
166
+ "dev": "modern-lib build --watch",
167
+ "build": "modern-lib build",
146
168
  "test": "jest --passWithNoTests"
147
169
  }
148
170
  }