@travetto/transformer 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.
@@ -1,57 +0,0 @@
1
- import * as ts from 'typescript';
2
- import { readFileSync } from 'fs';
3
-
4
- import { FsUtil, ScanFs } from '@travetto/boot';
5
- import { Util } from '@travetto/base';
6
-
7
- import { VisitorFactory, TransformerState, getAllTransformers } from '..';
8
-
9
- /**
10
- * Utils for testing transformers
11
- */
12
- export class TransformerTestUtil {
13
- /**
14
- * Compile a single file from a folder
15
- */
16
- static async compile(folder: string, file?: string): Promise<string> {
17
-
18
- const tsconfigObj = await import('@travetto/boot/tsconfig.trv.json');
19
-
20
- const prog = ts.createProgram({
21
- options: ts.convertCompilerOptionsFromJson(tsconfigObj, '').options,
22
- rootNames: (await ScanFs.scanDir({ testFile: f => f.startsWith('src/') && f.endsWith('.ts') }, folder))
23
- .filter(x => x.stats?.isFile())
24
- .filter(x => !file || x.file.endsWith(file))
25
- .map(x => x.file),
26
- });
27
- const log = `${folder}/.trv_compiler.log`;
28
-
29
- await FsUtil.unlinkRecursive(log);
30
-
31
- const transformers =
32
- (await ScanFs.scanDir({ testFile: f => f.startsWith('support/transformer') }, folder))
33
- .filter(x => x.stats?.isFile())
34
- .map(x => import(x.file).then(getAllTransformers));
35
-
36
- const visitor = new VisitorFactory(
37
- (ctx, src) => new TransformerState(src, ctx.factory, prog.getTypeChecker()),
38
- (await Promise.all(transformers)).flat(),
39
- log
40
- );
41
-
42
- const out = await new Promise<string>(res => {
43
- prog.emit(prog.getSourceFile(`src/${file}`), (__, data) => res(data), undefined, false,
44
- { before: [visitor.visitor()] }
45
- );
46
- });
47
-
48
- await Util.wait('1s'); // Wait for file buffer to sync
49
- try {
50
- console.info(readFileSync(log, 'utf8'));
51
- } catch { }
52
-
53
- await FsUtil.unlinkRecursive(log);
54
-
55
- return out;
56
- }
57
- }