@eggjs/bin 7.3.1 → 7.4.0-beta.10

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.
Files changed (58) hide show
  1. package/README.md +3 -21
  2. package/bin/dev.js +0 -0
  3. package/dist/baseCommand.d.ts +52 -0
  4. package/dist/baseCommand.js +288 -0
  5. package/dist/commands/cov.d.ts +27 -0
  6. package/dist/commands/cov.js +86 -0
  7. package/dist/commands/dev.d.ts +26 -0
  8. package/dist/commands/dev.js +86 -0
  9. package/dist/commands/test.d.ts +28 -0
  10. package/dist/commands/test.js +168 -0
  11. package/dist/index.d.ts +7 -0
  12. package/dist/index.js +8 -0
  13. package/dist/scripts/postinstall.mjs +9 -6
  14. package/dist/scripts/start-cluster.cjs +3 -2
  15. package/dist/scripts/start-cluster.mjs +3 -2
  16. package/{src/types.ts → dist/types.d.ts} +4 -1
  17. package/dist/utils.js +34 -0
  18. package/package.json +54 -73
  19. package/scripts/postinstall.mjs +9 -6
  20. package/scripts/start-cluster.cjs +3 -2
  21. package/scripts/start-cluster.mjs +3 -2
  22. package/dist/commonjs/baseCommand.d.ts +0 -49
  23. package/dist/commonjs/baseCommand.js +0 -374
  24. package/dist/commonjs/commands/cov.d.ts +0 -22
  25. package/dist/commonjs/commands/cov.js +0 -98
  26. package/dist/commonjs/commands/dev.d.ts +0 -21
  27. package/dist/commonjs/commands/dev.js +0 -101
  28. package/dist/commonjs/commands/test.d.ts +0 -23
  29. package/dist/commonjs/commands/test.js +0 -222
  30. package/dist/commonjs/index.d.ts +0 -7
  31. package/dist/commonjs/index.js +0 -30
  32. package/dist/commonjs/package.json +0 -3
  33. package/dist/commonjs/types.d.ts +0 -9
  34. package/dist/commonjs/types.js +0 -3
  35. package/dist/commonjs/utils.d.ts +0 -4
  36. package/dist/commonjs/utils.js +0 -45
  37. package/dist/esm/baseCommand.d.ts +0 -49
  38. package/dist/esm/baseCommand.js +0 -366
  39. package/dist/esm/commands/cov.d.ts +0 -22
  40. package/dist/esm/commands/cov.js +0 -92
  41. package/dist/esm/commands/dev.d.ts +0 -21
  42. package/dist/esm/commands/dev.js +0 -98
  43. package/dist/esm/commands/test.d.ts +0 -23
  44. package/dist/esm/commands/test.js +0 -216
  45. package/dist/esm/index.d.ts +0 -7
  46. package/dist/esm/index.js +0 -8
  47. package/dist/esm/package.json +0 -3
  48. package/dist/esm/types.d.ts +0 -9
  49. package/dist/esm/types.js +0 -2
  50. package/dist/esm/utils.d.ts +0 -4
  51. package/dist/esm/utils.js +0 -36
  52. package/dist/package.json +0 -4
  53. package/src/baseCommand.ts +0 -395
  54. package/src/commands/cov.ts +0 -101
  55. package/src/commands/dev.ts +0 -106
  56. package/src/commands/test.ts +0 -236
  57. package/src/index.ts +0 -9
  58. package/src/utils.ts +0 -37
