@modern-js/utils 2.35.0 → 2.35.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. package/dist/cjs/cli/alias.js +3 -3
  2. package/dist/cjs/cli/constants/chainId.js +3 -3
  3. package/dist/cjs/cli/is/config.js +9 -11
  4. package/dist/cjs/cli/logger.js +6 -1
  5. package/dist/cjs/cli/port.js +1 -1
  6. package/dist/cjs/cli/prettyInstructions.js +2 -5
  7. package/dist/cjs/cli/require.js +1 -2
  8. package/dist/cjs/universal/formatWebpack.js +3 -3
  9. package/dist/esm/cli/alias.js +3 -3
  10. package/dist/esm/cli/constants/chainId.js +3 -3
  11. package/dist/esm/cli/is/config.js +9 -11
  12. package/dist/esm/cli/logger.js +6 -1
  13. package/dist/esm/cli/port.js +1 -1
  14. package/dist/esm/cli/prettyInstructions.js +2 -3
  15. package/dist/esm/cli/require.js +1 -2
  16. package/dist/esm/universal/formatWebpack.js +3 -3
  17. package/dist/esm-node/cli/alias.js +3 -3
  18. package/dist/esm-node/cli/constants/chainId.js +3 -3
  19. package/dist/esm-node/cli/is/config.js +9 -11
  20. package/dist/esm-node/cli/logger.js +6 -1
  21. package/dist/esm-node/cli/port.js +1 -1
  22. package/dist/esm-node/cli/prettyInstructions.js +2 -5
  23. package/dist/esm-node/cli/require.js +1 -2
  24. package/dist/esm-node/universal/formatWebpack.js +3 -3
  25. package/dist/types/cli/constants/chainId.d.ts +2 -2
  26. package/dist/types/cli/logger.d.ts +5 -0
  27. package/package.json +4 -75
  28. package/dist/cjs/runtime/nestedRoutes.js +0 -149
  29. package/dist/cjs/runtime/remixRouter.js +0 -6
  30. package/dist/cjs/runtime/router.js +0 -6
  31. package/dist/cjs/runtime-browser/index.js +0 -6
  32. package/dist/cjs/runtime-browser/parsed.js +0 -28
  33. package/dist/cjs/runtime-node/index.js +0 -28
  34. package/dist/cjs/runtime-node/loaderContext/createLoaderCtx.js +0 -34
  35. package/dist/cjs/runtime-node/loaderContext/createRequestCtx.js +0 -38
  36. package/dist/cjs/runtime-node/loaderContext/index.js +0 -22
  37. package/dist/cjs/runtime-node/nestedRoutes.js +0 -28
  38. package/dist/cjs/runtime-node/router.js +0 -6
  39. package/dist/cjs/runtime-node/serialize.js +0 -17
  40. package/dist/cjs/runtime-node/storage.js +0 -48
  41. package/dist/cjs/universal/time.js +0 -38
  42. package/dist/esm/runtime/nestedRoutes.js +0 -163
  43. package/dist/esm/runtime/remixRouter.js +0 -1
  44. package/dist/esm/runtime/router.js +0 -1
  45. package/dist/esm/runtime-browser/index.js +0 -1
  46. package/dist/esm/runtime-browser/parsed.js +0 -18
  47. package/dist/esm/runtime-node/index.js +0 -6
  48. package/dist/esm/runtime-node/loaderContext/createLoaderCtx.js +0 -20
  49. package/dist/esm/runtime-node/loaderContext/createRequestCtx.js +0 -24
  50. package/dist/esm/runtime-node/loaderContext/index.js +0 -3
  51. package/dist/esm/runtime-node/nestedRoutes.js +0 -20
  52. package/dist/esm/runtime-node/router.js +0 -1
  53. package/dist/esm/runtime-node/serialize.js +0 -6
  54. package/dist/esm/runtime-node/storage.js +0 -36
  55. package/dist/esm/universal/time.js +0 -29
  56. package/dist/esm-node/runtime/nestedRoutes.js +0 -129
  57. package/dist/esm-node/runtime/remixRouter.js +0 -1
  58. package/dist/esm-node/runtime/router.js +0 -1
  59. package/dist/esm-node/runtime-browser/index.js +0 -1
  60. package/dist/esm-node/runtime-browser/parsed.js +0 -18
  61. package/dist/esm-node/runtime-node/index.js +0 -6
  62. package/dist/esm-node/runtime-node/loaderContext/createLoaderCtx.js +0 -15
  63. package/dist/esm-node/runtime-node/loaderContext/createRequestCtx.js +0 -19
  64. package/dist/esm-node/runtime-node/loaderContext/index.js +0 -3
  65. package/dist/esm-node/runtime-node/nestedRoutes.js +0 -18
  66. package/dist/esm-node/runtime-node/router.js +0 -1
  67. package/dist/esm-node/runtime-node/serialize.js +0 -6
  68. package/dist/esm-node/runtime-node/storage.js +0 -38
  69. package/dist/esm-node/universal/time.js +0 -28
  70. package/dist/types/runtime/nestedRoutes.d.ts +0 -13
  71. package/dist/types/runtime/remixRouter.d.ts +0 -1
  72. package/dist/types/runtime/router.d.ts +0 -1
  73. package/dist/types/runtime-browser/index.d.ts +0 -1
  74. package/dist/types/runtime-browser/parsed.d.ts +0 -1
  75. package/dist/types/runtime-node/index.d.ts +0 -10
  76. package/dist/types/runtime-node/loaderContext/createLoaderCtx.d.ts +0 -7
  77. package/dist/types/runtime-node/loaderContext/createRequestCtx.d.ts +0 -7
  78. package/dist/types/runtime-node/loaderContext/index.d.ts +0 -4
  79. package/dist/types/runtime-node/nestedRoutes.d.ts +0 -3
  80. package/dist/types/runtime-node/router.d.ts +0 -1
  81. package/dist/types/runtime-node/serialize.d.ts +0 -1
  82. package/dist/types/runtime-node/storage.d.ts +0 -5
  83. package/dist/types/universal/time.d.ts +0 -1
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.35.0",
18
+ "version": "2.35.1",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -34,33 +34,6 @@
34
34
  "types": "./dist/types/cli/constants/chainId.d.ts",
