@travetto/compiler
Advanced tools
Comparing version 4.0.0-rc.2 to 4.0.0-rc.3
@@ -28,3 +28,7 @@ // @ts-check | ||
const module = ctx.workspace.type === 'module' ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS; | ||
return (content = '') => ts.transpile(content, { target: ts.ScriptTarget.ES2022, module, esModuleInterop: true, allowSyntheticDefaultImports: true }); | ||
return (content = '') => | ||
ts.transpile(content, { target: ts.ScriptTarget.ES2022, module, esModuleInterop: true, allowSyntheticDefaultImports: true }) | ||
.replace(/from '([.][^']+)'/g, (_, i) => `from '${i.replace(/[.]js$/, '')}.js'`) | ||
.replace(/from '(@travetto\/(.*?))'/g, (_, i, s) => | ||
`from '${path.resolve(ctx.workspace.path, ctx.build.compilerFolder, `${i}${s.includes('/') ? '.js' : '/__index__.js'}`)}'`); | ||
}; | ||
@@ -31,0 +35,0 @@ |
{ | ||
"name": "@travetto/compiler", | ||
"version": "4.0.0-rc.2", | ||
"version": "4.0.0-rc.3", | ||
"description": "The compiler infrastructure for the Travetto framework", | ||
@@ -34,8 +34,8 @@ "keywords": [ | ||
"@parcel/watcher": "^2.4.0", | ||
"@travetto/manifest": "^4.0.0-rc.2", | ||
"@travetto/transformer": "^4.0.0-rc.2", | ||
"@travetto/manifest": "^4.0.0-rc.3", | ||
"@travetto/transformer": "^4.0.0-rc.3", | ||
"@types/node": "^20.11.16" | ||
}, | ||
"peerDependencies": { | ||
"@travetto/cli": "^4.0.0-rc.2" | ||
"@travetto/cli": "^4.0.0-rc.4" | ||
}, | ||
@@ -42,0 +42,0 @@ "peerDependenciesMeta": { |
@@ -1,2 +0,2 @@ | ||
import { ManifestContext, ManifestModuleUtil, ManifestUtil, RuntimeIndex, path } from '@travetto/manifest'; | ||
import { ManifestContext, ManifestModuleUtil, ManifestUtil, PackageUtil, RuntimeIndex, path } from '@travetto/manifest'; | ||
@@ -25,2 +25,19 @@ import type { CompileStateEntry } from './types'; | ||
#getIgnores(): string[] { | ||
// TODO: Read .gitignore? | ||
let ignores = PackageUtil.readPackage(this.#state.manifest.workspace.path)?.travetto?.build?.watchIgnores; | ||
if (!ignores) { | ||
ignores = ['node_modules/**']; | ||
} | ||
return [ | ||
...ignores, | ||
'.git', '**/.git', | ||
`${this.#state.manifest.build.outputFolder}/node_modules/**`, | ||
`${this.#state.manifest.build.compilerFolder}/node_modules/**`, | ||
`${this.#state.manifest.build.toolFolder}/**` | ||
]; | ||
} | ||
/** Watch files */ | ||
@@ -30,2 +47,3 @@ async * #watchFolder(rootPath: string): AsyncIterable<WatchEvent> { | ||
const lib = await import('@parcel/watcher'); | ||
const ignore = this.#getIgnores(); | ||
@@ -41,11 +59,3 @@ const cleanup = await lib.subscribe(rootPath, (err, events) => { | ||
} | ||
}, { | ||
// TODO: Read .gitignore? | ||
ignore: [ | ||
'node_modules', '**/node_modules', '.git', '**/.git', | ||
`${this.#state.manifest.build.outputFolder}/node_modules/**`, | ||
`${this.#state.manifest.build.compilerFolder}/node_modules/**`, | ||
`${this.#state.manifest.build.toolFolder}/**` | ||
] | ||
}); | ||
}, { ignore }); | ||
@@ -52,0 +62,0 @@ if (this.#signal.aborted) { // If already aborted, can happen async |
@@ -0,2 +1,3 @@ | ||
// @trv-no-transform | ||
import { Compiler } from '../src/compiler'; | ||
Compiler.main(); |
@@ -0,1 +1,2 @@ | ||
// @trv-no-transform | ||
import fs from 'node:fs/promises'; | ||
@@ -43,2 +44,3 @@ import path from 'node:path'; | ||
} | ||
LogUtil.cleanup(); | ||
}; | ||
@@ -45,0 +47,0 @@ |
@@ -13,2 +13,4 @@ import type { ManifestContext } from '@travetto/manifest'; | ||
const ESC = '\x1b['; | ||
export class LogUtil { | ||
@@ -26,3 +28,3 @@ | ||
// Move to 1st position, and clear after text | ||
const done = process.stdout.write(`\x1b[1G${text}\x1b[0K`); | ||
const done = process.stdout.write(`${ESC}1G${text}${ESC}0K`); | ||
this.linePartial = !!text; | ||
@@ -34,3 +36,2 @@ if (!done) { | ||
/** | ||
@@ -46,5 +47,16 @@ * Set level for operation | ||
this.root = ctx.workspace.path; | ||
this.logProgress = (this.isLevelActive('info') && process.stdout.isTTY) ? this.#logProgressEvent : undefined; | ||
// If we are in info or a terminal and also in a tty | ||
this.logProgress = ((this.isLevelActive('info') || process.env.PS1) && process.stdout.isTTY) ? this.#logProgressEvent : undefined; | ||
if (this.logProgress) { | ||
process.stdout.write(`${ESC}?25l`); // Hide cursor | ||
} | ||
process.on('exit', () => this.cleanup()); | ||
} | ||
static cleanup(): void { | ||
if (this.logProgress) { | ||
process.stdout.write(`${ESC}!p`); // Reset | ||
} | ||
} | ||
static #logProgressEvent(ev: CompilerProgressEvent): Promise<void> | void { | ||
@@ -51,0 +63,0 @@ const pct = Math.trunc(ev.idx * 100 / ev.total); |
@@ -40,7 +40,7 @@ import rl from 'node:readline/promises'; | ||
async #fetch(rel: string, opts?: RequestInit & { timeout?: number }): Promise<Response> { | ||
async #fetch(rel: string, opts?: RequestInit & { timeout?: number }, logTimeout = true): Promise<Response> { | ||
const ctrl = new AbortController(); | ||
opts?.signal?.addEventListener('abort', () => ctrl.abort()); | ||
const timeoutId = setTimeout(() => { | ||
this.#log('error', `Timeout on request to ${this.#url}${rel}`); | ||
logTimeout && this.#log('error', `Timeout on request to ${this.#url}${rel}`); | ||
ctrl.abort('TIMEOUT'); | ||
@@ -57,3 +57,3 @@ }, 100).unref(); | ||
info(): Promise<CompilerServerInfo | undefined> { | ||
return this.#fetch('/info').then(v => v.json(), () => undefined) | ||
return this.#fetch('/info', {}, false).then(v => v.json(), () => undefined) | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
@@ -60,0 +60,0 @@ .then(v => v as CompilerServerInfo); |
@@ -15,3 +15,4 @@ import fs from 'node:fs/promises'; | ||
writePid(pid: number): Promise<void> { | ||
async writePid(pid: number): Promise<void> { | ||
await fs.mkdir(path.dirname(this.#file), { recursive: true }); | ||
return fs.writeFile(this.#file, JSON.stringify(pid), 'utf8'); | ||
@@ -18,0 +19,0 @@ } |
@@ -23,3 +23,3 @@ import http from 'node:http'; | ||
#server: http.Server; | ||
#listeners: { res: http.ServerResponse, type: CompilerEventType }[] = []; | ||
#listeners: Record<string, { res: http.ServerResponse, type: CompilerEventType }> = {}; | ||
#shutdown = new AbortController(); | ||
@@ -101,4 +101,5 @@ signal = this.#shutdown.signal; | ||
res.writeHead(200); | ||
const id = `id_${Date.now()}_${Math.random()}`.replace('.', '1'); | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
this.#listeners.push({ res, type: type as 'change' }); | ||
this.#listeners[id] = { res, type: type as 'change' }; | ||
if (type === 'state') { // Send on initial connect | ||
@@ -108,5 +109,5 @@ res.write(JSON.stringify({ state: this.info.state })); | ||
res.write('\n'); // Send at least one byte on listen | ||
await new Promise(resolve => res.on('close', resolve)); | ||
this.#listeners.splice(this.#listeners.findIndex(x => x.res === res), 1); | ||
res.end(); | ||
// Do not wait on it | ||
res.on('close', () => { delete this.#listeners[id]; }); | ||
} | ||
@@ -116,3 +117,3 @@ | ||
const msg = `${JSON.stringify(ev.payload)}\n`; | ||
for (const el of this.#listeners) { | ||
for (const el of Object.values(this.#listeners)) { | ||
if (!el.res.closed && el.type === ev.type) { | ||
@@ -128,4 +129,4 @@ el.res.write(msg); | ||
await new Promise(r => setTimeout(r, 20)); | ||
for (const el of this.#listeners) { | ||
el.res.destroy(); | ||
for (const el of Object.values(this.#listeners)) { | ||
el.res.end(); | ||
} | ||
@@ -132,0 +133,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
80433
1766