@modern-js/plugin-worker 2.5.0 → 2.6.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.
@@ -17,7 +17,6 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var constants_exports = {};
19
19
  __export(constants_exports, {
20
- LOCK_FILE: () => LOCK_FILE,
21
20
  MANIFEST_FILE: () => MANIFEST_FILE,
22
21
  PKG_FILE: () => PKG_FILE,
23
22
  WORKER_SERVER: () => WORKER_SERVER,
@@ -29,15 +28,9 @@ const WORKER_SERVER = "worker-server";
29
28
  const WORKER_SERVER_ENTRY = "index.js";
30
29
  const MANIFEST_FILE = "manifest.js";
31
30
  const PKG_FILE = "package.json";
32
- const LOCK_FILE = {
33
- yarn: "yarn.lock",
34
- npm: "package-lock.json",
35
- pnpm: "pnpm-lock.yaml"
36
- };
37
31
  const WRANGLER_FILE = "wrangler.toml";
38
32
  // Annotate the CommonJS export names for ESM import in node:
39
33
  0 && (module.exports = {
40
- LOCK_FILE,
41
34
  MANIFEST_FILE,
42
35
  PKG_FILE,
43
36
  WORKER_SERVER,
package/dist/cjs/index.js CHANGED
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
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.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -30,7 +34,6 @@ var import_path = __toESM(require("path"));
30
34
  var import_utils = require("@modern-js/utils");
31
35
  var import_constants = require("./constants");
32
36
  var import_code = require("./code");
33
- var import_utils2 = require("./utils");
34
37
  var src_default = () => ({
35
38
  name: "@modern-js/plugin-worker",
36
39
  setup: (ctx) => {
@@ -40,47 +43,69 @@ var src_default = () => ({
40
43
  output: {
41
44
  disableNodePolyfill: false
42
45
  }
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
+ // },
43
57
  };
44
58
  },
45
- async beforeDeploy() {
59
+ async afterDev() {
46
60
  const { appDirectory, distDirectory } = ctx.useAppContext();
47
61
  const configContext = ctx.useResolvedConfigContext();
48
62
  if (!(0, import_utils.isServiceWorker)(configContext)) {
49
63
  return;
50
64
  }
51
- const workServerDir = import_path.default.join(distDirectory, import_constants.WORKER_SERVER);
52
- import_utils.fs.removeSync(workServerDir);
53
- import_utils.fs.mkdirSync(workServerDir);
54
- import_utils.fs.writeFileSync(
55
- import_path.default.join(workServerDir, import_constants.WORKER_SERVER_ENTRY),
56
- (0, import_code.worker)()
57
- );
58
- const routeJSON = import_path.default.join(distDirectory, import_utils.ROUTE_SPEC_FILE);
59
- const { routes } = import_utils.fs.readJSONSync(routeJSON);
60
- let importStr = ``;
61
- let pageStr = ``;
62
- const routeArr = [];
63
- routes.forEach(
64
- (route) => {
65
- if (route.isSSR) {
66
- importStr += `import { serverRender as ${route.entryName}ServerRender } from "../${route.worker}";
65
+ writeWorkerServerFile(appDirectory, distDirectory);
66
+ },
67
+ async afterBuild() {
68
+ const { appDirectory, distDirectory } = ctx.useAppContext();
69
+ const configContext = ctx.useResolvedConfigContext();
70
+ if (!(0, import_utils.isServiceWorker)(configContext)) {
71
+ return;
72
+ }
73
+ writeWorkerServerFile(appDirectory, distDirectory);
74
+ }
75
+ };
76
+ }
77
+ });
78
+ const writeWorkerServerFile = (appDirectory, distDirectory) => {
79
+ const workServerDir = import_path.default.join(distDirectory, import_constants.WORKER_SERVER);
80
+ import_utils.fs.removeSync(workServerDir);
81
+ import_utils.fs.mkdirSync(workServerDir);
82
+ import_utils.fs.writeFileSync(import_path.default.join(workServerDir, import_constants.WORKER_SERVER_ENTRY), (0, import_code.worker)());
83
+ const routeJSON = import_path.default.join(distDirectory, import_utils.ROUTE_SPEC_FILE);
84
+ const { routes } = import_utils.fs.readJSONSync(routeJSON);
85
+ let importStr = ``;
86
+ let pageStr = ``;
87
+ const routeArr = [];
88
+ routes.forEach(
89
+ (route) => {
90
+ if (route.isSSR) {
91
+ importStr += `import { serverRender as ${route.entryName}ServerRender } from "../${route.worker}";
67
92
  `;
68
- }
69
- importStr += `import ${route.entryName}template from "../${route.entryPath}";
93
+ }
94
+ importStr += `import ${route.entryName}template from "../${route.entryPath}";
70
95
  `;
71
- pageStr += `"${route.urlPath}": {
96
+ pageStr += `"${route.urlPath}": {
72
97
  entryName: "${route.entryName}",
73
98
  template: ${route.entryName}template,
74
99
  serverRender: ${route.isSSR ? `${route.entryName}ServerRender` : void 0},
75
100
  },`;
76
- routeArr.push({
77
- entryName: route.entryName,
78
- isSSR: route.isSSR,
79
- urlPath: route.urlPath
80
- });
81
- }
82
- );
83
- const manifest = `
101
+ routeArr.push({
102
+ entryName: route.entryName,
103
+ isSSR: route.isSSR,
104
+ urlPath: route.urlPath
105
+ });
106
+ }
107
+ );
108
+ const manifest = `
84
109
  ${importStr}
85
110
 
86
111
  export const manifest = {
@@ -90,35 +115,15 @@ export const manifest = {
90
115
  routes: ${JSON.stringify(routeArr, null, " ")}
91
116
  }
92
117
  `;
93
- import_utils.fs.writeFileSync(import_path.default.join(workServerDir, import_constants.MANIFEST_FILE), manifest);
94
- const pkg = import_utils.fs.readJSONSync(import_path.default.join(appDirectory, import_constants.PKG_FILE));
95
- await import_utils.fs.writeJSON(
96
- import_path.default.join(distDirectory, import_constants.PKG_FILE),
97
- {
98
- name: pkg.name,
99
- version: pkg.version,
100
- dependencies: {
101
- "@modern-js/prod-server": "0.0.0-next-20230209112307",
102
- wrangler: "^2.9.0"
103
- },
104
- resolutions: pkg.resolutions || {},
105
- pnpm: pkg.pnpm || {}
106
- },
107
- { spaces: 2 }
108
- );
109
- const manager = await (0, import_utils.getPackageManager)(appDirectory);
110
- const lockfile = import_constants.LOCK_FILE[manager];
111
- (0, import_utils2.copyfile)(distDirectory, appDirectory, [lockfile]);
112
- import_utils.fs.writeFileSync(
113
- import_path.default.join(distDirectory, import_constants.WRANGLER_FILE),
114
- `name = "${pkg.name}"
118
+ import_utils.fs.writeFileSync(import_path.default.join(workServerDir, import_constants.MANIFEST_FILE), manifest);
119
+ const pkg = import_utils.fs.readJSONSync(import_path.default.join(appDirectory, import_constants.PKG_FILE));
120
+ import_utils.fs.writeFileSync(
121
+ import_path.default.join(distDirectory, import_constants.WRANGLER_FILE),
122
+ `name = "${pkg.name}"
115
123
  main = "${import_path.default.join(import_constants.WORKER_SERVER, import_constants.WORKER_SERVER_ENTRY)}"
116
- compatibility_date = "${new Date().toISOString().substring(0, 10)}"
124
+ compatibility_date = "${(/* @__PURE__ */ new Date()).toISOString().substring(0, 10)}"
117
125
  `
118
- );
119
- }
120
- };
121
- }
122
- });
126
+ );
127
+ };
123
128
  // Annotate the CommonJS export names for ESM import in node:
124
129
  0 && (module.exports = {});
@@ -2,14 +2,8 @@ const WORKER_SERVER = "worker-server";
2
2
  const WORKER_SERVER_ENTRY = "index.js";
3
3
  const MANIFEST_FILE = "manifest.js";
4
4
  const PKG_FILE = "package.json";
5
- const LOCK_FILE = {
6
- yarn: "yarn.lock",
7
- npm: "package-lock.json",
8
- pnpm: "pnpm-lock.yaml"
9
- };
10
5
  const WRANGLER_FILE = "wrangler.toml";
11
6
  export {
12
- LOCK_FILE,
13
7
  MANIFEST_FILE,
14
8
  PKG_FILE,
15
9
  WORKER_SERVER,
package/dist/esm/index.js CHANGED
@@ -1,12 +1,6 @@
1
1
  import path from "path";
2
+ import { fs, isServiceWorker, ROUTE_SPEC_FILE } from "@modern-js/utils";
2
3
  import {
3
- fs,
4
- getPackageManager,
5
- isServiceWorker,
6
- ROUTE_SPEC_FILE
7
- } from "@modern-js/utils";
8
- import {
9
- LOCK_FILE,
10
4
  MANIFEST_FILE,
11
5
  PKG_FILE,
12
6
  WORKER_SERVER,
@@ -14,7 +8,6 @@ import {
14
8
  WRANGLER_FILE
15
9
  } from "./constants";
16
10
  import { worker } from "./code";
17
- import { copyfile } from "./utils";
18
11
  var src_default = () => ({
19
12
  name: "@modern-js/plugin-worker",
20
13
  setup: (ctx) => {
@@ -24,47 +17,69 @@ var src_default = () => ({
24
17
  output: {
25
18
  disableNodePolyfill: false
26
19
  }
20
+ // TODO
21
+ // tools: {
22
+ // webpackChain: (chain, { isServiceWorker }) => {
23
+ // if (isServiceWorker) {
24
+ // chain.resolve.alias.set(
25
+ // 'async_hooks',
26
+ // path.resolve(__dirname, './async_hooks'),
27
+ // );
28
+ // }
29
+ // },
30
+ // },
27
31
  };
28
32
  },
29
- async beforeDeploy() {
33
+ async afterDev() {
30
34
  const { appDirectory, distDirectory } = ctx.useAppContext();
31
35
  const configContext = ctx.useResolvedConfigContext();
32
36
  if (!isServiceWorker(configContext)) {
33
37
  return;
34
38
  }
35
- const workServerDir = path.join(distDirectory, WORKER_SERVER);
36
- fs.removeSync(workServerDir);
37
- fs.mkdirSync(workServerDir);
38
- fs.writeFileSync(
39
- path.join(workServerDir, WORKER_SERVER_ENTRY),
40
- worker()
41
- );
42
- const routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
43
- const { routes } = fs.readJSONSync(routeJSON);
44
- let importStr = ``;
45
- let pageStr = ``;
46
- const routeArr = [];
47
- routes.forEach(
48
- (route) => {
49
- if (route.isSSR) {
50
- importStr += `import { serverRender as ${route.entryName}ServerRender } from "../${route.worker}";
39
+ writeWorkerServerFile(appDirectory, distDirectory);
40
+ },
41
+ async afterBuild() {
42
+ const { appDirectory, distDirectory } = ctx.useAppContext();
43
+ const configContext = ctx.useResolvedConfigContext();
44
+ if (!isServiceWorker(configContext)) {
45
+ return;
46
+ }
47
+ writeWorkerServerFile(appDirectory, distDirectory);
48
+ }
49
+ };
50
+ }
51
+ });
52
+ const writeWorkerServerFile = (appDirectory, distDirectory) => {
53
+ const workServerDir = path.join(distDirectory, WORKER_SERVER);
54
+ fs.removeSync(workServerDir);
55
+ fs.mkdirSync(workServerDir);
56
+ fs.writeFileSync(path.join(workServerDir, WORKER_SERVER_ENTRY), worker());
57
+ const routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
58
+ const { routes } = fs.readJSONSync(routeJSON);
59
+ let importStr = ``;
60
+ let pageStr = ``;
61
+ const routeArr = [];
62
+ routes.forEach(
63
+ (route) => {
64
+ if (route.isSSR) {
65
+ importStr += `import { serverRender as ${route.entryName}ServerRender } from "../${route.worker}";
51
66
  `;
52
- }
53
- importStr += `import ${route.entryName}template from "../${route.entryPath}";
67
+ }
68
+ importStr += `import ${route.entryName}template from "../${route.entryPath}";
54
69
  `;
55
- pageStr += `"${route.urlPath}": {
70
+ pageStr += `"${route.urlPath}": {
56
71
  entryName: "${route.entryName}",
57
72
  template: ${route.entryName}template,
58
73
  serverRender: ${route.isSSR ? `${route.entryName}ServerRender` : void 0},
59
74
  },`;
60
- routeArr.push({
61
- entryName: route.entryName,
62
- isSSR: route.isSSR,
63
- urlPath: route.urlPath
64
- });
65
- }
66
- );
67
- const manifest = `
75
+ routeArr.push({
76
+ entryName: route.entryName,
77
+ isSSR: route.isSSR,
78
+ urlPath: route.urlPath
79
+ });
80
+ }
81
+ );
82
+ const manifest = `
68
83
  ${importStr}
69
84
 
70
85
  export const manifest = {
@@ -74,36 +89,16 @@ export const manifest = {
74
89
  routes: ${JSON.stringify(routeArr, null, " ")}
75
90
  }
76
91
  `;
77
- fs.writeFileSync(path.join(workServerDir, MANIFEST_FILE), manifest);
78
- const pkg = fs.readJSONSync(path.join(appDirectory, PKG_FILE));
79
- await fs.writeJSON(
80
- path.join(distDirectory, PKG_FILE),
81
- {
82
- name: pkg.name,
83
- version: pkg.version,
84
- dependencies: {
85
- "@modern-js/prod-server": "0.0.0-next-20230209112307",
86
- wrangler: "^2.9.0"
87
- },
88
- resolutions: pkg.resolutions || {},
89
- pnpm: pkg.pnpm || {}
90
- },
91
- { spaces: 2 }
92
- );
93
- const manager = await getPackageManager(appDirectory);
94
- const lockfile = LOCK_FILE[manager];
95
- copyfile(distDirectory, appDirectory, [lockfile]);
96
- fs.writeFileSync(
97
- path.join(distDirectory, WRANGLER_FILE),
98
- `name = "${pkg.name}"
92
+ fs.writeFileSync(path.join(workServerDir, MANIFEST_FILE), manifest);
93
+ const pkg = fs.readJSONSync(path.join(appDirectory, PKG_FILE));
94
+ fs.writeFileSync(
95
+ path.join(distDirectory, WRANGLER_FILE),
96
+ `name = "${pkg.name}"
99
97
  main = "${path.join(WORKER_SERVER, WORKER_SERVER_ENTRY)}"
100
- compatibility_date = "${new Date().toISOString().substring(0, 10)}"
98
+ compatibility_date = "${(/* @__PURE__ */ new Date()).toISOString().substring(0, 10)}"
101
99
  `
102
- );
103
- }
104
- };
105
- }
106
- });
100
+ );
101
+ };
107
102
  export {
108
103
  src_default as default
109
104
  };
@@ -2,5 +2,4 @@ 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 LOCK_FILE: Record<string, string>;
6
5
  export declare const WRANGLER_FILE = "wrangler.toml";
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.5.0",
14
+ "version": "2.6.0",
15
15
  "types": "./dist/types/index.d.ts",
16
16
  "jsnext:source": "./src/index.ts",
17
17
  "main": "./dist/cjs/index.js",
@@ -37,19 +37,20 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@babel/runtime": "^7.18.0",
40
- "@modern-js/utils": "2.5.0",
41
- "@modern-js/server-utils": "2.5.0"
40
+ "@modern-js/server-utils": "2.6.0",
41
+ "@modern-js/utils": "2.6.0",
42
+ "@modern-js/prod-server": "2.6.0"
42
43
  },