@@ -0,0 +1,168 @@
1
+ import { BaseCommand } from "../baseCommand.js";
2
+ import { debuglog } from "node:util";
3
+ import path from "node:path";
4
+ import os from "node:os";
5
+ import fs from "node:fs/promises";
6
+ import { Args, Flags } from "@oclif/core";
7
+ import globby from "globby";
8
+ import { EggType, detectType, importResolve } from "@eggjs/utils";
9
+ import { getChangedFilesForRoots } from "jest-changed-files";
10
+ import ciParallelVars from "ci-parallel-vars";
11
+
12
+ //#region src/commands/test.ts
13
+ const debug = debuglog("egg-bin/commands/test");
14
+ var Test = class extends BaseCommand {
15
+ static args = { file: Args.string({ description: "file(s) to test" }) };
16
+ static description = "Run the test";
17
+ static examples = [
18
+ "<%= config.bin %> <%= command.id %>",
19
+ "<%= config.bin %> <%= command.id %> test/index.test.ts",
20
+ "<%= config.bin %> <%= command.id %> test/index.test.ts,test/user.test.ts,...",
21
+ "<%= config.bin %> <%= command.id %> --json",
22
+ "<%= config.bin %> <%= command.id %> --log-level debug"
23
+ ];
24
+ static flags = {
25
+ bail: Flags.boolean({
26
+ description: "bbort (\"bail\") after first test failure",
27
+ default: false,
28
+ char: "b"
29
+ }),
30
+ timeout: Flags.integer({
31
+ char: "t",
32
+ description: "set test-case timeout in milliseconds",
33
+ default: parseInt(process.env.TEST_TIMEOUT ?? "60000")
34
+ }),
35
+ "no-timeout": Flags.boolean({ description: "disable timeout" }),
36
+ grep: Flags.string({
37
+ char: "g",
38
+ description: "only run tests matching <pattern>"
39
+ }),
40
+ changed: Flags.boolean({
41
+ description: "only test with changed files and match test/**/*.test.(js|ts)",
42
+ char: "c"
43
+ }),
44
+ mochawesome: Flags.boolean({
45
+ description: "[default: true] enable mochawesome reporter",
46
+ default: true,
47
+ allowNo: true
48
+ }),
49
+ parallel: Flags.boolean({
50
+ description: "mocha parallel mode",
51
+ default: false,
52
+ char: "p"
53
+ }),
54
+ jobs: Flags.integer({
55
+ char: "t",
56
+ description: "number of jobs to run in parallel",
57
+ default: os.cpus().length - 1
58
+ }),
59
+ "auto-agent": Flags.boolean({
60
+ description: "[default: true] auto bootstrap agent in mocha master process",
61
+ default: true,
62
+ allowNo: true
63
+ })
64
+ };
65
+ async run() {
66
+ const { flags } = this;
67
+ try {
68
+ await fs.access(flags.base);
69
+ } catch (err) {
70
+ console.error("baseDir: %o not exists", flags.base);
71
+ throw err;
72
+ }
73
+ const mochaFile = process.env.MOCHA_FILE || importResolve("mocha/bin/_mocha");
74
+ if (flags.parallel) {
75
+ this.env.ENABLE_MOCHA_PARALLEL = "true";
76
+ if (flags["auto-agent"]) this.env.AUTO_AGENT = "true";
77
+ }
78
+ this.env.NODE_ENV = "test";
79
+ if (flags["no-timeout"]) flags.timeout = 0;
80
+ debug("run test: %s %o flags: %o", mochaFile, this.args, flags);
81
+ const mochaArgs = await this.formatMochaArgs();
82
+ if (!mochaArgs) return;
83
+ await this.runMocha(mochaFile, mochaArgs);
84
+ }
85
+ async runMocha(mochaFile, mochaArgs) {
86
+ await this.forkNode(mochaFile, mochaArgs, { execArgv: [...process.execArgv, "--unhandled-rejections=strict"] });
87
+ }
88
+ async formatMochaArgs() {
89
+ const { args, flags } = this;
90
+ const requires = await this.formatRequires();
91
+ const eggType = await detectType(flags.base);
92
+ debug("eggType: %s", eggType);
93
+ if (eggType === EggType.application) try {
94
+ const eggMockRegister = importResolve("@eggjs/mock/register", { paths: [flags.base] });
95
+ requires.push(eggMockRegister);
96
+ debug("auto register @eggjs/mock/register: %o", eggMockRegister);
97
+ } catch (err) {
98
+ debug("auto register @eggjs/mock fail, can not require @eggjs/mock on %o, error: %s", flags.base, err.message);
99
+ }
100
+ let reporter = this.env.TEST_REPORTER;
101
+ let reporterOptions = "";
102
+ if (!reporter && flags.mochawesome) {
103
+ reporter = importResolve("mochawesome-with-mocha", { paths: [flags.base] });
104
+ reporterOptions = "reportDir=node_modules/.mochawesome-reports";
105
+ if (flags.parallel) requires.push(path.join(reporter, "../register.js"));
106
+ }
107
+ const ext = flags.typescript ? "ts" : "js";
108
+ let pattern = args.file ? args.file.split(",") : [];
109
+ if (flags.changed) {
110
+ pattern = await this.getChangedTestFiles(flags.base, ext);
111
+ if (!pattern.length) {
112
+ console.log("No changed test files");
113
+ return;
114
+ }
115
+ debug("changed files: %o", pattern);
116
+ }
117
+ if (!pattern.length && process.env.TESTS) pattern = process.env.TESTS.split(",");
118
+ if (!pattern.length) pattern = [`test/**/*.test.${ext}`];
119
+ pattern = pattern.concat(["!test/fixtures", "!test/node_modules"]);
120
+ let files = globby.sync(pattern, { cwd: flags.base });
121
+ files.sort();
122
+ if (files.length === 0) {
123
+ console.log("No test files found with pattern %o", pattern);
124
+ return;
125
+ }
126
+ if (ciParallelVars) {
127
+ const { index: currentIndex, total: totalRuns } = ciParallelVars;
128
+ const fileCount = files.length;
129
+ const each = Math.floor(fileCount / totalRuns);
130
+ const remainder = fileCount % totalRuns;
131
+ const offset = Math.min(currentIndex, remainder) + currentIndex * each;
132
+ const currentFileCount = each + (currentIndex < remainder ? 1 : 0);
133
+ files = files.slice(offset, offset + currentFileCount);
134
+ console.log("# Split test files in parallel CI jobs: %d/%d, files: %d/%d", currentIndex + 1, totalRuns, files.length, fileCount);
135
+ }
136
+ const setupFile = path.join(flags.base, `test/.setup.${ext}`);
137
+ try {
138
+ await fs.access(setupFile);
139
+ files.unshift(setupFile);
140
+ } catch {}
141
+ const grep = flags.grep ? flags.grep.split(",") : [];
142
+ return [
143
+ "--exit",
144
+ flags.bail ? "--bail" : "",
145
+ grep.map((pattern$1) => `--grep='${pattern$1}'`).join(" "),
146
+ flags.timeout ? `--timeout=${flags.timeout}` : "--no-timeout",
147
+ flags.parallel ? "--parallel" : "",
148
+ flags.parallel && flags.jobs ? `--jobs=${flags.jobs}` : "",
149
+ reporter ? `--reporter=${reporter}` : "",
150
+ reporterOptions ? `--reporter-options=${reporterOptions}` : "",
151
+ ...requires.map((r) => `--require=${r}`),
152
+ ...files,
153
+ flags["dry-run"] ? "--dry-run" : ""
154
+ ].filter((a) => a.trim());
155
+ }
156
+ async getChangedTestFiles(dir, ext) {
157
+ const changedFiles = (await getChangedFilesForRoots([path.join(dir, "test")], {})).changedFiles;
158
+ const files = [];
159
+ for (let cf of changedFiles) if (cf.endsWith(`.test.${ext}`)) {
160
+ if (process.platform === "win32") cf = cf.replace(/\\/g, "/");
161
+ files.push(cf);
162
+ }
163
+ return files;
164
+ }
165
+ };
166
+
167
+ //#endregion
168
+ export { Test as default };
@@ -0,0 +1,7 @@
1
+ import { PackageEgg } from "./types.js";
2
+ import { BaseCommand, ForkError, ForkNodeOptions } from "./baseCommand.js";
3
+ import { Test } from "./commands/test.js";
4
+ import { Cov } from "./commands/cov.js";
5
+ import { Dev } from "./commands/dev.js";
6
+ export * from "@oclif/core";
7
+ export { BaseCommand, Cov, Dev, ForkError, ForkNodeOptions, PackageEgg, Test };
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import { BaseCommand, ForkError } from "./baseCommand.js";
2
+ import Test from "./commands/test.js";
3
+ import Cov from "./commands/cov.js";
4
+ import Dev from "./commands/dev.js";
5
+
6
+ export * from "@oclif/core"
7
+
8
+ export { BaseCommand, Cov, Dev, ForkError, Test };
@@ -1,11 +1,12 @@
1
1
  import { debuglog } from 'node:util';
