1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | const ts = require("typescript");
|
14 | const compilerOptions = {
|
15 | target: ts.ScriptTarget.ES2015,
|
16 | module: ts.ModuleKind.ES2015,
|
17 | moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
18 | strict: true,
|
19 | noUnusedLocals: true,
|
20 | noUnusedParameters: true,
|
21 | declaration: true,
|
22 | lib: [
|
23 | 'lib.dom.d.ts',
|
24 | 'lib.esnext.d.ts',
|
25 | ],
|
26 | };
|
27 | const diagnosticsHost = {
|
28 | getNewLine: () => '\n',
|
29 | getCurrentDirectory: () => process.cwd(),
|
30 | getCanonicalFileName: (fileName) => fileName,
|
31 | };
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | function verifyTypings(filePaths) {
|
40 | const program = ts.createProgram(filePaths, compilerOptions);
|
41 | const emitResult = program.emit();
|
42 | const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
43 | if (diagnostics.length > 0) {
|
44 | return {
|
45 | success: false,
|
46 | errorLog: ts.formatDiagnosticsWithColorAndContext(diagnostics, diagnosticsHost)
|
47 | };
|
48 | }
|
49 | return { success: true, errorLog: '' };
|
50 | }
|
51 | exports.verifyTypings = verifyTypings;
|
52 |
|
\ | No newline at end of file |