35
35
  "default": "./dist/cjs/cli/constants/chainId.js"
36
36
  },
37
- "./runtime/router": {
38
- "types": "./dist/types/runtime/router.d.ts",
39
- "default": "./dist/esm/runtime/router.js"
40
- },
41
- "./runtime/remix-router": {
42
- "types": "./dist/types/runtime/remixRouter.d.ts",
43
- "require": "./dist/cjs/runtime/remixRouter.js",
44
- "default": "./dist/esm/runtime/remixRouter.js"
45
- },
46
- "./runtime/nested-routes": {
47
- "types": "./dist/types/runtime/nestedRoutes.d.ts",
48
- "default": "./dist/esm/runtime/nestedRoutes.js"
49
- },
50
- "./runtime-browser": {
51
- "jsnext:source": "./src/runtime-browser/index.d.ts",
52
- "default": "./dist/esm/runtime-browser/index.js"
53
- },
54
- "./runtime-node": {
55
- "types": "./dist/types/runtime-node/index.d.ts",
56
- "require": "./dist/cjs/runtime-node/index.js",
57
- "default": "./dist/esm/runtime-node/index.js"
58
- },
59
- "./runtime-node/router": {
60
- "types": "./dist/types/runtime-node/router.d.ts",
61
- "require": "./dist/cjs/runtime-node/router.js",
62
- "default": "./dist/esm/runtime-node/router.js"
63
- },
64
37
  "./universal/constants": {
65
38
  "types": "./dist/types/universal/constants.d.ts",
66
39
  "import": "./dist/esm/universal/constants.js",
@@ -76,11 +49,6 @@
76
49
  "import": "./dist/esm/universal/pluginDagSort.js",
77
50
  "default": "./dist/cjs/universal/pluginDagSort.js"
78
51
  },
