@modern-js/plugin-ssg 2.0.0-beta.0 → 2.0.0-beta.2

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,23 +1,16 @@
1
1
  "use strict";
2
2
 
3
3
  var _prodServer = _interopRequireDefault(require("@modern-js/prod-server"));
4
-
5
4
  var _portfinder = _interopRequireDefault(require("portfinder"));
6
-
7
5
  var _make = require("../libs/make");
8
-
9
6
  var _prerender = require("./prerender");
10
-
11
7
  var _consts = require("./consts");
12
-
13
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
-
15
9
  process.on('message', async chunk => {
16
10
  if (chunk === _consts.CLOSE_SIGN) {
17
11
  // eslint-disable-next-line no-process-exit
18
12
  process.exit();
19
13
  }
20
-
21
14
  const context = JSON.parse(chunk);
22
15
  const {
23
16
  routes,
@@ -27,12 +20,12 @@ process.on('message', async chunk => {
27
20
  plugins
28
21
  } = context;
29
22
  let modernServer = null;
30
-
31
23
  try {
32
24
  const {
33
25
  server: serverOptions
34
- } = options; // start server in default port
26
+ } = options;
35
27
 
28
+ // start server in default port
36
29
  const defaultPort = Number(process.env.PORT) || serverOptions.port;
37
30
  _portfinder.default.basePort = defaultPort;
38
31
  const port = await _portfinder.default.getPortPromise();
@@ -42,21 +35,22 @@ process.on('message', async chunk => {
42
35
  routes,
43
36
  staticGenerate: true,
44
37
  internalPlugins: plugins
45
- }); // listen just for bff request in ssr page
38
+ });
46
39
 
40
+ // listen just for bff request in ssr page
47
41
  modernServer.listen(port, async err => {
48
42
  if (err) {
49
43
  throw err;
50
44
  }
51
-
52
45
  if (!modernServer) {
53
46
  return;
54
- } // get server handler, render to ssr
55
-
47
+ }
56
48
 
49
+ // get server handler, render to ssr
57
50
  const render = (0, _prerender.compile)(modernServer.getRequestHandler());
58
- const renderPromiseAry = (0, _make.makeRender)(renderRoutes, render, port); // eslint-disable-next-line promise/no-promise-in-callback
51
+ const renderPromiseAry = (0, _make.makeRender)(renderRoutes, render, port);
59
52
 
53
+ // eslint-disable-next-line promise/no-promise-in-callback
60
54
  const htmlAry = await Promise.all(renderPromiseAry);
61
55
  htmlAry.forEach(html => {
62
56
  process.send(html);
@@ -66,7 +60,6 @@ process.on('message', async chunk => {
66
60
  });
67
61
  } catch (e) {
68
62
  var _modernServer;
69
-
70
63
  (_modernServer = modernServer) === null || _modernServer === void 0 ? void 0 : _modernServer.close();
71
64
  throw e;
72
65
  }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -1,5 +1,3 @@
1
- import type { CliPlugin } from '@modern-js/core';
2
-
3
- declare const _default: () => CliPlugin;
4
-
1
+ import type { AppTools, CliPlugin } from '@modern-js/app-tools';
2
+ declare const _default: () => CliPlugin<AppTools>;
5
3
  export default _default;
@@ -1,5 +1,5 @@
1
1
  import { ServerRoute as ModernRoute } from '@modern-js/types';
2
- import { ServerConfig } from '@modern-js/core';
2
+ import { ServerUserConfig } from '@modern-js/app-tools';
3
3
  import { SsgRoute, SSGConfig, EntryPoint, SSGMultiEntryOptions, AgreedRoute } from '../types';
4
4
  export declare function formatOutput(filename: string): string;
5
5
  export declare function formatPath(str: string): string;
@@ -9,7 +9,7 @@ export declare function getOutput(route: SsgRoute, base: string, agreed?: boolea
9
9
  export declare const readJSONSpec: (dir: string) => ModernRoute[];
10
10
  export declare const writeJSONSpec: (dir: string, routes: ModernRoute[]) => void;
11
11
  export declare const replaceWithAlias: (base: string, filePath: string, alias: string) => string;
12
- export declare const standardOptions: (ssgOptions: SSGConfig, entrypoints: EntryPoint[], routes: ModernRoute[], server: ServerConfig) => false | SSGMultiEntryOptions;
12
+ export declare const standardOptions: (ssgOptions: SSGConfig, entrypoints: EntryPoint[], routes: ModernRoute[], server: ServerUserConfig) => false | SSGMultiEntryOptions;
13
13
  export declare const openRouteSSR: (routes: ModernRoute[], entries?: string[]) => {
14
14
  isSSR: boolean;
15
15
  bundle: string;
@@ -1,4 +1,4 @@
1
- import type { NormalizedConfig, PluginAPI } from '@modern-js/core';
1
+ import type { AppNormalizedConfig, PluginAPI, AppTools } from '@modern-js/app-tools';
2
2
  import { ServerRoute as ModernRoute } from '@modern-js/types';
3
3
  import { SsgRoute } from '../types';
4
- export declare const createServer: (api: PluginAPI, ssgRoutes: SsgRoute[], pageRoutes: ModernRoute[], apiRoutes: ModernRoute[], options: NormalizedConfig, appDirectory: string) => Promise<string[]>;
4
+ export declare const createServer: (api: PluginAPI<AppTools>, ssgRoutes: SsgRoute[], pageRoutes: ModernRoute[], apiRoutes: ModernRoute[], options: AppNormalizedConfig, appDirectory: string) => Promise<string[]>;
@@ -1,5 +1,5 @@
1
1
  import type { ServerRoute as ModernRoute } from '@modern-js/types';
2
- import type { SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions } from '@modern-js/core';
2
+ import { SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions } from '@modern-js/app-tools';
3
3
  export type { SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions };
4
4
  export declare type AgreedRoute = {
5
5
  path?: string;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.0.0-beta.0",
14
+ "version": "2.0.0-beta.2",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -55,10 +55,10 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@babel/runtime": "^7.18.0",
58
- "@modern-js/utils": "2.0.0-beta.0",
59
58
  "node-mocks-http": "^1.10.1",
60
59
  "normalize-path": "^3.0.0",
61
- "portfinder": "^1.0.28"
60
+ "portfinder": "^1.0.28",
61
+ "@modern-js/utils": "2.0.0-beta.2"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "react-router-dom": ">=5.1.2"
@@ -69,17 +69,17 @@
69
69
  }
70
70
  },
71
71
  "devDependencies": {
72
- "@modern-js/types": "2.0.0-beta.0",
73
- "@modern-js/prod-server": "2.0.0-beta.0",
74
72
  "@types/jest": "^27",
75
73
  "@types/node": "^14",
76
- "@modern-js/core": "2.0.0-beta.0",
77
- "@scripts/build": "2.0.0-beta.0",
78
- "@scripts/jest-config": "2.0.0-beta.0",
79
74
  "react-router-dom": "^6.4.2",
80
75
  "react": "^18",
81
76
  "typescript": "^4",
82
- "jest": "^27"
77
+ "jest": "^27",
78
+ "@modern-js/types": "2.0.0-beta.2",
79
+ "@modern-js/prod-server": "2.0.0-beta.2",
80
+ "@scripts/build": "2.0.0-beta.2",
81
+ "@modern-js/app-tools": "2.0.0-beta.2",
82
+ "@scripts/jest-config": "2.0.0-beta.2"
83
83
  },
84
84
  "sideEffects": false,
85
85
  "modernConfig": {
@@ -92,9 +92,9 @@
92
92
  "access": "public"
93
93
  },
94
94
  "scripts": {
95
- "new": "modern new",
96
- "build": "modern build",
97
- "dev": "modern build --watch",
95
+ "new": "modern-lib new",
96
+ "build": "modern-lib build",
97
+ "dev": "modern-lib build --watch",
98
98
  "test": "jest --passWithNoTests"
99
99
  }
100
100
  }