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