2
2
  import path from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
+
4
5
  import { runScript } from 'runscript';
5
6
  import { readJSON, exists } from 'utility';
6
7
  import { importResolve } from '@eggjs/utils';
7
8
 
8
- const debug = debuglog('@eggjs/bin/scripts/postinstall');
9
+ const debug = debuglog('egg-bin/scripts/postinstall');
9
10
 
10
11
  const __filename = fileURLToPath(import.meta.url);
11
12
  const __dirname = path.dirname(__filename);
@@ -13,9 +14,11 @@ const rootDir = path.dirname(__dirname);
13
14
 
14
15
  async function main() {
15
16
  // node postintall.js </path/to/egg-ts-helper/dist/bin> <framework-package-name>
16
- const etsBinFile = process.argv[2] || importResolve('egg-ts-helper/dist/bin.js', {
17
- paths: [ rootDir ],
18
- });
17
+ const etsBinFile =
18
+ process.argv[2] ||
19
+ importResolve('egg-ts-helper/dist/bin.js', {
20
+ paths: [rootDir],
21
+ });
19
22
  const frameworkPackageName = process.argv[3] || 'egg';
20
23
 
21
24
  // try to use INIT_CWD env https://docs.npmjs.com/cli/v9/commands/npm-run-script
@@ -52,9 +55,9 @@ async function main() {
52
55
  // https://github.com/eggjs/egg-ts-helper/pull/104
53
56
  process.env.ETS_SCRIPT_FRAMEWORK = frameworkPackageName;
54
57
  console.log('[@eggjs/bin/postinstall] run %s on %s', etsBinFile, npmRunRoot);
55
- runScript(`node "${etsBinFile}"`);
58
+ await runScript(`node "${etsBinFile}"`);
56
59
  }
57
60
  }
