@modern-js/plugin-worker 2.35.0 → 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 +24 -7
- package/dist/cjs/constants.js +35 -30
- package/dist/cjs/index.js +56 -38
- package/dist/esm/code.js +4 -1
- package/dist/esm/constants.js +16 -7
- package/dist/esm/index.js +6 -2
- package/package.json +9 -9
package/dist/cjs/code.js
CHANGED
@@ -1,13 +1,26 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.defineProperty
|
3
|
-
|
4
|
-
|
5
|
-
Object.
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
+
});
|
package/dist/cjs/constants.js
CHANGED
@@ -1,37 +1,32 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.defineProperty
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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.
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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,
|
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,
|
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 =
|
73
|
-
const serverHookDir =
|
74
|
-
const isExistsServerHook =
|
75
|
-
const relativePath =
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
const routeJSON =
|
80
|
-
const { routes } =
|
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 ${
|
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 ? `${
|
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
|
-
|
120
|
-
const pkg =
|
121
|
-
|
122
|
-
main = "${
|
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
|
-
|
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
|
-
|
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
|
+
};
|
package/dist/esm/constants.js
CHANGED
@@ -1,7 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
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
|
-
|
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.
|
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.
|
47
|
-
"@modern-js/utils": "2.
|
48
|
-
"@modern-js/prod-server": "2.
|
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/
|
56
|
-
"@modern-js/
|
57
|
-
"@
|
58
|
-
"@
|
59
|
-
"@scripts/
|
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",
|