@travetto/compiler 4.0.9 → 4.1.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": "4.0.9",
3
+ "version": "4.1.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": "^4.0.3",
35
- "@travetto/transformer": "^4.0.4",
36
- "@types/node": "^20.11.25"
34
+ "@travetto/manifest": "^4.1.0",
35
+ "@travetto/transformer": "^4.1.1",
36
+ "@types/node": "^20.14.2"
37
37
  },
38
38
  "peerDependencies": {
39
- "@travetto/cli": "^4.0.7"
39
+ "@travetto/cli": "^4.1.1"
40
40
  },
41
41
  "peerDependenciesMeta": {
42
42
  "@travetto/cli": {
package/src/compiler.ts CHANGED
@@ -67,6 +67,7 @@ export class Compiler {
67
67
  case 'error': {
68
68
  process.exitCode = 1;
69
69
  if (err) {
70
+ EventUtil.sendEvent('log', { level: 'error', message: err.toString(), time: Date.now() });
70
71
  log.error('Shutting down due to failure', err.message);
71
72
  }
72
73
  break;
@@ -127,7 +128,7 @@ export class Compiler {
127
128
  EventUtil.sendEvent('state', { state: 'init', extra: { pid: process.pid } });
128
129
 
129
130
  const emitter = await this.getCompiler();
130
- let failed = false;
131
+ let failure: Error | undefined;
131
132
 
132
133
  log.debug('Compiler loaded');
133
134
 
@@ -136,17 +137,16 @@ export class Compiler {
136
137
  if (this.#dirtyFiles.length) {
137
138
  for await (const ev of this.emit(this.#dirtyFiles, emitter)) {
138
139
  if (ev.err) {
139
- failed = true;
140
140
  const compileError = CompilerUtil.buildTranspileError(ev.file, ev.err);
141
+ failure ??= compileError;
141
142
  EventUtil.sendEvent('log', { level: 'error', message: compileError.toString(), time: Date.now() });
142
143
  }
143
144
  }
144
145
  if (this.#signal.aborted) {
145
146
  log.debug('Compilation aborted');
146
- } else if (failed) {
147
+ } else if (failure) {
147
148
  log.debug('Compilation failed');
148
- process.exitCode = 1;
149
- return;
149
+ return this.#shutdown('error', failure);
150
150
  } else {
151
151
  log.debug('Compilation succeeded');
152
152
  }
package/src/state.ts CHANGED
@@ -63,14 +63,15 @@ export class CompilerState implements ts.CompilerHost {
63
63
 
64
64
  // Register all inputs
65
65
  for (const x of this.#modules) {
66
+ const base = x?.files ?? {};
66
67
  const files = [
67
- ...x.files.bin ?? [],
68
- ...x.files.src ?? [],
69
- ...x.files.support ?? [],
70
- ...x.files.doc ?? [],
71
- ...x.files.test ?? [],
72
- ...x.files.$index ?? [],
73
- ...x.files.$package ?? []
68
+ ...base.bin ?? [],
69
+ ...base.src ?? [],
70
+ ...base.support ?? [],
71
+ ...base.doc ?? [],
72
+ ...base.test ?? [],
73
+ ...base.$index ?? [],
74
+ ...base.$package ?? []
74
75
  ];
75
76
  for (const [file, type] of files) {
76
77
  if (CompilerUtil.validFile(type) || type === 'typings') {
@@ -103,7 +104,11 @@ export class CompilerState implements ts.CompilerHost {
103
104
  }
104
105
 
105
106
  getArbitraryInputFile(): string {
106
- return this.getBySource(this.#manifestIndex.getModule('@travetto/manifest')!.files.src[0].sourceFile)!.inputFile;
107
+ const randomSource = this.#manifestIndex.getWorkspaceModules()
108
+ .filter(x => x.files.src?.length)[0]
109
+ .files.src[0].sourceFile;
110
+
111
+ return this.getBySource(randomSource)!.inputFile;
107
112
  }
108
113
 
109
114
  async createProgram(force = false): Promise<ts.Program> {
package/src/util.ts CHANGED
@@ -105,7 +105,6 @@ export class CompilerUtil {
105
105
  }
106
106
 
107
107
  const errors: string[] = diagnostics.slice(0, 5).map(diag => {
108
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
109
108
  const message = ts.flattenDiagnosticMessageText(diag.messageText, '\n');
110
109
  if (diag.file) {
111
110
  const { line, character } = diag.file.getLineAndCharacterOfPosition(diag.start!);
package/src/watch.ts CHANGED
@@ -30,6 +30,10 @@ export class CompilerWatcher {
30
30
  this.#signal = signal;
31
31
  }
32
32
 
33
+ #reset(ev: WatchEvent): never {
34
+ throw new Error('RESET', { cause: `${ev.action}:${ev.file}` });
35
+ }
36
+
33
37
  #getIgnores(): string[] {
34
38
  // TODO: Read .gitignore?
35
39
  let ignores = PackageUtil.readPackage(this.#state.manifest.workspace.path)?.travetto?.build?.watchIgnores;
@@ -101,7 +105,11 @@ export class CompilerWatcher {
101
105
 
102
106
  for (const file of allFiles) {
103
107
  for (const parent of parents.get(file.mod)!) {
104
- moduleToFiles.get(parent)!.files.push(file);
108
+ const mod = moduleToFiles.get(parent);
109
+ if (!mod || !mod.files) {
110
+ this.#reset({ action: file.action, file: file.moduleFile });
111
+ }
112
+ mod.files.push(file);
105
113
  }
106
114
  }
107
115
 
@@ -157,7 +165,7 @@ export class CompilerWatcher {
157
165
  sourceFile === ROOT_PKG ||
158
166
  (action === 'delete' && (sourceFile === OUTPUT_PATH || sourceFile === COMPILER_PATH))
159
167
  ) {
160
- throw new Error('RESET', { cause: `${action}:${sourceFile}` });
168
+ this.#reset(ev);
161
169
  }
162
170
 
163
171
  const fileType = ManifestModuleUtil.getFileType(sourceFile);