Skip to content

Commit ec11a7f

Browse files
authored
fix -p erroring when directly passed a config file (#486)
1 parent 1b76301 commit ec11a7f

File tree

6 files changed

+671
-1
lines changed

6 files changed

+671
-1
lines changed

internal/execute/tsc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func executeCommandLineWorker(sys System, cb cbType, commandLine *tsoptions.Pars
4949
}
5050

5151
fileOrDirectory := tspath.NormalizePath(commandLine.CompilerOptions().Project)
52-
if fileOrDirectory != "" || sys.FS().DirectoryExists(fileOrDirectory) {
52+
if sys.FS().DirectoryExists(fileOrDirectory) {
5353
configFileName = tspath.CombinePaths(fileOrDirectory, "tsconfig.json")
5454
if !sys.FS().FileExists(configFileName) {
5555
reportDiagnostic(ast.NewCompilerDiagnostic(diagnostics.Cannot_find_a_tsconfig_json_file_at_the_current_directory_Colon_0, configFileName))

internal/execute/tsc_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,38 @@ func TestTsc(t *testing.T) {
6565
sys: newTestSys(FileMap{"/home/src/workspaces/project/first.ts": `export const Key = Symbol()`}, ""),
6666
commandLineArgs: []string{"--lib", "es6 ", "first.ts"},
6767
},
68+
{
69+
subScenario: "Project is empty string",
70+
sys: newTestSys(FileMap{
71+
"/home/src/workspaces/project/first.ts": `export const a = 1`,
72+
"/home/src/workspaces/project/tsconfig.json": `{ "compilerOptions": { "strict": true, "noEmit": true } }`,
73+
}, ""),
74+
commandLineArgs: []string{},
75+
},
76+
{
77+
subScenario: "Parse -p",
78+
sys: newTestSys(FileMap{
79+
"/home/src/workspaces/project/first.ts": `export const a = 1`,
80+
"/home/src/workspaces/project/tsconfig.json": `{ "compilerOptions": { "strict": true, "noEmit": true } }`,
81+
}, ""),
82+
commandLineArgs: []string{"-p", "."},
83+
},
84+
{
85+
subScenario: "Parse -p with path to tsconfig file",
86+
sys: newTestSys(FileMap{
87+
"/home/src/workspaces/project/first.ts": `export const a = 1`,
88+
"/home/src/workspaces/project/tsconfig.json": `{ "compilerOptions": { "strict": true, "noEmit": true } }`,
89+
}, ""),
90+
commandLineArgs: []string{"-p", "/home/src/workspaces/project/tsconfig.json"},
91+
},
92+
{
93+
subScenario: "Parse -p with path to tsconfig folder",
94+
sys: newTestSys(FileMap{
95+
"/home/src/workspaces/project/first.ts": `export const a = 1`,
96+
"/home/src/workspaces/project/tsconfig.json": `{ "compilerOptions": { "strict": true, "noEmit": true } }`,
97+
}, ""),
98+
commandLineArgs: []string{"-p", "/home/src/workspaces/project"},
99+
},
68100
{
69101
subScenario: "Parse enum type options",
70102
sys: newTestSys(nil, ""),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
2+
currentDirectory::/home/src/workspaces/project
3+
useCaseSensitiveFileNames::true
4+
Input::-p /home/src/workspaces/project/tsconfig.json
5+
//// [/home/src/workspaces/project/first.ts] new file
6+
export const a = 1
7+
//// [/home/src/workspaces/project/tsconfig.json] new file
8+
{ "compilerOptions": { "strict": true, "noEmit": true } }
9+
10+
ExitStatus:: 0
11+
12+
ParsedCommandLine::{
13+
"parsedConfig": {
14+
"compilerOptions": {
15+
"allowJs": null,
16+
"allowArbitraryExtensions": null,
17+
"allowSyntheticDefaultImports": null,
18+
"allowImportingTsExtensions": null,
19+
"allowNonTsExtensions": null,
20+
"allowUmdGlobalAccess": null,
21+
"allowUnreachableCode": null,
22+
"allowUnusedLabels": null,
23+
"assumeChangesOnlyAffectDirectDependencies": null,
24+
"alwaysStrict": null,
25+
"baseUrl": "",
26+
"build": null,
27+
"checkJs": null,
28+
"customConditions": null,
29+
"composite": null,
30+
"emitDeclarationOnly": null,
31+
"emitBOM": null,
32+
"emitDecoratorMetadata": null,
33+
"downlevelIteration": null,
34+
"declaration": null,
35+
"declarationDir": "",
36+
"declarationMap": null,
37+
"disableSizeLimit": null,
38+
"disableSourceOfProjectReferenceRedirect": null,
39+
"disableSolutionSearching": null,
40+
"disableReferencedProjectLoad": null,
41+
"esModuleInterop": null,
42+
"exactOptionalPropertyTypes": null,
43+
"experimentalDecorators": null,
44+
"forceConsistentCasingInFileNames": null,
45+
"isolatedModules": null,
46+
"isolatedDeclarations": null,
47+
"ignoreDeprecations": "",
48+
"importHelpers": null,
49+
"inlineSourceMap": null,
50+
"inlineSources": null,
51+
"init": null,
52+
"incremental": null,
53+
"jsx": 0,
54+
"jsxFactory": "",
55+
"jsxFragmentFactory": "",
56+
"jsxImportSource": "",
57+
"keyofStringsOnly": null,
58+
"lib": null,
59+
"locale": "",
60+
"mapRoot": "",
61+
"module": 0,
62+
"moduleResolution": 0,
63+
"moduleSuffixes": null,
64+
"moduleDetectionKind": 0,
65+
"newLine": 0,
66+
"noEmit": null,
67+
"noCheck": null,
68+
"noErrorTruncation": null,
69+
"noFallthroughCasesInSwitch": null,
70+
"noImplicitAny": null,
71+
"noImplicitThis": null,
72+
"noImplicitReturns": null,
73+
"noEmitHelpers": null,
74+
"noLib": null,
75+
"noPropertyAccessFromIndexSignature": null,
76+
"noUncheckedIndexedAccess": null,
77+
"noEmitOnError": null,
78+
"noUnusedLocals": null,
79+
"noUnusedParameters": null,
80+
"noResolve": null,
81+
"noImplicitOverride": null,
82+
"noUncheckedSideEffectImports": null,
83+
"out": "",
84+
"outDir": "",
85+
"outFile": "",
86+
"paths": null,
87+
"preserveConstEnums": null,
88+
"preserveSymlinks": null,
89+
"project": "/home/src/workspaces/project/tsconfig.json",
90+
"resolveJsonModule": null,
91+
"resolvePackageJsonExports": null,
92+
"resolvePackageJsonImports": null,
93+
"removeComments": null,
94+
"rewriteRelativeImportExtensions": null,
95+
"reactNamespace": "",
96+
"rootDir": "",
97+
"rootDirs": null,
98+
"skipLibCheck": null,
99+
"strict": null,
100+
"strictBindCallApply": null,
101+
"strictBuiltinIteratorReturn": null,
102+
"strictFunctionTypes": null,
103+
"strictNullChecks": null,
104+
"strictPropertyInitialization": null,
105+
"stripInternal": null,
106+
"skipDefaultLibCheck": null,
107+
"sourceMap": null,
108+
"sourceRoot": "",
109+
"suppressOutputPathCheck": null,
110+
"target": 0,
111+
"traceResolution": null,
112+
"tsBuildInfoFile": "",
113+
"typeRoots": null,
114+
"types": null,
115+
"useDefineForClassFields": null,
116+
"useUnknownInCatchVariables": null,
117+
"verbatimModuleSyntax": null,
118+
"maxNodeModuleJsDepth": null,
119+
"configFilePath": "",
120+
"noDtsResolution": null,
121+
"pathsBasePath": "",
122+
"diagnostics": null,
123+
"extendedDiagnostics": null,
124+
"generateCpuProfile": "",
125+
"generateTrace": "",
126+
"listEmittedFiles": null,
127+
"listFiles": null,
128+
"explainFiles": null,
129+
"listFilesOnly": null,
130+
"noEmitForJsFiles": null,
131+
"preserveWatchOutput": null,
132+
"pretty": null,
133+
"version": null,
134+
"watch": null,
135+
"showConfig": null,
136+
"tscBuild": null
137+
},
138+
"watchOptions": {
139+
"watchInterval": null,
140+
"watchFile": 0,
141+
"watchDirectory": 0,
142+
"fallbackPolling": 0,
143+
"synchronousWatchDirectory": null,
144+
"excludeDirectories": null,
145+
"excludeFiles": null
146+
},
147+
"fileNames": [],
148+
"projectReferences": null
149+
},
150+
"configFile": null,
151+
"errors": [],
152+
"raw": {
153+
"project": "/home/src/workspaces/project/tsconfig.json"
154+
},
155+
"compileOnSave": null
156+
}
157+
Output::
158+
//// [/home/src/workspaces/project/first.ts] no change
159+
//// [/home/src/workspaces/project/tsconfig.json] no change
160+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
2+
currentDirectory::/home/src/workspaces/project
3+
useCaseSensitiveFileNames::true
4+
Input::-p /home/src/workspaces/project
5+
//// [/home/src/workspaces/project/first.ts] new file
6+
export const a = 1
7+
//// [/home/src/workspaces/project/tsconfig.json] new file
8+
{ "compilerOptions": { "strict": true, "noEmit": true } }
9+
10+
ExitStatus:: 0
11+
12+
ParsedCommandLine::{
13+
"parsedConfig": {
14+
"compilerOptions": {
15+
"allowJs": null,
16+
"allowArbitraryExtensions": null,
17+
"allowSyntheticDefaultImports": null,
18+
"allowImportingTsExtensions": null,
19+
"allowNonTsExtensions": null,
20+
"allowUmdGlobalAccess": null,
21+
"allowUnreachableCode": null,
22+
"allowUnusedLabels": null,
23+
"assumeChangesOnlyAffectDirectDependencies": null,
24+
"alwaysStrict": null,
25+
"baseUrl": "",
26+
"build": null,
27+
"checkJs": null,
28+
"customConditions": null,
29+
"composite": null,
30+
"emitDeclarationOnly": null,
31+
"emitBOM": null,
32+
"emitDecoratorMetadata": null,
33+
"downlevelIteration": null,
34+
"declaration": null,
35+
"declarationDir": "",
36+
"declarationMap": null,
37+
"disableSizeLimit": null,
38+
"disableSourceOfProjectReferenceRedirect": null,
39+
"disableSolutionSearching": null,
40+
"disableReferencedProjectLoad": null,
41+
"esModuleInterop": null,
42+
"exactOptionalPropertyTypes": null,
43+
"experimentalDecorators": null,
44+
"forceConsistentCasingInFileNames": null,
45+
"isolatedModules": null,
46+
"isolatedDeclarations": null,
47+
"ignoreDeprecations": "",
48+
"importHelpers": null,
49+
"inlineSourceMap": null,
50+
"inlineSources": null,
51+
"init": null,
52+
"incremental": null,
53+
"jsx": 0,
54+
"jsxFactory": "",
55+
"jsxFragmentFactory": "",
56+
"jsxImportSource": "",
57+
"keyofStringsOnly": null,
58+
"lib": null,
59+
"locale": "",
60+
"mapRoot": "",
61+
"module": 0,
62+
"moduleResolution": 0,
63+
"moduleSuffixes": null,
64+
"moduleDetectionKind": 0,
65+
"newLine": 0,
66+
"noEmit": null,
67+
"noCheck": null,
68+
"noErrorTruncation": null,
69+
"noFallthroughCasesInSwitch": null,
70+
"noImplicitAny": null,
71+
"noImplicitThis": null,
72+
"noImplicitReturns": null,
73+
"noEmitHelpers": null,
74+
"noLib": null,
75+
"noPropertyAccessFromIndexSignature": null,
76+
"noUncheckedIndexedAccess": null,
77+
"noEmitOnError": null,
78+
"noUnusedLocals": null,
79+
"noUnusedParameters": null,
80+
"noResolve": null,
81+
"noImplicitOverride": null,
82+
"noUncheckedSideEffectImports": null,
83+
"out": "",
84+
"outDir": "",
85+
"outFile": "",
86+
"paths": null,
87+
"preserveConstEnums": null,
88+
"preserveSymlinks": null,
89+
"project": "/home/src/workspaces/project",
90+
"resolveJsonModule": null,
91+
"resolvePackageJsonExports": null,
92+
"resolvePackageJsonImports": null,
93+
"removeComments": null,
94+
"rewriteRelativeImportExtensions": null,
95+
"reactNamespace": "",
96+
"rootDir": "",
97+
"rootDirs": null,
98+
"skipLibCheck": null,
99+
"strict": null,
100+
"strictBindCallApply": null,
101+
"strictBuiltinIteratorReturn": null,
102+
"strictFunctionTypes": null,
103+
"strictNullChecks": null,
104+
"strictPropertyInitialization": null,
105+
"stripInternal": null,
106+
"skipDefaultLibCheck": null,
107+
"sourceMap": null,
108+
"sourceRoot": "",
109+
"suppressOutputPathCheck": null,
110+
"target": 0,
111+
"traceResolution": null,
112+
"tsBuildInfoFile": "",
113+
"typeRoots": null,
114+
"types": null,
115+
"useDefineForClassFields": null,
116+
"useUnknownInCatchVariables": null,
117+
"verbatimModuleSyntax": null,
118+
"maxNodeModuleJsDepth": null,
119+
"configFilePath": "",
120+
"noDtsResolution": null,
121+
"pathsBasePath": "",
122+
"diagnostics": null,
123+
"extendedDiagnostics": null,
124+
"generateCpuProfile": "",
125+
"generateTrace": "",
126+
"listEmittedFiles": null,
127+
"listFiles": null,
128+
"explainFiles": null,
129+
"listFilesOnly": null,
130+
"noEmitForJsFiles": null,
131+
"preserveWatchOutput": null,
132+
"pretty": null,
133+
"version": null,
134+
"watch": null,
135+
"showConfig": null,
136+
"tscBuild": null
137+
},
138+
"watchOptions": {
139+
"watchInterval": null,
140+
"watchFile": 0,
141+
"watchDirectory": 0,
142+
"fallbackPolling": 0,
143+
"synchronousWatchDirectory": null,
144+
"excludeDirectories": null,
145+
"excludeFiles": null
146+
},
147+
"fileNames": [],
148+
"projectReferences": null
149+
},
150+
"configFile": null,
151+
"errors": [],
152+
"raw": {
153+
"project": "/home/src/workspaces/project"
154+
},
155+
"compileOnSave": null
156+
}
157+
Output::
158+
//// [/home/src/workspaces/project/first.ts] no change
159+
//// [/home/src/workspaces/project/tsconfig.json] no change
160+

0 commit comments

Comments
 (0)