@travetto/compiler 4.0.4 → 4.0.5

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": "@travetto/compiler",
3
- "version": "4.0.4",
3
+ "version": "4.0.5",
4
4
  "description": "The compiler infrastructure for the Travetto framework",
5
5
  "keywords": [
6
6
  "compiler",
package/src/compiler.ts CHANGED
@@ -10,7 +10,7 @@ import { CompileEmitEvent, CompileEmitter } from './types';
10
10
  import { EventUtil } from './event';
11
11
 
12
12
  import { IpcLogger } from '../support/log';
13
- import { CommonUtil } from '../support/util';
13
+ import { TimerUtil } from '../support/timer';
14
14
 
15
15
  const log = new IpcLogger({ level: 'debug' });
16
16
 
@@ -82,7 +82,7 @@ export class Compiler {
82
82
  process.removeAllListeners('disconnect');
83
83
  process.removeAllListeners('message');
84
84
  this.#ctrl.abort();
85
- CommonUtil.nonBlockingTimeout(1000).then(() => process.exit()); // Allow upto 1s to shutdown gracefully
85
+ TimerUtil.nonBlockingTimeout(1000).then(() => process.exit()); // Allow upto 1s to shutdown gracefully
86
86
  }
87
87
 
88
88
  /**
@@ -113,7 +113,7 @@ export class Compiler {
113
113
  }
114
114
  EventUtil.sendEvent('progress', { total: files.length, idx: files.length, message: 'Complete', operation: 'compile', complete: true });
115
115
 
116
- await CommonUtil.queueMacroTask();
116
+ await TimerUtil.queueMacroTask();
117
117
 
118
118
  log.debug(`Compiled ${i} files`);
119
119
  }
@@ -6,7 +6,7 @@ import { ManifestContext } from '@travetto/manifest';
6
6
 
7
7
  import type { CompilerEvent, CompilerEventType, CompilerServerInfo, CompilerStateType } from '../types';
8
8
  import type { LogShape } from '../log';
9
- import { CommonUtil } from '../util';
9
+ import { TimerUtil } from '../timer';
10
10
  import { ProcessHandle } from './process-handle';
11
11
 
12
12
  type FetchEventsConfig<T> = {
@@ -129,7 +129,7 @@ export class CompilerClient {
129
129
  if (line.trim().charAt(0) === '{') {
130
130
  const val = JSON.parse(line);
131
131
  if (cfg.until?.(val)) {
132
- await CommonUtil.queueMacroTask();
132
+ await TimerUtil.queueMacroTask();
133
133
  ctrl.abort();
134
134
  }
135
135
  yield val;
@@ -140,7 +140,7 @@ export class CompilerClient {
140
140
  }
141
141
  signal.removeEventListener('abort', quit);
142
142
 
143
- await CommonUtil.queueMacroTask();
143
+ await TimerUtil.queueMacroTask();
144
144
 
145
145
  info = await this.info();
146
146
 
@@ -3,7 +3,7 @@ import path from 'node:path';
3
3
 
4
4
  import type { ManifestContext } from '@travetto/manifest';
5
5
  import { Log, Logger } from '../log';
6
- import { CommonUtil } from '../util';
6
+ import { TimerUtil } from '../timer';
7
7
 
8
8
  export class ProcessHandle {
9
9
 
@@ -56,7 +56,7 @@ export class ProcessHandle {
56
56
  if (!await this.isRunning()) {
57
57
  return true;
58
58
  }
59
- await CommonUtil.nonBlockingTimeout(100);
59
+ await TimerUtil.nonBlockingTimeout(100);
60
60
  }
61
61
  try {
62
62
  this.#log.debug('Force Killing', pid);
@@ -8,6 +8,7 @@ import type { ManifestContext } from '@travetto/manifest';
8
8
  import type { CompilerMode, CompilerProgressEvent, CompilerEvent, CompilerEventType, CompilerServerInfo } from '../types';
9
9
  import { Log } from '../log';
10
10
  import { CommonUtil } from '../util';
11
+ import { TimerUtil } from '../timer';
11
12
  import { CompilerClient } from './client';
12
13
  import { ProcessHandle } from './process-handle';
13
14
 
@@ -77,7 +78,7 @@ export class CompilerServer {
77
78
  .on('close', () => log.debug('Server close event'));
78
79
 
79
80
  const url = new URL(this.#url);
80
- CommonUtil.queueMacroTask().then(() => this.#server.listen(+url.port, url.hostname)); // Run async
81
+ TimerUtil.queueMacroTask().then(() => this.#server.listen(+url.port, url.hostname)); // Run async
81
82
  });
82
83
 
83
84
  if (output === 'retry') {
@@ -121,7 +122,7 @@ export class CompilerServer {
121
122
  async #disconnectActive(): Promise<void> {
122
123
  log.info('Server disconnect requested');
123
124
  this.info.iteration = Date.now();
124
- await CommonUtil.nonBlockingTimeout(20);
125
+ await TimerUtil.nonBlockingTimeout(20);
125
126
  for (const el of Object.values(this.#listeners)) {
126
127
  try { el.res.end(); } catch { }
127
128
  }
@@ -204,7 +205,7 @@ export class CompilerServer {
204
205
 
205
206
  try {
206
207
  await new Promise((resolve, reject) => {
207
- CommonUtil.nonBlockingTimeout(2000).then(reject); // Wait 2s max
208
+ TimerUtil.nonBlockingTimeout(2000).then(reject); // Wait 2s max
208
209
  this.#server.close(resolve);
209
210
  this.#emitEvent({ type: 'state', payload: { state: 'closed' } });
210
211
  setImmediate(() => {
@@ -0,0 +1,17 @@
1
+ import timers from 'node:timers/promises';
2
+
3
+ export class TimerUtil {
4
+ /**
5
+ * Non-blocking timeout, that is cancellable
6
+ */
7
+ static nonBlockingTimeout(time: number): Promise<void> {
8
+ return timers.setTimeout(time, undefined, { ref: false }).catch(() => { });
9
+ }
10
+
11
+ /**
12
+ * Queue new macrotask
13
+ */
14
+ static queueMacroTask(): Promise<void> {
15
+ return timers.setImmediate(undefined);
16
+ }
17
+ }
package/support/util.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
- import timers from 'node:timers/promises';
4
3
  import { setMaxListeners } from 'node:events';
5
4
 
6
5
  import type { ManifestContext } from '@travetto/manifest';
@@ -106,18 +105,4 @@ export class CommonUtil {
106
105
  return import(path.join(outputRoot, 'node_modules', mod)); // Return function to run import on a module
107
106
  };
108
107
  }
109
-
110
- /**
111
- * Non-blocking timeout, that is cancellable
112
- */
113
- static nonBlockingTimeout(time: number): Promise<void> {
114
- return timers.setTimeout(time, undefined, { ref: false }).catch(() => { });
115
- }
116
-
117
- /**
118
- * Queue new macrotask
119
- */
120
- static queueMacroTask(): Promise<void> {
121
- return timers.setImmediate(undefined);
122
- }
123
108
  }