@appweaver/cli 1.0.13 → 1.0.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appweaver/cli",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Appweaver - the backend framework for AI-first development (@cli)",
5
5
  "author": "Luka Matosevic",
6
6
  "license": "MIT",
@@ -34,10 +34,10 @@
34
34
  "@sinclair/typebox": "0.34.49",
35
35
  "@sinclair/typebox-codegen": "0.11.1",
36
36
  "commander": "15.0.0",
37
+ "fkill": "10.0.3",
37
38
  "glob": "13.0.6",
38
39
  "prettier": "3.8.4",
39
40
  "rimraf": "6.1.3",
40
- "tree-kill": "1.2.2",
41
41
  "ts-node": "10.9.2",
42
42
  "tsc-alias": "1.8.17",
43
43
  "tsc-watch": "7.2.0"
@@ -69,18 +69,19 @@ async function startBunProject(mainFilePath, watch) {
69
69
  */
70
70
  async function watchNodeProject(mainFilePath, projectFile) {
71
71
  let abortController;
72
+ let runningProcess;
72
73
  const watch = new client_1.TscWatchClient();
73
74
  // Handler for every successful compilation of watched code, aborts previous
74
75
  // process and starts a new one
75
76
  watch.on('success', async () => {
76
- if (abortController) {
77
- abortController.abort();
78
- }
77
+ abortController?.abort();
78
+ // Wait for the previous process to fully terminate before starting a new one
79
+ await runningProcess;
79
80
  abortController = new AbortController();
80
81
  // Replace import alias paths in compiled code
81
82
  await (0, tsc_alias_1.replaceTscAliasPaths)({ configFile: projectFile });
82
83
  // Start the main application process
83
- await (0, utils_1.runProcess)('node', [mainFilePath], {
84
+ runningProcess = (0, utils_1.runProcess)('node', [mainFilePath], {
84
85
  signal: abortController.signal
85
86
  });
86
87
  });
@@ -116,9 +117,7 @@ async function watchBunProcess() {
116
117
  let debounceTimer;
117
118
  // Starts a new process and aborts the previous one
118
119
  async function start() {
119
- if (abortController) {
120
- abortController.abort();
121
- }
120
+ abortController?.abort();
122
121
  abortController = new AbortController();
123
122
  await (0, utils_1.runProcess)('bun', [common_1.config.APP_MAIN_FILE_PATH], {
124
123
  signal: abortController.signal
@@ -6,7 +6,7 @@
6
6
  * @param {Object} [params={ quiet: false }] - Configurations for how the process should run.
7
7
  * @param {boolean} [params.quiet=false] - If true, suppresses the process output.
8
8
  * @param {AbortSignal} [params.signal] - Optional AbortSignal to terminate the running process.
9
- * @return {Promise<number>} A promise that resolves with the exit code of the process or 1 on error.
9
+ * @return {Promise<number>} A promise that resolves with the exit code of the process.
10
10
  */
11
11
  export declare function runProcess(cmd: string, args?: string[], params?: {
12
12
  quiet?: boolean;
@@ -8,7 +8,7 @@ exports.assertEnv = assertEnv;
8
8
  exports.assertEnvs = assertEnvs;
9
9
  exports.isBunProcess = isBunProcess;
10
10
  const node_child_process_1 = require("node:child_process");
11
- const tree_kill_1 = __importDefault(require("tree-kill"));
11
+ const fkill_1 = __importDefault(require("fkill"));
12
12
  const common_1 = require("@appweaver/common");
13
13
  /**
14
14
  * Executes a shell command with optional arguments and configuration parameters.
@@ -18,7 +18,7 @@ const common_1 = require("@appweaver/common");
18
18
  * @param {Object} [params={ quiet: false }] - Configurations for how the process should run.
19
19
  * @param {boolean} [params.quiet=false] - If true, suppresses the process output.
20
20
  * @param {AbortSignal} [params.signal] - Optional AbortSignal to terminate the running process.
21
- * @return {Promise<number>} A promise that resolves with the exit code of the process or 1 on error.
21
+ * @return {Promise<number>} A promise that resolves with the exit code of the process.
22
22
  */
23
23
  function runProcess(cmd, args = [], params = {}) {
24
24
  const { quiet = false, signal } = params;
@@ -32,19 +32,27 @@ function runProcess(cmd, args = [], params = {}) {
32
32
  shell: true,
33
33
  env: { ...process.env, WEAVER_CLI: undefined }
34
34
  });
35
+ let aborted = false;
35
36
  if (signal) {
36
- const abortHandler = () => {
37
+ const abortHandler = async () => {
37
38
  if (child.pid) {
38
- (0, tree_kill_1.default)(child.pid, () => {
39
- resolve(0);
40
- });
39
+ aborted = true;
40
+ try {
41
+ await (0, fkill_1.default)(child.pid, { force: true, tree: true });
42
+ }
43
+ catch (e) {
44
+ console.error('Failed to kill process:', e);
45
+ }
46
+ resolve(0);
41
47
  }
42
48
  };
43
49
  signal.addEventListener('abort', abortHandler, { once: true });
44
50
  }
45
51
  child.on('error', reject);
46
52
  child.on('close', (code) => {
47
- resolve(code ?? 99);
53
+ if (!aborted) {
54
+ resolve(code ?? 99);
55
+ }
48
56
  });
49
57
  });
50
58
  }