@modern-js/plugin-data-loader 2.35.2-alpha.0 → 2.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/runtime/index.js +4 -1
- package/dist/esm/runtime/index.js +4 -1
- package/dist/esm-node/runtime/index.js +4 -1
- package/package.json +8 -8
- package/dist/js/modern/cli/create-request.js +0 -66
- package/dist/js/modern/cli/generate-client.js +0 -42
- package/dist/js/modern/cli/loader.js +0 -40
- package/dist/js/modern/common/constants.js +0 -6
- package/dist/js/modern/server/index.js +0 -237
- package/dist/js/node/cli/create-request.js +0 -90
- package/dist/js/node/cli/generate-client.js +0 -71
- package/dist/js/node/cli/loader.js +0 -61
- package/dist/js/node/common/constants.js +0 -30
- package/dist/js/node/server/index.js +0 -261
- package/dist/js/treeshaking/cli/create-request.js +0 -186
- package/dist/js/treeshaking/cli/generate-client.js +0 -45
- package/dist/js/treeshaking/cli/loader.js +0 -154
- package/dist/js/treeshaking/common/constants.js +0 -3
- package/dist/js/treeshaking/server/index.js +0 -578
|
@@ -83,7 +83,10 @@ const createRequest = (context) => {
|
|
|
83
83
|
headers: createLoaderHeaders(context.headers),
|
|
84
84
|
signal: controller.signal
|
|
85
85
|
};
|
|
86
|
-
if (
|
|
86
|
+
if (![
|
|
87
|
+
"GET",
|
|
88
|
+
"HEAD"
|
|
89
|
+
].includes(context.method.toUpperCase())) {
|
|
87
90
|
init.body = context.req;
|
|
88
91
|
}
|
|
89
92
|
const request = new Request(url.href, init);
|
|
@@ -96,7 +96,10 @@ var createRequest = function(context) {
|
|
|
96
96
|
headers: createLoaderHeaders(context.headers),
|
|
97
97
|
signal: controller.signal
|
|
98
98
|
};
|
|
99
|
-
if (
|
|
99
|
+
if (![
|
|
100
|
+
"GET",
|
|
101
|
+
"HEAD"
|
|
102
|
+
].includes(context.method.toUpperCase())) {
|
|
100
103
|
init.body = context.req;
|
|
101
104
|
}
|
|
102
105
|
var request = new Request(url.href, init);
|
|
@@ -58,7 +58,10 @@ const createRequest = (context) => {
|
|
|
58
58
|
headers: createLoaderHeaders(context.headers),
|
|
59
59
|
signal: controller.signal
|
|
60
60
|
};
|
|
61
|
-
if (
|
|
61
|
+
if (![
|
|
62
|
+
"GET",
|
|
63
|
+
"HEAD"
|
|
64
|
+
].includes(context.method.toUpperCase())) {
|
|
62
65
|
init.body = context.req;
|
|
63
66
|
}
|
|
64
67
|
const request = new Request(url.href, init);
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.37.0",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"@remix-run/node": "^1.12.0",
|
|
59
59
|
"path-to-regexp": "^6.2.0",
|
|
60
60
|
"@swc/helpers": "0.5.1",
|
|
61
|
-
"@modern-js/
|
|
62
|
-
"@modern-js/utils": "2.
|
|
61
|
+
"@modern-js/utils": "2.37.0",
|
|
62
|
+
"@modern-js/runtime-utils": "2.37.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@types/babel__core": "^7.20.0",
|
|
@@ -75,11 +75,11 @@
|
|
|
75
75
|
"webpack": "^5.88.1",
|
|
76
76
|
"react": "^18",
|
|
77
77
|
"react-dom": "^18",
|
|
78
|
-
"@modern-js/
|
|
79
|
-
"@modern-js/
|
|
80
|
-
"@
|
|
81
|
-
"@
|
|
82
|
-
"@scripts/jest-config": "2.
|
|
78
|
+
"@modern-js/core": "2.37.0",
|
|
79
|
+
"@modern-js/server-core": "2.37.0",
|
|
80
|
+
"@modern-js/types": "2.37.0",
|
|
81
|
+
"@scripts/build": "2.37.0",
|
|
82
|
+
"@scripts/jest-config": "2.37.0"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"react": ">=17.0.0"
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
import { compile } from "path-to-regexp";
|
|
22
|
-
import { redirect } from "react-router-dom";
|
|
23
|
-
import { LOADER_ID_PARAM, DIRECT_PARAM } from "../common/constants";
|
|
24
|
-
const getRequestUrl = ({
|
|
25
|
-
params,
|
|
26
|
-
request,
|
|
27
|
-
routeId
|
|
28
|
-
}) => {
|
|
29
|
-
const url = new URL(request.url);
|
|
30
|
-
const toPath = compile(url.pathname, {
|
|
31
|
-
encode: encodeURIComponent
|
|
32
|
-
});
|
|
33
|
-
const newPathName = toPath(params);
|
|
34
|
-
url.pathname = newPathName;
|
|
35
|
-
url.searchParams.append(LOADER_ID_PARAM, routeId);
|
|
36
|
-
url.searchParams.append(DIRECT_PARAM, "true");
|
|
37
|
-
return url;
|
|
38
|
-
};
|
|
39
|
-
const handleRedirectResponse = (res) => {
|
|
40
|
-
const { headers } = res;
|
|
41
|
-
const location = headers.get("X-Modernjs-Redirect");
|
|
42
|
-
if (location) {
|
|
43
|
-
return redirect(location);
|
|
44
|
-
}
|
|
45
|
-
return res;
|
|
46
|
-
};
|
|
47
|
-
const createRequest = (routeId, method = "get") => {
|
|
48
|
-
return (_0) => __async(void 0, [_0], function* ({
|
|
49
|
-
params,
|
|
50
|
-
request
|
|
51
|
-
}) {
|
|
52
|
-
const url = getRequestUrl({ params, request, routeId });
|
|
53
|
-
const res = yield fetch(url, {
|
|
54
|
-
method,
|
|
55
|
-
signal: request.signal
|
|
56
|
-
});
|
|
57
|
-
if (!res.ok) {
|
|
58
|
-
throw res;
|
|
59
|
-
}
|
|
60
|
-
return handleRedirectResponse(res);
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
export {
|
|
64
|
-
createRequest,
|
|
65
|
-
getRequestUrl
|
|
66
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
const generateClient = ({
|
|
3
|
-
mapFile,
|
|
4
|
-
loaderId
|
|
5
|
-
}) => {
|
|
6
|
-
delete require.cache[mapFile];
|
|
7
|
-
const loadersMap = require(mapFile);
|
|
8
|
-
let requestCode = ``;
|
|
9
|
-
let exportsCode = ``;
|
|
10
|
-
const requestCreatorPath = path.join(__dirname, "./create-request").replace("/node/cli/", "/treeshaking/cli/").replace(/\\/g, "/");
|
|
11
|
-
const importCode = `
|
|
12
|
-
import { createRequest } from '${requestCreatorPath}';
|
|
13
|
-
`;
|
|
14
|
-
if (!loaderId) {
|
|
15
|
-
requestCode = Object.keys(loadersMap).map((loaderId2) => {
|
|
16
|
-
const { routeId } = loadersMap[loaderId2];
|
|
17
|
-
return `
|
|
18
|
-
const ${loaderId2} = createRequest('${routeId}');
|
|
19
|
-
`;
|
|
20
|
-
}).join("");
|
|
21
|
-
exportsCode = `export {`;
|
|
22
|
-
for (const loader of Object.keys(loadersMap)) {
|
|
23
|
-
exportsCode += `${loader},`;
|
|
24
|
-
}
|
|
25
|
-
exportsCode += "}";
|
|
26
|
-
} else {
|
|
27
|
-
const loader = loadersMap[loaderId];
|
|
28
|
-
requestCode = `
|
|
29
|
-
const loader = createRequest('${loader.routeId}');
|
|
30
|
-
`;
|
|
31
|
-
exportsCode = `export default loader;`;
|
|
32
|
-
}
|
|
33
|
-
const generatedCode = `
|
|
34
|
-
${importCode}
|
|
35
|
-
${requestCode}
|
|
36
|
-
${exportsCode}
|
|
37
|
-
`;
|
|
38
|
-
return generatedCode;
|
|
39
|
-
};
|
|
40
|
-
export {
|
|
41
|
-
generateClient
|
|
42
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
import { generateClient } from "./generate-client";
|
|
22
|
-
function loader(source) {
|
|
23
|
-
return __async(this, null, function* () {
|
|
24
|
-
var _a;
|
|
25
|
-
this.cacheable();
|
|
26
|
-
const target = (_a = this._compiler) == null ? void 0 : _a.options.target;
|
|
27
|
-
if (target === "node") {
|
|
28
|
-
return source;
|
|
29
|
-
}
|
|
30
|
-
const options = this.getOptions();
|
|
31
|
-
const code = generateClient({
|
|
32
|
-
mapFile: options.mapFile,
|
|
33
|
-
loaderId: options.loaderId
|
|
34
|
-
});
|
|
35
|
-
return code;
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
export {
|
|
39
|
-
loader as default
|
|
40
|
-
};
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __async = (__this, __arguments, generator) => {
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
var fulfilled = (value) => {
|
|
23
|
-
try {
|
|
24
|
-
step(generator.next(value));
|
|
25
|
-
} catch (e) {
|
|
26
|
-
reject(e);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var rejected = (value) => {
|
|
30
|
-
try {
|
|
31
|
-
step(generator.throw(value));
|
|
32
|
-
} catch (e) {
|
|
33
|
-
reject(e);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
import path from "path";
|
|
41
|
-
import {
|
|
42
|
-
installGlobals,
|
|
43
|
-
writeReadableStreamToWritable,
|
|
44
|
-
Response as NodeResponse
|
|
45
|
-
} from "@remix-run/node";
|
|
46
|
-
import {
|
|
47
|
-
matchRoutes
|
|
48
|
-
} from "react-router-dom";
|
|
49
|
-
import { MAIN_ENTRY_NAME, SERVER_BUNDLE_DIRECTORY } from "@modern-js/utils";
|
|
50
|
-
import { LOADER_ID_PARAM } from "../common/constants";
|
|
51
|
-
installGlobals();
|
|
52
|
-
const redirectStatusCodes = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
53
|
-
function isRedirectResponse(response) {
|
|
54
|
-
return redirectStatusCodes.has(response.status);
|
|
55
|
-
}
|
|
56
|
-
function isResponse(value) {
|
|
57
|
-
return value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined";
|
|
58
|
-
}
|
|
59
|
-
const json = (data, init = {}) => {
|
|
60
|
-
const responseInit = typeof init === "number" ? { status: init } : init;
|
|
61
|
-
const headers = new Headers(responseInit.headers);
|
|
62
|
-
if (!headers.has("Content-Type")) {
|
|
63
|
-
headers.set("Content-Type", "application/json; charset=utf-8");
|
|
64
|
-
}
|
|
65
|
-
return new NodeResponse(JSON.stringify(data), __spreadProps(__spreadValues({}, responseInit), {
|
|
66
|
-
headers
|
|
67
|
-
}));
|
|
68
|
-
};
|
|
69
|
-
const callRouteLoader = (_0) => __async(void 0, [_0], function* ({
|
|
70
|
-
routeId,
|
|
71
|
-
loader,
|
|
72
|
-
params,
|
|
73
|
-
request,
|
|
74
|
-
loadContext
|
|
75
|
-
}) {
|
|
76
|
-
if (!loader) {
|
|
77
|
-
throw new Error(
|
|
78
|
-
`You made a ${request.method} request to ${request.url} but did not provide a default component or \`loader\` for route "${routeId}", so there is no way to handle the request.`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
let result;
|
|
82
|
-
try {
|
|
83
|
-
result = yield loader({
|
|
84
|
-
request,
|
|
85
|
-
params
|
|
86
|
-
});
|
|
87
|
-
} catch (error) {
|
|
88
|
-
if (!isResponse(error)) {
|
|
89
|
-
throw error;
|
|
90
|
-
}
|
|
91
|
-
result = error;
|
|
92
|
-
}
|
|
93
|
-
if (result === void 0) {
|
|
94
|
-
throw new Error(
|
|
95
|
-
`You defined a loader for route "${routeId}" but didn't return anything from your \`loader\` function. Please return a value or \`null\`.`
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
return isResponse(result) ? result : json(result);
|
|
99
|
-
});
|
|
100
|
-
const createLoaderHeaders = (requestHeaders) => {
|
|
101
|
-
const headers = new Headers();
|
|
102
|
-
for (const [key, values] of Object.entries(requestHeaders)) {
|
|
103
|
-
if (values) {
|
|
104
|
-
if (Array.isArray(values)) {
|
|
105
|
-
for (const value of values) {
|
|
106
|
-
headers.append(key, value);
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
headers.set(key, values);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return headers;
|
|
114
|
-
};
|
|
115
|
-
const createLoaderRequest = (context) => {
|
|
116
|
-
const origin = `${context.protocol}://${context.host}`;
|
|
117
|
-
const url = new URL(context.url, origin);
|
|
118
|
-
const controller = new AbortController();
|
|
119
|
-
const init = {
|
|
120
|
-
method: context.method,
|
|
121
|
-
headers: createLoaderHeaders(context.headers),
|
|
122
|
-
signal: controller.signal
|
|
123
|
-
};
|
|
124
|
-
return new Request(url.href, init);
|
|
125
|
-
};
|
|
126
|
-
const sendLoaderResponse = (res, nodeResponse) => __async(void 0, null, function* () {
|
|
127
|
-
res.statusMessage = nodeResponse.statusText;
|
|
128
|
-
res.statusCode = nodeResponse.status;
|
|
129
|
-
for (const [key, value] of nodeResponse.headers.entries()) {
|
|
130
|
-
res.setHeader(key, value);
|
|
131
|
-
}
|
|
132
|
-
if (nodeResponse.body) {
|
|
133
|
-
yield writeReadableStreamToWritable(nodeResponse.body, res);
|
|
134
|
-
} else {
|
|
135
|
-
res.end();
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
const getPathWithoutEntry = (pathname, entryPath) => {
|
|
139
|
-
if (entryPath === "/") {
|
|
140
|
-
return pathname;
|
|
141
|
-
}
|
|
142
|
-
return pathname.replace(entryPath, "");
|
|
143
|
-
};
|
|
144
|
-
const matchEntry = (pathname, entries) => {
|
|
145
|
-
return entries.find((entry) => pathname.startsWith(entry.urlPath));
|
|
146
|
-
};
|
|
147
|
-
const handleRequest = (_0) => __async(void 0, [_0], function* ({
|
|
148
|
-
context,
|
|
149
|
-
serverRoutes,
|
|
150
|
-
distDir
|
|
151
|
-
}) {
|
|
152
|
-
const { method, query } = context;
|
|
153
|
-
const routeId = query[LOADER_ID_PARAM];
|
|
154
|
-
if (!routeId || method.toLowerCase() !== "get") {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
const entry = matchEntry(context.path, serverRoutes);
|
|
158
|
-
if (!entry) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
const routesPath = path.join(
|
|
162
|
-
distDir,
|
|
163
|
-
SERVER_BUNDLE_DIRECTORY,
|
|
164
|
-
`${entry.entryName || MAIN_ENTRY_NAME}-server-loaders`
|
|
165
|
-
);
|
|
166
|
-
const { routes } = yield import(routesPath);
|
|
167
|
-
if (!routes) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
const { res } = context;
|
|
171
|
-
const pathname = getPathWithoutEntry(context.path, entry.urlPath);
|
|
172
|
-
const matches = matchRoutes(routes, pathname);
|
|
173
|
-
if (!matches) {
|
|
174
|
-
res.statusCode = 403;
|
|
175
|
-
res.end(`Route ${pathname} was not matched`);
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
const match = matches == null ? void 0 : matches.find((match2) => match2.route.id === routeId);
|
|
179
|
-
if (!match) {
|
|
180
|
-
res.statusCode = 403;
|
|
181
|
-
res.end(`Route ${routeId} does not match URL ${context.path}`);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
const request = createLoaderRequest(context);
|
|
185
|
-
let response;
|
|
186
|
-
try {
|
|
187
|
-
response = yield callRouteLoader({
|
|
188
|
-
loader: match.route.loader,
|
|
189
|
-
routeId: match.route.id,
|
|
190
|
-
params: match.params,
|
|
191
|
-
request,
|
|
192
|
-
loadContext: {}
|
|
193
|
-
});
|
|
194
|
-
if (isRedirectResponse(response)) {
|
|
195
|
-
const headers = new Headers(response.headers);
|
|
196
|
-
headers.set("X-Modernjs-Redirect", headers.get("Location"));
|
|
197
|
-
headers.delete("Location");
|
|
198
|
-
response = new NodeResponse(null, {
|
|
199
|
-
status: 204,
|
|
200
|
-
headers
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
} catch (error) {
|
|
204
|
-
const message = String(error);
|
|
205
|
-
response = new NodeResponse(message, {
|
|
206
|
-
status: 500,
|
|
207
|
-
headers: {
|
|
208
|
-
"Content-Type": "text/plain"
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
sendLoaderResponse(res, response);
|
|
213
|
-
});
|
|
214
|
-
var server_default = () => ({
|
|
215
|
-
name: "@modern-js/plugin-data-loader",
|
|
216
|
-
setup: () => ({
|
|
217
|
-
preparebeforeRouteHandler({
|
|
218
|
-
serverRoutes,
|
|
219
|
-
distDir
|
|
220
|
-
}) {
|
|
221
|
-
return (context) => __async(this, null, function* () {
|
|
222
|
-
return handleRequest({
|
|
223
|
-
serverRoutes,
|
|
224
|
-
distDir,
|
|
225
|
-
context
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
})
|
|
230
|
-
});
|
|
231
|
-
export {
|
|
232
|
-
server_default as default,
|
|
233
|
-
getPathWithoutEntry,
|
|
234
|
-
handleRequest,
|
|
235
|
-
isRedirectResponse,
|
|
236
|
-
isResponse
|
|
237
|
-
};
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var __async = (__this, __arguments, generator) => {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
var fulfilled = (value) => {
|
|
21
|
-
try {
|
|
22
|
-
step(generator.next(value));
|
|
23
|
-
} catch (e) {
|
|
24
|
-
reject(e);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var rejected = (value) => {
|
|
28
|
-
try {
|
|
29
|
-
step(generator.throw(value));
|
|
30
|
-
} catch (e) {
|
|
31
|
-
reject(e);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
var create_request_exports = {};
|
|
39
|
-
__export(create_request_exports, {
|
|
40
|
-
createRequest: () => createRequest,
|
|
41
|
-
getRequestUrl: () => getRequestUrl
|
|
42
|
-
});
|
|
43
|
-
module.exports = __toCommonJS(create_request_exports);
|
|
44
|
-
var import_path_to_regexp = require("path-to-regexp");
|
|
45
|
-
var import_react_router_dom = require("react-router-dom");
|
|
46
|
-
var import_constants = require("../common/constants");
|
|
47
|
-
const getRequestUrl = ({
|
|
48
|
-
params,
|
|
49
|
-
request,
|
|
50
|
-
routeId
|
|
51
|
-
}) => {
|
|
52
|
-
const url = new URL(request.url);
|
|
53
|
-
const toPath = (0, import_path_to_regexp.compile)(url.pathname, {
|
|
54
|
-
encode: encodeURIComponent
|
|
55
|
-
});
|
|
56
|
-
const newPathName = toPath(params);
|
|
57
|
-
url.pathname = newPathName;
|
|
58
|
-
url.searchParams.append(import_constants.LOADER_ID_PARAM, routeId);
|
|
59
|
-
url.searchParams.append(import_constants.DIRECT_PARAM, "true");
|
|
60
|
-
return url;
|
|
61
|
-
};
|
|
62
|
-
const handleRedirectResponse = (res) => {
|
|
63
|
-
const { headers } = res;
|
|
64
|
-
const location = headers.get("X-Modernjs-Redirect");
|
|
65
|
-
if (location) {
|
|
66
|
-
return (0, import_react_router_dom.redirect)(location);
|
|
67
|
-
}
|
|
68
|
-
return res;
|
|
69
|
-
};
|
|
70
|
-
const createRequest = (routeId, method = "get") => {
|
|
71
|
-
return (_0) => __async(void 0, [_0], function* ({
|
|
72
|
-
params,
|
|
73
|
-
request
|
|
74
|
-
}) {
|
|
75
|
-
const url = getRequestUrl({ params, request, routeId });
|
|
76
|
-
const res = yield fetch(url, {
|
|
77
|
-
method,
|
|
78
|
-
signal: request.signal
|
|
79
|
-
});
|
|
80
|
-
if (!res.ok) {
|
|
81
|
-
throw res;
|
|
82
|
-
}
|
|
83
|
-
return handleRedirectResponse(res);
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
-
0 && (module.exports = {
|
|
88
|
-
createRequest,
|
|
89
|
-
getRequestUrl
|
|
90
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var generate_client_exports = {};
|
|
25
|
-
__export(generate_client_exports, {
|
|
26
|
-
generateClient: () => generateClient
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(generate_client_exports);
|
|
29
|
-
var import_path = __toESM(require("path"));
|
|
30
|
-
const generateClient = ({
|
|
31
|
-
mapFile,
|
|
32
|
-
loaderId
|
|
33
|
-
}) => {
|
|
34
|
-
delete require.cache[mapFile];
|
|
35
|
-
const loadersMap = require(mapFile);
|
|
36
|
-
let requestCode = ``;
|
|
37
|
-
let exportsCode = ``;
|
|
38
|
-
const requestCreatorPath = import_path.default.join(__dirname, "./create-request").replace("/node/cli/", "/treeshaking/cli/").replace(/\\/g, "/");
|
|
39
|
-
const importCode = `
|
|
40
|
-
import { createRequest } from '${requestCreatorPath}';
|
|
41
|
-
`;
|
|
42
|
-
if (!loaderId) {
|
|
43
|
-
requestCode = Object.keys(loadersMap).map((loaderId2) => {
|
|
44
|
-
const { routeId } = loadersMap[loaderId2];
|
|
45
|
-
return `
|
|
46
|
-
const ${loaderId2} = createRequest('${routeId}');
|
|
47
|
-
`;
|
|
48
|
-
}).join("");
|
|
49
|
-
exportsCode = `export {`;
|
|
50
|
-
for (const loader of Object.keys(loadersMap)) {
|
|
51
|
-
exportsCode += `${loader},`;
|
|
52
|
-
}
|
|
53
|
-
exportsCode += "}";
|
|
54
|
-
} else {
|
|
55
|
-
const loader = loadersMap[loaderId];
|
|
56
|
-
requestCode = `
|
|
57
|
-
const loader = createRequest('${loader.routeId}');
|
|
58
|
-
`;
|
|
59
|
-
exportsCode = `export default loader;`;
|
|
60
|
-
}
|
|
61
|
-
const generatedCode = `
|
|
62
|
-
${importCode}
|
|
63
|
-
${requestCode}
|
|
64
|
-
${exportsCode}
|
|
65
|
-
`;
|
|
66
|
-
return generatedCode;
|
|
67
|
-
};
|
|
68
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
-
0 && (module.exports = {
|
|
70
|
-
generateClient
|
|
71
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var __async = (__this, __arguments, generator) => {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
var fulfilled = (value) => {
|
|
21
|
-
try {
|
|
22
|
-
step(generator.next(value));
|
|
23
|
-
} catch (e) {
|
|
24
|
-
reject(e);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var rejected = (value) => {
|
|
28
|
-
try {
|
|
29
|
-
step(generator.throw(value));
|
|
30
|
-
} catch (e) {
|
|
31
|
-
reject(e);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
var loader_exports = {};
|
|
39
|
-
__export(loader_exports, {
|
|
40
|
-
default: () => loader
|
|
41
|
-
});
|
|
42
|
-
module.exports = __toCommonJS(loader_exports);
|
|
43
|
-
var import_generate_client = require("./generate-client");
|
|
44
|
-
function loader(source) {
|
|
45
|
-
return __async(this, null, function* () {
|
|
46
|
-
var _a;
|
|
47
|
-
this.cacheable();
|
|
48
|
-
const target = (_a = this._compiler) == null ? void 0 : _a.options.target;
|
|
49
|
-
if (target === "node") {
|
|
50
|
-
return source;
|
|
51
|
-
}
|
|
52
|
-
const options = this.getOptions();
|
|
53
|
-
const code = (0, import_generate_client.generateClient)({
|
|
54
|
-
mapFile: options.mapFile,
|
|
55
|
-
loaderId: options.loaderId
|
|
56
|
-
});
|
|
57
|
-
return code;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
-
0 && (module.exports = {});
|