-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: expand tsconfig.json include lists
- Loading branch information
1 parent
15d70e3
commit fde4338
Showing
19 changed files
with
5,328 additions
and
5,364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,44 @@ | ||
import minimatch from "minimatch"; | ||
import * as fs from "mz/fs"; | ||
import * as path from "path"; | ||
import * as ts from "typescript"; | ||
|
||
export const parseRawCompilerOptions = async (projectPath: string): Promise<ts.CompilerOptions> => { | ||
export interface ParsedCompilerOptions extends ts.CompilerOptions { | ||
include?: string[]; | ||
} | ||
|
||
export const parseRawCompilerOptions = async (cwd: string, projectPath: string): Promise<ts.CompilerOptions> => { | ||
const configRaw = (await fs.readFile(projectPath)).toString(); | ||
const compilerOptions = ts.parseConfigFileTextToJson(projectPath, configRaw); | ||
if (compilerOptions.error !== undefined) { | ||
throw new Error(`Could not parse compiler options from '${projectPath}': ${compilerOptions.error}`); | ||
} | ||
|
||
return compilerOptions.config as ts.CompilerOptions; | ||
const config = compilerOptions.config as ParsedCompilerOptions; | ||
|
||
// TSConfig includes often come in a glob form like ["src"] | ||
if (config.include) { | ||
config.include = ts.parseJsonConfigFileContent( | ||
compilerOptions.config, | ||
{ | ||
useCaseSensitiveFileNames: true, | ||
readDirectory: (rootDir, extensions, excludes, includes) => | ||
includes | ||
.flatMap((include) => | ||
fs.readdirSync(path.join(rootDir, include)).map((fileName) => path.join(rootDir, include, fileName)), | ||
) | ||
.filter( | ||
(filePath) => | ||
!excludes?.some((exclude) => minimatch(filePath, exclude)) && | ||
extensions.some((extension) => filePath.endsWith(extension)), | ||
) | ||
.map((filePath) => path.relative(rootDir, filePath)), | ||
fileExists: (filePath) => fs.statSync(filePath).isFile(), | ||
readFile: (filePath) => fs.readFileSync(filePath).toString(), | ||
}, | ||
cwd, | ||
).fileNames; | ||
} | ||
|
||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import minimatch from "minimatch"; | ||
import * as fs from "mz/fs"; | ||
import * as path from "path"; | ||
import * as ts from "typescript"; | ||
|
||
export const parseJsonConfigFileContent = (config: unknown, cwd: string, existingOptions?: ts.CompilerOptions) => { | ||
return ts.parseJsonConfigFileContent( | ||
config, | ||
{ | ||
useCaseSensitiveFileNames: true, | ||
readDirectory: (rootDir, extensions, excludes, includes) => | ||
includes | ||
.flatMap((include) => | ||
fs.readdirSync(path.join(rootDir, include)).map((fileName) => path.join(rootDir, include, fileName)), | ||
) | ||
.filter( | ||
(filePath) => | ||
!excludes?.some((exclude) => minimatch(filePath, exclude)) && | ||
extensions.some((extension) => filePath.endsWith(extension)), | ||
) | ||
.map((filePath) => path.relative(rootDir, filePath)), | ||
fileExists: (filePath) => fs.statSync(filePath).isFile(), | ||
readFile: (filePath) => fs.readFileSync(filePath).toString(), | ||
}, | ||
cwd, | ||
existingOptions, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* foo */ /* foo */ (function() { | ||
console.log("Hello, world!"); | ||
|
||
function ignoreChanges(): string { | ||
return undefined; | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(function() { | ||
console.log("Hello, world!"); | ||
|
||
function ignoreChanges(): string { | ||
return undefined; | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const prefix = "/* foo */ "; | ||
|
||
module.exports.fileMutator = (request) => { | ||
return request.sourceFile.getText().indexOf(prefix) === -1 | ||
? [ | ||
{ | ||
insertion: prefix, | ||
range: { | ||
begin: 0, | ||
}, | ||
type: "text-insert", | ||
}, | ||
] | ||
: []; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"include": ["*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"mutators": ["./sampleMutator.js"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* foo */ /* foo */ (function() { | ||
console.log("Hello, world!"); | ||
|
||
function ignoreChanges(): string { | ||
return undefined; | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(function() { | ||
console.log("Hello, world!"); | ||
|
||
function ignoreChanges(): string { | ||
return undefined; | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const prefix = "/* foo */ "; | ||
|
||
module.exports.fileMutator = (request) => { | ||
return request.sourceFile.getText().indexOf(prefix) === -1 | ||
? [ | ||
{ | ||
insertion: prefix, | ||
range: { | ||
begin: 0, | ||
}, | ||
type: "text-insert", | ||
}, | ||
] | ||
: []; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"include": ["."] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"mutators": ["./sampleMutator.js"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.