@travetto/compiler 3.0.0-rc.27 → 3.0.0-rc.28
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 +3 -3
- package/src/compiler.ts +3 -7
- package/support/launcher.ts +11 -1
- package/support/lock.ts +11 -13
- package/support/log.ts +22 -7
- package/support/transpile.ts +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/compiler",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.28",
|
|
4
4
|
"description": "Compiler",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiler",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@parcel/watcher": "^2.1.0",
|
|
34
34
|
"@travetto/manifest": "^3.0.0-rc.15",
|
|
35
|
-
"@travetto/terminal": "^3.0.0-rc.
|
|
35
|
+
"@travetto/terminal": "^3.0.0-rc.9",
|
|
36
36
|
"@travetto/transformer": "^3.0.0-rc.19"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@travetto/cli": "^3.0.0-rc.
|
|
39
|
+
"@travetto/cli": "^3.0.0-rc.19"
|
|
40
40
|
},
|
|
41
41
|
"peerDependenciesMeta": {
|
|
42
42
|
"@travetto/cli": {
|
package/src/compiler.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { install } from 'source-map-support';
|
|
2
|
-
import timers from 'timers/promises';
|
|
3
2
|
import ts from 'typescript';
|
|
4
3
|
import fs from 'fs/promises';
|
|
5
4
|
|
|
@@ -12,8 +11,6 @@ import { CompilerWatcher } from './watch';
|
|
|
12
11
|
import { Log } from './log';
|
|
13
12
|
import { CompileEmitError, CompileEmitEvent, CompileEmitter } from './types';
|
|
14
13
|
|
|
15
|
-
const PING_THRESHOLD = 1000;
|
|
16
|
-
|
|
17
14
|
/**
|
|
18
15
|
* Compilation support
|
|
19
16
|
*/
|
|
@@ -134,11 +131,10 @@ export class Compiler {
|
|
|
134
131
|
if (watch) {
|
|
135
132
|
Log.info('Watch is ready');
|
|
136
133
|
await this.#watchLocalModules(emitter);
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
const output = this.#state.resolveOutputFile('.');
|
|
135
|
+
for await (const _ of fs.watch(output)) {
|
|
136
|
+
if (!await fs.stat(output).catch(() => false)) {
|
|
139
137
|
process.send?.('restart');
|
|
140
|
-
} else {
|
|
141
|
-
process.send?.('ping');
|
|
142
138
|
}
|
|
143
139
|
}
|
|
144
140
|
}
|
package/support/launcher.ts
CHANGED
|
@@ -108,7 +108,14 @@ async function exportManifest(ctx: ManifestContext, output?: string, env = 'dev'
|
|
|
108
108
|
* Launch
|
|
109
109
|
*/
|
|
110
110
|
export async function launch(ctx: ManifestContext, root: ManifestContext, op?: 'build' | 'watch' | 'manifest', args: (string | undefined)[] = []): Promise<void> {
|
|
111
|
+
// If quiet enabled, turn off all output by default
|
|
112
|
+
LogUtil.level = process.env.TRV_BUILD ?? (process.env.TRV_QUIET ? 'none' : (!op ? 'warn' : 'info'));
|
|
113
|
+
|
|
111
114
|
if (op !== 'manifest' && await LockManager.getCompileAction(root, op) === 'build') {
|
|
115
|
+
|
|
116
|
+
// Ready signal
|
|
117
|
+
process.send?.('ready');
|
|
118
|
+
|
|
112
119
|
await LockManager.withLocks(root, async (acquire, release) => {
|
|
113
120
|
let action: CompileResult;
|
|
114
121
|
do {
|
|
@@ -118,7 +125,10 @@ export async function launch(ctx: ManifestContext, root: ManifestContext, op?: '
|
|
|
118
125
|
}
|
|
119
126
|
action = await compile(root, op, msg => {
|
|
120
127
|
switch (msg) {
|
|
121
|
-
case 'build-complete':
|
|
128
|
+
case 'build-complete': {
|
|
129
|
+
release('build');
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
122
132
|
}
|
|
123
133
|
});
|
|
124
134
|
} while (action === 'restart');
|
package/support/lock.ts
CHANGED
|
@@ -50,7 +50,7 @@ export class LockManager {
|
|
|
50
50
|
const content = await fs.readFile(file, 'utf8');
|
|
51
51
|
const filePid = parseInt(content, 10);
|
|
52
52
|
if (stale) {
|
|
53
|
-
LogUtil.log('lock', [], '
|
|
53
|
+
LogUtil.log('lock', [], 'debug', `${type} file is stale: ${stat.mtimeMs} vs ${Date.now()}`);
|
|
54
54
|
} else {
|
|
55
55
|
pid = filePid;
|
|
56
56
|
}
|
|
@@ -118,25 +118,24 @@ export class LockManager {
|
|
|
118
118
|
* Read the watch lock file and determine its result, communicating with the user as necessary
|
|
119
119
|
*/
|
|
120
120
|
static async #getWatchAction(ctx: ManifestContext, log: CompilerLogger, lockType: LockType | undefined, buildState: LockDetails): Promise<LockAction> {
|
|
121
|
-
const level = lockType ? 'info' : 'debug';
|
|
122
121
|
if (lockType === 'watch') {
|
|
123
|
-
log(
|
|
122
|
+
log('info', 'Already running');
|
|
124
123
|
return 'skip';
|
|
125
124
|
} else {
|
|
126
125
|
if (buildState.pid) {
|
|
127
|
-
log('
|
|
126
|
+
log('warn', 'Already running, waiting for build to finish');
|
|
128
127
|
switch (await this.#waitForRelease(ctx, 'build')) {
|
|
129
128
|
case 'complete': {
|
|
130
|
-
log(
|
|
129
|
+
log('info', 'Completed build');
|
|
131
130
|
return 'skip';
|
|
132
131
|
}
|
|
133
132
|
case 'stale': {
|
|
134
|
-
log(
|
|
133
|
+
log('info', 'Became stale, retrying');
|
|
135
134
|
return 'retry';
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
137
|
} else {
|
|
139
|
-
log(
|
|
138
|
+
log('info', 'Already running, and has built');
|
|
140
139
|
return 'skip';
|
|
141
140
|
}
|
|
142
141
|
}
|
|
@@ -146,21 +145,20 @@ export class LockManager {
|
|
|
146
145
|
* Read the build lock file and determine its result, communicating with the user as necessary
|
|
147
146
|
*/
|
|
148
147
|
static async #getBuildAction(ctx: ManifestContext, log: CompilerLogger, lockType: LockType | undefined): Promise<LockAction> {
|
|
149
|
-
const level = lockType ? 'info' : 'debug';
|
|
150
148
|
if (lockType === 'watch') {
|
|
151
|
-
log('
|
|
149
|
+
log('warn', 'Build already running, waiting to begin watch');
|
|
152
150
|
const res = await this.#waitForRelease(ctx, 'build');
|
|
153
|
-
log(
|
|
151
|
+
log('info', `Finished with status of ${res}, retrying`);
|
|
154
152
|
return 'retry';
|
|
155
153
|
} else {
|
|
156
|
-
log('
|
|
154
|
+
log('warn', 'Already running, waiting for completion');
|
|
157
155
|
switch (await this.#waitForRelease(ctx, lockType ?? 'build')) {
|
|
158
156
|
case 'complete': {
|
|
159
|
-
log(
|
|
157
|
+
log('info', 'Completed');
|
|
160
158
|
return 'skip';
|
|
161
159
|
}
|
|
162
160
|
case 'stale': {
|
|
163
|
-
log(
|
|
161
|
+
log('info', 'Became stale, retrying');
|
|
164
162
|
return 'retry';
|
|
165
163
|
}
|
|
166
164
|
}
|
package/support/log.ts
CHANGED
|
@@ -2,16 +2,24 @@ export type CompilerLogEvent = [level: 'info' | 'debug' | 'warn', message: strin
|
|
|
2
2
|
export type CompilerLogger = (...args: CompilerLogEvent) => void;
|
|
3
3
|
export type WithLogger<T> = (log: CompilerLogger) => Promise<T>;
|
|
4
4
|
|
|
5
|
-
const ENV_LEVEL = process.env.TRV_BUILD ?? 'info';
|
|
6
|
-
const LEVELS = {
|
|
7
|
-
warn: /^(debug|info|warn)$/.test(ENV_LEVEL),
|
|
8
|
-
info: /^(debug|info)$/.test(ENV_LEVEL),
|
|
9
|
-
debug: /^debug$/.test(ENV_LEVEL),
|
|
10
|
-
};
|
|
11
5
|
const SCOPE_MAX = 15;
|
|
12
6
|
|
|
13
7
|
export class LogUtil {
|
|
14
8
|
|
|
9
|
+
static levels: {
|
|
10
|
+
debug: boolean;
|
|
11
|
+
info: boolean;
|
|
12
|
+
warn: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static set level(value: string) {
|
|
16
|
+
this.levels = {
|
|
17
|
+
warn: /^(debug|info|warn)$/.test(value),
|
|
18
|
+
info: /^(debug|info)$/.test(value),
|
|
19
|
+
debug: /^debug$/.test(value),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
15
23
|
/**
|
|
16
24
|
* Is object a log event
|
|
17
25
|
*/
|
|
@@ -22,7 +30,14 @@ export class LogUtil {
|
|
|
22
30
|
*/
|
|
23
31
|
static log(scope: string, args: string[], ...[level, msg]: CompilerLogEvent): void {
|
|
24
32
|
const message = msg.replaceAll(process.cwd(), '.');
|
|
25
|
-
|
|
33
|
+
if (LogUtil.levels[level]) {
|
|
34
|
+
const params = [`[${scope.padEnd(SCOPE_MAX, ' ')}]`, ...args, message];
|
|
35
|
+
if (!/(0|false|off|no)$/i.test(process.env.TRV_LOG_TIME ?? '')) {
|
|
36
|
+
params.unshift(new Date().toISOString());
|
|
37
|
+
}
|
|
38
|
+
// eslint-disable-next-line no-console
|
|
39
|
+
console[level]!(...params);
|
|
40
|
+
}
|
|
26
41
|
}
|
|
27
42
|
|
|
28
43
|
/**
|
package/support/transpile.ts
CHANGED
|
@@ -166,13 +166,14 @@ export class TranspileUtil {
|
|
|
166
166
|
static async runCompiler(ctx: ManifestContext, manifest: ManifestRoot, changed: DeltaEvent[], watch: boolean, onMessage: (msg: unknown) => void): Promise<CompileResult> {
|
|
167
167
|
const compiler = path.resolve(ctx.workspacePath, ctx.compilerFolder);
|
|
168
168
|
const main = path.resolve(compiler, 'node_modules', '@travetto/compiler/support/compiler-entry.js');
|
|
169
|
-
const deltaFile = path.resolve(os.tmpdir(), `manifest-delta.${
|
|
169
|
+
const deltaFile = path.resolve(os.tmpdir(), `manifest-delta.${process.pid}.${process.ppid}.${Date.now()}.json`);
|
|
170
170
|
|
|
171
171
|
const changedFiles = changed[0]?.file === '*' ? ['*'] : changed.map(ev =>
|
|
172
172
|
path.resolve(manifest.workspacePath, manifest.modules[ev.module].sourceFolder, ev.file)
|
|
173
173
|
);
|
|
174
174
|
|
|
175
175
|
let proc: cp.ChildProcess | undefined;
|
|
176
|
+
let kill: (() => void) | undefined;
|
|
176
177
|
|
|
177
178
|
try {
|
|
178
179
|
await this.writeTextFile(deltaFile, changedFiles.join('\n'));
|
|
@@ -195,9 +196,14 @@ export class TranspileUtil {
|
|
|
195
196
|
}
|
|
196
197
|
})
|
|
197
198
|
.on('exit', code => (code !== null && code > 0) ? rej(new Error('Failed during compilation')) : res('complete'));
|
|
199
|
+
kill = (): void => { proc?.kill('SIGKILL'); };
|
|
200
|
+
process.on('exit', kill);
|
|
198
201
|
}));
|
|
199
202
|
} finally {
|
|
200
203
|
if (proc?.killed === false) { proc.kill('SIGKILL'); }
|
|
204
|
+
if (kill) {
|
|
205
|
+
process.removeListener('exit', kill);
|
|
206
|
+
}
|
|
201
207
|
await fs.rm(deltaFile, { force: true });
|
|
202
208
|
}
|
|
203
209
|
}
|