Skip to content

Commit

Permalink
fix(vite): do not set compiler options in project tsconfig.json
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Oct 18, 2024
1 parent c4213a5 commit e2c6a38
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
16 changes: 3 additions & 13 deletions packages/vite/src/generators/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,10 @@ export async function viteConfigurationGeneratorInternal(
tree,
joinPathFragments(projectRoot, 'tsconfig.lib.json'),
(json) => {
if (!json.compilerOptions) {
json.compilerOptions = {};
}
if (!json.compilerOptions.types) {
json.compilerOptions.types = [];
}
json.compilerOptions ??= {};
json.compilerOptions.types ??= [];
if (!json.compilerOptions.types.includes('vite/client')) {
return {
...json,
compilerOptions: {
...json.compilerOptions,
types: [...json.compilerOptions.types, 'vite/client'],
},
};
json.compilerOptions.types.push('vite/client');
}
return json;
}
Expand Down
32 changes: 21 additions & 11 deletions packages/vite/src/utils/generator-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,15 @@ export function editTsConfig(
) {
const projectConfig = readProjectConfiguration(tree, options.project);

const config = readJson(tree, `${projectConfig.root}/tsconfig.json`);
let tsconfigPath = joinPathFragments(projectConfig.root, 'tsconfig.json');
const isTsSolutionSetup = isUsingTsSolutionSetup(tree);
if (isTsSolutionSetup) {
tsconfigPath = [
joinPathFragments(projectConfig.root, 'tsconfig.app.json'),
joinPathFragments(projectConfig.root, 'tsconfig.lib.json'),
].find((p) => tree.exists(p));
}
const config = readJson(tree, tsconfigPath);

switch (options.uiFramework) {
case 'react':
Expand All @@ -245,21 +253,23 @@ export function editTsConfig(
};
break;
case 'none':
config.compilerOptions = {
module: 'commonjs',
forceConsistentCasingInFileNames: true,
strict: true,
noImplicitOverride: true,
noPropertyAccessFromIndexSignature: true,
noImplicitReturns: true,
noFallthroughCasesInSwitch: true,
};
if (!isTsSolutionSetup) {
config.compilerOptions = {
module: 'commonjs',
forceConsistentCasingInFileNames: true,
strict: true,
noImplicitOverride: true,
noPropertyAccessFromIndexSignature: true,
noImplicitReturns: true,
noFallthroughCasesInSwitch: true,
};
}
break;
default:
break;
}

writeJson(tree, `${projectConfig.root}/tsconfig.json`, config);
writeJson(tree, tsconfigPath, config);
}

export function deleteWebpackConfig(
Expand Down

0 comments on commit e2c6a38

Please sign in to comment.