Skip to content

Commit

Permalink
Formatting (prettier).
Browse files Browse the repository at this point in the history
  • Loading branch information
seivan committed Apr 7, 2021
1 parent b539d31 commit a1b49fd
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions src/configuration.ts
Expand Up @@ -41,30 +41,35 @@ function fixConfig(ts: TSCommon, config: _ts.ParsedCommandLine) {
return config;
}

function readTsConfigExtendForTsNodeRecursively(cwd: string, ts: TSCommon, rawConfig: { [key: string]: any } = {}): TsConfigOptions {

function readTsConfigExtendForTsNodeRecursively(
cwd: string,
ts: TSCommon,
rawConfig: { [key: string]: any } = {}
): TsConfigOptions {
const configKey = 'ts-node';
const recurse = (extending: { [key: string]: any } = {}, original: { [key: string]: any } = {}) => {
return readTsConfigExtendForTsNodeRecursively(cwd, ts, { [configKey]: { ...extending[configKey], ...original[configKey] } });
}
const recurse = (
extending: { [key: string]: any } = {},
original: { [key: string]: any } = {}
) => {
return readTsConfigExtendForTsNodeRecursively(cwd, ts, {
[configKey]: { ...extending[configKey], ...original[configKey] },
});
};

const { extends: extendFile, ...config } = rawConfig;

const result = extendFile == undefined
?
filterRecognizedTsConfigTsNodeOptions(config[configKey])
:
[extendFile]
.filter(x => x && typeof x == 'string')
.map(x => x as string)
.map(extended => resolve(cwd, extended))
.map(pathString => ts.readConfigFile(pathString, ts.sys.readFile))
.map(readFile => readFile.config)
.map(extendedConfig => recurse(extendedConfig, config))
[0];
const result =
extendFile == undefined
? filterRecognizedTsConfigTsNodeOptions(config[configKey])
: [extendFile]
.filter((x) => x && typeof x == 'string')
.map((x) => x as string)
.map((extended) => resolve(cwd, extended))
.map((pathString) => ts.readConfigFile(pathString, ts.sys.readFile))
.map((readFile) => readFile.config)
.map((extendedConfig) => recurse(extendedConfig, config))[0];

return result ?? {};

}
/**
* Load TypeScript configuration. Returns the parsed TypeScript config and
Expand Down Expand Up @@ -130,7 +135,11 @@ export function readConfig(
}

// Fix ts-node options that come from tsconfig.json
const tsNodeOptionsFromTsconfig: TsConfigOptions = readTsConfigExtendForTsNodeRecursively(cwd, ts, config);
const tsNodeOptionsFromTsconfig: TsConfigOptions = readTsConfigExtendForTsNodeRecursively(
cwd,
ts,
config
);
// Remove resolution of "files".
const files =
rawApiOptions.files ?? tsNodeOptionsFromTsconfig.files ?? DEFAULTS.files;
Expand All @@ -144,9 +153,9 @@ export function readConfig(
const defaultCompilerOptionsForNodeVersion = skipDefaultCompilerOptions
? undefined
: {
...getDefaultTsconfigJsonForNodeVersion(ts).compilerOptions,
types: ['node'],
};
...getDefaultTsconfigJsonForNodeVersion(ts).compilerOptions,
types: ['node'],
};

// Merge compilerOptions from all sources
config.compilerOptions = Object.assign(
Expand Down

0 comments on commit a1b49fd

Please sign in to comment.