@runtyped/type-compiler 1.0.20-alpha.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.
Files changed (84) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +4 -0
  3. package/compiler-debug.ts +38 -0
  4. package/deepkit-compiler-debug.js +5 -0
  5. package/deepkit-type-install.js +5 -0
  6. package/dist/cjs/compiler-debug.d.ts +1 -0
  7. package/dist/cjs/compiler-debug.js +28 -0
  8. package/dist/cjs/compiler-debug.js.map +1 -0
  9. package/dist/cjs/index.d.ts +7 -0
  10. package/dist/cjs/index.js +36 -0
  11. package/dist/cjs/index.js.map +1 -0
  12. package/dist/cjs/install-transformer.d.ts +7 -0
  13. package/dist/cjs/install-transformer.js +77 -0
  14. package/dist/cjs/install-transformer.js.map +1 -0
  15. package/dist/cjs/src/compiler.d.ts +313 -0
  16. package/dist/cjs/src/compiler.js +2506 -0
  17. package/dist/cjs/src/compiler.js.map +1 -0
  18. package/dist/cjs/src/config.d.ts +83 -0
  19. package/dist/cjs/src/config.js +248 -0
  20. package/dist/cjs/src/config.js.map +1 -0
  21. package/dist/cjs/src/debug.d.ts +9 -0
  22. package/dist/cjs/src/debug.js +26 -0
  23. package/dist/cjs/src/debug.js.map +1 -0
  24. package/dist/cjs/src/loader.d.ts +18 -0
  25. package/dist/cjs/src/loader.js +55 -0
  26. package/dist/cjs/src/loader.js.map +1 -0
  27. package/dist/cjs/src/plugin.d.ts +14 -0
  28. package/dist/cjs/src/plugin.js +46 -0
  29. package/dist/cjs/src/plugin.js.map +1 -0
  30. package/dist/cjs/src/reflection-ast.d.ts +46 -0
  31. package/dist/cjs/src/reflection-ast.js +335 -0
  32. package/dist/cjs/src/reflection-ast.js.map +1 -0
  33. package/dist/cjs/src/resolver.d.ts +27 -0
  34. package/dist/cjs/src/resolver.js +88 -0
  35. package/dist/cjs/src/resolver.js.map +1 -0
  36. package/dist/cjs/src/ts-types.d.ts +17 -0
  37. package/dist/cjs/src/ts-types.js +6 -0
  38. package/dist/cjs/src/ts-types.js.map +1 -0
  39. package/dist/esm/compiler-debug.d.ts +1 -0
  40. package/dist/esm/compiler-debug.js +26 -0
  41. package/dist/esm/compiler-debug.js.map +1 -0
  42. package/dist/esm/index.d.ts +7 -0
  43. package/dist/esm/index.js +19 -0
  44. package/dist/esm/index.js.map +1 -0
  45. package/dist/esm/install-transformer.d.ts +7 -0
  46. package/dist/esm/install-transformer.js +75 -0
  47. package/dist/esm/install-transformer.js.map +1 -0
  48. package/dist/esm/src/compiler.d.ts +313 -0
  49. package/dist/esm/src/compiler.js +2463 -0
  50. package/dist/esm/src/compiler.js.map +1 -0
  51. package/dist/esm/src/config.d.ts +83 -0
  52. package/dist/esm/src/config.js +238 -0
  53. package/dist/esm/src/config.js.map +1 -0
  54. package/dist/esm/src/debug.d.ts +9 -0
  55. package/dist/esm/src/debug.js +21 -0
  56. package/dist/esm/src/debug.js.map +1 -0
  57. package/dist/esm/src/loader.d.ts +18 -0
  58. package/dist/esm/src/loader.js +48 -0
  59. package/dist/esm/src/loader.js.map +1 -0
  60. package/dist/esm/src/plugin.d.ts +14 -0
  61. package/dist/esm/src/plugin.js +40 -0
  62. package/dist/esm/src/plugin.js.map +1 -0
  63. package/dist/esm/src/reflection-ast.d.ts +46 -0
  64. package/dist/esm/src/reflection-ast.js +284 -0
  65. package/dist/esm/src/reflection-ast.js.map +1 -0
  66. package/dist/esm/src/resolver.d.ts +27 -0
  67. package/dist/esm/src/resolver.js +80 -0
  68. package/dist/esm/src/resolver.js.map +1 -0
  69. package/dist/esm/src/ts-types.d.ts +17 -0
  70. package/dist/esm/src/ts-types.js +5 -0
  71. package/dist/esm/src/ts-types.js.map +1 -0
  72. package/index.ts +22 -0
  73. package/install-transformer.ts +84 -0
  74. package/package.json +59 -0
  75. package/src/compiler.ts +3003 -0
  76. package/src/config.ts +331 -0
  77. package/src/debug.ts +22 -0
  78. package/src/loader.ts +58 -0
  79. package/src/plugin.ts +58 -0
  80. package/src/reflection-ast.ts +335 -0
  81. package/src/resolver.ts +113 -0
  82. package/src/ts-types.ts +28 -0
  83. package/tsconfig.esm.json +16 -0
  84. package/tsconfig.json +27 -0
