@travetto/compiler 5.0.0-rc.0 → 5.0.0-rc.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/compiler",
3
- "version": "5.0.0-rc.0",
3
+ "version": "5.0.0-rc.1",
4
4
  "description": "The compiler infrastructure for the Travetto framework",
5
5
  "keywords": [
6
6
  "compiler",
@@ -31,12 +31,12 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@parcel/watcher": "^2.4.1",
34
- "@travetto/manifest": "^5.0.0-rc.0",
34
+ "@travetto/manifest": "^5.0.0-rc.1",
35
35
  "@travetto/transformer": "^5.0.0-rc.0",
36
36
  "@types/node": "^20.14.10"
37
37
  },
38
38
  "peerDependencies": {
39
- "@travetto/cli": "^5.0.0-rc.0"
39
+ "@travetto/cli": "^5.0.0-rc.1"
40
40
  },
41
41
  "peerDependenciesMeta": {
42
42
  "@travetto/cli": {
@@ -71,10 +71,9 @@ export const main = (ctx: ManifestContext) => {
71
71
 
72
72
  /** Stream events */
73
73
  events: async (type: string, handler: (ev: unknown) => unknown): Promise<void> => {
74
- if (type === 'change' || type === 'log' || type === 'progress' || type === 'state') {
75
- for await (const ev of client.fetchEvents(type)) { await handler(ev); }
76
- } else if (type === 'all') {
77
- for await (const ev of client.fetchEvents(type)) { await handler(ev); }
74
+ if (type === 'change' || type === 'log' || type === 'progress' || type === 'state' || type === 'all') {
75
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
76
+ for await (const ev of client.fetchEvents(type as 'change')) { await handler(ev); }
78
77
  } else {
79
78
  throw new Error(`Unknown event type: ${type}`);
80
79
  }
@@ -16,12 +16,19 @@ export class ProcessHandle {
16
16
  }
17
17
 
18
18
  async writePid(pid: number): Promise<void> {
19
+ const current = await this.getPid();
20
+ if (!process.env.TRV_BUILD_REENTRANT && current && pid !== current && current > 0) {
21
+ try {
22
+ process.kill(current);
23
+ } catch { }
24
+ }
19
25
  await fs.mkdir(path.dirname(this.#file), { recursive: true });
20
26
  return fs.writeFile(this.#file, JSON.stringify(pid), 'utf8');
21
27
  }
22
28
 
23
29
  getPid(): Promise<number | undefined> {
24
- return fs.readFile(this.#file, 'utf8').then(v => +v, () => undefined);
30
+ return fs.readFile(this.#file, 'utf8')
31
+ .then(v => +v > 0 ? +v : undefined, () => undefined);
25
32
  }
26
33
 
27
34
  async isRunning(): Promise<boolean> {
@@ -190,9 +190,9 @@ export class CompilerServer {
190
190
 
191
191
  if (ev.type === 'state') {
192
192
  this.info.state = ev.payload.state;
193
- await this.#handle.compiler.writePid(this.info.compilerPid);
194
193
  if (ev.payload.state === 'init' && ev.payload.extra && 'pid' in ev.payload.extra && typeof ev.payload.extra.pid === 'number') {
195
194
  this.info.compilerPid = ev.payload.extra.pid;
195
+ await this.#handle.compiler.writePid(this.info.compilerPid);
196
196
  }
197
197
  log.info(`State changed: ${this.info.state}`);
198
198
  } else if (ev.type === 'log') {
@@ -249,4 +249,4 @@ export class CompilerServer {
249
249
  log.info(running ? 'Starting server' : 'Server already running under a different process', this.#url);
250
250
  return running ? this : undefined;
251
251
  }
252
- }
252
+ }