43
44
  "devDependencies": {
44
45
  "typescript": "^4",
45
46
  "@types/jest": "^27",
46
47
  "@types/node": "^14",
47
48
  "jest": "^27",
48
- "@modern-js/app-tools": "2.5.0",
49
- "@modern-js/core": "2.5.0",
50
- "@modern-js/types": "2.5.0",
51
- "@scripts/build": "2.5.0",
52
- "@scripts/jest-config": "2.5.0"
49
+ "@modern-js/app-tools": "2.6.0",
50
+ "@modern-js/types": "2.6.0",
51
+ "@modern-js/core": "2.6.0",
52
+ "@scripts/jest-config": "2.6.0",
53
+ "@scripts/build": "2.6.0"
53
54
  },
54
55
  "sideEffects": [
55
56
  "*.css",
package/dist/cjs/utils.js DELETED
@@ -1,59 +0,0 @@
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
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
23
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var utils_exports = {};
25
- __export(utils_exports, {
26
- copyfile: () => copyfile
27
- });
28
- module.exports = __toCommonJS(utils_exports);
29
- var import_path = __toESM(require("path"));
30
- var import_utils = require("@modern-js/utils");
31
- const copyfile = (target, source, fl) => {
32
- fl.forEach((ff) => {
33
- if (!ff) {
34
- return;
35
- }
36
- if (typeof ff === "string") {
37
- cpfile(target, source, ff);
38
- return;
39
- }
40
- const sourceIncludeFiles = import_utils.fs.readdirSync(source);
41
- for (const filename of sourceIncludeFiles) {
42
- if (ff.test(filename)) {
43
- cpfile(target, source, filename);
44
- }
45
- }
46
- });
47
- function cpfile(target2, source2, filename) {
48
- const filepath = import_path.default.join(source2, filename);
49
- if (!import_utils.fs.existsSync(filepath)) {
50
- return;
51
- }
52
- const targetPath = import_path.default.join(target2, filename);
53
- import_utils.fs.copySync(filepath, targetPath);
54
- }
55
- };
56
- // Annotate the CommonJS export names for ESM import in node:
57
- 0 && (module.exports = {
58
- copyfile
59
- });
package/dist/esm/utils.js DELETED
@@ -1,30 +0,0 @@
1
- import path from "path";
2
- import { fs } from "@modern-js/utils";
3
- const copyfile = (target, source, fl) => {
4
- fl.forEach((ff) => {
5
- if (!ff) {
6
- return;
7
- }
8
- if (typeof ff === "string") {
9
- cpfile(target, source, ff);
10
- return;
11
- }
12
- const sourceIncludeFiles = fs.readdirSync(source);
13
- for (const filename of sourceIncludeFiles) {
14
- if (ff.test(filename)) {
15
- cpfile(target, source, filename);
16
- }
17
- }
18
- });
19
- function cpfile(target2, source2, filename) {
20
- const filepath = path.join(source2, filename);
21
- if (!fs.existsSync(filepath)) {
22
- return;
23
- }
24
- const targetPath = path.join(target2, filename);
25
- fs.copySync(filepath, targetPath);
26
- }
27
- };
28
- export {
29
- copyfile
30
- };
@@ -1 +0,0 @@
1
- export declare const copyfile: (target: string, source: string, fl: (string | RegExp)[]) => void;