@travetto/base
Advanced tools
Comparing version 3.4.0-rc.6 to 3.4.0-rc.7
{ | ||
"name": "@travetto/base", | ||
"version": "3.4.0-rc.6", | ||
"version": "3.4.0-rc.7", | ||
"description": "Environment config and common utilities for travetto applications.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -67,3 +67,3 @@ <!-- This file was generated by @travetto/doc and should not be modified directly --> | ||
The source for each field is: | ||
* `envName` - This is derived from `process.env.TRV_ENV` with a fallback of `process.NODE_ENV` | ||
* `envName` - This is derived from `process.env.TRV_ENV` with a fallback of `process.env.NODE_ENV` | ||
* `devMode` - This is true if `process.env.NODE_ENV` is dev* or test | ||
@@ -70,0 +70,0 @@ * `dynamic` - This is derived from `process.env.TRV_DYNAMIC`. This field reflects certain feature sets used throughout the framework. |
@@ -30,5 +30,3 @@ import rl from 'readline/promises'; | ||
{ type: 'progress', payload: ProgressEvent } | | ||
{ type: 'state', payload: StateEvent } | | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
{ type: 'custom', payload: any }; | ||
{ type: 'state', payload: StateEvent }; | ||
@@ -52,12 +50,7 @@ type CompilerEventType = CompilerEvent['type']; | ||
if (cfg.signal) { | ||
cfg.signal.addEventListener('abort', () => this.#kill.abort()); | ||
cfg.signal.addEventListener('abort', () => this.close()); | ||
} | ||
ShutdownManager.onExitRequested(() => this.#kill.abort()); | ||
ShutdownManager.onExitRequested(() => this.close()); | ||
} | ||
replaceSignal(signal: AbortSignal): void { | ||
this.#kill = new AbortController(); | ||
signal.addEventListener('abort', () => this.#kill.abort()); | ||
} | ||
close(): void { | ||
@@ -67,8 +60,29 @@ this.#kill.abort(); | ||
#nestedCtrl(signal?: AbortSignal): AbortController & { cleanup?: () => void } { | ||
const ctrl = new AbortController(); | ||
const kill = (): void => ctrl.abort(); | ||
const parent = signal ?? this.#kill.signal; | ||
parent.addEventListener('abort', kill); | ||
Object.assign(ctrl, { | ||
cleanup: () => { | ||
parent.removeEventListener('abort', kill); | ||
ctrl.abort(); | ||
} | ||
}); | ||
return ctrl; | ||
} | ||
/** Get compiler info */ | ||
async getInfo(env?: boolean): Promise<ServerInfo | undefined> { | ||
const res = await fetch(`${this.#url}/info?${env ? 'env' : ''}`, { signal: this.#kill.signal }).catch(err => ({ ok: false, json: () => undefined })); | ||
if (res.ok) { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
return (await res.json()) as ServerInfo; | ||
async getInfo(): Promise<ServerInfo | undefined> { | ||
const ctrl = this.#nestedCtrl(); | ||
try { | ||
const res = await fetch(`${this.#url}/info`, { signal: ctrl.signal }); | ||
if (res.ok) { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
return (await res.json()) as ServerInfo; | ||
} | ||
} catch { | ||
return; | ||
} finally { | ||
ctrl.cleanup?.(); | ||
} | ||
@@ -87,6 +101,7 @@ } | ||
const ctrl = this.#nestedCtrl(signal); | ||
const { iteration } = info; | ||
for (; ;) { | ||
try { | ||
const stream = await fetch(`${this.#url}/event/${type}`, { signal: signal ?? this.#kill.signal }); | ||
const stream = await fetch(`${this.#url}/event/${type}`, { signal: ctrl.signal }); | ||
for await (const line of rl.createInterface(Readable.fromWeb(stream.body!))) { | ||
@@ -100,2 +115,3 @@ if (line.trim().charAt(0) === '{') { | ||
if (this.#kill.signal?.aborted || (await this.getInfo())?.iteration !== iteration) { // If aborted, or server is not available or iteration is changed | ||
ctrl.cleanup?.(); | ||
return; | ||
@@ -111,10 +127,15 @@ } | ||
>(type: V, payload: T, signal?: AbortSignal): Promise<void> { | ||
const res = await fetch(`${this.#url}/send-event`, { | ||
method: 'POST', | ||
body: JSON.stringify({ type, payload }), | ||
headers: { 'Content-Type': 'application/json' }, | ||
signal | ||
}); | ||
if (!res.ok) { | ||
throw new AppError('Unable to send event'); | ||
const ctrl = this.#nestedCtrl(signal); | ||
try { | ||
const res = await fetch('/send-event', { | ||
method: 'POST', | ||
body: JSON.stringify({ type, payload }), | ||
headers: { 'Content-Type': 'application/json' }, | ||
signal: ctrl.signal | ||
}); | ||
if (!res.ok) { | ||
throw new AppError('Unable to send event'); | ||
} | ||
} finally { | ||
ctrl.cleanup?.(); | ||
} | ||
@@ -128,9 +149,11 @@ } | ||
async * listenFileChanges(restartOnExit = false): AsyncIterable<ChangeEvent> { | ||
let info = await this.getInfo(); | ||
let delay = 1000; | ||
while (info?.mode !== 'watch') { // If we not are watching from the beginning, wait for the server to change | ||
await new Promise(r => setTimeout(r, 1000)); // Check once a second to see when the compiler comes up | ||
await new Promise(r => setTimeout(r, delay)); // Check once a second to see when the compiler comes up | ||
info = await this.getInfo(); | ||
if (info) { | ||
return; | ||
} else { | ||
delay += 200; | ||
} | ||
@@ -137,0 +160,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98145
2172