Skip to content
Open
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
19 changes: 12 additions & 7 deletions bin/svelte-check-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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() {
Expand All @@ -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)) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -139,9 +143,10 @@ Commands:
status Show daemon status

Options:
--workspace <path> Path to workspace (default: current directory)
--tsconfig <path> Path to tsconfig.json
--help Show this help message
--workspace <path> Path to workspace (default: current directory)
--tsconfig <path> Path to tsconfig.json
--fail-on-warnings Exit with error code when there are warnings (check command only)
--help Show this help message
`);
}

Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
6 changes: 5 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down