-
Notifications
You must be signed in to change notification settings - Fork 3
/
compiler.js
62 lines (53 loc) · 1.57 KB
/
compiler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { Babel, BabelCompiler } from 'meteor/babel-compiler';
import { transform } from '@babel/core';
import ignore from 'ignore';
export default class TypeScriptCompiler extends BabelCompiler {
constructor() {
super({
react: true,
});
}
/**
* Pass in the TypeScript compilation source map.
**/
inferExtraBabelOptions(inputFile, babelOptions, cacheDeps) {
const result = super.inferExtraBabelOptions(
inputFile,
babelOptions,
cacheDeps,
);
babelOptions.plugins = babelOptions.plugins || [];
babelOptions.plugins.unshift(
inputFile.require('@babel/plugin-transform-typescript'),
);
return result;
}
/**
* Process all files so we can removed ignored files before handing off to the Babel Compiler
**/
processFilesForTarget(inputFiles) {
inputFiles = this.removeIgnoredFiles(inputFiles);
super.processFilesForTarget(inputFiles);
}
removeIgnoredFiles(inputFiles) {
const ignoreFile = inputFiles.find(
(inputFile) => inputFile.getBasename() === '.tsignore',
);
if (!ignoreFile) {
return inputFiles;
}
const ignoredFiles = ignore().add(ignoreFile.getContentsAsString());
ignoredFiles.add('**/.tsignore');
const filter = ignoredFiles.createFilter();
return inputFiles.filter((inputFile) =>
filter(inputFile.getPathInPackage()),
);
}
processOneFileForTarget(inputFile) {
const result = super.processOneFileForTarget(inputFile);
if (result) {
result.path = result.path.replace(/\.ts(x)?/, '.js$1');
return result;
}
}
}