@travetto/compiler
Advanced tools
Comparing version 4.0.3 to 4.0.4
@@ -17,2 +17,3 @@ #!/usr/bin/env node | ||
' * event <log|progress|state> - Watch events in realtime as newline delimited JSON', | ||
' * exec <file> [...args] - Allow for compiling and executing an entrypoint file', | ||
' * manifest --prod [output] - Generate the project manifest', | ||
@@ -39,2 +40,3 @@ ].join('\n'); | ||
case 'manifest': return ops.manifest(args[0], flags.some(x => x === '--prod')); | ||
case 'exec': return ops.getLoader().then(v => v(args[0], all.slice(1))); | ||
case 'start': | ||
@@ -41,0 +43,0 @@ case 'watch': return ops.watch(); |
{ | ||
"name": "@travetto/compiler", | ||
"version": "4.0.3", | ||
"version": "4.0.4", | ||
"description": "The compiler infrastructure for the Travetto framework", | ||
@@ -34,8 +34,8 @@ "keywords": [ | ||
"@parcel/watcher": "^2.4.0", | ||
"@travetto/manifest": "^4.0.0", | ||
"@travetto/transformer": "^4.0.1", | ||
"@travetto/manifest": "^4.0.1", | ||
"@travetto/transformer": "^4.0.2", | ||
"@types/node": "^20.11.16" | ||
}, | ||
"peerDependencies": { | ||
"@travetto/cli": "^4.0.3" | ||
"@travetto/cli": "^4.0.4" | ||
}, | ||
@@ -42,0 +42,0 @@ "peerDependenciesMeta": { |
@@ -34,2 +34,3 @@ <!-- This file was generated by @travetto/doc and should not be modified directly --> | ||
* `event <log|progress|state>` - Watch events in realtime as newline delimited JSON | ||
* `exec <file> [...args]` - Allow for compiling and executing an entrypoint file | ||
* `manifest --prod [output]` - Generate the project manifest | ||
@@ -36,0 +37,0 @@ In addition to the normal output, the compiler supports an environment variable `TRV_BUILD` that supports the following values: `debug`, `info`, `warn` or `none`. This provides different level of logging during the build process which is helpful to diagnose any odd behaviors. When invoking an unknown command (e.g. `<other>` from above), the default level is `warn`. Otherwise the default logging level is `info`. |
@@ -1,2 +0,1 @@ | ||
import timers from 'node:timers/promises'; | ||
import fs from 'node:fs/promises'; | ||
@@ -14,2 +13,3 @@ import { setMaxListeners } from 'node:events'; | ||
import { IpcLogger } from '../support/log'; | ||
import { CommonUtil } from '../support/util'; | ||
@@ -86,3 +86,3 @@ const log = new IpcLogger({ level: 'debug' }); | ||
this.#ctrl.abort(); | ||
setTimeout(() => process.exit(), 1000).unref(); // Allow upto 1s to shutdown gracefully | ||
CommonUtil.nonBlockingTimeout(1000).then(() => process.exit()); // Allow upto 1s to shutdown gracefully | ||
} | ||
@@ -118,3 +118,3 @@ | ||
await timers.setTimeout(1); | ||
await CommonUtil.queueMacroTask(); | ||
@@ -121,0 +121,0 @@ log.debug(`Compiled ${i} files`); |
@@ -94,3 +94,3 @@ // @trv-no-transform | ||
/** Build and return a loader */ | ||
async getLoader(): Promise<(mod: string) => Promise<unknown>> { | ||
async getLoader(): Promise<(mod: string, args?: string[]) => Promise<unknown>> { | ||
Log.initLevel('none'); | ||
@@ -97,0 +97,0 @@ if (!(await client.isWatching())) { // Short circuit if we can |
@@ -9,2 +9,3 @@ import rl from 'node:readline/promises'; | ||
import type { LogShape } from '../log'; | ||
import { CommonUtil } from '../util'; | ||
import { ProcessHandle } from './process-handle'; | ||
@@ -49,13 +50,15 @@ | ||
const ctrl = new AbortController(); | ||
const timeoutCtrl = new AbortController(); | ||
opts?.signal?.addEventListener('abort', () => ctrl.abort()); | ||
const timeoutId = setTimeout(() => { | ||
logTimeout && this.#log.error(`Timeout on request to ${this.#url}${rel}`); | ||
ctrl.abort('TIMEOUT'); | ||
}, opts?.timeout ?? 100).unref(); | ||
try { | ||
const res = await fetch(`${this.#url}${rel}`, { ...opts, signal: ctrl.signal }); | ||
return { ok: res.ok, text: await res.text() }; | ||
} finally { | ||
clearTimeout(timeoutId); | ||
} | ||
timers.setTimeout(opts?.timeout ?? 100, undefined, { ref: false, signal: timeoutCtrl.signal }) | ||
.then(() => { | ||
logTimeout && this.#log.error(`Timeout on request to ${this.#url}${rel}`); | ||
ctrl.abort('TIMEOUT'); | ||
}) | ||
.catch(() => { }); | ||
const res = await fetch(`${this.#url}${rel}`, { ...opts, signal: ctrl.signal }); | ||
const out = { ok: res.ok, text: await res.text() }; | ||
timeoutCtrl.abort(); | ||
return out; | ||
} | ||
@@ -131,3 +134,3 @@ | ||
if (cfg.until?.(val)) { | ||
await timers.setTimeout(1); | ||
await CommonUtil.queueMacroTask(); | ||
ctrl.abort(); | ||
@@ -143,3 +146,3 @@ } | ||
await timers.setTimeout(1); | ||
await CommonUtil.queueMacroTask(); | ||
@@ -146,0 +149,0 @@ info = await this.info(); |
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import timers from 'node:timers/promises'; | ||
import type { ManifestContext } from '@travetto/manifest'; | ||
import { Log, Logger } from '../log'; | ||
import { CommonUtil } from '../util'; | ||
@@ -59,3 +59,3 @@ export class ProcessHandle { | ||
} | ||
await timers.setTimeout(100); | ||
await CommonUtil.nonBlockingTimeout(100); | ||
} | ||
@@ -62,0 +62,0 @@ try { |
@@ -80,3 +80,3 @@ import http from 'node:http'; | ||
const url = new URL(this.#url); | ||
setTimeout(() => this.#server.listen(+url.port, url.hostname), 1); // Run async | ||
CommonUtil.queueMacroTask().then(() => this.#server.listen(+url.port, url.hostname)); // Run async | ||
}); | ||
@@ -90,3 +90,3 @@ | ||
// Let the server finish | ||
await this.#client.waitForState(['close'], 'Server closed', this.signal); | ||
await this.#client.waitForState(['closed'], 'Server closed', this.signal); | ||
return this.#tryListen(attempt + 1); | ||
@@ -126,3 +126,3 @@ } else if (output === 'ok') { | ||
this.info.iteration = Date.now(); | ||
await new Promise(r => setTimeout(r, 20)); | ||
await CommonUtil.nonBlockingTimeout(20); | ||
for (const el of Object.values(this.#listeners)) { | ||
@@ -210,5 +210,5 @@ try { el.res.end(); } catch { } | ||
await new Promise((resolve, reject) => { | ||
setTimeout(reject, 2000).unref(); // 2s max wait | ||
CommonUtil.nonBlockingTimeout(2000).then(reject); // Wait 2s max | ||
this.#server.close(resolve); | ||
this.#emitEvent({ type: 'state', payload: { state: 'close' } }); | ||
this.#emitEvent({ type: 'state', payload: { state: 'closed' } }); | ||
setImmediate(() => { | ||
@@ -215,0 +215,0 @@ this.#server.closeAllConnections(); |
export type CompilerMode = 'build' | 'watch'; | ||
export type CompilerStateType = 'startup' | 'init' | 'compile-start' | 'compile-end' | 'watch-start' | 'watch-end' | 'reset' | 'close'; | ||
export type CompilerStateType = 'startup' | 'init' | 'compile-start' | 'compile-end' | 'watch-start' | 'watch-end' | 'reset' | 'closed'; | ||
export type CompilerChangeEvent = { file: string, action: 'create' | 'update' | 'delete', output: string, module: string, time: number }; | ||
@@ -5,0 +5,0 @@ export type CompilerLogLevel = 'info' | 'debug' | 'warn' | 'error'; |
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import timers from 'node:timers/promises'; | ||
import { setMaxListeners } from 'node:events'; | ||
@@ -98,9 +99,26 @@ | ||
*/ | ||
static moduleLoader(ctx: ManifestContext): (mod: string) => Promise<unknown> { | ||
return (mod) => { | ||
static moduleLoader(ctx: ManifestContext): (mod: string, args?: string[]) => Promise<unknown> { | ||
return (mod, args) => { | ||
const outputRoot = path.resolve(ctx.workspace.path, ctx.build.outputFolder); | ||
process.env.TRV_MANIFEST = path.resolve(outputRoot, 'node_modules', ctx.main.name); // Setup for running | ||
if (args) { | ||
process.argv = [process.argv0, mod, ...args]; | ||
} | ||
return import(path.join(outputRoot, 'node_modules', mod)); // Return function to run import on a module | ||
}; | ||
} | ||
/** | ||
* Non-blocking timeout, that is cancellable | ||
*/ | ||
static nonBlockingTimeout(time: number): Promise<void> { | ||
return timers.setTimeout(time, undefined, { ref: false }).catch(() => { }); | ||
} | ||
/** | ||
* Queue new macrotask | ||
*/ | ||
static queueMacroTask(): Promise<void> { | ||
return timers.setImmediate(undefined); | ||
} | ||
} |
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
82397
1807
93
Updated@travetto/manifest@^4.0.1
Updated@travetto/transformer@^4.0.2