@youcan/app 2.3.2 → 2.3.3

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.
@@ -1,6 +1,9 @@
1
1
  import { AppCommand } from '@/util/app-command';
2
2
  declare class Dev extends AppCommand {
3
3
  static description: string;
4
+ private workers;
5
+ constructor(argv: string[], config: any);
6
+ private setupExitHandlers;
4
7
  private readonly hotKeys;
5
8
  run(): Promise<any>;
6
9
  private prepareNetworkOptions;
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import { bootTunnelWorker, bootAppWorker, bootWebWorker, bootExtensionWorker } from '../../services/dev/workers/index.js';
2
3
  import { APP_CONFIG_FILENAME } from '../../../constants.js';
3
4
  import { AppCommand } from '../../../util/app-command.js';
@@ -6,6 +7,36 @@ import { Session, Tasks, UI, System, Services, Filesystem, Path, Env, Http } fro
6
7
 
7
8
  class Dev extends AppCommand {
8
9
  static description = 'Run the app in dev mode';
10
+ workers = [];
11
+ constructor(argv, config) {
12
+ super(argv, config);
13
+ this.setupExitHandlers();
14
+ }
15
+ setupExitHandlers() {
16
+ const cleanupAndExit = () => {
17
+ try {
18
+ if (this.controller) {
19
+ this.controller.abort();
20
+ }
21
+ this.workers = [];
22
+ console.log('Shutting down...');
23
+ setTimeout(() => {
24
+ process.exit(0);
25
+ }, 100);
26
+ }
27
+ catch (error) {
28
+ process.exit(0);
29
+ }
30
+ };
31
+ process.once('SIGINT', cleanupAndExit);
32
+ process.once('SIGTERM', cleanupAndExit);
33
+ process.once('SIGQUIT', cleanupAndExit);
34
+ process.once('exit', () => {
35
+ if (this.controller) {
36
+ this.controller.abort();
37
+ }
38
+ });
39
+ }
9
40
  hotKeys = [
10
41
  {
11
42
  keyboardKey: 'p',
@@ -15,7 +46,21 @@ class Dev extends AppCommand {
15
46
  {
16
47
  keyboardKey: 'q',
17
48
  description: 'quit',
18
- handler: () => this.exit(0),
49
+ handler: () => {
50
+ try {
51
+ if (this.controller) {
52
+ this.controller.abort();
53
+ }
54
+ this.workers = [];
55
+ console.log('Shutting down...');
56
+ setTimeout(() => {
57
+ process.exit(0);
58
+ }, 100);
59
+ }
60
+ catch (error) {
61
+ process.exit(0);
62
+ }
63
+ },
19
64
  },
20
65
  ];
21
66
  async run() {
@@ -43,7 +88,7 @@ class Dev extends AppCommand {
43
88
  this.runWorkers(workers);
44
89
  }
45
90
  async prepareNetworkOptions() {
46
- const port = await System.getNextAvailablePort(3000);
91
+ const port = await System.getPortOrNextOrRandom(3000);
47
92
  this.app.network_config = {
48
93
  app_port: port,
49
94
  app_url: `http://localhost:${port}`,
@@ -61,7 +106,6 @@ class Dev extends AppCommand {
61
106
  }
62
107
  async reloadWorkers() {
63
108
  this.controller = new AbortController();
64
- // Preserve network config.
65
109
  const networkConfig = this.app.network_config;
66
110
  this.app = await load();
67
111
  this.app.network_config = networkConfig;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@youcan/app",
3
3
  "type": "module",
4
- "version": "2.3.2",
4
+ "version": "2.3.3",
5
5
  "description": "OCLIF plugin for building apps",
6
6
  "author": "YouCan <contact@youcan.shop> (https://youcan.shop)",
7
7
  "license": "MIT",
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "@oclif/core": "^2.15.0",
19
19
  "dayjs": "^1.11.10",
20
- "@youcan/cli-kit": "2.3.2"
20
+ "@youcan/cli-kit": "2.3.3"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@oclif/plugin-legacy": "^1.3.0",