@travetto/compiler 3.0.0-rc.28 → 3.0.0-rc.29

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": "3.0.0-rc.28",
3
+ "version": "3.0.0-rc.29",
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.9",
35
+ "@travetto/terminal": "^3.0.0-rc.10",
36
36
  "@travetto/transformer": "^3.0.0-rc.19"
37
37
  },
38
38
  "peerDependencies": {
39
- "@travetto/cli": "^3.0.0-rc.19"
39
+ "@travetto/cli": "^3.0.0-rc.20"
40
40
  },
41
41
  "peerDependenciesMeta": {
42
42
  "@travetto/cli": {
package/src/compiler.ts CHANGED
@@ -21,21 +21,22 @@ export class Compiler {
21
21
  */
22
22
  static async main(): Promise<void> {
23
23
  const [dirty, watch] = process.argv.slice(2);
24
- install();
24
+ const state = await CompilerState.get(RootIndex);
25
25
  const dirtyFiles = (await fs.readFile(dirty, 'utf8')).split(/\n/).filter(x => !!x);
26
- return new Compiler().init(dirtyFiles).then(c => c.run(watch === 'true'));
26
+ await new Compiler(state, dirtyFiles, watch === 'true').run();
27
+ process.exit(0);
27
28
  }
28
29
 
29
30
  #state: CompilerState;
30
31
  #dirtyFiles: string[];
32
+ #watch?: boolean;
31
33
 
32
- async init(dirtyFiles: string[]): Promise<this> {
33
- this.#state = await CompilerState.get(RootIndex);
34
+ constructor(state: CompilerState, dirtyFiles: string[], watch?: boolean) {
35
+ this.#state = state;
34
36
  this.#dirtyFiles = dirtyFiles[0] === '*' ?
35
37
  this.#state.getAllFiles() :
36
38
  dirtyFiles.map(f => this.#state.getBySource(f)!.input);
37
-
38
- return this;
39
+ this.#watch = watch;
39
40
  }
40
41
 
41
42
  /**
@@ -96,9 +97,14 @@ export class Compiler {
96
97
  /**
97
98
  * Run the compiler
98
99
  */
99
- async run(watch?: boolean): Promise<void> {
100
+ async run(): Promise<void> {
101
+ await GlobalTerminal.init();
102
+ install();
103
+
100
104
  Log.debug('Compilation started');
101
105
 
106
+ process.on('disconnect', () => process.exit(0));
107
+
102
108
  const emitter = await this.getCompiler();
103
109
  let failed = false;
104
110
 
@@ -120,7 +126,7 @@ export class Compiler {
120
126
  } else {
121
127
  Log.debug('Compilation succeeded');
122
128
  }
123
- } else if (watch) {
129
+ } else if (this.#watch) {
124
130
  // Prime compiler before complete
125
131
  const resolved = this.#state.getArbitraryInputFile();
126
132
  await emitter(resolved, true);
@@ -128,7 +134,7 @@ export class Compiler {
128
134
 
129
135
  process.send?.('build-complete');
130
136
 
131
- if (watch) {
137
+ if (this.#watch) {
132
138
  Log.info('Watch is ready');
133
139
  await this.#watchLocalModules(emitter);
134
140
  const output = this.#state.resolveOutputFile('.');
@@ -139,4 +145,4 @@ export class Compiler {
139
145
  }
140
146
  }
141
147
  }
142
- }
148
+ }
@@ -21,7 +21,10 @@ async function compile(ctx: ManifestContext, op: 'watch' | 'build' | undefined,
21
21
 
22
22
  await LogUtil.withLogger('precompile', async () => {
23
23
  for (const mod of PRECOMPILE_MODS) {
24
- changes += (await TranspileUtil.compileIfStale(ctx, 'precompile', mod, SOURCE_SEED)).length;
24
+ const count = (await TranspileUtil.compileIfStale(ctx, 'precompile', mod, SOURCE_SEED)).length;
25
+ if (mod !== '@travetto/terminal') {
26
+ changes += count;
27
+ }
25
28
  }
26
29
  });
27
30
 
package/support/lock.ts CHANGED
@@ -28,7 +28,7 @@ export class LockManager {
28
28
  * Get the lock file name
29
29
  */
30
30
  static #getFileName(ctx: ManifestContext, type: LockType): string {
31
- return path.resolve(ctx.workspacePath, ctx.toolFolder, `${type}.pid`);
31
+ return path.resolve(ctx.workspacePath, ctx.toolFolder, `${type}.lock`);
32
32
  }
33
33
 
34
34
  /**
@@ -47,8 +47,7 @@ export class LockManager {
47
47
  const stale = this.#isStale(stat);
48
48
  let pid: number | undefined;
49
49
  if (stat) {
50
- const content = await fs.readFile(file, 'utf8');
51
- const filePid = parseInt(content, 10);
50
+ const { pid: filePid } = JSON.parse(await fs.readFile(file, 'utf8'));
52
51
  if (stale) {
53
52
  LogUtil.log('lock', [], 'debug', `${type} file is stale: ${stat.mtimeMs} vs ${Date.now()}`);
54
53
  } else {
@@ -65,7 +64,7 @@ export class LockManager {
65
64
  const file = this.#getFileName(ctx, type);
66
65
  mkdirSync(path.dirname(file), { recursive: true });
67
66
  LogUtil.log('lock', [], 'debug', `Acquiring ${type}`);
68
- writeFileSync(file, `${process.pid}`, 'utf8');
67
+ writeFileSync(file, JSON.stringify({ pid: process.pid }), 'utf8');
69
68
  }
70
69
 
71
70
  /**
@@ -131,8 +131,8 @@ export class TranspileUtil {
131
131
  }
132
132
 
133
133
  /**
134
- * Recompile folder if stale
135
- */
134
+ * Recompile folder if stale
135
+ */
136
136
  static async compileIfStale(ctx: ManifestContext, scope: string, mod: string, seed: string[]): Promise<string[]> {
137
137
  const files = await this.getModuleSources(ctx, mod, seed);
138
138
  const changes = files.filter(x => x.stale).map(x => x.input);