@travetto/compiler 3.0.0-rc.2 → 3.0.0-rc.21
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 +8 -5
- package/__index__.ts +6 -0
- package/bin/trv.js +71 -0
- package/package.json +32 -15
- package/src/compiler.ts +106 -147
- package/src/log.ts +18 -0
- package/src/state.ts +213 -0
- package/src/types.ts +14 -0
- package/src/util.ts +147 -0
- package/src/watch.ts +142 -0
- package/support/compiler-entry.ts +2 -0
- package/support/launcher.ts +139 -0
- package/support/lock-pinger.ts +25 -0
- package/support/lock.ts +237 -0
- package/support/log.ts +31 -0
- package/support/transpile.ts +202 -0
- package/tsconfig.trv.json +23 -0
- package/LICENSE +0 -21
- package/index.ts +0 -3
- package/src/host.ts +0 -142
- package/src/transformer.ts +0 -75
- package/support/dynamic.compiler.ts +0 -72
- package/support/phase.init.ts +0 -13
- package/support/phase.reset.ts +0 -10
package/src/transformer.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript';
|
|
2
|
-
|
|
3
|
-
import { SourceIndex } from '@travetto/boot/src/internal/source';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
NodeTransformer, VisitorFactory, TransformerState, getAllTransformers
|
|
7
|
-
} from '@travetto/transformer'; // Narrow import to minimize scope
|
|
8
|
-
|
|
9
|
-
type TransformerList = { before: ts.TransformerFactory<ts.SourceFile>[] };
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Manages the typescript transformers
|
|
14
|
-
*/
|
|
15
|
-
export class TransformerManager {
|
|
16
|
-
|
|
17
|
-
#cached: TransformerList | undefined;
|
|
18
|
-
#transformers: NodeTransformer<TransformerState>[] = [];
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Read all transformers from disk under the pattern support/transformer.*
|
|
22
|
-
*/
|
|
23
|
-
async init(): Promise<void> {
|
|
24
|
-
if (this.#cached) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Modules
|
|
29
|
-
const found = SourceIndex.find({ folder: 'support', filter: /\/transformer.*[.]ts/ });
|
|
30
|
-
|
|
31
|
-
for (const entry of found) { // Exclude based on blacklist
|
|
32
|
-
this.#transformers.push(...getAllTransformers(await import(entry.file)));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
console.debug('Transformers', {
|
|
36
|
-
order: this.#transformers.map(x => {
|
|
37
|
-
const flags = [
|
|
38
|
-
...(x.target ? [] : ['all']),
|
|
39
|
-
...(x.before ? ['before'] : []),
|
|
40
|
-
...(x.after ? ['after'] : [])
|
|
41
|
-
];
|
|
42
|
-
return { type: x.type, key: x.key, flags: flags.join(' ') };
|
|
43
|
-
})
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// Prepare a new visitor factory with a given type checker
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
build(checker: ts.TypeChecker): void {
|
|
50
|
-
const visitor = new VisitorFactory(
|
|
51
|
-
(ctx, src) => new TransformerState(src, ctx.factory, checker),
|
|
52
|
-
this.#transformers
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
// Define transformers for the compiler
|
|
56
|
-
this.#cached = {
|
|
57
|
-
before: [visitor.visitor()]
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Get typescript transformer object
|
|
63
|
-
*/
|
|
64
|
-
getTransformers(): TransformerList | undefined {
|
|
65
|
-
return this.#cached!;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Reset state
|
|
70
|
-
*/
|
|
71
|
-
reset(): void {
|
|
72
|
-
this.#transformers = [];
|
|
73
|
-
this.#cached = undefined;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { AppManifest, Class, ShutdownManager } from '@travetto/base';
|
|
2
|
-
import { RetargettingProxy } from '@travetto/base/src/internal/proxy';
|
|
3
|
-
import { FsUtil, PathUtil } from '@travetto/boot';
|
|
4
|
-
import { ModuleUtil } from '@travetto/boot/src/internal/module-util';
|
|
5
|
-
import { ModuleManager } from '@travetto/boot/src/internal/module';
|
|
6
|
-
|
|
7
|
-
import { FilePresenceManager } from '@travetto/watch';
|
|
8
|
-
|
|
9
|
-
import { Compiler } from '../src/compiler';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Wraps the compiler supporting real-time changes to files
|
|
13
|
-
*/
|
|
14
|
-
export function init($Compiler: Class<typeof Compiler>): typeof $Compiler {
|
|
15
|
-
/**
|
|
16
|
-
* Extending the $Compiler class to add some functionality
|
|
17
|
-
*/
|
|
18
|
-
const Cls = class extends $Compiler {
|
|
19
|
-
#modules = new Map<string, RetargettingProxy<unknown>>();
|
|
20
|
-
|
|
21
|
-
constructor(...args: unknown[]) {
|
|
22
|
-
super(...args);
|
|
23
|
-
|
|
24
|
-
ShutdownManager.onUnhandled(err => {
|
|
25
|
-
if (err && (err.message ?? '').includes('Cannot find module')) { // Handle module reloading
|
|
26
|
-
console.error('Cannot find module', { error: err });
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
}, 0);
|
|
30
|
-
|
|
31
|
-
// Proxy all file loads
|
|
32
|
-
ModuleUtil.addHandler((name, mod) => {
|
|
33
|
-
if (name.includes(PathUtil.cwd) && !name.includes('node_modules') && /src\//.test(name)) {
|
|
34
|
-
if (!this.#modules.has(name)) {
|
|
35
|
-
this.#modules.set(name, new RetargettingProxy(mod));
|
|
36
|
-
} else {
|
|
37
|
-
this.#modules.get(name)!.setTarget(mod);
|
|
38
|
-
}
|
|
39
|
-
return this.#modules.get(name)!.get();
|
|
40
|
-
} else {
|
|
41
|
-
return mod;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// Clear target on unload
|
|
46
|
-
ModuleManager.onUnload(f => this.#modules.get(f)?.setTarget(null));
|
|
47
|
-
|
|
48
|
-
new FilePresenceManager(
|
|
49
|
-
[...AppManifest.source.local, ...AppManifest.source.common]
|
|
50
|
-
.map(x => `./${x}`)
|
|
51
|
-
.filter(x => FsUtil.existsSync(x)),
|
|
52
|
-
{
|
|
53
|
-
ignoreInitial: true,
|
|
54
|
-
validFile: x => x.endsWith('.ts') && !x.endsWith('.d.ts')
|
|
55
|
-
}
|
|
56
|
-
).on('all', ({ event, entry }) => {
|
|
57
|
-
switch (event) {
|
|
58
|
-
case 'added': this.added(entry.file); break;
|
|
59
|
-
case 'removed': this.removed(entry.file); break;
|
|
60
|
-
case 'changed': this.changed(entry.file); break;
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
reset(): void {
|
|
66
|
-
super.reset();
|
|
67
|
-
this.#modules.clear();
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
return Cls;
|
|
72
|
-
}
|
package/support/phase.init.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Responsible for initializing the compiler
|
|
3
|
-
*/
|
|
4
|
-
export const init = {
|
|
5
|
-
key: '@trv:compiler/init',
|
|
6
|
-
after: ['@trv:base/init'],
|
|
7
|
-
before: ['@trv:base/transpile'],
|
|
8
|
-
action: async (): Promise<void> => {
|
|
9
|
-
// Overrides the require behavior
|
|
10
|
-
const { Compiler } = await import('../src/compiler');
|
|
11
|
-
await Compiler.init();
|
|
12
|
-
}
|
|
13
|
-
};
|
package/support/phase.reset.ts
DELETED