package/src/config.ts ADDED
@@ -0,0 +1,331 @@
1
+ import { dirname, isAbsolute, join } from 'path';
2
+ import type { CompilerOptions, ParseConfigHost } from 'typescript';
3
+ import ts from 'typescript';
4
+
5
+ import { debug, debug2, isDebug } from './debug.js';
6
+ import { patternMatch } from './resolver.js';
7
+
8
+ /**
9
+ * Default means reflection is enabled for this file.
10
+ * Never means the whole reflection is disabled for this file.
11
+ * Explicit means that reflection is per default disabled for this file, but each symbol/type
12
+ * in it is allowed to enable it using jsdoc `@reflection`.
13
+ */
14
+ export const reflectionModes = ['default', 'explicit', 'never'] as const;
15
+ export type Mode = (typeof reflectionModes)[number];
16
+ export type RawMode = Mode | '' | boolean | string | string[] | undefined;
17
+
18
+ // don't use from @runtyped/core since we don't want to have a dependency to @runtyped/core
19
+ export function isObject(obj: any): obj is { [key: string]: any } {
20
+ if (!obj) {
21
+ return false;
22
+ }
23
+ return typeof obj === 'object' && !Array.isArray(obj);
24
+ }
25
+
26
+ const defaultMergeStrategy = 'merge';
27
+
28
+ /**
29
+ * These are the values that can be in the tsconfig.json file.
30
+ */
31
+ export interface TsConfigJson {
32
+ extends?: string;
33
+ compilerOptions?: any;
34
+
35
+ reflection?: RawMode;
36
+
37
+ deepkitCompilerOptions?: {
38
+ /**
39
+ * Either true to activate reflection for all files compiled using this tsconfig,
40
+ * or a list of globs/file paths relative to this tsconfig.json.
41
+ * Globs/file paths can be prefixed with a ! to exclude them.
42
+ */
43
+ reflection?: RawMode;
44
+
45
+ /**
46
+ * If a tsconfig extends another tsconfig, this option defines how the reflection/exclude
47
+ * options are merged. The default strategy is `merge`, which means that the reflection/exclude
48
+ * options are merged with the parent tsconfig.json. If set to `replace`, the reflection/exclude
49
+ * options are not merged, but the parent tsconfig.json is ignored.
50
+ */
51
+ mergeStrategy?: 'merge' | 'replace';
52
+
53
+ /**
54
+ * List of globs/file paths relative to this tsconfig.json
55
+ * which are then excluded from the type compilation step.
56
+ * Per default a few global .d.ts files are excluded like `lib.dom*.d.ts` and `*typedarrays.d.ts`.
57
+ */
58
+ exclude?: string[];
59
+ };
60
+ }
61
+
62
+ /**
63
+ * Read config and parses under TypeScript specification.
64
+ */
65
+ function readTsConfig(parseConfigHost: ParseConfigHost, path: string): TsConfigJson | undefined {
66
+ const configFile = ts.readConfigFile(path, (path: string) => parseConfigHost.readFile(path));
67
+ if (configFile.error) {
68
+ debug(`Failed to read tsconfig ${path}: ${configFile.error.messageText}`);
69
+ return;
70
+ }
71
+
72
+ const parsed = ts.parseJsonConfigFileContent(configFile.config, parseConfigHost, dirname(path));
73
+ // errors we ignore entirely
74
+ const ignoredErrors = [
75
+ 18003, // No inputs were found in config file.
76
+ ];
77
+ // errors we soft ignore but still log
78
+ const softErrors: number[] = [
79
+ 18000, // Circularity detected while resolving configuration
80
+ ];
81
+ const errors = parsed.errors.filter(v => !ignoredErrors.includes(v.code));
82
+ if (errors.length) {
83
+ debug(`Failed to parse tsconfig ${path}: ${parsed.errors.map(v => v.messageText).join(', ')}`);
84
+ }
85
+ const hardErrors = errors.filter(v => !softErrors.includes(v.code));
86
+ if (hardErrors.length) {
87
+ return;
88
+ }
89
+
90
+ return Object.assign(configFile.config, {
91
+ compilerOptions: parsed.options,
92
+ });
93
+ }
94
+
95
+ export interface ReflectionConfig {
96
+ /**
97
+ * Allows to exclude type definitions/TS files from being included in the type compilation step.
98
+ * When a global .d.ts is matched, their types won't be embedded (useful to exclude DOM for example)
99
+ */
100
+ exclude?: string[];
101
+
102
+ /**
103
+ * Either a boolean indication general reflection mode,
104
+ * or a list of globs to match against.
105
+ */
106
+ reflection?: string[] | Mode;
107
+ }
108
+
109
+ export interface CurrentConfig extends ReflectionConfig {
110
+ compilerOptions: ts.CompilerOptions;
111
+ mergeStrategy?: 'merge' | 'replace';
112
+ extends?: string;
113
+ }
114
+
115
+ export interface ResolvedConfig extends ReflectionConfig {
116
+ path: string; //tsconfig path
117
+ compilerOptions: ts.CompilerOptions;
118
+ mergeStrategy: 'merge' | 'replace';
119
+ }
120
+
121
+ export function reflectionModeMatcher(config: ReflectionConfig, filePath: string): Mode {
122
+ if (Array.isArray(config.exclude)) {
123
+ if (patternMatch(filePath, config.exclude)) return 'never';
124
+ }
125
+ if (Array.isArray(config.reflection)) {
126
+ return patternMatch(filePath, config.reflection) ? 'default' : 'never';
127
+ }
128
+ if (config.reflection === 'default' || config.reflection === 'explicit') return config.reflection;
129
+ return 'never';
130
+ }
131
+
132
+ function ensureStringArray(value: any): string[] {
133
+ if (Array.isArray(value)) return value.map(v => '' + v);
134
+ if ('string' === typeof value) return [value];
135
+ return [];
136
+ }
137
+
138
+ export function parseRawMode(mode: RawMode): string[] | Mode {
139
+ if ('boolean' === typeof mode) return mode ? 'default' : 'never';
140
+ if (mode === 'default' || mode === 'explicit') return mode;
141
+ return ensureStringArray(mode);
142
+ }
143
+
144
+ function resolvePaths(baseDir: string, paths: any): void {
145
+ if (!paths || !Array.isArray(paths)) return;
146
+
147
+ for (let i = 0; i < paths.length; i++) {
148
+ if ('string' !== typeof paths[i]) continue;
149
+ if (isAbsolute(paths[i])) continue;
150
+ let path = paths[i];
151
+ let exclude = false;
152
+ if (path.startsWith('!')) {
153
+ exclude = true;
154
+ path = path.substring(1);
155
+ }
156
+
157
+ // we treat as relative if it starts with ./ or contains a /
158
+ if (path.startsWith('./') || path.includes('/')) {
159
+ path = join(baseDir, path);
160
+ }
161
+ // ensure backslashes are forward slashes
162
+ path = path.replace(/\\/g, '/');
163
+ if (exclude) path = '!' + path;
164
+ paths[i] = path;
165
+ }
166
+ }
167
+
168
+ function appendPaths(strategy: 'merge' | 'replace' = defaultMergeStrategy, parent: string[], existing?: string[]) {
169
+ // important to always return a new array, otherwise we would modify the parent array with subsequent calls
170
+ if (strategy === 'replace') {
171
+ // replace means we stick with existing if it is defined, otherwise we use parent
172
+ return [...(existing || parent)];
173
+ }
174
+ if (!existing) return [...parent];
175
+ return [...parent, ...existing];
176
+ }
177
+
178
+ function applyConfigValues(existing: CurrentConfig, parent: TsConfigJson, baseDir: string) {
179
+ const parentReflection = isObject(parent.deepkitCompilerOptions)
180
+ ? parent.deepkitCompilerOptions?.reflection
181
+ : parent.reflection;
182
+
183
+ if (isObject(parent.deepkitCompilerOptions) && 'undefined' === typeof existing.mergeStrategy) {
184
+ existing.mergeStrategy = parent.deepkitCompilerOptions.mergeStrategy;
185
+ }
186
+
187
+ if ('undefined' !== typeof parentReflection) {
188
+ const next = parseRawMode(parentReflection);
189
+ if ('undefined' === typeof existing.reflection) {
190
+ existing.reflection = next;
191
+ } else if ('string' === typeof existing.reflection) {
192
+ // if existing is already a string, there is nothing to inherit from parent
193
+ } else if (Array.isArray(next) && Array.isArray(existing.reflection)) {
194
+ existing.reflection = appendPaths(existing.mergeStrategy, next, existing.reflection);
195
+ } else if ('string' === typeof next && Array.isArray(existing.reflection)) {
196
+ // debug(`Warning: config parent tsconfig has reflection=${next}, but child tsconfig has reflection=${JSON.stringify(existing.reflection)}. reflection stays as array.`);
197
+ }
198
+ }
199
+
200
+ if (isObject(parent.deepkitCompilerOptions)) {
201
+ if (`undefined` !== typeof parent.deepkitCompilerOptions.exclude) {
202
+ const next = ensureStringArray(parent.deepkitCompilerOptions.exclude);
203
+ existing.exclude = appendPaths(existing.mergeStrategy, next, existing.exclude);
204
+ }
205
+ }
206
+
207
+ resolvePaths(baseDir, existing.reflection);
208
+ resolvePaths(baseDir, existing.exclude);
209
+
210
+ if (parent.compilerOptions) {
211
+ // typescript already correctly merges the compiler options
212
+ if (Object.keys(existing.compilerOptions).length === 0) {
213
+ Object.assign(existing.compilerOptions, parent.compilerOptions);
214
+ }
215
+ }
216
+ existing.extends = parent.extends;
217
+ }
218
+
219
+ export interface MatchResult {
220
+ tsConfigPath: string;
221
+ mode: (typeof reflectionModes)[number];
222
+ }
223
+
224
+ export const defaultExcluded = [
225
+ 'lib.dom*.d.ts',
226
+ '*typedarrays.d.ts',
227
+ 'lib.webworker*.d.ts',
228
+ 'lib.decorator*.d.ts',
229
+ 'lib.es2015.proxy.d.ts',
230
+ 'lib.es2020.sharedmemory.d.ts',
231
+ 'lib.es2015.core.d.ts',
232
+ ];
233
+
234
+ export type Matcher = (path: string) => MatchResult;
235
+ export type ConfigResolver = { match: Matcher; config: ResolvedConfig };
236
+ export type ReflectionConfigCache = { [path: string]: ConfigResolver };
237
+
238
+ export function getConfigResolver(
239
+ cache: ReflectionConfigCache,
240
+ host: ParseConfigHost,
241
+ compilerOptions: CompilerOptions,
242
+ sourceFile: { fileName: string },
243
+ tsConfigPath: string = '',
244
+ ): ConfigResolver {
245
+ let config: CurrentConfig = {
246
+ // We use the parameter `compilerOptions` only for compilerOptions.configFilePath.
247
+ // We load the compilerOptions manually since transformers don't get the full picture
248
+ // (path aliases are missing for example).
249
+ // It's important to load compilerOptions manually if there is compilerOptions.configFilePath
250
+ // since not all build tools provide the full compilerOptions.
251
+ compilerOptions: {},
252
+ };
253
+
254
+ tsConfigPath = tsConfigPath || ('string' === typeof compilerOptions.configFilePath ? compilerOptions.configFilePath : '');
255
+
256
+ if (tsConfigPath) {
257
+ if (cache[tsConfigPath]) return cache[tsConfigPath];
258
+ const configFile = readTsConfig(host, tsConfigPath);
259
+ if (configFile) applyConfigValues(config, configFile, dirname(tsConfigPath));
260
+ } else {
261
+ if (!tsConfigPath && sourceFile) {
262
+ //find tsconfig via sourceFile.fileName
263
+ const baseDir = dirname(sourceFile.fileName);
264
+ const configPath = ts.findConfigFile(baseDir, path => {
265
+ path = isAbsolute(path) ? path : join(baseDir, path);
266
+ return host.fileExists(path);
267
+ });
268
+ debug2(`No tsConfigPath|compilerOptions.configFilePath provided. Manually searching for tsconfig.json in ${baseDir} returned ${configPath}`);
269
+ if (configPath) {
270
+ //configPath might be relative to passed basedir
271
+ tsConfigPath = isAbsolute(configPath) ? configPath : join(baseDir, configPath);
272
+ }
273
+ }
274
+ if (tsConfigPath) {
275
+ if (cache[tsConfigPath]) return cache[tsConfigPath];
276
+ //configPath might be relative to passed basedir
277
+ const configFile = readTsConfig(host, tsConfigPath);
278
+ if (configFile) applyConfigValues(config, configFile, dirname(tsConfigPath));
279
+ }
280
+ }
281
+
282
+ if (tsConfigPath) {
283
+ let basePath = dirname(tsConfigPath);
284
+ let currentConfig = config;
285
+ const seen = new Set<string>();
286
+ seen.add(tsConfigPath);
287
+ //iterate through all configs (this.config.extends) until we have all reflection options found.
288
+ while (currentConfig.extends) {
289
+ const path = join(basePath, currentConfig.extends);
290
+ if (seen.has(path)) break;
291
+ seen.add(path);
292
+ const nextConfig = ts.readConfigFile(path, (path: string) => host.readFile(path));
293
+ if (!nextConfig) break;
294
+ basePath = dirname(path);
295
+ applyConfigValues(currentConfig, nextConfig.config, basePath);
296
+ }
297
+ } else {
298
+ throw new Error(`No tsconfig found for ${sourceFile?.fileName}, that is weird. Either provide a tsconfig or compilerOptions.configFilePath`);
299
+ }
300
+
301
+ config.exclude = config.exclude ? [...defaultExcluded, ...config.exclude] : [...defaultExcluded];
302
+
303
+ config.compilerOptions.configFilePath = tsConfigPath;
304
+
305
+ const resolvedConfig: ResolvedConfig = {
306
+ path: tsConfigPath,
307
+ // we want to maintain options passed from tsc API (transpile, Program)
308
+ compilerOptions: Object.assign(config.compilerOptions, compilerOptions),
309
+ exclude: config.exclude,
310
+ reflection: config.reflection,
311
+ mergeStrategy: config.mergeStrategy || defaultMergeStrategy,
312
+ };
313
+
314
+ if (isDebug()) {
315
+ debug(
316
+ `Found config ${resolvedConfig.path}:\nreflection:`,
317
+ resolvedConfig.reflection,
318
+ `\nexclude:`,
319
+ resolvedConfig.exclude,
320
+ `\npaths:`,
321
+ resolvedConfig.compilerOptions.paths,
322
+ );
323
+ }
324
+
325
+ const match = (path: string) => {
326
+ const mode = reflectionModeMatcher(config, path);
327
+ return { mode, tsConfigPath };
328
+ };
329
+
330
+ return (cache[tsConfigPath] = { config: resolvedConfig, match });
331
+ }
package/src/debug.ts ADDED
@@ -0,0 +1,22 @@
1
+ export function isDebug(level: number = 1) {
2
+ const expected = 'runtyped' + (level > 1 ? '+'.repeat(level - 1) : '');
3
+ return 'undefined' !== typeof process && 'string' === typeof process.env.DEBUG && process.env.DEBUG.includes(expected);
4
+ }
5
+
6
+ /**
7
+ * First level debugging with DEBUG=runtyped
8
+ */
9
+ export function debug(...message: any[]): void {
10
+ if (isDebug(1)) {
11
+ console.debug(...message);
12
+ }
13
+ }
14
+
15
+ /**
16
+ * Second level debugging with DEBUG=runtyped+
17
+ */
18
+ export function debug2(...message: any[]): void {
19
+ if (isDebug(2)) {
20
+ console.debug(...message);
21
+ }
22
+ }
package/src/loader.ts ADDED
@@ -0,0 +1,58 @@
1
+ import type { CompilerOptions, SourceFile, TransformationContext } from 'typescript';
2
+ import ts from 'typescript';
3
+ import { Cache, ReflectionTransformer } from './compiler.js';
4
+
5
+ export class DeepkitLoader {
6
+ protected options: CompilerOptions = {
7
+ allowJs: true,
8
+ declaration: false,
9
+ };
10
+
11
+ protected host = ts.createCompilerHost(this.options);
12
+
13
+ protected program = ts.createProgram([], this.options, this.host);
14
+
15
+ protected printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
16
+ protected cache = new Cache;
17
+
18
+ protected knownFiles: { [path: string]: string } = {};
19
+ protected sourceFiles: { [path: string]: SourceFile } = {};
20
+
21
+ constructor() {
22
+ const originReadFile = this.host.readFile;
23
+ this.host.readFile = (fileName: string) => {
24
+ if (this.knownFiles[fileName]) return this.knownFiles[fileName];
25
+ return originReadFile.call(this.host, fileName);
26
+ };
27
+
28
+ //the program should not write any files
29
+ this.host.writeFile = () => {
30
+ };
31
+
32
+ const originalGetSourceFile = this.host.getSourceFile;
33
+ this.host.getSourceFile = (fileName: string, languageVersion: ts.ScriptTarget, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined => {
34
+ if (this.sourceFiles[fileName]) return this.sourceFiles[fileName];
35
+ return originalGetSourceFile.call(this.host, fileName, languageVersion, onError, shouldCreateNewSourceFile);
36
+ };
37
+ }
38
+
39
+ transform(source: string, path: string): string {
40
+ this.knownFiles[path] = source;
41
+ const sourceFile = ts.createSourceFile(path, source, ts.ScriptTarget.ESNext, true, path.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
42
+ let newSource = source;
43
+
44
+ ts.transform(sourceFile, [
45
+ (context: TransformationContext) => {
46
+ const transformer = new ReflectionTransformer(context, this.cache).forHost(this.host).withReflection({ reflection: 'default' });
47
+ return (node: SourceFile): SourceFile => {
48
+ const sourceFile = transformer.transformSourceFile(node);
49
+
50
+ newSource = this.printer.printNode(ts.EmitHint.SourceFile, sourceFile, sourceFile);
51
+ return sourceFile;
52
+ };
53
+ }
54
+ ], this.options);
55
+
56
+ return newSource;
57
+ }
58
+ }
package/src/plugin.ts ADDED
@@ -0,0 +1,58 @@
1
+ import ts from 'typescript';
2
+ import { cwd } from 'process';
3
+ import { createFilter } from '@rollup/pluginutils';
4
+ import { declarationTransformer, transformer } from './compiler.js';
5
+
6
+ export interface Options {
7
+ include?: string;
8
+ exclude?: string;
9
+ tsConfig?: string;
10
+ transformers?: ts.CustomTransformers;
11
+ compilerOptions?: ts.CompilerOptions;
12
+ readFile?: (path: string) => string | undefined;
13
+ }
14
+
15
+ export type Transform = (code: string, fileName: string) => { code: string, map?: string } | undefined;
16
+
17
+ export function deepkitType(options: Options = {}): Transform {
18
+ const filter = createFilter(options.include ?? ['**/*.tsx', '**/*.ts'], options.exclude ?? 'node_modules/**');
19
+
20
+ const transformers = options.transformers || {
21
+ before: [transformer],
22
+ after: [declarationTransformer],
23
+ };
24
+
25
+ const configFilePath = options.tsConfig || cwd() + '/tsconfig.json';
26
+
27
+ const tsConfig = ts.readConfigFile(configFilePath, options.readFile || ts.sys.readFile);
28
+
29
+ if (tsConfig.error) {
30
+ throw new Error(ts.formatDiagnostic(tsConfig.error, {
31
+ getCanonicalFileName: (fileName: string) => fileName,
32
+ getCurrentDirectory: ts.sys.getCurrentDirectory,
33
+ getNewLine: () => ts.sys.newLine,
34
+ }));
35
+ }
36
+
37
+ const compilerOptions = Object.assign({
38
+ 'target': ts.ScriptTarget.ESNext,
39
+ 'module': ts.ModuleKind.ESNext,
40
+ configFilePath,
41
+ }, tsConfig.config, options.compilerOptions || {});
42
+
43
+ return function transform(code: string, fileName: string) {
44
+ if (!filter(fileName)) return;
45
+
46
+ const transformed = ts.transpileModule(code, {
47
+ compilerOptions,
48
+ fileName,
49
+ //@ts-ignore
50
+ transformers
51
+ });
52
+
53
+ return {
54
+ code: transformed.outputText,
55
+ map: transformed.sourceMapText,
56
+ };
57
+ };
58
+ }