@modern-js/plugin-data-loader 0.0.0-next-1692706973808 → 0.0.0-next-1692727667183
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 +40 -2
- package/dist/cjs/cli/loader.js +14 -0
- package/dist/cjs/runtime/index.js +5 -2
- package/dist/esm/cli/loader.js +79 -39
- package/dist/esm/runtime/index.js +7 -4
- package/dist/esm-node/cli/loader.js +14 -0
- package/dist/esm-node/runtime/index.js +6 -3
- package/dist/types/cli/loader.d.ts +6 -2
- package/package.json +14 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,48 @@
|
|
|
1
1
|
# @modern-js/plugin-data-loader
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-1692727667183
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a030aff28: feat: support loader context
|
|
8
|
+
feat: 支持 loader context
|
|
9
|
+
- 4323e6880: feat: support client-data file
|
|
10
|
+
feat: 支持 client-data 文件
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 607616660: fix: packaging errors found by publint
|
|
15
|
+
|
|
16
|
+
fix: 修复 publint 检测到的 packaging 问题
|
|
17
|
+
|
|
18
|
+
- 3c911009a: chore(builder): using unified version of webpack-chain
|
|
19
|
+
|
|
20
|
+
chore(builder): 使用统一的 webpack-chain 版本
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [607616660]
|
|
23
|
+
- Updated dependencies [a030aff28]
|
|
24
|
+
- Updated dependencies [3c911009a]
|
|
25
|
+
- @modern-js/utils@0.0.0-next-1692727667183
|
|
26
|
+
|
|
27
|
+
## 2.31.2
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- Updated dependencies [15d30abdc66]
|
|
32
|
+
- @modern-js/utils@2.31.2
|
|
33
|
+
|
|
34
|
+
## 2.31.1
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- @modern-js/utils@2.31.1
|
|
39
|
+
|
|
40
|
+
## 2.31.0
|
|
4
41
|
|
|
5
42
|
### Patch Changes
|
|
6
43
|
|
|
7
|
-
-
|
|
44
|
+
- Updated dependencies [1882366]
|
|
45
|
+
- @modern-js/utils@2.31.0
|
|
8
46
|
|
|
9
47
|
## 2.30.0
|
|
10
48
|
|
package/dist/cjs/cli/loader.js
CHANGED
|
@@ -8,6 +8,8 @@ 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");
|
|
11
13
|
const _generateClient = require("./generateClient");
|
|
12
14
|
async function loader(source) {
|
|
13
15
|
var _this__compiler;
|
|
@@ -33,6 +35,18 @@ async function loader(source) {
|
|
|
33
35
|
if (!options.mapFile) {
|
|
34
36
|
return source;
|
|
35
37
|
}
|
|
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
|
+
}
|
|
36
50
|
const code = (0, _generateClient.generateClient)({
|
|
37
51
|
mapFile: options.mapFile,
|
|
38
52
|
loaderId: options.loaderId
|
|
@@ -107,12 +107,15 @@ const handleRequest = async ({ context, serverRoutes, routes: routesConfig }) =>
|
|
|
107
107
|
const { queryRoute } = (0, _remixrouter.createStaticHandler)(routes, {
|
|
108
108
|
basename
|
|
109
109
|
});
|
|
110
|
-
const { res, logger } = context;
|
|
110
|
+
const { res, logger, reporter } = context;
|
|
111
111
|
const request = createLoaderRequest(context);
|
|
112
|
+
const requestContext = (0, _runtimenode.createRequestContext)();
|
|
113
|
+
requestContext.set(_runtimenode.reporterCtx, reporter);
|
|
112
114
|
let response;
|
|
113
115
|
try {
|
|
114
116
|
response = await queryRoute(request, {
|
|
115
|
-
routeId
|
|
117
|
+
routeId,
|
|
118
|
+
requestContext
|
|
116
119
|
});
|
|
117
120
|
if (isResponse(response) && isRedirectResponse(response.status)) {
|
|
118
121
|
response = convertModernRedirectResponse(response.headers, basename);
|
package/dist/esm/cli/loader.js
CHANGED
|
@@ -1,53 +1,93 @@
|
|
|
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";
|
|
4
6
|
import { generateClient } from "./generateClient";
|
|
5
7
|
export default function loader(source) {
|
|
6
8
|
return _loader.apply(this, arguments);
|
|
7
9
|
}
|
|
8
10
|
function _loader() {
|
|
9
11
|
_loader = _async_to_generator(function(source) {
|
|
10
|
-
var _this__compiler, target, resourceQuery, options, code;
|
|
12
|
+
var _this__compiler, target, resourceQuery, options, readFile, clientDataPath, clientDataContent, error, code;
|
|
11
13
|
return _ts_generator(this, function(_state) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
switch (_state.label) {
|
|
15
|
+
case 0:
|
|
16
|
+
this.cacheable();
|
|
17
|
+
target = (_this__compiler = this._compiler) === null || _this__compiler === void 0 ? void 0 : _this__compiler.options.target;
|
|
18
|
+
if (target === "node") {
|
|
19
|
+
return [
|
|
20
|
+
2,
|
|
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
|
+
];
|
|
19
90
|
}
|
|
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
|
-
];
|
|
51
91
|
});
|
|
52
92
|
});
|
|
53
93
|
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 } from "@modern-js/utils/runtime-node";
|
|
9
|
+
import { matchEntry, createRequestContext, reporterCtx } 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, request, response, deferredData, body, init, headers, error, _logger, message;
|
|
158
|
+
var context, serverRoutes, routesConfig, method, query, routeId, entry, basename, routes, queryRoute, res, logger, reporter, request, requestContext, 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,8 +176,10 @@ 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, reporter = context.reporter;
|
|
180
180
|
request = createLoaderRequest(context);
|
|
181
|
+
requestContext = createRequestContext();
|
|
182
|
+
requestContext.set(reporterCtx, reporter);
|
|
181
183
|
_state.label = 1;
|
|
182
184
|
case 1:
|
|
183
185
|
_state.trys.push([
|
|
@@ -189,7 +191,8 @@ export var handleRequest = function() {
|
|
|
189
191
|
return [
|
|
190
192
|
4,
|
|
191
193
|
queryRoute(request, {
|
|
192
|
-
routeId: routeId
|
|
194
|
+
routeId: routeId,
|
|
195
|
+
requestContext: requestContext
|
|
193
196
|
})
|
|
194
197
|
];
|
|
195
198
|
case 2:
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { promisify } from "util";
|
|
2
|
+
import { logger } from "@modern-js/utils/logger";
|
|
1
3
|
import { generateClient } from "./generateClient";
|
|
2
4
|
export default async function loader(source) {
|
|
3
5
|
var _this__compiler;
|
|
@@ -23,6 +25,18 @@ export default async function loader(source) {
|
|
|
23
25
|
if (!options.mapFile) {
|
|
24
26
|
return source;
|
|
25
27
|
}
|
|
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
|
+
}
|
|
26
40
|
const code = generateClient({
|
|
27
41
|
mapFile: options.mapFile,
|
|
28
42
|
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 } from "@modern-js/utils/runtime-node";
|
|
5
|
+
import { matchEntry, createRequestContext, reporterCtx } 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,12 +85,15 @@ export const handleRequest = async ({ context, serverRoutes, routes: routesConfi
|
|
|
85
85
|
const { queryRoute } = createStaticHandler(routes, {
|
|
86
86
|
basename
|
|
87
87
|
});
|
|
88
|
-
const { res, logger } = context;
|
|
88
|
+
const { res, logger, reporter } = context;
|
|
89
89
|
const request = createLoaderRequest(context);
|
|
90
|
+
const requestContext = createRequestContext();
|
|
91
|
+
requestContext.set(reporterCtx, reporter);
|
|
90
92
|
let response;
|
|
91
93
|
try {
|
|
92
94
|
response = await queryRoute(request, {
|
|
93
|
-
routeId
|
|
95
|
+
routeId,
|
|
96
|
+
requestContext
|
|
94
97
|
});
|
|
95
98
|
if (isResponse(response) && isRedirectResponse(response.status)) {
|
|
96
99
|
response = convertModernRedirectResponse(response.headers, basename);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { LoaderContext } from 'webpack';
|
|
2
|
-
|
|
3
|
+
type Context = {
|
|
3
4
|
mapFile: string;
|
|
4
5
|
loaderId?: string;
|
|
5
|
-
|
|
6
|
+
clientData?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export default function loader(this: LoaderContext<Context>, source: string): Promise<string | Buffer | undefined>;
|
|
9
|
+
export {};
|
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-1692727667183",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
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",
|
|
22
|
+
"jsnext:source": "./src/runtime/index.ts",
|
|
23
|
+
"types": "./dist/types/runtime/index.d.ts",
|
|
24
|
+
"main": "./dist/cjs/runtime/index.js",
|
|
25
|
+
"module": "./dist/esm/runtime/index.js",
|
|
26
26
|
"exports": {
|
|
27
27
|
"./loader": {
|
|
28
|
-
"jsnext:source": "./src/cli/loader.ts",
|
|
29
28
|
"types": "./dist/types/cli/loader.d.ts",
|
|
29
|
+
"jsnext:source": "./src/cli/loader.ts",
|
|
30
30
|
"default": "./dist/cjs/cli/loader.js"
|
|
31
31
|
},
|
|
32
32
|
"./server": {
|
|
33
|
-
"jsnext:source": "./src/server/index.ts",
|
|
34
33
|
"types": "./dist/types/server/index.d.ts",
|
|
34
|
+
"jsnext:source": "./src/server/index.ts",
|
|
35
35
|
"default": "./dist/cjs/server/index.js"
|
|
36
36
|
},
|
|
37
37
|
"./runtime": {
|
|
38
|
-
"jsnext:source": "./src/runtime/index.ts",
|
|
39
38
|
"types": "./dist/types/runtime/index.d.ts",
|
|
39
|
+
"jsnext:source": "./src/runtime/index.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-1692727667183"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@types/babel__core": "^7.20.0",
|
|
@@ -72,14 +72,13 @@
|
|
|
72
72
|
"ts-jest": "^29.1.0",
|
|
73
73
|
"typescript": "^5",
|
|
74
74
|
"webpack": "^5.88.1",
|
|
75
|
-
"webpack-chain": "^6.5.1",
|
|
76
75
|
"react": "^18",
|
|
77
76
|
"react-dom": "^18",
|
|
78
|
-
"@modern-js/core": "0.0.0-next-
|
|
79
|
-
"@modern-js/server-core": "0.0.0-next-
|
|
80
|
-
"@modern-js/types": "0.0.0-next-
|
|
81
|
-
"@scripts/build": "0.0.0-next-
|
|
82
|
-
"@scripts/jest-config": "0.0.0-next-
|
|
77
|
+
"@modern-js/core": "0.0.0-next-1692727667183",
|
|
78
|
+
"@modern-js/server-core": "0.0.0-next-1692727667183",
|
|
79
|
+
"@modern-js/types": "0.0.0-next-1692727667183",
|
|
80
|
+
"@scripts/build": "0.0.0-next-1692727667183",
|
|
81
|
+
"@scripts/jest-config": "0.0.0-next-1692727667183"
|
|
83
82
|
},
|
|
84
83
|
"peerDependencies": {
|
|
85
84
|
"react": ">=17.0.0"
|