Skip to content

Commit aebfa88

Browse files
committed
1 parent f79f4b5 commit aebfa88

File tree

2 files changed

+63
-29
lines changed

2 files changed

+63
-29
lines changed

scripts/check/check-package.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { existsSync } from 'node:fs';
12
import { isAbsolute } from 'node:path';
23
import { parseArgs } from 'node:util';
34

@@ -19,15 +20,17 @@ const normalizedCwd = cwd ? (isAbsolute(cwd) ? cwd : join(ROOT_DIRECTORY, cwd))
1920

2021
const tsconfigPath = join(normalizedCwd, 'tsconfig.json');
2122

22-
const { options, fileNames } = getTSFilesAndConfig(tsconfigPath, normalizedCwd);
23-
const { program, host } = getTSProgramAndHost(fileNames, options);
24-
25-
const tsDiagnostics = getTSDiagnostics(program, normalizedCwd, host);
26-
if (tsDiagnostics.length > 0) {
27-
console.log(tsDiagnostics);
28-
process.exit(1);
29-
} else if (!process.env.CI) {
30-
console.log('✅ No type errors');
23+
if (existsSync(tsconfigPath)) {
24+
const { options, fileNames } = getTSFilesAndConfig(tsconfigPath, normalizedCwd);
25+
const { program, host } = getTSProgramAndHost(fileNames, options);
26+
27+
const tsDiagnostics = getTSDiagnostics(program, normalizedCwd, host);
28+
if (tsDiagnostics.length > 0) {
29+
console.log(tsDiagnostics);
30+
process.exit(1);
31+
} else if (!process.env.CI) {
32+
console.log('✅ No type errors');
33+
}
3134
}
3235

3336
// TODO, add more package checks here, like:

scripts/tasks/check.ts

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,62 @@
1-
import type { Task } from '../task';
2-
import { ROOT_DIRECTORY } from '../utils/constants';
3-
import { exec } from '../utils/exec';
4-
import { maxConcurrentTasks } from '../utils/maxConcurrentTasks';
5-
6-
// The amount of VCPUs for the check task on CI is 4 (large resource)
1+
import { join } from 'node:path';
72

8-
const parallel = process.env.CI ? '' : `--parallel=${maxConcurrentTasks}`;
3+
// eslint-disable-next-line depend/ban-dependencies
4+
import { execaCommand } from 'execa';
95

10-
const linkCommand = `yarn nx run-many -t check ${parallel}`;
11-
const nolinkCommand = `yarn nx run-many -t check -c production ${parallel}`;
6+
import type { Task } from '../task';
7+
import { CODE_DIRECTORY, ROOT_DIRECTORY } from '../utils/constants';
8+
import { getCodeWorkspaces } from '../utils/workspace';
129

1310
export const check: Task = {
1411
description: 'Typecheck the source code of the monorepo',
1512
async ready() {
1613
return false;
1714
},
18-
async run(_, { dryRun, debug, link, skipCache }) {
19-
const command = link ? linkCommand : nolinkCommand;
20-
return exec(
21-
`${command} ${skipCache || process.env.CI ? '--skip-nx-cache' : ''}`,
22-
{ cwd: ROOT_DIRECTORY },
23-
{
24-
startMessage: '🥾 Checking for TS errors',
25-
errorMessage: '❌ TS errors detected',
26-
dryRun,
27-
debug,
15+
async run(_, {}) {
16+
const failed: string[] = [];
17+
// const command = link ? linkCommand : nolinkCommand;
18+
const workspaces = await getCodeWorkspaces();
19+
20+
for (const workspace of workspaces) {
21+
if (workspace.location === '.') {
22+
continue; // skip root directory
23+
}
24+
const cwd = join(CODE_DIRECTORY, workspace.location);
25+
console.log('');
26+
console.log('Checking ' + workspace.name + ' at ' + cwd);
27+
28+
let command = '';
29+
if (workspace.name === '@storybook/vue3') {
30+
command = `npx vue-tsc --noEmit --project ${join(cwd, 'tsconfig.json')}`;
31+
} else if (workspace.name === '@storybook/svelte') {
32+
command = `npx svelte-check`;
33+
} else {
34+
const script = join(ROOT_DIRECTORY, 'scripts', 'check', 'check-package.ts');
35+
command = `yarn exec jiti ${script} --cwd ${cwd}`;
36+
// command = `npx tsc --noEmit --project ${join(cwd, 'tsconfig.json')}`;
2837
}
29-
);
38+
39+
const sub = execaCommand(`${command}`, {
40+
cwd,
41+
env: {
42+
NODE_ENV: 'production',
43+
},
44+
});
45+
46+
sub.stdout?.on('data', (data) => {
47+
process.stdout.write(data);
48+
});
49+
sub.stderr?.on('data', (data) => {
50+
process.stderr.write(data);
51+
});
52+
53+
await sub.catch((error) => {
54+
failed.push(workspace.name);
55+
});
56+
}
57+
58+
if (failed.length > 0) {
59+
throw new Error(`Failed to check ${failed.join(', ')}`);
60+
}
3061
},
3162
};

0 commit comments

Comments
 (0)