@tyndall/lint 0.0.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/README.md +28 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/package.json +25 -0
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @tyndall/lint
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
Lint and format execution package for Hyper tooling and scaffolding workflows.
|
|
5
|
+
|
|
6
|
+
## Responsibilities
|
|
7
|
+
- Provide `runLint` / `runFormat` programmatic APIs for Hyper CLI and scaffolding.
|
|
8
|
+
- Build deterministic Biome command invocations from typed options.
|
|
9
|
+
- Provide a resilient runtime path by falling back from `biome` to `bunx @biomejs/biome` when needed.
|
|
10
|
+
|
|
11
|
+
## Public API Highlights
|
|
12
|
+
- runLint
|
|
13
|
+
- runFormat
|
|
14
|
+
- `commandArgs` support for custom command prefixes (for example, `bunx --bun @biomejs/biome`).
|
|
15
|
+
|
|
16
|
+
## Development
|
|
17
|
+
- Build: bun run --filter @tyndall/lint build
|
|
18
|
+
- Test (from workspace root): bun test
|
|
19
|
+
|
|
20
|
+
## Documentation
|
|
21
|
+
- Package specification: [spec.md](./spec.md)
|
|
22
|
+
- Package architecture: [architecture.md](./architecture.md)
|
|
23
|
+
- Package changes: [CHANGELOG.md](./CHANGELOG.md)
|
|
24
|
+
|
|
25
|
+
## Maintenance Rules
|
|
26
|
+
- Keep this document aligned with implemented package behavior.
|
|
27
|
+
- Update spec.md and architecture.md whenever package contracts or design boundaries change.
|
|
28
|
+
- Record user-visible package changes in CHANGELOG.md.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface LintOptions {
|
|
2
|
+
cwd: string;
|
|
3
|
+
fix?: boolean;
|
|
4
|
+
files?: string[];
|
|
5
|
+
command?: string;
|
|
6
|
+
commandArgs?: string[];
|
|
7
|
+
exec?: ExecFn;
|
|
8
|
+
}
|
|
9
|
+
export interface FormatOptions {
|
|
10
|
+
cwd: string;
|
|
11
|
+
write?: boolean;
|
|
12
|
+
files?: string[];
|
|
13
|
+
command?: string;
|
|
14
|
+
commandArgs?: string[];
|
|
15
|
+
exec?: ExecFn;
|
|
16
|
+
}
|
|
17
|
+
export interface ExecPayload {
|
|
18
|
+
command: string;
|
|
19
|
+
args: string[];
|
|
20
|
+
cwd: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ExecResult {
|
|
23
|
+
code: number;
|
|
24
|
+
error?: Error;
|
|
25
|
+
}
|
|
26
|
+
export type ExecFn = (payload: ExecPayload) => Promise<ExecResult>;
|
|
27
|
+
export interface LintResult extends ExecResult {
|
|
28
|
+
command: string;
|
|
29
|
+
args: string[];
|
|
30
|
+
cwd: string;
|
|
31
|
+
}
|
|
32
|
+
export declare const runLint: (options: LintOptions) => Promise<LintResult>;
|
|
33
|
+
export declare const runFormat: (options: FormatOptions) => Promise<LintResult>;
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;AAEnE,MAAM,WAAW,UAAW,SAAQ,UAAU;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AA4DD,eAAO,MAAM,OAAO,GAAU,SAAS,WAAW,KAAG,OAAO,CAAC,UAAU,CAC5C,CAAC;AAE5B,eAAO,MAAM,SAAS,GAAU,SAAS,aAAa,KAAG,OAAO,CAAC,UAAU,CAC9C,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
const BUNX_BIOME_FALLBACK = {
|
|
3
|
+
command: "bunx",
|
|
4
|
+
commandArgs: ["--bun", "@biomejs/biome"],
|
|
5
|
+
};
|
|
6
|
+
const buildArgs = (mode, options) => {
|
|
7
|
+
const args = [...(options.commandArgs ?? []), mode];
|
|
8
|
+
if (mode === "lint" && options.fix) {
|
|
9
|
+
args.push("--fix");
|
|
10
|
+
}
|
|
11
|
+
if (mode === "format" && options.write) {
|
|
12
|
+
args.push("--write");
|
|
13
|
+
}
|
|
14
|
+
// Default to the current working directory when no files are specified.
|
|
15
|
+
const files = options.files && options.files.length > 0 ? options.files : ["."];
|
|
16
|
+
args.push(...files);
|
|
17
|
+
return args;
|
|
18
|
+
};
|
|
19
|
+
const defaultExec = async ({ command, args, cwd }) => new Promise((resolve) => {
|
|
20
|
+
const child = spawn(command, args, { cwd, stdio: "inherit" });
|
|
21
|
+
child.once("error", (error) => {
|
|
22
|
+
const code = error.code === "ENOENT" ? 127 : 1;
|
|
23
|
+
resolve({ code, error });
|
|
24
|
+
});
|
|
25
|
+
child.once("exit", (code) => resolve({ code: code ?? 0 }));
|
|
26
|
+
});
|
|
27
|
+
const runBiome = async (mode, options) => {
|
|
28
|
+
const exec = options.exec ?? defaultExec;
|
|
29
|
+
const canFallbackToBunx = options.command === undefined && options.commandArgs === undefined;
|
|
30
|
+
let command = options.command ?? "biome";
|
|
31
|
+
let args = buildArgs(mode, options);
|
|
32
|
+
let result = await exec({ command, args, cwd: options.cwd });
|
|
33
|
+
if (result.code === 127 && canFallbackToBunx) {
|
|
34
|
+
command = BUNX_BIOME_FALLBACK.command;
|
|
35
|
+
args = buildArgs(mode, { ...options, commandArgs: BUNX_BIOME_FALLBACK.commandArgs });
|
|
36
|
+
result = await exec({ command, args, cwd: options.cwd });
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
command,
|
|
40
|
+
args,
|
|
41
|
+
cwd: options.cwd,
|
|
42
|
+
code: result.code,
|
|
43
|
+
error: result.error,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export const runLint = async (options) => runBiome("lint", options);
|
|
47
|
+
export const runFormat = async (options) => runBiome("format", options);
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tyndall/lint",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"bun": "./src/index.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -p tsconfig.json",
|
|
22
|
+
"lint": "bunx --bun @biomejs/biome lint .",
|
|
23
|
+
"format": "bunx --bun @biomejs/biome format --write ."
|
|
24
|
+
}
|
|
25
|
+
}
|