79
- "./universal/time": {
80
- "types": "./dist/types/universal/time.d.ts",
81
- "import": "./dist/esm/universal/time.js",
82
- "default": "./dist/cjs/universal/time.js"
83
- },
84
52
  "./ajv": "./dist/compiled/ajv/index.js",
85
53
  "./commander": "./dist/compiled/commander/index.js",
86
54
  "./ora": "./dist/compiled/ora/index.js",
@@ -117,24 +85,6 @@
117
85
  "chain-id": [
118
86
  "./dist/types/cli/constants/chainId.d.ts"
119
87
  ],
120
- "runtime/router": [
121
- "./dist/types/runtime/router.d.ts"
122
- ],
123
- "runtime/remix-router": [
124
- "./dist/types/runtime/remixRouter.d.ts"
125
- ],
126
- "runtime/nested-routes": [
127
- "./dist/types/runtime/nestedRoutes.d.ts"
128
- ],
129
- "runtime-browser": [
130
- "./dist/types/runtime-browser/index.d.ts"
131
- ],
132
- "runtime-node": [
133
- "./dist/types/runtime-node/index.d.ts"
134
- ],
135
- "runtime-node/router": [
136
- "./dist/types/runtime-node/router.d.ts"
137
- ],
138
88
  "universal/constants": [
139
89
  "./dist/types/universal/constants.d.ts"
140
90
  ],
@@ -144,9 +94,6 @@
144
94
  "universal/plugin-dag-sort": [
145
95
  "./dist/types/universal/pluginDagSort.d.ts"
146
96
  ],
147
- "universal/time": [
148
- "./dist/types/universal/time.d.ts"
149
- ],
150
97
  "ajv": [
151
98
  "./dist/compiled/ajv/types/ajv.d.ts"
152
99
  ],
@@ -221,35 +168,17 @@
221
168
  "dependencies": {
222
169
  "caniuse-lite": "^1.0.30001520",
223
170
  "lodash": "^4.17.21",
224
- "serialize-javascript": "^6.0.0",
225
- "react-router-dom": "6.15.0",
226
- "@remix-run/router": "1.8.0",
227
171
  "@swc/helpers": "0.5.1"
228
172
  },
229
- "peerDependencies": {
230
- "react": ">=17.0.0",
231
- "react-dom": ">=17.0.0"
232
- },
233
- "peerDependenciesMeta": {
234
- "react": {
235
- "optional": true
236
- },
237
- "react-dom": {
238
- "optional": true
239
- }
240
- },
241
173
  "devDependencies": {
242
- "react": "^18.2.0",
243
- "react-dom": "^18.2.0",
244
174
  "@types/jest": "^29",
245
175
  "@types/node": "^14",
246
176
  "jest": "^29",
247
177
  "typescript": "^5",
248
178
  "webpack": "^5.88.1",
249
- "@types/serialize-javascript": "^5.0.1",
250
- "@modern-js/types": "2.35.0",
251
- "@scripts/jest-config": "2.35.0",
252
- "@scripts/build": "2.35.0"
179
+ "@modern-js/types": "2.35.1",
180
+ "@scripts/build": "2.35.1",
181
+ "@scripts/jest-config": "2.35.1"
253
182
  },
254
183
  "sideEffects": false,
