Skip to content

Commit 5e01a4f

Browse files
committed
tsc -b extends
1 parent cb3592d commit 5e01a4f

10 files changed

+1037
-237
lines changed

internal/execute/tsc_test.go

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -326,79 +326,6 @@ func TestNoEmit(t *testing.T) {
326326
}).run(t, "noEmit")
327327
}
328328

329-
func TestExtends(t *testing.T) {
330-
t.Parallel()
331-
extendsSysScenario := func(subScenario string, commandlineArgs []string) *tscInput {
332-
return &tscInput{
333-
subScenario: subScenario,
334-
commandLineArgs: commandlineArgs,
335-
files: FileMap{
336-
"/home/src/projects/configs/first/tsconfig.json": stringtestutil.Dedent(`
337-
{
338-
"extends": "../second/tsconfig.json",
339-
"include": ["${configDir}/src"],
340-
"compilerOptions": {
341-
"typeRoots": ["root1", "${configDir}/root2", "root3"],
342-
"types": [],
343-
}
344-
}`),
345-
"/home/src/projects/configs/second/tsconfig.json": stringtestutil.Dedent(`
346-
{
347-
"files": ["${configDir}/main.ts"],
348-
"compilerOptions": {
349-
"declarationDir": "${configDir}/decls",
350-
"paths": {
351-
"@myscope/*": ["${configDir}/types/*"],
352-
"other/*": ["other/*"],
353-
},
354-
"baseUrl": "${configDir}",
355-
},
356-
"watchOptions": {
357-
"excludeFiles": ["${configDir}/main.ts"],
358-
},
359-
}`),
360-
"/home/src/projects/myproject/tsconfig.json": stringtestutil.Dedent(`
361-
{
362-
"extends": "../configs/first/tsconfig.json",
363-
"compilerOptions": {
364-
"declaration": true,
365-
"outDir": "outDir",
366-
"traceResolution": true,
367-
},
368-
}`),
369-
"/home/src/projects/myproject/main.ts": stringtestutil.Dedent(`
370-
// some comment
371-
export const y = 10;
372-
import { x } from "@myscope/sometype";
373-
`),
374-
"/home/src/projects/myproject/src/secondary.ts": stringtestutil.Dedent(`
375-
// some comment
376-
export const z = 10;
377-
import { k } from "other/sometype2";
378-
`),
379-
"/home/src/projects/myproject/types/sometype.ts": stringtestutil.Dedent(`
380-
// some comment
381-
export const x = 10;
382-
`),
383-
"/home/src/projects/myproject/root2/other/sometype2/index.d.ts": stringtestutil.Dedent(`
384-
export const k = 10;
385-
`),
386-
},
387-
cwd: "/home/src/projects/myproject",
388-
}
389-
}
390-
391-
cases := []*tscInput{
392-
extendsSysScenario("configDir template", []string{"--explainFiles"}),
393-
extendsSysScenario("configDir template showConfig", []string{"--showConfig"}),
394-
extendsSysScenario("configDir template with commandline", []string{"--explainFiles", "--outDir", "${configDir}/outDir"}),
395-
}
396-
397-
for _, c := range cases {
398-
c.run(t, "extends")
399-
}
400-
}
401-
402329
func TestTypeAcquisition(t *testing.T) {
403330
t.Parallel()
404331
(&tscInput{
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
package execute_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/testutil/stringtestutil"
7+
"github.com/microsoft/typescript-go/internal/vfs/vfstest"
8+
)
9+
10+
func TestTscExtends(t *testing.T) {
11+
t.Parallel()
12+
testCases := []*tscInput{
13+
{
14+
subScenario: "when building solution with projects extends config with include",
15+
files: getBuildConfigFileExtendsFileMap(),
16+
cwd: "/home/src/workspaces/solution",
17+
commandLineArgs: []string{"--b", "--v", "--listFiles"},
18+
},
19+
{
20+
subScenario: "when building project uses reference and both extend config with include",
21+
files: getBuildConfigFileExtendsFileMap(),
22+
cwd: "/home/src/workspaces/solution",
23+
commandLineArgs: []string{"--b", "webpack/tsconfig.json", "--v", "--listFiles"},
24+
},
25+
getTscExtendsWithSymlinkTestCase("-p"),
26+
getTscExtendsWithSymlinkTestCase("-b"),
27+
getTscExtendsConfigDirTestCase("", []string{"--explainFiles"}),
28+
getTscExtendsConfigDirTestCase(" showConfig", []string{"--showConfig"}),
29+
getTscExtendsConfigDirTestCase(" with commandline", []string{"--explainFiles", "--outDir", "${configDir}/outDir"}),
30+
getTscExtendsConfigDirTestCase("", []string{"--b", "--explainFiles", "--v"}),
31+
}
32+
33+
for _, test := range testCases {
34+
test.run(t, "extends")
35+
}
36+
}
37+
38+
func getBuildConfigFileExtendsFileMap() FileMap {
39+
return FileMap{
40+
"/home/src/workspaces/solution/tsconfig.json": stringtestutil.Dedent(`
41+
{
42+
"references": [
43+
{ "path": "./shared/tsconfig.json" },
44+
{ "path": "./webpack/tsconfig.json" },
45+
],
46+
"files": [],
47+
}`),
48+
"/home/src/workspaces/solution/shared/tsconfig-base.json": stringtestutil.Dedent(`
49+
{
50+
"include": ["./typings-base/"],
51+
}`),
52+
"/home/src/workspaces/solution/shared/typings-base/globals.d.ts": `type Unrestricted = any;`,
53+
"/home/src/workspaces/solution/shared/tsconfig.json": stringtestutil.Dedent(`
54+
{
55+
"extends": "./tsconfig-base.json",
56+
"compilerOptions": {
57+
"composite": true,
58+
"outDir": "../target-tsc-build/",
59+
"rootDir": "..",
60+
},
61+
"files": ["./index.ts"],
62+
}`),
63+
"/home/src/workspaces/solution/shared/index.ts": `export const a: Unrestricted = 1;`,
64+
"/home/src/workspaces/solution/webpack/tsconfig.json": stringtestutil.Dedent(`
65+
{
66+
"extends": "../shared/tsconfig-base.json",
67+
"compilerOptions": {
68+
"composite": true,
69+
"outDir": "../target-tsc-build/",
70+
"rootDir": "..",
71+
},
72+
"files": ["./index.ts"],
73+
"references": [{ "path": "../shared/tsconfig.json" }],
74+
}`),
75+
"/home/src/workspaces/solution/webpack/index.ts": `export const b: Unrestricted = 1;`,
76+
}
77+
}
78+
79+
func getTscExtendsWithSymlinkTestCase(builtType string) *tscInput {
80+
return &tscInput{
81+
subScenario: "resolves the symlink path",
82+
files: FileMap{
83+
"/users/user/projects/myconfigs/node_modules/@something/tsconfig-node/tsconfig.json": stringtestutil.Dedent(`
84+
{
85+
"extends": "@something/tsconfig-base/tsconfig.json",
86+
"compilerOptions": {
87+
"removeComments": true
88+
}
89+
}
90+
`),
91+
"/users/user/projects/myconfigs/node_modules/@something/tsconfig-base/tsconfig.json": stringtestutil.Dedent(`
92+
{
93+
"compilerOptions": { "composite": true }
94+
}
95+
`),
96+
"/users/user/projects/myproject/src/index.ts": stringtestutil.Dedent(`
97+
// some comment
98+
export const x = 10;
99+
`),
100+
"/users/user/projects/myproject/src/tsconfig.json": stringtestutil.Dedent(`
101+
{
102+
"extends": "@something/tsconfig-node/tsconfig.json"
103+
}`),
104+
"/users/user/projects/myproject/node_modules/@something/tsconfig-node": vfstest.Symlink("/users/user/projects/myconfigs/node_modules/@something/tsconfig-node"),
105+
},
106+
cwd: "/users/user/projects/myproject",
107+
commandLineArgs: []string{builtType, "src", "--extendedDiagnostics"},
108+
}
109+
}
110+
111+
func getTscExtendsConfigDirTestCase(subScenarioSufix string, commandLineArgs []string) *tscInput {
112+
return &tscInput{
113+
subScenario: "configDir template" + subScenarioSufix,
114+
files: FileMap{
115+
"/home/src/projects/configs/first/tsconfig.json": stringtestutil.Dedent(`
116+
{
117+
"extends": "../second/tsconfig.json",
118+
"include": ["${configDir}/src"],
119+
"compilerOptions": {
120+
"typeRoots": ["root1", "${configDir}/root2", "root3"],
121+
"types": [],
122+
},
123+
}`),
124+
"/home/src/projects/configs/second/tsconfig.json": stringtestutil.Dedent(`
125+
{
126+
"files": ["${configDir}/main.ts"],
127+
"compilerOptions": {
128+
"declarationDir": "${configDir}/decls",
129+
"paths": {
130+
"@myscope/*": ["${configDir}/types/*"],
131+
},
132+
},
133+
"watchOptions": {
134+
"excludeFiles": ["${configDir}/main.ts"],
135+
},
136+
}`),
137+
"/home/src/projects/myproject/tsconfig.json": stringtestutil.Dedent(`
138+
{
139+
"extends": "../configs/first/tsconfig.json",
140+
"compilerOptions": {
141+
"declaration": true,
142+
"outDir": "outDir",
143+
"traceResolution": true,
144+
},
145+
}`),
146+
"/home/src/projects/myproject/main.ts": stringtestutil.Dedent(`
147+
// some comment
148+
export const y = 10;
149+
import { x } from "@myscope/sometype";
150+
`),
151+
"/home/src/projects/myproject/types/sometype.ts": stringtestutil.Dedent(`
152+
export const x = 10;
153+
`),
154+
},
155+
cwd: "/home/src/projects/myproject",
156+
commandLineArgs: commandLineArgs,
157+
}
158+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
currentDirectory::/home/src/projects/myproject
2+
useCaseSensitiveFileNames::true
3+
Input::
4+
//// [/home/src/projects/configs/first/tsconfig.json] *new*
5+
{
6+
"extends": "../second/tsconfig.json",
7+
"include": ["${configDir}/src"],
8+
"compilerOptions": {
9+
"typeRoots": ["root1", "${configDir}/root2", "root3"],
10+
"types": [],
11+
},
12+
}
13+
//// [/home/src/projects/configs/second/tsconfig.json] *new*
14+
{
15+
"files": ["${configDir}/main.ts"],
16+
"compilerOptions": {
17+
"declarationDir": "${configDir}/decls",
18+
"paths": {
19+
"@myscope/*": ["${configDir}/types/*"],
20+
},
21+
},
22+
"watchOptions": {
23+
"excludeFiles": ["${configDir}/main.ts"],
24+
},
25+
}
26+
//// [/home/src/projects/myproject/main.ts] *new*
27+
// some comment
28+
export const y = 10;
29+
import { x } from "@myscope/sometype";
30+
//// [/home/src/projects/myproject/tsconfig.json] *new*
31+
{
32+
"extends": "../configs/first/tsconfig.json",
33+
"compilerOptions": {
34+
"declaration": true,
35+
"outDir": "outDir",
36+
"traceResolution": true,
37+
},
38+
}
39+
//// [/home/src/projects/myproject/types/sometype.ts] *new*
40+
export const x = 10;
41+
42+
tsgo --b --explainFiles --v
43+
ExitStatus:: Success
44+
Output::
45+
[HH:MM:SS AM] Projects in this build:
46+
* tsconfig.json
47+
48+
[HH:MM:SS AM] Project 'tsconfig.json' is out of date because output file 'outDir/tsconfig.tsbuildinfo' does not exist
49+
50+
[HH:MM:SS AM] Building project 'tsconfig.json'...
51+
52+
======== Resolving module '@myscope/sometype' from '/home/src/projects/myproject/main.ts'. ========
53+
Module resolution kind is not specified, using 'Bundler'.
54+
Resolving in CJS mode with conditions 'require', 'types'.
55+
'paths' option is specified, looking for a pattern to match module name '@myscope/sometype'.
56+
Module name '@myscope/sometype', matched pattern '@myscope/*'.
57+
Trying substitution '/home/src/projects/myproject/types/*', candidate module location: '/home/src/projects/myproject/types/sometype'.
58+
Loading module as file / folder, candidate module location '/home/src/projects/myproject/types/sometype', target file types: TypeScript, JavaScript, Declaration, JSON.
59+
File '/home/src/projects/myproject/types/sometype.ts' exists - use it as a name resolution result.
60+
======== Module name '@myscope/sometype' was successfully resolved to '/home/src/projects/myproject/types/sometype.ts'. ========
61+
../../tslibs/TS/Lib/lib.d.ts
62+
Default library for target 'ES5'
63+
types/sometype.ts
64+
Imported via @myscope/sometype from file 'main.ts'
65+
main.ts
66+
Part of 'files' list in tsconfig.json
67+
//// [/home/src/projects/myproject/decls/main.d.ts] *new*
68+
// some comment
69+
export declare const y = 10;
70+
71+
//// [/home/src/projects/myproject/decls/types/sometype.d.ts] *new*
72+
export declare const x = 10;
73+
74+
//// [/home/src/projects/myproject/outDir/main.js] *new*
75+
"use strict";
76+
Object.defineProperty(exports, "__esModule", { value: true });
77+
exports.y = void 0;
78+
// some comment
79+
exports.y = 10;
80+
81+
//// [/home/src/projects/myproject/outDir/tsconfig.tsbuildinfo] *new*
82+
{"version":"FakeTSVersion","root":["../main.ts"]}
83+
//// [/home/src/projects/myproject/outDir/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
84+
{
85+
"version": "FakeTSVersion",
86+
"root": [
87+
{
88+
"files": [
89+
"../main.ts"
90+
],
91+
"original": "../main.ts"
92+
}
93+
],
94+
"size": 49
95+
}
96+
//// [/home/src/projects/myproject/outDir/types/sometype.js] *new*
97+
"use strict";
98+
Object.defineProperty(exports, "__esModule", { value: true });
99+
exports.x = void 0;
100+
exports.x = 10;
101+
102+
//// [/home/src/tslibs/TS/Lib/lib.d.ts] *Lib*
103+
/// <reference no-default-lib="true"/>
104+
interface Boolean {}
105+
interface Function {}
106+
interface CallableFunction {}
107+
interface NewableFunction {}
108+
interface IArguments {}
109+
interface Number { toExponential: any; }
110+
interface Object {}
111+
interface RegExp {}
112+
interface String { charAt: any; }
113+
interface Array<T> { length: number; [n: number]: T; }
114+
interface ReadonlyArray<T> {}
115+
interface SymbolConstructor {
116+
(desc?: string | number): symbol;
117+
for(name: string): symbol;
118+
readonly toStringTag: symbol;
119+
}
120+
declare var Symbol: SymbolConstructor;
121+
interface Symbol {
122+
readonly [Symbol.toStringTag]: string;
123+
}
124+
declare const console: { log(msg: any): void; };
125+
126+
tsconfig.json::
127+
SemanticDiagnostics::
128+
*refresh* /home/src/tslibs/TS/Lib/lib.d.ts
129+
*refresh* /home/src/projects/myproject/types/sometype.ts
130+
*refresh* /home/src/projects/myproject/main.ts
131+
Signatures::
132+
(stored at emit) /home/src/projects/myproject/types/sometype.ts
133+
(stored at emit) /home/src/projects/myproject/main.ts

0 commit comments

Comments
 (0)