Skip to content

Commit

Permalink
fix(vite): add missing types for tsconfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
barbados-clemens committed Feb 25, 2023
1 parent 5bc73d3 commit f522af5
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion packages/react/src/utils/create-ts-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tree } from 'nx/src/generators/tree';
import * as shared from '@nrwl/js/src/utils/typescript/create-ts-config';
import { writeJson } from 'nx/src/generators/utils/json';
import { updateJson, writeJson } from 'nx/src/generators/utils/json';

export function createTsConfig(
host: Tree,
Expand Down Expand Up @@ -56,6 +56,38 @@ export function createTsConfig(
}

writeJson(host, `${projectRoot}/tsconfig.json`, json);

const tsconfigProjectPath = `${projectRoot}/tsconfig.${type}.json`;
if (host.exists(tsconfigProjectPath)) {
updateJson(host, tsconfigProjectPath, (json) => {
json.compilerOptions ??= {};

const types = new Set(json.compilerOptions.types ?? []);
types.add('node');
types.add('vite/client');

json.compilerOptions.types = Array.from(types);

return json;
});
}

const tsconfigSpecPath = `${projectRoot}/tsconfig.spec.json`;
if (options.unitTestRunner === 'vitest' && host.exists(tsconfigSpecPath)) {
updateJson(host, tsconfigSpecPath, (json) => {
json.compilerOptions ??= {};

const types = new Set(json.compilerOptions.types ?? []);
types.add('node');
types.add('vite/client');
types.add('vitest/globals');
types.add('vitest/importMeta');

json.compilerOptions.types = Array.from(types);

return json;
});
}
}

export function extractTsConfigBase(host: Tree) {
Expand Down

0 comments on commit f522af5

Please sign in to comment.