1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const ts_morph_1 = require("ts-morph");
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function createSourceFile(mainFile, ...referencedFiles) {
|
13 | const project = createProject();
|
14 | referencedFiles.forEach(fileDetail => {
|
15 | project.createSourceFile(`test/${fileDetail.path}.ts`, fileDetail.content);
|
16 | });
|
17 | const mainSource = project.createSourceFile(`test/${mainFile.path}.ts`, mainFile.content);
|
18 | validateProject(project);
|
19 | return mainSource;
|
20 | }
|
21 | exports.createSourceFile = createSourceFile;
|
22 |
|
23 |
|
24 |
|
25 | function createProject() {
|
26 | return new ts_morph_1.Project({
|
27 | compilerOptions: {
|
28 | target: ts_morph_1.ts.ScriptTarget.ESNext,
|
29 | module: ts_morph_1.ts.ModuleKind.CommonJS,
|
30 | strict: true,
|
31 | noImplicitAny: true,
|
32 | strictNullChecks: true,
|
33 | strictFunctionTypes: true,
|
34 | strictPropertyInitialization: true,
|
35 | noImplicitThis: true,
|
36 | alwaysStrict: true,
|
37 | noImplicitReturns: true,
|
38 | noFallthroughCasesInSwitch: true,
|
39 | moduleResolution: ts_morph_1.ts.ModuleResolutionKind.NodeJs,
|
40 | experimentalDecorators: true,
|
41 | baseUrl: "./",
|
42 | paths: {
|
43 | "@airtasker/spot": ["./lib/src/lib"]
|
44 | }
|
45 | }
|
46 | });
|
47 | }
|
48 | exports.createProject = createProject;
|
49 | function createProjectFromExistingSourceFile(filePath) {
|
50 | const project = createProject();
|
51 | const file = project.addSourceFileAtPath(filePath);
|
52 | project.resolveSourceFileDependencies();
|
53 | validateProject(project);
|
54 | return { project, file };
|
55 | }
|
56 | exports.createProjectFromExistingSourceFile = createProjectFromExistingSourceFile;
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | function validateProject(project) {
|
63 | const diagnostics = project.getPreEmitDiagnostics();
|
64 | if (diagnostics.length > 0) {
|
65 | throw new Error(diagnostics
|
66 | .map(diagnostic => {
|
67 | const message = diagnostic.getMessageText();
|
68 | return typeof message === "string"
|
69 | ? message
|
70 | : message.getMessageText();
|
71 | })
|
72 | .join("\n"));
|
73 | }
|
74 | }
|
75 | exports.validateProject = validateProject;
|