@modern-js/plugin-ssg 1.2.15-alpha.0 → 1.15.0

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,12 +1,33 @@
1
1
  # @modern-js/plugin-ssg
2
2
 
3
- ## 1.2.15-alpha.0
3
+ ## 1.15.0
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - Updated dependencies [9cd364e06]
8
- - Updated dependencies [a90bc96bd]
9
- - @modern-js/utils@1.7.9-alpha.0
7
+ - Updated dependencies [8658a78]
8
+ - Updated dependencies [05d4a4f]
9
+ - Updated dependencies [ad05af9]
10
+ - Updated dependencies [5d53d1c]
11
+ - Updated dependencies [37cd159]
12
+ - @modern-js/utils@1.15.0
13
+
14
+ ## 1.2.16
15
+
16
+ ### Patch Changes
17
+
18
+ - 5876e63: fix: the SSG callback is called once for each baseUrl, when a user configures multiple baseUrl.
19
+ fix: 当用户配置了多个 baseUrl 时,将会为每个 baseUrl 调用一次 SSG 回调函数。
20
+ - Updated dependencies [4fc801f]
21
+ - Updated dependencies [c8614b8]
22
+ - @modern-js/utils@1.8.0
23
+
24
+ ## 1.2.15
25
+
26
+ ### Patch Changes
27
+
28
+ - d6b7383: ssg load plugin correctly
29
+ - Updated dependencies [dc4676b]
30
+ - @modern-js/utils@1.7.12
10
31
 
11
32
  ## 1.2.14
12
33
 
