@modern-js/plugin-worker 2.35.1 → 2.36.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/cjs/code.js CHANGED
@@ -1,13 +1,26 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "worker", {
6
- enumerable: true,
7
- get: function() {
8
- return worker;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var code_exports = {};
20
+ __export(code_exports, {
21
+ worker: () => worker
10
22
  });
23
+ module.exports = __toCommonJS(code_exports);
11
24
  const worker = () => `
12
25
  // work entry code
13
26
  import { createHandler } from "@modern-js/prod-server/worker";
@@ -36,3 +49,7 @@ addEventListener("fetch", (event) => {
36
49
  event.respondWith(handleRequest(event.request));
37
50
  });
38
51
  `;
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ worker
55
+ });
@@ -1,37 +1,32 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
6
7
  for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- WORKER_SERVER: function() {
14
- return WORKER_SERVER;
15
- },
16
- WORKER_SERVER_ENTRY: function() {
17
- return WORKER_SERVER_ENTRY;
18
- },
19
- MANIFEST_FILE: function() {
20
- return MANIFEST_FILE;
21
- },
22
- PKG_FILE: function() {
23
- return PKG_FILE;
24
- },
25
- WRANGLER_FILE: function() {
26
- return WRANGLER_FILE;
27
- },
28
- WEB_APP_NAME: function() {
29
- return WEB_APP_NAME;
30
- },
31
- SERVER_HOOKS: function() {
32
- return SERVER_HOOKS;
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var constants_exports = {};
20
+ __export(constants_exports, {
21
+ MANIFEST_FILE: () => MANIFEST_FILE,
22
+ PKG_FILE: () => PKG_FILE,
23
+ SERVER_HOOKS: () => SERVER_HOOKS,
24
+ WEB_APP_NAME: () => WEB_APP_NAME,
25
+ WORKER_SERVER: () => WORKER_SERVER,
26
+ WORKER_SERVER_ENTRY: () => WORKER_SERVER_ENTRY,
27
+ WRANGLER_FILE: () => WRANGLER_FILE
34
28
  });
29
+ module.exports = __toCommonJS(constants_exports);
35
30
  const WORKER_SERVER = "worker-server";
36
31
  const WORKER_SERVER_ENTRY = "index.js";
37
32
  const MANIFEST_FILE = "manifest.js";
@@ -39,3 +34,13 @@ const PKG_FILE = "package.json";
39
34
  const WRANGLER_FILE = "wrangler.toml";
40
35
  const WEB_APP_NAME = "index";
41
36
  const SERVER_HOOKS = "serverHooks";
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ MANIFEST_FILE,
40
+ PKG_FILE,
41
+ SERVER_HOOKS,
42
+ WEB_APP_NAME,
43
+ WORKER_SERVER,
44
+ WORKER_SERVER_ENTRY,
45
+ WRANGLER_FILE
46
+ });
package/dist/cjs/index.js CHANGED
@@ -1,27 +1,41 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
6
9
  for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- workerPlugin: function() {
14
- return workerPlugin;
15
- },
16
- default: function() {
17
- return _default;
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
17
  }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var src_exports = {};
30
+ __export(src_exports, {
31
+ default: () => src_default,
32
+ workerPlugin: () => workerPlugin
19
33
  });
