@modern-js/plugin-ssg 1.2.7 → 1.2.10
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 +42 -0
- package/dist/js/modern/index.js +1 -2
- package/dist/js/modern/server/index.js +3 -5
- package/dist/js/node/index.js +1 -2
- package/dist/js/node/server/index.js +3 -6
- package/dist/types/server/index.d.ts +2 -2
- package/package.json +5 -5
- package/tests/.eslintrc.js +0 -6
- package/tests/index.test.ts +0 -8
- package/tests/lib.test.ts +0 -104
- package/tests/material/lib.route.json +0 -24
- package/tests/material/replace.route.json +0 -45
- package/tests/tsconfig.json +0 -10
- package/tests/util.test.ts +0 -157
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
# @modern-js/plugin-ssg
|
|
2
2
|
|
|
3
|
+
## 1.2.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 895fa0ff: chore: using "workspace:\*" in devDependencies
|
|
8
|
+
- b54a15ed: fix ssg with server plugin
|
|
9
|
+
- Updated dependencies [2d155c4c]
|
|
10
|
+
- Updated dependencies [123e432d]
|
|
11
|
+
- Updated dependencies [e5a9b26d]
|
|
12
|
+
- Updated dependencies [0b26b93b]
|
|
13
|
+
- Updated dependencies [123e432d]
|
|
14
|
+
- Updated dependencies [f9f66ef9]
|
|
15
|
+
- Updated dependencies [592edabc]
|
|
16
|
+
- Updated dependencies [895fa0ff]
|
|
17
|
+
- Updated dependencies [3578913e]
|
|
18
|
+
- Updated dependencies [1c3beab3]
|
|
19
|
+
- @modern-js/utils@1.6.0
|
|
20
|
+
|
|
21
|
+
## 1.2.9
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
|
|
26
|
+
- 60f7d8bf: feat: add tests dir to npmignore
|
|
27
|
+
- Updated dependencies [b8599d09]
|
|
28
|
+
- Updated dependencies [60f7d8bf]
|
|
29
|
+
- Updated dependencies [3bf4f8b0]
|
|
30
|
+
- @modern-js/utils@1.5.0
|
|
31
|
+
|
|
32
|
+
## 1.2.8
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- 046e58aa: fix: plugin-analyze and plugin-ssg should not import method from core
|
|
37
|
+
- Updated dependencies [77ff9754]
|
|
38
|
+
- Updated dependencies [d2d1d6b2]
|
|
39
|
+
- Updated dependencies [07a4887e]
|
|
40
|
+
- Updated dependencies [ea2ae711]
|
|
41
|
+
- Updated dependencies [17d0cc46]
|
|
42
|
+
- Updated dependencies [d2d1d6b2]
|
|
43
|
+
- @modern-js/utils@1.4.0
|
|
44
|
+
|
|
3
45
|
## 1.2.7
|
|
4
46
|
|
|
5
47
|
### Patch Changes
|
package/dist/js/modern/index.js
CHANGED
|
@@ -35,7 +35,6 @@ export default (() => ({
|
|
|
35
35
|
};
|
|
36
36
|
},
|
|
37
37
|
|
|
38
|
-
// eslint-disable-next-line max-statements
|
|
39
38
|
async afterBuild() {
|
|
40
39
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
41
40
|
const appContext = api.useAppContext();
|
|
@@ -169,7 +168,7 @@ export default (() => ({
|
|
|
169
168
|
ssgRoute.isSSR = false;
|
|
170
169
|
ssgRoute.output = formatOutput(ssgRoute.output);
|
|
171
170
|
});
|
|
172
|
-
const htmlAry = await createServer(ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
|
|
171
|
+
const htmlAry = await createServer(api, ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
|
|
173
172
|
|
|
174
173
|
writeHtmlFile(htmlAry, ssgRoutes, buildDir); // format route info, side effect
|
|
175
174
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import childProcess from 'child_process';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { logger } from '@modern-js/utils';
|
|
4
|
-
import { useAppContext } from '@modern-js/core';
|
|
5
4
|
import { openRouteSSR } from "../libs/util";
|
|
6
5
|
import { CLOSE_SIGN } from "./consts";
|
|
7
|
-
export const createServer = (ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
6
|
+
export const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
8
7
|
// this side of the shallow copy of a route for subsequent render processing, to prevent the modification of the current field
|
|
9
8
|
// manually enable the server-side rendering configuration for all routes that require SSG
|
|
10
9
|
const backup = openRouteSSR(pageRoutes);
|
|
@@ -13,9 +12,8 @@ export const createServer = (ssgRoutes, pageRoutes, apiRoutes, options, appDirec
|
|
|
13
12
|
cwd: appDirectory,
|
|
14
13
|
silent: true
|
|
15
14
|
});
|
|
16
|
-
const appContext = useAppContext();
|
|
17
|
-
const
|
|
18
|
-
const plugins = serverPlugins.map(p => p.name);
|
|
15
|
+
const appContext = api.useAppContext();
|
|
16
|
+
const plugins = appContext.plugins.filter(p => p.server).map(p => p.server);
|
|
19
17
|
cp.send(JSON.stringify({
|
|
20
18
|
options,
|
|
21
19
|
renderRoutes: ssgRoutes,
|
package/dist/js/node/index.js
CHANGED
|
@@ -52,7 +52,6 @@ var _default = () => ({
|
|
|
52
52
|
};
|
|
53
53
|
},
|
|
54
54
|
|
|
55
|
-
// eslint-disable-next-line max-statements
|
|
56
55
|
async afterBuild() {
|
|
57
56
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
58
57
|
const appContext = api.useAppContext();
|
|
@@ -187,7 +186,7 @@ var _default = () => ({
|
|
|
187
186
|
ssgRoute.isSSR = false;
|
|
188
187
|
ssgRoute.output = (0, _util.formatOutput)(ssgRoute.output);
|
|
189
188
|
});
|
|
190
|
-
const htmlAry = await (0, _server.createServer)(ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
|
|
189
|
+
const htmlAry = await (0, _server.createServer)(api, ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
|
|
191
190
|
|
|
192
191
|
(0, _output.writeHtmlFile)(htmlAry, ssgRoutes, buildDir); // format route info, side effect
|
|
193
192
|
|
|
@@ -11,15 +11,13 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
11
11
|
|
|
12
12
|
var _utils = require("@modern-js/utils");
|
|
13
13
|
|
|
14
|
-
var _core = require("@modern-js/core");
|
|
15
|
-
|
|
16
14
|
var _util = require("../libs/util");
|
|
17
15
|
|
|
18
16
|
var _consts = require("./consts");
|
|
19
17
|
|
|
20
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
19
|
|
|
22
|
-
const createServer = (ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
20
|
+
const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
23
21
|
// this side of the shallow copy of a route for subsequent render processing, to prevent the modification of the current field
|
|
24
22
|
// manually enable the server-side rendering configuration for all routes that require SSG
|
|
25
23
|
const backup = (0, _util.openRouteSSR)(pageRoutes);
|
|
@@ -30,9 +28,8 @@ const createServer = (ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) =
|
|
|
30
28
|
silent: true
|
|
31
29
|
});
|
|
32
30
|
|
|
33
|
-
const appContext =
|
|
34
|
-
const
|
|
35
|
-
const plugins = serverPlugins.map(p => p.name);
|
|
31
|
+
const appContext = api.useAppContext();
|
|
32
|
+
const plugins = appContext.plugins.filter(p => p.server).map(p => p.server);
|
|
36
33
|
cp.send(JSON.stringify({
|
|
37
34
|
options,
|
|
38
35
|
renderRoutes: ssgRoutes,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NormalizedConfig } from '@modern-js/core';
|
|
1
|
+
import type { NormalizedConfig, PluginAPI } 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[], pageRoutes: ModernRoute[], apiRoutes: ModernRoute[], options: NormalizedConfig, appDirectory: string) => Promise<string[]>;
|
|
4
|
+
export declare const createServer: (api: PluginAPI, ssgRoutes: SsgRoute[], pageRoutes: ModernRoute[], apiRoutes: ModernRoute[], options: NormalizedConfig, appDirectory: string) => Promise<string[]>;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.2.
|
|
14
|
+
"version": "1.2.10",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -55,15 +55,15 @@
|
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@babel/runtime": "^7",
|
|
58
|
-
"@modern-js/utils": "^1.
|
|
58
|
+
"@modern-js/utils": "^1.6.0",
|
|
59
59
|
"node-mocks-http": "^1.10.1",
|
|
60
60
|
"normalize-path": "^3.0.0",
|
|
61
61
|
"portfinder": "^1.0.28",
|
|
62
62
|
"react-router-dom": "^5.2.1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@modern-js/types": "
|
|
66
|
-
"@modern-js/prod-server": "
|
|
65
|
+
"@modern-js/types": "1.5.1",
|
|
66
|
+
"@modern-js/prod-server": "1.1.2",
|
|
67
67
|
"@types/jest": "^26",
|
|
68
68
|
"@types/node": "^14",
|
|
69
69
|
"@types/react": "^17",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@types/react-router": "^5.1.16",
|
|
72
72
|
"@types/react-router-dom": "^5.1.8",
|
|
73
73
|
"typescript": "^4",
|
|
74
|
-
"@modern-js/core": "1.
|
|
74
|
+
"@modern-js/core": "1.9.0",
|
|
75
75
|
"@scripts/build": "0.0.0",
|
|
76
76
|
"jest": "^27",
|
|
77
77
|
"@scripts/jest-config": "0.0.0"
|
package/tests/.eslintrc.js
DELETED
package/tests/index.test.ts
DELETED
package/tests/lib.test.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { ServerRoute as ModernRoute } from '@modern-js/types';
|
|
4
|
-
import { exist, replaceRoute } from '../src/libs/replace';
|
|
5
|
-
import { makeRoute } from '../src/libs/make';
|
|
6
|
-
|
|
7
|
-
describe('test functional function', () => {
|
|
8
|
-
it('should check route exist correctly', () => {
|
|
9
|
-
const pageRoutes: ModernRoute[] = JSON.parse(
|
|
10
|
-
fs.readFileSync(path.join(__dirname, 'material/lib.route.json'), 'utf-8'),
|
|
11
|
-
).routes;
|
|
12
|
-
const testRoutes = [
|
|
13
|
-
{
|
|
14
|
-
urlPath: '/lib/entry',
|
|
15
|
-
entryName: 'entry',
|
|
16
|
-
result: 0,
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
urlPath: '/lib/home',
|
|
20
|
-
entryName: 'home1',
|
|
21
|
-
result: -1,
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
urlPath: '/lib/home1',
|
|
25
|
-
entryName: 'home',
|
|
26
|
-
result: -1,
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
urlPath: '/lib/user',
|
|
30
|
-
entryName: 'mobile',
|
|
31
|
-
result: 2,
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
urlPath: '/lib/user',
|
|
35
|
-
entryName: 'pc',
|
|
36
|
-
result: 3,
|
|
37
|
-
},
|
|
38
|
-
];
|
|
39
|
-
testRoutes.forEach(route => {
|
|
40
|
-
expect(exist(route as any, pageRoutes)).toBe(route.result);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should replace route correctly', () => {
|
|
45
|
-
const matrial = JSON.parse(
|
|
46
|
-
fs.readFileSync(
|
|
47
|
-
path.join(__dirname, 'material/replace.route.json'),
|
|
48
|
-
'utf-8',
|
|
49
|
-
),
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
const { origin, ssg, final } = matrial;
|
|
53
|
-
const result = replaceRoute(ssg, origin);
|
|
54
|
-
|
|
55
|
-
expect(result).toEqual(final);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('shoule generate route correctly', () => {
|
|
59
|
-
const baseRoute: ModernRoute = {
|
|
60
|
-
urlPath: '/foo',
|
|
61
|
-
isSPA: true,
|
|
62
|
-
isSSR: false,
|
|
63
|
-
entryName: 'foo',
|
|
64
|
-
isApi: false,
|
|
65
|
-
bundle: '',
|
|
66
|
-
entryPath: 'html/foo/index.html',
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const route1 = makeRoute(baseRoute, '/baz');
|
|
70
|
-
expect(route1.urlPath).toBe('/foo/baz');
|
|
71
|
-
expect(route1.urlPath).toBe('/foo/baz');
|
|
72
|
-
|
|
73
|
-
const route2 = makeRoute(baseRoute, { url: '/baz' });
|
|
74
|
-
expect(route2.urlPath).toBe('/foo/baz');
|
|
75
|
-
expect(route2.output).toBe(path.normalize('html/foo/baz'));
|
|
76
|
-
|
|
77
|
-
const route3 = makeRoute(baseRoute, {
|
|
78
|
-
url: '/baz',
|
|
79
|
-
output: 'html/baz.html',
|
|
80
|
-
});
|
|
81
|
-
expect(route3.output).toBe(path.normalize('html/baz.html'));
|
|
82
|
-
|
|
83
|
-
const route4 = makeRoute(
|
|
84
|
-
baseRoute,
|
|
85
|
-
{
|
|
86
|
-
url: '/baz',
|
|
87
|
-
},
|
|
88
|
-
{ ua: 'mobile' },
|
|
89
|
-
);
|
|
90
|
-
expect(route4.headers).toEqual({ ua: 'mobile' });
|
|
91
|
-
|
|
92
|
-
const route5 = makeRoute(
|
|
93
|
-
baseRoute,
|
|
94
|
-
{
|
|
95
|
-
url: '/baz',
|
|
96
|
-
headers: {
|
|
97
|
-
ua: 'pc',
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
{ ua: 'mobile' },
|
|
101
|
-
);
|
|
102
|
-
expect(route5.headers).toEqual({ ua: 'pc' });
|
|
103
|
-
});
|
|
104
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"routes": [
|
|
3
|
-
{
|
|
4
|
-
"urlPath": "/lib/entry",
|
|
5
|
-
"entryPath": "html/entry/index.html",
|
|
6
|
-
"entryName": "entry"
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
"urlPath": "/lib/home",
|
|
10
|
-
"entryPath": "html/home/index.html",
|
|
11
|
-
"entryName": "home"
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"urlPath": "/lib/user",
|
|
15
|
-
"entryPath": "html/mobile/index.html",
|
|
16
|
-
"entryName": "mobile"
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"urlPath": "/lib/user",
|
|
20
|
-
"entryPath": "html/mobile/index.html",
|
|
21
|
-
"entryName": "pc"
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"origin": [{
|
|
3
|
-
"urlPath": "/lib/entry",
|
|
4
|
-
"entryPath": "html/entry/index.html",
|
|
5
|
-
"entryName": "entry"
|
|
6
|
-
}, {
|
|
7
|
-
"urlPath": "/lib/home",
|
|
8
|
-
"entryPath": "html/home/index.html",
|
|
9
|
-
"entryName": "home"
|
|
10
|
-
}, {
|
|
11
|
-
"urlPath": "/lib/mobile",
|
|
12
|
-
"entryPath": "html/mobile/index.html",
|
|
13
|
-
"entryName": "mobile"
|
|
14
|
-
}],
|
|
15
|
-
"ssg": [{
|
|
16
|
-
"urlPath": "/lib/entry",
|
|
17
|
-
"entryPath": "html/entry/index.html",
|
|
18
|
-
"entryName": "entry"
|
|
19
|
-
}, {
|
|
20
|
-
"urlPath": "/lib/home",
|
|
21
|
-
"entryPath": "html/home.html",
|
|
22
|
-
"entryName": "home"
|
|
23
|
-
}, {
|
|
24
|
-
"urlPath": "/lib/pc",
|
|
25
|
-
"entryPath": "html/pc/index.html",
|
|
26
|
-
"entryName": "pc"
|
|
27
|
-
}],
|
|
28
|
-
"final": [{
|
|
29
|
-
"urlPath": "/lib/entry",
|
|
30
|
-
"entryPath": "html/entry/index.html",
|
|
31
|
-
"entryName": "entry"
|
|
32
|
-
}, {
|
|
33
|
-
"urlPath": "/lib/home",
|
|
34
|
-
"entryPath": "html/home.html",
|
|
35
|
-
"entryName": "home"
|
|
36
|
-
}, {
|
|
37
|
-
"urlPath": "/lib/mobile",
|
|
38
|
-
"entryPath": "html/mobile/index.html",
|
|
39
|
-
"entryName": "mobile"
|
|
40
|
-
}, {
|
|
41
|
-
"urlPath": "/lib/pc",
|
|
42
|
-
"entryPath": "html/pc/index.html",
|
|
43
|
-
"entryName": "pc"
|
|
44
|
-
}]
|
|
45
|
-
}
|
package/tests/tsconfig.json
DELETED
package/tests/util.test.ts
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatOutput,
|
|
3
|
-
formatPath,
|
|
4
|
-
isDynamicUrl,
|
|
5
|
-
getUrlPrefix,
|
|
6
|
-
getOutput,
|
|
7
|
-
replaceWithAlias,
|
|
8
|
-
standardOptions,
|
|
9
|
-
openRouteSSR,
|
|
10
|
-
} from '../src/libs/util';
|
|
11
|
-
|
|
12
|
-
describe('test ssg util function', () => {
|
|
13
|
-
it('should return format path correctly', () => {
|
|
14
|
-
const f1 = formatPath('foo');
|
|
15
|
-
expect(f1).toBe('/foo');
|
|
16
|
-
|
|
17
|
-
const f2 = formatPath('/foo/');
|
|
18
|
-
expect(f2).toBe('/foo');
|
|
19
|
-
|
|
20
|
-
const f3 = formatPath('foo/');
|
|
21
|
-
expect(f3).toBe('/foo');
|
|
22
|
-
|
|
23
|
-
const f4 = formatPath('./foo');
|
|
24
|
-
expect(f4).toBe('/foo');
|
|
25
|
-
|
|
26
|
-
const f5 = formatPath('/');
|
|
27
|
-
expect(f5).toBe('/');
|
|
28
|
-
|
|
29
|
-
const f6 = formatPath(1 as any);
|
|
30
|
-
expect(f6).toBe(1);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should detect dynamic url correctly', () => {
|
|
34
|
-
const d1 = isDynamicUrl('/:foo');
|
|
35
|
-
expect(d1).toBe(true);
|
|
36
|
-
|
|
37
|
-
const d2 = isDynamicUrl('/foo');
|
|
38
|
-
expect(d2).toBe(false);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should get url base correctly', () => {
|
|
42
|
-
const r1: any = { entryName: 'main' };
|
|
43
|
-
expect(getUrlPrefix(r1, '/')).toBe('');
|
|
44
|
-
expect(getUrlPrefix(r1, '/base')).toBe('/base');
|
|
45
|
-
|
|
46
|
-
const r2: any = { entryName: 'home' };
|
|
47
|
-
expect(getUrlPrefix(r2, '/')).toBe('/home');
|
|
48
|
-
expect(getUrlPrefix(r2, '/base')).toBe('/base/home');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should get output correctly', () => {
|
|
52
|
-
const r1: any = { urlPath: '/foo/a' };
|
|
53
|
-
expect(getOutput(r1, '', true)).toBe('foo/a');
|
|
54
|
-
expect(getOutput(r1, '/foo', true)).toBe('a');
|
|
55
|
-
expect(getOutput(r1, '/foo/a', true)).toBe('');
|
|
56
|
-
|
|
57
|
-
const r2 = {
|
|
58
|
-
urlPath: '/foo/a',
|
|
59
|
-
output: './foo/a.html',
|
|
60
|
-
};
|
|
61
|
-
expect(getOutput(r2 as any, '', false)).toBe(r2.output);
|
|
62
|
-
expect(getOutput(r2 as any, '/foo', true)).toBe(r2.output);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should return format output correctly', () => {
|
|
66
|
-
const entryPath1 = '/base/home/index.html';
|
|
67
|
-
expect(formatOutput(entryPath1)).toBe(entryPath1);
|
|
68
|
-
|
|
69
|
-
const entryPath2 = '/base/home';
|
|
70
|
-
expect(formatOutput(entryPath2)).toBe(entryPath1);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should replace alias correctly', () => {
|
|
74
|
-
expect(replaceWithAlias('/src', '/src/app.js', '@src')).toBe('@src/app.js');
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// eslint-disable-next-line max-statements
|
|
78
|
-
it('should starndar user config correctly', () => {
|
|
79
|
-
const opt0 = standardOptions(false, []);
|
|
80
|
-
expect(opt0).toBeFalsy();
|
|
81
|
-
|
|
82
|
-
const opt1 = standardOptions(true, [{ entryName: 'main', entry: '' }]);
|
|
83
|
-
expect(opt1).toEqual({ main: true });
|
|
84
|
-
|
|
85
|
-
const opt2 = standardOptions(true, [
|
|
86
|
-
{ entryName: 'main', entry: '' },
|
|
87
|
-
{ entryName: 'home', entry: '' },
|
|
88
|
-
]);
|
|
89
|
-
expect(opt2).toEqual({ main: true, home: true });
|
|
90
|
-
|
|
91
|
-
const opt3 = standardOptions(true, [
|
|
92
|
-
{ entryName: 'main', entry: '' },
|
|
93
|
-
{ entryName: 'home', entry: '' },
|
|
94
|
-
]);
|
|
95
|
-
expect(opt3).toEqual({ main: true, home: true });
|
|
96
|
-
|
|
97
|
-
// single entry, object config
|
|
98
|
-
const ssg1 = {
|
|
99
|
-
routes: ['/foo', { url: '/baz' }],
|
|
100
|
-
};
|
|
101
|
-
const opt4 = standardOptions(ssg1, [{ entryName: 'main', entry: '' }]);
|
|
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'] } });
|
|
145
|
-
});
|
|
146
|
-
|
|
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
|
-
});
|
|
157
|
-
});
|