@modern-js/plugin-ssg 1.21.5 → 2.0.0-beta.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/CHANGELOG.md +49 -17
- package/dist/js/modern/index.js +24 -34
- package/dist/js/modern/libs/make.js +0 -4
- package/dist/js/modern/libs/output.js +0 -2
- package/dist/js/modern/libs/replace.js +6 -15
- package/dist/js/modern/libs/util.js +35 -28
- package/dist/js/modern/server/index.js +1 -4
- package/dist/js/modern/server/prerender.js +0 -6
- package/dist/js/modern/server/process.js +9 -28
- package/dist/js/node/index.js +23 -46
- package/dist/js/node/libs/make.js +0 -9
- package/dist/js/node/libs/output.js +0 -7
- package/dist/js/node/libs/replace.js +6 -19
- package/dist/js/node/libs/util.js +36 -46
- package/dist/js/node/server/index.js +1 -16
- package/dist/js/node/server/prerender.js +0 -14
- package/dist/js/node/server/process.js +9 -34
- package/dist/types/index.d.ts +0 -2
- package/dist/types/libs/util.d.ts +3 -2
- package/dist/types/types.d.ts +5 -4
- package/package.json +19 -36
|
@@ -1,37 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _prodServer = _interopRequireDefault(require("@modern-js/prod-server"));
|
|
4
|
-
|
|
5
4
|
var _portfinder = _interopRequireDefault(require("portfinder"));
|
|
6
|
-
|
|
7
|
-
var _utils = require("@modern-js/utils");
|
|
8
|
-
|
|
9
5
|
var _make = require("../libs/make");
|
|
10
|
-
|
|
11
6
|
var _prerender = require("./prerender");
|
|
12
|
-
|
|
13
7
|
var _consts = require("./consts");
|
|
14
|
-
|
|
15
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
|
-
const safetyRequire = (filename, base) => {
|
|
18
|
-
try {
|
|
19
|
-
return (0, _utils.compatRequire)(require.resolve(`${filename}/server`, {
|
|
20
|
-
paths: [base]
|
|
21
|
-
}));
|
|
22
|
-
} catch (e) {
|
|
23
|
-
return (0, _utils.compatRequire)(require.resolve(filename, {
|
|
24
|
-
paths: [base]
|
|
25
|
-
}));
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
9
|
process.on('message', async chunk => {
|
|
30
10
|
if (chunk === _consts.CLOSE_SIGN) {
|
|
31
11
|
// eslint-disable-next-line no-process-exit
|
|
32
12
|
process.exit();
|
|
33
13
|
}
|
|
34
|
-
|
|
35
14
|
const context = JSON.parse(chunk);
|
|
36
15
|
const {
|
|
37
16
|
routes,
|
|
@@ -40,17 +19,13 @@ process.on('message', async chunk => {
|
|
|
40
19
|
appDirectory,
|
|
41
20
|
plugins
|
|
42
21
|
} = context;
|
|
43
|
-
const instances = plugins.map(plugin => {
|
|
44
|
-
const mod = safetyRequire(plugin, appDirectory);
|
|
45
|
-
return mod();
|
|
46
|
-
});
|
|
47
22
|
let modernServer = null;
|
|
48
|
-
|
|
49
23
|
try {
|
|
50
24
|
const {
|
|
51
25
|
server: serverOptions
|
|
52
|
-
} = options;
|
|
26
|
+
} = options;
|
|
53
27
|
|
|
28
|
+
// start server in default port
|
|
54
29
|
const defaultPort = Number(process.env.PORT) || serverOptions.port;
|
|
55
30
|
_portfinder.default.basePort = defaultPort;
|
|
56
31
|
const port = await _portfinder.default.getPortPromise();
|
|
@@ -59,22 +34,23 @@ process.on('message', async chunk => {
|
|
|
59
34
|
config: options,
|
|
60
35
|
routes,
|
|
61
36
|
staticGenerate: true,
|
|
62
|
-
|
|
63
|
-
});
|
|
37
|
+
internalPlugins: plugins
|
|
38
|
+
});
|
|
64
39
|
|
|
40
|
+
// listen just for bff request in ssr page
|
|
65
41
|
modernServer.listen(port, async err => {
|
|
66
42
|
if (err) {
|
|
67
43
|
throw err;
|
|
68
44
|
}
|
|
69
|
-
|
|
70
45
|
if (!modernServer) {
|
|
71
46
|
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
47
|
+
}
|
|
74
48
|
|
|
49
|
+
// get server handler, render to ssr
|
|
75
50
|
const render = (0, _prerender.compile)(modernServer.getRequestHandler());
|
|
76
|
-
const renderPromiseAry = (0, _make.makeRender)(renderRoutes, render, port);
|
|
51
|
+
const renderPromiseAry = (0, _make.makeRender)(renderRoutes, render, port);
|
|
77
52
|
|
|
53
|
+
// eslint-disable-next-line promise/no-promise-in-callback
|
|
78
54
|
const htmlAry = await Promise.all(renderPromiseAry);
|
|
79
55
|
htmlAry.forEach(html => {
|
|
80
56
|
process.send(html);
|
|
@@ -84,7 +60,6 @@ process.on('message', async chunk => {
|
|
|
84
60
|
});
|
|
85
61
|
} catch (e) {
|
|
86
62
|
var _modernServer;
|
|
87
|
-
|
|
88
63
|
(_modernServer = modernServer) === null || _modernServer === void 0 ? void 0 : _modernServer.close();
|
|
89
64
|
throw e;
|
|
90
65
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ServerRoute as ModernRoute } from '@modern-js/types';
|
|
2
2
|
import { ServerConfig } from '@modern-js/core';
|
|
3
|
-
import { SsgRoute, SSGConfig, EntryPoint, SSGMultiEntryOptions } from '../types';
|
|
3
|
+
import { SsgRoute, SSGConfig, EntryPoint, SSGMultiEntryOptions, AgreedRoute } from '../types';
|
|
4
4
|
export declare function formatOutput(filename: string): string;
|
|
5
5
|
export declare function formatPath(str: string): string;
|
|
6
6
|
export declare function isDynamicUrl(url: string): boolean;
|
|
@@ -20,4 +20,5 @@ export declare const openRouteSSR: (routes: ModernRoute[], entries?: string[]) =
|
|
|
20
20
|
isApi?: boolean | undefined;
|
|
21
21
|
enableModernMode?: boolean | undefined;
|
|
22
22
|
responseHeaders?: Record<string, unknown> | undefined;
|
|
23
|
-
}[];
|
|
23
|
+
}[];
|
|
24
|
+
export declare const flattenRoutes: (routes: AgreedRoute[]) => AgreedRoute[];
|
package/dist/types/types.d.ts
CHANGED
|
@@ -2,10 +2,11 @@ import type { ServerRoute as ModernRoute } from '@modern-js/types';
|
|
|
2
2
|
import type { SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions } from '@modern-js/core';
|
|
3
3
|
export type { SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions };
|
|
4
4
|
export declare type AgreedRoute = {
|
|
5
|
-
path
|
|
6
|
-
component
|
|
7
|
-
_component
|
|
8
|
-
|
|
5
|
+
path?: string;
|
|
6
|
+
component?: string;
|
|
7
|
+
_component?: string;
|
|
8
|
+
children?: AgreedRoute[];
|
|
9
|
+
exact?: boolean;
|
|
9
10
|
};
|
|
10
11
|
export declare type EntryPoint = {
|
|
11
12
|
entryName: string;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "
|
|
14
|
+
"version": "2.0.0-beta.1",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -58,22 +58,28 @@
|
|
|
58
58
|
"node-mocks-http": "^1.10.1",
|
|
59
59
|
"normalize-path": "^3.0.0",
|
|
60
60
|
"portfinder": "^1.0.28",
|
|
61
|
-
"
|
|
62
|
-
|
|
61
|
+
"@modern-js/utils": "2.0.0-beta.1"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"react-router-dom": ">=5.1.2"
|
|
65
|
+
},
|
|
66
|
+
"peerDependenciesMeta": {
|
|
67
|
+
"react-router-dom": {
|
|
68
|
+
"optional": true
|
|
69
|
+
}
|
|
63
70
|
},
|
|
64
71
|
"devDependencies": {
|
|
65
72
|
"@types/jest": "^27",
|
|
66
73
|
"@types/node": "^14",
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"react": "^17",
|
|
74
|
+
"react-router-dom": "^6.4.2",
|
|
75
|
+
"react": "^18",
|
|
70
76
|
"typescript": "^4",
|
|
71
77
|
"jest": "^27",
|
|
72
|
-
"@modern-js/types": "
|
|
73
|
-
"@modern-js/prod-server": "
|
|
74
|
-
"@modern-js/core": "
|
|
75
|
-
"@scripts/build": "
|
|
76
|
-
"@scripts/jest-config": "
|
|
78
|
+
"@modern-js/types": "2.0.0-beta.1",
|
|
79
|
+
"@modern-js/prod-server": "2.0.0-beta.1",
|
|
80
|
+
"@modern-js/core": "2.0.0-beta.1",
|
|
81
|
+
"@scripts/build": "2.0.0-beta.1",
|
|
82
|
+
"@scripts/jest-config": "2.0.0-beta.1"
|
|
77
83
|
},
|
|
78
84
|
"sideEffects": false,
|
|
79
85
|
"modernConfig": {
|
|
@@ -85,33 +91,10 @@
|
|
|
85
91
|
"registry": "https://registry.npmjs.org/",
|
|
86
92
|
"access": "public"
|
|
87
93
|
},
|
|
88
|
-
"wireit": {
|
|
89
|
-
"build": {
|
|
90
|
-
"command": "modern build",
|
|
91
|
-
"files": [
|
|
92
|
-
"src/**/*",
|
|
93
|
-
"tsconfig.json",
|
|
94
|
-
"package.json"
|
|
95
|
-
],
|
|
96
|
-
"output": [
|
|
97
|
-
"dist/**/*"
|
|
98
|
-
]
|
|
99
|
-
},
|
|
100
|
-
"test": {
|
|
101
|
-
"command": "jest --passWithNoTests",
|
|
102
|
-
"files": [
|
|
103
|
-
"src/**/*",
|
|
104
|
-
"tsconfig.json",
|
|
105
|
-
"package.json",
|
|
106
|
-
"tests/**/*"
|
|
107
|
-
],
|
|
108
|
-
"output": []
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
94
|
"scripts": {
|
|
112
95
|
"new": "modern new",
|
|
113
|
-
"build": "
|
|
96
|
+
"build": "modern build",
|
|
114
97
|
"dev": "modern build --watch",
|
|
115
|
-
"test": "
|
|
98
|
+
"test": "jest --passWithNoTests"
|
|
116
99
|
}
|
|
117
100
|
}
|