@@ -45,22 +45,61 @@ const core = __importStar(__nccwpck_require__(7484));
4545const exec = __importStar(__nccwpck_require__(5236));
4646const path = __importStar(__nccwpck_require__(6928));
4747const fs = __importStar(__nccwpck_require__(9896));
48+ function stripAnsi(input) {
49+ return input.replace(/[\u001B\u009B][[()\]#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
50+ }
51+ function parseFindings(output, workingDirectory) {
52+ const clean = stripAnsi(output);
53+ const lines = clean.split(/\r?\n/);
54+ const findings = [];
55+ for (let i = 0; i < lines.length; i++) {
56+ const loc = lines[i].match(/^(.+?):(\d+):(\d+)$/);
57+ if (!loc)
58+ continue;
59+ const [, relFile, lineStr, colStr] = loc;
60+ const next = lines[i + 1] || '';
61+ const sevLine = next.match(/^\s*(Error|Warning|Warn|Hint):\s*(.*?)(?:\s+\([^)]+\))?$/);
62+ if (!sevLine)
63+ continue;
64+ let sev = sevLine[1];
65+ const message = sevLine[2];
66+ if (sev === 'Warn')
67+ sev = 'Warning';
68+ const filePath = path.normalize(path.join(workingDirectory, relFile));
69+ const line = parseInt(lineStr, 10) || 1;
70+ const col = parseInt(colStr, 10) || 1;
71+ findings.push({ severity: sev, message, file: filePath, line, col });
72+ }
73+ return findings;
74+ }
75+ function annotateFromOutput(output, workingDirectory) {
76+ const findings = parseFindings(output, workingDirectory);
77+ for (const f of findings) {
78+ const props = { file: f.file, startLine: f.line, startColumn: f.col, title: 'svelte-check' };
79+ if (f.severity === 'Error')
80+ core.error(f.message, props);
81+ else if (f.severity === 'Warning')
82+ core.warning(f.message, props);
83+ else
84+ core.notice(f.message, props);
85+ }
86+ return findings;
87+ }
4888async function run() {
4989 try {
5090 const workingDirectory = core.getInput('working-directory') || '.';
5191 const failOnWarnings = core.getInput('fail-on-warnings') === 'true';
5292 const failOnHints = core.getInput('fail-on-hints') === 'true';
5393 const tsconfig = core.getInput('tsconfig');
54- const matcherPath = path.join(__dirname, '..', '.github', 'svelte-check-matcher.json');
94+ // When bundled with ncc, the matcher file should be in the same directory as index.js
95+ const matcherPath = path.join(__dirname, 'svelte-check-matcher.json');
5596 core.info(`Adding problem matcher: ${matcherPath}`);
5697 console.log(`::add-matcher::${matcherPath}`);
57- // Detect SvelteKit and run `svelte-kit sync` to ensure .svelte-kit/tsconfig.json exists
5898 let looksLikeSvelteKit = false;
5999 try {
60100 const pkgJsonPath = path.join(workingDirectory, 'package.json');
61101 const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
62- looksLikeSvelteKit = Boolean((pkg.dependencies && pkg.dependencies['@sveltejs/kit']) ||
63- (pkg.devDependencies && pkg.devDependencies['@sveltejs/kit']));
102+ looksLikeSvelteKit = Boolean((pkg.dependencies && pkg.dependencies['@sveltejs/kit']) || (pkg.devDependencies && pkg.devDependencies['@sveltejs/kit']));
64103 }
65104 catch {
66105 // ignore, skip sync
@@ -100,39 +139,39 @@ async function run() {
100139 };
101140 const exitCode = await exec.exec(npx, args, options);
102141 core.info(`svelte-check exit code: ${exitCode}`);
103- const errorCount = (output.match(/Error:/g) || []).length;
104- const warningCount = (output.match(/Warning:/g) || []).length;
105- const hintCount = (output.match(/Hint:/g) || []).length;
142+ const findings = annotateFromOutput(output + '\n' + errorOutput, workingDirectory);
143+ const errorCount = findings.filter((f) => f.severity === 'Error').length;
144+ const warningCount = findings.filter((f) => f.severity === 'Warning').length;
145+ const hintCount = findings.filter((f) => f.severity === 'Hint').length;
106146 core.setOutput('errors', String(errorCount));
107147 core.setOutput('warnings', String(warningCount));
108148 core.setOutput('hints', String(hintCount));
109149 core.info('Svelte Check Results:');
110150 core.info(` Errors: ${errorCount}`);
111151 core.info(` Warnings: ${warningCount}`);
112152 core.info(` Hints: ${hintCount}`);
113- let shouldFail = false;
153+ // Always fail if svelte-check itself failed
154+ if (exitCode !== 0) {
155+ core.error(`svelte-check exited with code ${exitCode}`);
156+ }
157+ let shouldFail = exitCode !== 0;
114158 if (errorCount > 0) {
115159 shouldFail = true;
116- core.error(`Found ${errorCount} errors `);
160+ core.error(`Found ${errorCount} error(s) - failing build `);
117161 }
118162 if (failOnWarnings && warningCount > 0) {
119163 shouldFail = true;
120- core.error(`Found ${warningCount} warnings (fail-on-warnings is enabled)`);
164+ core.error(`Found ${warningCount} warning(s) (fail-on-warnings is enabled)`);
121165 }
122166 if (failOnHints && hintCount > 0) {
123167 shouldFail = true;
124- core.error(`Found ${hintCount} hints (fail-on-hints is enabled)`);
125- }
126- // If svelte-check failed for other reasons, surface stderr
127- if (!shouldFail && exitCode !== 0 && errorOutput.trim()) {
128- shouldFail = true;
129- core.error(errorOutput);
168+ core.error(`Found ${hintCount} hint(s) (fail-on-hints is enabled)`);
130169 }
131170 if (shouldFail) {
132171 core.setFailed('Svelte check found issues');
133172 }
134173 else {
135- core.info('Svelte check completed successfully');
174+ core.info('✅ Svelte check completed successfully');
136175 }
137176 }
138177 catch (error) {
0 commit comments