@modern-js/plugin-worker 0.0.0-next-1683623792316 → 0.0.0-next-1683641210643

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,18 +1,20 @@
1
1
  # @modern-js/plugin-worker
2
2
 
3
- ## 0.0.0-next-1683623792316
3
+ ## 0.0.0-next-1683641210643
4
4
 
5
- ### Minor Changes
5
+ ### Patch Changes
6
+
7
+ - @modern-js/prod-server@0.0.0-next-1683641210643
8
+ - @modern-js/server-utils@0.0.0-next-1683641210643
9
+ - @modern-js/utils@0.0.0-next-1683641210643
6
10
 
7
- - 2b159b988: feat: worker support custom server hook api
8
- feat: worker 支持自定义 server hook api
11
+ ## 2.18.0
9
12
 
10
13
  ### Patch Changes
11
14
 
12
- - Updated dependencies [2b159b988]
13
- - @modern-js/prod-server@0.0.0-next-1683623792316
14
- - @modern-js/server-utils@0.0.0-next-1683623792316
15
- - @modern-js/utils@0.0.0-next-1683623792316
15
+ - @modern-js/prod-server@2.18.0
16
+ - @modern-js/server-utils@2.18.0
17
+ - @modern-js/utils@2.18.0
16
18
 
17
19
  ## 2.17.1
18
20
 
package/dist/cjs/code.js CHANGED
@@ -19,15 +19,16 @@ async function handleRequest(request) {
19
19
  url: request.url,
20
20
  },
21
21
  url: handleUrl(request.url),
22
+ body: null,
22
23
  loadableStats,
23
24
  routeManifest,
24
25
  };
25
26
  const handler = createHandler(manifest);
26
- const {body, status, headers = new Headers()} = await handler(context);
27
- headers.set('content-type', 'text/html;charset=UTF-8');
28
- return new Response(body, {
29
- status,
30
- headers,
27
+ await handler(context);
28
+ return new Response(context.body, {
29
+ headers: {
30
+ 'content-type': 'text/html;charset=UTF-8',
31
+ },
31
32
  });
32
33
  }
33
34
 
@@ -14,14 +14,10 @@ _export(exports, {
14
14
  WORKER_SERVER_ENTRY: () => WORKER_SERVER_ENTRY,
15
15
  MANIFEST_FILE: () => MANIFEST_FILE,
16
16
  PKG_FILE: () => PKG_FILE,
17
- WRANGLER_FILE: () => WRANGLER_FILE,
18
- WEB_APP_NAME: () => WEB_APP_NAME,
19
- CUSTOM_SERVER: () => CUSTOM_SERVER
17
+ WRANGLER_FILE: () => WRANGLER_FILE
20
18
  });
21
19
  const WORKER_SERVER = "worker-server";
22
20
  const WORKER_SERVER_ENTRY = "index.js";
23
21
  const MANIFEST_FILE = "manifest.js";
24
22
  const PKG_FILE = "package.json";
25
23
  const WRANGLER_FILE = "wrangler.toml";
26
- const WEB_APP_NAME = "index";
27
- const CUSTOM_SERVER = "customServer";
package/dist/cjs/index.js CHANGED
@@ -15,50 +15,41 @@ function _interop_require_default(obj) {
15
15
  default: obj
16
16
  };
17
17
  }
