@travetto/compiler 3.3.0 → 3.3.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": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "description": "The compiler infrastructure for the Travetto framework",
5
5
  "keywords": [
6
6
  "compiler",
@@ -30,13 +30,13 @@
30
30
  "directory": "module/compiler"
31
31
  },
32
32
  "dependencies": {
33
- "@parcel/watcher": "^2.2.0",
34
- "@travetto/manifest": "^3.3.0",
35
- "@travetto/terminal": "^3.3.0",
36
- "@travetto/transformer": "^3.3.0"
33
+ "@parcel/watcher": "^2.3.0",
34
+ "@travetto/manifest": "^3.3.1",
35
+ "@travetto/terminal": "^3.3.1",
36
+ "@travetto/transformer": "^3.3.1"
37
37
  },
38
38
  "peerDependencies": {
39
- "@travetto/cli": "^3.3.0"
39
+ "@travetto/cli": "^3.3.3"
40
40
  },
41
41
  "peerDependenciesMeta": {
42
42
  "@travetto/cli": {
package/src/compiler.ts CHANGED
@@ -24,7 +24,7 @@ export class Compiler {
24
24
  const state = await CompilerState.get(RootIndex);
25
25
  const dirtyFiles = ManifestModuleUtil.getFileType(dirty) === 'ts' ? [dirty] : (await fs.readFile(dirty, 'utf8')).split(/\n/).filter(x => !!x);
26
26
  await new Compiler(state, dirtyFiles, watch === 'true').run();
27
- process.exit(0);
27
+ process.exit();
28
28
  }
29
29
 
30
30
  #state: CompilerState;
@@ -132,20 +132,23 @@ export class Compiler {
132
132
  if (this.#watch) {
133
133
  Log.info('Watch is ready');
134
134
  for await (const { file, action } of CompilerWatcher.watch(this.#state)) {
135
+ if (action === 'restart') {
136
+ Log.info(`Triggering restart due to change in ${file}`);
137
+ process.send?.({ type: 'restart' });
138
+ return;
139
+ }
140
+ const module = file.split('node_modules/')[1];
135
141
  if (action !== 'delete') {
136
142
  const err = await emitter(file, true);
137
143
  if (err) {
138
144
  Log.info('Compilation Error', CompilerUtil.buildTranspileError(file, err));
139
145
  } else {
140
- Log.info(`Compiled ${file.split('node_modules/')[1]}`);
146
+ Log.info(`Compiled ${module}`);
141
147
  }
142
148
  } else {
143
- Log.info(`Removed ${file.split('node_modules/')[1]}`);
149
+ Log.info(`Removed ${module}`);
144
150
  }
145
151
  }
146
- if (!process.exitCode) {
147
- process.send?.({ type: 'restart' });
148
- }
149
152
  }
150
153
  }
151
154
  }
package/src/watch.ts CHANGED
@@ -9,6 +9,9 @@ import { getManifestContext } from '@travetto/manifest/bin/context';
9
9
  import { CompilerState } from './state';
10
10
  import { CompilerUtil } from './util';
11
11
 
12
+ type CompileWatchEvent = WatchEvent | { action: 'restart', file: string };
13
+ const RESTART_SIGNAL = 'RESTART_SIGNAL';
14
+
12
15
  /**
13
16
  * Utils for watching
14
17
  */
@@ -19,7 +22,7 @@ export class CompilerWatcher {
19
22
  * @param state
20
23
  * @returns
21
24
  */
22
- static watch(state: CompilerState): AsyncIterable<WatchEvent> {
25
+ static watch(state: CompilerState): AsyncIterable<CompileWatchEvent> {
23
26
  return new CompilerWatcher(state).watchChanges();
24
27
  }
25
28
 
@@ -74,14 +77,15 @@ export class CompilerWatcher {
74
77
  * @param handler
75
78
  * @returns
76
79
  */
77
- async * watchChanges(): AsyncIterable<WatchEvent> {
80
+ async * watchChanges(): AsyncIterable<CompileWatchEvent> {
78
81
  const stream = this.#watchFiles();
79
82
 
80
83
  const mods = this.#getModuleMap();
81
84
  for await (const { file: sourceFile, action, folder } of stream) {
82
85
 
83
- if (folder === '.trv_internal') {
84
- break;
86
+ if (folder === RESTART_SIGNAL) {
87
+ yield { action: 'restart', file: sourceFile };
88
+ return;
85
89
  }
86
90
 
87
91
  const mod = mods[folder];
@@ -168,14 +172,27 @@ export class CompilerWatcher {
168
172
  const outputWatch = (root: string, sources: string[]): WatchFolder => {
169
173
  const valid = new Set(sources.map(src => path.resolve(root, src)));
170
174
  return {
171
- src: root, target: '.trv_internal', immediate: true, includeHidden: true,
175
+ src: root, target: RESTART_SIGNAL, immediate: true, includeHidden: true,
172
176
  filter: ev => ev.action === 'delete' && valid.has(path.resolve(root, ev.file))
173
177
  };
174
178
  };
179
+
180
+ const topLevelFiles = (root: string, files: string[]): WatchFolder => {
181
+ const valid = new Set(files.map(src => path.resolve(root, src)));
182
+ return {
183
+ src: root, target: RESTART_SIGNAL, immediate: true,
184
+ filter: ev => valid.has(path.resolve(root, ev.file))
185
+ };
186
+ };
187
+
175
188
  moduleFolders.push(
176
189
  outputWatch(RootIndex.manifest.workspacePath, [
177
190
  RootIndex.manifest.outputFolder,
178
191
  RootIndex.manifest.compilerFolder
192
+ ]),
193
+ topLevelFiles(RootIndex.manifest.workspacePath, [
194
+ 'package.json',
195
+ 'package-lock.json'
179
196
  ])
180
197
  );
181
198