Skip to content
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

fix(tsload): fix tsconfig inheritance resolution #29766

Merged
merged 1 commit into from
Mar 1, 2024
Merged
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
10 changes: 7 additions & 3 deletions packages/playwright/src/third_party/tsconfig-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ function resolveConfigFile(baseConfigFile: string, referencedConfigFile: string)
referencedConfigFile += '.json';
const currentDir = path.dirname(baseConfigFile);
let resolvedConfigFile = path.resolve(currentDir, referencedConfigFile);
if (referencedConfigFile.indexOf('/') !== -1 && referencedConfigFile.indexOf('.') !== -1 && !fs.existsSync(referencedConfigFile))
// TODO: I don't see how this makes sense, delete in the next minor release.
if (referencedConfigFile.includes('/') && referencedConfigFile.includes('.') && !fs.existsSync(resolvedConfigFile))
Copy link
Member Author

Choose a reason for hiding this comment

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

This is where the bug was - referencedConfigFile vs resolvedConfigFile. We should delete this code altogether imo

resolvedConfigFile = path.join(currentDir, 'node_modules', referencedConfigFile);
return resolvedConfigFile;
}
Expand All @@ -117,6 +118,7 @@ function loadTsConfig(
let result: LoadedTsConfig = {
tsConfigPath: configFilePath,
};
// Retain result instance below, so that caching works.
visited.set(configFilePath, result);

if (!fs.existsSync(configFilePath))
Expand All @@ -137,7 +139,8 @@ function loadTsConfig(
const extendsDir = path.dirname(extendedConfig);
base.baseUrl = path.join(extendsDir, base.baseUrl);
}
result = { ...result, ...base, tsConfigPath: configFilePath };
// Retain result instance, so that caching works.
Object.assign(result, base, { tsConfigPath: configFilePath });
}

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

result = { ...result, ...loadedConfig };
// Retain result instance, so that caching works.
Object.assign(result, loadedConfig);

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