@boperators/cli 0.1.4 → 0.2.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 CHANGED
@@ -65,6 +65,17 @@ Exit code is 1 on violations (suitable for CI / prepublish scripts). Use `--warn
65
65
  | `--project <path>` | `tsconfig.json` | Path to tsconfig.json to use |
66
66
  | `--warn` | `false` | Emit warnings instead of exiting with an error on violations |
67
67
 
68
+ ## Comparison with Other Approaches
69
+
70
+ | Approach | When it runs | Use case |
71
+ |----------|-------------|----------|
72
+ | **`@boperators/cli`** | Before compilation | Batch transform to disk, then compile normally |
73
+ | **`@boperators/plugin-tsc`** | During compilation | Seamless `tsc` integration, no intermediate files |
74
+ | **`@boperators/webpack-loader`** | During bundling | Webpack projects, integrates into existing build pipeline |
75
+ | **`@boperators/plugin-vite`** | During bundling | Vite projects, integrates into Rollup-based pipeline |
76
+ | **`@boperators/plugin-esbuild`** | During bundling | ESBuild projects, fast bundler integration |
77
+ | **`@boperators/plugin-bun`** | At runtime | Bun-only, transforms on module load |
78
+
68
79
  ## License
69
80
 
70
81
  MIT
package/dist/index.js CHANGED
@@ -4,40 +4,11 @@ import path from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { Command } from "@commander-js/extra-typings";
6
6
  import { ErrorManager, loadConfig, OverloadInjector, OverloadStore, Project as TsMorphProject, validateExports, } from "boperators";
7
+ import { computeCommonSourceDirectory, resolveTsConfig } from "./utils.js";
7
8
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
9
  const packageJsonPath = path.join(__dirname, "..", "package.json");
9
10
  const packageJson = fs.readFileSync(packageJsonPath, "utf-8");
10
11
  const { version } = JSON.parse(packageJson);
11
- /** Resolve tsconfig path relative to cwd if not absolute. */
12
- function resolveTsConfig(project) {
13
- const p = path.isAbsolute(project)
14
- ? project
15
- : path.join(process.cwd(), project);
16
- if (!fs.existsSync(p)) {
17
- throw new Error(`Unable to find tsconfig file at "${p}".`);
18
- }
19
- return p;
20
- }
21
- /**
22
- * Compute the common ancestor directory of a set of file paths — this matches
23
- * what TypeScript does when `rootDir` is not specified in tsconfig.
24
- */
25
- function computeCommonSourceDirectory(filePaths, fallback) {
26
- if (filePaths.length === 0)
27
- return fallback;
28
- const dirs = filePaths.map((p) => path.dirname(p.replaceAll("\\", "/")));
29
- const segments = dirs.map((d) => d.split("/"));
30
- const first = segments[0];
31
- let commonLength = first.length;
32
- for (const seg of segments.slice(1)) {
33
- let i = 0;
34
- while (i < commonLength && i < seg.length && first[i] === seg[i]) {
35
- i++;
36
- }
37
- commonLength = i;
38
- }
39
- return first.slice(0, commonLength).join("/") || "/";
40
- }
41
12
  const program = new Command()
42
13
  .name("boperate")
43
14
  .description("Parse operator overloads and inject them into TypeScript files.")
@@ -118,7 +89,7 @@ program
118
89
  if (!fs.existsSync(outDir)) {
119
90
  fs.mkdirSync(outDir, { recursive: true });
120
91
  }
121
- fs.writeFileSync(outPath, JSON.stringify(result.sourceMap.edits, null, 2));
92
+ fs.writeFileSync(outPath, JSON.stringify(result.edits, null, 2));
122
93
  });
123
94
  }
124
95
  });
@@ -0,0 +1,7 @@
1
+ /** Resolve tsconfig path relative to cwd if not absolute. */
2
+ export declare function resolveTsConfig(project: string): string;
3
+ /**
4
+ * Compute the common ancestor directory of a set of file paths — this matches
5
+ * what TypeScript does when `rootDir` is not specified in tsconfig.
6
+ */
7
+ export declare function computeCommonSourceDirectory(filePaths: string[], fallback: string): string;
package/dist/utils.js ADDED
@@ -0,0 +1,32 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ /** Resolve tsconfig path relative to cwd if not absolute. */
4
+ export function resolveTsConfig(project) {
5
+ const p = path.isAbsolute(project)
6
+ ? project
7
+ : path.join(process.cwd(), project);
8
+ if (!fs.existsSync(p)) {
9
+ throw new Error(`Unable to find tsconfig file at "${p}".`);
10
+ }
11
+ return p;
12
+ }
13
+ /**
14
+ * Compute the common ancestor directory of a set of file paths — this matches
15
+ * what TypeScript does when `rootDir` is not specified in tsconfig.
16
+ */
17
+ export function computeCommonSourceDirectory(filePaths, fallback) {
18
+ if (filePaths.length === 0)
19
+ return fallback;
20
+ const dirs = filePaths.map((p) => path.dirname(p.replaceAll("\\", "/")));
21
+ const segments = dirs.map((d) => d.split("/"));
22
+ const first = segments[0];
23
+ let commonLength = first.length;
24
+ for (const seg of segments.slice(1)) {
25
+ let i = 0;
26
+ while (i < commonLength && i < seg.length && first[i] === seg[i]) {
27
+ i++;
28
+ }
29
+ commonLength = i;
30
+ }
31
+ return first.slice(0, commonLength).join("/") || "/";
32
+ }
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@boperators/cli",
3
- "version": "0.1.4",
3
+ "version": "0.2.1",
4
4
  "license": "MIT",
5
5
  "description": "CLI tool for boperators - transforms TypeScript files with operator overloads.",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/DiefBell/boperators",
8
+ "url": "git+https://github.com/DiefBell/boperators.git",
9
9
  "directory": "cli"
10
10
  },
11
+ "bugs": {
12
+ "url": "https://github.com/DiefBell/boperators/issues"
13
+ },
11
14
  "homepage": "https://github.com/DiefBell/boperators/tree/main/cli",
12
15
  "type": "module",
13
16
  "bin": {
@@ -26,6 +29,7 @@
26
29
  "scripts": {
27
30
  "build": "tsc",
28
31
  "watch": "tsc -w",
32
+ "test": "bun test",
29
33
  "prepublish": "bun run build"
30
34
  },
31
35
  "files": [
@@ -39,7 +43,7 @@
39
43
  "@commander-js/extra-typings": "^13.0.0"
40
44
  },
41
45
  "peerDependencies": {
42
- "boperators": "0.1.4",
46
+ "boperators": "0.2.1",
43
47
  "typescript": ">=5.0.0 <5.10.0"
44
48
  },
45
49
  "devDependencies": {