255
184
  "scripts": {
@@ -1,149 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- transformNestedRoutes: function() {
14
- return transformNestedRoutes;
15
- },
16
- renderNestedRoute: function() {
17
- return renderNestedRoute;
18
- }
19
- });
20
- const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
21
- const _jsxruntime = require("react/jsx-runtime");
22
- const _react = /* @__PURE__ */ _interop_require_wildcard._(require("react"));
23
- const _reactrouterdom = require("react-router-dom");
24
- const _constants = require("../universal/constants");
25
- const _time = require("../universal/time");
26
- const transformNestedRoutes = (routes, reporter) => {
27
- const routeElements = [];
28
- for (const route of routes) {
29
- const routeElement = renderNestedRoute(route, {
30
- reporter
31
- });
32
- routeElements.push(routeElement);
33
- }
34
- return (0, _reactrouterdom.createRoutesFromElements)(routeElements);
35
- };
36
- const renderNestedRoute = (nestedRoute, options = {}) => {
37
- var _config, _children;
38
- const { children, index, id, component, isRoot, lazyImport, config, handle } = nestedRoute;
39
- const Component = component;
40
- const { parent, DeferredDataComponent, props = {}, reporter } = options;
41
- const routeProps = {
42
- caseSensitive: nestedRoute.caseSensitive,
43
- path: nestedRoute.path,
44
- id: nestedRoute.id,
45
- loader: createLoader(nestedRoute, reporter),
46
- action: nestedRoute.action,
47
- hasErrorBoundary: nestedRoute.hasErrorBoundary,
48
- shouldRevalidate: nestedRoute.shouldRevalidate,
49
- handle: {
50
- ...handle,
51
- ...typeof config === "object" ? (_config = config) === null || _config === void 0 ? void 0 : _config.handle : {}
52
- },
53
- index: nestedRoute.index,
54
- element: nestedRoute.element,
55
- errorElement: nestedRoute.errorElement
56
- };
57
- if (nestedRoute.error) {
58
- const errorElement = /* @__PURE__ */ (0, _jsxruntime.jsx)(nestedRoute.error, {});
59
- routeProps.errorElement = errorElement;
60
- }
61
- let element;
62
- if (Component) {
63
- var _parent;
64
- if (((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.loading) && lazyImport) {
65
- const Loading = parent.loading;
66
- if (isLoadableComponent(Component)) {
67
- element = /* @__PURE__ */ (0, _jsxruntime.jsx)(Component, {
68
- fallback: /* @__PURE__ */ (0, _jsxruntime.jsx)(Loading, {})
69
- });
70
- } else {
71
- element = /* @__PURE__ */ (0, _jsxruntime.jsx)(_react.Suspense, {
72
- fallback: /* @__PURE__ */ (0, _jsxruntime.jsx)(Loading, {}),
73
- children: /* @__PURE__ */ (0, _jsxruntime.jsx)(Component, {})
74
- });
75
- }
76
- } else if (isLoadableComponent(Component) && lazyImport) {
77
- element = /* @__PURE__ */ (0, _jsxruntime.jsx)(Component, {});
78
- } else if (isRoot) {
79
- var _props;
80
- element = /* @__PURE__ */ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
81
- children: [
82
- /* @__PURE__ */ (0, _jsxruntime.jsx)(Component, {
83
- ...props
84
- }),
85
- typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ (0, _jsxruntime.jsx)(DeferredDataComponent, {
86
- nonce: (_props = props) === null || _props === void 0 ? void 0 : _props.nonce
87
- })
88
- ]
89
- });
90
- } else if (lazyImport) {
91
- element = /* @__PURE__ */ (0, _jsxruntime.jsx)(_react.Suspense, {
92
- fallback: null,
93
- children: /* @__PURE__ */ (0, _jsxruntime.jsx)(Component, {})
94
- });
95
- } else {
96
- element = /* @__PURE__ */ (0, _jsxruntime.jsx)(Component, {});
97
- }
98
- } else {
99
- var _parent1;
100
- nestedRoute.loading = (_parent1 = parent) === null || _parent1 === void 0 ? void 0 : _parent1.loading;
101
- routeProps.element = /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.Outlet, {});
102
- }
103
- if (element) {
104
- routeProps.element = element;
105
- }
106
- const childElements = (_children = children) === null || _children === void 0 ? void 0 : _children.map((childRoute) => {
107
- return renderNestedRoute(childRoute, {
108
- parent: nestedRoute,
109
- reporter
110
- });
111
- });
112
- const routeElement = index ? /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.Route, {
113
- ...routeProps,
114
- index: true
115
- }, id) : /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.Route, {
116
- ...routeProps,
117
- index: false,
118
- children: childElements
119
- }, id);
120
- return routeElement;
121
- };
122
- function createLoader(route, reporter) {
123
- const { loader } = route;
124
- if (loader) {
125
- return async (args) => {
126
- if (typeof route.lazyImport === "function") {
127
- route.lazyImport();
128
- }
129
- const end = (0, _time.time)();
130
- const res = await loader(args);
131
- const cost = end();
132
- if (typeof document === "undefined" && reporter) {
133
- var _reporter;
134
- (_reporter = reporter) === null || _reporter === void 0 ? void 0 : _reporter.reportTiming(`${_constants.LOADER_REPORTER_NAME}-${route.id}`, cost);
135
- }
136
- return res;
137
- };
138
- } else {
139
- return () => {
140
- if (typeof route.lazyImport === "function") {
141
- route.lazyImport();
142
- }
143
- return null;
144
- };
145
- }
146
- }
147
- function isLoadableComponent(component) {
148
- return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
149
- }
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- const _export_star = require("@swc/helpers/_/_export_star");
6
- _export_star._(require("@remix-run/router"), exports);
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- const _export_star = require("@swc/helpers/_/_export_star");
6
- _export_star._(require("react-router-dom"), exports);
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- const _export_star = require("@swc/helpers/_/_export_star");
6
- _export_star._(require("./parsed"), exports);
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "parsedJSONFromElement", {
6
- enumerable: true,
7
- get: function() {
8
- return parsedJSONFromElement;
9
- }
10
- });
11
- const parsedJSONFromElement = (id) => {
12
- const elements = document.querySelectorAll(`#${id}`);
13
- if (elements.length === 0) {
14
- return void 0;
15
- }
16
- const element = elements[elements.length - 1];
17
- if (element) {
18
- try {
19
- var _element;
20
- const parsed = JSON.parse(((_element = element) === null || _element === void 0 ? void 0 : _element.textContent) || "");
21
- return parsed;
22
- } catch (e) {
23
- console.error(`parse ${id} error`, e);
24
- return void 0;
25
- }
26
- }
27
- return void 0;
28
- };
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- run: function() {
14
- return run;
15
- },
16
- useHeaders: function() {
17
- return useHeaders;
18
- },
19
- serializeJson: function() {
20
- return _serialize.serializeJson;
21
- }
22
- });
23
- const _export_star = require("@swc/helpers/_/_export_star");
24
- const _storage = require("./storage");
25
- const _serialize = require("./serialize");
26
- _export_star._(require("./nestedRoutes"), exports);
27
- _export_star._(require("./loaderContext"), exports);
28
- const { run, useContext: useHeaders } = (0, _storage.createStorage)();
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- LoaderContext: function() {
14
- return LoaderContext;
15
- },
16
- createLoaderContext: function() {
17
- return createLoaderContext;
18
- }
19
- });
20
- class LoaderContext {
21
- getDefaultValue() {
22
- if (!this.defaultValue) {
23
- throw new Error("Can't get defaultValue before initialed");
24
- }
25
- return this.defaultValue;
26
- }
27
- constructor(defaultValue) {
28
- this.defaultValue = defaultValue;
29
- this.symbol = Symbol("loaderContext");
30
- }
31
- }
32
- function createLoaderContext(defaultValue) {
33
- return new LoaderContext(defaultValue);
34
- }
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- RequestContext: function() {
14
- return RequestContext;
15
- },
16
- createRequestContext: function() {
17
- return createRequestContext;
18
- }
19
- });
20
- class RequestContext {
21
- get(loaderCtx) {
22
- const { symbol } = loaderCtx;
23
- if (this.store.get(symbol)) {
24
- return this.store.get(symbol);
25
- }
26
- return loaderCtx.getDefaultValue();
27
- }
28
- set(loaderCtx, value) {
29
- const { symbol } = loaderCtx;
30
- this.store.set(symbol, value);
31
- }
32
- constructor() {
33
- this.store = /* @__PURE__ */ new Map();
34
- }
35
- }
36
- function createRequestContext() {
37
- return new RequestContext();
38
- }
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- createRequestContext: function() {
14
- return _createRequestCtx.createRequestContext;
15
- },
16
- reporterCtx: function() {
17
- return reporterCtx;
18
- }
19
- });
20
- const _createLoaderCtx = require("./createLoaderCtx");
21
- const _createRequestCtx = require("./createRequestCtx");
22
- const reporterCtx = (0, _createLoaderCtx.createLoaderContext)();
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "matchEntry", {
6
- enumerable: true,
7
- get: function() {
8
- return matchEntry;
9
- }
10
- });
11
- function sortByUrlPath(entries) {
12
- entries.sort(function(a, b) {
13
- const length1 = a.urlPath.length;
14
- const length2 = b.urlPath.length;
15
- if (length1 < length2) {
16
- return 1;
17
- }
18
- if (length1 > length2) {
19
- return -1;
20
- }
21
- return 0;
22
- });
23
- return entries;
24
- }
25
- const matchEntry = (pathname, entries) => {
26
- sortByUrlPath(entries);
27
- return entries.find((entry) => pathname.startsWith(entry.urlPath));
28
- };
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- const _export_star = require("@swc/helpers/_/_export_star");
6
- _export_star._(require("react-router-dom/server"), exports);
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "serializeJson", {
6
- enumerable: true,
7
- get: function() {
8
- return serializeJson;
9
- }
10
- });
11
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
12
- const _serializejavascript = /* @__PURE__ */ _interop_require_default._(require("serialize-javascript"));
13
- const serializeJson = (data) => {
14
- return (0, _serializejavascript.default)(data, {
15
- isJSON: true
16
- });
17
- };
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "createStorage", {
6
- enumerable: true,
7
- get: function() {
8
- return createStorage;
9
- }
10
- });
11
- const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
- const _async_hooks = /* @__PURE__ */ _interop_require_wildcard._(require("async_hooks"));
13
- const createStorage = () => {
14
- let storage;
15
- if (typeof _async_hooks.AsyncLocalStorage !== "undefined") {
16
- storage = new _async_hooks.AsyncLocalStorage();
17
- }
18
- const run = (context, cb) => {
19
- if (!storage) {
20
- throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
21
- `);
22
- }
23
- return new Promise((resolve, reject) => {
24
- storage.run(context, () => {
25
- try {
26
- return resolve(cb());
27
- } catch (error) {
28
- return reject(error);
29
- }
30
- });
31
- });
32
- };
33
- const useContext = () => {
34
- if (!storage) {
35
- throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
36
- `);
37
- }
38
- const context = storage.getStore();
39
- if (!context) {
40
- throw new Error(`Can't call useContext out of scope, make sure @modern-js/utils is a single version in node_modules`);
41
- }
42
- return context;
43
- };
44
- return {
45
- run,
46
- useContext
47
- };
48
- };
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "time", {
6
- enumerable: true,
7
- get: function() {
8
- return time;
9
- }
10
- });
11
- function processHrtime(previousTimestamp) {
12
- const now = (/* @__PURE__ */ new Date()).getTime();
13
- const clocktime = now * 1e-3;
14
- let seconds = Math.floor(clocktime);
15
- let nanoseconds = Math.floor(clocktime % 1 * 1e9);
16
- if (previousTimestamp) {
17
- seconds -= previousTimestamp[0];
18
- nanoseconds -= previousTimestamp[1];
19
- if (nanoseconds < 0) {
20
- seconds--;
21
- nanoseconds += 1e9;
22
- }
23
- }
24
- return [
25
- seconds,
26
- nanoseconds
27
- ];
28
- }
29
- const getLatency = (hrtime) => {
30
- const [s, ns] = processHrtime(hrtime);
31
- return s * 1e3 + ns / 1e6;
32
- };
33
- const time = () => {
34
- const hrtime = processHrtime();
35
- return () => {
36
- return getLatency(hrtime);
37
- };
38
- };