@modern-js/utils 2.35.0 → 2.36.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. package/dist/cjs/cli/alias.js +48 -49
  2. package/dist/cjs/cli/applyOptionsChain.js +30 -13
  3. package/dist/cjs/cli/babel.js +36 -26
  4. package/dist/cjs/cli/commands.js +29 -21
  5. package/dist/cjs/cli/common.js +29 -20
  6. package/dist/cjs/cli/config.js +24 -7
  7. package/dist/cjs/cli/constants/chainId.js +27 -10
  8. package/dist/cjs/cli/constants/index.js +86 -104
  9. package/dist/cjs/cli/ensure.js +37 -18
  10. package/dist/cjs/cli/fs.js +29 -19
  11. package/dist/cjs/cli/get/config.js +26 -9
  12. package/dist/cjs/cli/get/data.js +67 -54
  13. package/dist/cjs/cli/get/index.js +46 -25
  14. package/dist/cjs/cli/index.js +58 -23
  15. package/dist/cjs/cli/is/config.js +45 -41
  16. package/dist/cjs/cli/is/env.js +32 -29
  17. package/dist/cjs/cli/is/index.js +26 -8
  18. package/dist/cjs/cli/is/project.js +67 -53
  19. package/dist/cjs/cli/is/type.js +39 -36
  20. package/dist/cjs/cli/logger.js +25 -125
  21. package/dist/cjs/cli/monorepo.js +58 -58
  22. package/dist/cjs/cli/package.js +34 -26
  23. package/dist/cjs/cli/path.js +64 -54
  24. package/dist/cjs/cli/port.js +39 -13
  25. package/dist/cjs/cli/prettyInstructions.js +50 -34
  26. package/dist/cjs/cli/require.js +36 -31
  27. package/dist/cjs/cli/runtimeExports.js +42 -16
  28. package/dist/cjs/cli/watch.js +41 -22
  29. package/dist/cjs/compiled.js +127 -138
  30. package/dist/cjs/import.js +25 -15
  31. package/dist/cjs/index.js +24 -6
  32. package/dist/cjs/universal/constants.js +29 -21
  33. package/dist/cjs/universal/formatWebpack.js +28 -18
  34. package/dist/cjs/universal/pluginDagSort.js +25 -8
  35. package/dist/esm/cli/alias.js +13 -25
  36. package/dist/esm/cli/applyOptionsChain.js +4 -1
  37. package/dist/esm/cli/babel.js +6 -2
  38. package/dist/esm/cli/commands.js +10 -4
  39. package/dist/esm/cli/common.js +8 -3
  40. package/dist/esm/cli/config.js +4 -1
  41. package/dist/esm/cli/constants/chainId.js +7 -4
  42. package/dist/esm/cli/constants/index.js +64 -31
  43. package/dist/esm/cli/ensure.js +6 -2
  44. package/dist/esm/cli/fs.js +6 -2
  45. package/dist/esm/cli/get/config.js +4 -1
  46. package/dist/esm/cli/get/data.js +18 -8
  47. package/dist/esm/cli/get/index.js +6 -2
  48. package/dist/esm/cli/is/config.js +23 -17
  49. package/dist/esm/cli/is/env.js +12 -8
  50. package/dist/esm/cli/is/index.js +0 -1
  51. package/dist/esm/cli/is/project.js +17 -8
  52. package/dist/esm/cli/is/type.js +20 -9
  53. package/dist/esm/cli/logger.js +4 -123
  54. package/dist/esm/cli/monorepo.js +14 -16
  55. package/dist/esm/cli/package.js +10 -4
  56. package/dist/esm/cli/path.js +24 -11
  57. package/dist/esm/cli/port.js +6 -3
  58. package/dist/esm/cli/prettyInstructions.js +8 -5
  59. package/dist/esm/cli/require.js +15 -8
  60. package/dist/esm/cli/runtimeExports.js +6 -3
  61. package/dist/esm/cli/watch.js +10 -6
  62. package/dist/esm/compiled.js +65 -31
  63. package/dist/esm/import.js +6 -3
  64. package/dist/esm/universal/constants.js +10 -4
  65. package/dist/esm/universal/formatWebpack.js +8 -5
  66. package/dist/esm/universal/pluginDagSort.js +5 -2
  67. package/dist/esm-node/cli/alias.js +11 -22
  68. package/dist/esm-node/cli/applyOptionsChain.js +4 -1
  69. package/dist/esm-node/cli/babel.js +6 -2
  70. package/dist/esm-node/cli/commands.js +10 -4
  71. package/dist/esm-node/cli/common.js +8 -3
  72. package/dist/esm-node/cli/config.js +4 -1
  73. package/dist/esm-node/cli/constants/chainId.js +7 -4
  74. package/dist/esm-node/cli/constants/index.js +64 -31
  75. package/dist/esm-node/cli/ensure.js +6 -2
  76. package/dist/esm-node/cli/fs.js +6 -2
  77. package/dist/esm-node/cli/get/config.js +4 -1
  78. package/dist/esm-node/cli/get/data.js +18 -8
  79. package/dist/esm-node/cli/get/index.js +6 -2
  80. package/dist/esm-node/cli/is/config.js +23 -17
  81. package/dist/esm-node/cli/is/env.js +12 -6
  82. package/dist/esm-node/cli/is/index.js +0 -1
  83. package/dist/esm-node/cli/is/project.js +16 -7
  84. package/dist/esm-node/cli/is/type.js +20 -9
  85. package/dist/esm-node/cli/logger.js +4 -108
  86. package/dist/esm-node/cli/monorepo.js +14 -18
  87. package/dist/esm-node/cli/package.js +10 -4
  88. package/dist/esm-node/cli/path.js +24 -11
  89. package/dist/esm-node/cli/port.js +5 -2
  90. package/dist/esm-node/cli/prettyInstructions.js +8 -7
  91. package/dist/esm-node/cli/require.js +15 -8
  92. package/dist/esm-node/cli/runtimeExports.js +4 -1
  93. package/dist/esm-node/cli/watch.js +6 -2
  94. package/dist/esm-node/compiled.js +65 -31
  95. package/dist/esm-node/import.js +5 -2
  96. package/dist/esm-node/universal/constants.js +10 -4
  97. package/dist/esm-node/universal/formatWebpack.js +8 -5
  98. package/dist/esm-node/universal/pluginDagSort.js +5 -2
  99. package/dist/types/cli/alias.d.ts +0 -5
  100. package/dist/types/cli/constants/chainId.d.ts +2 -2
  101. package/dist/types/cli/is/env.d.ts +1 -2
  102. package/dist/types/cli/is/index.d.ts +0 -1
  103. package/dist/types/cli/logger.d.ts +1 -64
  104. package/dist/types/cli/monorepo.d.ts +0 -1
  105. package/package.json +6 -84
  106. package/dist/cjs/cli/is/platform.js +0 -21
  107. package/dist/cjs/runtime/nestedRoutes.js +0 -149
  108. package/dist/cjs/runtime/remixRouter.js +0 -6
  109. package/dist/cjs/runtime/router.js +0 -6
  110. package/dist/cjs/runtime-browser/index.js +0 -6
  111. package/dist/cjs/runtime-browser/parsed.js +0 -28
  112. package/dist/cjs/runtime-node/index.js +0 -28
  113. package/dist/cjs/runtime-node/loaderContext/createLoaderCtx.js +0 -34
  114. package/dist/cjs/runtime-node/loaderContext/createRequestCtx.js +0 -38
  115. package/dist/cjs/runtime-node/loaderContext/index.js +0 -22
  116. package/dist/cjs/runtime-node/nestedRoutes.js +0 -28
  117. package/dist/cjs/runtime-node/router.js +0 -6
  118. package/dist/cjs/runtime-node/serialize.js +0 -17
  119. package/dist/cjs/runtime-node/storage.js +0 -48
  120. package/dist/cjs/universal/time.js +0 -38
  121. package/dist/compiled/gradient-string/index.d.ts +0 -1
  122. package/dist/compiled/gradient-string/index.js +0 -1
  123. package/dist/compiled/gradient-string/license +0 -21
  124. package/dist/compiled/gradient-string/package.json +0 -1
  125. package/dist/compiled/webpack-dev-middleware/index.js +0 -7
  126. package/dist/compiled/webpack-dev-middleware/license +0 -20
  127. package/dist/compiled/webpack-dev-middleware/package.json +0 -1
  128. package/dist/compiled/webpack-dev-middleware/types/index.d.ts +0 -262
  129. package/dist/esm/cli/is/platform.js +0 -6
  130. package/dist/esm/runtime/nestedRoutes.js +0 -163
  131. package/dist/esm/runtime/remixRouter.js +0 -1
  132. package/dist/esm/runtime/router.js +0 -1
  133. package/dist/esm/runtime-browser/index.js +0 -1
  134. package/dist/esm/runtime-browser/parsed.js +0 -18
  135. package/dist/esm/runtime-node/index.js +0 -6
  136. package/dist/esm/runtime-node/loaderContext/createLoaderCtx.js +0 -20
  137. package/dist/esm/runtime-node/loaderContext/createRequestCtx.js +0 -24
  138. package/dist/esm/runtime-node/loaderContext/index.js +0 -3
  139. package/dist/esm/runtime-node/nestedRoutes.js +0 -20
  140. package/dist/esm/runtime-node/router.js +0 -1
  141. package/dist/esm/runtime-node/serialize.js +0 -6
  142. package/dist/esm/runtime-node/storage.js +0 -36
  143. package/dist/esm/universal/time.js +0 -29
  144. package/dist/esm-node/cli/is/platform.js +0 -2
  145. package/dist/esm-node/runtime/nestedRoutes.js +0 -129
  146. package/dist/esm-node/runtime/remixRouter.js +0 -1
  147. package/dist/esm-node/runtime/router.js +0 -1
  148. package/dist/esm-node/runtime-browser/index.js +0 -1
  149. package/dist/esm-node/runtime-browser/parsed.js +0 -18
  150. package/dist/esm-node/runtime-node/index.js +0 -6
  151. package/dist/esm-node/runtime-node/loaderContext/createLoaderCtx.js +0 -15
  152. package/dist/esm-node/runtime-node/loaderContext/createRequestCtx.js +0 -19
  153. package/dist/esm-node/runtime-node/loaderContext/index.js +0 -3
  154. package/dist/esm-node/runtime-node/nestedRoutes.js +0 -18
  155. package/dist/esm-node/runtime-node/router.js +0 -1
  156. package/dist/esm-node/runtime-node/serialize.js +0 -6
  157. package/dist/esm-node/runtime-node/storage.js +0 -38
  158. package/dist/esm-node/universal/time.js +0 -28
  159. package/dist/types/cli/is/platform.d.ts +0 -2
  160. package/dist/types/runtime/nestedRoutes.d.ts +0 -13
  161. package/dist/types/runtime/remixRouter.d.ts +0 -1
  162. package/dist/types/runtime/router.d.ts +0 -1
  163. package/dist/types/runtime-browser/index.d.ts +0 -1
  164. package/dist/types/runtime-browser/parsed.d.ts +0 -1
  165. package/dist/types/runtime-node/index.d.ts +0 -10
  166. package/dist/types/runtime-node/loaderContext/createLoaderCtx.d.ts +0 -7
  167. package/dist/types/runtime-node/loaderContext/createRequestCtx.d.ts +0 -7
  168. package/dist/types/runtime-node/loaderContext/index.d.ts +0 -4
  169. package/dist/types/runtime-node/nestedRoutes.d.ts +0 -3
  170. package/dist/types/runtime-node/router.d.ts +0 -1
  171. package/dist/types/runtime-node/serialize.d.ts +0 -1
  172. package/dist/types/runtime-node/storage.d.ts +0 -5
  173. package/dist/types/universal/time.d.ts +0 -1
