@modern-js/prod-server 2.10.0 → 2.12.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 +33 -0
- package/dist/cjs/libs/render/index.js +1 -1
- package/dist/cjs/libs/render/ssr.js +5 -4
- package/dist/cjs/libs/render/utils.js +5 -5
- package/dist/esm/libs/render/index.js +2 -2
- package/dist/esm/libs/render/ssr.js +5 -4
- package/dist/esm/libs/render/utils.js +2 -2
- package/dist/esm-node/libs/render/index.js +2 -2
- package/dist/esm-node/libs/render/ssr.js +6 -7
- package/dist/esm-node/libs/render/utils.js +3 -3
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/libs/render/utils.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @modern-js/prod-server
|
|
2
2
|
|
|
3
|
+
## 2.12.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7980842: fix: function injectServerData name typo
|
|
8
|
+
|
|
9
|
+
fix: 修复 injectServerData 函数命名错误
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [c2ca6c8]
|
|
12
|
+
- Updated dependencies [6d86e34]
|
|
13
|
+
- @modern-js/utils@2.12.0
|
|
14
|
+
- @modern-js/server-core@2.12.0
|
|
15
|
+
|
|
16
|
+
## 2.11.0
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 381a3b9: feat(utils): move universal utils to the universal folder
|
|
21
|
+
|
|
22
|
+
feat(utils): 将运行时使用的 utils 移动到 universal 目录
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [cfb058f]
|
|
25
|
+
- Updated dependencies [0bd018b]
|
|
26
|
+
- Updated dependencies [5d624fd]
|
|
27
|
+
- Updated dependencies [e2466a1]
|
|
28
|
+
- Updated dependencies [02bb383]
|
|
29
|
+
- Updated dependencies [381a3b9]
|
|
30
|
+
- Updated dependencies [7a60f10]
|
|
31
|
+
- Updated dependencies [274b2e5]
|
|
32
|
+
- Updated dependencies [b9e1c54]
|
|
33
|
+
- @modern-js/utils@2.11.0
|
|
34
|
+
- @modern-js/server-core@2.11.0
|
|
35
|
+
|
|
3
36
|
## 2.10.0
|
|
4
37
|
|
|
5
38
|
### Minor Changes
|
|
@@ -88,7 +88,7 @@ const createRenderHandler = ({
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
return {
|
|
91
|
-
content: route.entryName ? (0, import_utils2.
|
|
91
|
+
content: route.entryName ? (0, import_utils2.injectServerData)(content.toString(), ctx) : content,
|
|
92
92
|
contentType: import_utils.mime.contentType(import_path.default.extname(templatePath))
|
|
93
93
|
};
|
|
94
94
|
};
|
|
@@ -32,6 +32,7 @@ __export(ssr_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(ssr_exports);
|
|
33
33
|
var import_path = __toESM(require("path"));
|
|
34
34
|
var import_utils = require("@modern-js/utils");
|
|
35
|
+
var import_constants = require("@modern-js/utils/constants");
|
|
35
36
|
var import_cache = __toESM(require("./cache"));
|
|
36
37
|
var import_measure = require("./measure");
|
|
37
38
|
var import_utils2 = require("./utils");
|
|
@@ -47,9 +48,9 @@ const render = async (ctx, renderOptions, runner) => {
|
|
|
47
48
|
enableUnsafeCtx = false
|
|
48
49
|
} = renderOptions;
|
|
49
50
|
const bundleJS = import_path.default.join(distDir, bundle);
|
|
50
|
-
const loadableUri = import_path.default.join(distDir,
|
|
51
|
+
const loadableUri = import_path.default.join(distDir, import_constants.LOADABLE_STATS_FILE);
|
|
51
52
|
const loadableStats = import_utils.fs.existsSync(loadableUri) ? require(loadableUri) : "";
|
|
52
|
-
const routesManifestUri = import_path.default.join(distDir,
|
|
53
|
+
const routesManifestUri = import_path.default.join(distDir, import_constants.ROUTE_MANIFEST_FILE);
|
|
53
54
|
const routeManifest = import_utils.fs.existsSync(routesManifestUri) ? require(routesManifestUri) : void 0;
|
|
54
55
|
const context = {
|
|
55
56
|
request: {
|
|
@@ -86,7 +87,7 @@ const render = async (ctx, renderOptions, runner) => {
|
|
|
86
87
|
context.logger = (0, import_measure.createLogger)(context, ctx.logger);
|
|
87
88
|
context.metrics = (0, import_measure.createMetrics)(context, ctx.metrics);
|
|
88
89
|
runner.extendSSRContext(context);
|
|
89
|
-
const serverRender = require(bundleJS)[
|
|
90
|
+
const serverRender = require(bundleJS)[import_constants.SERVER_RENDER_FUNCTION_NAME];
|
|
90
91
|
const content = await (0, import_cache.default)(serverRender, ctx)(context);
|
|
91
92
|
const { url, status = 302 } = context.redirection;
|
|
92
93
|
if (url) {
|
|
@@ -99,7 +100,7 @@ const render = async (ctx, renderOptions, runner) => {
|
|
|
99
100
|
}
|
|
100
101
|
if (typeof content === "string") {
|
|
101
102
|
return {
|
|
102
|
-
content: (0, import_utils2.
|
|
103
|
+
content: (0, import_utils2.injectServerData)(content, ctx),
|
|
103
104
|
contentType: import_utils.mime.contentType("html")
|
|
104
105
|
};
|
|
105
106
|
} else {
|
|
@@ -17,12 +17,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
var utils_exports = {};
|
|
19
19
|
__export(utils_exports, {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
injectServerData: () => injectServerData,
|
|
21
|
+
injectServerDataStream: () => injectServerDataStream
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(utils_exports);
|
|
24
24
|
var import_template = require("../hook-api/template");
|
|
25
|
-
const
|
|
25
|
+
const injectServerData = (content, context) => {
|
|
26
26
|
const template = new import_template.TemplateAPI(content);
|
|
27
27
|
template.prependHead(
|
|
28
28
|
`<script>window._SERVER_DATA=${JSON.stringify(
|
|
@@ -42,6 +42,6 @@ const injectServerDataStream = (content, context) => {
|
|
|
42
42
|
};
|
|
43
43
|
// Annotate the CommonJS export names for ESM import in node:
|
|
44
44
|
0 && (module.exports = {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
injectServerData,
|
|
46
|
+
injectServerDataStream
|
|
47
47
|
});
|
|
@@ -128,7 +128,7 @@ import { ERROR_DIGEST } from "../../constants";
|
|
|
128
128
|
import { handleDirectory } from "./static";
|
|
129
129
|
import { readFile } from "./reader";
|
|
130
130
|
import * as ssr from "./ssr";
|
|
131
|
-
import {
|
|
131
|
+
import { injectServerData } from "./utils";
|
|
132
132
|
var createRenderHandler = function(param) {
|
|
133
133
|
var distDir = param.distDir, staticGenerate = param.staticGenerate, forceCSR = param.forceCSR;
|
|
134
134
|
return function() {
|
|
@@ -219,7 +219,7 @@ var createRenderHandler = function(param) {
|
|
|
219
219
|
return [
|
|
220
220
|
2,
|
|
221
221
|
{
|
|
222
|
-
content: route.entryName ?
|
|
222
|
+
content: route.entryName ? injectServerData(content.toString(), ctx) : content,
|
|
223
223
|
contentType: mime.contentType(path.extname(templatePath))
|
|
224
224
|
}
|
|
225
225
|
];
|
|
@@ -123,10 +123,11 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
123
123
|
}
|
|
124
124
|
};
|
|
125
125
|
import path from "path";
|
|
126
|
-
import { fs,
|
|
126
|
+
import { fs, mime } from "@modern-js/utils";
|
|
127
|
+
import { LOADABLE_STATS_FILE, ROUTE_MANIFEST_FILE, SERVER_RENDER_FUNCTION_NAME } from "@modern-js/utils/constants";
|
|
127
128
|
import cache from "./cache";
|
|
128
129
|
import { createLogger, createMetrics } from "./measure";
|
|
129
|
-
import { injectServerDataStream,
|
|
130
|
+
import { injectServerDataStream, injectServerData } from "./utils";
|
|
130
131
|
var render = function() {
|
|
131
132
|
var _ref = _asyncToGenerator(function(ctx, renderOptions, runner) {
|
|
132
133
|
var _ctx_res, urlPath, bundle, distDir, template, entryName, staticGenerate, _renderOptions_enableUnsafeCtx, enableUnsafeCtx, bundleJS, loadableUri, loadableStats, routesManifestUri, routeManifest, context, serverRender, content, _context_redirection, url, _context_redirection_status, status;
|
|
@@ -137,7 +138,7 @@ var render = function() {
|
|
|
137
138
|
bundleJS = path.join(distDir, bundle);
|
|
138
139
|
loadableUri = path.join(distDir, LOADABLE_STATS_FILE);
|
|
139
140
|
loadableStats = fs.existsSync(loadableUri) ? require(loadableUri) : "";
|
|
140
|
-
routesManifestUri = path.join(distDir,
|
|
141
|
+
routesManifestUri = path.join(distDir, ROUTE_MANIFEST_FILE);
|
|
141
142
|
routeManifest = fs.existsSync(routesManifestUri) ? require(routesManifestUri) : void 0;
|
|
142
143
|
context = {
|
|
143
144
|
request: {
|
|
@@ -197,7 +198,7 @@ var render = function() {
|
|
|
197
198
|
return [
|
|
198
199
|
2,
|
|
199
200
|
{
|
|
200
|
-
content:
|
|
201
|
+
content: injectServerData(content, ctx),
|
|
201
202
|
contentType: mime.contentType("html")
|
|
202
203
|
}
|
|
203
204
|
];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TemplateAPI, templateInjectableStream } from "../hook-api/template";
|
|
2
|
-
var
|
|
2
|
+
var injectServerData = function(content, context) {
|
|
3
3
|
var template = new TemplateAPI(content);
|
|
4
4
|
template.prependHead("<script>window._SERVER_DATA=".concat(JSON.stringify(context.serverData), "</script>"));
|
|
5
5
|
return template.get();
|
|
@@ -9,4 +9,4 @@ var injectServerDataStream = function(content, context) {
|
|
|
9
9
|
prependHead: "<script>window._SERVER_DATA=".concat(JSON.stringify(context.serverData), "</script>")
|
|
10
10
|
}));
|
|
11
11
|
};
|
|
12
|
-
export {
|
|
12
|
+
export { injectServerData, injectServerDataStream };
|
|
@@ -4,7 +4,7 @@ import { ERROR_DIGEST } from "../../constants";
|
|
|
4
4
|
import { handleDirectory } from "./static";
|
|
5
5
|
import { readFile } from "./reader";
|
|
6
6
|
import * as ssr from "./ssr";
|
|
7
|
-
import {
|
|
7
|
+
import { injectServerData } from "./utils";
|
|
8
8
|
const createRenderHandler = ({
|
|
9
9
|
distDir,
|
|
10
10
|
staticGenerate,
|
|
@@ -56,7 +56,7 @@ const createRenderHandler = ({
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
return {
|
|
59
|
-
content: route.entryName ?
|
|
59
|
+
content: route.entryName ? injectServerData(content.toString(), ctx) : content,
|
|
60
60
|
contentType: mime.contentType(path.extname(templatePath))
|
|
61
61
|
};
|
|
62
62
|
};
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
+
import { fs, mime } from "@modern-js/utils";
|
|
2
3
|
import {
|
|
3
|
-
fs,
|
|
4
4
|
LOADABLE_STATS_FILE,
|
|
5
|
-
|
|
6
|
-
ROUTE_MINIFEST_FILE,
|
|
5
|
+
ROUTE_MANIFEST_FILE,
|
|
7
6
|
SERVER_RENDER_FUNCTION_NAME
|
|
8
|
-
} from "@modern-js/utils";
|
|
7
|
+
} from "@modern-js/utils/constants";
|
|
9
8
|
import cache from "./cache";
|
|
10
9
|
import { createLogger, createMetrics } from "./measure";
|
|
11
|
-
import { injectServerDataStream,
|
|
10
|
+
import { injectServerDataStream, injectServerData } from "./utils";
|
|
12
11
|
const render = async (ctx, renderOptions, runner) => {
|
|
13
12
|
var _a;
|
|
14
13
|
const {
|
|
@@ -23,7 +22,7 @@ const render = async (ctx, renderOptions, runner) => {
|
|
|
23
22
|
const bundleJS = path.join(distDir, bundle);
|
|
24
23
|
const loadableUri = path.join(distDir, LOADABLE_STATS_FILE);
|
|
25
24
|
const loadableStats = fs.existsSync(loadableUri) ? require(loadableUri) : "";
|
|
26
|
-
const routesManifestUri = path.join(distDir,
|
|
25
|
+
const routesManifestUri = path.join(distDir, ROUTE_MANIFEST_FILE);
|
|
27
26
|
const routeManifest = fs.existsSync(routesManifestUri) ? require(routesManifestUri) : void 0;
|
|
28
27
|
const context = {
|
|
29
28
|
request: {
|
|
@@ -73,7 +72,7 @@ const render = async (ctx, renderOptions, runner) => {
|
|
|
73
72
|
}
|
|
74
73
|
if (typeof content === "string") {
|
|
75
74
|
return {
|
|
76
|
-
content:
|
|
75
|
+
content: injectServerData(content, ctx),
|
|
77
76
|
contentType: mime.contentType("html")
|
|
78
77
|
};
|
|
79
78
|
} else {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TemplateAPI, templateInjectableStream } from "../hook-api/template";
|
|
2
|
-
const
|
|
2
|
+
const injectServerData = (content, context) => {
|
|
3
3
|
const template = new TemplateAPI(content);
|
|
4
4
|
template.prependHead(
|
|
5
5
|
`<script>window._SERVER_DATA=${JSON.stringify(
|
|
@@ -18,6 +18,6 @@ const injectServerDataStream = (content, context) => {
|
|
|
18
18
|
);
|
|
19
19
|
};
|
|
20
20
|
export {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
injectServerData,
|
|
22
|
+
injectServerDataStream
|
|
23
23
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
/// <reference types="node/http" />
|
|
5
|
-
/// <reference types=".dts-temp/
|
|
5
|
+
/// <reference types=".dts-temp/DxlrmidoZSzE3A7elWdZ1/src/type" />
|
|
6
6
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
7
7
|
import qs from 'querystring';
|
|
8
8
|
import type { ModernServerContext as ModernServerContextInterface } from '@modern-js/types';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Readable } from 'stream';
|
|
3
3
|
import type { ModernServerContext } from '@modern-js/types';
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const injectServerData: (content: string, context: ModernServerContext) => string;
|
|
5
5
|
export declare const injectServerDataStream: (content: Readable, context: ModernServerContext) => import("stream").Transform;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node/http" />
|
|
3
|
-
/// <reference types=".dts-temp/
|
|
3
|
+
/// <reference types=".dts-temp/DxlrmidoZSzE3A7elWdZ1/src/type" />
|
|
4
4
|
import { IncomingMessage } from 'http';
|
|
5
5
|
import type { OutputNormalizedConfig, HtmlNormalizedConfig } from '@modern-js/server-core';
|
|
6
6
|
export declare const debug: any;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.12.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/cjs/index.js",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"merge-deep": "^3.0.3",
|
|
57
57
|
"path-to-regexp": "^6.2.0",
|
|
58
58
|
"serve-static": "^1.14.1",
|
|
59
|
-
"@modern-js/utils": "2.
|
|
60
|
-
"@modern-js/server-core": "2.
|
|
59
|
+
"@modern-js/utils": "2.12.0",
|
|
60
|
+
"@modern-js/server-core": "2.12.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/cookie": "^0.4.1",
|
|
@@ -73,10 +73,10 @@
|
|
|
73
73
|
"node-mocks-http": "^1.11.0",
|
|
74
74
|
"portfinder": "^1.0.28",
|
|
75
75
|
"typescript": "^4",
|
|
76
|
-
"@modern-js/types": "2.
|
|
77
|
-
"@modern-js/server-core": "2.
|
|
78
|
-
"@scripts/
|
|
79
|
-
"@scripts/
|
|
76
|
+
"@modern-js/types": "2.12.0",
|
|
77
|
+
"@modern-js/server-core": "2.12.0",
|
|
78
|
+
"@scripts/jest-config": "2.12.0",
|
|
79
|
+
"@scripts/build": "2.12.0"
|
|
80
80
|
},
|
|
81
81
|
"sideEffects": false,
|
|
82
82
|
"publishConfig": {
|