@modern-js/plugin-data-loader 0.0.0-next-1692674328976 → 0.0.0-next-1692686860783
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 +2 -35
- package/dist/cjs/cli/loader.js +0 -14
- package/dist/cjs/runtime/index.js +2 -5
- package/dist/esm/cli/loader.js +39 -79
- package/dist/esm/runtime/index.js +4 -7
- package/dist/esm-node/cli/loader.js +0 -14
- package/dist/esm-node/runtime/index.js +3 -6
- package/dist/types/cli/loader.d.ts +2 -6
- package/package.json +14 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,43 +1,10 @@
|
|
|
1
1
|
# @modern-js/plugin-data-loader
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- a030aff285: feat: support loader context
|
|
8
|
-
feat: 支持 loader context
|
|
9
|
-
- 4323e6880d: feat: support client-data file
|
|
10
|
-
feat: 支持 client-data 文件
|
|
11
|
-
|
|
12
|
-
### Patch Changes
|
|
13
|
-
|
|
14
|
-
- 6076166600: fix: packaging errors found by publint
|
|
15
|
-
|
|
16
|
-
fix: 修复 publint 检测到的 packaging 问题
|
|
17
|
-
|
|
18
|
-
- Updated dependencies [6076166600]
|
|
19
|
-
- Updated dependencies [a030aff285]
|
|
20
|
-
- @modern-js/utils@0.0.0-next-1692674328976
|
|
21
|
-
|
|
22
|
-
## 2.31.2
|
|
23
|
-
|
|
24
|
-
### Patch Changes
|
|
25
|
-
|
|
26
|
-
- Updated dependencies [15d30abdc66]
|
|
27
|
-
- @modern-js/utils@2.31.2
|
|
28
|
-
|
|
29
|
-
## 2.31.1
|
|
30
|
-
|
|
31
|
-
### Patch Changes
|
|
32
|
-
|
|
33
|
-
- @modern-js/utils@2.31.1
|
|
34
|
-
|
|
35
|
-
## 2.31.0
|
|
3
|
+
## 0.0.0-next-1692686860783
|
|
36
4
|
|
|
37
5
|
### Patch Changes
|
|
38
6
|
|
|
39
|
-
-
|
|
40
|
-
- @modern-js/utils@2.31.0
|
|
7
|
+
- @modern-js/utils@0.0.0-next-1692686860783
|
|
41
8
|
|
|
42
9
|
## 2.30.0
|
|
43
10
|
|
package/dist/cjs/cli/loader.js
CHANGED
|
@@ -8,8 +8,6 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return loader;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _util = require("util");
|
|
12
|
-
const _logger = require("@modern-js/utils/logger");
|
|
13
11
|
const _generateClient = require("./generateClient");
|
|
14
12
|
async function loader(source) {
|
|
15
13
|
var _this__compiler;
|
|
@@ -35,18 +33,6 @@ async function loader(source) {
|
|
|
35
33
|
if (!options.mapFile) {
|
|
36
34
|
return source;
|
|
37
35
|
}
|
|
38
|
-
if (options.clientData) {
|
|
39
|
-
const readFile = (0, _util.promisify)(this.fs.readFile);
|
|
40
|
-
try {
|
|
41
|
-
const clientDataPath = this.resourcePath.includes(".loader.") ? this.resourcePath.replace(".loader.", ".data.client.") : this.resourcePath.replace(".data.", ".data.client.");
|
|
42
|
-
const clientDataContent = await readFile(clientDataPath);
|
|
43
|
-
return clientDataContent;
|
|
44
|
-
} catch (error) {
|
|
45
|
-
if (process.env.NODE_ENV === "development") {
|
|
46
|
-
_logger.logger.error(`Failed to read the clientData file ${options.clientData}`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
36
|
const code = (0, _generateClient.generateClient)({
|
|
51
37
|
mapFile: options.mapFile,
|
|
52
38
|
loaderId: options.loaderId
|
|
@@ -107,15 +107,12 @@ const handleRequest = async ({ context, serverRoutes, routes: routesConfig }) =>
|
|
|
107
107
|
const { queryRoute } = (0, _remixrouter.createStaticHandler)(routes, {
|
|
108
108
|
basename
|
|
109
109
|
});
|
|
110
|
-
const { res, logger
|
|
110
|
+
const { res, logger } = context;
|
|
111
111
|
const request = createLoaderRequest(context);
|
|
112
|
-
const requestContext = (0, _runtimenode.createRequestContext)();
|
|
113
|
-
requestContext.set(_runtimenode.reporterCtx, reporter);
|
|
114
112
|
let response;
|
|
115
113
|
try {
|
|
116
114
|
response = await queryRoute(request, {
|
|
117
|
-
routeId
|
|
118
|
-
requestContext
|
|
115
|
+
routeId
|
|
119
116
|
});
|
|
120
117
|
if (isResponse(response) && isRedirectResponse(response.status)) {
|
|
121
118
|
response = convertModernRedirectResponse(response.headers, basename);
|
package/dist/esm/cli/loader.js
CHANGED
|
@@ -1,93 +1,53 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
-
import { promisify } from "util";
|
|
5
|
-
import { logger } from "@modern-js/utils/logger";
|
|
6
4
|
import { generateClient } from "./generateClient";
|
|
7
5
|
export default function loader(source) {
|
|
8
6
|
return _loader.apply(this, arguments);
|
|
9
7
|
}
|
|
10
8
|
function _loader() {
|
|
11
9
|
_loader = _async_to_generator(function(source) {
|
|
12
|
-
var _this__compiler, target, resourceQuery, options,
|
|
10
|
+
var _this__compiler, target, resourceQuery, options, code;
|
|
13
11
|
return _ts_generator(this, function(_state) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
source
|
|
22
|
-
];
|
|
23
|
-
}
|
|
24
|
-
if (target === "webworker") {
|
|
25
|
-
return [
|
|
26
|
-
2,
|
|
27
|
-
source
|
|
28
|
-
];
|
|
29
|
-
}
|
|
30
|
-
resourceQuery = this.resourceQuery;
|
|
31
|
-
options = resourceQuery.slice(1).split("&").map(function(item) {
|
|
32
|
-
return item.split("=");
|
|
33
|
-
}).reduce(function(pre, cur) {
|
|
34
|
-
var _cur = _sliced_to_array(cur, 2), key = _cur[0], value = _cur[1];
|
|
35
|
-
if (!key || !value) {
|
|
36
|
-
return pre;
|
|
37
|
-
}
|
|
38
|
-
pre[key] = value;
|
|
39
|
-
return pre;
|
|
40
|
-
}, {});
|
|
41
|
-
if (!options.mapFile) {
|
|
42
|
-
return [
|
|
43
|
-
2,
|
|
44
|
-
source
|
|
45
|
-
];
|
|
46
|
-
}
|
|
47
|
-
if (!options.clientData)
|
|
48
|
-
return [
|
|
49
|
-
3,
|
|
50
|
-
4
|
|
51
|
-
];
|
|
52
|
-
readFile = promisify(this.fs.readFile);
|
|
53
|
-
_state.label = 1;
|
|
54
|
-
case 1:
|
|
55
|
-
_state.trys.push([
|
|
56
|
-
1,
|
|
57
|
-
3,
|
|
58
|
-
,
|
|
59
|
-
4
|
|
60
|
-
]);
|
|
61
|
-
clientDataPath = this.resourcePath.includes(".loader.") ? this.resourcePath.replace(".loader.", ".data.client.") : this.resourcePath.replace(".data.", ".data.client.");
|
|
62
|
-
return [
|
|
63
|
-
4,
|
|
64
|
-
readFile(clientDataPath)
|
|
65
|
-
];
|
|
66
|
-
case 2:
|
|
67
|
-
clientDataContent = _state.sent();
|
|
68
|
-
return [
|
|
69
|
-
2,
|
|
70
|
-
clientDataContent
|
|
71
|
-
];
|
|
72
|
-
case 3:
|
|
73
|
-
error = _state.sent();
|
|
74
|
-
if (process.env.NODE_ENV === "development") {
|
|
75
|
-
logger.error("Failed to read the clientData file ".concat(options.clientData));
|
|
76
|
-
}
|
|
77
|
-
return [
|
|
78
|
-
3,
|
|
79
|
-
4
|
|
80
|
-
];
|
|
81
|
-
case 4:
|
|
82
|
-
code = generateClient({
|
|
83
|
-
mapFile: options.mapFile,
|
|
84
|
-
loaderId: options.loaderId
|
|
85
|
-
});
|
|
86
|
-
return [
|
|
87
|
-
2,
|
|
88
|
-
code
|
|
89
|
-
];
|
|
12
|
+
this.cacheable();
|
|
13
|
+
target = (_this__compiler = this._compiler) === null || _this__compiler === void 0 ? void 0 : _this__compiler.options.target;
|
|
14
|
+
if (target === "node") {
|
|
15
|
+
return [
|
|
16
|
+
2,
|
|
17
|
+
source
|
|
18
|
+
];
|
|
90
19
|
}
|
|
20
|
+
if (target === "webworker") {
|
|
21
|
+
return [
|
|
22
|
+
2,
|
|
23
|
+
source
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
resourceQuery = this.resourceQuery;
|
|
27
|
+
options = resourceQuery.slice(1).split("&").map(function(item) {
|
|
28
|
+
return item.split("=");
|
|
29
|
+
}).reduce(function(pre, cur) {
|
|
30
|
+
var _cur = _sliced_to_array(cur, 2), key = _cur[0], value = _cur[1];
|
|
31
|
+
if (!key || !value) {
|
|
32
|
+
return pre;
|
|
33
|
+
}
|
|
34
|
+
pre[key] = value;
|
|
35
|
+
return pre;
|
|
36
|
+
}, {});
|
|
37
|
+
if (!options.mapFile) {
|
|
38
|
+
return [
|
|
39
|
+
2,
|
|
40
|
+
source
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
code = generateClient({
|
|
44
|
+
mapFile: options.mapFile,
|
|
45
|
+
loaderId: options.loaderId
|
|
46
|
+
});
|
|
47
|
+
return [
|
|
48
|
+
2,
|
|
49
|
+
code
|
|
50
|
+
];
|
|
91
51
|
});
|
|
92
52
|
});
|
|
93
53
|
return _loader.apply(this, arguments);
|
|
@@ -6,7 +6,7 @@ import { installGlobals, writeReadableStreamToWritable, Response as NodeResponse
|
|
|
6
6
|
import { createStaticHandler, ErrorResponse, UNSAFE_DEFERRED_SYMBOL as DEFERRED_SYMBOL } from "@modern-js/utils/runtime/remix-router";
|
|
7
7
|
import { transformNestedRoutes } from "@modern-js/utils/runtime/nested-routes";
|
|
8
8
|
import { isPlainObject } from "@modern-js/utils/lodash";
|
|
9
|
-
import { matchEntry
|
|
9
|
+
import { matchEntry } from "@modern-js/utils/runtime-node";
|
|
10
10
|
import { CONTENT_TYPE_DEFERRED, LOADER_ID_PARAM } from "../common/constants";
|
|
11
11
|
import { createDeferredReadableStream } from "./response";
|
|
12
12
|
installGlobals();
|
|
@@ -155,7 +155,7 @@ var sendLoaderResponse = function() {
|
|
|
155
155
|
}();
|
|
156
156
|
export var handleRequest = function() {
|
|
157
157
|
var _ref = _async_to_generator(function(param) {
|
|
158
|
-
var context, serverRoutes, routesConfig, method, query, routeId, entry, basename, routes, queryRoute, res, logger,
|
|
158
|
+
var context, serverRoutes, routesConfig, method, query, routeId, entry, basename, routes, queryRoute, res, logger, request, response, deferredData, body, init, headers, error, _logger, message;
|
|
159
159
|
return _ts_generator(this, function(_state) {
|
|
160
160
|
switch (_state.label) {
|
|
161
161
|
case 0:
|
|
@@ -176,10 +176,8 @@ export var handleRequest = function() {
|
|
|
176
176
|
queryRoute = createStaticHandler(routes, {
|
|
177
177
|
basename: basename
|
|
178
178
|
}).queryRoute;
|
|
179
|
-
res = context.res, logger = context.logger
|
|
179
|
+
res = context.res, logger = context.logger;
|
|
180
180
|
request = createLoaderRequest(context);
|
|
181
|
-
requestContext = createRequestContext();
|
|
182
|
-
requestContext.set(reporterCtx, reporter);
|
|
183
181
|
_state.label = 1;
|
|
184
182
|
case 1:
|
|
185
183
|
_state.trys.push([
|
|
@@ -191,8 +189,7 @@ export var handleRequest = function() {
|
|
|
191
189
|
return [
|
|
192
190
|
4,
|
|
193
191
|
queryRoute(request, {
|
|
194
|
-
routeId: routeId
|
|
195
|
-
requestContext: requestContext
|
|
192
|
+
routeId: routeId
|
|
196
193
|
})
|
|
197
194
|
];
|
|
198
195
|
case 2:
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { promisify } from "util";
|
|
2
|
-
import { logger } from "@modern-js/utils/logger";
|
|
3
1
|
import { generateClient } from "./generateClient";
|
|
4
2
|
export default async function loader(source) {
|
|
5
3
|
var _this__compiler;
|
|
@@ -25,18 +23,6 @@ export default async function loader(source) {
|
|
|
25
23
|
if (!options.mapFile) {
|
|
26
24
|
return source;
|
|
27
25
|
}
|
|
28
|
-
if (options.clientData) {
|
|
29
|
-
const readFile = promisify(this.fs.readFile);
|
|
30
|
-
try {
|
|
31
|
-
const clientDataPath = this.resourcePath.includes(".loader.") ? this.resourcePath.replace(".loader.", ".data.client.") : this.resourcePath.replace(".data.", ".data.client.");
|
|
32
|
-
const clientDataContent = await readFile(clientDataPath);
|
|
33
|
-
return clientDataContent;
|
|
34
|
-
} catch (error) {
|
|
35
|
-
if (process.env.NODE_ENV === "development") {
|
|
36
|
-
logger.error(`Failed to read the clientData file ${options.clientData}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
26
|
const code = generateClient({
|
|
41
27
|
mapFile: options.mapFile,
|
|
42
28
|
loaderId: options.loaderId
|
|
@@ -2,7 +2,7 @@ import { installGlobals, writeReadableStreamToWritable, Response as NodeResponse
|
|
|
2
2
|
import { createStaticHandler, ErrorResponse, UNSAFE_DEFERRED_SYMBOL as DEFERRED_SYMBOL } from "@modern-js/utils/runtime/remix-router";
|
|
3
3
|
import { transformNestedRoutes } from "@modern-js/utils/runtime/nested-routes";
|
|
4
4
|
import { isPlainObject } from "@modern-js/utils/lodash";
|
|
5
|
-
import { matchEntry
|
|
5
|
+
import { matchEntry } from "@modern-js/utils/runtime-node";
|
|
6
6
|
import { CONTENT_TYPE_DEFERRED, LOADER_ID_PARAM } from "../common/constants";
|
|
7
7
|
import { createDeferredReadableStream } from "./response";
|
|
8
8
|
installGlobals();
|
|
@@ -85,15 +85,12 @@ export const handleRequest = async ({ context, serverRoutes, routes: routesConfi
|
|
|
85
85
|
const { queryRoute } = createStaticHandler(routes, {
|
|
86
86
|
basename
|
|
87
87
|
});
|
|
88
|
-
const { res, logger
|
|
88
|
+
const { res, logger } = context;
|
|
89
89
|
const request = createLoaderRequest(context);
|
|
90
|
-
const requestContext = createRequestContext();
|
|
91
|
-
requestContext.set(reporterCtx, reporter);
|
|
92
90
|
let response;
|
|
93
91
|
try {
|
|
94
92
|
response = await queryRoute(request, {
|
|
95
|
-
routeId
|
|
96
|
-
requestContext
|
|
93
|
+
routeId
|
|
97
94
|
});
|
|
98
95
|
if (isResponse(response) && isRedirectResponse(response.status)) {
|
|
99
96
|
response = convertModernRedirectResponse(response.headers, basename);
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import type { LoaderContext } from 'webpack';
|
|
3
|
-
|
|
2
|
+
export default function loader(this: LoaderContext<{
|
|
4
3
|
mapFile: string;
|
|
5
4
|
loaderId?: string;
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
export default function loader(this: LoaderContext<Context>, source: string): Promise<string | Buffer | undefined>;
|
|
9
|
-
export {};
|
|
5
|
+
}>, source: string): Promise<string>;
|
package/package.json
CHANGED
|
@@ -15,28 +15,28 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "0.0.0-next-
|
|
18
|
+
"version": "0.0.0-next-1692686860783",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
22
|
-
"jsnext:source": "./src/
|
|
23
|
-
"types": "./dist/types/
|
|
24
|
-
"main": "./dist/cjs/
|
|
25
|
-
"module": "./dist/esm/
|
|
22
|
+
"jsnext:source": "./src/index.ts",
|
|
23
|
+
"types": "./dist/types/index.d.ts",
|
|
24
|
+
"main": "./dist/cjs/index.js",
|
|
25
|
+
"module": "./dist/esm/index.js",
|
|
26
26
|
"exports": {
|
|
27
27
|
"./loader": {
|
|
28
|
-
"types": "./dist/types/cli/loader.d.ts",
|
|
29
28
|
"jsnext:source": "./src/cli/loader.ts",
|
|
29
|
+
"types": "./dist/types/cli/loader.d.ts",
|
|
30
30
|
"default": "./dist/cjs/cli/loader.js"
|
|
31
31
|
},
|
|
32
32
|
"./server": {
|
|
33
|
-
"types": "./dist/types/server/index.d.ts",
|
|
34
33
|
"jsnext:source": "./src/server/index.ts",
|
|
34
|
+
"types": "./dist/types/server/index.d.ts",
|
|
35
35
|
"default": "./dist/cjs/server/index.js"
|
|
36
36
|
},
|
|
37
37
|
"./runtime": {
|
|
38
|
-
"types": "./dist/types/runtime/index.d.ts",
|
|
39
38
|
"jsnext:source": "./src/runtime/index.ts",
|
|
39
|
+
"types": "./dist/types/runtime/index.d.ts",
|
|
40
40
|
"default": "./dist/esm/runtime/index.js"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
@@ -58,7 +58,7 @@
|
|
|
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/utils": "0.0.0-next-
|
|
61
|
+
"@modern-js/utils": "0.0.0-next-1692686860783"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@types/babel__core": "^7.20.0",
|
|
@@ -75,11 +75,11 @@
|
|
|
75
75
|
"webpack-chain": "^6.5.1",
|
|
76
76
|
"react": "^18",
|
|
77
77
|
"react-dom": "^18",
|
|
78
|
-
"@modern-js/types": "0.0.0-next-
|
|
79
|
-
"@modern-js/core": "0.0.0-next-
|
|
80
|
-
"@modern-js/server-core": "0.0.0-next-
|
|
81
|
-
"@scripts/build": "0.0.0-next-
|
|
82
|
-
"@scripts/jest-config": "0.0.0-next-
|
|
78
|
+
"@modern-js/types": "0.0.0-next-1692686860783",
|
|
79
|
+
"@modern-js/core": "0.0.0-next-1692686860783",
|
|
80
|
+
"@modern-js/server-core": "0.0.0-next-1692686860783",
|
|
81
|
+
"@scripts/build": "0.0.0-next-1692686860783",
|
|
82
|
+
"@scripts/jest-config": "0.0.0-next-1692686860783"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"react": ">=17.0.0"
|