Skip to content

Commit ae01679

Browse files
authored
Fix the race with project refernces computations (#1698)
1 parent 1ebf658 commit ae01679

10 files changed

+12306
-5
lines changed

internal/compiler/projectreferenceparser.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ func (t *projectReferenceParseTask) parse(projectReferenceParser *projectReferen
1818
if t.resolved == nil {
1919
return
2020
}
21-
if t.resolved.SourceToProjectReference() == nil {
22-
projectReferenceParser.wg.Queue(func() {
23-
t.resolved.ParseInputOutputNames()
24-
})
25-
}
21+
t.resolved.ParseInputOutputNames()
2622
if subReferences := t.resolved.ResolvedProjectReferencePaths(); len(subReferences) > 0 {
2723
t.subTasks = createProjectReferenceParseTasks(subReferences)
2824
}

internal/execute/tsctests/tscbuild_test.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,6 +2068,89 @@ func TestBuildProgramUpdates(t *testing.T) {
20682068
}
20692069
}
20702070

2071+
func TestBuildProjectsBuilding(t *testing.T) {
2072+
t.Parallel()
2073+
addPackageFiles := func(files FileMap, index int) {
2074+
files[fmt.Sprintf(`/user/username/projects/myproject/pkg%d/index.ts`, index)] = fmt.Sprintf(`export const pkg%d = %d;`, index, index)
2075+
var references string
2076+
if index > 0 {
2077+
references = `"references": [{ "path": "../pkg0" }],`
2078+
}
2079+
files[fmt.Sprintf(`/user/username/projects/myproject/pkg%d/tsconfig.json`, index)] = stringtestutil.Dedent(fmt.Sprintf(`
2080+
{
2081+
"compilerOptions": { "composite": true },
2082+
%s
2083+
}`, references))
2084+
}
2085+
addSolution := func(files FileMap, count int) {
2086+
var pkgReferences []string
2087+
for i := range count {
2088+
pkgReferences = append(pkgReferences, fmt.Sprintf(`{ "path": "./pkg%d" }`, i))
2089+
}
2090+
files[`/user/username/projects/myproject/tsconfig.json`] = stringtestutil.Dedent(fmt.Sprintf(`
2091+
{
2092+
"compilerOptions": { "composite": true },
2093+
"references": [
2094+
%s
2095+
]
2096+
}`, strings.Join(pkgReferences, ",\n\t\t\t\t")))
2097+
}
2098+
files := func(count int) FileMap {
2099+
files := FileMap{}
2100+
for i := range count {
2101+
addPackageFiles(files, i)
2102+
}
2103+
addSolution(files, count)
2104+
return files
2105+
}
2106+
2107+
getTestCases := func(pkgCount int) []*tscInput {
2108+
edits := []*tscEdit{
2109+
{
2110+
caption: "dts doesn't change",
2111+
edit: func(sys *testSys) {
2112+
sys.appendFile(`/user/username/projects/myproject/pkg0/index.ts`, `const someConst2 = 10;`)
2113+
},
2114+
},
2115+
noChange,
2116+
{
2117+
caption: "dts change",
2118+
edit: func(sys *testSys) {
2119+
sys.appendFile(`/user/username/projects/myproject/pkg0/index.ts`, `export const someConst = 10;`)
2120+
},
2121+
},
2122+
noChange,
2123+
}
2124+
return []*tscInput{
2125+
{
2126+
subScenario: fmt.Sprintf(`when there are %d projects in a solution`, pkgCount),
2127+
files: files(pkgCount),
2128+
cwd: "/user/username/projects/myproject",
2129+
commandLineArgs: []string{"-b", "-v"},
2130+
edits: edits,
2131+
},
2132+
{
2133+
subScenario: fmt.Sprintf(`when there are %d projects in a solution`, pkgCount),
2134+
files: files(pkgCount),
2135+
cwd: "/user/username/projects/myproject",
2136+
commandLineArgs: []string{"-b", "-w", "-v"},
2137+
edits: edits,
2138+
},
2139+
}
2140+
}
2141+
2142+
testCases := slices.Concat(
2143+
getTestCases(3),
2144+
getTestCases(5),
2145+
getTestCases(8),
2146+
getTestCases(23),
2147+
)
2148+
2149+
for _, test := range testCases {
2150+
test.run(t, "projectsBuilding")
2151+
}
2152+
}
2153+
20712154
func TestBuildProjectReferenceWithRootDirInParent(t *testing.T) {
20722155
t.Parallel()
20732156
getBuildProjectReferenceWithRootDirInParentFileMap := func(modify func(files FileMap)) FileMap {

0 commit comments

Comments
 (0)