@modern-js/utils 2.34.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/compiled/gradient-string/index.d.ts +1 -0
- package/dist/compiled/gradient-string/index.js +1 -0
- package/dist/compiled/gradient-string/license +21 -0
- package/dist/compiled/gradient-string/package.json +1 -0
- 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 +8 -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
@@ -79,9 +79,9 @@ export default {
|
|
79
79
|
});
|
80
80
|
}
|
81
81
|
function formatWebpackMessages(json, color = defaultColor) {
|
82
|
-
var _json_errors,
|
83
|
-
const formattedErrors =
|
84
|
-
const formattedWarnings =
|
82
|
+
var _json_errors, _json_warnings, _result_errors;
|
83
|
+
const formattedErrors = json === null || json === void 0 ? void 0 : (_json_errors = json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
|
84
|
+
const formattedWarnings = json === null || json === void 0 ? void 0 : (_json_warnings = json.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
|
85
85
|
const result = {
|
86
86
|
errors: formattedErrors || [],
|
87
87
|
warnings: formattedWarnings || [],
|
@@ -89,8 +89,6 @@ export declare const CHAIN_ID: {
|
|
89
89
|
readonly STYLE: "style-loader";
|
90
90
|
/** postcss-loader */
|
91
91
|
readonly POSTCSS: "postcss";
|
92
|
-
/** markdown-loader */
|
93
|
-
readonly MARKDOWN: "markdown";
|
94
92
|
/** ignore-css-loader */
|
95
93
|
readonly IGNORE_CSS: "ignore-css";
|
96
94
|
/** css-modules-typescript-loader */
|
@@ -172,6 +170,8 @@ export declare const CHAIN_ID: {
|
|
172
170
|
readonly HTML_ASYNC_CHUNK: "html-async-chunk";
|
173
171
|
/** SWC_POLYFILL_CHECKER */
|
174
172
|
readonly SWC_POLYFILL_CHECKER: "swc-polyfill-checker-plugin";
|
173
|
+
/** RouterPlugin */
|
174
|
+
readonly ROUTER_MANIFEST: "route-plugin";
|
175
175
|
};
|
176
176
|
/** Predefined minimizers */
|
177
177
|
readonly MINIMIZER: {
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.
|
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",
|
@@ -100,6 +68,7 @@
|
|
100
68
|
"./browserslist": "./dist/compiled/browserslist/index.js",
|
101
69
|
"./webpack-chain": "./dist/compiled/webpack-chain/index.js",
|
102
70
|
"./tsconfig-paths": "./dist/compiled/tsconfig-paths/index.js",
|
71
|
+
"./gradient-string": "./dist/compiled/gradient-string/index.js",
|
103
72
|
"./better-ajv-errors": "./dist/compiled/better-ajv-errors/index.js",
|
104
73
|
"./webpack-dev-middleware": "./dist/compiled/webpack-dev-middleware/index.js"
|
105
74
|
},
|
@@ -116,24 +85,6 @@
|
|
116
85
|
"chain-id": [
|
117
86
|
"./dist/types/cli/constants/chainId.d.ts"
|
118
87
|
],
|
119
|
-
"runtime/router": [
|
120
|
-
"./dist/types/runtime/router.d.ts"
|
121
|
-
],
|
122
|
-
"runtime/remix-router": [
|
123
|
-
"./dist/types/runtime/remixRouter.d.ts"
|
124
|
-
],
|
125
|
-
"runtime/nested-routes": [
|
126
|
-
"./dist/types/runtime/nestedRoutes.d.ts"
|
127
|
-
],
|
128
|
-
"runtime-browser": [
|
129
|
-
"./dist/types/runtime-browser/index.d.ts"
|
130
|
-
],
|
131
|
-
"runtime-node": [
|
132
|
-
"./dist/types/runtime-node/index.d.ts"
|
133
|
-
],
|
134
|
-
"runtime-node/router": [
|
135
|
-
"./dist/types/runtime-node/router.d.ts"
|
136
|
-
],
|
137
88
|
"universal/constants": [
|
138
89
|
"./dist/types/universal/constants.d.ts"
|
139
90
|
],
|
@@ -143,9 +94,6 @@
|
|
143
94
|
"universal/plugin-dag-sort": [
|
144
95
|
"./dist/types/universal/pluginDagSort.d.ts"
|
145
96
|
],
|
146
|
-
"universal/time": [
|
147
|
-
"./dist/types/universal/time.d.ts"
|
148
|
-
],
|
149
97
|
"ajv": [
|
150
98
|
"./dist/compiled/ajv/types/ajv.d.ts"
|
151
99
|
],
|
@@ -200,6 +148,9 @@
|
|
200
148
|
"tsconfig-paths": [
|
201
149
|
"./dist/compiled/tsconfig-paths/lib/index.d.ts"
|
202
150
|
],
|
151
|
+
"gradient-string": [
|
152
|
+
"./dist/compiled/gradient-string/index.d.ts"
|
153
|
+
],
|
203
154
|
"better-ajv-errors": [
|
204
155
|
"./dist/compiled/better-ajv-errors/index.d.ts"
|
205
156
|
],
|
@@ -217,35 +168,17 @@
|
|
217
168
|
"dependencies": {
|
218
169
|
"caniuse-lite": "^1.0.30001520",
|
219
170
|
"lodash": "^4.17.21",
|
220
|
-
"serialize-javascript": "^6.0.0",
|
221
|
-
"react-router-dom": "6.15.0",
|
222
|
-
"@remix-run/router": "1.8.0",
|
223
171
|
"@swc/helpers": "0.5.1"
|
224
172
|
},
|
225
|
-
"peerDependencies": {
|
226
|
-
"react": ">=17.0.0",
|
227
|
-
"react-dom": ">=17.0.0"
|
228
|
-
},
|
229
|
-
"peerDependenciesMeta": {
|
230
|
-
"react": {
|
231
|
-
"optional": true
|
232
|
-
},
|
233
|
-
"react-dom": {
|
234
|
-
"optional": true
|
235
|
-
}
|
236
|
-
},
|
237
173
|
"devDependencies": {
|
238
|
-
"react": "^18.2.0",
|
239
|
-
"react-dom": "^18.2.0",
|
240
174
|
"@types/jest": "^29",
|
241
175
|
"@types/node": "^14",
|
242
176
|
"jest": "^29",
|
243
177
|
"typescript": "^5",
|
244
178
|
"webpack": "^5.88.1",
|
245
|
-
"@types
|
246
|
-
"@
|
247
|
-
"@scripts/jest-config": "2.
|
248
|
-
"@scripts/build": "2.34.0"
|
179
|
+
"@modern-js/types": "2.35.1",
|
180
|
+
"@scripts/build": "2.35.1",
|
181
|
+
"@scripts/jest-config": "2.35.1"
|
249
182
|
},
|
250
183
|
"sideEffects": false,
|
251
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,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,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
|
-
};
|