@modern-js/plugin-worker 2.21.1 → 2.22.1
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 +30 -0
- package/dist/cjs/code.js +5 -2
- package/dist/cjs/constants.js +23 -5
- package/dist/cjs/index.js +49 -33
- package/dist/esm/code.js +2 -1
- 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,5 +1,35 @@
|
|
1
1
|
# @modern-js/plugin-worker
|
2
2
|
|
3
|
+
## 2.22.1
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Updated dependencies [e2848a2]
|
8
|
+
- Updated dependencies [4be1da5]
|
9
|
+
- Updated dependencies [d4045ed]
|
10
|
+
- Updated dependencies [1f02cd2]
|
11
|
+
- @modern-js/utils@2.22.1
|
12
|
+
- @modern-js/server-utils@2.22.1
|
13
|
+
- @modern-js/prod-server@2.22.1
|
14
|
+
|
15
|
+
## 2.22.0
|
16
|
+
|
17
|
+
### Minor Changes
|
18
|
+
|
19
|
+
- cb9e1ec: feat: worker ssr support server hooks
|
20
|
+
feat: worker ssr 支持 server hooks
|
21
|
+
|
22
|
+
### Patch Changes
|
23
|
+
|
24
|
+
- Updated dependencies [3d48836]
|
25
|
+
- Updated dependencies [5050e8e]
|
26
|
+
- Updated dependencies [4991c8a]
|
27
|
+
- Updated dependencies [cb9e1ec]
|
28
|
+
- Updated dependencies [ea961e7]
|
29
|
+
- @modern-js/utils@2.22.0
|
30
|
+
- @modern-js/prod-server@2.22.0
|
31
|
+
- @modern-js/server-utils@2.22.0
|
32
|
+
|
3
33
|
## 2.21.1
|
4
34
|
|
5
35
|
### Patch Changes
|
package/dist/cjs/code.js
CHANGED
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
});
|
5
5
|
Object.defineProperty(exports, "worker", {
|
6
6
|
enumerable: true,
|
7
|
-
get: ()
|
7
|
+
get: function() {
|
8
|
+
return worker;
|
9
|
+
}
|
8
10
|
});
|
9
11
|
const worker = () => `
|
10
12
|
// work entry code
|
@@ -13,13 +15,14 @@ import loadableStats from "../loadable-stats.json";
|
|
13
15
|
import routeManifest from "../routes-manifest.json";
|
14
16
|
import { manifest } from "./manifest";
|
15
17
|
|
18
|
+
const handler = createHandler(manifest);
|
19
|
+
|
16
20
|
async function handleRequest(request) {
|
17
21
|
const options = {
|
18
22
|
request,
|
19
23
|
loadableStats,
|
20
24
|
routeManifest,
|
21
25
|
}
|
22
|
-
const handler = createHandler(manifest);
|
23
26
|
|
24
27
|
const { body, status, headers } = await handler(options);
|
25
28
|
|
package/dist/cjs/constants.js
CHANGED
@@ -10,14 +10,32 @@ function _export(target, all) {
|
|
10
10
|
});
|
11
11
|
}
|
12
12
|
_export(exports, {
|
13
|
-
WORKER_SERVER: ()
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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;
|
33
|
+
}
|
18
34
|
});
|
19
35
|
const WORKER_SERVER = "worker-server";
|
20
36
|
const WORKER_SERVER_ENTRY = "index.js";
|
21
37
|
const MANIFEST_FILE = "manifest.js";
|
22
38
|
const PKG_FILE = "package.json";
|
23
39
|
const WRANGLER_FILE = "wrangler.toml";
|
40
|
+
const WEB_APP_NAME = "index";
|
41
|
+
const SERVER_HOOKS = "serverHooks";
|
package/dist/cjs/index.js
CHANGED
@@ -4,48 +4,59 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
});
|
5
5
|
Object.defineProperty(exports, "default", {
|
6
6
|
enumerable: true,
|
7
|
-
get: ()
|
7
|
+
get: function() {
|
8
|
+
return _default;
|
9
|
+
}
|
8
10
|
});
|
9
11
|
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
10
12
|
const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
|
11
13
|
const _utils = require("@modern-js/utils");
|
12
14
|
const _constants = require("./constants");
|
13
15
|
const _code = require("./code");
|
14
|
-
const _default = () =>
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
const _default = () => {
|
17
|
+
return {
|
18
|
+
name: "@modern-js/plugin-worker",
|
19
|
+
setup: (ctx) => {
|
20
|
+
return {
|
21
|
+
async config() {
|
22
|
+
return {
|
23
|
+
output: {
|
24
|
+
disableNodePolyfill: false
|
25
|
+
}
|
26
|
+
};
|
27
|
+
},
|
28
|
+
validateSchema() {
|
29
|
+
return _utils.PLUGIN_SCHEMAS["@modern-js/plugin-worker"];
|
30
|
+
},
|
31
|
+
async afterDev() {
|
32
|
+
var _configContext_deploy_worker;
|
33
|
+
const { appDirectory, distDirectory } = ctx.useAppContext();
|
34
|
+
const configContext = ctx.useResolvedConfigContext();
|
35
|
+
if (!(0, _utils.isServiceWorker)(configContext)) {
|
36
|
+
return;
|
22
37
|
}
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
},
|
36
|
-
async afterBuild() {
|
37
|
-
const { appDirectory, distDirectory } = ctx.useAppContext();
|
38
|
-
const configContext = ctx.useResolvedConfigContext();
|
39
|
-
if (!(0, _utils.isServiceWorker)(configContext)) {
|
40
|
-
return;
|
38
|
+
const enableWorkerInWeb = configContext.deploy.enableWorker || ((_configContext_deploy_worker = configContext.deploy.worker) === null || _configContext_deploy_worker === void 0 ? void 0 : _configContext_deploy_worker.web);
|
39
|
+
writeWorkerServerFile(appDirectory, distDirectory, enableWorkerInWeb);
|
40
|
+
},
|
41
|
+
async afterBuild() {
|
42
|
+
var _configContext_deploy_worker;
|
43
|
+
const { appDirectory, distDirectory } = ctx.useAppContext();
|
44
|
+
const configContext = ctx.useResolvedConfigContext();
|
45
|
+
if (!(0, _utils.isServiceWorker)(configContext)) {
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
const enableWorkerInWeb = configContext.deploy.enableWorker || ((_configContext_deploy_worker = configContext.deploy.worker) === null || _configContext_deploy_worker === void 0 ? void 0 : _configContext_deploy_worker.web);
|
49
|
+
writeWorkerServerFile(appDirectory, distDirectory, enableWorkerInWeb);
|
41
50
|
}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
const writeWorkerServerFile = (appDirectory, distDirectory) => {
|
51
|
+
};
|
52
|
+
}
|
53
|
+
};
|
54
|
+
};
|
55
|
+
const writeWorkerServerFile = (appDirectory, distDirectory, enableWorkerInWeb) => {
|
48
56
|
const workServerDir = _path.default.join(distDirectory, _constants.WORKER_SERVER);
|
57
|
+
const serverHookDir = _path.default.join(appDirectory, _utils.SERVER_DIR, _constants.WEB_APP_NAME);
|
58
|
+
const isExistsServerHook = _utils.fs.existsSync(`${serverHookDir}.ts`) || _utils.fs.existsSync(`${serverHookDir}.js`);
|
59
|
+
const relativePath = _path.default.relative(workServerDir, serverHookDir);
|
49
60
|
_utils.fs.removeSync(workServerDir);
|
50
61
|
_utils.fs.mkdirSync(workServerDir);
|
51
62
|
_utils.fs.writeFileSync(_path.default.join(workServerDir, _constants.WORKER_SERVER_ENTRY), (0, _code.worker)());
|
@@ -54,6 +65,10 @@ const writeWorkerServerFile = (appDirectory, distDirectory) => {
|
|
54
65
|
let importStr = ``;
|
55
66
|
let pageStr = ``;
|
56
67
|
const routeArr = [];
|
68
|
+
if (isExistsServerHook && !enableWorkerInWeb) {
|
69
|
+
importStr += `import * as ${_constants.SERVER_HOOKS} from '${relativePath}'
|
70
|
+
`;
|
71
|
+
}
|
57
72
|
routes.forEach((route) => {
|
58
73
|
if (route.isSSR) {
|
59
74
|
importStr += `import { serverRender as ${route.entryName}ServerRender } from "../${route.worker}";
|
@@ -63,6 +78,7 @@ const writeWorkerServerFile = (appDirectory, distDirectory) => {
|
|
63
78
|
importStr += `import ${route.entryName}template from "../${route.entryPath}";
|
64
79
|
`;
|
65
80
|
pageStr += `"${route.urlPath}": {
|
81
|
+
${isExistsServerHook && !enableWorkerInWeb ? `${_constants.SERVER_HOOKS},` : ""}
|
66
82
|
entryName: "${route.entryName}",
|
67
83
|
template: ${route.entryName}template,
|
68
84
|
serverRender: ${route.isSSR ? `${route.entryName}ServerRender` : void 0},
|
package/dist/esm/code.js
CHANGED
@@ -5,13 +5,14 @@ import loadableStats from "../loadable-stats.json";
|
|
5
5
|
import routeManifest from "../routes-manifest.json";
|
6
6
|
import { manifest } from "./manifest";
|
7
7
|
|
8
|
+
const handler = createHandler(manifest);
|
9
|
+
|
8
10
|
async function handleRequest(request) {
|
9
11
|
const options = {
|
10
12
|
request,
|
11
13
|
loadableStats,
|
12
14
|
routeManifest,
|
13
15
|
}
|
14
|
-
const handler = createHandler(manifest);
|
15
16
|
|
16
17
|
const { body, status, headers } = await handler(options);
|
17
18
|
|
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 { 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 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 serverHookDir = path.join(appDirectory, SERVER_DIR, WEB_APP_NAME);
|
47
|
+
const isExistsServerHook = fs.existsSync(`${serverHookDir}.ts`) || fs.existsSync(`${serverHookDir}.js`);
|
48
|
+
const relativePath = path.relative(workServerDir, serverHookDir);
|
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 (isExistsServerHook && !enableWorkerInWeb) {
|
58
|
+
importStr += `import * as ${SERVER_HOOKS} 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
|
+
${isExistsServerHook && !enableWorkerInWeb ? `${SERVER_HOOKS},` : ""}
|
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 SERVER_HOOKS = "serverHooks";
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.
|
18
|
+
"version": "2.22.1",
|
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.22.1",
|
47
|
+
"@modern-js/utils": "2.22.1",
|
48
|
+
"@modern-js/prod-server": "2.22.1"
|
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.
|
56
|
-
"@modern-js/core": "2.
|
57
|
-
"@scripts/build": "2.
|
58
|
-
"@modern-js/types": "2.
|
59
|
-
"@scripts/jest-config": "2.
|
55
|
+
"@modern-js/app-tools": "2.22.1",
|
56
|
+
"@modern-js/core": "2.22.1",
|
57
|
+
"@scripts/build": "2.22.1",
|
58
|
+
"@modern-js/types": "2.22.1",
|
59
|
+
"@scripts/jest-config": "2.22.1"
|
60
60
|
},
|
61
61
|
"sideEffects": [
|
62
62
|
"*.css",
|