@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.
- package/dist/cjs/cli/alias.js +3 -3
- package/dist/cjs/cli/constants/chainId.js +3 -3
- package/dist/cjs/cli/is/config.js +9 -11
- package/dist/cjs/cli/logger.js +6 -1
- package/dist/cjs/cli/port.js +1 -1
- package/dist/cjs/cli/prettyInstructions.js +2 -5
- package/dist/cjs/cli/require.js +1 -2
- package/dist/cjs/universal/formatWebpack.js +3 -3
- package/dist/esm/cli/alias.js +3 -3
- package/dist/esm/cli/constants/chainId.js +3 -3
- package/dist/esm/cli/is/config.js +9 -11
- package/dist/esm/cli/logger.js +6 -1
- package/dist/esm/cli/port.js +1 -1
- package/dist/esm/cli/prettyInstructions.js +2 -3
- package/dist/esm/cli/require.js +1 -2
- package/dist/esm/universal/formatWebpack.js +3 -3
- package/dist/esm-node/cli/alias.js +3 -3
- package/dist/esm-node/cli/constants/chainId.js +3 -3
- package/dist/esm-node/cli/is/config.js +9 -11
- package/dist/esm-node/cli/logger.js +6 -1
- package/dist/esm-node/cli/port.js +1 -1
- package/dist/esm-node/cli/prettyInstructions.js +2 -5
- package/dist/esm-node/cli/require.js +1 -2
- package/dist/esm-node/universal/formatWebpack.js +3 -3
- package/dist/types/cli/constants/chainId.d.ts +2 -2
- package/dist/types/cli/logger.d.ts +5 -0
- package/package.json +4 -75
- package/dist/cjs/runtime/nestedRoutes.js +0 -149
- package/dist/cjs/runtime/remixRouter.js +0 -6
- package/dist/cjs/runtime/router.js +0 -6
- package/dist/cjs/runtime-browser/index.js +0 -6
- package/dist/cjs/runtime-browser/parsed.js +0 -28
- package/dist/cjs/runtime-node/index.js +0 -28
- package/dist/cjs/runtime-node/loaderContext/createLoaderCtx.js +0 -34
- package/dist/cjs/runtime-node/loaderContext/createRequestCtx.js +0 -38
- package/dist/cjs/runtime-node/loaderContext/index.js +0 -22
- package/dist/cjs/runtime-node/nestedRoutes.js +0 -28
- package/dist/cjs/runtime-node/router.js +0 -6
- package/dist/cjs/runtime-node/serialize.js +0 -17
- package/dist/cjs/runtime-node/storage.js +0 -48
- package/dist/cjs/universal/time.js +0 -38
- package/dist/esm/runtime/nestedRoutes.js +0 -163
- package/dist/esm/runtime/remixRouter.js +0 -1
- package/dist/esm/runtime/router.js +0 -1
- package/dist/esm/runtime-browser/index.js +0 -1
- package/dist/esm/runtime-browser/parsed.js +0 -18
- package/dist/esm/runtime-node/index.js +0 -6
- package/dist/esm/runtime-node/loaderContext/createLoaderCtx.js +0 -20
- package/dist/esm/runtime-node/loaderContext/createRequestCtx.js +0 -24
- package/dist/esm/runtime-node/loaderContext/index.js +0 -3
- package/dist/esm/runtime-node/nestedRoutes.js +0 -20
- package/dist/esm/runtime-node/router.js +0 -1
- package/dist/esm/runtime-node/serialize.js +0 -6
- package/dist/esm/runtime-node/storage.js +0 -36
- package/dist/esm/universal/time.js +0 -29
- package/dist/esm-node/runtime/nestedRoutes.js +0 -129
- package/dist/esm-node/runtime/remixRouter.js +0 -1
- package/dist/esm-node/runtime/router.js +0 -1
- package/dist/esm-node/runtime-browser/index.js +0 -1
- package/dist/esm-node/runtime-browser/parsed.js +0 -18
- package/dist/esm-node/runtime-node/index.js +0 -6
- package/dist/esm-node/runtime-node/loaderContext/createLoaderCtx.js +0 -15
- package/dist/esm-node/runtime-node/loaderContext/createRequestCtx.js +0 -19
- package/dist/esm-node/runtime-node/loaderContext/index.js +0 -3
- package/dist/esm-node/runtime-node/nestedRoutes.js +0 -18
- package/dist/esm-node/runtime-node/router.js +0 -1
- package/dist/esm-node/runtime-node/serialize.js +0 -6
- package/dist/esm-node/runtime-node/storage.js +0 -38
- package/dist/esm-node/universal/time.js +0 -28
- package/dist/types/runtime/nestedRoutes.d.ts +0 -13
- package/dist/types/runtime/remixRouter.d.ts +0 -1
- package/dist/types/runtime/router.d.ts +0 -1
- package/dist/types/runtime-browser/index.d.ts +0 -1
- package/dist/types/runtime-browser/parsed.d.ts +0 -1
- package/dist/types/runtime-node/index.d.ts +0 -10
- package/dist/types/runtime-node/loaderContext/createLoaderCtx.d.ts +0 -7
- package/dist/types/runtime-node/loaderContext/createRequestCtx.d.ts +0 -7
- package/dist/types/runtime-node/loaderContext/index.d.ts +0 -4
- package/dist/types/runtime-node/nestedRoutes.d.ts +0 -3
- package/dist/types/runtime-node/router.d.ts +0 -1
- package/dist/types/runtime-node/serialize.d.ts +0 -1
- package/dist/types/runtime-node/storage.d.ts +0 -5
- 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,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,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,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,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,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,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,13 +0,0 @@
|
|
1
|
-
/// <reference types="react" />
|
2
|
-
import type { NestedRoute, Reporter } from '@modern-js/types';
|
3
|
-
export declare const transformNestedRoutes: (routes: NestedRoute[], reporter: Reporter) => import("react-router-dom").RouteObject[];
|
4
|
-
type DeferredDataComponentType = (props?: {
|
5
|
-
nonce?: string;
|
6
|
-
}) => JSX.Element | null;
|
7
|
-
export declare const renderNestedRoute: (nestedRoute: NestedRoute, options?: {
|
8
|
-
parent?: NestedRoute;
|
9
|
-
DeferredDataComponent?: DeferredDataComponentType;
|
10
|
-
props?: Record<string, any>;
|
11
|
-
reporter?: Reporter;
|
12
|
-
}) => JSX.Element;
|
13
|
-
export {};
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from '@remix-run/router';
|