18
- const _default = () => {
19
- return {
20
- name: "@modern-js/plugin-worker",
21
- setup: (ctx) => {
22
- return {
23
- async config() {
24
- return {
25
- output: {
26
- disableNodePolyfill: false
27
- }
28
- };
29
- },
30
- validateSchema() {
31
- return _utils.PLUGIN_SCHEMAS["@modern-js/plugin-worker"];
32
- },
33
- async afterDev() {
34
- var _configContext_deploy_worker;
35
- const { appDirectory, distDirectory } = ctx.useAppContext();
36
- const configContext = ctx.useResolvedConfigContext();
37
- if (!(0, _utils.isServiceWorker)(configContext)) {
38
- return;
18
+ const _default = () => ({
19
+ name: "@modern-js/plugin-worker",
20
+ setup: (ctx) => {
21
+ return {
22
+ async config() {
23
+ return {
24
+ output: {
25
+ disableNodePolyfill: false
39
26
  }
40
- const enableWorkerInWeb = configContext.deploy.enableWorker || ((_configContext_deploy_worker = configContext.deploy.worker) === null || _configContext_deploy_worker === void 0 ? void 0 : _configContext_deploy_worker.web);
41
- writeWorkerServerFile(appDirectory, distDirectory, enableWorkerInWeb);
42
- },
43
- async afterBuild() {
44
- var _configContext_deploy_worker;
45
- const { appDirectory, distDirectory } = ctx.useAppContext();
46
- const configContext = ctx.useResolvedConfigContext();
47
- if (!(0, _utils.isServiceWorker)(configContext)) {
48
- return;
49
- }
50
- const enableWorkerInWeb = configContext.deploy.enableWorker || ((_configContext_deploy_worker = configContext.deploy.worker) === null || _configContext_deploy_worker === void 0 ? void 0 : _configContext_deploy_worker.web);
51
- writeWorkerServerFile(appDirectory, distDirectory, enableWorkerInWeb);
27
+ };
28
+ },
29
+ validateSchema() {
30
+ return _utils.PLUGIN_SCHEMAS["@modern-js/plugin-worker"];
31
+ },
32
+ async afterDev() {
33
+ const { appDirectory, distDirectory } = ctx.useAppContext();
34
+ const configContext = ctx.useResolvedConfigContext();
35
+ if (!(0, _utils.isServiceWorker)(configContext)) {
36
+ return;
52
37
  }
53
- };
54
- }
55
- };
56
- };
57
- const writeWorkerServerFile = (appDirectory, distDirectory, enableWorkerInWeb) => {
38
+ writeWorkerServerFile(appDirectory, distDirectory);
39
+ },
40
+ async afterBuild() {
41
+ const { appDirectory, distDirectory } = ctx.useAppContext();
42
+ const configContext = ctx.useResolvedConfigContext();
43
+ if (!(0, _utils.isServiceWorker)(configContext)) {
44
+ return;
45
+ }
46
+ writeWorkerServerFile(appDirectory, distDirectory);
47
+ }
48
+ };
49
+ }
50
+ });
51
+ const writeWorkerServerFile = (appDirectory, distDirectory) => {
58
52
  const workServerDir = _path.default.join(distDirectory, _constants.WORKER_SERVER);
59
- const customServerDir = _path.default.join(appDirectory, _utils.SERVER_DIR, _constants.WEB_APP_NAME);
60
- const isExistsCustomServer = _utils.fs.existsSync(`${customServerDir}.ts`) || _utils.fs.existsSync(`${customServerDir}.js`);
61
- const relativePath = _path.default.relative(workServerDir, customServerDir);
62
53
  _utils.fs.removeSync(workServerDir);
63
54
  _utils.fs.mkdirSync(workServerDir);
64
55
  _utils.fs.writeFileSync(_path.default.join(workServerDir, _constants.WORKER_SERVER_ENTRY), (0, _code.worker)());
@@ -67,10 +58,6 @@ const writeWorkerServerFile = (appDirectory, distDirectory, enableWorkerInWeb) =
67
58
  let importStr = ``;
68
59
  let pageStr = ``;
69
60
  const routeArr = [];
70
- if (isExistsCustomServer && !enableWorkerInWeb) {
71
- importStr += `import * as ${_constants.CUSTOM_SERVER} from '${relativePath}'
72
- `;
73
- }
74
61
  routes.forEach((route) => {
75
62
  if (route.isSSR) {
76
63
  importStr += `import { serverRender as ${route.entryName}ServerRender } from "../${route.worker}";
@@ -80,7 +67,6 @@ const writeWorkerServerFile = (appDirectory, distDirectory, enableWorkerInWeb) =
80
67
  importStr += `import ${route.entryName}template from "../${route.entryPath}";
81
68
  `;
82
69
  pageStr += `"${route.urlPath}": {
83
- ${isExistsCustomServer && !enableWorkerInWeb ? `${_constants.CUSTOM_SERVER},` : ""}
84
70
  entryName: "${route.entryName}",
85
71
  template: ${route.entryName}template,
86
72
  serverRender: ${route.isSSR ? `${route.entryName}ServerRender` : void 0},
package/dist/esm/code.js CHANGED
@@ -11,15 +11,16 @@ async function handleRequest(request) {
11
11
  url: request.url,
12
12
  },
13
13
  url: handleUrl(request.url),
14
+ body: null,
14
15
  loadableStats,
15
16
  routeManifest,
16
17
  };
17
18
  const handler = createHandler(manifest);
18
- const {body, status, headers = new Headers()} = await handler(context);
19
- headers.set('content-type', 'text/html;charset=UTF-8');
20
- return new Response(body, {
21
- status,
22
- headers,
19
+ await handler(context);
20
+ return new Response(context.body, {
21
+ headers: {
22
+ 'content-type': 'text/html;charset=UTF-8',
23
+ },
23
24
  });
24
25
  }
25
26
 
@@ -3,5 +3,3 @@ export const WORKER_SERVER_ENTRY = "index.js";
3
3
  export const MANIFEST_FILE = "manifest.js";
4
4
  export const PKG_FILE = "package.json";
5
5
  export const WRANGLER_FILE = "wrangler.toml";
6
- export const WEB_APP_NAME = "index";
7
- export const CUSTOM_SERVER = "customServer";
package/dist/esm/index.js CHANGED
@@ -1,51 +1,42 @@
1
1
  import path from "path";
2
- import { fs, isServiceWorker, PLUGIN_SCHEMAS, ROUTE_SPEC_FILE, SERVER_DIR } from "@modern-js/utils";
3
- import { CUSTOM_SERVER, MANIFEST_FILE, PKG_FILE, WEB_APP_NAME, WORKER_SERVER, WORKER_SERVER_ENTRY, WRANGLER_FILE } from "./constants";
2
+ import { fs, isServiceWorker, PLUGIN_SCHEMAS, ROUTE_SPEC_FILE } from "@modern-js/utils";
3
+ import { MANIFEST_FILE, PKG_FILE, WORKER_SERVER, WORKER_SERVER_ENTRY, WRANGLER_FILE } from "./constants";
4
4
  import { worker } from "./code";
5
- export default () => {
6
- return {
7
- name: "@modern-js/plugin-worker",
8
- setup: (ctx) => {
9
- return {
10
- async config() {
11
- return {
12
- output: {
13
- disableNodePolyfill: false
14
- }
15
- };
16
- },
17
- validateSchema() {
18
- return PLUGIN_SCHEMAS["@modern-js/plugin-worker"];
19
- },
20
- async afterDev() {
21
- var _configContext_deploy_worker;
22
- const { appDirectory, distDirectory } = ctx.useAppContext();
23
- const configContext = ctx.useResolvedConfigContext();
24
- if (!isServiceWorker(configContext)) {
25
- return;
5
+ export default () => ({
6
+ name: "@modern-js/plugin-worker",
7
+ setup: (ctx) => {
8
+ return {
9
+ async config() {
10
+ return {
11
+ output: {
12
+ disableNodePolyfill: false
26
13
  }
27
- const enableWorkerInWeb = configContext.deploy.enableWorker || ((_configContext_deploy_worker = configContext.deploy.worker) === null || _configContext_deploy_worker === void 0 ? void 0 : _configContext_deploy_worker.web);
28
- writeWorkerServerFile(appDirectory, distDirectory, enableWorkerInWeb);
29
- },
30
- async afterBuild() {
31
- var _configContext_deploy_worker;
32
- const { appDirectory, distDirectory } = ctx.useAppContext();
33
- const configContext = ctx.useResolvedConfigContext();
34
- if (!isServiceWorker(configContext)) {
35
- return;
36
- }
37
- const enableWorkerInWeb = configContext.deploy.enableWorker || ((_configContext_deploy_worker = configContext.deploy.worker) === null || _configContext_deploy_worker === void 0 ? void 0 : _configContext_deploy_worker.web);
38
- writeWorkerServerFile(appDirectory, distDirectory, enableWorkerInWeb);
14
+ };
15
+ },
16
+ validateSchema() {
17
+ return PLUGIN_SCHEMAS["@modern-js/plugin-worker"];
18
+ },
19
+ async afterDev() {
20
+ const { appDirectory, distDirectory } = ctx.useAppContext();
21
+ const configContext = ctx.useResolvedConfigContext();
22
+ if (!isServiceWorker(configContext)) {
23
+ return;
39
24
  }
40
- };
41
- }
42
- };
43
- };
44
- const writeWorkerServerFile = (appDirectory, distDirectory, enableWorkerInWeb) => {
25
+ writeWorkerServerFile(appDirectory, distDirectory);
26
+ },
27
+ async afterBuild() {
28
+ const { appDirectory, distDirectory } = ctx.useAppContext();
29
+ const configContext = ctx.useResolvedConfigContext();
30
+ if (!isServiceWorker(configContext)) {
31
+ return;
32
+ }
33
+ writeWorkerServerFile(appDirectory, distDirectory);
34
+ }
35
+ };
36
+ }
37
+ });
38
+ const writeWorkerServerFile = (appDirectory, distDirectory) => {
45
39
  const workServerDir = path.join(distDirectory, WORKER_SERVER);
46
- const customServerDir = path.join(appDirectory, SERVER_DIR, WEB_APP_NAME);
47
- const isExistsCustomServer = fs.existsSync(`${customServerDir}.ts`) || fs.existsSync(`${customServerDir}.js`);
48
- const relativePath = path.relative(workServerDir, customServerDir);
49
40
  fs.removeSync(workServerDir);
50
41
  fs.mkdirSync(workServerDir);
51
42
  fs.writeFileSync(path.join(workServerDir, WORKER_SERVER_ENTRY), worker());
@@ -54,10 +45,6 @@ const writeWorkerServerFile = (appDirectory, distDirectory, enableWorkerInWeb) =
54
45
  let importStr = ``;
55
46
  let pageStr = ``;
56
47
  const routeArr = [];
57
- if (isExistsCustomServer && !enableWorkerInWeb) {
58
- importStr += `import * as ${CUSTOM_SERVER} from '${relativePath}'
59
- `;
60
- }
61
48
  routes.forEach((route) => {
62
49
  if (route.isSSR) {
63
50
  importStr += `import { serverRender as ${route.entryName}ServerRender } from "../${route.worker}";
@@ -67,7 +54,6 @@ const writeWorkerServerFile = (appDirectory, distDirectory, enableWorkerInWeb) =
67
54
  importStr += `import ${route.entryName}template from "../${route.entryPath}";
68
55
  `;
69
56
  pageStr += `"${route.urlPath}": {
70
- ${isExistsCustomServer && !enableWorkerInWeb ? `${CUSTOM_SERVER},` : ""}
71
57
  entryName: "${route.entryName}",
72
58
  template: ${route.entryName}template,
73
59
  serverRender: ${route.isSSR ? `${route.entryName}ServerRender` : void 0},
@@ -2,6 +2,4 @@ export declare const WORKER_SERVER = "worker-server";
2
2
  export declare const WORKER_SERVER_ENTRY = "index.js";
3
3
  export declare const MANIFEST_FILE = "manifest.js";
4
4
  export declare const PKG_FILE = "package.json";
5
- export declare const WRANGLER_FILE = "wrangler.toml";
6
- export declare const WEB_APP_NAME = "index";
7
- export declare const CUSTOM_SERVER = "customServer";
5
+ export declare const WRANGLER_FILE = "wrangler.toml";
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "0.0.0-next-1683623792316",
18
+ "version": "0.0.0-next-1683641210643",
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-1683623792316",
47
- "@modern-js/utils": "0.0.0-next-1683623792316",
48
- "@modern-js/prod-server": "0.0.0-next-1683623792316"
46
+ "@modern-js/server-utils": "0.0.0-next-1683641210643",
47
+ "@modern-js/utils": "0.0.0-next-1683641210643",
48
+ "@modern-js/prod-server": "0.0.0-next-1683641210643"
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-1683623792316",
56
- "@modern-js/core": "0.0.0-next-1683623792316",
57
- "@scripts/build": "0.0.0-next-1683623792316",
58
- "@modern-js/types": "0.0.0-next-1683623792316",
59
- "@scripts/jest-config": "0.0.0-next-1683623792316"
55
+ "@modern-js/app-tools": "0.0.0-next-1683641210643",
56
+ "@modern-js/core": "0.0.0-next-1683641210643",
57
+ "@modern-js/types": "0.0.0-next-1683641210643",
58
+ "@scripts/build": "0.0.0-next-1683641210643",
59
+ "@scripts/jest-config": "0.0.0-next-1683641210643"
60
60
  },
61
61
  "sideEffects": [
62
62
  "*.css",