@modern-js/plugin-ssg 2.15.0 → 2.16.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,5 +1,18 @@
1
1
  # @modern-js/plugin-ssg
2
2
 
3
+ ## 2.16.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 4e876ab: chore: package.json include the monorepo-relative directory
8
+
9
+ chore: 在 package.json 中声明 monorepo 的子路径
10
+
11
+ - Updated dependencies [5954330]
12
+ - Updated dependencies [7596520]
13
+ - Updated dependencies [4e876ab]
14
+ - @modern-js/utils@2.16.0
15
+
3
16
  ## 2.15.0
4
17
 
5
18
  ### Patch Changes
package/dist/cjs/index.js CHANGED
@@ -1,57 +1,44 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var src_exports = {};
29
- __export(src_exports, {
30
- default: () => src_default
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: () => _default
31
8
  });
32
- module.exports = __toCommonJS(src_exports);
33
- var import_path = __toESM(require("path"));
34
- var import_utils = require("@modern-js/utils");
35
- var import_react_router_dom = require("react-router-dom");
36
- var import_util = require("./libs/util");
37
- var import_server = require("./server");
38
- var import_output = require("./libs/output");
39
- var import_replace = require("./libs/replace");
40
- var import_make = require("./libs/make");
41
- var src_default = () => ({
9
+ const _path = /* @__PURE__ */ _interop_require_default(require("path"));
10
+ const _utils = require("@modern-js/utils");
11
+ const _reactrouterdom = require("react-router-dom");
12
+ const _util = require("./libs/util");
13
+ const _server = require("./server");
14
+ const _output = require("./libs/output");
15
+ const _replace = require("./libs/replace");
16
+ const _make = require("./libs/make");
17
+ function _interop_require_default(obj) {
18
+ return obj && obj.__esModule ? obj : {
19
+ default: obj
20
+ };
21
+ }
22
+ const _default = () => ({
42
23
  name: "@modern-js/plugin-ssg",
43
- pre: ["@modern-js/plugin-server", "@modern-js/plugin-bff"],
24
+ pre: [
25
+ "@modern-js/plugin-server",
26
+ "@modern-js/plugin-bff"
27
+ ],
44
28
  setup: (api) => {
45
29
  const agreedRouteMap = {};
46
30
  return {
47
31
  validateSchema() {
48
- return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-ssg"];
32
+ return _utils.PLUGIN_SCHEMAS["@modern-js/plugin-ssg"];
49
33
  },
50
34
  modifyFileSystemRoutes({ entrypoint, routes }) {
51
35
  const { entryName } = entrypoint;
52
- const flattedRoutes = (0, import_util.flattenRoutes)(routes);
36
+ const flattedRoutes = (0, _util.flattenRoutes)(routes);
53
37
  agreedRouteMap[entryName] = flattedRoutes;
54
- return { entrypoint, routes };
38
+ return {
39
+ entrypoint,
40
+ routes
41
+ };
55
42
  },
56
43
  async afterBuild() {
57
44
  const resolvedConfig = api.useResolvedConfigContext();
@@ -60,19 +47,14 @@ var src_default = () => ({
60
47
  const { output, server } = resolvedConfig;
61
48
  const { ssg, distPath: { root: outputPath } = {} } = output;
62
49
  const ssgOptions = (Array.isArray(ssg) ? ssg.pop() : ssg) || true;
63
- const buildDir = import_path.default.join(appDirectory, outputPath);
64
- const routes = (0, import_util.readJSONSpec)(buildDir);
50
+ const buildDir = _path.default.join(appDirectory, outputPath);
51
+ const routes = (0, _util.readJSONSpec)(buildDir);
65
52
  const pageRoutes = routes.filter((route) => !route.isApi);
66
53
  const apiRoutes = routes.filter((route) => route.isApi);
67
54
  if (pageRoutes.length === 0) {
68
55
  return;
69
56
  }
70
- const intermediateOptions = (0, import_util.standardOptions)(
71
- ssgOptions,
72
- entrypoints,
73
- pageRoutes,
74
- server
75
- );
57
+ const intermediateOptions = (0, _util.standardOptions)(ssgOptions, entrypoints, pageRoutes, server);
76
58
  if (!intermediateOptions) {
77
59
  return;
78
60
  }
@@ -86,11 +68,14 @@ var src_default = () => ({
86
68
  return;
87
69
  }
88
70
  if (entryOptions === true) {
89
- ssgRoutes.push({ ...pageRoute, output: entryPath });
71
+ ssgRoutes.push({
72
+ ...pageRoute,
73
+ output: entryPath
74
+ });
90
75
  } else if (entryOptions.routes && entryOptions.routes.length > 0) {
91
76
  const { routes: enrtyRoutes, headers } = entryOptions;
92
77
  enrtyRoutes.forEach((route) => {
93
- ssgRoutes.push((0, import_make.makeRoute)(pageRoute, route, headers));
78
+ ssgRoutes.push((0, _make.makeRoute)(pageRoute, route, headers));
94
79
  });
95
80
  }
96
81
  } else {
@@ -98,35 +83,32 @@ var src_default = () => ({
98
83
  return;
99
84
  }
100
85
  if (entryOptions === true) {
101
- entryOptions = { preventDefault: [], routes: [], headers: {} };
86
+ entryOptions = {
87
+ preventDefault: [],
88
+ routes: [],
89
+ headers: {}
90
+ };
102
91
  }
103
- const {
104
- preventDefault = [],
105
- routes: userRoutes = [],
106
- headers
107
- } = entryOptions;
92
+ const { preventDefault = [], routes: userRoutes = [], headers } = entryOptions;
108
93
  if (userRoutes.length > 0) {
109
94
  userRoutes.forEach((route) => {
110
95
  if (typeof route === "string") {
111
- ssgRoutes.push((0, import_make.makeRoute)(pageRoute, route, headers));
96
+ ssgRoutes.push((0, _make.makeRoute)(pageRoute, route, headers));
112
97
  } else if (Array.isArray(route.params)) {
113
98
  route.params.forEach((param) => {
114
- ssgRoutes.push(
115
- (0, import_make.makeRoute)(
116
- pageRoute,
117
- { ...route, url: (0, import_react_router_dom.generatePath)(route.url, param) },
118
- headers
119
- )
120
- );
99
+ ssgRoutes.push((0, _make.makeRoute)(pageRoute, {
100
+ ...route,
101
+ url: (0, _reactrouterdom.generatePath)(route.url, param)
102
+ }, headers));
121
103
  });
122
104
  } else {
123
- ssgRoutes.push((0, import_make.makeRoute)(pageRoute, route, headers));
105
+ ssgRoutes.push((0, _make.makeRoute)(pageRoute, route, headers));
124
106
  }
125
107
  });
126
108
  } else {
127
109
  agreedRoutes.filter((route) => !preventDefault.includes(route.path)).forEach((route) => {
128
- if (!(0, import_util.isDynamicUrl)(route.path)) {
129
- ssgRoutes.push((0, import_make.makeRoute)(pageRoute, route.path, headers));
110
+ if (!(0, _util.isDynamicUrl)(route.path)) {
111
+ ssgRoutes.push((0, _make.makeRoute)(pageRoute, route.path, headers));
130
112
  }
131
113
  });
132
114
  }
@@ -137,36 +119,21 @@ var src_default = () => ({
137
119
  }
138
120
  ssgRoutes.forEach((ssgRoute) => {
139
121
  if (ssgRoute.isSSR) {
140
- const isOriginRoute = pageRoutes.some(
141
- (pageRoute) => pageRoute.urlPath === ssgRoute.urlPath && pageRoute.entryName === ssgRoute.entryName
142
- );
122
+ const isOriginRoute = pageRoutes.some((pageRoute) => pageRoute.urlPath === ssgRoute.urlPath && pageRoute.entryName === ssgRoute.entryName);
143
123
  if (isOriginRoute) {
144
- throw new Error(
145
- `ssg can not using with ssr,url - ${ssgRoute.urlPath}, entry - ${ssgRoute.entryName} `
146
- );
124
+ throw new Error(`ssg can not using with ssr,url - ${ssgRoute.urlPath}, entry - ${ssgRoute.entryName} `);
147
125
  }
148
- import_utils.logger.warn(
149
- `new ssg route ${ssgRoute.urlPath} is using ssr now,maybe from parent route ${ssgRoute.entryName},close ssr`
150
- );
126
+ _utils.logger.warn(`new ssg route ${ssgRoute.urlPath} is using ssr now,maybe from parent route ${ssgRoute.entryName},close ssr`);
151
127
  }
152
128
  ssgRoute.isSSR = false;
153
- ssgRoute.output = (0, import_util.formatOutput)(ssgRoute.output);
129
+ ssgRoute.output = (0, _util.formatOutput)(ssgRoute.output);
154
130
  });
155
- const htmlAry = await (0, import_server.createServer)(
156
- api,
157
- ssgRoutes,
158
- pageRoutes,
159
- apiRoutes,
160
- resolvedConfig,
161
- appDirectory
162
- );
163
- (0, import_output.writeHtmlFile)(htmlAry, ssgRoutes, buildDir);
164
- (0, import_replace.replaceRoute)(ssgRoutes, pageRoutes);
165
- (0, import_util.writeJSONSpec)(buildDir, pageRoutes.concat(apiRoutes));
166
- import_utils.logger.info("ssg Compiled successfully");
131
+ const htmlAry = await (0, _server.createServer)(api, ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory);
132
+ (0, _output.writeHtmlFile)(htmlAry, ssgRoutes, buildDir);
133
+ (0, _replace.replaceRoute)(ssgRoutes, pageRoutes);
134
+ (0, _util.writeJSONSpec)(buildDir, pageRoutes.concat(apiRoutes));
135
+ _utils.logger.info("ssg Compiled successfully");
167
136
  }
168
137
  };
169
138
  }
170
139
  });
171
- // Annotate the CommonJS export names for ESM import in node:
172
- 0 && (module.exports = {});
@@ -1,67 +1,53 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
8
6
  for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var make_exports = {};
29
- __export(make_exports, {
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
30
13
  makeRender: () => makeRender,
31
14
  makeRoute: () => makeRoute
32
15
  });
33
- module.exports = __toCommonJS(make_exports);
34
- var import_path = __toESM(require("path"));
35
- var import_normalize_path = __toESM(require("normalize-path"));
16
+ const _path = /* @__PURE__ */ _interop_require_default(require("path"));
17
+ const _normalizepath = /* @__PURE__ */ _interop_require_default(require("normalize-path"));
18
+ function _interop_require_default(obj) {
19
+ return obj && obj.__esModule ? obj : {
20
+ default: obj
21
+ };
22
+ }
36
23
  function makeRender(ssgRoutes, render, port) {
37
- return ssgRoutes.map(
38
- (ssgRoute) => render({
39
- url: ssgRoute.urlPath,
40
- headers: { host: `localhost:${port}`, ...ssgRoute.headers },
41
- connection: {}
42
- })
43
- );
24
+ return ssgRoutes.map((ssgRoute) => render({
25
+ url: ssgRoute.urlPath,
26
+ headers: {
27
+ host: `localhost:${port}`,
28
+ ...ssgRoute.headers
29
+ },
30
+ connection: {}
31
+ }));
44
32
  }
45
33
  function makeRoute(baseRoute, route, headers = {}) {
46
34
  const { urlPath, entryPath } = baseRoute;
47
35
  if (typeof route === "string") {
48
36
  return {
49
37
  ...baseRoute,
50
- urlPath: (0, import_normalize_path.default)(`${urlPath}${route}`) || "/",
38
+ urlPath: (0, _normalizepath.default)(`${urlPath}${route}`) || "/",
51
39
  headers,
52
- output: import_path.default.join(entryPath, `..${route === "/" ? "" : route}`)
40
+ output: _path.default.join(entryPath, `..${route === "/" ? "" : route}`)
53
41
  };
54
42
  } else {
55
43
  return {
56
44
  ...baseRoute,
57
- urlPath: (0, import_normalize_path.default)(`${urlPath}${route.url}`) || "/",
58
- headers: { ...headers, ...route.headers },
59
- output: route.output ? import_path.default.normalize(route.output) : import_path.default.join(entryPath, `..${route.url === "/" ? "" : route.url}`)
45
+ urlPath: (0, _normalizepath.default)(`${urlPath}${route.url}`) || "/",
46
+ headers: {
47
+ ...headers,
48
+ ...route.headers
49
+ },
50
+ output: route.output ? _path.default.normalize(route.output) : _path.default.join(entryPath, `..${route.url === "/" ? "" : route.url}`)
60
51
  };
61
52
  }
62
53
  }
63
- // Annotate the CommonJS export names for ESM import in node:
64
- 0 && (module.exports = {
65
- makeRender,
66
- makeRoute
67
- });
@@ -1,48 +1,25 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var output_exports = {};
29
- __export(output_exports, {
30
- writeHtmlFile: () => writeHtmlFile
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
31
4
  });
32
- module.exports = __toCommonJS(output_exports);
33
- var import_path = __toESM(require("path"));
34
- var import_utils = require("@modern-js/utils");
5
+ Object.defineProperty(exports, "writeHtmlFile", {
6
+ enumerable: true,
7
+ get: () => writeHtmlFile
8
+ });
9
+ const _path = /* @__PURE__ */ _interop_require_default(require("path"));
10
+ const _utils = require("@modern-js/utils");
11
+ function _interop_require_default(obj) {
12
+ return obj && obj.__esModule ? obj : {
13
+ default: obj
14
+ };
15
+ }
35
16
  function writeHtmlFile(htmlAry, ssgRoutes, baseDir) {
36
17
  htmlAry.forEach((html, index) => {
37
18
  const ssgRoute = ssgRoutes[index];
38
- const filepath = import_path.default.join(baseDir, ssgRoute.output);
39
- if (!import_utils.fs.existsSync(import_path.default.dirname(filepath))) {
40
- import_utils.fs.ensureDirSync(import_path.default.dirname(filepath));
19
+ const filepath = _path.default.join(baseDir, ssgRoute.output);
20
+ if (!_utils.fs.existsSync(_path.default.dirname(filepath))) {
21
+ _utils.fs.ensureDirSync(_path.default.dirname(filepath));
41
22
  }
42
- import_utils.fs.writeFileSync(filepath, html);
23
+ _utils.fs.writeFileSync(filepath, html);
43
24
  });
44
25
  }
45
- // Annotate the CommonJS export names for ESM import in node:
46
- 0 && (module.exports = {
47
- writeHtmlFile
48
- });
@@ -1,40 +1,27 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
8
6
  for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var replace_exports = {};
29
- __export(replace_exports, {
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
30
13
  exist: () => exist,
31
14
  replaceRoute: () => replaceRoute
32
15
  });
33
- module.exports = __toCommonJS(replace_exports);
34
- var import_normalize_path = __toESM(require("normalize-path"));
16
+ const _normalizepath = /* @__PURE__ */ _interop_require_default(require("normalize-path"));
17
+ function _interop_require_default(obj) {
18
+ return obj && obj.__esModule ? obj : {
19
+ default: obj
20
+ };
21
+ }
35
22
  function exist(route, pageRoutes) {
36
23
  return pageRoutes.slice().findIndex((pageRoute) => {
37
- const urlEqual = (0, import_normalize_path.default)(pageRoute.urlPath) === (0, import_normalize_path.default)(route.urlPath);
24
+ const urlEqual = (0, _normalizepath.default)(pageRoute.urlPath) === (0, _normalizepath.default)(route.urlPath);
38
25
  const entryEqual = pageRoute.entryName === route.entryName;
39
26
  if (urlEqual && entryEqual) {
40
27
  return true;
@@ -45,16 +32,17 @@ function exist(route, pageRoutes) {
45
32
  function replaceRoute(ssgRoutes, pageRoutes) {
46
33
  const cleanSsgRoutes = ssgRoutes.map((ssgRoute) => {
47
34
  const { output, headers, ...cleanSsgRoute } = ssgRoute;
48
- return Object.assign(
49
- cleanSsgRoute,
50
- output ? { entryPath: output } : {}
51
- );
35
+ return Object.assign(cleanSsgRoute, output ? {
36
+ entryPath: output
37
+ } : {});
52
38
  });
53
39
  const freshRoutes = [];
54
40
  cleanSsgRoutes.forEach((ssgRoute) => {
55
41
  const index = exist(ssgRoute, pageRoutes);
56
42
  if (index < 0) {
57
- freshRoutes.push({ ...ssgRoute });
43
+ freshRoutes.push({
44
+ ...ssgRoute
45
+ });
58
46
  } else {
59
47
  pageRoutes[index].entryPath = ssgRoute.entryPath;
60
48
  }
@@ -62,8 +50,3 @@ function replaceRoute(ssgRoutes, pageRoutes) {
62
50
  pageRoutes.push(...freshRoutes);
63
51
  return pageRoutes;
64
52
  }
65
- // Annotate the CommonJS export names for ESM import in node:
66
- 0 && (module.exports = {
67
- exist,
68
- replaceRoute
69
- });