@@ -43,7 +43,8 @@ export default (() => ({
43
43
  entrypoints
44
44
  } = appContext;
45
45
  const {
46
- output
46
+ output,
47
+ server
47
48
  } = resolvedConfig;
48
49
  const {
49
50
  ssg,
@@ -65,7 +66,7 @@ export default (() => ({
65
66
  return;
66
67
  }
67
68
 
68
- const intermediateOptions = standardOptions(ssgOptions, entrypoints);
69
+ const intermediateOptions = standardOptions(ssgOptions, entrypoints, pageRoutes, server);
69
70
 
70
71
  if (!intermediateOptions) {
71
72
  return;
@@ -79,7 +80,7 @@ export default (() => ({
79
80
  entryPath
80
81
  } = pageRoute;
81
82
  const agreedRoutes = agreedRouteMap[entryName];
82
- let entryOptions = intermediateOptions[entryName];
83
+ let entryOptions = intermediateOptions[entryName] || intermediateOptions[pageRoute.urlPath];
83
84
 
84
85
  if (!agreedRoutes) {
85
86
  // default behavior for non-agreed route
@@ -95,7 +95,7 @@ export const writeJSONSpec = (dir, routes) => {
95
95
  });
96
96
  };
97
97
  export const replaceWithAlias = (base, filePath, alias) => path.posix.join(alias, path.posix.relative(base, filePath));
98
- export const standardOptions = (ssgOptions, entrypoints) => {
98
+ export const standardOptions = (ssgOptions, entrypoints, routes, server) => {
99
99
  if (ssgOptions === false) {
100
100
  return false;
101
101
  }
@@ -121,9 +121,21 @@ export const standardOptions = (ssgOptions, entrypoints) => {
121
121
  for (const entrypoint of entrypoints) {
122
122
  const {
123
123
  entryName
124
- } = entrypoint; // Todo may be async function
125
-
126
- intermediateOptions[entryName] = ssgOptions(entryName);
124
+ } = entrypoint; // TODO: may be async function
125
+
126
+ if (Array.isArray(server === null || server === void 0 ? void 0 : server.baseUrl)) {
127
+ for (const url of server.baseUrl) {
128
+ const matchUrl = entryName === 'main' ? url : `${url}/${entryName}`;
129
+ const route = routes.find(route => route.urlPath === matchUrl);
130
+ intermediateOptions[route === null || route === void 0 ? void 0 : route.urlPath] = ssgOptions(entryName, {
131
+ baseUrl: url
132
+ });
133
+ }
134
+ } else {
135
+ intermediateOptions[entryName] = ssgOptions(entryName, {
136
+ baseUrl: server === null || server === void 0 ? void 0 : server.baseUrl
137
+ });
138
+ }
127
139
  }
128
140
 
129
141
  return intermediateOptions;
@@ -31,7 +31,10 @@ process.on('message', async chunk => {
31
31
  appDirectory,
32
32
  plugins
33
33
  } = context;
34
- const instances = plugins.map(plugin => safetyRequire(plugin, appDirectory));
34
+ const instances = plugins.map(plugin => {
35
+ const mod = safetyRequire(plugin, appDirectory);
36
+ return mod();
37
+ });
35
38
  let modernServer = null;
36
39
 
37
40
  try {
@@ -60,7 +60,8 @@ var _default = () => ({
60
60
  entrypoints
61
61
  } = appContext;
62
62
  const {
63
- output
63
+ output,
64
+ server
64
65
  } = resolvedConfig;
65
66
  const {
66
67
  ssg,
@@ -83,7 +84,7 @@ var _default = () => ({
83
84
  return;
84
85
  }
85
86
 
86
- const intermediateOptions = (0, _util.standardOptions)(ssgOptions, entrypoints);
87
+ const intermediateOptions = (0, _util.standardOptions)(ssgOptions, entrypoints, pageRoutes, server);
87
88
 
88
89
  if (!intermediateOptions) {
89
90
  return;
@@ -97,7 +98,7 @@ var _default = () => ({
97
98
  entryPath
98
99
  } = pageRoute;
99
100
  const agreedRoutes = agreedRouteMap[entryName];
100
- let entryOptions = intermediateOptions[entryName];
101
+ let entryOptions = intermediateOptions[entryName] || intermediateOptions[pageRoute.urlPath];
101
102
 
102
103
  if (!agreedRoutes) {
103
104
  // default behavior for non-agreed route
@@ -126,7 +126,7 @@ const replaceWithAlias = (base, filePath, alias) => _path.default.posix.join(ali
126
126
 
127
127
  exports.replaceWithAlias = replaceWithAlias;
128
128
 
129
- const standardOptions = (ssgOptions, entrypoints) => {
129
+ const standardOptions = (ssgOptions, entrypoints, routes, server) => {
130
130
  if (ssgOptions === false) {
131
131
  return false;
132
132
  }
@@ -152,9 +152,21 @@ const standardOptions = (ssgOptions, entrypoints) => {
152
152
  for (const entrypoint of entrypoints) {
153
153
  const {
154
154
  entryName
155
- } = entrypoint; // Todo may be async function
156
-
157
- intermediateOptions[entryName] = ssgOptions(entryName);
155
+ } = entrypoint; // TODO: may be async function
156
+
157
+ if (Array.isArray(server === null || server === void 0 ? void 0 : server.baseUrl)) {
158
+ for (const url of server.baseUrl) {
159
+ const matchUrl = entryName === 'main' ? url : `${url}/${entryName}`;
160
+ const route = routes.find(route => route.urlPath === matchUrl);
161
+ intermediateOptions[route === null || route === void 0 ? void 0 : route.urlPath] = ssgOptions(entryName, {
162
+ baseUrl: url
163
+ });
164
+ }
165
+ } else {
166
+ intermediateOptions[entryName] = ssgOptions(entryName, {
167
+ baseUrl: server === null || server === void 0 ? void 0 : server.baseUrl
168
+ });
169
+ }
158
170
  }
159
171
 
160
172
  return intermediateOptions;
@@ -40,7 +40,10 @@ process.on('message', async chunk => {
40
40
  appDirectory,
41
41
  plugins
42
42
  } = context;
43
- const instances = plugins.map(plugin => safetyRequire(plugin, appDirectory));
43
+ const instances = plugins.map(plugin => {
44
+ const mod = safetyRequire(plugin, appDirectory);
45
+ return mod();
46
+ });
44
47
  let modernServer = null;
45
48
 
46
49
  try {
@@ -1,4 +1,5 @@
1
1
  import { ServerRoute as ModernRoute } from '@modern-js/types';
2
+ import { ServerConfig } from '@modern-js/core';
2
3
  import { SsgRoute, SSGConfig, EntryPoint, SSGMultiEntryOptions } from '../types';
3
4
  export declare function formatOutput(filename: string): string;
4
5
  export declare function formatPath(str: string): string;
@@ -8,7 +9,7 @@ export declare function getOutput(route: SsgRoute, base: string, agreed?: boolea
8
9
  export declare const readJSONSpec: (dir: string) => ModernRoute[];
9
10
  export declare const writeJSONSpec: (dir: string, routes: ModernRoute[]) => void;
10
11
  export declare const replaceWithAlias: (base: string, filePath: string, alias: string) => string;
11
- export declare const standardOptions: (ssgOptions: SSGConfig, entrypoints: EntryPoint[]) => false | SSGMultiEntryOptions;
12
+ export declare const standardOptions: (ssgOptions: SSGConfig, entrypoints: EntryPoint[], routes: ModernRoute[], server: ServerConfig) => false | SSGMultiEntryOptions;
12
13
  export declare const openRouteSSR: (routes: ModernRoute[], entries?: string[]) => {
13
14
  isSSR: boolean;
14
15
  bundle: string;
@@ -18,4 +19,5 @@ export declare const openRouteSSR: (routes: ModernRoute[], entries?: string[]) =
18
19
  isSPA?: boolean | undefined;
19
20
  isApi?: boolean | undefined;
20
21
  enableModernMode?: boolean | undefined;
22
+ responseHeaders?: Record<string, unknown> | undefined;
21
23
  }[];
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.2.15-alpha.0",
14
+ "version": "1.15.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -55,24 +55,24 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@babel/runtime": "^7.18.0",
58
- "@modern-js/utils": "^1.7.9-alpha.0",
58
+ "@modern-js/utils": "1.15.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.5.5-alpha.0",
66
- "@modern-js/prod-server": "1.1.9-alpha.0",
65
+ "@modern-js/types": "1.15.0",
66
+ "@modern-js/prod-server": "1.15.0",
67
67
  "@types/jest": "^27",
68
68
  "@types/node": "^14",
69
69
  "@types/react": "^17",
70
70
  "@types/react-dom": "^17",
71
71
  "@types/react-router": "^5.1.16",
72
72
  "@types/react-router-dom": "^5.1.8",
73
- "@modern-js/core": "1.12.2-alpha.0",
74
- "@scripts/build": "0.0.0",
75
- "@scripts/jest-config": "0.0.0",
73
+ "@modern-js/core": "1.15.0",
74
+ "@scripts/build": "1.15.0",
75
+ "@scripts/jest-config": "1.15.0",
76
76
  "react": "^17",
77
77
  "typescript": "^4",
78
78
  "jest": "^27"