Skip to content

Commit 5cfca4d

Browse files
committed
custom script
1 parent 7daaaa4 commit 5cfca4d

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

.github/workflows/validate.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
- name: Check format
5656
run: npm run check-format
5757

58-
check-types-this-is-only-warning-fixing-is-not-required:
58+
type-warnings:
5959
runs-on: ubuntu-latest
6060
steps:
6161
- name: Checkout
@@ -69,6 +69,6 @@ jobs:
6969
cache: npm
7070
- name: Install dependencies
7171
run: npm ci
72-
- name: Check types (This is only warning, fixing is not required)
72+
- name: Check types
7373
continue-on-error: true
7474
run: npm run check-types
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import pathUtil from 'node:path';
2+
import ts from 'typescript';
3+
4+
/**
5+
* @fileoverview
6+
* tsc command output will be parsed by GitHub Actions as errors.
7+
* We want them to be just warnings.
8+
*/
9+
10+
const check = () => {
11+
const rootDir = pathUtil.join(import.meta.dirname, '..');
12+
13+
const tsconfigPath = pathUtil.join(rootDir, 'tsconfig.json');
14+
const commandLine = ts.getParsedCommandLineOfConfigFile(tsconfigPath, {}, ts.sys);
15+
16+
const program = ts.createProgram({
17+
rootNames: commandLine.fileNames,
18+
options: commandLine.options
19+
});
20+
const emitted = program.emit();
21+
22+
const diagnostics = [
23+
...ts.getPreEmitDiagnostics(program),
24+
...emitted.diagnostics
25+
];
26+
27+
for (const diagnostic of diagnostics) {
28+
// https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-commands
29+
let output = '';
30+
const relativeFileName = pathUtil.relative(rootDir, diagnostic.file.fileName);
31+
output += `::warning file=${relativeFileName}`;
32+
33+
const startPosition = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
34+
output += `,line=${startPosition.line + 1},col=${startPosition.character + 1}`;
35+
36+
const endPosition = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
37+
output += `,endLine=${endPosition.line + 1},endCol=${endPosition.character + 1}`;
38+
39+
output += ",title=Type warning - may indicate a bug. No action required if no bug.";
40+
output += `::${diagnostic.messageText}`;
41+
42+
console.log(output);
43+
}
44+
45+
console.log(`${diagnostics.length} warnings.`);
46+
};
47+
48+
check();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"check-format": "prettier . --check",
1717
"upload-translations": "node development/upload-translations.js",
1818
"download-translations": "node development/download-translations.js",
19-
"check-types": "tsc"
19+
"check-types": "node development/check-extension-types.js"
2020
},
2121
"repository": {
2222
"type": "git",

0 commit comments

Comments
 (0)