Skip to content

Commit

Permalink
fix(vite): typecheck vue projects with vue-tsc #20242
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Jun 7, 2024
1 parent 7495f06 commit 88c02f1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
8 changes: 7 additions & 1 deletion packages/vite/src/executors/build/build.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
loadViteDynamicImport,
validateTypes,
} from '../../utils/executor-utils';
import { type Plugin } from 'vite';

export async function* viteBuildExecutor(
options: Record<string, any> & ViteBuildExecutorOptions,
Expand Down Expand Up @@ -82,8 +83,13 @@ export async function* viteBuildExecutor(
if (!options.skipTypeCheck) {
await validateTypes({
workspaceRoot: context.root,
projectRoot: projectRoot,
tsconfig: options.tsConfig ?? getProjectTsConfigPath(projectRoot),
isVueProject: Boolean(
resolved.config.plugins?.find(
(plugin: Plugin) =>
typeof plugin === 'object' && plugin?.name === 'vite:vue'
)
),
});
}

Expand Down
36 changes: 24 additions & 12 deletions packages/vite/src/utils/executor-utils.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
import { printDiagnostics, runTypeCheck } from '@nx/js';
import { join } from 'path';
import { ViteBuildExecutorOptions } from '../executors/build/schema';
import { ExecutorContext } from '@nx/devkit';
import { ExecutorContext, getPackageManagerCommand } from '@nx/devkit';
import { ViteDevServerExecutorOptions } from '../executors/dev-server/schema';
import {
calculateProjectBuildableDependencies,
createTmpTsConfig,
} from '@nx/js/src/utils/buildable-libs-utils';
import { getProjectTsConfigPath } from './options-utils';
import { execSync } from 'node:child_process';
import { printDiagnostics, runTypeCheck } from '@nx/js';
import { join } from 'path';

export async function validateTypes(opts: {
workspaceRoot: string;
projectRoot: string;
tsconfig: string;
isVueProject?: boolean;
}): Promise<void> {
const result = await runTypeCheck({
workspaceRoot: opts.workspaceRoot,
tsConfigPath: join(opts.workspaceRoot, opts.tsconfig),
mode: 'noEmit',
});
if (!opts.isVueProject) {
const result = await runTypeCheck({
workspaceRoot: opts.workspaceRoot,
tsConfigPath: join(opts.workspaceRoot, opts.tsconfig),
mode: 'noEmit',
});

await printDiagnostics(result.errors, result.warnings);
await printDiagnostics(result.errors, result.warnings);

if (result.errors.length > 0) {
throw new Error('Found type errors. See above.');
if (result.errors.length > 0) {
throw new Error('Found type errors. See above.');
}
} else {
const pm = getPackageManagerCommand();
const cp = execSync(
`${pm.exec} vue-tsc --noEmit -p ${opts.tsconfig} --composite false`,
{
cwd: opts.workspaceRoot,
stdio: 'inherit',
}
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const nxVersion = require('../../package.json').version;

// vue core
export const vueVersion = '^3.3.4';
export const vueTscVersion = '^1.8.8';
export const vueTscVersion = '^2.0.0';
export const vueRouterVersion = '^4.2.4';

// test deps
Expand Down

0 comments on commit 88c02f1

Please sign in to comment.