@modern-js/prod-server 2.45.0 → 2.46.1
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/libs/hook-api/template.js +7 -4
- package/dist/cjs/libs/hook-api/templateForStream.js +2 -2
- package/dist/cjs/libs/render/ssr.js +3 -0
- package/dist/cjs/server/modernServer.js +1 -1
- package/dist/esm/libs/hook-api/template.js +14 -4
- package/dist/esm/libs/hook-api/templateForStream.js +6 -2
- package/dist/esm/libs/render/ssr.js +4 -1
- package/dist/esm/server/modernServer.js +2 -2
- package/dist/esm-node/libs/hook-api/template.js +7 -4
- package/dist/esm-node/libs/hook-api/templateForStream.js +2 -2
- package/dist/esm-node/libs/render/ssr.js +3 -0
- package/dist/esm-node/server/modernServer.js +2 -2
- package/dist/types/libs/hook-api/template.d.ts +1 -0
- package/package.json +9 -8
|
@@ -25,8 +25,8 @@ module.exports = __toCommonJS(template_exports);
|
|
|
25
25
|
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
26
26
|
const RegList = {
|
|
27
27
|
before: {
|
|
28
|
-
head: "<head
|
|
29
|
-
body: "<body
|
|
28
|
+
head: "<head[^>]*>",
|
|
29
|
+
body: "<body[^>]*>"
|
|
30
30
|
},
|
|
31
31
|
after: {
|
|
32
32
|
head: "</head>",
|
|
@@ -42,7 +42,7 @@ class TemplateAPI {
|
|
|
42
42
|
}
|
|
43
43
|
prependHead(fragment) {
|
|
44
44
|
const { head } = RegList.before;
|
|
45
|
-
return this.
|
|
45
|
+
return this.replaceByFunction(new RegExp(head), (beforeHead) => `${beforeHead}${fragment}`);
|
|
46
46
|
}
|
|
47
47
|
appendHead(fragment) {
|
|
48
48
|
const { head } = RegList.after;
|
|
@@ -50,12 +50,15 @@ class TemplateAPI {
|
|
|
50
50
|
}
|
|
51
51
|
prependBody(fragment) {
|
|
52
52
|
const { body } = RegList.before;
|
|
53
|
-
return this.
|
|
53
|
+
return this.replaceByFunction(new RegExp(body), (beforeBody) => `${beforeBody}${fragment}`);
|
|
54
54
|
}
|
|
55
55
|
appendBody(fragment) {
|
|
56
56
|
const { body } = RegList.after;
|
|
57
57
|
return this.replace(body, `${fragment}${body}`);
|
|
58
58
|
}
|
|
59
|
+
replaceByFunction(reg, replacer) {
|
|
60
|
+
this.content = this.content.replace(reg, replacer);
|
|
61
|
+
}
|
|
59
62
|
replace(reg, text) {
|
|
60
63
|
this.content = this.content.replace(reg, text);
|
|
61
64
|
}
|
|
@@ -28,7 +28,7 @@ const templateInjectableStream = ({ prependHead, appendHead, prependBody, append
|
|
|
28
28
|
let chunk_str = chunk.toString();
|
|
29
29
|
if (prependHead) {
|
|
30
30
|
const { head } = import_template.RegList.before;
|
|
31
|
-
chunk_str = chunk_str.replace(head, `${
|
|
31
|
+
chunk_str = chunk_str.replace(new RegExp(head), (beforeHead) => `${beforeHead}${prependHead}`);
|
|
32
32
|
}
|
|
33
33
|
if (appendHead) {
|
|
34
34
|
const { head } = import_template.RegList.after;
|
|
@@ -36,7 +36,7 @@ const templateInjectableStream = ({ prependHead, appendHead, prependBody, append
|
|
|
36
36
|
}
|
|
37
37
|
if (prependBody) {
|
|
38
38
|
const { body } = import_template.RegList.before;
|
|
39
|
-
chunk_str = chunk_str.replace(body, `${
|
|
39
|
+
chunk_str = chunk_str.replace(new RegExp(body), (beforeBody) => `${beforeBody}${prependBody}`);
|
|
40
40
|
}
|
|
41
41
|
if (appendBody) {
|
|
42
42
|
const { body } = import_template.RegList.after;
|
|
@@ -33,6 +33,7 @@ __export(ssr_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(ssr_exports);
|
|
34
34
|
var import_path = __toESM(require("path"));
|
|
35
35
|
var import_utils = require("@modern-js/utils");
|
|
36
|
+
var isbot = __toESM(require("isbot"));
|
|
36
37
|
var import_hook_api = require("../hook-api");
|
|
37
38
|
var import_afterRenderForStream = require("../hook-api/afterRenderForStream");
|
|
38
39
|
var import_measure = require("./measure");
|
|
@@ -47,6 +48,7 @@ const render = async (ctx, renderOptions, runner) => {
|
|
|
47
48
|
const loadableStats = import_utils.fs.existsSync(loadableUri) ? require(loadableUri) : "";
|
|
48
49
|
const routesManifestUri = import_path.default.join(distDir, import_utils.ROUTE_MANIFEST_FILE);
|
|
49
50
|
const routeManifest = import_utils.fs.existsSync(routesManifestUri) ? require(routesManifestUri) : void 0;
|
|
51
|
+
const isSpider = isbot.default(ctx.headers["user-agent"] || null);
|
|
50
52
|
const context = {
|
|
51
53
|
request: {
|
|
52
54
|
baseUrl: urlPath,
|
|
@@ -79,6 +81,7 @@ const render = async (ctx, renderOptions, runner) => {
|
|
|
79
81
|
req: ctx.req,
|
|
80
82
|
res: ctx.res,
|
|
81
83
|
enableUnsafeCtx,
|
|
84
|
+
isSpider,
|
|
82
85
|
nonce
|
|
83
86
|
};
|
|
84
87
|
context.logger = (0, import_measure.createLogger)(context, ctx.logger);
|
|
@@ -63,7 +63,7 @@ class ModernServer {
|
|
|
63
63
|
const usageRoutes = this.filterRoutes(this.getRoutes());
|
|
64
64
|
this.router.reset(usageRoutes);
|
|
65
65
|
this.warmupSSRBundle();
|
|
66
|
-
import_cacheMod.cacheMod.loadServerCacheMod(this.pwd);
|
|
66
|
+
import_cacheMod.cacheMod.loadServerCacheMod((0, import_utils.isProd)() ? distDir : this.pwd);
|
|
67
67
|
await this.prepareFrameHandler();
|
|
68
68
|
await this.prepareLoaderHandler(usageRoutes, distDir);
|
|
69
69
|
this.routeRenderHandler = this.getRenderHandler();
|
|
@@ -3,8 +3,8 @@ import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
|
3
3
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
4
4
|
var RegList = {
|
|
5
5
|
before: {
|
|
6
|
-
head: "<head
|
|
7
|
-
body: "<body
|
|
6
|
+
head: "<head[^>]*>",
|
|
7
|
+
body: "<body[^>]*>"
|
|
8
8
|
},
|
|
9
9
|
after: {
|
|
10
10
|
head: "</head>",
|
|
@@ -35,7 +35,9 @@ var TemplateAPI = /* @__PURE__ */ function() {
|
|
|
35
35
|
key: "prependHead",
|
|
36
36
|
value: function prependHead(fragment) {
|
|
37
37
|
var head = RegList.before.head;
|
|
38
|
-
return this.
|
|
38
|
+
return this.replaceByFunction(new RegExp(head), function(beforeHead) {
|
|
39
|
+
return "".concat(beforeHead).concat(fragment);
|
|
40
|
+
});
|
|
39
41
|
}
|
|
40
42
|
},
|
|
41
43
|
{
|
|
@@ -49,7 +51,9 @@ var TemplateAPI = /* @__PURE__ */ function() {
|
|
|
49
51
|
key: "prependBody",
|
|
50
52
|
value: function prependBody(fragment) {
|
|
51
53
|
var body = RegList.before.body;
|
|
52
|
-
return this.
|
|
54
|
+
return this.replaceByFunction(new RegExp(body), function(beforeBody) {
|
|
55
|
+
return "".concat(beforeBody).concat(fragment);
|
|
56
|
+
});
|
|
53
57
|
}
|
|
54
58
|
},
|
|
55
59
|
{
|
|
@@ -59,6 +63,12 @@ var TemplateAPI = /* @__PURE__ */ function() {
|
|
|
59
63
|
return this.replace(body, "".concat(fragment).concat(body));
|
|
60
64
|
}
|
|
61
65
|
},
|
|
66
|
+
{
|
|
67
|
+
key: "replaceByFunction",
|
|
68
|
+
value: function replaceByFunction(reg, replacer) {
|
|
69
|
+
this.content = this.content.replace(reg, replacer);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
62
72
|
{
|
|
63
73
|
key: "replace",
|
|
64
74
|
value: function replace(reg, text) {
|
|
@@ -7,7 +7,9 @@ var templateInjectableStream = function(param) {
|
|
|
7
7
|
var chunk_str = chunk.toString();
|
|
8
8
|
if (prependHead) {
|
|
9
9
|
var head = RegList.before.head;
|
|
10
|
-
chunk_str = chunk_str.replace(
|
|
10
|
+
chunk_str = chunk_str.replace(new RegExp(head), function(beforeHead) {
|
|
11
|
+
return "".concat(beforeHead).concat(prependHead);
|
|
12
|
+
});
|
|
11
13
|
}
|
|
12
14
|
if (appendHead) {
|
|
13
15
|
var head1 = RegList.after.head;
|
|
@@ -15,7 +17,9 @@ var templateInjectableStream = function(param) {
|
|
|
15
17
|
}
|
|
16
18
|
if (prependBody) {
|
|
17
19
|
var body = RegList.before.body;
|
|
18
|
-
chunk_str = chunk_str.replace(
|
|
20
|
+
chunk_str = chunk_str.replace(new RegExp(body), function(beforeBody) {
|
|
21
|
+
return "".concat(beforeBody).concat(prependBody);
|
|
22
|
+
});
|
|
19
23
|
}
|
|
20
24
|
if (appendBody) {
|
|
21
25
|
var body1 = RegList.after.body;
|
|
@@ -2,6 +2,7 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { fs, mime, LOADABLE_STATS_FILE, ROUTE_MANIFEST_FILE, SERVER_RENDER_FUNCTION_NAME } from "@modern-js/utils";
|
|
5
|
+
import * as isbot from "isbot";
|
|
5
6
|
import { createAfterStreamingRenderContext } from "../hook-api";
|
|
6
7
|
import { afterRenderInjectableStream } from "../hook-api/afterRenderForStream";
|
|
7
8
|
import { createLogger, createMetrics } from "./measure";
|
|
@@ -9,7 +10,7 @@ import { injectServerDataStream, injectServerData } from "./utils";
|
|
|
9
10
|
import { ssrCache } from "./ssrCache";
|
|
10
11
|
var render = function() {
|
|
11
12
|
var _ref = _async_to_generator(function(ctx, renderOptions, runner) {
|
|
12
|
-
var _ctx_res, distDir, route, template, staticGenerate, _renderOptions_enableUnsafeCtx, enableUnsafeCtx, nonce, urlPath, bundle, entryName, bundleJS, loadableUri, loadableStats, routesManifestUri, routeManifest, context, bundleJSContent, serverRender, content, _context_redirection, url, _context_redirection_status, status, contentStream, afterStreamingRenderContext;
|
|
13
|
+
var _ctx_res, distDir, route, template, staticGenerate, _renderOptions_enableUnsafeCtx, enableUnsafeCtx, nonce, urlPath, bundle, entryName, bundleJS, loadableUri, loadableStats, routesManifestUri, routeManifest, isSpider, context, bundleJSContent, serverRender, content, _context_redirection, url, _context_redirection_status, status, contentStream, afterStreamingRenderContext;
|
|
13
14
|
return _ts_generator(this, function(_state) {
|
|
14
15
|
switch (_state.label) {
|
|
15
16
|
case 0:
|
|
@@ -20,6 +21,7 @@ var render = function() {
|
|
|
20
21
|
loadableStats = fs.existsSync(loadableUri) ? require(loadableUri) : "";
|
|
21
22
|
routesManifestUri = path.join(distDir, ROUTE_MANIFEST_FILE);
|
|
22
23
|
routeManifest = fs.existsSync(routesManifestUri) ? require(routesManifestUri) : void 0;
|
|
24
|
+
isSpider = isbot.default(ctx.headers["user-agent"] || null);
|
|
23
25
|
context = {
|
|
24
26
|
request: {
|
|
25
27
|
baseUrl: urlPath,
|
|
@@ -52,6 +54,7 @@ var render = function() {
|
|
|
52
54
|
req: ctx.req,
|
|
53
55
|
res: ctx.res,
|
|
54
56
|
enableUnsafeCtx,
|
|
57
|
+
isSpider,
|
|
55
58
|
nonce
|
|
56
59
|
};
|
|
57
60
|
context.logger = createLogger(context, ctx.logger);
|
|
@@ -7,7 +7,7 @@ import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_
|
|
|
7
7
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
8
8
|
import { createServer } from "http";
|
|
9
9
|
import path from "path";
|
|
10
|
-
import { fs, isPromise, isWebOnly, mime, ROUTE_SPEC_FILE } from "@modern-js/utils";
|
|
10
|
+
import { fs, isProd, isPromise, isWebOnly, mime, ROUTE_SPEC_FILE } from "@modern-js/utils";
|
|
11
11
|
import { time } from "@modern-js/runtime-utils/time";
|
|
12
12
|
import { RouteMatchManager } from "../libs/route";
|
|
13
13
|
import { createRenderHandler } from "../libs/render";
|
|
@@ -83,7 +83,7 @@ var ModernServer = /* @__PURE__ */ function() {
|
|
|
83
83
|
usageRoutes = _this.filterRoutes(_this.getRoutes());
|
|
84
84
|
_this.router.reset(usageRoutes);
|
|
85
85
|
_this.warmupSSRBundle();
|
|
86
|
-
cacheMod.loadServerCacheMod(_this.pwd);
|
|
86
|
+
cacheMod.loadServerCacheMod(isProd() ? distDir : _this.pwd);
|
|
87
87
|
return [
|
|
88
88
|
4,
|
|
89
89
|
_this.prepareFrameHandler()
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
2
|
const RegList = {
|
|
3
3
|
before: {
|
|
4
|
-
head: "<head
|
|
5
|
-
body: "<body
|
|
4
|
+
head: "<head[^>]*>",
|
|
5
|
+
body: "<body[^>]*>"
|
|
6
6
|
},
|
|
7
7
|
after: {
|
|
8
8
|
head: "</head>",
|
|
@@ -18,7 +18,7 @@ class TemplateAPI {
|
|
|
18
18
|
}
|
|
19
19
|
prependHead(fragment) {
|
|
20
20
|
const { head } = RegList.before;
|
|
21
|
-
return this.
|
|
21
|
+
return this.replaceByFunction(new RegExp(head), (beforeHead) => `${beforeHead}${fragment}`);
|
|
22
22
|
}
|
|
23
23
|
appendHead(fragment) {
|
|
24
24
|
const { head } = RegList.after;
|
|
@@ -26,12 +26,15 @@ class TemplateAPI {
|
|
|
26
26
|
}
|
|
27
27
|
prependBody(fragment) {
|
|
28
28
|
const { body } = RegList.before;
|
|
29
|
-
return this.
|
|
29
|
+
return this.replaceByFunction(new RegExp(body), (beforeBody) => `${beforeBody}${fragment}`);
|
|
30
30
|
}
|
|
31
31
|
appendBody(fragment) {
|
|
32
32
|
const { body } = RegList.after;
|
|
33
33
|
return this.replace(body, `${fragment}${body}`);
|
|
34
34
|
}
|
|
35
|
+
replaceByFunction(reg, replacer) {
|
|
36
|
+
this.content = this.content.replace(reg, replacer);
|
|
37
|
+
}
|
|
35
38
|
replace(reg, text) {
|
|
36
39
|
this.content = this.content.replace(reg, text);
|
|
37
40
|
}
|
|
@@ -5,7 +5,7 @@ const templateInjectableStream = ({ prependHead, appendHead, prependBody, append
|
|
|
5
5
|
let chunk_str = chunk.toString();
|
|
6
6
|
if (prependHead) {
|
|
7
7
|
const { head } = RegList.before;
|
|
8
|
-
chunk_str = chunk_str.replace(head, `${
|
|
8
|
+
chunk_str = chunk_str.replace(new RegExp(head), (beforeHead) => `${beforeHead}${prependHead}`);
|
|
9
9
|
}
|
|
10
10
|
if (appendHead) {
|
|
11
11
|
const { head } = RegList.after;
|
|
@@ -13,7 +13,7 @@ const templateInjectableStream = ({ prependHead, appendHead, prependBody, append
|
|
|
13
13
|
}
|
|
14
14
|
if (prependBody) {
|
|
15
15
|
const { body } = RegList.before;
|
|
16
|
-
chunk_str = chunk_str.replace(body, `${
|
|
16
|
+
chunk_str = chunk_str.replace(new RegExp(body), (beforeBody) => `${beforeBody}${prependBody}`);
|
|
17
17
|
}
|
|
18
18
|
if (appendBody) {
|
|
19
19
|
const { body } = RegList.after;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fs, mime, LOADABLE_STATS_FILE, ROUTE_MANIFEST_FILE, SERVER_RENDER_FUNCTION_NAME } from "@modern-js/utils";
|
|
3
|
+
import * as isbot from "isbot";
|
|
3
4
|
import { createAfterStreamingRenderContext } from "../hook-api";
|
|
4
5
|
import { afterRenderInjectableStream } from "../hook-api/afterRenderForStream";
|
|
5
6
|
import { createLogger, createMetrics } from "./measure";
|
|
@@ -14,6 +15,7 @@ const render = async (ctx, renderOptions, runner) => {
|
|
|
14
15
|
const loadableStats = fs.existsSync(loadableUri) ? require(loadableUri) : "";
|
|
15
16
|
const routesManifestUri = path.join(distDir, ROUTE_MANIFEST_FILE);
|
|
16
17
|
const routeManifest = fs.existsSync(routesManifestUri) ? require(routesManifestUri) : void 0;
|
|
18
|
+
const isSpider = isbot.default(ctx.headers["user-agent"] || null);
|
|
17
19
|
const context = {
|
|
18
20
|
request: {
|
|
19
21
|
baseUrl: urlPath,
|
|
@@ -46,6 +48,7 @@ const render = async (ctx, renderOptions, runner) => {
|
|
|
46
48
|
req: ctx.req,
|
|
47
49
|
res: ctx.res,
|
|
48
50
|
enableUnsafeCtx,
|
|
51
|
+
isSpider,
|
|
49
52
|
nonce
|
|
50
53
|
};
|
|
51
54
|
context.logger = createLogger(context, ctx.logger);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
2
|
import { createServer } from "http";
|
|
3
3
|
import path from "path";
|
|
4
|
-
import { fs, isPromise, isWebOnly, mime, ROUTE_SPEC_FILE } from "@modern-js/utils";
|
|
4
|
+
import { fs, isProd, isPromise, isWebOnly, mime, ROUTE_SPEC_FILE } from "@modern-js/utils";
|
|
5
5
|
import { time } from "@modern-js/runtime-utils/time";
|
|
6
6
|
import { RouteMatchManager } from "../libs/route";
|
|
7
7
|
import { createRenderHandler } from "../libs/render";
|
|
@@ -30,7 +30,7 @@ class ModernServer {
|
|
|
30
30
|
const usageRoutes = this.filterRoutes(this.getRoutes());
|
|
31
31
|
this.router.reset(usageRoutes);
|
|
32
32
|
this.warmupSSRBundle();
|
|
33
|
-
cacheMod.loadServerCacheMod(this.pwd);
|
|
33
|
+
cacheMod.loadServerCacheMod(isProd() ? distDir : this.pwd);
|
|
34
34
|
await this.prepareFrameHandler();
|
|
35
35
|
await this.prepareLoaderHandler(usageRoutes, distDir);
|
|
36
36
|
this.routeRenderHandler = this.getRenderHandler();
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.46.1",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
+
"isbot": "^3.8.0",
|
|
66
67
|
"@swc/helpers": "0.5.3",
|
|
67
68
|
"cookie": "0.5.0",
|
|
68
69
|
"etag": "^1.8.1",
|
|
@@ -73,10 +74,10 @@
|
|
|
73
74
|
"node-html-parser": "^6.1.5",
|
|
74
75
|
"path-to-regexp": "^6.2.0",
|
|
75
76
|
"serve-static": "^1.14.1",
|
|
76
|
-
"@modern-js/plugin": "2.
|
|
77
|
-
"@modern-js/server-core": "2.
|
|
78
|
-
"@modern-js/
|
|
79
|
-
"@modern-js/utils": "2.
|
|
77
|
+
"@modern-js/plugin": "2.46.1",
|
|
78
|
+
"@modern-js/server-core": "2.46.1",
|
|
79
|
+
"@modern-js/utils": "2.46.1",
|
|
80
|
+
"@modern-js/runtime-utils": "2.46.1"
|
|
80
81
|
},
|
|
81
82
|
"devDependencies": {
|
|
82
83
|
"@types/cookie": "0.5.1",
|
|
@@ -94,9 +95,9 @@
|
|
|
94
95
|
"portfinder": "^1.0.28",
|
|
95
96
|
"typescript": "^5",
|
|
96
97
|
"ws": "^8.13.0",
|
|
97
|
-
"@modern-js/types": "2.
|
|
98
|
-
"@scripts/
|
|
99
|
-
"@scripts/
|
|
98
|
+
"@modern-js/types": "2.46.1",
|
|
99
|
+
"@scripts/jest-config": "2.46.1",
|
|
100
|
+
"@scripts/build": "2.46.1"
|
|
100
101
|
},
|
|
101
102
|
"sideEffects": false,
|
|
102
103
|
"publishConfig": {
|