@modern-js/plugin-ssg 1.2.8 → 1.2.9

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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # @modern-js/plugin-ssg
2
2
 
3
+ ## 1.2.9
4
+
5
+ ### Patch Changes
6
+
7
+ - 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
8
+ - 60f7d8bf: feat: add tests dir to npmignore
9
+ - Updated dependencies [b8599d09]
10
+ - Updated dependencies [60f7d8bf]
11
+ - Updated dependencies [3bf4f8b0]
12
+ - @modern-js/utils@1.5.0
13
+
3
14
  ## 1.2.8
4
15
 
5
16
  ### Patch Changes
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.2.8",
14
+ "version": "1.2.9",
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.4.0",
58
+ "@modern-js/utils": "^1.5.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": "^1.4.0",
66
- "@modern-js/prod-server": "^1.1.0",
65
+ "@modern-js/types": "^1.5.0",
66
+ "@modern-js/prod-server": "^1.1.1",
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.7.0",
74
+ "@modern-js/core": "1.8.0",
75
75
  "@scripts/build": "0.0.0",
76
76
  "jest": "^27",
77
77
  "@scripts/jest-config": "0.0.0"
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- extends: ['@modern-js'],
3
- parserOptions: {
4
- project: require.resolve('./tsconfig.json'),
5
- },
6
- };
@@ -1,8 +0,0 @@
1
- import plugin from '../src';
2
-
3
- describe('plugin-ssg', () => {
4
- it('default', () => {
5
- expect(plugin).toBeDefined();
6
- expect(plugin().name).toBe('@modern-js/plugin-ssg');
7
- });
8
- });
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
- }
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "@modern-js/tsconfig/base",
3
- "compilerOptions": {
4
- "declaration": false,
5
- "jsx": "preserve",
6
- "baseUrl": "./",
7
- "paths": {},
8
- "esModuleInterop": true
9
- }
10
- }
@@ -1,156 +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
- it('should starndar user config correctly', () => {
78
- const opt0 = standardOptions(false, []);
79
- expect(opt0).toBeFalsy();
80
-
81
- const opt1 = standardOptions(true, [{ entryName: 'main', entry: '' }]);
82
- expect(opt1).toEqual({ main: true });
83
-
84
- const opt2 = standardOptions(true, [
85
- { entryName: 'main', entry: '' },
86
- { entryName: 'home', entry: '' },
87
- ]);
88
- expect(opt2).toEqual({ main: true, home: true });
89
-
90
- const opt3 = standardOptions(true, [
91
- { entryName: 'main', entry: '' },
92
- { entryName: 'home', entry: '' },
93
- ]);
94
- expect(opt3).toEqual({ main: true, home: true });
95
-
96
- // single entry, object config
97
- const ssg1 = {
98
- routes: ['/foo', { url: '/baz' }],
99
- };
100
- const opt4 = standardOptions(ssg1, [{ entryName: 'main', entry: '' }]);
101
- expect(opt4).toEqual({ main: ssg1 });
102
-
103
- // error usage, just test
104
- const ssg2 = {
105
- routes: ['/foo', { url: '/baz' }],
106
- };
107
- const opt5 = standardOptions(ssg2, [
108
- { entryName: 'main', entry: '' },
109
- { entryName: 'home', entry: '' },
110
- ]);
111
- expect(opt5).toEqual(ssg2);
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'] } });
144
- });
145
-
146
- it('should get ssr route correctly', () => {
147
- const ssrRoutes = openRouteSSR([
148
- {
149
- isSSR: false,
150
- },
151
- ] as any);
152
-
153
- expect(ssrRoutes[0].isSSR).toBeTruthy();
154
- expect(ssrRoutes[0].bundle).toBeDefined();
155
- });
156
- });