Skip to content

Commit

Permalink
fix svelte typecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
MP281X committed May 10, 2024
1 parent 8b92ac9 commit 7192520
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "module",
"version": "1.1.11",
"version": "1.1.12",
"name": "@mp281x/shared-config",
"publishConfig": { "registry": "https://npm.pkg.github.com/@mp281x" },

Expand Down
7 changes: 4 additions & 3 deletions src/lib/findProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const getWorkspaceProjects = (dir: string) => {
return globs.flatMap((glob) => findGlob(glob, { cwd: dir })).filter((path) => fs.existsSync(`${dir}/${path}/package.json`))
}

export type Project = { name: string; scripts: string[]; lspPlugin: boolean; cwd: string }
export type Project = { name: string; scripts: string[]; lspPlugin: boolean; cwd: string; type: 'svelte' | 'node' }
// find all the projects in a the monorepo/repo
export const findProjects = (dir: string = process.cwd()): Project[] => {
const projects = getWorkspaceProjects(dir).flatMap((project) => findProjects(project))
Expand All @@ -24,8 +24,8 @@ export const findProjects = (dir: string = process.cwd()): Project[] => {
if (!fs.existsSync(`${dir}/package.json`)) return []

// load the package info
type PackageJSON = { scripts?: Record<string, string> }
const { scripts } = parseConfig<PackageJSON>(`${dir}/package.json`) ?? {}
type PackageJSON = { scripts?: Record<string, string>; devDependencies?: Record<string, string> }
const { scripts, devDependencies } = parseConfig<PackageJSON>(`${dir}/package.json`) ?? {}

// read the tsconfig and check if the project is using the custom lsp plugin
type TSConfig = { compilerOptions?: { plugins?: { name: string }[] } }
Expand All @@ -37,6 +37,7 @@ export const findProjects = (dir: string = process.cwd()): Project[] => {
{
scripts: Object.keys(scripts ?? {}),
name: dir.split('/').pop() ?? '',
type: devDependencies?.['svelte'] ? 'svelte' : 'node',
lspPlugin,
cwd: dir
}
Expand Down
32 changes: 25 additions & 7 deletions src/task-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,31 @@ if (flags.length === 0 || flags.includes('--check')) {
})

// type check
for (const { name, cwd } of projects) {
await execCmd({
title: `${name}:tsc`,
cmd: ['tsc', '--noEmit'],
mode: 'sync',
cwd
})
for (const { name, cwd, type } of projects) {
if (type === 'svelte') {
await execCmd({
title: `svelte-sync:${name}`,
cmd: ['svelte-kit', 'sync'],
mode: 'sync',
cwd
})

await execCmd({
title: `svelte-check:${name}`,
cmd: ['svelte-check', '--output=human', '--tsconfig=./tsconfig.json'],
mode: 'sync',
cwd
})
}

if (type === 'node') {
await execCmd({
title: `${name}:tsc`,
cmd: ['tsc', '--noEmit'],
mode: 'sync',
cwd
})
}
}
}

Expand Down

0 comments on commit 7192520

Please sign in to comment.