Skip to content

Commit 672c8fb

Browse files
committed
chore: align action to node20, ignore lib, update workflows, rebuild dist
1 parent 2a986bc commit 672c8fb

File tree

12 files changed

+102
-262
lines changed

12 files changed

+102
-262
lines changed

.github/svelte-check-matcher.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"column": 3
1111
},
1212
{
13-
"regexp": "^\\s*(Error|Warning|Warn):\\s*(.*?)(?:\\s+\\((?:ts|js|svelte|css)\\))?$",
13+
"regexp": "^\\s*(Error|Warning|Warn|Hint):\\s*(.+?)(?:\\s+\\([^)]+\\))?$",
1414
"severity": 1,
1515
"message": 2,
1616
"loop": false

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup Node.js
1616
uses: actions/setup-node@v4
1717
with:
18-
node-version: '24'
18+
node-version: '20'
1919
cache: 'npm'
2020

2121
- name: Install dependencies

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Setup Node.js
1515
uses: actions/setup-node@v4
1616
with:
17-
node-version: '22'
17+
node-version: '20'
1818
cache: 'npm'
1919

2020
- name: Install dependencies
@@ -74,4 +74,4 @@ jobs:
7474
echo "❌ Expected action to fail on warnings"
7575
exit 1
7676
fi
77-
echo "✅ Action correctly failed when fail-on-warnings enabled"
77+
echo "✅ Action correctly failed when fail-on-warnings enabled"

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ node_modules/
55
.vscode/
66

77
# Don't ignore dist/ - GitHub Actions need the compiled code
8-
# dist/
8+
# dist/
9+
10+
# Ignore build intermediates and coverage
11+
lib/
12+
coverage/

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ outputs:
3232
description: 'Number of hints found'
3333

3434
runs:
35-
using: 'node24'
35+
using: 'node20'
3636
main: 'dist/index.js'

dist/index.js

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,61 @@ const core = __importStar(__nccwpck_require__(7484));
4545
const exec = __importStar(__nccwpck_require__(5236));
4646
const path = __importStar(__nccwpck_require__(6928));
4747
const 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+
}
4888
async 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) {

dist/svelte-check-matcher.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "svelte-check",
5+
"pattern": [
6+
{
7+
"regexp": "^([^\\s].*):(\\d+):(\\d+)$",
8+
"file": 1,
9+
"line": 2,
10+
"column": 3
11+
},
12+
{
13+
"regexp": "^\\s*(Error|Warning|Warn|Hint):\\s*(.+?)(?:\\s+\\([^)]+\\))?$",
14+
"severity": 1,
15+
"message": 2,
16+
"loop": false
17+
}
18+
]
19+
}
20+
]
21+
}

lib/__tests__/index.test.js

Lines changed: 0 additions & 78 deletions
This file was deleted.

lib/__tests__/setup.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)