fix(vite): Update typings and fix when converting lib to vite (#18956)
This commit is contained in:
parent
610ac979f4
commit
8f1429da97
@ -2,13 +2,13 @@
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
|
||||
"types": ["node"]
|
||||
"types": [
|
||||
"node",
|
||||
<% if (style === 'styled-jsx') { %>"@nx/react/typings/styled-jsx.d.ts",<% } %>
|
||||
"@nx/react/typings/cssmodule.d.ts",
|
||||
"@nx/react/typings/image.d.ts"
|
||||
]
|
||||
},
|
||||
"files": [<% if (style === 'styled-jsx') { %>
|
||||
"<%= offsetFromRoot %>node_modules/@nx/react/typings/styled-jsx.d.ts",<% } %>
|
||||
"<%= offsetFromRoot %>node_modules/@nx/react/typings/cssmodule.d.ts",
|
||||
"<%= offsetFromRoot %>node_modules/@nx/react/typings/image.d.ts"
|
||||
],
|
||||
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"],
|
||||
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
||||
}
|
||||
|
||||
@ -2,13 +2,13 @@
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
|
||||
"types": ["node"]
|
||||
"types": [
|
||||
"node",
|
||||
<% if (style === 'styled-jsx') { %>"@nx/react/typings/styled-jsx.d.ts",<% } %>
|
||||
"@nx/react/typings/cssmodule.d.ts",
|
||||
"@nx/react/typings/image.d.ts"
|
||||
]
|
||||
},
|
||||
"files": [<% if (style === 'styled-jsx') { %>
|
||||
"<%= offsetFromRoot %>node_modules/@nx/react/typings/styled-jsx.d.ts",<% } %>
|
||||
"<%= offsetFromRoot %>node_modules/@nx/react/typings/cssmodule.d.ts",
|
||||
"<%= offsetFromRoot %>node_modules/@nx/react/typings/image.d.ts"
|
||||
],
|
||||
"exclude": ["**/*.spec.ts", "**/*.test.ts", "**/*.spec.tsx", "**/*.test.tsx", "**/*.spec.js", "**/*.test.js", "**/*.spec.jsx", "**/*.test.jsx"],
|
||||
"include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"]
|
||||
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
||||
}
|
||||
|
||||
@ -68,7 +68,12 @@ describe('lib', () => {
|
||||
unitTestRunner: 'vitest',
|
||||
});
|
||||
const tsconfigApp = readJson(tree, 'my-lib/tsconfig.lib.json');
|
||||
expect(tsconfigApp.compilerOptions.types).toEqual(['node', 'vite/client']);
|
||||
expect(tsconfigApp.compilerOptions.types).toEqual([
|
||||
'node',
|
||||
'@nx/react/typings/cssmodule.d.ts',
|
||||
'@nx/react/typings/image.d.ts',
|
||||
'vite/client',
|
||||
]);
|
||||
const tsconfigSpec = readJson(tree, 'my-lib/tsconfig.spec.json');
|
||||
expect(tsconfigSpec.compilerOptions.types).toEqual([
|
||||
'vitest/globals',
|
||||
|
||||
@ -2,9 +2,11 @@ import {
|
||||
convertNxGenerator,
|
||||
formatFiles,
|
||||
GeneratorCallback,
|
||||
joinPathFragments,
|
||||
readProjectConfiguration,
|
||||
runTasksInSerial,
|
||||
Tree,
|
||||
updateJson,
|
||||
} from '@nx/devkit';
|
||||
|
||||
import {
|
||||
@ -174,6 +176,22 @@ export async function viteConfigurationGenerator(
|
||||
}
|
||||
}
|
||||
|
||||
if (projectType === 'library') {
|
||||
// update tsconfig.lib.json to include vite/client
|
||||
updateJson(tree, joinPathFragments(root, 'tsconfig.lib.json'), (json) => {
|
||||
if (!json.compilerOptions.types.includes('vite/client')) {
|
||||
return {
|
||||
...json,
|
||||
compilerOptions: {
|
||||
...json.compilerOptions,
|
||||
types: [...json.compilerOptions.types, 'vite/client'],
|
||||
},
|
||||
};
|
||||
}
|
||||
return json;
|
||||
});
|
||||
}
|
||||
|
||||
createOrEditViteConfig(tree, schema, false, projectAlreadyHasViteTargets);
|
||||
|
||||
if (schema.includeVitest) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user