@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.
- package/README.md +7 -12
- package/__index__.ts +15 -0
- package/package.json +13 -6
- package/src/importer.ts +120 -35
- package/src/manager.ts +74 -0
- package/src/register.ts +40 -11
- package/src/resolver/builder.ts +61 -53
- package/src/resolver/cache.ts +2 -2
- package/src/resolver/coerce.ts +103 -0
- package/src/resolver/service.ts +48 -9
- package/src/resolver/types.ts +7 -4
- package/src/state.ts +85 -71
- package/src/types/shared.ts +1 -1
- package/src/types/visitor.ts +7 -5
- package/src/util/core.ts +8 -6
- package/src/util/declaration.ts +3 -3
- package/src/util/decorator.ts +1 -1
- package/src/util/doc.ts +1 -1
- package/src/util/import.ts +17 -10
- package/src/util/literal.ts +3 -2
- package/src/util/log.ts +4 -5
- package/src/util/system.ts +31 -0
- package/src/visitor.ts +13 -33
- package/index.ts +0 -7
- package/src/util/index.ts +0 -6
- package/test-support/util.ts +0 -57
package/test-support/util.ts
DELETED
|
@@ -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
|
-
}
|