@nu-art/build-and-install 0.204.89 → 0.204.91

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": "@nu-art/build-and-install",
3
- "version": "0.204.89",
3
+ "version": "0.204.91",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -10,6 +10,12 @@ export declare class PhaseRunner extends BaseUnit implements UnitPhaseImplemento
10
10
  private killed?;
11
11
  private runningStatus;
12
12
  private phaseFilter;
13
+ /**
14
+ * kill counter that will intercept the kill event and if the threshold will be met the main process will be killed as well
15
+ * @private
16
+ */
17
+ private killCounter;
18
+ private static KILL_THRESHOLD;
13
19
  constructor(projectPath: RelativePath);
14
20
  protected init(): Promise<void>;
15
21
  private filterUnits;
@@ -46,6 +46,11 @@ const CONST_ProjectDependencyKey = 'APP_VERSION_DEPENDENCY';
46
46
  class PhaseRunner extends core_1.BaseUnit {
47
47
  constructor(projectPath) {
48
48
  super({ label: 'Phase Runner', key: 'phase-runner' });
49
+ /**
50
+ * kill counter that will intercept the kill event and if the threshold will be met the main process will be killed as well
51
+ * @private
52
+ */
53
+ this.killCounter = 0;
49
54
  //######################### Internal Logic #########################
50
55
  this.phaseFilters = {
51
56
  [types_1.PhaseRunnerMode_Normal]: async (phase) => {
@@ -372,17 +377,34 @@ class PhaseRunner extends core_1.BaseUnit {
372
377
  //######################### Public Functions #########################
373
378
  async execute() {
374
379
  return new MemStorage_1.MemStorage().init(async () => {
380
+ process.on('SIGINT', () => {
381
+ this.killRunner();
382
+ });
375
383
  await this.init();
376
384
  await this.buildUnitDependencyTree();
377
385
  await this.executeImpl();
378
386
  });
379
387
  }
380
388
  async killRunner() {
381
- this.killed = true;
389
+ this.killCounter++;
390
+ if (this.killCounter === PhaseRunner.KILL_THRESHOLD)
391
+ process.exit(1);
392
+ if (this.killed)
393
+ process.exit(1);
382
394
  await this.setRunningStatus();
383
395
  this.logDebug('Killing units');
384
- await Promise.all(this.units.map(unit => unit.kill()));
396
+ await Promise.all(this.units.map(async (unit) => {
397
+ try {
398
+ await unit.kill();
399
+ }
400
+ catch (e) {
401
+ unit.logError(`Error killing unit`, e);
402
+ }
403
+ }));
385
404
  this.logDebug('Units killed');
405
+ this.killed = true;
406
+ if (params_1.RuntimeParams.closeOnExit)
407
+ process.exit(1);
386
408
  }
387
409
  //######################### Phase Implementation #########################
388
410
  async printHelp() {
@@ -421,4 +443,5 @@ class PhaseRunner extends core_1.BaseUnit {
421
443
  this.logInfo('Unit Dependencies Tree:', dependencyTree);
422
444
  }
423
445
  }
446
+ PhaseRunner.KILL_THRESHOLD = 5;
424
447
  exports.PhaseRunner = PhaseRunner;
@@ -4,7 +4,6 @@ exports.BAIScreen = void 0;
4
4
  const ConsoleContainer_1 = require("@nu-art/commando/console/ConsoleContainer");
5
5
  const ts_common_1 = require("@nu-art/ts-common");
6
6
  const PhaseRunnerDispatcher_1 = require("../phase-runner/PhaseRunnerDispatcher");
7
- const params_1 = require("../../core/params/params");
8
7
  class BAIScreen extends ConsoleContainer_1.ConsoleContainer {
9
8
  //######################### Initialization #########################
10
9
  /**
@@ -63,8 +62,6 @@ class BAIScreen extends ConsoleContainer_1.ConsoleContainer {
63
62
  this.logInfo('Kill command received');
64
63
  await ((_a = this.onKillCallback) === null || _a === void 0 ? void 0 : _a.call(this));
65
64
  this.logInfo('Killed!');
66
- if (params_1.RuntimeParams.closeOnExit)
67
- process.exit(1);
68
65
  }
69
66
  }
70
67
  exports.BAIScreen = BAIScreen;
@@ -1,4 +1,4 @@
1
- import { Logger } from '@nu-art/ts-common';
1
+ import { AsyncVoidFunction, Logger } from '@nu-art/ts-common';
2
2
  import { RunnerParamKey } from '../../phase-runner/RunnerParams';
3
3
  export type BaseUnit_Config = {
4
4
  key: string;
@@ -15,7 +15,10 @@ export declare class BaseUnit<C extends BaseUnit_Config = BaseUnit_Config, RTC e
15
15
  private unitStatus?;
16
16
  private logger;
17
17
  private classStack;
18
+ private processTerminator;
18
19
  constructor(config: C);
20
+ registerTerminatable(terminatable: AsyncVoidFunction): void;
21
+ unregisterTerminatable(terminatable: AsyncVoidFunction): void;
19
22
  protected init(setInitialized?: boolean): Promise<void>;
20
23
  protected getRunnerParam(key: RunnerParamKey): string | undefined;
21
24
  private initLogClient;
@@ -8,6 +8,7 @@ const params_1 = require("../../../core/params/params");
8
8
  class BaseUnit extends ts_common_1.Logger {
9
9
  constructor(config) {
10
10
  super(config.key);
11
+ this.processTerminator = [];
11
12
  //######################### Class Stack Logic #########################
12
13
  this.addToClassStack = (cls) => {
13
14
  this.classStack.add(cls.name);
@@ -24,6 +25,12 @@ class BaseUnit extends ts_common_1.Logger {
24
25
  this.addToClassStack(BaseUnit);
25
26
  this.initLogClient();
26
27
  }
28
+ registerTerminatable(terminatable) {
29
+ this.processTerminator.push(terminatable);
30
+ }
31
+ unregisterTerminatable(terminatable) {
32
+ (0, ts_common_1.removeItemFromArray)(this.processTerminator, terminatable);
33
+ }
27
34
  async init(setInitialized = true) {
28
35
  this.setStatus('Initializing');
29
36
  //Register the unit to PhaseRunnerEvent dispatcher
@@ -59,7 +66,11 @@ class BaseUnit extends ts_common_1.Logger {
59
66
  return this.unitStatus;
60
67
  }
61
68
  async kill() {
62
- return;
69
+ if (!this.processTerminator.length)
70
+ return;
71
+ this.logWarning(`Killing unit - ${this.config.label}`);
72
+ await Promise.all(this.processTerminator.map(toTerminate => toTerminate()));
73
+ this.logWarning(`Unit killed - ${this.config.label}`);
63
74
  }
64
75
  getLogs() {
65
76
  return this.logger.buffers[0];
@@ -101,13 +101,17 @@ class Unit_TypescriptLib extends Unit_Typescript_1.Unit_Typescript {
101
101
  const pathToCompile = `${this.runtime.pathTo.pkg}/src/main`;
102
102
  const pathToTSConfig = `${pathToCompile}/tsconfig.json`;
103
103
  try {
104
- await nvm_1.NVM
105
- .createInteractiveCommando(basic_1.Cli_Basic)
106
- .setUID(this.config.key)
104
+ let pid;
105
+ const commando = nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic);
106
+ this.registerTerminatable(async () => {
107
+ console.log(`killing ${pid}`);
108
+ process.kill(pid, 2);
109
+ });
110
+ await commando.setUID(this.config.key)
107
111
  .cd(this.runtime.pathTo.pkg)
108
112
  .append(`tsc -p "${pathToTSConfig}" --rootDir "${pathToCompile}" --outDir "${this.runtime.pathTo.output}"`)
109
113
  .addLogProcessor((log) => !log.includes('Now using node') && !log.includes('.nvmrc\' with version'))
110
- .execute((stdout, stderr, exitCode) => {
114
+ .executeAsync(_pid => pid = _pid, (stdout, stderr, exitCode) => {
111
115
  if (exitCode > 0)
112
116
  throw new CliError_1.CommandoException(`Error compiling`, stdout, stderr, exitCode);
113
117
  });
@@ -9,9 +9,6 @@ export type Unit_FirebaseFunctionsApp_Config = Unit_TypescriptLib_Config & {
9
9
  };
10
10
  export declare class Unit_FirebaseFunctionsApp<C extends Unit_FirebaseFunctionsApp_Config = Unit_FirebaseFunctionsApp_Config> extends Unit_TypescriptLib<C> implements UnitPhaseImplementor<[Phase_ResolveConfigs, Phase_Launch, Phase_DeployBackend]>, OnUnitWatchCompiled {
11
11
  static staggerCount: number;
12
- private emulatorPid?;
13
- private proxyPid?;
14
- private launchCommandos;
15
12
  __onUnitWatchCompiled(unit: BaseUnit): Promise<void>;
16
13
  constructor(config: Unit_FirebaseFunctionsApp<C>['config']);
17
14
  resolveConfigs(): Promise<void>;
@@ -26,13 +23,8 @@ export declare class Unit_FirebaseFunctionsApp<C extends Unit_FirebaseFunctionsA
26
23
  private resolveFunctionsRuntimeConfig;
27
24
  private createAppVersionFile;
28
25
  private createDependenciesDir;
29
- private clearPorts;
30
- private onLaunched;
31
- private initLaunch;
32
- private initLaunchListeners;
26
+ private releasePorts;
33
27
  private runProxy;
34
28
  private runEmulator;
35
- kill(): Promise<void>;
36
- private printFiles;
37
29
  private deployImpl;
38
30
  }
@@ -52,16 +52,13 @@ class Unit_FirebaseFunctionsApp extends core_1.Unit_TypescriptLib {
52
52
  async launch() {
53
53
  this.setStatus('Launching');
54
54
  await (0, ts_common_1.sleep)(2 * ts_common_1.Second * Unit_FirebaseFunctionsApp.staggerCount++);
55
- await this.initLaunch();
56
- await this.initLaunchListeners();
57
- await this.clearPorts();
55
+ await this.releasePorts();
58
56
  await Promise.all([
59
57
  this.runProxy(),
60
58
  this.runEmulator(),
61
59
  ]);
62
60
  }
63
61
  async deployBackend() {
64
- await this.printFiles();
65
62
  await this.deployImpl();
66
63
  }
67
64
  //######################### ResolveConfig Logic #########################
@@ -237,55 +234,43 @@ class Unit_FirebaseFunctionsApp extends core_1.Unit_TypescriptLib {
237
234
  this.packageJson.dist = packageJsonConverter(this.packageJson.dist);
238
235
  }
239
236
  //######################### Launch Logic #########################
240
- async clearPorts() {
237
+ async releasePorts() {
238
+ const commando = nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic);
241
239
  const allPorts = Array.from({ length: 10 }, (_, i) => `${this.config.firebaseConfig.basePort + i}`);
242
- await shell_1.Commando.create(basic_1.Cli_Basic)
240
+ await commando.setUID(this.config.key)
243
241
  .append(`array=($(lsof -ti:${allPorts.join(',')}))`)
244
242
  .append(`((\${#array[@]} > 0)) && kill -9 "\${array[@]}"`)
245
243
  .append('echo ')
246
244
  .execute();
247
245
  }
248
- onLaunched() {
249
- this.setStatus('Launch Complete');
250
- }
251
- async initLaunch() {
252
- this.launchCommandos = {
253
- emulator: nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic).setUID(this.config.key).cd(this.runtime.pathTo.pkg),
254
- proxy: nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic).setUID(this.config.key).cd(this.runtime.pathTo.pkg),
255
- };
256
- }
257
- async initLaunchListeners() {
258
- this.launchCommandos.emulator.onLog(/.*Emulator Hub running.*/, () => this.onLaunched());
259
- }
260
246
  async runProxy() {
261
- await this.launchCommandos.proxy
247
+ let pid;
248
+ const commando = nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic);
249
+ this.registerTerminatable(() => commando.gracefullyKill(pid));
250
+ await commando.setUID(this.config.key)
251
+ .cd(this.runtime.pathTo.pkg)
262
252
  .append('ts-node src/main/proxy.ts')
263
- .executeAsync(pid => this.proxyPid = pid);
253
+ .executeAsync(_pid => pid = _pid);
264
254
  }
265
255
  async runEmulator() {
266
- await this.launchCommandos.emulator
256
+ let pid;
257
+ const commando = nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic);
258
+ const terminatable = () => commando.gracefullyKill(pid);
259
+ this.registerTerminatable(terminatable);
260
+ await commando.setUID(this.config.key)
261
+ .cd(this.runtime.pathTo.pkg)
262
+ .onLog(/.*Emulator Hub running.*/, () => this.setStatus('Launch Complete'))
267
263
  .append(`firebase emulators:start --export-on-exit --import=.trash/data ${params_1.RuntimeParams.debugBackend ? `--inspect-functions ${this.config.firebaseConfig.debugPort}` : ''}`)
268
- .executeAsync(pid => this.emulatorPid = pid);
269
- }
270
- async kill() {
271
- if (!this.launchCommandos)
272
- return;
273
- this.logWarning(`Killing unit - ${this.config.label}`);
274
- await this.launchCommandos.emulator.gracefullyKill(this.emulatorPid);
275
- await this.launchCommandos.proxy.gracefullyKill(this.proxyPid);
276
- this.logWarning(`Unit killed - ${this.config.label}`);
264
+ .executeAsync(_pid => pid = _pid);
265
+ this.unregisterTerminatable(terminatable);
277
266
  }
278
267
  //######################### Deploy Logic #########################
279
- async printFiles() {
280
- await shell_1.Commando.create(basic_1.Cli_Basic)
268
+ async deployImpl() {
269
+ await nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic)
281
270
  .cd(this.runtime.pathTo.output)
282
271
  .ls()
283
272
  .cat('package.json')
284
273
  .cat('index.js')
285
- .execute();
286
- }
287
- async deployImpl() {
288
- await nvm_1.NVM.createCommando(basic_1.Cli_Basic)
289
274
  .cd(this.runtime.pathTo.pkg)
290
275
  .append(`firebase --debug deploy --only functions --force`)
291
276
  .execute();
@@ -293,48 +278,3 @@ class Unit_FirebaseFunctionsApp extends core_1.Unit_TypescriptLib {
293
278
  }
294
279
  Unit_FirebaseFunctionsApp.staggerCount = 0;
295
280
  exports.Unit_FirebaseFunctionsApp = Unit_FirebaseFunctionsApp;
296
- // export class CommandoCLIListener {
297
- //
298
- // private cb: CommandoCLIListener_Callback;
299
- // protected filter?: RegExp;
300
- //
301
- // constructor(callback: CommandoCLIListener_Callback, filter?: string | RegExp) {
302
- // this.cb = callback;
303
- // if (!filter)
304
- // return;
305
- //
306
- // if (typeof filter === 'string')
307
- // this.filter = new RegExp(filter);
308
- // else
309
- // this.filter = filter as RegExp;
310
- // }
311
- //
312
- // //######################### Inner Logic #########################
313
- //
314
- // private _process(stdout: string) {
315
- // if (!this.stdoutPassesFilter(stdout))
316
- // return false;
317
- //
318
- // this.process(stdout);
319
- // return true;
320
- // }
321
- //
322
- // private stdoutPassesFilter = (stdout: string): boolean => {
323
- // if (!this.filter)
324
- // return true;
325
- //
326
- // return this.filter.test(stdout);
327
- // };
328
- //
329
- // //######################### Functions #########################
330
- //
331
- // public listen = <T extends Commando | CommandoInteractive>(commando: T): T => {
332
- // const process = this._process.bind(this);
333
- // commando.addLogProcessor(process);
334
- // return commando;
335
- // };
336
- //
337
- // protected process(stdout: string) {
338
- // this.cb(stdout);
339
- // }
340
- // }
@@ -94,7 +94,7 @@ class Unit_FirebaseHostingApp extends core_1.Unit_TypescriptLib {
94
94
  //######################### Compile Logic #########################
95
95
  async compileImpl() {
96
96
  await nvm_1.NVM
97
- .createCommando(basic_1.Cli_Basic)
97
+ .createInteractiveCommando(basic_1.Cli_Basic)
98
98
  .cd(this.runtime.pathTo.pkg)
99
99
  .append(`ENV=${params_1.RuntimeParams.environment} npm run build`)
100
100
  .execute();
@@ -137,7 +137,7 @@ class Unit_FirebaseHostingApp extends core_1.Unit_TypescriptLib {
137
137
  }
138
138
  //######################### Deploy Logic #########################
139
139
  async deployImpl() {
140
- await nvm_1.NVM.createCommando(basic_1.Cli_Basic)
140
+ await nvm_1.NVM.createInteractiveCommando(basic_1.Cli_Basic)
141
141
  .cd(this.runtime.pathTo.pkg)
142
142
  .append(`firebase --debug deploy --only hosting`)
143
143
  .execute();