diff --git a/bin/svelte-check-daemon.js b/bin/svelte-check-daemon.js index 96c23b8..f6fb369 100644 --- a/bin/svelte-check-daemon.js +++ b/bin/svelte-check-daemon.js @@ -13,6 +13,7 @@ const command = args[0]; function parseArgs() { let workspacePath = process.cwd(); let tsconfigPath = undefined; + let failOnWarnings = false; for (let i = 0; i < args.length; i++) { if (args[i] === '--workspace' && args[i + 1]) { @@ -21,10 +22,12 @@ function parseArgs() { } else if (args[i] === '--tsconfig' && args[i + 1]) { tsconfigPath = args[i + 1]; i++; + } else if (args[i] === '--fail-on-warnings') { + failOnWarnings = true; } } - return { workspacePath, tsconfigPath }; + return { workspacePath, tsconfigPath, failOnWarnings }; } async function runDaemon() { @@ -34,7 +37,7 @@ async function runDaemon() { } async function runCheck() { - const { workspacePath, tsconfigPath } = parseArgs(); + const { workspacePath, tsconfigPath, failOnWarnings } = parseArgs(); // In CI, always run svelte-kit sync first to ensure generated types are up to date if (process.env.CI || !isDaemonRunning(workspacePath)) { @@ -52,7 +55,7 @@ async function runCheck() { console.error('\x1b[33m Start the daemon with: svelte-check-daemon start\x1b[0m\n'); } - const { success, output } = runSvelteCheckDirectly(workspacePath, tsconfigPath); + const { success, output } = runSvelteCheckDirectly(workspacePath, tsconfigPath, failOnWarnings); console.log(output); process.exit(success ? 0 : 1); } @@ -84,7 +87,8 @@ async function runCheck() { } console.log(status.output); - process.exit(status.hasErrors ? 1 : 0); + const shouldFail = status.hasErrors || (failOnWarnings && status.hasWarnings); + process.exit(shouldFail ? 1 : 0); } function stopDaemon() { @@ -139,9 +143,10 @@ Commands: status Show daemon status Options: - --workspace Path to workspace (default: current directory) - --tsconfig Path to tsconfig.json - --help Show this help message + --workspace Path to workspace (default: current directory) + --tsconfig Path to tsconfig.json + --fail-on-warnings Exit with error code when there are warnings (check command only) + --help Show this help message `); } diff --git a/package.json b/package.json index 1a99049..731cb21 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@ampcode/svelte-check-daemon", "publisher": "ampcode", "description": "A daemon for svelte-check that caches results for faster type checking", - "version": "0.0.4", + "version": "0.1.0", "packageManager": "pnpm@10.24.0", "license": "Apache-2.0", "type": "module", @@ -32,13 +32,15 @@ ], "scripts": { "build": "tsc", - "prepublishOnly": "pnpm build" + "prepublishOnly": "pnpm build", + "prepare": "pnpm build" }, "peerDependencies": { "svelte-check": ">=4.0.0" }, "devDependencies": { "@types/node": "^20.0.0", - "typescript": "^5.0.0" + "typescript": "^5.0.0", + "pnpm": "^10.0.0" } } diff --git a/src/client.ts b/src/client.ts index 8d4aaf3..e29bd06 100644 --- a/src/client.ts +++ b/src/client.ts @@ -57,12 +57,16 @@ export function isDaemonRunning(workspacePath: string): boolean { export function runSvelteCheckDirectly( workspacePath: string, - tsconfigPath?: string + tsconfigPath?: string, + failOnWarnings?: boolean ): { success: boolean; output: string } { const args = ['--output', 'human']; if (tsconfigPath) { args.push('--tsconfig', tsconfigPath); } + if (failOnWarnings) { + args.push('--fail-on-warnings'); + } const result = spawnSync('svelte-check', args, { cwd: workspacePath,