@coralogix/tsgo-strict 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -1
- package/bin/tsgo-strict +33 -0
- package/index.d.ts +61 -0
- package/index.js +34 -0
- package/install.js +80 -0
- package/lib/resolve.js +80 -0
- package/package.json +48 -4
package/README.md
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
1
|
# @coralogix/tsgo-strict
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Strict-only TypeScript checking powered by the [`tsgo`](https://www.npmjs.com/package/@typescript/native-preview) native compiler, reading `typescript-strict-plugin`-style config so you can adopt `strict: true` gradually.
|
|
4
|
+
|
|
5
|
+
Ships a native Rust CLI plus an N-API addon via platform-specific subpackages; no Node runtime work on the hot path.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install --save-dev @coralogix/tsgo-strict @typescript/native-preview
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The correct native binary and addon for your platform are installed automatically through `optionalDependencies`.
|
|
14
|
+
|
|
15
|
+
## CLI usage
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
tsgo-strict --project tsconfig.json
|
|
19
|
+
tsgo-strict src/feature # run strict check only against this subtree
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Programmatic API
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { run } from '@coralogix/tsgo-strict';
|
|
26
|
+
|
|
27
|
+
const result = await run({
|
|
28
|
+
project: 'tsconfig.json',
|
|
29
|
+
subset: ['src/feature'],
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log(result.errorCount, result.diagnostics);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Full TypeScript types are shipped with the package.
|
|
36
|
+
|
|
37
|
+
## Supported platforms
|
|
38
|
+
|
|
39
|
+
- linux-x64 (gnu, musl)
|
|
40
|
+
- linux-arm64 (gnu)
|
|
41
|
+
- darwin-x64, darwin-arm64
|
|
42
|
+
- win32-x64 (msvc)
|
package/bin/tsgo-strict
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// JS launcher shim. Follows the esbuild pattern: on *nix, `install.js` may
|
|
5
|
+
// hard-link the platform-specific native binary over this file during
|
|
6
|
+
// postinstall, turning this path into the native executable (one less
|
|
7
|
+
// Node startup per invocation). On Windows, yarn, or when postinstall is
|
|
8
|
+
// skipped, this shim stays in place and spawns the binary each time.
|
|
9
|
+
|
|
10
|
+
const fs = require('node:fs');
|
|
11
|
+
const { spawnSync } = require('node:child_process');
|
|
12
|
+
const { resolveBinary } = require('../lib/resolve');
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const binary = resolveBinary();
|
|
16
|
+
// GitHub Actions' upload-artifact strips the executable bit, so the
|
|
17
|
+
// published platform tarball can ship the binary at 0644. Ensure it's
|
|
18
|
+
// runnable before we spawn it. Best-effort: swallow chmod errors so we
|
|
19
|
+
// don't mask the real spawn error.
|
|
20
|
+
try {
|
|
21
|
+
const st = fs.statSync(binary);
|
|
22
|
+
if ((st.mode & 0o111) === 0) fs.chmodSync(binary, 0o755);
|
|
23
|
+
} catch {}
|
|
24
|
+
const result = spawnSync(binary, process.argv.slice(2), { stdio: 'inherit' });
|
|
25
|
+
if (result.error) {
|
|
26
|
+
process.stderr.write(`tsgo-strict: failed to launch native binary: ${result.error.message}\n`);
|
|
27
|
+
process.exit(2);
|
|
28
|
+
}
|
|
29
|
+
process.exit(result.status == null ? 2 : result.status);
|
|
30
|
+
} catch (err) {
|
|
31
|
+
process.stderr.write(`${err.message}\n`);
|
|
32
|
+
process.exit(2);
|
|
33
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Coralogix Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// Type definitions for `@coralogix/tsgo-strict`.
|
|
18
|
+
//
|
|
19
|
+
// The runtime surface is implemented in `index.js` and backed by a native
|
|
20
|
+
// N-API addon shipped in `@coralogix/tsgo-strict-<triple>` platform subpackages.
|
|
21
|
+
|
|
22
|
+
export type Category = 'error' | 'warning' | 'message';
|
|
23
|
+
|
|
24
|
+
export interface RunOptions {
|
|
25
|
+
/** Path to the project tsconfig, absolute or relative to `cwd`. Defaults to `tsconfig.json`. */
|
|
26
|
+
project?: string;
|
|
27
|
+
/** Working directory for binary and tsconfig resolution. Defaults to `process.cwd()`. */
|
|
28
|
+
cwd?: string;
|
|
29
|
+
/** Restrict the check to these files or directories. Empty / omitted means the full project. */
|
|
30
|
+
subset?: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface RunDiagnostic {
|
|
34
|
+
/** Project-relative path, or `undefined` for global diagnostics. */
|
|
35
|
+
file?: string;
|
|
36
|
+
/** 1-based line number. */
|
|
37
|
+
line?: number;
|
|
38
|
+
/** 1-based column number. */
|
|
39
|
+
column?: number;
|
|
40
|
+
/** TypeScript diagnostic code (e.g. `2345`). */
|
|
41
|
+
code: number;
|
|
42
|
+
category: Category;
|
|
43
|
+
message: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface RunTiming {
|
|
47
|
+
label: string;
|
|
48
|
+
durationMs: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface RunResult {
|
|
52
|
+
/** Total diagnostic count. */
|
|
53
|
+
errorCount: number;
|
|
54
|
+
/** `0` clean, `1` strict errors, `2` internal failure. */
|
|
55
|
+
exitCode: number;
|
|
56
|
+
diagnostics: RunDiagnostic[];
|
|
57
|
+
timings: RunTiming[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Run the strict checker programmatically. Resolves with structured diagnostics and per-phase timings. */
|
|
61
|
+
export function run(options?: RunOptions): Promise<RunResult>;
|
package/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Coralogix Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
'use strict';
|
|
18
|
+
|
|
19
|
+
const { resolveNativeAddon } = require('./lib/resolve');
|
|
20
|
+
|
|
21
|
+
let cachedAddon = null;
|
|
22
|
+
function loadAddon() {
|
|
23
|
+
if (cachedAddon) return cachedAddon;
|
|
24
|
+
const addonPath = resolveNativeAddon();
|
|
25
|
+
cachedAddon = require(addonPath);
|
|
26
|
+
return cachedAddon;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function run(options = {}) {
|
|
30
|
+
const addon = loadAddon();
|
|
31
|
+
return addon.run(options);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = { run };
|
package/install.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026 Coralogix Ltd.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
// Postinstall optimizer (esbuild-style). The JS shim at `bin/tsgo-strict`
|
|
21
|
+
// always works, but spawning a separate Node process per invocation adds
|
|
22
|
+
// ~30-50ms of startup. On *nix, we hard-link the platform-specific native
|
|
23
|
+
// binary directly over the shim so `node_modules/.bin/tsgo-strict` (which
|
|
24
|
+
// symlinks to this file) resolves to the native ELF/Mach-O directly.
|
|
25
|
+
//
|
|
26
|
+
// This is a pure optimization — if it fails for any reason, the JS shim
|
|
27
|
+
// is preserved and everything still works. On Windows, yarn, or when
|
|
28
|
+
// installed with `--ignore-scripts`, the shim stays in place.
|
|
29
|
+
|
|
30
|
+
const fs = require('node:fs');
|
|
31
|
+
const path = require('node:path');
|
|
32
|
+
|
|
33
|
+
function isYarn() {
|
|
34
|
+
const ua = process.env.npm_config_user_agent;
|
|
35
|
+
return !!ua && /\byarn\//.test(ua);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function main() {
|
|
39
|
+
// Windows: keep the JS shim. npm on Windows generates `.cmd`/`.ps1`
|
|
40
|
+
// wrappers next to the shim — replacing it with a PE executable would
|
|
41
|
+
// break those wrappers.
|
|
42
|
+
if (process.platform === 'win32') return;
|
|
43
|
+
if (isYarn()) return;
|
|
44
|
+
|
|
45
|
+
let resolveBinary;
|
|
46
|
+
try {
|
|
47
|
+
({ resolveBinary } = require('./lib/resolve'));
|
|
48
|
+
} catch {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let binary;
|
|
53
|
+
try {
|
|
54
|
+
binary = resolveBinary();
|
|
55
|
+
} catch {
|
|
56
|
+
// Platform not supported, or the optional dep didn't install. The
|
|
57
|
+
// shim will surface a helpful error the first time it runs.
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!fs.existsSync(binary)) return;
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const st = fs.statSync(binary);
|
|
65
|
+
if ((st.mode & 0o111) === 0) fs.chmodSync(binary, 0o755);
|
|
66
|
+
} catch {}
|
|
67
|
+
|
|
68
|
+
const shim = path.join(__dirname, 'bin', 'tsgo-strict');
|
|
69
|
+
const tmp = path.join(__dirname, 'bin', 'tsgo-strict.tmp');
|
|
70
|
+
try {
|
|
71
|
+
try { fs.unlinkSync(tmp); } catch {}
|
|
72
|
+
fs.linkSync(binary, tmp);
|
|
73
|
+
fs.renameSync(tmp, shim);
|
|
74
|
+
} catch {
|
|
75
|
+
// Cross-device link, read-only fs, whatever — shim stays put.
|
|
76
|
+
try { fs.unlinkSync(tmp); } catch {}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
main();
|
package/lib/resolve.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Coralogix Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
'use strict';
|
|
18
|
+
|
|
19
|
+
// Internal platform-binary + N-API addon resolver. Not part of the public
|
|
20
|
+
// package surface; the bin launcher and `index.js` import from here
|
|
21
|
+
// directly.
|
|
22
|
+
|
|
23
|
+
const path = require('node:path');
|
|
24
|
+
const { familySync, MUSL } = require('detect-libc');
|
|
25
|
+
|
|
26
|
+
function pickPackage() {
|
|
27
|
+
const platform = process.platform;
|
|
28
|
+
const arch = process.arch;
|
|
29
|
+
const family = platform === 'linux' ? familySync() : null;
|
|
30
|
+
|
|
31
|
+
if (platform === 'linux' && arch === 'x64') {
|
|
32
|
+
return family === MUSL
|
|
33
|
+
? '@coralogix/tsgo-strict-linux-x64-musl'
|
|
34
|
+
: '@coralogix/tsgo-strict-linux-x64-gnu';
|
|
35
|
+
}
|
|
36
|
+
if (platform === 'linux' && arch === 'arm64') {
|
|
37
|
+
if (family === MUSL) return null;
|
|
38
|
+
return '@coralogix/tsgo-strict-linux-arm64-gnu';
|
|
39
|
+
}
|
|
40
|
+
if (platform === 'darwin' && arch === 'arm64') return '@coralogix/tsgo-strict-darwin-arm64';
|
|
41
|
+
if (platform === 'win32' && arch === 'x64') return '@coralogix/tsgo-strict-win32-x64-msvc';
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function platformPackageJson() {
|
|
46
|
+
const name = pickPackage();
|
|
47
|
+
if (!name) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`tsgo-strict: unsupported platform ${process.platform}-${process.arch} (libc family: ${familySync() || 'n/a'})`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
let packagePath;
|
|
53
|
+
try {
|
|
54
|
+
packagePath = require.resolve(`${name}/package.json`);
|
|
55
|
+
} catch {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`tsgo-strict: expected platform package '${name}' is not installed. ` +
|
|
58
|
+
`This usually means 'optionalDependencies' was not installed (check npm/pnpm/yarn install logs).`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return { name, packagePath, pkg: require(packagePath) };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function resolveBinary() {
|
|
65
|
+
// Platform packages don't declare `bin` (that would collide with this
|
|
66
|
+
// launcher's own `bin` entry on hoist). Hard-code the staged path —
|
|
67
|
+
// it matches what the release workflow writes into
|
|
68
|
+
// `npm/platforms/<triple>/bin/`.
|
|
69
|
+
const { packagePath } = platformPackageJson();
|
|
70
|
+
const relative = process.platform === 'win32' ? 'bin/tsgo-strict.exe' : 'bin/tsgo-strict';
|
|
71
|
+
return path.resolve(path.dirname(packagePath), relative);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function resolveNativeAddon() {
|
|
75
|
+
const { pkg, packagePath } = platformPackageJson();
|
|
76
|
+
const relative = pkg.main || 'native/tsgo-strict.node';
|
|
77
|
+
return path.resolve(path.dirname(packagePath), relative);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
module.exports = { pickPackage, resolveBinary, resolveNativeAddon };
|
package/package.json
CHANGED
|
@@ -1,14 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coralogix/tsgo-strict",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "High-performance strict-only TypeScript checking with tsgo and subset file support",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"typescript",
|
|
7
|
+
"tsgo",
|
|
8
|
+
"typecheck",
|
|
9
|
+
"strict",
|
|
10
|
+
"cli"
|
|
11
|
+
],
|
|
5
12
|
"license": "Apache-2.0",
|
|
6
13
|
"repository": {
|
|
7
14
|
"type": "git",
|
|
8
15
|
"url": "git+https://github.com/coralogix/tsgo-strict.git"
|
|
9
16
|
},
|
|
10
17
|
"publishConfig": {
|
|
11
|
-
"access": "public"
|
|
12
|
-
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"main": "index.js",
|
|
21
|
+
"types": "index.d.ts",
|
|
22
|
+
"bin": {
|
|
23
|
+
"tsgo-strict": "bin/tsgo-strict"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"postinstall": "node install.js"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"lib",
|
|
30
|
+
"bin",
|
|
31
|
+
"install.js",
|
|
32
|
+
"index.js",
|
|
33
|
+
"index.d.ts",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE"
|
|
36
|
+
],
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18"
|
|
39
|
+
},
|
|
40
|
+
"optionalDependencies": {
|
|
41
|
+
"@coralogix/tsgo-strict-linux-x64-gnu": "0.1.0",
|
|
42
|
+
"@coralogix/tsgo-strict-linux-x64-musl": "0.1.0",
|
|
43
|
+
"@coralogix/tsgo-strict-linux-arm64-gnu": "0.1.0",
|
|
44
|
+
"@coralogix/tsgo-strict-darwin-arm64": "0.1.0",
|
|
45
|
+
"@coralogix/tsgo-strict-win32-x64-msvc": "0.1.0"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"detect-libc": "^2.0.3"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@typescript/native-preview": ">=7.0.0-dev"
|
|
52
|
+
},
|
|
53
|
+
"peerDependenciesMeta": {
|
|
54
|
+
"@typescript/native-preview": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
13
57
|
}
|
|
14
58
|
}
|