@modern-js/plugin-ssg 1.2.2 → 1.2.5
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 +44 -0
- package/dist/js/modern/index.js +2 -4
- package/dist/js/modern/libs/util.js +12 -2
- package/dist/js/modern/server/index.js +6 -13
- package/dist/js/modern/server/process.js +6 -5
- package/dist/js/modern/types.js +1 -1
- package/dist/js/node/index.js +2 -4
- package/dist/js/node/libs/util.js +15 -2
- package/dist/js/node/server/index.js +6 -12
- package/dist/js/node/server/process.js +6 -5
- package/dist/js/node/types.js +1 -3
- package/dist/types/libs/util.d.ts +11 -1
- package/dist/types/server/index.d.ts +1 -1
- package/dist/types/types.d.ts +8 -2
- package/package.json +25 -8
- package/tests/util.test.ts +54 -41
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# @modern-js/plugin-ssg
|
|
2
2
|
|
|
3
|
+
## 1.2.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 73306c0d: fix ssg type
|
|
8
|
+
- 59010b7a: rewrite server lifecycle, add unit test
|
|
9
|
+
- aed9912e: fix: output.ssg type error
|
|
10
|
+
- Updated dependencies [cc5e8001]
|
|
11
|
+
- Updated dependencies [2520ea86]
|
|
12
|
+
- Updated dependencies [db43dce6]
|
|
13
|
+
- Updated dependencies [e81fd9b7]
|
|
14
|
+
- Updated dependencies [1c411e71]
|
|
15
|
+
- @modern-js/core@1.4.6
|
|
16
|
+
- @modern-js/utils@1.3.4
|
|
17
|
+
|
|
18
|
+
## 1.2.4
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 02fb4146: support product server
|
|
23
|
+
- cc8501c1: fix ssg build after modify server
|
|
24
|
+
- Updated dependencies [969f172f]
|
|
25
|
+
- Updated dependencies [4c792f68]
|
|
26
|
+
- Updated dependencies [4b5d4bf4]
|
|
27
|
+
- Updated dependencies [62f5b8c8]
|
|
28
|
+
- Updated dependencies [55e18278]
|
|
29
|
+
- Updated dependencies [4499a674]
|
|
30
|
+
- Updated dependencies [403f5169]
|
|
31
|
+
- Updated dependencies [a7f42f48]
|
|
32
|
+
- @modern-js/core@1.4.4
|
|
33
|
+
- @modern-js/utils@1.3.3
|
|
34
|
+
|
|
35
|
+
## 1.2.3
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- 1e17ef11: fix: fix ssg with new plugin route logic
|
|
40
|
+
- Updated dependencies [53aca274]
|
|
41
|
+
- Updated dependencies [78279953]
|
|
42
|
+
- Updated dependencies [e116ace5]
|
|
43
|
+
- Updated dependencies [4d72edea]
|
|
44
|
+
- @modern-js/core@1.4.1
|
|
45
|
+
- @modern-js/utils@1.3.1
|
|
46
|
+
|
|
3
47
|
## 1.2.2
|
|
4
48
|
|
|
5
49
|
### Patch Changes
|
package/dist/js/modern/index.js
CHANGED
|
@@ -84,8 +84,6 @@ export default createPlugin(() => {
|
|
|
84
84
|
let entryOptions = intermediateOptions[entryName];
|
|
85
85
|
|
|
86
86
|
if (!agreedRoutes) {
|
|
87
|
-
var _entryOptions$routes;
|
|
88
|
-
|
|
89
87
|
// default behavior for non-agreed route
|
|
90
88
|
if (!entryOptions) {
|
|
91
89
|
return;
|
|
@@ -96,7 +94,7 @@ export default createPlugin(() => {
|
|
|
96
94
|
ssgRoutes.push(_objectSpread(_objectSpread({}, pageRoute), {}, {
|
|
97
95
|
output: entryPath
|
|
98
96
|
}));
|
|
99
|
-
} else if (
|
|
97
|
+
} else if (entryOptions.routes && entryOptions.routes.length > 0) {
|
|
100
98
|
// if entryOptions is object and has routes options
|
|
101
99
|
// add every route in options
|
|
102
100
|
const {
|
|
@@ -172,7 +170,7 @@ export default createPlugin(() => {
|
|
|
172
170
|
ssgRoute.isSSR = false;
|
|
173
171
|
ssgRoute.output = formatOutput(ssgRoute.output);
|
|
174
172
|
});
|
|
175
|
-
const htmlAry = await createServer(ssgRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
|
|
173
|
+
const htmlAry = await createServer(ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
|
|
176
174
|
|
|
177
175
|
writeHtmlFile(htmlAry, ssgRoutes, buildDir); // format route info, side effect
|
|
178
176
|
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
|
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
|
|
1
7
|
import path from 'path';
|
|
2
|
-
import { ROUTE_SPEC_FILE, fs, isSingleEntry } from '@modern-js/utils';
|
|
8
|
+
import { ROUTE_SPEC_FILE, fs, isSingleEntry, SERVER_BUNDLE_DIRECTORY } from '@modern-js/utils';
|
|
3
9
|
export function formatOutput(filename) {
|
|
4
10
|
const outputPath = path.extname(filename) ? filename : `${filename}/index.html`;
|
|
5
11
|
return outputPath;
|
|
@@ -124,4 +130,8 @@ export const standardOptions = (ssgOptions, entrypoints) => {
|
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
return false;
|
|
127
|
-
};
|
|
133
|
+
};
|
|
134
|
+
export const openRouteSSR = routes => routes.map(ssgRoute => _objectSpread(_objectSpread({}, ssgRoute), {}, {
|
|
135
|
+
isSSR: true,
|
|
136
|
+
bundle: `${SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
|
|
137
|
+
}));
|
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
1
|
import childProcess from 'child_process';
|
|
8
2
|
import path from 'path';
|
|
9
|
-
import { logger
|
|
3
|
+
import { logger } from '@modern-js/utils';
|
|
10
4
|
import { useAppContext } from '@modern-js/core';
|
|
5
|
+
import { openRouteSSR } from "../libs/util";
|
|
11
6
|
import { CLOSE_SIGN } from "./consts";
|
|
12
|
-
export const createServer = (ssgRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
7
|
+
export const createServer = (ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
13
8
|
// this side of the shallow copy of a route for subsequent render processing, to prevent the modification of the current field
|
|
14
9
|
// manually enable the server-side rendering configuration for all routes that require SSG
|
|
15
|
-
const backup =
|
|
16
|
-
isSSR: true,
|
|
17
|
-
bundle: `${SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
|
|
18
|
-
}));
|
|
10
|
+
const backup = openRouteSSR(pageRoutes);
|
|
19
11
|
const total = backup.concat(apiRoutes);
|
|
20
12
|
const cp = childProcess.fork(path.join(__dirname, 'process'), {
|
|
21
13
|
cwd: appDirectory,
|
|
@@ -26,6 +18,7 @@ export const createServer = (ssgRoutes, apiRoutes, options, appDirectory) => new
|
|
|
26
18
|
const plugins = serverPlugins.map(p => p.name);
|
|
27
19
|
cp.send(JSON.stringify({
|
|
28
20
|
options,
|
|
21
|
+
renderRoutes: ssgRoutes,
|
|
29
22
|
routes: total,
|
|
30
23
|
appDirectory,
|
|
31
24
|
plugins
|
|
@@ -41,7 +34,7 @@ export const createServer = (ssgRoutes, apiRoutes, options, appDirectory) => new
|
|
|
41
34
|
htmlChunks.length = 0;
|
|
42
35
|
}
|
|
43
36
|
|
|
44
|
-
if (htmlAry.length ===
|
|
37
|
+
if (htmlAry.length === ssgRoutes.length) {
|
|
45
38
|
cp.send(CLOSE_SIGN);
|
|
46
39
|
resolve(htmlAry);
|
|
47
40
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import server from '@modern-js/prod-server';
|
|
2
2
|
import portfinder from 'portfinder';
|
|
3
3
|
import { compatRequire } from '@modern-js/utils';
|
|
4
4
|
import { makeRender } from "../libs/make";
|
|
@@ -26,6 +26,7 @@ process.on('message', async chunk => {
|
|
|
26
26
|
const context = JSON.parse(chunk);
|
|
27
27
|
const {
|
|
28
28
|
routes,
|
|
29
|
+
renderRoutes,
|
|
29
30
|
options,
|
|
30
31
|
appDirectory,
|
|
31
32
|
plugins
|
|
@@ -35,13 +36,13 @@ process.on('message', async chunk => {
|
|
|
35
36
|
|
|
36
37
|
try {
|
|
37
38
|
const {
|
|
38
|
-
server
|
|
39
|
+
server: serverOptions
|
|
39
40
|
} = options; // start server in default port
|
|
40
41
|
|
|
41
|
-
const defaultPort = Number(process.env.PORT) ||
|
|
42
|
+
const defaultPort = Number(process.env.PORT) || serverOptions.port;
|
|
42
43
|
portfinder.basePort = defaultPort;
|
|
43
44
|
const port = await portfinder.getPortPromise();
|
|
44
|
-
modernServer = await
|
|
45
|
+
modernServer = await server({
|
|
45
46
|
pwd: appDirectory,
|
|
46
47
|
config: options,
|
|
47
48
|
routes,
|
|
@@ -60,7 +61,7 @@ process.on('message', async chunk => {
|
|
|
60
61
|
|
|
61
62
|
|
|
62
63
|
const render = createRender(modernServer.getRequestHandler());
|
|
63
|
-
const renderPromiseAry = makeRender(
|
|
64
|
+
const renderPromiseAry = makeRender(renderRoutes, render, port); // eslint-disable-next-line promise/no-promise-in-callback
|
|
64
65
|
|
|
65
66
|
const htmlAry = await Promise.all(renderPromiseAry);
|
|
66
67
|
htmlAry.forEach(html => {
|
package/dist/js/modern/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import '@modern-js/core';
|
package/dist/js/node/index.js
CHANGED
|
@@ -103,8 +103,6 @@ var _default = (0, _core.createPlugin)(() => {
|
|
|
103
103
|
let entryOptions = intermediateOptions[entryName];
|
|
104
104
|
|
|
105
105
|
if (!agreedRoutes) {
|
|
106
|
-
var _entryOptions$routes;
|
|
107
|
-
|
|
108
106
|
// default behavior for non-agreed route
|
|
109
107
|
if (!entryOptions) {
|
|
110
108
|
return;
|
|
@@ -115,7 +113,7 @@ var _default = (0, _core.createPlugin)(() => {
|
|
|
115
113
|
ssgRoutes.push(_objectSpread(_objectSpread({}, pageRoute), {}, {
|
|
116
114
|
output: entryPath
|
|
117
115
|
}));
|
|
118
|
-
} else if (
|
|
116
|
+
} else if (entryOptions.routes && entryOptions.routes.length > 0) {
|
|
119
117
|
// if entryOptions is object and has routes options
|
|
120
118
|
// add every route in options
|
|
121
119
|
const {
|
|
@@ -191,7 +189,7 @@ var _default = (0, _core.createPlugin)(() => {
|
|
|
191
189
|
ssgRoute.isSSR = false;
|
|
192
190
|
ssgRoute.output = (0, _util.formatOutput)(ssgRoute.output);
|
|
193
191
|
});
|
|
194
|
-
const htmlAry = await (0, _server.createServer)(ssgRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
|
|
192
|
+
const htmlAry = await (0, _server.createServer)(ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
|
|
195
193
|
|
|
196
194
|
(0, _output.writeHtmlFile)(htmlAry, ssgRoutes, buildDir); // format route info, side effect
|
|
197
195
|
|
|
@@ -8,7 +8,7 @@ exports.formatPath = formatPath;
|
|
|
8
8
|
exports.getOutput = getOutput;
|
|
9
9
|
exports.getUrlPrefix = getUrlPrefix;
|
|
10
10
|
exports.isDynamicUrl = isDynamicUrl;
|
|
11
|
-
exports.writeJSONSpec = exports.standardOptions = exports.replaceWithAlias = exports.readJSONSpec = void 0;
|
|
11
|
+
exports.writeJSONSpec = exports.standardOptions = exports.replaceWithAlias = exports.readJSONSpec = exports.openRouteSSR = void 0;
|
|
12
12
|
|
|
13
13
|
var _path = _interopRequireDefault(require("path"));
|
|
14
14
|
|
|
@@ -16,6 +16,12 @@ var _utils = require("@modern-js/utils");
|
|
|
16
16
|
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
18
|
|
|
19
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
20
|
+
|
|
21
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
22
|
+
|
|
23
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
24
|
+
|
|
19
25
|
function formatOutput(filename) {
|
|
20
26
|
const outputPath = _path.default.extname(filename) ? filename : `${filename}/index.html`;
|
|
21
27
|
return outputPath;
|
|
@@ -157,4 +163,11 @@ const standardOptions = (ssgOptions, entrypoints) => {
|
|
|
157
163
|
return false;
|
|
158
164
|
};
|
|
159
165
|
|
|
160
|
-
exports.standardOptions = standardOptions;
|
|
166
|
+
exports.standardOptions = standardOptions;
|
|
167
|
+
|
|
168
|
+
const openRouteSSR = routes => routes.map(ssgRoute => _objectSpread(_objectSpread({}, ssgRoute), {}, {
|
|
169
|
+
isSSR: true,
|
|
170
|
+
bundle: `${_utils.SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
|
|
171
|
+
}));
|
|
172
|
+
|
|
173
|
+
exports.openRouteSSR = openRouteSSR;
|
|
@@ -13,23 +13,16 @@ var _utils = require("@modern-js/utils");
|
|
|
13
13
|
|
|
14
14
|
var _core = require("@modern-js/core");
|
|
15
15
|
|
|
16
|
+
var _util = require("../libs/util");
|
|
17
|
+
|
|
16
18
|
var _consts = require("./consts");
|
|
17
19
|
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
23
|
-
|
|
24
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
25
|
-
|
|
26
|
-
const createServer = (ssgRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
22
|
+
const createServer = (ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
27
23
|
// this side of the shallow copy of a route for subsequent render processing, to prevent the modification of the current field
|
|
28
24
|
// manually enable the server-side rendering configuration for all routes that require SSG
|
|
29
|
-
const backup =
|
|
30
|
-
isSSR: true,
|
|
31
|
-
bundle: `${_utils.SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
|
|
32
|
-
}));
|
|
25
|
+
const backup = (0, _util.openRouteSSR)(pageRoutes);
|
|
33
26
|
const total = backup.concat(apiRoutes);
|
|
34
27
|
|
|
35
28
|
const cp = _child_process.default.fork(_path.default.join(__dirname, 'process'), {
|
|
@@ -42,6 +35,7 @@ const createServer = (ssgRoutes, apiRoutes, options, appDirectory) => new Promis
|
|
|
42
35
|
const plugins = serverPlugins.map(p => p.name);
|
|
43
36
|
cp.send(JSON.stringify({
|
|
44
37
|
options,
|
|
38
|
+
renderRoutes: ssgRoutes,
|
|
45
39
|
routes: total,
|
|
46
40
|
appDirectory,
|
|
47
41
|
plugins
|
|
@@ -57,7 +51,7 @@ const createServer = (ssgRoutes, apiRoutes, options, appDirectory) => new Promis
|
|
|
57
51
|
htmlChunks.length = 0;
|
|
58
52
|
}
|
|
59
53
|
|
|
60
|
-
if (htmlAry.length ===
|
|
54
|
+
if (htmlAry.length === ssgRoutes.length) {
|
|
61
55
|
cp.send(_consts.CLOSE_SIGN);
|
|
62
56
|
resolve(htmlAry);
|
|
63
57
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _prodServer = _interopRequireDefault(require("@modern-js/prod-server"));
|
|
4
4
|
|
|
5
5
|
var _portfinder = _interopRequireDefault(require("portfinder"));
|
|
6
6
|
|
|
@@ -35,6 +35,7 @@ process.on('message', async chunk => {
|
|
|
35
35
|
const context = JSON.parse(chunk);
|
|
36
36
|
const {
|
|
37
37
|
routes,
|
|
38
|
+
renderRoutes,
|
|
38
39
|
options,
|
|
39
40
|
appDirectory,
|
|
40
41
|
plugins
|
|
@@ -44,13 +45,13 @@ process.on('message', async chunk => {
|
|
|
44
45
|
|
|
45
46
|
try {
|
|
46
47
|
const {
|
|
47
|
-
server
|
|
48
|
+
server: serverOptions
|
|
48
49
|
} = options; // start server in default port
|
|
49
50
|
|
|
50
|
-
const defaultPort = Number(process.env.PORT) ||
|
|
51
|
+
const defaultPort = Number(process.env.PORT) || serverOptions.port;
|
|
51
52
|
_portfinder.default.basePort = defaultPort;
|
|
52
53
|
const port = await _portfinder.default.getPortPromise();
|
|
53
|
-
modernServer = await (0,
|
|
54
|
+
modernServer = await (0, _prodServer.default)({
|
|
54
55
|
pwd: appDirectory,
|
|
55
56
|
config: options,
|
|
56
57
|
routes,
|
|
@@ -69,7 +70,7 @@ process.on('message', async chunk => {
|
|
|
69
70
|
|
|
70
71
|
|
|
71
72
|
const render = (0, _prerender.compile)(modernServer.getRequestHandler());
|
|
72
|
-
const renderPromiseAry = (0, _make.makeRender)(
|
|
73
|
+
const renderPromiseAry = (0, _make.makeRender)(renderRoutes, render, port); // eslint-disable-next-line promise/no-promise-in-callback
|
|
73
74
|
|
|
74
75
|
const htmlAry = await Promise.all(renderPromiseAry);
|
|
75
76
|
htmlAry.forEach(html => {
|
package/dist/js/node/types.js
CHANGED
|
@@ -8,4 +8,14 @@ export declare function getOutput(route: SsgRoute, base: string, agreed?: boolea
|
|
|
8
8
|
export declare const readJSONSpec: (dir: string) => ModernRoute[];
|
|
9
9
|
export declare const writeJSONSpec: (dir: string, routes: ModernRoute[]) => void;
|
|
10
10
|
export declare const replaceWithAlias: (base: string, filePath: string, alias: string) => string;
|
|
11
|
-
export declare const standardOptions: (ssgOptions: SSG, entrypoints: EntryPoint[]) => false | MultiEntryOptions;
|
|
11
|
+
export declare const standardOptions: (ssgOptions: SSG, entrypoints: EntryPoint[]) => false | MultiEntryOptions;
|
|
12
|
+
export declare const openRouteSSR: (routes: ModernRoute[]) => {
|
|
13
|
+
isSSR: boolean;
|
|
14
|
+
bundle: string;
|
|
15
|
+
entryName?: string | undefined;
|
|
16
|
+
urlPath: string;
|
|
17
|
+
entryPath: string;
|
|
18
|
+
isSPA?: boolean | undefined;
|
|
19
|
+
isApi?: boolean | undefined;
|
|
20
|
+
enableModernMode?: boolean | undefined;
|
|
21
|
+
}[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { NormalizedConfig } from '@modern-js/core';
|
|
2
2
|
import { ServerRoute as ModernRoute } from '@modern-js/types';
|
|
3
3
|
import { SsgRoute } from '../types';
|
|
4
|
-
export declare const createServer: (ssgRoutes: SsgRoute[], apiRoutes: ModernRoute[], options: NormalizedConfig, appDirectory: string) => Promise<string[]>;
|
|
4
|
+
export declare const createServer: (ssgRoutes: SsgRoute[], pageRoutes: ModernRoute[], apiRoutes: ModernRoute[], options: NormalizedConfig, appDirectory: string) => Promise<string[]>;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ServerRoute as ModernRoute } from '@modern-js/types';
|
|
2
|
+
import '@modern-js/core';
|
|
2
3
|
export declare type AgreedRoute = {
|
|
3
4
|
path: string;
|
|
4
5
|
component: string;
|
|
@@ -25,10 +26,15 @@ export declare type RouteOptions = string | {
|
|
|
25
26
|
export declare type SingleEntryOptions = boolean | {
|
|
26
27
|
preventDefault?: string[];
|
|
27
28
|
headers?: Record<string, any>;
|
|
28
|
-
routes
|
|
29
|
+
routes?: RouteOptions[];
|
|
29
30
|
};
|
|
30
31
|
export declare type MultiEntryOptions = Record<string, SingleEntryOptions>;
|
|
31
32
|
export declare type SSG = boolean | SingleEntryOptions | MultiEntryOptions | ((entryName: string) => SingleEntryOptions);
|
|
32
33
|
export declare type ExtendOutputConfig = {
|
|
33
34
|
ssg: SSG;
|
|
34
|
-
};
|
|
35
|
+
};
|
|
36
|
+
declare module '@modern-js/core' {
|
|
37
|
+
interface OutputConfig {
|
|
38
|
+
ssg?: SSG;
|
|
39
|
+
}
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -11,12 +11,22 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.2.
|
|
14
|
+
"version": "1.2.5",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
18
18
|
"module": "./dist/js/treeshaking/index.js",
|
|
19
19
|
"jsnext:modern": "./dist/js/modern/index.js",
|
|
20
|
+
"typesVersions": {
|
|
21
|
+
"*": {
|
|
22
|
+
".": [
|
|
23
|
+
"./dist/types/index.d.ts"
|
|
24
|
+
],
|
|
25
|
+
"types": [
|
|
26
|
+
"./dist/types/types.d.ts"
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
},
|
|
20
30
|
"exports": {
|
|
21
31
|
".": {
|
|
22
32
|
"node": {
|
|
@@ -33,19 +43,27 @@
|
|
|
33
43
|
"require": "./dist/js/node/index.js"
|
|
34
44
|
},
|
|
35
45
|
"default": "./dist/js/treeshaking/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./types": {
|
|
48
|
+
"node": {
|
|
49
|
+
"import": "./dist/js/modern/types.js",
|
|
50
|
+
"require": "./dist/js/node/types.js",
|
|
51
|
+
"types": "./dist/types/types.d.ts"
|
|
52
|
+
},
|
|
53
|
+
"default": "./dist/js/treeshaking/types.js"
|
|
36
54
|
}
|
|
37
55
|
},
|
|
38
56
|
"dependencies": {
|
|
39
57
|
"@babel/runtime": "^7",
|
|
40
|
-
"@modern-js/utils": "^1.3.
|
|
58
|
+
"@modern-js/utils": "^1.3.4",
|
|
41
59
|
"node-mocks-http": "^1.10.1",
|
|
42
60
|
"normalize-path": "^3.0.0",
|
|
43
61
|
"portfinder": "^1.0.28",
|
|
44
62
|
"react-router-dom": "^5.2.1"
|
|
45
63
|
},
|
|
46
64
|
"devDependencies": {
|
|
47
|
-
"@modern-js/
|
|
48
|
-
"@modern-js/
|
|
65
|
+
"@modern-js/types": "^1.3.4",
|
|
66
|
+
"@modern-js/prod-server": "^1.0.2",
|
|
49
67
|
"@types/jest": "^26",
|
|
50
68
|
"@types/node": "^14",
|
|
51
69
|
"@types/react": "^17",
|
|
@@ -53,13 +71,13 @@
|
|
|
53
71
|
"@types/react-router": "^5.1.16",
|
|
54
72
|
"@types/react-router-dom": "^5.1.8",
|
|
55
73
|
"typescript": "^4",
|
|
56
|
-
"@modern-js/core": "^1.4.
|
|
74
|
+
"@modern-js/core": "^1.4.6",
|
|
57
75
|
"@scripts/build": "0.0.0",
|
|
58
76
|
"jest": "^27",
|
|
59
77
|
"@scripts/jest-config": "0.0.0"
|
|
60
78
|
},
|
|
61
79
|
"peerDependencies": {
|
|
62
|
-
"@modern-js/core": "^1.4.
|
|
80
|
+
"@modern-js/core": "^1.4.6"
|
|
63
81
|
},
|
|
64
82
|
"sideEffects": false,
|
|
65
83
|
"modernConfig": {
|
|
@@ -69,8 +87,7 @@
|
|
|
69
87
|
},
|
|
70
88
|
"publishConfig": {
|
|
71
89
|
"registry": "https://registry.npmjs.org/",
|
|
72
|
-
"access": "public"
|
|
73
|
-
"types": "./dist/types/index.d.ts"
|
|
90
|
+
"access": "public"
|
|
74
91
|
},
|
|
75
92
|
"scripts": {
|
|
76
93
|
"new": "modern new",
|
package/tests/util.test.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
getOutput,
|
|
7
7
|
replaceWithAlias,
|
|
8
8
|
standardOptions,
|
|
9
|
+
openRouteSSR,
|
|
9
10
|
} from '../src/libs/util';
|
|
10
11
|
|
|
11
12
|
describe('test ssg util function', () => {
|
|
@@ -73,6 +74,7 @@ describe('test ssg util function', () => {
|
|
|
73
74
|
expect(replaceWithAlias('/src', '/src/app.js', '@src')).toBe('@src/app.js');
|
|
74
75
|
});
|
|
75
76
|
|
|
77
|
+
// eslint-disable-next-line max-statements
|
|
76
78
|
it('should starndar user config correctly', () => {
|
|
77
79
|
const opt0 = standardOptions(false, []);
|
|
78
80
|
expect(opt0).toBeFalsy();
|
|
@@ -98,47 +100,58 @@ describe('test ssg util function', () => {
|
|
|
98
100
|
};
|
|
99
101
|
const opt4 = standardOptions(ssg1, [{ entryName: 'main', entry: '' }]);
|
|
100
102
|
expect(opt4).toEqual({ main: ssg1 });
|
|
103
|
+
|
|
104
|
+
// error usage, just test
|
|
105
|
+
const ssg2 = {
|
|
106
|
+
routes: ['/foo', { url: '/baz' }],
|
|
107
|
+
};
|
|
108
|
+
const opt5 = standardOptions(ssg2, [
|
|
109
|
+
{ entryName: 'main', entry: '' },
|
|
110
|
+
{ entryName: 'home', entry: '' },
|
|
111
|
+
]);
|
|
112
|
+
expect(opt5).toEqual(ssg2);
|
|
113
|
+
|
|
114
|
+
const ssg3 = {
|
|
115
|
+
main: { routes: ['/foo', { url: '/baz' }] },
|
|
116
|
+
home: false,
|
|
117
|
+
};
|
|
118
|
+
const opt6 = standardOptions(ssg3, [
|
|
119
|
+
{ entryName: 'main', entry: '' },
|
|
120
|
+
{ entryName: 'home', entry: '' },
|
|
121
|
+
]);
|
|
122
|
+
expect(opt6).toEqual(ssg3);
|
|
123
|
+
|
|
124
|
+
const ssg4 = () => true;
|
|
125
|
+
const opt7 = standardOptions(ssg4, [
|
|
126
|
+
{ entryName: 'main', entry: '' },
|
|
127
|
+
{ entryName: 'home', entry: '' },
|
|
128
|
+
]);
|
|
129
|
+
expect(opt7).toEqual({ main: true, home: true });
|
|
130
|
+
|
|
131
|
+
const ssg5 = (entryName: string) => {
|
|
132
|
+
if (entryName === 'main') {
|
|
133
|
+
return true;
|
|
134
|
+
} else {
|
|
135
|
+
return {
|
|
136
|
+
routes: ['/foo'],
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const opt8 = standardOptions(ssg5, [
|
|
141
|
+
{ entryName: 'main', entry: '' },
|
|
142
|
+
{ entryName: 'home', entry: '' },
|
|
143
|
+
]);
|
|
144
|
+
expect(opt8).toEqual({ main: true, home: { routes: ['/foo'] } });
|
|
101
145
|
});
|
|
102
146
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const ssg3 = {
|
|
114
|
-
main: { routes: ['/foo', { url: '/baz' }] },
|
|
115
|
-
home: false,
|
|
116
|
-
};
|
|
117
|
-
const opt6 = standardOptions(ssg3, [
|
|
118
|
-
{ entryName: 'main', entry: '' },
|
|
119
|
-
{ entryName: 'home', entry: '' },
|
|
120
|
-
]);
|
|
121
|
-
expect(opt6).toEqual(ssg3);
|
|
122
|
-
|
|
123
|
-
const ssg4 = () => true;
|
|
124
|
-
const opt7 = standardOptions(ssg4, [
|
|
125
|
-
{ entryName: 'main', entry: '' },
|
|
126
|
-
{ entryName: 'home', entry: '' },
|
|
127
|
-
]);
|
|
128
|
-
expect(opt7).toEqual({ main: true, home: true });
|
|
129
|
-
|
|
130
|
-
const ssg5 = (entryName: string) => {
|
|
131
|
-
if (entryName === 'main') {
|
|
132
|
-
return true;
|
|
133
|
-
} else {
|
|
134
|
-
return {
|
|
135
|
-
routes: ['/foo'],
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
const opt8 = standardOptions(ssg5, [
|
|
140
|
-
{ entryName: 'main', entry: '' },
|
|
141
|
-
{ entryName: 'home', entry: '' },
|
|
142
|
-
]);
|
|
143
|
-
expect(opt8).toEqual({ main: true, home: { routes: ['/foo'] } });
|
|
147
|
+
it('should get ssr route correctly', () => {
|
|
148
|
+
const ssrRoutes = openRouteSSR([
|
|
149
|
+
{
|
|
150
|
+
isSSR: false,
|
|
151
|
+
},
|
|
152
|
+
] as any);
|
|
153
|
+
|
|
154
|
+
expect(ssrRoutes[0].isSSR).toBeTruthy();
|
|
155
|
+
expect(ssrRoutes[0].bundle).toBeDefined();
|
|
156
|
+
});
|
|
144
157
|
});
|