Skip to content

Commit b670506

Browse files
committed
cherry-pick(#29766): fix(tsload): fix tsconfig inheritance resolution
1 parent 3a43813 commit b670506

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/playwright/src/third_party/tsconfig-loader.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ function resolveConfigFile(baseConfigFile: string, referencedConfigFile: string)
101101
referencedConfigFile += '.json';
102102
const currentDir = path.dirname(baseConfigFile);
103103
let resolvedConfigFile = path.resolve(currentDir, referencedConfigFile);
104-
if (referencedConfigFile.indexOf('/') !== -1 && referencedConfigFile.indexOf('.') !== -1 && !fs.existsSync(referencedConfigFile))
104+
// TODO: I don't see how this makes sense, delete in the next minor release.
105+
if (referencedConfigFile.includes('/') && referencedConfigFile.includes('.') && !fs.existsSync(resolvedConfigFile))
105106
resolvedConfigFile = path.join(currentDir, 'node_modules', referencedConfigFile);
106107
return resolvedConfigFile;
107108
}
@@ -117,6 +118,7 @@ function loadTsConfig(
117118
let result: LoadedTsConfig = {
118119
tsConfigPath: configFilePath,
119120
};
121+
// Retain result instance below, so that caching works.
120122
visited.set(configFilePath, result);
121123

122124
if (!fs.existsSync(configFilePath))
@@ -137,7 +139,8 @@ function loadTsConfig(
137139
const extendsDir = path.dirname(extendedConfig);
138140
base.baseUrl = path.join(extendsDir, base.baseUrl);
139141
}
140-
result = { ...result, ...base, tsConfigPath: configFilePath };
142+
// Retain result instance, so that caching works.
143+
Object.assign(result, base, { tsConfigPath: configFilePath });
141144
}
142145

143146
const loadedConfig = Object.fromEntries(Object.entries({
@@ -146,7 +149,8 @@ function loadTsConfig(
146149
allowJs: parsedConfig?.compilerOptions?.allowJs,
147150
}).filter(([, value]) => value !== undefined));
148151

149-
result = { ...result, ...loadedConfig };
152+
// Retain result instance, so that caching works.
153+
Object.assign(result, loadedConfig);
150154

151155
for (const ref of parsedConfig.references || [])
152156
references.push(loadTsConfig(resolveConfigFile(configFilePath, ref.path), references, visited));

0 commit comments

Comments
 (0)