@evobug_com/safe-ts-skill 0.0.0-stage → 0.5.1
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/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +15 -2
- package/install.mjs +86 -0
- package/package.json +35 -4
- package/safe-ts-migrate/SKILL.md +178 -0
- package/safe-ts-migrate/references/architecture.md +146 -0
- package/safe-ts-migrate/references/behaviour.md +86 -0
- package/safe-ts-migrate/references/census.md +136 -0
- package/safe-ts-migrate/references/escape-hatches.md +72 -0
- package/safe-ts-migrate/references/final-pass.md +46 -0
- package/safe-ts-migrate/references/fix-the-design.md +87 -0
- package/safe-ts-migrate/references/order-and-gates.md +101 -0
- package/safe-ts-migrate/references/patterns-core.md +2229 -0
- package/safe-ts-migrate/references/patterns-react.md +266 -0
- package/safe-ts-migrate/references/patterns-vue.md +713 -0
- package/safe-ts-migrate/references/review-checklist.md +70 -0
- package/safe-ts-migrate/references/templates.md +260 -0
- package/safe-ts-migrate/references/tool-gaps.md +394 -0
- package/safe-ts-migrate/scripts/census.mjs +870 -0
- package/safe-ts-migrate/scripts/safe-ts.mjs +79 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Finds and runs the `safe-ts` binary that came with the project's packages. The census uses it
|
|
3
|
+
// to run `safe-ts check`; it also works on its own:
|
|
4
|
+
//
|
|
5
|
+
// node safe-ts.mjs check src/main.ts
|
|
6
|
+
//
|
|
7
|
+
// In package.json scripts and CI, call the `safe-ts` command itself: @evobug_com/safe-ts-native
|
|
8
|
+
// declares it as a bin, and comes with the transform and the oxlint plugin (with pnpm, add
|
|
9
|
+
// @evobug_com/safe-ts-native as a dev dependency to get the command). This file looks for the
|
|
10
|
+
// binary in the native addon's platform package
|
|
11
|
+
// (`node_modules/@evobug_com/safe-ts-native-<platform>/bin/safe-ts`), the way the VS Code
|
|
12
|
+
// extension does, so it needs no bin link. `SAFE_TS_BIN=<path>` (or the launcher's
|
|
13
|
+
// `SAFE_TS_CLI_PATH`) overrides the search.
|
|
14
|
+
import { spawnSync } from "node:child_process";
|
|
15
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
16
|
+
import { delimiter, dirname, join, resolve } from "node:path";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
|
|
19
|
+
const BINARY = process.platform === "win32" ? "safe-ts.exe" : "safe-ts";
|
|
20
|
+
|
|
21
|
+
/** The platform package's suffix (`linux-x64-gnu`, `darwin-arm64`, `win32-x64-msvc`). */
|
|
22
|
+
function platformId() {
|
|
23
|
+
let libc;
|
|
24
|
+
if (process.platform === "linux") {
|
|
25
|
+
try {
|
|
26
|
+
libc = readFileSync("/usr/bin/ldd", "utf8").includes("musl") ? "musl" : "gnu";
|
|
27
|
+
} catch {
|
|
28
|
+
libc = "gnu";
|
|
29
|
+
}
|
|
30
|
+
} else if (process.platform === "win32") {
|
|
31
|
+
libc = "msvc";
|
|
32
|
+
}
|
|
33
|
+
return [process.platform, process.arch, libc].filter(Boolean).join("-");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The path of the `safe-ts` binary: `SAFE_TS_BIN`, else the first one found in a
|
|
38
|
+
* `node_modules/@evobug_com/` of `from` or a parent (a repository build in `safe-ts-native/bin/`,
|
|
39
|
+
* the platform package, pnpm's `.pnpm/node_modules/`), else one on PATH. `undefined` if none.
|
|
40
|
+
* @param {string} [from]
|
|
41
|
+
* @returns {string | undefined}
|
|
42
|
+
*/
|
|
43
|
+
export function findSafeTs(from = process.cwd()) {
|
|
44
|
+
const given = process.env.SAFE_TS_BIN || process.env.SAFE_TS_CLI_PATH;
|
|
45
|
+
if (given) return given;
|
|
46
|
+
const packages = ["safe-ts-native", `safe-ts-native-${platformId()}`];
|
|
47
|
+
for (let dir = resolve(from); ; ) {
|
|
48
|
+
for (const modules of [join(dir, "node_modules"), join(dir, "node_modules", ".pnpm", "node_modules")]) {
|
|
49
|
+
for (const name of packages) {
|
|
50
|
+
const candidate = join(modules, "@evobug_com", name, "bin", BINARY);
|
|
51
|
+
if (existsSync(candidate)) return candidate;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const parent = dirname(dir);
|
|
55
|
+
if (parent === dir) break;
|
|
56
|
+
dir = parent;
|
|
57
|
+
}
|
|
58
|
+
for (const entry of (process.env.PATH ?? "").split(delimiter)) {
|
|
59
|
+
if (entry !== "" && existsSync(join(entry, BINARY))) return join(entry, BINARY);
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (process.argv[1] !== undefined && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
65
|
+
const binary = findSafeTs();
|
|
66
|
+
if (binary === undefined) {
|
|
67
|
+
console.error(
|
|
68
|
+
"safe-ts.mjs: no safe-ts binary found. Install @evobug_com/safe-ts-transform (it brings " +
|
|
69
|
+
"@evobug_com/safe-ts-native and its platform package), or set SAFE_TS_BIN.",
|
|
70
|
+
);
|
|
71
|
+
process.exit(2);
|
|
72
|
+
}
|
|
73
|
+
const run = spawnSync(binary, process.argv.slice(2), { stdio: "inherit" });
|
|
74
|
+
if (run.error) {
|
|
75
|
+
console.error(`safe-ts.mjs: could not run ${binary}: ${run.error.message}`);
|
|
76
|
+
process.exit(2);
|
|
77
|
+
}
|
|
78
|
+
process.exit(run.status ?? 1);
|
|
79
|
+
}
|