@modern-js/plugin-worker 2.14.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,28 @@
1
1
  # @modern-js/plugin-worker
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
+ - @modern-js/prod-server@2.16.0
16
+ - @modern-js/server-utils@2.16.0
17
+
18
+ ## 2.15.0
19
+
20
+ ### Patch Changes
21
+
22
+ - @modern-js/prod-server@2.15.0
23
+ - @modern-js/server-utils@2.15.0
24
+ - @modern-js/utils@2.15.0
25
+
3
26
  ## 2.14.0
4
27
 
5
28
  ### Patch Changes
package/dist/cjs/code.js CHANGED
@@ -1,25 +1,11 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var code_exports = {};
19
- __export(code_exports, {
20
- worker: () => worker
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "worker", {
6
+ enumerable: true,
7
+ get: () => worker
21
8
  });
22
- module.exports = __toCommonJS(code_exports);
23
9
  const worker = () => `
24
10
  // work entry code
25
11
  import { createHandler, handleUrl } from "@modern-js/prod-server/worker";
@@ -50,7 +36,3 @@ addEventListener("fetch", (event) => {
50
36
  event.respondWith(handleRequest(event.request));
51
37
  });
52
38
  `;
53
- // Annotate the CommonJS export names for ESM import in node:
54
- 0 && (module.exports = {
55
- worker
56
- });
@@ -1,39 +1,23 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
6
  for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var constants_exports = {};
19
- __export(constants_exports, {
20
- MANIFEST_FILE: () => MANIFEST_FILE,
21
- PKG_FILE: () => PKG_FILE,
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
22
13
  WORKER_SERVER: () => WORKER_SERVER,
23
14
  WORKER_SERVER_ENTRY: () => WORKER_SERVER_ENTRY,
15
+ MANIFEST_FILE: () => MANIFEST_FILE,
16
+ PKG_FILE: () => PKG_FILE,
24
17
  WRANGLER_FILE: () => WRANGLER_FILE
25
18
  });
26
- module.exports = __toCommonJS(constants_exports);
27
19
  const WORKER_SERVER = "worker-server";
28
20
  const WORKER_SERVER_ENTRY = "index.js";
29
21
  const MANIFEST_FILE = "manifest.js";
30
22
  const PKG_FILE = "package.json";
31
23
  const WRANGLER_FILE = "wrangler.toml";
32
- // Annotate the CommonJS export names for ESM import in node:
33
- 0 && (module.exports = {
34
- MANIFEST_FILE,
35
- PKG_FILE,
36
- WORKER_SERVER,
37
- WORKER_SERVER_ENTRY,
38
- WRANGLER_FILE
39
- });
package/dist/cjs/index.js CHANGED
@@ -1,40 +1,21 @@
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_constants = require("./constants");
36
- var import_code = require("./code");
37
- var src_default = () => ({
9
+ const _path = /* @__PURE__ */ _interop_require_default(require("path"));
10
+ const _utils = require("@modern-js/utils");
11
+ const _constants = require("./constants");
12
+ const _code = require("./code");
13
+ function _interop_require_default(obj) {
14
+ return obj && obj.__esModule ? obj : {
15
+ default: obj
16
+ };
17
+ }
18
+ const _default = () => ({
38
19
  name: "@modern-js/plugin-worker",
39
20
  setup: (ctx) => {
40
21
  return {
@@ -43,26 +24,15 @@ var src_default = () => ({
43
24
  output: {
44
25
  disableNodePolyfill: false
45
26
  }
46
- // TODO
47
- // tools: {
48
- // webpackChain: (chain, { isServiceWorker }) => {
49
- // if (isServiceWorker) {
50
- // chain.resolve.alias.set(
51
- // 'async_hooks',
52
- // path.resolve(__dirname, './async_hooks'),
53
- // );
54
- // }
55
- // },
56
- // },
57
27
  };
58
28
  },
59
29
  validateSchema() {
60
- return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-worker"];
30
+ return _utils.PLUGIN_SCHEMAS["@modern-js/plugin-worker"];
61
31
  },
62
32
  async afterDev() {
63
33
  const { appDirectory, distDirectory } = ctx.useAppContext();
64
34
  const configContext = ctx.useResolvedConfigContext();
65
- if (!(0, import_utils.isServiceWorker)(configContext)) {
35
+ if (!(0, _utils.isServiceWorker)(configContext)) {
66
36
  return;
67
37
  }
68
38
  writeWorkerServerFile(appDirectory, distDirectory);
@@ -70,7 +40,7 @@ var src_default = () => ({
70
40
  async afterBuild() {
71
41
  const { appDirectory, distDirectory } = ctx.useAppContext();
72
42
  const configContext = ctx.useResolvedConfigContext();
73
- if (!(0, import_utils.isServiceWorker)(configContext)) {
43
+ if (!(0, _utils.isServiceWorker)(configContext)) {
74
44
  return;
75
45
  }
76
46
  writeWorkerServerFile(appDirectory, distDirectory);
@@ -79,37 +49,35 @@ var src_default = () => ({
79
49
  }
80
50
  });
81
51
  const writeWorkerServerFile = (appDirectory, distDirectory) => {
82
- const workServerDir = import_path.default.join(distDirectory, import_constants.WORKER_SERVER);
83
- import_utils.fs.removeSync(workServerDir);
84
- import_utils.fs.mkdirSync(workServerDir);
85
- import_utils.fs.writeFileSync(import_path.default.join(workServerDir, import_constants.WORKER_SERVER_ENTRY), (0, import_code.worker)());
86
- const routeJSON = import_path.default.join(distDirectory, import_utils.ROUTE_SPEC_FILE);
87
- const { routes } = import_utils.fs.readJSONSync(routeJSON);
52
+ const workServerDir = _path.default.join(distDirectory, _constants.WORKER_SERVER);
53
+ _utils.fs.removeSync(workServerDir);
54
+ _utils.fs.mkdirSync(workServerDir);
55
+ _utils.fs.writeFileSync(_path.default.join(workServerDir, _constants.WORKER_SERVER_ENTRY), (0, _code.worker)());
56
+ const routeJSON = _path.default.join(distDirectory, _utils.ROUTE_SPEC_FILE);
57
+ const { routes } = _utils.fs.readJSONSync(routeJSON);
88
58
  let importStr = ``;
89
59
  let pageStr = ``;
90
60
  const routeArr = [];
91
- routes.forEach(
92
- (route) => {
93
- if (route.isSSR) {
94
- importStr += `import { serverRender as ${route.entryName}ServerRender } from "../${route.worker}";
61
+ routes.forEach((route) => {
62
+ if (route.isSSR) {
63
+ importStr += `import { serverRender as ${route.entryName}ServerRender } from "../${route.worker}";
95
64
  `;
96
- }
97
- if (!route.isApi) {
98
- importStr += `import ${route.entryName}template from "../${route.entryPath}";
65
+ }
66
+ if (!route.isApi) {
67
+ importStr += `import ${route.entryName}template from "../${route.entryPath}";
99
68
  `;
100
- pageStr += `"${route.urlPath}": {
69
+ pageStr += `"${route.urlPath}": {
101
70
  entryName: "${route.entryName}",
102
71
  template: ${route.entryName}template,
103
72
  serverRender: ${route.isSSR ? `${route.entryName}ServerRender` : void 0},
104
73
  },`;
105
- routeArr.push({
106
- entryName: route.entryName,
107
- isSSR: route.isSSR,
108
- urlPath: route.urlPath
109
- });
110
- }
74
+ routeArr.push({
75
+ entryName: route.entryName,
76
+ isSSR: route.isSSR,
77
+ urlPath: route.urlPath
78
+ });
111
79
  }
112
- );
80
+ });
113
81
  const manifest = `
114
82
  ${importStr}
115
83
 
@@ -120,15 +88,10 @@ export const manifest = {
120
88
  routes: ${JSON.stringify(routeArr, null, " ")}
121
89
  }
122
90
  `;
123
- import_utils.fs.writeFileSync(import_path.default.join(workServerDir, import_constants.MANIFEST_FILE), manifest);
124
- const pkg = import_utils.fs.readJSONSync(import_path.default.join(appDirectory, import_constants.PKG_FILE));
125
- import_utils.fs.writeFileSync(
126
- import_path.default.join(distDirectory, import_constants.WRANGLER_FILE),
127
- `name = "${pkg.name}"
128
- main = "${import_path.default.join(import_constants.WORKER_SERVER, import_constants.WORKER_SERVER_ENTRY)}"
91
+ _utils.fs.writeFileSync(_path.default.join(workServerDir, _constants.MANIFEST_FILE), manifest);
92
+ const pkg = _utils.fs.readJSONSync(_path.default.join(appDirectory, _constants.PKG_FILE));
93
+ _utils.fs.writeFileSync(_path.default.join(distDirectory, _constants.WRANGLER_FILE), `name = "${pkg.name}"
94
+ main = "${_path.default.join(_constants.WORKER_SERVER, _constants.WORKER_SERVER_ENTRY)}"
129
95
  compatibility_date = "${(/* @__PURE__ */ new Date()).toISOString().substring(0, 10)}"
130
- `
131
- );
96
+ `);
132
97
  };
133
- // Annotate the CommonJS export names for ESM import in node:
134
- 0 && (module.exports = {});
package/dist/esm/code.js CHANGED
@@ -1,4 +1,4 @@
1
- const worker = () => `
1
+ export const worker = () => `
2
2
  // work entry code
3
3
  import { createHandler, handleUrl } from "@modern-js/prod-server/worker";
4
4
  import loadableStats from "../loadable-stats.json";
@@ -28,6 +28,3 @@ addEventListener("fetch", (event) => {
28
28
  event.respondWith(handleRequest(event.request));
29
29
  });
30
30
  `;
31
- export {
32
- worker
33
- };
@@ -1,12 +1,5 @@
1
- const WORKER_SERVER = "worker-server";
2
- const WORKER_SERVER_ENTRY = "index.js";
3
- const MANIFEST_FILE = "manifest.js";
4
- const PKG_FILE = "package.json";
5
- const WRANGLER_FILE = "wrangler.toml";
6
- export {
7
- MANIFEST_FILE,
8
- PKG_FILE,
9
- WORKER_SERVER,
10
- WORKER_SERVER_ENTRY,
11
- WRANGLER_FILE
12
- };
1
+ export const WORKER_SERVER = "worker-server";
2
+ export const WORKER_SERVER_ENTRY = "index.js";
3
+ export const MANIFEST_FILE = "manifest.js";
4
+ export const PKG_FILE = "package.json";
5
+ export const WRANGLER_FILE = "wrangler.toml";
package/dist/esm/index.js CHANGED
@@ -1,19 +1,8 @@
1
1
  import path from "path";
2
- import {
3
- fs,
4
- isServiceWorker,
5
- PLUGIN_SCHEMAS,
6
- ROUTE_SPEC_FILE
7
- } from "@modern-js/utils";
8
- import {
9
- MANIFEST_FILE,
10
- PKG_FILE,
11
- WORKER_SERVER,
12
- WORKER_SERVER_ENTRY,
13
- WRANGLER_FILE
14
- } 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";
15
4
  import { worker } from "./code";
16
- var src_default = () => ({
5
+ export default () => ({
17
6
  name: "@modern-js/plugin-worker",
18
7
  setup: (ctx) => {
19
8
  return {
@@ -22,17 +11,6 @@ var src_default = () => ({
22
11
  output: {
23
12
  disableNodePolyfill: false
24
13
  }
25
- // TODO
26
- // tools: {
27
- // webpackChain: (chain, { isServiceWorker }) => {
28
- // if (isServiceWorker) {
29
- // chain.resolve.alias.set(
30
- // 'async_hooks',
31
- // path.resolve(__dirname, './async_hooks'),
32
- // );
33
- // }
34
- // },
35
- // },
36
14
  };
37
15
  },
38
16
  validateSchema() {
@@ -67,28 +45,26 @@ const writeWorkerServerFile = (appDirectory, distDirectory) => {
67
45
  let importStr = ``;
68
46
  let pageStr = ``;
69
47
  const routeArr = [];
70
- routes.forEach(
71
- (route) => {
72
- if (route.isSSR) {
73
- importStr += `import { serverRender as ${route.entryName}ServerRender } from "../${route.worker}";
48
+ routes.forEach((route) => {
49
+ if (route.isSSR) {
50
+ importStr += `import { serverRender as ${route.entryName}ServerRender } from "../${route.worker}";
74
51
  `;
75
- }
76
- if (!route.isApi) {
77
- importStr += `import ${route.entryName}template from "../${route.entryPath}";
52
+ }
53
+ if (!route.isApi) {
54
+ importStr += `import ${route.entryName}template from "../${route.entryPath}";
78
55
  `;
79
- pageStr += `"${route.urlPath}": {
56
+ pageStr += `"${route.urlPath}": {
80
57
  entryName: "${route.entryName}",
81
58
  template: ${route.entryName}template,
82
59
  serverRender: ${route.isSSR ? `${route.entryName}ServerRender` : void 0},
83
60
  },`;
84
- routeArr.push({
85
- entryName: route.entryName,
86
- isSSR: route.isSSR,
87
- urlPath: route.urlPath
88
- });
89
- }
61
+ routeArr.push({
62
+ entryName: route.entryName,
63
+ isSSR: route.isSSR,
64
+ urlPath: route.urlPath
65
+ });
90
66
  }
91
- );
67
+ });
92
68
  const manifest = `
93
69
  ${importStr}
94
70
 
@@ -101,14 +77,8 @@ export const manifest = {
101
77
  `;
102
78
  fs.writeFileSync(path.join(workServerDir, MANIFEST_FILE), manifest);
103
79
  const pkg = fs.readJSONSync(path.join(appDirectory, PKG_FILE));
104
- fs.writeFileSync(
105
- path.join(distDirectory, WRANGLER_FILE),
106
- `name = "${pkg.name}"
80
+ fs.writeFileSync(path.join(distDirectory, WRANGLER_FILE), `name = "${pkg.name}"
107
81
  main = "${path.join(WORKER_SERVER, WORKER_SERVER_ENTRY)}"
108
82
  compatibility_date = "${(/* @__PURE__ */ new Date()).toISOString().substring(0, 10)}"
109
- `
110
- );
111
- };
112
- export {
113
- src_default as default
83
+ `);
114
84
  };
package/package.json CHANGED
@@ -3,7 +3,11 @@
3
3
  "description": "The meta-framework suite designed from scratch for frontend-focused modern web development.",
4
4
  "homepage": "https://modernjs.dev",
5
5
  "bugs": "https://github.com/web-infra-dev/modern.js/issues",
6
- "repository": "web-infra-dev/modern.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/web-infra-dev/modern.js",
9
+ "directory": "packages/server/plugin-worker"
10
+ },
7
11
  "license": "MIT",
8
12
  "keywords": [
9
13
  "react",
@@ -11,7 +15,7 @@
11
15
  "modern",
12
16
  "modern.js"
13
17
  ],
14
- "version": "2.14.0",
18
+ "version": "2.16.0",
15
19
  "types": "./dist/types/index.d.ts",
16
20
  "jsnext:source": "./src/index.ts",
17
21
  "main": "./dist/cjs/index.js",
@@ -39,20 +43,20 @@
39
43
  },
40
44
  "dependencies": {
41
45
  "@babel/runtime": "^7.18.0",
42
- "@modern-js/server-utils": "2.14.0",
43
- "@modern-js/utils": "2.14.0",
44
- "@modern-js/prod-server": "2.14.0"
46
+ "@modern-js/server-utils": "2.16.0",
47
+ "@modern-js/utils": "2.16.0",
48
+ "@modern-js/prod-server": "2.16.0"
45
49
  },
46
50
  "devDependencies": {
47
51
  "typescript": "^4",
48
52
  "@types/jest": "^29",
49
53
  "@types/node": "^14",
50
54
  "jest": "^29",
51
- "@modern-js/app-tools": "2.14.0",
52
- "@modern-js/core": "2.14.0",
53
- "@scripts/build": "2.14.0",
54
- "@modern-js/types": "2.14.0",
55
- "@scripts/jest-config": "2.14.0"
55
+ "@modern-js/app-tools": "2.16.0",
56
+ "@modern-js/core": "2.16.0",
57
+ "@scripts/build": "2.16.0",
58
+ "@modern-js/types": "2.16.0",
59
+ "@scripts/jest-config": "2.16.0"
56
60
  },
57
61
  "sideEffects": [
58
62
  "*.css",