@modern-js/plugin-worker 0.0.0-next-1683515948739 → 0.0.0-next-1683517409685

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,18 @@
1
1
  # @modern-js/plugin-worker
2
2
 
3
- ## 0.0.0-next-1683515948739
3
+ ## 0.0.0-next-1683517409685
4
+
5
+ ### Minor Changes
6
+
7
+ - 2b159b988: feat: worker support custom server hook api
8
+ feat: worker 支持自定义 server hook api
4
9
 
5
10
  ### Patch Changes
6
11
 
7
- - @modern-js/prod-server@0.0.0-next-1683515948739
8
- - @modern-js/server-utils@0.0.0-next-1683515948739
9
- - @modern-js/utils@0.0.0-next-1683515948739
12
+ - Updated dependencies [2b159b988]
13
+ - @modern-js/prod-server@0.0.0-next-1683517409685
14
+ - @modern-js/server-utils@0.0.0-next-1683517409685
15
+ - @modern-js/utils@0.0.0-next-1683517409685
10
16
 
11
17
  ## 2.17.1
12
18
 
package/dist/cjs/index.js CHANGED
@@ -48,8 +48,13 @@ const _default = () => ({
48
48
  };
49
49
  }
50
50
  });
51
+ const WEB_APP_NAME = "index";
51
52
  const writeWorkerServerFile = (appDirectory, distDirectory) => {
52
53
  const workServerDir = _path.default.join(distDirectory, _constants.WORKER_SERVER);
54
+ const pwd = (0, _utils.isProd)() ? distDirectory : appDirectory;
55
+ const customServerDir = _path.default.join(pwd, _utils.SERVER_DIR, WEB_APP_NAME);
56
+ const isExistsCustomServer = _utils.fs.existsSync(`${customServerDir}.ts`) || _utils.fs.existsSync(`${customServerDir}.js`);
57
+ const relativePath = _path.default.relative(workServerDir, customServerDir);
53
58
  _utils.fs.removeSync(workServerDir);
54
59
  _utils.fs.mkdirSync(workServerDir);
55
60
  _utils.fs.writeFileSync(_path.default.join(workServerDir, _constants.WORKER_SERVER_ENTRY), (0, _code.worker)());
@@ -58,6 +63,10 @@ const writeWorkerServerFile = (appDirectory, distDirectory) => {
58
63
  let importStr = ``;
59
64
  let pageStr = ``;
60
65
  const routeArr = [];
66
+ if (isExistsCustomServer) {
67
+ importStr += `import * as customServer from '${relativePath}'
68
+ `;
69
+ }
61
70
  routes.forEach((route) => {
62
71
  if (route.isSSR) {
63
72
  importStr += `import { serverRender as ${route.entryName}ServerRender } from "../${route.worker}";
@@ -67,6 +76,7 @@ const writeWorkerServerFile = (appDirectory, distDirectory) => {
67
76
  importStr += `import ${route.entryName}template from "../${route.entryPath}";
68
77
  `;
69
78
  pageStr += `"${route.urlPath}": {
79
+ ${isExistsCustomServer ? "customSerer," : ""}
70
80
  entryName: "${route.entryName}",
71
81
  template: ${route.entryName}template,
72
82
  serverRender: ${route.isSSR ? `${route.entryName}ServerRender` : void 0},
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import { fs, isServiceWorker, PLUGIN_SCHEMAS, ROUTE_SPEC_FILE } from "@modern-js/utils";
2
+ import { fs, isProd, isServiceWorker, PLUGIN_SCHEMAS, ROUTE_SPEC_FILE, SERVER_DIR } from "@modern-js/utils";
3
3
  import { MANIFEST_FILE, PKG_FILE, WORKER_SERVER, WORKER_SERVER_ENTRY, WRANGLER_FILE } from "./constants";
4
4
  import { worker } from "./code";
5
5
  export default () => ({
@@ -35,8 +35,13 @@ export default () => ({
35
35
  };
36
36
  }
37
37
  });
38
+ const WEB_APP_NAME = "index";
38
39
  const writeWorkerServerFile = (appDirectory, distDirectory) => {
39
40
  const workServerDir = path.join(distDirectory, WORKER_SERVER);
41
+ const pwd = isProd() ? distDirectory : appDirectory;
42
+ const customServerDir = path.join(pwd, SERVER_DIR, WEB_APP_NAME);
43
+ const isExistsCustomServer = fs.existsSync(`${customServerDir}.ts`) || fs.existsSync(`${customServerDir}.js`);
44
+ const relativePath = path.relative(workServerDir, customServerDir);
40
45
  fs.removeSync(workServerDir);
41
46
  fs.mkdirSync(workServerDir);
42
47
  fs.writeFileSync(path.join(workServerDir, WORKER_SERVER_ENTRY), worker());
@@ -45,6 +50,10 @@ const writeWorkerServerFile = (appDirectory, distDirectory) => {
45
50
  let importStr = ``;
46
51
  let pageStr = ``;
47
52
  const routeArr = [];
53
+ if (isExistsCustomServer) {
54
+ importStr += `import * as customServer from '${relativePath}'
55
+ `;
56
+ }
48
57
  routes.forEach((route) => {
49
58
  if (route.isSSR) {
50
59
  importStr += `import { serverRender as ${route.entryName}ServerRender } from "../${route.worker}";
@@ -54,6 +63,7 @@ const writeWorkerServerFile = (appDirectory, distDirectory) => {
54
63
  importStr += `import ${route.entryName}template from "../${route.entryPath}";
55
64
  `;
56
65
  pageStr += `"${route.urlPath}": {
66
+ ${isExistsCustomServer ? "customSerer," : ""}
57
67
  entryName: "${route.entryName}",
58
68
  template: ${route.entryName}template,
59
69
  serverRender: ${route.isSSR ? `${route.entryName}ServerRender` : void 0},
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "0.0.0-next-1683515948739",
18
+ "version": "0.0.0-next-1683517409685",
19
19
  "types": "./dist/types/index.d.ts",
20
20
  "jsnext:source": "./src/index.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -43,20 +43,20 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@babel/runtime": "^7.18.0",
46
- "@modern-js/server-utils": "0.0.0-next-1683515948739",
47
- "@modern-js/utils": "0.0.0-next-1683515948739",
48
- "@modern-js/prod-server": "0.0.0-next-1683515948739"
46
+ "@modern-js/server-utils": "0.0.0-next-1683517409685",
47
+ "@modern-js/prod-server": "0.0.0-next-1683517409685",
48
+ "@modern-js/utils": "0.0.0-next-1683517409685"
49
49
  },
50
50
  "devDependencies": {
51
51
  "typescript": "^4",
52
52
  "@types/jest": "^29",
53
53
  "@types/node": "^14",
54
54
  "jest": "^29",
55
- "@modern-js/app-tools": "0.0.0-next-1683515948739",
56
- "@modern-js/core": "0.0.0-next-1683515948739",
57
- "@scripts/build": "0.0.0-next-1683515948739",
58
- "@modern-js/types": "0.0.0-next-1683515948739",
59
- "@scripts/jest-config": "0.0.0-next-1683515948739"
55
+ "@modern-js/app-tools": "0.0.0-next-1683517409685",
56
+ "@modern-js/core": "0.0.0-next-1683517409685",
57
+ "@scripts/build": "0.0.0-next-1683517409685",
58
+ "@modern-js/types": "0.0.0-next-1683517409685",
59
+ "@scripts/jest-config": "0.0.0-next-1683517409685"
60
60
  },
61
61
  "sideEffects": [
62
62
  "*.css",