Skip to content

Add support for taking relative CLI args and using them as absolute internally #32992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ namespace ts {
name: "out",
type: "string",
affectsEmit: true,
isFilePath: false, // This is intentionally broken to support compatability with existing tsconfig files
isFilePath: false, // This is intentionally broken to support compatibility with existing tsconfig files
// for correct behaviour, please use outFile
category: Diagnostics.Advanced_Options,
paramType: Diagnostics.FILE,
Expand Down Expand Up @@ -2529,6 +2529,7 @@ namespace ts {
return options;
}

/* @internal */
function convertOptionsFromJson(optionDeclarations: readonly CommandLineOption[], jsonOptions: any, basePath: string,
defaultOptions: CompilerOptions | TypeAcquisition, diagnosticMessage: DiagnosticMessage, errors: Push<Diagnostic>) {

Expand All @@ -2541,7 +2542,16 @@ namespace ts {
for (const id in jsonOptions) {
const opt = optionNameMap.get(id);
if (opt) {
defaultOptions[opt.name] = convertJsonOption(opt, jsonOptions[id], basePath, errors);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is incorrect... You want do want to use convertJsonOption as was earlier here and combine the basePath with the nonrooted Paths as this is an API entry point and you cannot use sys.getCurrentDirectory() here..

The suggestedChange I recommended was to call convertOptionsFromJson with basePath as sys.getCurrentDirectory()

const value = convertJsonOption(opt, jsonOptions[id], basePath, errors);

const relative = isString(opt) && !isRootedDiskPath(opt);
if (relative && opt && opt.isFilePath) {
defaultOptions[opt.name] = getNormalizedAbsolutePath(value as string, sys.getCurrentDirectory());
}
else {
defaultOptions[opt.name] = value;
}
}
else {
errors.push(createCompilerDiagnostic(diagnosticMessage, id));
Expand Down
17 changes: 17 additions & 0 deletions src/testRunner/unittests/config/convertCompilerOptionsFromJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,23 @@ namespace ts {
);
});

it("Convert relative paths to absolute paths ", () => {
assertCompilerOptions({
compilerOptions: {
incremental: true,
outDir: "dist"
}
}, "tsconfig.json",
{
compilerOptions: {
incremental: true,
outDir: "/apath/dist",
configFilePath: "tsconfig.json"
},
errors: []
});
});

it("Convert tsconfig options when there are multiple invalid strings", () => {
assertCompilerOptionsWithJsonText(`{
"compilerOptions": {
Expand Down
1 change: 1 addition & 0 deletions src/tsc/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ namespace ts {
}

const commandLineOptions = commandLine.options;

if (configFileName) {
const configParseResult = parseConfigFileWithSystem(configFileName, commandLineOptions, sys, reportDiagnostic)!; // TODO: GH#18217
if (commandLineOptions.showConfig) {
Expand Down