@modern-js/plugin-data-loader 2.8.0 → 2.10.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/CHANGELOG.md +28 -0
- package/dist/cjs/common/utils.js +44 -0
- package/dist/cjs/runtime/index.js +10 -30
- package/dist/cjs/server/index.js +3 -3
- package/dist/esm/common/utils.js +21 -0
- package/dist/esm/runtime/index.js +15 -30
- package/dist/esm/server/index.js +2 -2
- package/dist/esm-node/common/utils.js +21 -0
- package/dist/esm-node/runtime/index.js +8 -27
- package/dist/esm-node/server/index.js +2 -2
- package/dist/types/cli/data.d.ts +7 -2
- package/dist/types/common/utils.d.ts +3 -0
- package/dist/types/runtime/index.d.ts +3 -4
- package/package.json +14 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @modern-js/plugin-data-loader
|
|
2
2
|
|
|
3
|
+
## 2.10.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3e0bd50: feat: when enable bff handle render, support use `useContext` to get framework plugin context in data loader.
|
|
8
|
+
feat: 当开启 BFF 托管渲染时,支持在 data loader 中使用 `useContext` 获取框架插件提供的上下文。
|
|
9
|
+
- 0da32d0: chore: upgrade jest and puppeteer
|
|
10
|
+
chore: 升级 jest 和 puppeteer 到 latest
|
|
11
|
+
- 0d9962b: fix: add types field in package.json
|
|
12
|
+
fix: 添加 package.json 中的 types 字段
|
|
13
|
+
- fbefa7e: chore(deps): bump webpack from 5.75.0 to 5.76.2
|
|
14
|
+
|
|
15
|
+
chore(deps): 将 webpack 从 5.75.0 升级至 5.76.2
|
|
16
|
+
|
|
17
|
+
- d6b6e29: fix: split server and runtime code in plugin-data-loader
|
|
18
|
+
fix: 分离 plugin-data-loader 中服务端和客户端运行时的代码
|
|
19
|
+
- Updated dependencies [0da32d0]
|
|
20
|
+
- Updated dependencies [fbefa7e]
|
|
21
|
+
- Updated dependencies [4d54233]
|
|
22
|
+
- Updated dependencies [6db4864]
|
|
23
|
+
- @modern-js/utils@2.10.0
|
|
24
|
+
|
|
25
|
+
## 2.9.0
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- @modern-js/utils@2.9.0
|
|
30
|
+
|
|
3
31
|
## 2.8.0
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
|
@@ -0,0 +1,44 @@
|
|
|
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 utils_exports = {};
|
|
19
|
+
__export(utils_exports, {
|
|
20
|
+
matchEntry: () => matchEntry
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(utils_exports);
|
|
23
|
+
function sortByUrlPath(entries) {
|
|
24
|
+
entries.sort(function(a, b) {
|
|
25
|
+
const length1 = a.urlPath.length;
|
|
26
|
+
const length2 = b.urlPath.length;
|
|
27
|
+
if (length1 < length2) {
|
|
28
|
+
return 1;
|
|
29
|
+
}
|
|
30
|
+
if (length1 > length2) {
|
|
31
|
+
return -1;
|
|
32
|
+
}
|
|
33
|
+
return 0;
|
|
34
|
+
});
|
|
35
|
+
return entries;
|
|
36
|
+
}
|
|
37
|
+
const matchEntry = (pathname, entries) => {
|
|
38
|
+
sortByUrlPath(entries);
|
|
39
|
+
return entries.find((entry) => pathname.startsWith(entry.urlPath));
|
|
40
|
+
};
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
matchEntry
|
|
44
|
+
});
|
|
@@ -19,8 +19,7 @@ var runtime_exports = {};
|
|
|
19
19
|
__export(runtime_exports, {
|
|
20
20
|
handleRequest: () => handleRequest,
|
|
21
21
|
isRedirectResponse: () => isRedirectResponse,
|
|
22
|
-
isResponse: () => isResponse
|
|
23
|
-
matchEntry: () => matchEntry
|
|
22
|
+
isResponse: () => isResponse
|
|
24
23
|
});
|
|
25
24
|
module.exports = __toCommonJS(runtime_exports);
|
|
26
25
|
var import_node = require("@remix-run/node");
|
|
@@ -28,6 +27,7 @@ var import_nestedRoutes = require("@modern-js/utils/nestedRoutes");
|
|
|
28
27
|
var import_remix_router = require("@modern-js/utils/remix-router");
|
|
29
28
|
var import_lodash = require("@modern-js/utils/lodash");
|
|
30
29
|
var import_constants = require("../common/constants");
|
|
30
|
+
var import_utils = require("../common/utils");
|
|
31
31
|
var import_response = require("./response");
|
|
32
32
|
(0, import_node.installGlobals)();
|
|
33
33
|
const redirectStatusCodes = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
@@ -37,20 +37,6 @@ function isRedirectResponse(status) {
|
|
|
37
37
|
function isResponse(value) {
|
|
38
38
|
return value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined";
|
|
39
39
|
}
|
|
40
|
-
function sortByUrlPath(entries) {
|
|
41
|
-
entries.sort(function(a, b) {
|
|
42
|
-
const length1 = a.urlPath.length;
|
|
43
|
-
const length2 = b.urlPath.length;
|
|
44
|
-
if (length1 < length2) {
|
|
45
|
-
return 1;
|
|
46
|
-
}
|
|
47
|
-
if (length1 > length2) {
|
|
48
|
-
return -1;
|
|
49
|
-
}
|
|
50
|
-
return 0;
|
|
51
|
-
});
|
|
52
|
-
return entries;
|
|
53
|
-
}
|
|
54
40
|
function convertModernRedirectResponse(headers, basename) {
|
|
55
41
|
const newHeaders = new Headers(headers);
|
|
56
42
|
let redirectUrl = headers.get("Location");
|
|
@@ -102,18 +88,14 @@ const sendLoaderResponse = async (res, nodeResponse) => {
|
|
|
102
88
|
res.end();
|
|
103
89
|
}
|
|
104
90
|
};
|
|
105
|
-
const matchEntry = (pathname, entries) => {
|
|
106
|
-
sortByUrlPath(entries);
|
|
107
|
-
return entries.find((entry) => pathname.startsWith(entry.urlPath));
|
|
108
|
-
};
|
|
109
91
|
const handleRequest = async ({
|
|
110
92
|
context,
|
|
111
93
|
serverRoutes,
|
|
112
|
-
routes
|
|
94
|
+
routes: routesConfig
|
|
113
95
|
}) => {
|
|
114
96
|
const { method, query } = context;
|
|
115
97
|
const routeId = query[import_constants.LOADER_ID_PARAM];
|
|
116
|
-
const entry = matchEntry(context.path, serverRoutes);
|
|
98
|
+
const entry = (0, import_utils.matchEntry)(context.path, serverRoutes);
|
|
117
99
|
if (!routeId || !entry) {
|
|
118
100
|
return;
|
|
119
101
|
}
|
|
@@ -121,17 +103,16 @@ const handleRequest = async ({
|
|
|
121
103
|
throw new Error("CSR data loader request only support http GET method");
|
|
122
104
|
}
|
|
123
105
|
const basename = entry.urlPath;
|
|
124
|
-
const
|
|
125
|
-
const
|
|
106
|
+
const routes = (0, import_nestedRoutes.transformNestedRoutes)(routesConfig);
|
|
107
|
+
const { queryRoute } = (0, import_remix_router.createStaticHandler)(routes, {
|
|
126
108
|
basename
|
|
127
109
|
});
|
|
128
110
|
const { res } = context;
|
|
129
111
|
const request = createLoaderRequest(context);
|
|
130
112
|
let response;
|
|
131
113
|
try {
|
|
132
|
-
response = await
|
|
133
|
-
routeId
|
|
134
|
-
requestContext: context
|
|
114
|
+
response = await queryRoute(request, {
|
|
115
|
+
routeId
|
|
135
116
|
});
|
|
136
117
|
if (isResponse(response) && isRedirectResponse(response.status)) {
|
|
137
118
|
response = convertModernRedirectResponse(response.headers, basename);
|
|
@@ -169,12 +150,11 @@ const handleRequest = async ({
|
|
|
169
150
|
}
|
|
170
151
|
});
|
|
171
152
|
}
|
|
172
|
-
sendLoaderResponse(res, response);
|
|
153
|
+
await sendLoaderResponse(res, response);
|
|
173
154
|
};
|
|
174
155
|
// Annotate the CommonJS export names for ESM import in node:
|
|
175
156
|
0 && (module.exports = {
|
|
176
157
|
handleRequest,
|
|
177
158
|
isRedirectResponse,
|
|
178
|
-
isResponse
|
|
179
|
-
matchEntry
|
|
159
|
+
isResponse
|
|
180
160
|
});
|
package/dist/cjs/server/index.js
CHANGED
|
@@ -33,16 +33,16 @@ module.exports = __toCommonJS(server_exports);
|
|
|
33
33
|
var import_path = __toESM(require("path"));
|
|
34
34
|
var import_fs = __toESM(require("fs"));
|
|
35
35
|
var import_utils = require("@modern-js/utils");
|
|
36
|
-
var
|
|
36
|
+
var import_utils2 = require("../common/utils");
|
|
37
37
|
var server_default = () => ({
|
|
38
38
|
name: "@modern-js/plugin-data-loader",
|
|
39
39
|
setup: () => ({
|
|
40
|
-
|
|
40
|
+
prepareLoaderHandler({
|
|
41
41
|
serverRoutes,
|
|
42
42
|
distDir
|
|
43
43
|
}) {
|
|
44
44
|
return async (context) => {
|
|
45
|
-
const entry = (0,
|
|
45
|
+
const entry = (0, import_utils2.matchEntry)(context.path, serverRoutes);
|
|
46
46
|
if (!entry) {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
var matchEntry = function(pathname, entries) {
|
|
16
|
+
sortByUrlPath(entries);
|
|
17
|
+
return entries.find(function(entry) {
|
|
18
|
+
return pathname.startsWith(entry.urlPath);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export { matchEntry };
|
|
@@ -180,6 +180,7 @@ import { transformNestedRoutes } from "@modern-js/utils/nestedRoutes";
|
|
|
180
180
|
import { createStaticHandler, ErrorResponse, UNSAFE_DEFERRED_SYMBOL as DEFERRED_SYMBOL } from "@modern-js/utils/remix-router";
|
|
181
181
|
import { isPlainObject } from "@modern-js/utils/lodash";
|
|
182
182
|
import { CONTENT_TYPE_DEFERRED, LOADER_ID_PARAM } from "../common/constants";
|
|
183
|
+
import { matchEntry } from "../common/utils";
|
|
183
184
|
import { createDeferredReadableStream } from "./response";
|
|
184
185
|
installGlobals();
|
|
185
186
|
var redirectStatusCodes = /* @__PURE__ */ new Set([
|
|
@@ -195,20 +196,6 @@ function isRedirectResponse(status) {
|
|
|
195
196
|
function isResponse(value) {
|
|
196
197
|
return value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined";
|
|
197
198
|
}
|
|
198
|
-
function sortByUrlPath(entries) {
|
|
199
|
-
entries.sort(function(a, b) {
|
|
200
|
-
var length1 = a.urlPath.length;
|
|
201
|
-
var length2 = b.urlPath.length;
|
|
202
|
-
if (length1 < length2) {
|
|
203
|
-
return 1;
|
|
204
|
-
}
|
|
205
|
-
if (length1 > length2) {
|
|
206
|
-
return -1;
|
|
207
|
-
}
|
|
208
|
-
return 0;
|
|
209
|
-
});
|
|
210
|
-
return entries;
|
|
211
|
-
}
|
|
212
199
|
function convertModernRedirectResponse(headers, basename) {
|
|
213
200
|
var newHeaders = new Headers(headers);
|
|
214
201
|
var redirectUrl = headers.get("Location");
|
|
@@ -338,19 +325,13 @@ var sendLoaderResponse = function() {
|
|
|
338
325
|
return _ref.apply(this, arguments);
|
|
339
326
|
};
|
|
340
327
|
}();
|
|
341
|
-
var matchEntry = function(pathname, entries) {
|
|
342
|
-
sortByUrlPath(entries);
|
|
343
|
-
return entries.find(function(entry) {
|
|
344
|
-
return pathname.startsWith(entry.urlPath);
|
|
345
|
-
});
|
|
346
|
-
};
|
|
347
328
|
var handleRequest = function() {
|
|
348
329
|
var _ref = _asyncToGenerator(function(param) {
|
|
349
|
-
var context, serverRoutes,
|
|
330
|
+
var context, serverRoutes, routesConfig, method, query, routeId, entry, basename, routes, queryRoute, res, request, response, deferredData, body, init, headers, error, message;
|
|
350
331
|
return __generator(this, function(_state) {
|
|
351
332
|
switch(_state.label){
|
|
352
333
|
case 0:
|
|
353
|
-
context = param.context, serverRoutes = param.serverRoutes,
|
|
334
|
+
context = param.context, serverRoutes = param.serverRoutes, routesConfig = param.routes;
|
|
354
335
|
method = context.method, query = context.query;
|
|
355
336
|
routeId = query[LOADER_ID_PARAM];
|
|
356
337
|
entry = matchEntry(context.path, serverRoutes);
|
|
@@ -363,10 +344,10 @@ var handleRequest = function() {
|
|
|
363
344
|
throw new Error("CSR data loader request only support http GET method");
|
|
364
345
|
}
|
|
365
346
|
basename = entry.urlPath;
|
|
366
|
-
|
|
367
|
-
|
|
347
|
+
routes = transformNestedRoutes(routesConfig);
|
|
348
|
+
queryRoute = createStaticHandler(routes, {
|
|
368
349
|
basename: basename
|
|
369
|
-
});
|
|
350
|
+
}).queryRoute;
|
|
370
351
|
res = context.res;
|
|
371
352
|
request = createLoaderRequest(context);
|
|
372
353
|
_state.label = 1;
|
|
@@ -379,9 +360,8 @@ var handleRequest = function() {
|
|
|
379
360
|
]);
|
|
380
361
|
return [
|
|
381
362
|
4,
|
|
382
|
-
|
|
383
|
-
routeId: routeId
|
|
384
|
-
requestContext: context
|
|
363
|
+
queryRoute(request, {
|
|
364
|
+
routeId: routeId
|
|
385
365
|
})
|
|
386
366
|
];
|
|
387
367
|
case 2:
|
|
@@ -428,7 +408,12 @@ var handleRequest = function() {
|
|
|
428
408
|
4
|
|
429
409
|
];
|
|
430
410
|
case 4:
|
|
431
|
-
|
|
411
|
+
return [
|
|
412
|
+
4,
|
|
413
|
+
sendLoaderResponse(res, response)
|
|
414
|
+
];
|
|
415
|
+
case 5:
|
|
416
|
+
_state.sent();
|
|
432
417
|
return [
|
|
433
418
|
2
|
|
434
419
|
];
|
|
@@ -439,4 +424,4 @@ var handleRequest = function() {
|
|
|
439
424
|
return _ref.apply(this, arguments);
|
|
440
425
|
};
|
|
441
426
|
}();
|
|
442
|
-
export { handleRequest, isRedirectResponse, isResponse
|
|
427
|
+
export { handleRequest, isRedirectResponse, isResponse };
|
package/dist/esm/server/index.js
CHANGED
|
@@ -125,13 +125,13 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
125
125
|
import path from "path";
|
|
126
126
|
import fs from "fs";
|
|
127
127
|
import { MAIN_ENTRY_NAME, SERVER_BUNDLE_DIRECTORY } from "@modern-js/utils";
|
|
128
|
-
import { matchEntry } from "../
|
|
128
|
+
import { matchEntry } from "../common/utils";
|
|
129
129
|
var server_default = function() {
|
|
130
130
|
return {
|
|
131
131
|
name: "@modern-js/plugin-data-loader",
|
|
132
132
|
setup: function() {
|
|
133
133
|
return {
|
|
134
|
-
|
|
134
|
+
prepareLoaderHandler: function prepareLoaderHandler(param) {
|
|
135
135
|
var serverRoutes = param.serverRoutes, distDir = param.distDir;
|
|
136
136
|
return function() {
|
|
137
137
|
var _ref = _asyncToGenerator(function(context) {
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
const matchEntry = (pathname, entries) => {
|
|
16
|
+
sortByUrlPath(entries);
|
|
17
|
+
return entries.find((entry) => pathname.startsWith(entry.urlPath));
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
matchEntry
|
|
21
|
+
};
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from "@modern-js/utils/remix-router";
|
|
12
12
|
import { isPlainObject } from "@modern-js/utils/lodash";
|
|
13
13
|
import { CONTENT_TYPE_DEFERRED, LOADER_ID_PARAM } from "../common/constants";
|
|
14
|
+
import { matchEntry } from "../common/utils";
|
|
14
15
|
import { createDeferredReadableStream } from "./response";
|
|
15
16
|
installGlobals();
|
|
16
17
|
const redirectStatusCodes = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
@@ -20,20 +21,6 @@ function isRedirectResponse(status) {
|
|
|
20
21
|
function isResponse(value) {
|
|
21
22
|
return value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined";
|
|
22
23
|
}
|
|
23
|
-
function sortByUrlPath(entries) {
|
|
24
|
-
entries.sort(function(a, b) {
|
|
25
|
-
const length1 = a.urlPath.length;
|
|
26
|
-
const length2 = b.urlPath.length;
|
|
27
|
-
if (length1 < length2) {
|
|
28
|
-
return 1;
|
|
29
|
-
}
|
|
30
|
-
if (length1 > length2) {
|
|
31
|
-
return -1;
|
|
32
|
-
}
|
|
33
|
-
return 0;
|
|
34
|
-
});
|
|
35
|
-
return entries;
|
|
36
|
-
}
|
|
37
24
|
function convertModernRedirectResponse(headers, basename) {
|
|
38
25
|
const newHeaders = new Headers(headers);
|
|
39
26
|
let redirectUrl = headers.get("Location");
|
|
@@ -85,14 +72,10 @@ const sendLoaderResponse = async (res, nodeResponse) => {
|
|
|
85
72
|
res.end();
|
|
86
73
|
}
|
|
87
74
|
};
|
|
88
|
-
const matchEntry = (pathname, entries) => {
|
|
89
|
-
sortByUrlPath(entries);
|
|
90
|
-
return entries.find((entry) => pathname.startsWith(entry.urlPath));
|
|
91
|
-
};
|
|
92
75
|
const handleRequest = async ({
|
|
93
76
|
context,
|
|
94
77
|
serverRoutes,
|
|
95
|
-
routes
|
|
78
|
+
routes: routesConfig
|
|
96
79
|
}) => {
|
|
97
80
|
const { method, query } = context;
|
|
98
81
|
const routeId = query[LOADER_ID_PARAM];
|
|
@@ -104,17 +87,16 @@ const handleRequest = async ({
|
|
|
104
87
|
throw new Error("CSR data loader request only support http GET method");
|
|
105
88
|
}
|
|
106
89
|
const basename = entry.urlPath;
|
|
107
|
-
const
|
|
108
|
-
const
|
|
90
|
+
const routes = transformNestedRoutes(routesConfig);
|
|
91
|
+
const { queryRoute } = createStaticHandler(routes, {
|
|
109
92
|
basename
|
|
110
93
|
});
|
|
111
94
|
const { res } = context;
|
|
112
95
|
const request = createLoaderRequest(context);
|
|
113
96
|
let response;
|
|
114
97
|
try {
|
|
115
|
-
response = await
|
|
116
|
-
routeId
|
|
117
|
-
requestContext: context
|
|
98
|
+
response = await queryRoute(request, {
|
|
99
|
+
routeId
|
|
118
100
|
});
|
|
119
101
|
if (isResponse(response) && isRedirectResponse(response.status)) {
|
|
120
102
|
response = convertModernRedirectResponse(response.headers, basename);
|
|
@@ -152,11 +134,10 @@ const handleRequest = async ({
|
|
|
152
134
|
}
|
|
153
135
|
});
|
|
154
136
|
}
|
|
155
|
-
sendLoaderResponse(res, response);
|
|
137
|
+
await sendLoaderResponse(res, response);
|
|
156
138
|
};
|
|
157
139
|
export {
|
|
158
140
|
handleRequest,
|
|
159
141
|
isRedirectResponse,
|
|
160
|
-
isResponse
|
|
161
|
-
matchEntry
|
|
142
|
+
isResponse
|
|
162
143
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import { MAIN_ENTRY_NAME, SERVER_BUNDLE_DIRECTORY } from "@modern-js/utils";
|
|
4
|
-
import { matchEntry } from "../
|
|
4
|
+
import { matchEntry } from "../common/utils";
|
|
5
5
|
var server_default = () => ({
|
|
6
6
|
name: "@modern-js/plugin-data-loader",
|
|
7
7
|
setup: () => ({
|
|
8
|
-
|
|
8
|
+
prepareLoaderHandler({
|
|
9
9
|
serverRoutes,
|
|
10
10
|
distDir
|
|
11
11
|
}) {
|
package/dist/types/cli/data.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* modified
|
|
3
|
-
*
|
|
2
|
+
* The following code is modified based on
|
|
3
|
+
* https://github.com/remix-run/remix/blob/2b5e1a72fc628d0408e27cf4d72e537762f1dc5b/packages/remix-react/data.ts
|
|
4
|
+
*
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
* Author Michael Jackson
|
|
7
|
+
* Copyright 2021 Remix Software Inc.
|
|
8
|
+
* https://github.com/remix-run/remix/blob/2b5e1a72fc628d0408e27cf4d72e537762f1dc5b/LICENSE.md
|
|
4
9
|
*/
|
|
5
10
|
import { UNSAFE_DeferredData as DeferredData } from '@modern-js/utils/remix-router';
|
|
6
11
|
export declare function parseDeferredReadableStream(stream: ReadableStream<Uint8Array>): Promise<DeferredData>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ModernServerContext, ServerRoute } from '@modern-js/types';
|
|
2
|
+
export type ServerContext = Pick<ModernServerContext, 'req' | 'res' | 'params' | 'headers' | 'method' | 'url' | 'host' | 'protocol' | 'origin' | 'href' | 'path' | 'query'>;
|
|
3
|
+
export declare const matchEntry: (pathname: string, entries: ServerRoute[]) => ServerRoute | undefined;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NestedRoute, ServerRoute } from '@modern-js/types';
|
|
2
2
|
import { Response as NodeResponse } from '@remix-run/node';
|
|
3
|
-
|
|
3
|
+
import { ServerContext } from '../common/utils';
|
|
4
4
|
export declare function isRedirectResponse(status: number): boolean;
|
|
5
5
|
export declare function isResponse(value: any): value is NodeResponse;
|
|
6
|
-
export declare const matchEntry: (pathname: string, entries: ServerRoute[]) => ServerRoute | undefined;
|
|
7
6
|
export declare const handleRequest: ({
|
|
8
7
|
context,
|
|
9
8
|
serverRoutes,
|
|
10
|
-
routes
|
|
9
|
+
routes: routesConfig
|
|
11
10
|
}: {
|
|
12
11
|
context: ServerContext;
|
|
13
12
|
serverRoutes: ServerRoute[];
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.10.0",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=14.17.6"
|
|
17
17
|
},
|
|
@@ -22,14 +22,17 @@
|
|
|
22
22
|
"exports": {
|
|
23
23
|
"./loader": {
|
|
24
24
|
"jsnext:source": "./src/cli/loader.ts",
|
|
25
|
+
"types": "./dist/types/cli/loader.d.ts",
|
|
25
26
|
"default": "./dist/cjs/cli/loader.js"
|
|
26
27
|
},
|
|
27
28
|
"./server": {
|
|
28
29
|
"jsnext:source": "./src/server/index.ts",
|
|
30
|
+
"types": "./dist/types/server/index.d.ts",
|
|
29
31
|
"default": "./dist/cjs/server/index.js"
|
|
30
32
|
},
|
|
31
33
|
"./runtime": {
|
|
32
34
|
"jsnext:source": "./src/runtime/index.ts",
|
|
35
|
+
"types": "./dist/types/runtime/index.d.ts",
|
|
33
36
|
"default": "./dist/esm/runtime/index.js"
|
|
34
37
|
}
|
|
35
38
|
},
|
|
@@ -52,26 +55,26 @@
|
|
|
52
55
|
"@remix-run/node": "^1.12.0",
|
|
53
56
|
"path-to-regexp": "^6.2.0",
|
|
54
57
|
"react-router-dom": "^6.8.1",
|
|
55
|
-
"@modern-js/utils": "2.
|
|
58
|
+
"@modern-js/utils": "2.10.0"
|
|
56
59
|
},
|
|
57
60
|
"devDependencies": {
|
|
58
61
|
"@types/babel__core": "^7.1.15",
|
|
59
|
-
"@types/jest": "^
|
|
62
|
+
"@types/jest": "^29",
|
|
60
63
|
"@types/node": "^14",
|
|
61
64
|
"@types/supertest": "^2.0.11",
|
|
62
65
|
"isomorphic-fetch": "^3.0.0",
|
|
63
|
-
"jest": "^
|
|
66
|
+
"jest": "^29",
|
|
64
67
|
"memfs": "^3.3.0",
|
|
65
68
|
"supertest": "^6.1.6",
|
|
66
|
-
"ts-jest": "^
|
|
69
|
+
"ts-jest": "^29.0.5",
|
|
67
70
|
"typescript": "^4",
|
|
68
|
-
"webpack": "^5.
|
|
71
|
+
"webpack": "^5.76.2",
|
|
69
72
|
"webpack-chain": "^6.5.1",
|
|
70
|
-
"@modern-js/core": "2.
|
|
71
|
-
"@modern-js/server-core": "2.
|
|
72
|
-
"@modern-js/types": "2.
|
|
73
|
-
"@scripts/jest-config": "2.
|
|
74
|
-
"@scripts/build": "2.
|
|
73
|
+
"@modern-js/core": "2.10.0",
|
|
74
|
+
"@modern-js/server-core": "2.10.0",
|
|
75
|
+
"@modern-js/types": "2.10.0",
|
|
76
|
+
"@scripts/jest-config": "2.10.0",
|
|
77
|
+
"@scripts/build": "2.10.0"
|
|
75
78
|
},
|
|
76
79
|
"sideEffects": false,
|
|
77
80
|
"publishConfig": {
|