58
61
  }
59
62
 
60
- main();
63
+ void main();
@@ -1,8 +1,9 @@
1
1
  /* eslint-disable @typescript-eslint/no-var-requires */
2
2
  const { debuglog } = require('node:util');
3
+
3
4
  const { importModule } = require('@eggjs/utils');
4
5
 
5
- const debug = debuglog('@eggjs/bin/scripts/start-cluster');
6
+ const debug = debuglog('egg-bin/scripts/start-cluster');
6
7
 
7
8
  async function main() {
8
9
  debug('argv: %o', process.argv);
@@ -12,4 +13,4 @@ async function main() {
12
13
  await startCluster(options);
13
14
  }
14
15
 
15
- main();
16
+ void main();
@@ -1,7 +1,8 @@
1
1
  import { debuglog } from 'node:util';
2
+
2
3
  import { importModule } from '@eggjs/utils';
3
4
 
4
- const debug = debuglog('@eggjs/bin/scripts/start-cluster');
5
+ const debug = debuglog('egg-bin/scripts/start-cluster');
5
6
 
6
7
  async function main() {
7
8
  debug('argv: %o', process.argv);
@@ -11,4 +12,4 @@ async function main() {
11
12
  await startCluster(options);
12
13
  }
13
14
 
14
- main();
15
+ void main();
@@ -1,4 +1,5 @@
1
- export interface PackageEgg {
1
+ //#region src/types.d.ts
2
+ interface PackageEgg {
2
3
  framework?: boolean;
3
4
  typescript?: boolean;
4
5
  tscompiler?: string;
@@ -7,3 +8,5 @@ export interface PackageEgg {
7
8
  require?: string | string[];
8
9
  import?: string | string[];
9
10
  }
11
+ //#endregion
12
+ export { PackageEgg };
package/dist/utils.js ADDED
@@ -0,0 +1,34 @@
1
+ import path from "node:path";
2
+ import fs from "node:fs/promises";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ //#region src/utils.ts
6
+ async function readPackageJSON(baseDir) {
7
+ const pkgFile = path.join(baseDir, "package.json");
8
+ try {
9
+ const pkgJSON = await fs.readFile(pkgFile, "utf8");
10
+ return JSON.parse(pkgJSON);
11
+ } catch {
12
+ return {};
13
+ }
14
+ }
15
+ async function hasTsConfig(baseDir) {
16
+ const pkgFile = path.join(baseDir, "tsconfig.json");
17
+ try {
18
+ await fs.access(pkgFile);
19
+ return true;
20
+ } catch {
21
+ return false;
22
+ }
23
+ }
24
+ function getSourceDirname() {
25
+ if (typeof __dirname === "string") return __dirname;
26
+ const __filename = fileURLToPath(import.meta.url);
27
+ return path.dirname(__filename);
28
+ }
29
+ function getSourceFilename(filename) {
30
+ return path.join(getSourceDirname(), filename);
31
+ }
32
+
33
+ //#endregion
34
+ export { getSourceDirname, getSourceFilename, hasTsConfig, readPackageJSON };
package/package.json CHANGED
@@ -1,42 +1,43 @@
1
1
  {
2
2
  "name": "@eggjs/bin",
3
- "version": "7.3.1",
3
+ "version": "7.4.0-beta.10",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
7
  "description": "egg developer tool",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git@github.com:eggjs/bin.git"
10
+ "url": "git://github.com/eggjs/egg.git",
11
+ "directory": "tools/egg-bin"
11
12
  },
12
- "bug": {
13
+ "bugs": {
13
14
  "url": "https://github.com/eggjs/egg/issues"
14
15
  },
15
- "homepage": "https://github.com/eggjs/bin",
16
+ "homepage": "https://github.com/eggjs/egg/tree/next/tools/egg-bin",
16
17
  "author": "fengmk2 <fengmk2@gmail.com> (https://github.com/fengmk2)",
17
18
  "engines": {
18
- "node": ">= 18.19.0"
19
+ "node": ">= 20.19.0"
19
20
  },
20
21
  "dependencies": {
21
- "@eggjs/utils": "^4.2.0",
22
22
  "@oclif/core": "^4.2.0",
23
23
  "@types/mocha": "^10.0.10",
24
- "@types/supertest": "^6.0.2",
25
- "c8": "^10.0.0",
24
+ "c8": "10.1.3",
26
25
  "ci-parallel-vars": "^1.0.1",
27
- "detect-port": "^2.0.0",
26
+ "detect-port": "^2.1.0",
28
27
  "egg-ts-helper": "^3.0.0",
29
- "globby": "^11.1.0",
30
- "jest-changed-files": "^29.4.2",
31
- "mocha": "^11.0.1",
32
- "mochawesome-with-mocha": "^8.0.0",
33
- "runscript": "^2.0.0",
28
+ "globby": "^11.0.2",
29
+ "jest-changed-files": "^30.0.0",
30
+ "mocha": "11.7.2",
31
+ "mochawesome-with-mocha": "8.0.0",
32
+ "runscript": "^2.0.1",
34
33
  "ts-node": "^10.9.2",
35
- "tsconfig-paths": "^4.1.2",
36
- "utility": "^2.4.0"
34
+ "tsconfig-paths": "^4.2.0",
35
+ "utility": "^2.5.0",
36
+ "@eggjs/utils": "4.5.0-beta.10",
37
+ "@eggjs/supertest": "8.3.0-beta.10"
37
38
  },
38
39
  "peerDependencies": {
39
- "@eggjs/mock": "6"
40
+ "@eggjs/mock": "6.1.0-beta.10"
40
41
  },
41
42
  "peerDependenciesMeta": {
42
43
  "@eggjs/mock": {
@@ -44,80 +45,60 @@
44
45
  }
45
46
  },
46
47
  "devDependencies": {
47
- "@arethetypeswrong/cli": "^0.17.1",
48
- "@eggjs/mock": "6",
49
- "@eggjs/tsconfig": "1",
50
- "@swc-node/register": "^1.6.1",
51
- "@swc/core": "^1.3.35",
52
- "@types/node": "22",
53
- "assert-file": "^1.0.0",
54
- "coffee": "^5.5.1",
55
- "cpy": "^8.1.2",
56
- "cpy-cli": "^5.0.0",
57
- "cross-env": "^7.0.3",
58
- "egg": "^4.0.7",
48
+ "@swc-node/register": "^1.11.1",
49
+ "@swc/core": "^1.13.5",
50
+ "@types/node": "24.5.2",
51
+ "assert-file": "1",
52
+ "coffee": "5",
53
+ "cpy": "^12.0.0",
54
+ "cpy-cli": "^6.0.0",
55
+ "cross-env": "^10.0.0",
59
56
  "esbuild": "^0.25.0",
60
57
  "esbuild-register": "^3.6.0",
61
- "eslint": "8",
62
- "eslint-config-egg": "14",
63
58
  "npminstall": "^7.12.0",
64
- "rimraf": "6",
65
- "supertest": "^7.0.0",
66
- "tshy": "3",
67
- "tshy-after": "1",
68
- "typescript": "5"
69
- },
70
- "scripts": {
71
- "postinstall": "node scripts/postinstall.mjs",
72
- "lint": "eslint --cache src test --ext .ts",
73
- "pretest": "npm run clean && npm run lint -- --fix && npm run prepublishOnly",
74
- "test": "node bin/run.js test",
75
- "cov": "c8 --temp-directory node_modules/.c8_output -r text-summary -r json-summary -r json -r lcov -r cobertura node bin/run.js test",
76
- "preci": "npm run clean && npm run lint && npm run prepublishOnly",
77
- "ci": "npm run cov",
78
- "clean": "rimraf dist",
79
- "copyScripts": "rimraf dist/scripts && cpy scripts dist",
80
- "prepublishOnly": "tshy && tshy-after && attw --pack && npm run copyScripts"
59
+ "rimraf": "^6.0.1",
60
+ "typescript": "5.9.2",
61
+ "tsdown": "^0.15.4",
62
+ "@eggjs/mock": "6.1.0-beta.10",
63
+ "@eggjs/tsconfig": "3.1.0-beta.10",
64
+ "egg": "4.1.0-beta.10"
81
65
  },
82
66
  "type": "module",
83
- "tshy": {
84
- "exports": {
85
- ".": "./src/index.ts",
86
- "./package.json": "./package.json"
87
- }
88
- },
89
- "exports": {
90
- ".": {
91
- "import": {
92
- "types": "./dist/esm/index.d.ts",
93
- "default": "./dist/esm/index.js"
94
- },
95
- "require": {
96
- "types": "./dist/commonjs/index.d.ts",
97
- "default": "./dist/commonjs/index.js"
98
- }
99
- },
100
- "./package.json": "./package.json"
101
- },
102
67
  "files": [
103
68
  "bin",
104
69
  "dist",
105
- "src",
106
70
  "scripts"
107
71
  ],
108
72
  "bin": {
109
73
  "egg-bin": "./bin/run.js"
110
74
  },
111
- "types": "./dist/commonjs/index.d.ts",
112
- "main": "./dist/commonjs/index.js",
113
- "module": "./dist/esm/index.js",
114
75
  "oclif": {
115
76
  "bin": "egg-bin",
116
- "commands": "./dist/esm/commands",
77
+ "commands": "./dist/commands",
117
78
  "dirname": "egg-bin",
118
79
  "topicSeparator": " ",
119
80
  "additionalHelpFlags": [
120
81
  "-h"
121
82
  ]
83
+ },
84
+ "main": "./dist/index.js",
85
+ "module": "./dist/index.js",
86
+ "types": "./dist/index.d.ts",
87
+ "exports": {
88
+ ".": "./dist/index.js",
89
+ "./package.json": "./package.json"
90
+ },
91
+ "scripts": {
92
+ "postinstall": "node scripts/postinstall.mjs",
93
+ "lint": "oxlint --type-aware",
94
+ "typecheck": "tsc --noEmit",
95
+ "pretest": "npm run clean && npm run lint -- --fix && npm run prepublishOnly",
96
+ "test": "node bin/run.js test",
97
+ "cov": "c8 --temp-directory node_modules/.c8_output -r text-summary -r json-summary -r json -r lcov -r cobertura node bin/run.js test",
98
+ "preci": "npm run clean && npm run lint && npm run prepublishOnly",
99
+ "ci": "npm run cov",
100
+ "clean": "rimraf dist",
101
+ "copyScripts": "rimraf dist/scripts && cpy scripts dist",
102
+ "build": "tsdown"
122
103
  }
123
- }
104
+ }
@@ -1,11 +1,12 @@
1
1
  import { debuglog } from 'node:util';
2
2
  import path from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
+
4
5
  import { runScript } from 'runscript';
5
6
  import { readJSON, exists } from 'utility';
6
7
  import { importResolve } from '@eggjs/utils';
7
8
 
8
- const debug = debuglog('@eggjs/bin/scripts/postinstall');
9
+ const debug = debuglog('egg-bin/scripts/postinstall');
9
10
 
10
11
  const __filename = fileURLToPath(import.meta.url);
11
12
  const __dirname = path.dirname(__filename);
@@ -13,9 +14,11 @@ const rootDir = path.dirname(__dirname);
13
14
 
14
15
  async function main() {
15
16
  // node postintall.js </path/to/egg-ts-helper/dist/bin> <framework-package-name>
16
- const etsBinFile = process.argv[2] || importResolve('egg-ts-helper/dist/bin.js', {
17
- paths: [ rootDir ],
18
- });
17
+ const etsBinFile =
18
+ process.argv[2] ||
19
+ importResolve('egg-ts-helper/dist/bin.js', {
20
+ paths: [rootDir],
21
+ });
19
22
  const frameworkPackageName = process.argv[3] || 'egg';
20
23
 
21
24
  // try to use INIT_CWD env https://docs.npmjs.com/cli/v9/commands/npm-run-script
@@ -52,9 +55,9 @@ async function main() {
52
55
  // https://github.com/eggjs/egg-ts-helper/pull/104
53
56
  process.env.ETS_SCRIPT_FRAMEWORK = frameworkPackageName;
54
57
  console.log('[@eggjs/bin/postinstall] run %s on %s', etsBinFile, npmRunRoot);
55
- runScript(`node "${etsBinFile}"`);
58
+ await runScript(`node "${etsBinFile}"`);
56
59
  }
57
60
  }
58
61
  }
59
62
 
60
- main();
63
+ void main();
@@ -1,8 +1,9 @@
1
1
  /* eslint-disable @typescript-eslint/no-var-requires */
2
2
  const { debuglog } = require('node:util');
3
+
3
4
  const { importModule } = require('@eggjs/utils');
4
5
 
5
- const debug = debuglog('@eggjs/bin/scripts/start-cluster');
6
+ const debug = debuglog('egg-bin/scripts/start-cluster');
6
7
 
7
8
  async function main() {
8
9
  debug('argv: %o', process.argv);
@@ -12,4 +13,4 @@ async function main() {
12
13
  await startCluster(options);
13
14
  }
14
15
 
15
- main();
16
+ void main();
@@ -1,7 +1,8 @@
1
1
  import { debuglog } from 'node:util';
2
+
2
3
  import { importModule } from '@eggjs/utils';
3
4
 
4
- const debug = debuglog('@eggjs/bin/scripts/start-cluster');
5
+ const debug = debuglog('egg-bin/scripts/start-cluster');
5
6
 
6
7
  async function main() {
7
8
  debug('argv: %o', process.argv);
@@ -11,4 +12,4 @@ async function main() {
11
12
  await startCluster(options);
12
13
  }
13
14
 
14
- main();
15
+ void main();
@@ -1,49 +0,0 @@
1
- import { ForkOptions } from 'node:child_process';
2
- import { Command, Flags, Interfaces } from '@oclif/core';
3
- import { PackageEgg } from './types.js';
4
- export declare class ForkError extends Error {
5
- code: number | null;
6
- constructor(message: string, code: number | null);
7
- }
8
- export interface ForkNodeOptions extends ForkOptions {
9
- dryRun?: boolean;
10
- }
11
- type Flags<T extends typeof Command> = Interfaces.InferredFlags<typeof BaseCommand['baseFlags'] & T['flags']>;
12
- type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
13
- export declare abstract class BaseCommand<T extends typeof Command> extends Command {
14
- #private;
15
- static enableJsonFlag: boolean;
16
- static baseFlags: {
17
- 'dry-run': Interfaces.BooleanFlag<boolean>;
18
- require: Interfaces.OptionFlag<string[] | undefined, Interfaces.CustomOptions>;
19
- import: Interfaces.OptionFlag<string[] | undefined, Interfaces.CustomOptions>;
20
- base: Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
21
- tscompiler: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
22
- typescript: Interfaces.BooleanFlag<boolean>;
23
- ts: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
24
- javascript: Interfaces.BooleanFlag<boolean>;
25
- declarations: Interfaces.BooleanFlag<boolean>;
26
- inspect: Interfaces.BooleanFlag<boolean>;
27
- 'inspect-brk': Interfaces.BooleanFlag<boolean>;
28
- };
29
- protected flags: Flags<T>;
30
- protected args: Args<T>;
31
- protected env: {
32
- [key: string]: string | undefined;
33
- TZ?: string;
34
- };
35
- protected pkg: Record<string, any>;
36
- protected isESM: boolean;
37
- protected pkgEgg: PackageEgg;
38
- protected globalExecArgv: string[];
39
- init(): Promise<void>;
40
- protected catch(err: Error & {
41
- exitCode?: number;
42
- }): Promise<any>;
43
- protected finally(_: Error | undefined): Promise<any>;
44
- protected formatRequires(): Promise<string[]>;
45
- protected formatImportModule(modulePath: string): string;
46
- protected addNodeOptions(options: string): void;
47
- protected forkNode(modulePath: string, forkArgs: string[], options?: ForkNodeOptions): Promise<void>;
48
- }
49
- export {};