@travetto/compiler 3.4.4 → 4.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/README.md +29 -27
- package/bin/common.js +51 -46
- package/bin/trvc.js +21 -14
- package/package.json +6 -7
- package/src/compiler.ts +96 -43
- package/src/event.ts +3 -3
- package/src/log.ts +1 -1
- package/src/state.ts +43 -25
- package/src/types.ts +1 -1
- package/src/util.ts +6 -6
- package/src/watch.ts +107 -117
- package/support/entry.trvc.ts +67 -37
- package/support/log.ts +55 -24
- package/support/queue.ts +11 -6
- package/support/server/client.ts +122 -81
- package/support/server/process-handle.ts +57 -0
- package/support/server/runner.ts +37 -64
- package/support/server/server.ts +86 -58
- package/support/setup.ts +38 -36
- package/support/types.ts +3 -4
- package/support/util.ts +20 -25
- package/src/internal/watch-core.ts +0 -104
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
|
|
3
|
-
import { IndexedModule, ManifestContext, ManifestModuleUtil, RootIndex, path } from '@travetto/manifest';
|
|
4
|
-
|
|
5
|
-
import { AsyncQueue } from '../../support/queue';
|
|
6
|
-
|
|
7
|
-
export type WatchEvent<T = {}> =
|
|
8
|
-
({ action: 'create' | 'update' | 'delete', file: string, folder: string } & T) |
|
|
9
|
-
{ action: 'reset', file: string };
|
|
10
|
-
|
|
11
|
-
const CREATE_THRESHOLD = 50;
|
|
12
|
-
const VALID_TYPES = new Set(['ts', 'typings', 'js', 'package-json']);
|
|
13
|
-
type ToWatch = { file: string, actions: string[] };
|
|
14
|
-
|
|
15
|
-
/** Watch file for reset */
|
|
16
|
-
async function watchForReset(q: AsyncQueue<WatchEvent>, root: string, files: ToWatch[], signal: AbortSignal): Promise<void> {
|
|
17
|
-
const watchers: Record<string, { folder: string, files: Map<string, (ToWatch & { name: string, actionSet: Set<string> })> }> = {};
|
|
18
|
-
// Group by base path
|
|
19
|
-
for (const el of files) {
|
|
20
|
-
const full = path.resolve(root, el.file);
|
|
21
|
-
const folder = path.dirname(full);
|
|
22
|
-
const tgt = { ...el, name: path.basename(el.file), actionSet: new Set(el.actions) };
|
|
23
|
-
const watcher = (watchers[folder] ??= { folder, files: new Map() });
|
|
24
|
-
watcher.files.set(tgt.name, tgt);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Fire them all off
|
|
28
|
-
Object.values(watchers).map(async (watcher) => {
|
|
29
|
-
for await (const ev of fs.watch(watcher.folder, { persistent: true, encoding: 'utf8', signal })) {
|
|
30
|
-
const toWatch = watcher.files.get(ev.filename!);
|
|
31
|
-
if (toWatch) {
|
|
32
|
-
const stat = await fs.stat(path.resolve(root, ev.filename!)).catch(() => undefined);
|
|
33
|
-
const action = !stat ? 'delete' : ((Date.now() - stat.ctimeMs) < CREATE_THRESHOLD) ? 'create' : 'update';
|
|
34
|
-
if (toWatch.actionSet.has(action)) {
|
|
35
|
-
q.add({ action: 'reset', file: ev.filename! });
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** Watch recursive files for a given folder */
|
|
43
|
-
async function watchFolder(ctx: ManifestContext, q: AsyncQueue<WatchEvent>, src: string, target: string, signal: AbortSignal): Promise<void> {
|
|
44
|
-
const lib = await import('@parcel/watcher');
|
|
45
|
-
const ignore = [
|
|
46
|
-
'node_modules', '**/.trv',
|
|
47
|
-
...((!ctx.monoRepo || src === ctx.workspacePath) ? [ctx.compilerFolder, ctx.outputFolder, ctx.toolFolder] : []),
|
|
48
|
-
...(await fs.readdir(src)).filter(x => x.startsWith('.'))
|
|
49
|
-
];
|
|
50
|
-
|
|
51
|
-
const cleanup = await lib.subscribe(src, async (err, events) => {
|
|
52
|
-
if (err) {
|
|
53
|
-
console.error('Watch Error', err);
|
|
54
|
-
}
|
|
55
|
-
for (const ev of events) {
|
|
56
|
-
const finalEv = { action: ev.type, file: path.toPosix(ev.path), folder: target };
|
|
57
|
-
if (ev.type !== 'delete') {
|
|
58
|
-
const stats = await fs.stat(finalEv.file);
|
|
59
|
-
if ((Date.now() - stats.ctimeMs) < CREATE_THRESHOLD) {
|
|
60
|
-
ev.type = 'create'; // Force create on newly stated files
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (ev.type === 'delete' && finalEv.file === src) {
|
|
65
|
-
return q.close();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const matches = !finalEv.file.includes('/.') && VALID_TYPES.has(ManifestModuleUtil.getFileType(finalEv.file));
|
|
69
|
-
if (matches) {
|
|
70
|
-
q.add(finalEv);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}, { ignore });
|
|
74
|
-
signal.addEventListener('abort', () => cleanup.unsubscribe());
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** Watch files */
|
|
78
|
-
export async function* fileWatchEvents(manifest: ManifestContext, modules: IndexedModule[], signal: AbortSignal): AsyncIterable<WatchEvent> {
|
|
79
|
-
const q = new AsyncQueue<WatchEvent>(signal);
|
|
80
|
-
|
|
81
|
-
for (const m of modules.filter(x => !manifest.monoRepo || x.sourcePath !== manifest.workspacePath)) {
|
|
82
|
-
watchFolder(manifest, q, m.sourcePath, m.sourcePath, signal);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Add monorepo folders
|
|
86
|
-
if (manifest.monoRepo) {
|
|
87
|
-
const mono = modules.find(x => x.sourcePath === manifest.workspacePath)!;
|
|
88
|
-
for (const folder of Object.keys(mono.files)) {
|
|
89
|
-
if (!folder.startsWith('$')) {
|
|
90
|
-
watchFolder(manifest, q, path.resolve(mono.sourcePath, folder), mono.sourcePath, signal);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
watchForReset(q, RootIndex.manifest.workspacePath, [
|
|
96
|
-
{ file: RootIndex.manifest.outputFolder, actions: ['delete'] },
|
|
97
|
-
{ file: RootIndex.manifest.compilerFolder, actions: ['delete'] },
|
|
98
|
-
{ file: RootIndex.manifest.toolFolder, actions: ['delete'] },
|
|
99
|
-
{ file: 'package-lock.json', actions: ['delete', 'update', 'create'] },
|
|
100
|
-
{ file: 'package.json', actions: ['delete', 'update', 'create'] }
|
|
101
|
-
], signal);
|
|
102
|
-
|
|
103
|
-
yield* q;
|
|
104
|
-
}
|