@modern-js/plugin-ssg 2.35.1 → 2.37.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/dist/cjs/index.js +61 -43
- package/dist/cjs/libs/make.js +41 -22
- package/dist/cjs/libs/output.js +40 -14
- package/dist/cjs/libs/replace.js +37 -18
- package/dist/cjs/libs/util.js +67 -57
- package/dist/cjs/server/consts.js +24 -7
- package/dist/cjs/server/index.js +46 -20
- package/dist/cjs/server/prerender.js +41 -15
- package/dist/cjs/server/process.js +33 -15
- package/dist/cjs/types.js +15 -3
- package/dist/esm/index.js +8 -4
- package/dist/esm/libs/make.js +7 -3
- package/dist/esm/libs/output.js +4 -1
- package/dist/esm/libs/replace.js +6 -2
- package/dist/esm/libs/util.js +25 -12
- package/dist/esm/server/consts.js +4 -1
- package/dist/esm/server/index.js +7 -4
- package/dist/esm/server/prerender.js +4 -1
- package/dist/esm/server/process.js +1 -1
- package/dist/esm/types.js +0 -1
- package/dist/esm-node/index.js +6 -2
- package/dist/esm-node/libs/make.js +6 -2
- package/dist/esm-node/libs/output.js +4 -1
- package/dist/esm-node/libs/replace.js +6 -2
- package/dist/esm-node/libs/util.js +24 -11
- package/dist/esm-node/server/consts.js +4 -1
- package/dist/esm-node/server/index.js +4 -1
- package/dist/esm-node/server/prerender.js +4 -1
- package/dist/esm-node/types.js +0 -1
- package/package.json +7 -7
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { ROUTE_SPEC_FILE, fs, isSingleEntry, SERVER_BUNDLE_DIRECTORY } from "@modern-js/utils";
|
|
3
|
-
|
|
3
|
+
function formatOutput(filename) {
|
|
4
4
|
const outputPath = path.extname(filename) ? filename : `${filename}/index.html`;
|
|
5
5
|
return outputPath;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
function formatPath(str) {
|
|
8
8
|
let addr = str;
|
|
9
9
|
if (!addr || typeof addr !== "string") {
|
|
10
10
|
return addr;
|
|
@@ -20,10 +20,10 @@ export function formatPath(str) {
|
|
|
20
20
|
}
|
|
21
21
|
return addr;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
function isDynamicUrl(url) {
|
|
24
24
|
return url.includes(":");
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
function getUrlPrefix(route, baseUrl) {
|
|
27
27
|
let base = "";
|
|
28
28
|
if (Array.isArray(baseUrl)) {
|
|
29
29
|
const filters = baseUrl.filter((url) => route.urlPath.includes(url));
|
|
@@ -42,7 +42,7 @@ export function getUrlPrefix(route, baseUrl) {
|
|
|
42
42
|
const prefix = `${base}/${entryName}`;
|
|
43
43
|
return prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
function getOutput(route, base, agreed) {
|
|
46
46
|
const { output } = route;
|
|
47
47
|
if (output) {
|
|
48
48
|
return output;
|
|
@@ -53,13 +53,13 @@ export function getOutput(route, base, agreed) {
|
|
|
53
53
|
}
|
|
54
54
|
throw new Error(`routing must provide output when calling createPage(), check ${route.urlPath}`);
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
const readJSONSpec = (dir) => {
|
|
57
57
|
const routeJSONPath = path.join(dir, ROUTE_SPEC_FILE);
|
|
58
58
|
const routeJSON = require(routeJSONPath);
|
|
59
59
|
const { routes } = routeJSON;
|
|
60
60
|
return routes;
|
|
61
61
|
};
|
|
62
|
-
|
|
62
|
+
const writeJSONSpec = (dir, routes) => {
|
|
63
63
|
const routeJSONPath = path.join(dir, ROUTE_SPEC_FILE);
|
|
64
64
|
fs.writeJSONSync(routeJSONPath, {
|
|
65
65
|
routes
|
|
@@ -67,8 +67,8 @@ export const writeJSONSpec = (dir, routes) => {
|
|
|
67
67
|
spaces: 2
|
|
68
68
|
});
|
|
69
69
|
};
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
const replaceWithAlias = (base, filePath, alias) => path.posix.join(alias, path.posix.relative(base, filePath));
|
|
71
|
+
const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
72
72
|
if (ssgOptions === false) {
|
|
73
73
|
return false;
|
|
74
74
|
}
|
|
@@ -108,12 +108,12 @@ export const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
|
108
108
|
}
|
|
109
109
|
return false;
|
|
110
110
|
};
|
|
111
|
-
|
|
111
|
+
const openRouteSSR = (routes, entries = []) => routes.map((ssgRoute) => ({
|
|
112
112
|
...ssgRoute,
|
|
113
113
|
isSSR: entries.includes(ssgRoute.entryName),
|
|
114
114
|
bundle: `${SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
|
|
115
115
|
}));
|
|
116
|
-
|
|
116
|
+
const flattenRoutes = (routes) => {
|
|
117
117
|
const parents = [];
|
|
118
118
|
const newRoutes = [];
|
|
119
119
|
const traverseRoute = (route) => {
|
|
@@ -138,3 +138,16 @@ export const flattenRoutes = (routes) => {
|
|
|
138
138
|
routes.forEach(traverseRoute);
|
|
139
139
|
return newRoutes;
|
|
140
140
|
};
|
|
141
|
+
export {
|
|
142
|
+
flattenRoutes,
|
|
143
|
+
formatOutput,
|
|
144
|
+
formatPath,
|
|
145
|
+
getOutput,
|
|
146
|
+
getUrlPrefix,
|
|
147
|
+
isDynamicUrl,
|
|
148
|
+
openRouteSSR,
|
|
149
|
+
readJSONSpec,
|
|
150
|
+
replaceWithAlias,
|
|
151
|
+
standardOptions,
|
|
152
|
+
writeJSONSpec
|
|
153
|
+
};
|
|
@@ -3,7 +3,7 @@ import path from "path";
|
|
|
3
3
|
import { logger } from "@modern-js/utils";
|
|
4
4
|
import { openRouteSSR } from "../libs/util";
|
|
5
5
|
import { CLOSE_SIGN } from "./consts";
|
|
6
|
-
|
|
6
|
+
const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
7
7
|
var _cp_stderr, _cp_stdout;
|
|
8
8
|
const entries = ssgRoutes.map((route) => route.entryName);
|
|
9
9
|
const backup = openRouteSSR(pageRoutes, entries);
|
|
@@ -57,3 +57,6 @@ export const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, app
|
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
});
|
|
60
|
+
export {
|
|
61
|
+
createServer
|
|
62
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import EventEmitter from "events";
|
|
2
2
|
import { Readable } from "stream";
|
|
3
3
|
import httpMocks from "node-mocks-http";
|
|
4
|
-
|
|
4
|
+
const compile = (requestHandler) => (options, extend = {}) => new Promise((resolve, reject) => {
|
|
5
5
|
const req = httpMocks.createRequest({
|
|
6
6
|
...options,
|
|
7
7
|
eventEmitter: Readable
|
|
@@ -32,3 +32,6 @@ export const compile = (requestHandler) => (options, extend = {}) => new Promise
|
|
|
32
32
|
reject(e);
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
|
+
export {
|
|
36
|
+
compile
|
|
37
|
+
};
|
package/dist/esm-node/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.37.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"normalize-path": "^3.0.0",
|
|
64
64
|
"portfinder": "^1.0.28",
|
|
65
65
|
"@swc/helpers": "0.5.1",
|
|
66
|
-
"@modern-js/utils": "2.
|
|
66
|
+
"@modern-js/utils": "2.37.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"react-router-dom": ">=5.1.2"
|
|
@@ -81,11 +81,11 @@
|
|
|
81
81
|
"react-dom": "^18",
|
|
82
82
|
"react-router-dom": "^6.8.1",
|
|
83
83
|
"typescript": "^5",
|
|
84
|
-
"@modern-js/
|
|
85
|
-
"@modern-js/
|
|
86
|
-
"@modern-js/
|
|
87
|
-
"@scripts/
|
|
88
|
-
"@scripts/
|
|
84
|
+
"@modern-js/app-tools": "2.37.0",
|
|
85
|
+
"@modern-js/prod-server": "2.37.0",
|
|
86
|
+
"@modern-js/types": "2.37.0",
|
|
87
|
+
"@scripts/build": "2.37.0",
|
|
88
|
+
"@scripts/jest-config": "2.37.0"
|
|
89
89
|
},
|
|
90
90
|
"sideEffects": false,
|
|
91
91
|
"publishConfig": {
|