@tyndall/oxc 0.0.2

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 ADDED
@@ -0,0 +1,28 @@
1
+ # @tyndall/oxc
2
+
3
+ ## Overview
4
+ Shared OXC lint/format execution utilities for Hyper tooling.
5
+
6
+ ## Responsibilities
7
+ - Provide `runLint` / `runFormat` programmatic APIs that invoke `oxlint` and `oxfmt`.
8
+ - Translate typed options into deterministic CLI arguments.
9
+ - Fall back to `bunx --bun oxlint` / `bunx --bun oxfmt` when binaries are missing.
10
+
11
+ ## Public API Highlights
12
+ - runLint
13
+ - runFormat
14
+ - `commandArgs` support for custom command prefixes (for example, `bunx --bun oxlint`).
15
+
16
+ ## Development
17
+ - Build: bun run --filter @tyndall/oxc 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.
@@ -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;AA0FD,eAAO,MAAM,OAAO,GAAU,SAAS,WAAW,KAAG,OAAO,CAAC,UAAU,CAAwB,CAAC;AAEhG,eAAO,MAAM,SAAS,GAAU,SAAS,aAAa,KAAG,OAAO,CAAC,UAAU,CAA0B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,75 @@
1
+ import { spawn } from "node:child_process";
2
+ const BUNX_OXLINT_FALLBACK = {
3
+ command: "bunx",
4
+ commandArgs: ["--bun", "oxlint"],
5
+ };
6
+ const BUNX_OXFMT_FALLBACK = {
7
+ command: "bunx",
8
+ commandArgs: ["--bun", "oxfmt"],
9
+ };
10
+ const buildLintArgs = (options) => {
11
+ const args = [...(options.commandArgs ?? [])];
12
+ if (options.fix) {
13
+ args.push("--fix");
14
+ }
15
+ const files = options.files && options.files.length > 0 ? options.files : ["."];
16
+ args.push(...files);
17
+ return args;
18
+ };
19
+ const buildFormatArgs = (options) => {
20
+ const args = [...(options.commandArgs ?? [])];
21
+ if (!options.write) {
22
+ args.push("--check");
23
+ }
24
+ const files = options.files && options.files.length > 0 ? options.files : ["."];
25
+ args.push(...files);
26
+ return args;
27
+ };
28
+ const defaultExec = async ({ command, args, cwd }) => new Promise((resolve) => {
29
+ const child = spawn(command, args, { cwd, stdio: "inherit" });
30
+ child.once("error", (error) => {
31
+ const code = error.code === "ENOENT" ? 127 : 1;
32
+ resolve({ code, error });
33
+ });
34
+ child.once("exit", (code) => resolve({ code: code ?? 0 }));
35
+ });
36
+ const runOxcLint = async (options) => {
37
+ const exec = options.exec ?? defaultExec;
38
+ const canFallbackToBunx = options.command === undefined && options.commandArgs === undefined;
39
+ let command = options.command ?? "oxlint";
40
+ let args = buildLintArgs(options);
41
+ let result = await exec({ command, args, cwd: options.cwd });
42
+ if (result.code === 127 && canFallbackToBunx) {
43
+ command = BUNX_OXLINT_FALLBACK.command;
44
+ args = buildLintArgs({ ...options, commandArgs: BUNX_OXLINT_FALLBACK.commandArgs });
45
+ result = await exec({ command, args, cwd: options.cwd });
46
+ }
47
+ return {
48
+ command,
49
+ args,
50
+ cwd: options.cwd,
51
+ code: result.code,
52
+ error: result.error,
53
+ };
54
+ };
55
+ const runOxcFormat = async (options) => {
56
+ const exec = options.exec ?? defaultExec;
57
+ const canFallbackToBunx = options.command === undefined && options.commandArgs === undefined;
58
+ let command = options.command ?? "oxfmt";
59
+ let args = buildFormatArgs(options);
60
+ let result = await exec({ command, args, cwd: options.cwd });
61
+ if (result.code === 127 && canFallbackToBunx) {
62
+ command = BUNX_OXFMT_FALLBACK.command;
63
+ args = buildFormatArgs({ ...options, commandArgs: BUNX_OXFMT_FALLBACK.commandArgs });
64
+ result = await exec({ command, args, cwd: options.cwd });
65
+ }
66
+ return {
67
+ command,
68
+ args,
69
+ cwd: options.cwd,
70
+ code: result.code,
71
+ error: result.error,
72
+ };
73
+ };
74
+ export const runLint = async (options) => runOxcLint(options);
75
+ export const runFormat = async (options) => runOxcFormat(options);
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@tyndall/oxc",
3
+ "version": "0.0.2",
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": "oxlint .",
23
+ "format": "oxfmt ."
24
+ },
25
+ "dependencies": {
26
+ "oxfmt": "^0.35.0",
27
+ "oxlint": "^1.50.0"
28
+ }
29
+ }