@@ -1,163 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
- import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
6
- import { Suspense } from "react";
7
- import { createRoutesFromElements, Outlet, Route } from "react-router-dom";
8
- import { LOADER_REPORTER_NAME } from "../universal/constants";
9
- import { time } from "../universal/time";
10
- export var transformNestedRoutes = function(routes, reporter) {
11
- var routeElements = [];
12
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
13
- try {
14
- for (var _iterator = routes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
15
- var route = _step.value;
16
- var routeElement = renderNestedRoute(route, {
17
- reporter: reporter
18
- });
19
- routeElements.push(routeElement);
20
- }
21
- } catch (err) {
22
- _didIteratorError = true;
23
- _iteratorError = err;
24
- } finally {
25
- try {
26
- if (!_iteratorNormalCompletion && _iterator.return != null) {
27
- _iterator.return();
28
- }
29
- } finally {
30
- if (_didIteratorError) {
31
- throw _iteratorError;
32
- }
33
- }
34
- }
35
- return createRoutesFromElements(routeElements);
36
- };
37
- export var renderNestedRoute = function(nestedRoute) {
38
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
39
- var _config, _children;
40
- 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;
41
- var Component = component;
42
- var parent = options.parent, DeferredDataComponent = options.DeferredDataComponent, _options_props = options.props, props = _options_props === void 0 ? {} : _options_props, reporter = options.reporter;
43
- var routeProps = {
44
- caseSensitive: nestedRoute.caseSensitive,
45
- path: nestedRoute.path,
46
- id: nestedRoute.id,
47
- loader: createLoader(nestedRoute, reporter),
48
- action: nestedRoute.action,
49
- hasErrorBoundary: nestedRoute.hasErrorBoundary,
50
- shouldRevalidate: nestedRoute.shouldRevalidate,
51
- handle: _object_spread({}, handle, typeof config === "object" ? (_config = config) === null || _config === void 0 ? void 0 : _config.handle : {}),
52
- index: nestedRoute.index,
53
- element: nestedRoute.element,
54
- errorElement: nestedRoute.errorElement
55
- };
56
- if (nestedRoute.error) {
57
- var errorElement = /* @__PURE__ */ _jsx(nestedRoute.error, {});
58
- routeProps.errorElement = errorElement;
59
- }
60
- var element;
61
- if (Component) {
62
- var _parent;
63
- if (((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.loading) && lazyImport) {
64
- var Loading = parent.loading;
65
- if (isLoadableComponent(Component)) {
66
- element = /* @__PURE__ */ _jsx(Component, {
67
- fallback: /* @__PURE__ */ _jsx(Loading, {})
68
- });
69
- } else {
70
- element = /* @__PURE__ */ _jsx(Suspense, {
71
- fallback: /* @__PURE__ */ _jsx(Loading, {}),
72
- children: /* @__PURE__ */ _jsx(Component, {})
73
- });
74
- }
75
- } else if (isLoadableComponent(Component) && lazyImport) {
76
- element = /* @__PURE__ */ _jsx(Component, {});
77
- } else if (isRoot) {
78
- var _props;
79
- element = /* @__PURE__ */ _jsxs(_Fragment, {
80
- children: [
81
- /* @__PURE__ */ _jsx(Component, _object_spread({}, props)),
82
- typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ _jsx(DeferredDataComponent, {
83
- nonce: (_props = props) === null || _props === void 0 ? void 0 : _props.nonce
84
- })
85
- ]
86
- });
87
- } else if (lazyImport) {
88
- element = /* @__PURE__ */ _jsx(Suspense, {
89
- fallback: null,
90
- children: /* @__PURE__ */ _jsx(Component, {})
91
- });
92
- } else {
93
- element = /* @__PURE__ */ _jsx(Component, {});
94
- }
95
- } else {
96
- var _parent1;
97
- nestedRoute.loading = (_parent1 = parent) === null || _parent1 === void 0 ? void 0 : _parent1.loading;
98
- routeProps.element = /* @__PURE__ */ _jsx(Outlet, {});
99
- }
100
- if (element) {
101
- routeProps.element = element;
102
- }
103
- var childElements = (_children = children) === null || _children === void 0 ? void 0 : _children.map(function(childRoute) {
104
- return renderNestedRoute(childRoute, {
105
- parent: nestedRoute,
106
- reporter: reporter
107
- });
108
- });
109
- var routeElement = index ? /* @__PURE__ */ _jsx(Route, _object_spread_props(_object_spread({}, routeProps), {
110
- index: true
111
- }), id) : /* @__PURE__ */ _jsx(Route, _object_spread_props(_object_spread({}, routeProps), {
112
- index: false,
113
- children: childElements
114
- }), id);
115
- return routeElement;
116
- };
117
- function createLoader(route, reporter) {
118
- var loader = route.loader;
119
- if (loader) {
120
- return function() {
121
- var _ref = _async_to_generator(function(args) {
122
- var end, res, cost, _reporter;
123
- return _ts_generator(this, function(_state) {
124
- switch (_state.label) {
125
- case 0:
126
- if (typeof route.lazyImport === "function") {
127
- route.lazyImport();
128
- }
129
- end = time();
130
- return [
131
- 4,
132
- loader(args)
133
- ];
134
- case 1:
135
- res = _state.sent();
136
- cost = end();
137
- if (typeof document === "undefined" && reporter) {
138
- ;
139
- (_reporter = reporter) === null || _reporter === void 0 ? void 0 : _reporter.reportTiming("".concat(LOADER_REPORTER_NAME, "-").concat(route.id), cost);
140
- }
141
- return [
142
- 2,
143
- res
144
- ];
145
- }
146
- });
147
- });
148
- return function(args) {
149
- return _ref.apply(this, arguments);
150
- };
151
- }();
152
- } else {
153
- return function() {
154
- if (typeof route.lazyImport === "function") {
155
- route.lazyImport();
156
- }
157
- return null;
158
- };
159
- }
160
- }
161
- function isLoadableComponent(component) {
162
- return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
163
- }
@@ -1 +0,0 @@
1
- export * from "@remix-run/router";
@@ -1 +0,0 @@
1
- export * from "react-router-dom";
@@ -1 +0,0 @@
1
- export * from "./parsed";
@@ -1,18 +0,0 @@
1
- export var parsedJSONFromElement = function(id) {
2
- var elements = document.querySelectorAll("#".concat(id));
3
- if (elements.length === 0) {
4
- return void 0;
5
- }
6
- var element = elements[elements.length - 1];
7
- if (element) {
8
- try {
9
- var _element;
10
- var parsed = JSON.parse(((_element = element) === null || _element === void 0 ? void 0 : _element.textContent) || "");
11
- return parsed;
12
- } catch (e) {
13
- console.error("parse ".concat(id, " error"), e);
14
- return void 0;
15
- }
16
- }
17
- return void 0;
18
- };
@@ -1,6 +0,0 @@
1
- import { createStorage } from "./storage";
2
- var _createStorage = createStorage(), run = _createStorage.run, useHeaders = _createStorage.useContext;
3
- export { run, useHeaders };
4
- export { serializeJson } from "./serialize";
5
- export * from "./nestedRoutes";
6
- export * from "./loaderContext";
@@ -1,20 +0,0 @@
1
- import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- export var LoaderContext = /* @__PURE__ */ function() {
3
- "use strict";
4
- function LoaderContext2(defaultValue) {
5
- _class_call_check(this, LoaderContext2);
6
- this.defaultValue = defaultValue;
7
- this.symbol = Symbol("loaderContext");
8
- }
9
- var _proto = LoaderContext2.prototype;
10
- _proto.getDefaultValue = function getDefaultValue() {
11
- if (!this.defaultValue) {
12
- throw new Error("Can't get defaultValue before initialed");
13
- }
14
- return this.defaultValue;
15
- };
16
- return LoaderContext2;
17
- }();
18
- export function createLoaderContext(defaultValue) {
19
- return new LoaderContext(defaultValue);
20
- }
@@ -1,24 +0,0 @@
1
- import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- export var RequestContext = /* @__PURE__ */ function() {
3
- "use strict";
4
- function RequestContext2() {
5
- _class_call_check(this, RequestContext2);
6
- this.store = /* @__PURE__ */ new Map();
7
- }
8
- var _proto = RequestContext2.prototype;
9
- _proto.get = function get(loaderCtx) {
10
- var symbol = loaderCtx.symbol;
11
- if (this.store.get(symbol)) {
12
- return this.store.get(symbol);
13
- }
14
- return loaderCtx.getDefaultValue();
15
- };
16
- _proto.set = function set(loaderCtx, value) {
17
- var symbol = loaderCtx.symbol;
18
- this.store.set(symbol, value);
19
- };
20
- return RequestContext2;
21
- }();
22
- export function createRequestContext() {
23
- return new RequestContext();
24
- }
@@ -1,3 +0,0 @@
1
- import { createLoaderContext } from "./createLoaderCtx";
2
- export { createRequestContext } from "./createRequestCtx";
3
- export var reporterCtx = createLoaderContext();
@@ -1,20 +0,0 @@
1
- function sortByUrlPath(entries) {
2
- entries.sort(function(a, b) {
3
- var length1 = a.urlPath.length;
4
- var length2 = b.urlPath.length;
5
- if (length1 < length2) {
6
- return 1;
7
- }
8
- if (length1 > length2) {
9
- return -1;
10
- }
11
- return 0;
12
- });
13
- return entries;
14
- }
15
- export var matchEntry = function(pathname, entries) {
16
- sortByUrlPath(entries);
17
- return entries.find(function(entry) {
18
- return pathname.startsWith(entry.urlPath);
19
- });
20
- };
@@ -1 +0,0 @@
1
- export * from "react-router-dom/server";
@@ -1,6 +0,0 @@
1
- import serialize from "serialize-javascript";
2
- export var serializeJson = function(data) {
3
- return serialize(data, {
4
- isJSON: true
5
- });
6
- };
@@ -1,36 +0,0 @@
1
- import * as ah from "async_hooks";
2
- var createStorage = function() {
3
- var storage;
4
- if (typeof ah.AsyncLocalStorage !== "undefined") {
5
- storage = new ah.AsyncLocalStorage();
6
- }
7
- var run = function(context, cb) {
8
- if (!storage) {
9
- throw new Error("Unable to use async_hook, please confirm the node version >= 12.17\n ");
10
- }
11
- return new Promise(function(resolve, reject) {
12
- storage.run(context, function() {
13
- try {
14
- return resolve(cb());
15
- } catch (error) {
16
- return reject(error);
17
- }
18
- });
19
- });
20
- };
21
- var useContext = function() {
22
- if (!storage) {
23
- throw new Error("Unable to use async_hook, please confirm the node version >= 12.17\n ");
24
- }
25
- var context = storage.getStore();
26
- if (!context) {
27
- throw new Error("Can't call useContext out of scope, make sure @modern-js/utils is a single version in node_modules");
28
- }
29
- return context;
30
- };
31
- return {
32
- run: run,
33
- useContext: useContext
34
- };
35
- };
36
- export { createStorage };
@@ -1,29 +0,0 @@
1
- import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
2
- function processHrtime(previousTimestamp) {
3
- var now = (/* @__PURE__ */ new Date()).getTime();
4
- var clocktime = now * 1e-3;
5
- var seconds = Math.floor(clocktime);
6
- var nanoseconds = Math.floor(clocktime % 1 * 1e9);
7
- if (previousTimestamp) {
8
- seconds -= previousTimestamp[0];
9
- nanoseconds -= previousTimestamp[1];
10
- if (nanoseconds < 0) {
11
- seconds--;
12
- nanoseconds += 1e9;
13
- }
14
- }
15
- return [
16
- seconds,
17
- nanoseconds
18
- ];
19
- }
20
- var getLatency = function(hrtime) {
21
- var _processHrtime = _sliced_to_array(processHrtime(hrtime), 2), s = _processHrtime[0], ns = _processHrtime[1];
22
- return s * 1e3 + ns / 1e6;
23
- };
24
- export var time = function() {
25
- var hrtime = processHrtime();
26
- return function() {
27
- return getLatency(hrtime);
28
- };
29
- };
@@ -1,2 +0,0 @@
1
- export const isNodeJS = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null && process.versions.electron == null;
2
- export const isBrowser = () => typeof window !== "undefined";
@@ -1,129 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { Suspense } from "react";
3
- import { createRoutesFromElements, Outlet, Route } from "react-router-dom";
4
- import { LOADER_REPORTER_NAME } from "../universal/constants";
5
- import { time } from "../universal/time";
6
- export const transformNestedRoutes = (routes, reporter) => {
7
- const routeElements = [];
8
- for (const route of routes) {
9
- const routeElement = renderNestedRoute(route, {
10
- reporter
11
- });
12
- routeElements.push(routeElement);
13
- }
14
- return createRoutesFromElements(routeElements);
15
- };
16
- export const renderNestedRoute = (nestedRoute, options = {}) => {
17
- var _config, _children;
18
- const { children, index, id, component, isRoot, lazyImport, config, handle } = nestedRoute;
19
- const Component = component;
20
- const { parent, DeferredDataComponent, props = {}, reporter } = options;
21
- const routeProps = {
22
- caseSensitive: nestedRoute.caseSensitive,
23
- path: nestedRoute.path,
24
- id: nestedRoute.id,
25
- loader: createLoader(nestedRoute, reporter),
26
- action: nestedRoute.action,
27
- hasErrorBoundary: nestedRoute.hasErrorBoundary,
28
- shouldRevalidate: nestedRoute.shouldRevalidate,
29
- handle: {
30
- ...handle,
31
- ...typeof config === "object" ? (_config = config) === null || _config === void 0 ? void 0 : _config.handle : {}
32
- },
33
- index: nestedRoute.index,
34
- element: nestedRoute.element,
35
- errorElement: nestedRoute.errorElement
36
- };
37
- if (nestedRoute.error) {
38
- const errorElement = /* @__PURE__ */ _jsx(nestedRoute.error, {});
39
- routeProps.errorElement = errorElement;
40
- }
41
- let element;
42
- if (Component) {
43
- var _parent;
44
- if (((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.loading) && lazyImport) {
45
- const Loading = parent.loading;
46
- if (isLoadableComponent(Component)) {
47
- element = /* @__PURE__ */ _jsx(Component, {
48
- fallback: /* @__PURE__ */ _jsx(Loading, {})
49
- });
50
- } else {
51
- element = /* @__PURE__ */ _jsx(Suspense, {
52
- fallback: /* @__PURE__ */ _jsx(Loading, {}),
53
- children: /* @__PURE__ */ _jsx(Component, {})
54
- });
55
- }
56
- } else if (isLoadableComponent(Component) && lazyImport) {
57
- element = /* @__PURE__ */ _jsx(Component, {});
58
- } else if (isRoot) {
59
- var _props;
60
- element = /* @__PURE__ */ _jsxs(_Fragment, {
61
- children: [
62
- /* @__PURE__ */ _jsx(Component, {
63
- ...props
64
- }),
65
- typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ _jsx(DeferredDataComponent, {
66
- nonce: (_props = props) === null || _props === void 0 ? void 0 : _props.nonce
67
- })
68
- ]
69
- });
70
- } else if (lazyImport) {
71
- element = /* @__PURE__ */ _jsx(Suspense, {
72
- fallback: null,
73
- children: /* @__PURE__ */ _jsx(Component, {})
74
- });
75
- } else {
76
- element = /* @__PURE__ */ _jsx(Component, {});
77
- }
78
- } else {
79
- var _parent1;
80
- nestedRoute.loading = (_parent1 = parent) === null || _parent1 === void 0 ? void 0 : _parent1.loading;
81
- routeProps.element = /* @__PURE__ */ _jsx(Outlet, {});
82
- }
83
- if (element) {
84
- routeProps.element = element;
85
- }
86
- const childElements = (_children = children) === null || _children === void 0 ? void 0 : _children.map((childRoute) => {
87
- return renderNestedRoute(childRoute, {
88
- parent: nestedRoute,
89
- reporter
90
- });
91
- });
92
- const routeElement = index ? /* @__PURE__ */ _jsx(Route, {
93
- ...routeProps,
94
- index: true
95
- }, id) : /* @__PURE__ */ _jsx(Route, {
96
- ...routeProps,
97
- index: false,
98
- children: childElements
99
- }, id);
100
- return routeElement;
101
- };
102
- function createLoader(route, reporter) {
103
- const { loader } = route;
104
- if (loader) {
105
- return async (args) => {
106
- if (typeof route.lazyImport === "function") {
107
- route.lazyImport();
108
- }
109
- const end = time();
110
- const res = await loader(args);
111
- const cost = end();
112
- if (typeof document === "undefined" && reporter) {
113
- var _reporter;
114
- (_reporter = reporter) === null || _reporter === void 0 ? void 0 : _reporter.reportTiming(`${LOADER_REPORTER_NAME}-${route.id}`, cost);
115
- }
116
- return res;
117
- };
118
- } else {
119
- return () => {
120
- if (typeof route.lazyImport === "function") {
121
- route.lazyImport();
122
- }
123
- return null;
124
- };
125
- }
126
- }
127
- function isLoadableComponent(component) {
128
- return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
129
- }
@@ -1 +0,0 @@
1
- export * from "@remix-run/router";
@@ -1 +0,0 @@
1
- export * from "react-router-dom";
@@ -1 +0,0 @@
1
- export * from "./parsed";
@@ -1,18 +0,0 @@
1
- export const parsedJSONFromElement = (id) => {
2
- const elements = document.querySelectorAll(`#${id}`);
3
- if (elements.length === 0) {
4
- return void 0;
5
- }
6
- const element = elements[elements.length - 1];
7
- if (element) {
8
- try {
9
- var _element;
10
- const parsed = JSON.parse(((_element = element) === null || _element === void 0 ? void 0 : _element.textContent) || "");
11
- return parsed;
12
- } catch (e) {
13
- console.error(`parse ${id} error`, e);
14
- return void 0;
15
- }
16
- }
17
- return void 0;
18
- };
@@ -1,6 +0,0 @@
1
- import { createStorage } from "./storage";
2
- const { run, useContext: useHeaders } = createStorage();
3
- export { run, useHeaders };
4
- export { serializeJson } from "./serialize";
5
- export * from "./nestedRoutes";
6
- export * from "./loaderContext";
@@ -1,15 +0,0 @@
1
- export class LoaderContext {
2
- getDefaultValue() {
3
- if (!this.defaultValue) {
4
- throw new Error("Can't get defaultValue before initialed");
5
- }
6
- return this.defaultValue;
7
- }
8
- constructor(defaultValue) {
9
- this.defaultValue = defaultValue;
10
- this.symbol = Symbol("loaderContext");
11
- }
12
- }
13
- export function createLoaderContext(defaultValue) {
14
- return new LoaderContext(defaultValue);
15
- }
@@ -1,19 +0,0 @@
1
- export class RequestContext {
2
- get(loaderCtx) {
3
- const { symbol } = loaderCtx;
4
- if (this.store.get(symbol)) {
5
- return this.store.get(symbol);
6
- }
7
- return loaderCtx.getDefaultValue();
8
- }
9
- set(loaderCtx, value) {
10
- const { symbol } = loaderCtx;
11
- this.store.set(symbol, value);
12
- }
13
- constructor() {
14
- this.store = /* @__PURE__ */ new Map();
15
- }
16
- }
17
- export function createRequestContext() {
18
- return new RequestContext();
19
- }
@@ -1,3 +0,0 @@
1
- import { createLoaderContext } from "./createLoaderCtx";
2
- export { createRequestContext } from "./createRequestCtx";
3
- export const reporterCtx = createLoaderContext();
@@ -1,18 +0,0 @@
1
- function sortByUrlPath(entries) {
2
- entries.sort(function(a, b) {
3
- const length1 = a.urlPath.length;
4
- const length2 = b.urlPath.length;
5
- if (length1 < length2) {
6
- return 1;
7
- }
8
- if (length1 > length2) {
9
- return -1;
10
- }
11
- return 0;
12
- });
13
- return entries;
14
- }
15
- export const matchEntry = (pathname, entries) => {
16
- sortByUrlPath(entries);
17
- return entries.find((entry) => pathname.startsWith(entry.urlPath));
18
- };
@@ -1 +0,0 @@
1
- export * from "react-router-dom/server";
@@ -1,6 +0,0 @@
1
- import serialize from "serialize-javascript";
2
- export const serializeJson = (data) => {
3
- return serialize(data, {
4
- isJSON: true
5
- });
6
- };
@@ -1,38 +0,0 @@
1
- import * as ah from "async_hooks";
2
- const createStorage = () => {
3
- let storage;
4
- if (typeof ah.AsyncLocalStorage !== "undefined") {
5
- storage = new ah.AsyncLocalStorage();
6
- }
7
- const run = (context, cb) => {
8
- if (!storage) {
9
- throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
10
- `);
11
- }
12
- return new Promise((resolve, reject) => {
13
- storage.run(context, () => {
14
- try {
15
- return resolve(cb());
16
- } catch (error) {
17
- return reject(error);
18
- }
19
- });
20
- });
21
- };
22
- const useContext = () => {
23
- if (!storage) {
24
- throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
25
- `);
26
- }
27
- const context = storage.getStore();
28
- 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`);
30
- }
31
- return context;
32
- };
33
- return {
34
- run,
35
- useContext
36
- };
37
- };
38
- export { createStorage };
@@ -1,28 +0,0 @@
1
- function processHrtime(previousTimestamp) {
2
- const now = (/* @__PURE__ */ new Date()).getTime();
3
- const clocktime = now * 1e-3;
4
- let seconds = Math.floor(clocktime);
5
- let nanoseconds = Math.floor(clocktime % 1 * 1e9);
6
- if (previousTimestamp) {
7
- seconds -= previousTimestamp[0];
8
- nanoseconds -= previousTimestamp[1];
9
- if (nanoseconds < 0) {
10
- seconds--;
11
- nanoseconds += 1e9;
12
- }
13
- }
14
- return [
15
- seconds,
16
- nanoseconds
17
- ];
18
- }
19
- const getLatency = (hrtime) => {
20
- const [s, ns] = processHrtime(hrtime);
21
- return s * 1e3 + ns / 1e6;
22
- };
23
- export const time = () => {
24
- const hrtime = processHrtime();
25
- return () => {
26
- return getLatency(hrtime);
27
- };
28
- };
@@ -1,2 +0,0 @@
1
- export declare const isNodeJS: () => boolean;
2
- export declare const isBrowser: () => boolean;