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(vite): typecheck vue projects with vue-tsc #20242 #26450

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
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
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 @@ -86,8 +87,13 @@ export async function* viteBuildExecutor(
if (!options.skipTypeCheck) {
await validateTypes({
workspaceRoot: context.root,
projectRoot: projectRoot,
tsconfig: tsConfigForBuild,
isVueProject: Boolean(
resolved.config.plugins?.find(
(plugin: Plugin) =>
typeof plugin === 'object' && plugin?.name === 'vite:vue'
)
),
});
}

Expand Down
40 changes: 26 additions & 14 deletions packages/vite/src/utils/executor-utils.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
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: opts.tsconfig.startsWith(opts.workspaceRoot)
? opts.tsconfig
: join(opts.workspaceRoot, opts.tsconfig),
mode: 'noEmit',
});
if (!opts.isVueProject) {
const result = await runTypeCheck({
workspaceRoot: opts.workspaceRoot,
tsConfigPath: opts.tsconfig.startsWith(opts.workspaceRoot)
? opts.tsconfig
: 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