@modern-js/plugin-ssg 2.35.0 → 2.36.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.
@@ -1,5 +1,5 @@
1
1
  import normalize from "normalize-path";
2
- export function exist(route, pageRoutes) {
2
+ function exist(route, pageRoutes) {
3
3
  return pageRoutes.slice().findIndex((pageRoute) => {
4
4
  const urlEqual = normalize(pageRoute.urlPath) === normalize(route.urlPath);
5
5
  const entryEqual = pageRoute.entryName === route.entryName;
@@ -9,7 +9,7 @@ export function exist(route, pageRoutes) {
9
9
  return false;
10
10
  });
11
11
  }
12
- export function replaceRoute(ssgRoutes, pageRoutes) {
12
+ function replaceRoute(ssgRoutes, pageRoutes) {
13
13
  const cleanSsgRoutes = ssgRoutes.map((ssgRoute) => {
14
14
  const { output, headers, ...cleanSsgRoute } = ssgRoute;
15
15
  return Object.assign(cleanSsgRoute, output ? {
@@ -30,3 +30,7 @@ export function replaceRoute(ssgRoutes, pageRoutes) {
30
30
  pageRoutes.push(...freshRoutes);
31
31
  return pageRoutes;
32
32
  }
33
+ export {
34
+ exist,
35
+ replaceRoute
36
+ };
@@ -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
- export function formatOutput(filename) {
3
+ function formatOutput(filename) {
4
4
  const outputPath = path.extname(filename) ? filename : `${filename}/index.html`;
5
5
  return outputPath;
6
6
  }
7
- export function formatPath(str) {
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
- export function isDynamicUrl(url) {
23
+ function isDynamicUrl(url) {
24
24
  return url.includes(":");
25
25
  }
26
- export function getUrlPrefix(route, baseUrl) {
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
- export function getOutput(route, base, agreed) {
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
- export const readJSONSpec = (dir) => {
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
- export const writeJSONSpec = (dir, routes) => {
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
- export const replaceWithAlias = (base, filePath, alias) => path.posix.join(alias, path.posix.relative(base, filePath));
71
- export const standardOptions = (ssgOptions, entrypoints, routes, server) => {
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
  }
@@ -89,21 +89,18 @@ export const standardOptions = (ssgOptions, entrypoints, routes, server) => {
89
89
  } else if (typeof ssgOptions === "function") {
90
90
  const intermediateOptions = {};
91
91
  for (const entrypoint of entrypoints) {
92
- var _server;
93
92
  const { entryName } = entrypoint;
94
- if (Array.isArray((_server = server) === null || _server === void 0 ? void 0 : _server.baseUrl)) {
93
+ if (Array.isArray(server === null || server === void 0 ? void 0 : server.baseUrl)) {
95
94
  for (const url of server.baseUrl) {
96
- var _route;
97
95
  const matchUrl = entryName === "main" ? url : `${url}/${entryName}`;
98
96
  const route = routes.find((route2) => route2.urlPath === matchUrl);
99
- intermediateOptions[(_route = route) === null || _route === void 0 ? void 0 : _route.urlPath] = ssgOptions(entryName, {
97
+ intermediateOptions[route === null || route === void 0 ? void 0 : route.urlPath] = ssgOptions(entryName, {
100
98
  baseUrl: url
101
99
  });
102
100
  }
103
101
  } else {
104
- var _server1;
105
102
  intermediateOptions[entryName] = ssgOptions(entryName, {
106
- baseUrl: (_server1 = server) === null || _server1 === void 0 ? void 0 : _server1.baseUrl
103
+ baseUrl: server === null || server === void 0 ? void 0 : server.baseUrl
107
104
  });
108
105
  }
109
106
  }
@@ -111,12 +108,12 @@ export const standardOptions = (ssgOptions, entrypoints, routes, server) => {
111
108
  }
112
109
  return false;
113
110
  };
114
- export const openRouteSSR = (routes, entries = []) => routes.map((ssgRoute) => ({
111
+ const openRouteSSR = (routes, entries = []) => routes.map((ssgRoute) => ({
115
112
  ...ssgRoute,
116
113
  isSSR: entries.includes(ssgRoute.entryName),
117
114
  bundle: `${SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
118
115
  }));
119
- export const flattenRoutes = (routes) => {
116
+ const flattenRoutes = (routes) => {
120
117
  const parents = [];
121
118
  const newRoutes = [];
122
119
  const traverseRoute = (route) => {
@@ -141,3 +138,16 @@ export const flattenRoutes = (routes) => {
141
138
  routes.forEach(traverseRoute);
142
139
  return newRoutes;
143
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
+ };
@@ -1 +1,4 @@
1
- export const CLOSE_SIGN = "modern_close_server";
1
+ const CLOSE_SIGN = "modern_close_server";
2
+ export {
3
+ CLOSE_SIGN
4
+ };
@@ -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
- export const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
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
- export const compile = (requestHandler) => (options, extend = {}) => new Promise((resolve, reject) => {
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
+ };
@@ -39,8 +39,7 @@ process.on("message", async (chunk) => {
39
39
  modernServer.close();
40
40
  });
41
41
  } catch (e) {
42
- var _modernServer;
43
- (_modernServer = modernServer) === null || _modernServer === void 0 ? void 0 : _modernServer.close();
42
+ modernServer === null || modernServer === void 0 ? void 0 : modernServer.close();
44
43
  process.stderr.write(e instanceof Error ? e.stack : e.toString());
45
44
  }
46
45
  });
@@ -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.35.0",
18
+ "version": "2.36.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.35.0"
66
+ "@modern-js/utils": "2.36.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/types": "2.35.0",
85
- "@modern-js/prod-server": "2.35.0",
86
- "@modern-js/app-tools": "2.35.0",
87
- "@scripts/build": "2.35.0",
88
- "@scripts/jest-config": "2.35.0"
84
+ "@modern-js/app-tools": "2.36.0",
85
+ "@modern-js/prod-server": "2.36.0",
86
+ "@modern-js/types": "2.36.0",
87
+ "@scripts/build": "2.36.0",
88
+ "@scripts/jest-config": "2.36.0"
89
89
  },
90
90
  "sideEffects": false,
91
91
  "publishConfig": {