@joe-sh/pj 1.4.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Joseph Schmitt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,277 @@
1
+ # @joe-sh/pj
2
+
3
+ TypeScript API and binary installer for [pj](https://github.com/josephschmitt/pj) - a fast project finder.
4
+
5
+ ## Features
6
+
7
+ - **Dual-purpose package**: Works as both a global CLI tool and a TypeScript library
8
+ - **Automatic binary management**: Downloads and manages the pj binary automatically
9
+ - **Smart binary resolution**: Prefers globally installed pj, falls back to managed binary
10
+ - **Full TypeScript support**: Complete type definitions for all APIs
11
+ - **Cross-platform**: Works on macOS, Linux, and Windows
12
+
13
+ ## Installation
14
+
15
+ ### As a global CLI tool
16
+
17
+ ```bash
18
+ npm install -g @joe-sh/pj
19
+ ```
20
+
21
+ Then use `pj` directly:
22
+
23
+ ```bash
24
+ pj --icons
25
+ ```
26
+
27
+ ### As a library
28
+
29
+ ```bash
30
+ npm install @joe-sh/pj
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ### Library API
36
+
37
+ ```typescript
38
+ import { Pj, discover } from '@joe-sh/pj';
39
+
40
+ // Using the class-based API
41
+ const pj = new Pj();
42
+ const projects = await pj.discover();
43
+ console.log(projects);
44
+
45
+ // Using standalone functions
46
+ const allProjects = await discover();
47
+
48
+ // Find a specific project
49
+ const myProject = await pj.findProject('my-app');
50
+
51
+ // Search for projects by pattern
52
+ const reactProjects = await pj.findProjects(/react/i);
53
+
54
+ // Get projects grouped by marker type
55
+ const byMarker = await pj.discoverByMarker();
56
+ console.log(byMarker.get('package.json')); // All Node.js projects
57
+ ```
58
+
59
+ ### Discovery Options
60
+
61
+ ```typescript
62
+ const projects = await pj.discover({
63
+ // Search paths
64
+ paths: ['~/projects', '~/code'],
65
+
66
+ // Project markers to detect
67
+ markers: ['.git', 'package.json', 'go.mod'],
68
+
69
+ // Patterns to exclude
70
+ excludes: ['node_modules', 'vendor'],
71
+
72
+ // Maximum search depth
73
+ maxDepth: 3,
74
+
75
+ // Include icons in output
76
+ icons: true,
77
+
78
+ // Bypass cache
79
+ noCache: true,
80
+ });
81
+ ```
82
+
83
+ ### Configuration Management
84
+
85
+ ```typescript
86
+ import { Pj, loadConfig, saveConfig } from '@joe-sh/pj';
87
+
88
+ // Load existing configuration
89
+ const config = await loadConfig();
90
+
91
+ // Create instance with custom config
92
+ const pj = new Pj({
93
+ paths: ['~/my-projects'],
94
+ maxDepth: 5,
95
+ });
96
+
97
+ // Save configuration
98
+ await pj.saveConfig();
99
+ ```
100
+
101
+ ### Binary Management
102
+
103
+ ```typescript
104
+ import { Pj, getBinaryManager } from '@joe-sh/pj';
105
+
106
+ const pj = new Pj();
107
+
108
+ // Check binary status
109
+ const status = await pj.getBinaryStatus();
110
+ console.log(status);
111
+ // { available: true, path: '/usr/local/bin/pj', version: '1.4.1', source: 'global' }
112
+
113
+ // Ensure binary is available (downloads if needed)
114
+ const binaryPath = await pj.ensureBinary();
115
+
116
+ // Update to latest version
117
+ await pj.updateBinary();
118
+
119
+ // Get version
120
+ const version = await pj.getBinaryVersion();
121
+ ```
122
+
123
+ ### Cache Management
124
+
125
+ ```typescript
126
+ const pj = new Pj();
127
+
128
+ // Clear the project cache
129
+ await pj.clearCache();
130
+
131
+ // Get cache info
132
+ const info = await pj.getCacheInfo();
133
+ console.log(info);
134
+ // { exists: true, path: '~/.cache/pj', fileCount: 3, totalSize: 4096 }
135
+ ```
136
+
137
+ ## API Reference
138
+
139
+ ### Pj Class
140
+
141
+ The main class for interacting with pj.
142
+
143
+ #### Constructor
144
+
145
+ ```typescript
146
+ new Pj(config?: Partial<PjConfig>)
147
+ ```
148
+
149
+ #### Methods
150
+
151
+ | Method | Description |
152
+ |--------|-------------|
153
+ | `discover(options?)` | Discover all projects |
154
+ | `discoverFromPaths(paths, options?)` | Discover projects from specific paths |
155
+ | `findProject(name, options?)` | Find a project by name |
156
+ | `findProjects(pattern, options?)` | Find projects matching a pattern |
157
+ | `discoverByMarker(options?)` | Get projects grouped by marker type |
158
+ | `countByMarker(options?)` | Count projects by marker type |
159
+ | `clearCache()` | Clear the pj project cache |
160
+ | `getCacheInfo()` | Get information about the pj cache |
161
+ | `loadConfig(path?)` | Load configuration from file |
162
+ | `saveConfig(config?, path?)` | Save configuration to file |
163
+ | `getConfig()` | Get current configuration |
164
+ | `setConfig(config)` | Update configuration |
165
+ | `ensureBinary(options?)` | Ensure the pj binary is available |
166
+ | `getBinaryStatus()` | Get the status of the pj binary |
167
+ | `updateBinary(options?)` | Update the pj binary |
168
+ | `getBinaryVersion()` | Get the version of the pj binary |
169
+
170
+ ### Standalone Functions
171
+
172
+ | Function | Description |
173
+ |----------|-------------|
174
+ | `discover(options?)` | Discover all projects |
175
+ | `discoverFromPaths(paths, options?)` | Discover from specific paths |
176
+ | `findProject(name, options?)` | Find a project by name |
177
+ | `findProjects(pattern, options?)` | Find projects by pattern |
178
+ | `discoverByMarker(options?)` | Group projects by marker |
179
+ | `countByMarker(options?)` | Count projects by marker |
180
+ | `loadConfig(path?)` | Load configuration |
181
+ | `saveConfig(config, path?)` | Save configuration |
182
+ | `clearCache()` | Clear the project cache |
183
+ | `getCacheInfo()` | Get cache information |
184
+ | `getBinaryManager()` | Get the binary manager instance |
185
+
186
+ ### Types
187
+
188
+ ```typescript
189
+ interface Project {
190
+ path: string; // Absolute path to the project
191
+ name: string; // Project name (directory name)
192
+ marker: string; // Marker that identified this project
193
+ icon?: string; // Optional Nerd Font icon
194
+ priority?: number; // Marker priority
195
+ }
196
+
197
+ interface DiscoverOptions {
198
+ paths?: string[];
199
+ markers?: string[];
200
+ excludes?: string[];
201
+ maxDepth?: number;
202
+ noIgnore?: boolean;
203
+ nested?: boolean;
204
+ noCache?: boolean;
205
+ icons?: boolean;
206
+ configPath?: string;
207
+ verbose?: boolean;
208
+ }
209
+
210
+ interface PjConfig {
211
+ paths: string[];
212
+ markers: string[];
213
+ exclude: string[];
214
+ maxDepth: number;
215
+ cacheTTL: number;
216
+ noIgnore: boolean;
217
+ noNested: boolean;
218
+ icons: Record<string, string>;
219
+ }
220
+
221
+ interface BinaryStatus {
222
+ available: boolean;
223
+ path: string | null;
224
+ version: string | null;
225
+ source: 'global' | 'cache' | 'env' | null;
226
+ }
227
+ ```
228
+
229
+ ## Environment Variables
230
+
231
+ | Variable | Description |
232
+ |----------|-------------|
233
+ | `PJ_BINARY_PATH` | Override the pj binary path |
234
+ | `PJ_SKIP_INSTALL` | Skip binary download during npm install |
235
+ | `PJ_INSTALL_BINARY` | Force binary download in CI environments |
236
+
237
+ ## Version Compatibility
238
+
239
+ This package tracks the [pj CLI](https://github.com/josephschmitt/pj) version using a **major.minor pinning** strategy:
240
+
241
+ | This package | Compatible pj versions |
242
+ |--------------|------------------------|
243
+ | `1.4.x` | `1.4.0`, `1.4.1`, `1.4.2`, ... |
244
+ | `1.5.x` | `1.5.0`, `1.5.1`, `1.5.2`, ... |
245
+
246
+ **How it works:**
247
+
248
+ - This package stays in sync with pj's major.minor version
249
+ - Patch versions (the third number) are independent — patches to this package are for TypeScript wrapper bug fixes, not pj CLI changes
250
+ - When you install or update, the package automatically downloads the **latest compatible pj patch** within your major.minor range
251
+
252
+ **What this means for you:**
253
+
254
+ - `@joe-sh/pj@1.4.2` will install the latest `pj 1.4.x` (e.g., `1.4.5` if available)
255
+ - When pj `1.5.0` is released, upgrade to `@joe-sh/pj@1.5.x` to get the new features
256
+
257
+ ## Binary Resolution Order
258
+
259
+ The package looks for the pj binary in this order:
260
+
261
+ 1. `PJ_BINARY_PATH` environment variable
262
+ 2. Globally installed `pj` in PATH (if version-compatible)
263
+ 3. Cached binary in `~/.cache/pj-node/` (if version-compatible)
264
+ 4. Downloads from GitHub releases (highest compatible version)
265
+
266
+ ## Requirements
267
+
268
+ - Node.js 20.0.0 or higher
269
+
270
+ ## Related Projects
271
+
272
+ - [pj](https://github.com/josephschmitt/pj) - The pj CLI tool
273
+ - [pj.nvim](https://github.com/josephschmitt/pj.nvim) - Neovim integration
274
+
275
+ ## License
276
+
277
+ MIT
package/bin/pj ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * CLI wrapper for pj
5
+ *
6
+ * This script ensures the pj binary is available and executes it with the
7
+ * provided arguments. It acts as a pass-through to the actual pj binary.
8
+ */
9
+
10
+ import { spawn } from "node:child_process";
11
+ import { getBinaryManager } from "../dist/index.js";
12
+
13
+ async function main() {
14
+ try {
15
+ const manager = getBinaryManager();
16
+ const binaryPath = await manager.getBinaryPath();
17
+
18
+ // Pass through all arguments to pj
19
+ const args = process.argv.slice(2);
20
+
21
+ const child = spawn(binaryPath, args, {
22
+ stdio: "inherit",
23
+ shell: false,
24
+ });
25
+
26
+ child.on("error", (error) => {
27
+ console.error(`Failed to start pj: ${error.message}`);
28
+ process.exit(1);
29
+ });
30
+
31
+ child.on("close", (code) => {
32
+ process.exit(code ?? 0);
33
+ });
34
+ } catch (error) {
35
+ console.error(
36
+ `Error: ${error instanceof Error ? error.message : String(error)}`
37
+ );
38
+ process.exit(1);
39
+ }
40
+ }
41
+
42
+ main();