20
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
21
- const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
22
- const _utils = require("@modern-js/utils");
23
- const _constants = require("./constants");
24
- const _code = require("./code");
34
+ module.exports = __toCommonJS(src_exports);
35
+ var import_path = __toESM(require("path"));
36
+ var import_utils = require("@modern-js/utils");
37
+ var import_constants = require("./constants");
38
+ var import_code = require("./code");
25
39
  const workerPlugin = () => ({
26
40
  name: "@modern-js/plugin-worker",
27
41
  setup: (ctx) => {
@@ -49,7 +63,7 @@ const workerPlugin = () => ({
49
63
  var _configContext_deploy_worker;
50
64
  const { appDirectory, distDirectory } = ctx.useAppContext();
51
65
  const configContext = ctx.useResolvedConfigContext();
52
- if (!(0, _utils.isServiceWorker)(configContext)) {
66
+ if (!(0, import_utils.isServiceWorker)(configContext)) {
53
67
  return;
54
68
  }
55
69
  const enableWorkerInWeb = configContext.deploy.enableWorker || ((_configContext_deploy_worker = configContext.deploy.worker) === null || _configContext_deploy_worker === void 0 ? void 0 : _configContext_deploy_worker.web);
@@ -59,7 +73,7 @@ const workerPlugin = () => ({
59
73
  var _configContext_deploy_worker;
60
74
  const { appDirectory, distDirectory } = ctx.useAppContext();
61
75
  const configContext = ctx.useResolvedConfigContext();
62
- if (!(0, _utils.isServiceWorker)(configContext)) {
76
+ if (!(0, import_utils.isServiceWorker)(configContext)) {
63
77
  return;
64
78
  }
65
79
  const enableWorkerInWeb = configContext.deploy.enableWorker || ((_configContext_deploy_worker = configContext.deploy.worker) === null || _configContext_deploy_worker === void 0 ? void 0 : _configContext_deploy_worker.web);
@@ -69,20 +83,20 @@ const workerPlugin = () => ({
69
83
  }
70
84
  });
71
85
  const writeWorkerServerFile = (appDirectory, distDirectory, enableWorkerInWeb) => {
72
- const workServerDir = _path.default.join(distDirectory, _constants.WORKER_SERVER);
73
- const serverHookDir = _path.default.join(appDirectory, _utils.SERVER_DIR, _constants.WEB_APP_NAME);
74
- const isExistsServerHook = _utils.fs.existsSync(`${serverHookDir}.ts`) || _utils.fs.existsSync(`${serverHookDir}.js`);
75
- const relativePath = _path.default.relative(workServerDir, serverHookDir);
76
- _utils.fs.removeSync(workServerDir);
77
- _utils.fs.mkdirSync(workServerDir);
78
- _utils.fs.writeFileSync(_path.default.join(workServerDir, _constants.WORKER_SERVER_ENTRY), (0, _code.worker)());
79
- const routeJSON = _path.default.join(distDirectory, _utils.ROUTE_SPEC_FILE);
80
- const { routes } = _utils.fs.readJSONSync(routeJSON);
86
+ const workServerDir = import_path.default.join(distDirectory, import_constants.WORKER_SERVER);
87
+ const serverHookDir = import_path.default.join(appDirectory, import_utils.SERVER_DIR, import_constants.WEB_APP_NAME);
88
+ const isExistsServerHook = import_utils.fs.existsSync(`${serverHookDir}.ts`) || import_utils.fs.existsSync(`${serverHookDir}.js`);
89
+ const relativePath = import_path.default.relative(workServerDir, serverHookDir);
90
+ import_utils.fs.removeSync(workServerDir);
91
+ import_utils.fs.mkdirSync(workServerDir);
92
+ import_utils.fs.writeFileSync(import_path.default.join(workServerDir, import_constants.WORKER_SERVER_ENTRY), (0, import_code.worker)());
93
+ const routeJSON = import_path.default.join(distDirectory, import_utils.ROUTE_SPEC_FILE);
94
+ const { routes } = import_utils.fs.readJSONSync(routeJSON);
81
95
  let importStr = ``;
82
96
  let pageStr = ``;
83
97
  const routeArr = [];
84
98
  if (isExistsServerHook && !enableWorkerInWeb) {
85
- importStr += `import * as ${_constants.SERVER_HOOKS} from '${relativePath}'
99
+ importStr += `import * as ${import_constants.SERVER_HOOKS} from '${relativePath}'
86
100
  `;
87
101
  }
88
102
  routes.forEach((route) => {
@@ -94,7 +108,7 @@ const writeWorkerServerFile = (appDirectory, distDirectory, enableWorkerInWeb) =
94
108
  importStr += `import ${route.entryName}template from "../${route.entryPath}";
95
109
  `;
96
110
  pageStr += `"${route.urlPath}": {
97
- ${isExistsServerHook && !enableWorkerInWeb ? `${_constants.SERVER_HOOKS},` : ""}
111
+ ${isExistsServerHook && !enableWorkerInWeb ? `${import_constants.SERVER_HOOKS},` : ""}
98
112
  entryName: "${route.entryName}",
99
113
  template: ${route.entryName}template,
100
114
  serverRender: ${route.isSSR ? `${route.entryName}ServerRender` : void 0},
@@ -116,11 +130,15 @@ export const manifest = {
116
130
  routes: ${JSON.stringify(routeArr, null, " ")}
117
131
  }
118
132
  `;
119
- _utils.fs.writeFileSync(_path.default.join(workServerDir, _constants.MANIFEST_FILE), manifest);
120
- const pkg = _utils.fs.readJSONSync(_path.default.join(appDirectory, _constants.PKG_FILE));
121
- _utils.fs.writeFileSync(_path.default.join(distDirectory, _constants.WRANGLER_FILE), `name = "${pkg.name}"
122
- main = "${_path.default.join(_constants.WORKER_SERVER, _constants.WORKER_SERVER_ENTRY)}"
133
+ import_utils.fs.writeFileSync(import_path.default.join(workServerDir, import_constants.MANIFEST_FILE), manifest);
134
+ const pkg = import_utils.fs.readJSONSync(import_path.default.join(appDirectory, import_constants.PKG_FILE));
135
+ import_utils.fs.writeFileSync(import_path.default.join(distDirectory, import_constants.WRANGLER_FILE), `name = "${pkg.name}"
136
+ main = "${import_path.default.join(import_constants.WORKER_SERVER, import_constants.WORKER_SERVER_ENTRY)}"
123
137
  compatibility_date = "${(/* @__PURE__ */ new Date()).toISOString().substring(0, 10)}"
124
138
  `);
125
139
  };
126
- const _default = workerPlugin;
140
+ var src_default = workerPlugin;
141
+ // Annotate the CommonJS export names for ESM import in node:
142
+ 0 && (module.exports = {
143
+ workerPlugin
144
+ });
package/dist/esm/code.js CHANGED
@@ -1,4 +1,4 @@
1
- export const worker = () => `
1
+ const worker = () => `
2
2
  // work entry code
3
3
  import { createHandler } from "@modern-js/prod-server/worker";
4
4
  import loadableStats from "../loadable-stats.json";
@@ -26,3 +26,6 @@ addEventListener("fetch", (event) => {
26
26
  event.respondWith(handleRequest(event.request));
27
27
  });
28
28
  `;
29
+ export {
30
+ worker
31
+ };
@@ -1,7 +1,16 @@
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";
6
- export const WEB_APP_NAME = "index";
7
- export const SERVER_HOOKS = "serverHooks";
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
+ const WEB_APP_NAME = "index";
7
+ const SERVER_HOOKS = "serverHooks";
8
+ export {
9
+ MANIFEST_FILE,
10
+ PKG_FILE,
11
+ SERVER_HOOKS,
12
+ WEB_APP_NAME,
13
+ WORKER_SERVER,
14
+ WORKER_SERVER_ENTRY,
15
+ WRANGLER_FILE
16
+ };
package/dist/esm/index.js CHANGED
@@ -2,7 +2,7 @@ import path from "path";
2
2
  import { fs, isServiceWorker, ROUTE_SPEC_FILE, SERVER_DIR } from "@modern-js/utils";
3
3
  import { MANIFEST_FILE, PKG_FILE, SERVER_HOOKS, WEB_APP_NAME, WORKER_SERVER, WORKER_SERVER_ENTRY, WRANGLER_FILE } from "./constants";
4
4
  import { worker } from "./code";
5
- export const workerPlugin = () => ({
5
+ const workerPlugin = () => ({
6
6
  name: "@modern-js/plugin-worker",
7
7
  setup: (ctx) => {
8
8
  return {
@@ -103,4 +103,8 @@ main = "${path.join(WORKER_SERVER, WORKER_SERVER_ENTRY)}"
103
103
  compatibility_date = "${(/* @__PURE__ */ new Date()).toISOString().substring(0, 10)}"
104
104
  `);
105
105
  };
106
- export default workerPlugin;
106
+ var src_default = workerPlugin;
107
+ export {
108
+ src_default as default,
109
+ workerPlugin
110
+ };
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.35.1",
18
+ "version": "2.36.0",
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
  "@swc/helpers": "0.5.1",
46
- "@modern-js/server-utils": "2.35.1",
47
- "@modern-js/utils": "2.35.1",
48
- "@modern-js/prod-server": "2.35.1"
46
+ "@modern-js/server-utils": "2.36.0",
47
+ "@modern-js/utils": "2.36.0",
48
+ "@modern-js/prod-server": "2.36.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "typescript": "^5",
52
52
  "@types/jest": "^29",
53
53
  "@types/node": "^14",
54
54
  "jest": "^29",
55
- "@modern-js/app-tools": "2.35.1",
56
- "@modern-js/core": "2.35.1",
57
- "@modern-js/types": "2.35.1",
58
- "@scripts/jest-config": "2.35.1",
59
- "@scripts/build": "2.35.1"
55
+ "@modern-js/app-tools": "2.36.0",
56
+ "@modern-js/core": "2.36.0",
57
+ "@scripts/build": "2.36.0",
58
+ "@modern-js/types": "2.36.0",
59
+ "@scripts/jest-config": "2.36.0"
60
60
  },
61
61
  "sideEffects": [
62
62
  "*.css",