@travetto/compiler
Advanced tools
Comparing version 4.0.5 to 4.0.6
{ | ||
"name": "@travetto/compiler", | ||
"version": "4.0.5", | ||
"version": "4.0.6", | ||
"description": "The compiler infrastructure for the Travetto framework", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -13,3 +13,3 @@ import fs from 'node:fs/promises'; | ||
import { IpcLogger } from '../support/log'; | ||
import { TimerUtil } from '../support/timer'; | ||
import { CommonUtil } from '../support/util'; | ||
@@ -86,3 +86,3 @@ const log = new IpcLogger({ level: 'debug' }); | ||
this.#ctrl.abort(); | ||
TimerUtil.nonBlockingTimeout(1000).then(() => process.exit()); // Allow upto 1s to shutdown gracefully | ||
CommonUtil.nonBlockingTimeout(1000).then(() => process.exit()); // Allow upto 1s to shutdown gracefully | ||
} | ||
@@ -118,3 +118,3 @@ | ||
await TimerUtil.queueMacroTask(); | ||
await CommonUtil.queueMacroTask(); | ||
@@ -121,0 +121,0 @@ log.debug(`Compiled ${i} files`); |
@@ -7,3 +7,3 @@ import ts from 'typescript'; | ||
import { CommonUtil } from '../support/util'; | ||
import { TypescriptUtil } from '../support/ts-util'; | ||
@@ -86,3 +86,3 @@ import { CompilerUtil } from './util'; | ||
this.#compilerOptions = { | ||
...await CommonUtil.getCompilerOptions(this.#manifest), | ||
...await TypescriptUtil.getCompilerOptions(this.#manifest), | ||
rootDir: this.#rootDir, | ||
@@ -89,0 +89,0 @@ outDir: this.#outputPath |
@@ -9,3 +9,2 @@ // @trv-no-transform | ||
import { Log } from './log'; | ||
import { CommonUtil } from './util'; | ||
import { CompilerSetup } from './setup'; | ||
@@ -101,3 +100,11 @@ import { CompilerServer } from './server/server'; | ||
} | ||
return CommonUtil.moduleLoader(ctx); | ||
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 | ||
}; | ||
}, | ||
@@ -104,0 +111,0 @@ |
@@ -9,3 +9,3 @@ import rl from 'node:readline/promises'; | ||
import type { LogShape } from '../log'; | ||
import { TimerUtil } from '../timer'; | ||
import { CommonUtil } from '../util'; | ||
import { ProcessHandle } from './process-handle'; | ||
@@ -133,3 +133,3 @@ | ||
if (cfg.until?.(val)) { | ||
await TimerUtil.queueMacroTask(); | ||
await CommonUtil.queueMacroTask(); | ||
ctrl.abort(); | ||
@@ -145,3 +145,3 @@ } | ||
await TimerUtil.queueMacroTask(); | ||
await CommonUtil.queueMacroTask(); | ||
@@ -148,0 +148,0 @@ info = await this.info(); |
@@ -6,3 +6,3 @@ import fs from 'node:fs/promises'; | ||
import { Log, Logger } from '../log'; | ||
import { TimerUtil } from '../timer'; | ||
import { CommonUtil } from '../util'; | ||
@@ -60,3 +60,3 @@ export class ProcessHandle { | ||
} | ||
await TimerUtil.nonBlockingTimeout(100); | ||
await CommonUtil.nonBlockingTimeout(100); | ||
} | ||
@@ -63,0 +63,0 @@ try { |
@@ -11,3 +11,2 @@ import http from 'node:http'; | ||
import { CommonUtil } from '../util'; | ||
import { TimerUtil } from '../timer'; | ||
import { CompilerClient } from './client'; | ||
@@ -82,3 +81,3 @@ import { ProcessHandle } from './process-handle'; | ||
const url = new URL(this.#url); | ||
TimerUtil.queueMacroTask().then(() => this.#server.listen(+url.port, url.hostname)); // Run async | ||
CommonUtil.queueMacroTask().then(() => this.#server.listen(+url.port, url.hostname)); // Run async | ||
}); | ||
@@ -127,3 +126,3 @@ | ||
this.info.iteration = Date.now(); | ||
await TimerUtil.nonBlockingTimeout(20); | ||
await CommonUtil.nonBlockingTimeout(20); | ||
for (const el of Object.values(this.#listeners)) { | ||
@@ -211,3 +210,3 @@ try { el.res.end(); } catch { } | ||
await new Promise((resolve, reject) => { | ||
TimerUtil.nonBlockingTimeout(2000).then(reject); // Wait 2s max | ||
CommonUtil.nonBlockingTimeout(2000).then(reject); // Wait 2s max | ||
this.#server.close(resolve); | ||
@@ -214,0 +213,0 @@ this.#emitEvent({ type: 'state', payload: { state: 'closed' } }); |
@@ -9,2 +9,3 @@ import path from 'node:path'; | ||
import { CommonUtil } from './util'; | ||
import { TypescriptUtil } from './ts-util'; | ||
@@ -61,3 +62,3 @@ type ModFile = { input: string, output: string, stale: boolean }; | ||
const content = ts.transpile(text, { | ||
...await CommonUtil.getCompilerOptions(ctx), | ||
...await TypescriptUtil.getCompilerOptions(ctx), | ||
sourceMap: false, | ||
@@ -64,0 +65,0 @@ inlineSourceMap: true, |
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { setMaxListeners } from 'node:events'; | ||
import timers from 'node:timers/promises'; | ||
import type { ManifestContext } from '@travetto/manifest'; | ||
import { Log } from './log'; | ||
const OPT_CACHE: Record<string, import('typescript').CompilerOptions> = {}; | ||
export class CommonUtil { | ||
/** | ||
* Returns the compiler options | ||
*/ | ||
static async getCompilerOptions(ctx: ManifestContext): Promise<{}> { | ||
if (!(ctx.workspace.path in OPT_CACHE)) { | ||
let tsconfig = path.resolve(ctx.workspace.path, 'tsconfig.json'); | ||
if (!await fs.stat(tsconfig).then(_ => true, _ => false)) { | ||
tsconfig = path.resolve(ctx.workspace.path, ctx.build.compilerModuleFolder, 'tsconfig.trv.json'); | ||
} | ||
const ts = (await import('typescript')).default; | ||
const { options } = ts.parseJsonSourceFileConfigFileContent( | ||
ts.readJsonConfigFile(tsconfig, ts.sys.readFile), ts.sys, ctx.workspace.path | ||
); | ||
OPT_CACHE[ctx.workspace.path] = { | ||
...options, | ||
allowJs: true, | ||
resolveJsonModule: true, | ||
sourceRoot: ctx.workspace.path, | ||
rootDir: ctx.workspace.path, | ||
outDir: path.resolve(ctx.workspace.path), | ||
module: ctx.workspace.type === 'commonjs' ? ts.ModuleKind.CommonJS : ts.ModuleKind.ESNext, | ||
}; | ||
} | ||
return OPT_CACHE[ctx.workspace.path]; | ||
} | ||
/** | ||
* Determine file type | ||
@@ -95,15 +62,14 @@ */ | ||
/** | ||
* Create a module loader given a context, and assuming build is complete | ||
* @param ctx | ||
* Non-blocking timeout, that is cancellable | ||
*/ | ||
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 | ||
}; | ||
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
82281
1803