You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CLAUDE.md
+42-13Lines changed: 42 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,6 +49,13 @@ You are a **Principal Software Engineer** responsible for:
49
49
-**Update snapshots**: `pnpm test:unit -u` or `pnpm testu`
50
50
-**Coverage report**: `pnpm test:unit:coverage`
51
51
52
+
#### Vitest Memory Optimization (CRITICAL)
53
+
-**Pool configuration**: Use `pool: 'forks'` with `singleFork: true`, `maxForks: 1`, `isolate: true`
54
+
-**Memory limits**: Set `NODE_OPTIONS="--max-old-space-size=4096 --max-semi-space-size=512"` in `.env.test`
55
+
-**Timeout settings**: Use `testTimeout: 60000, hookTimeout: 60000` for stability
56
+
-**Thread limits**: Use `singleThread: true, maxThreads: 1` to prevent RegExp compiler exhaustion
57
+
-**Test cleanup**: 🚨 MANDATORY - Use `await trash([paths])` in test scripts/utilities only. For cleanup within `/src/` test files, use `fs.rm()` with proper error handling
58
+
52
59
### Cross-Platform Compatibility - CRITICAL: Windows and POSIX
53
60
-**🚨 MANDATORY**: Tests and functionality MUST work on both POSIX (macOS/Linux) and Windows systems
54
61
-**Path handling**: ALWAYS use `path.join()`, `path.resolve()`, `path.sep` for file paths
@@ -59,6 +66,9 @@ You are a **Principal Software Engineer** responsible for:
59
66
-**Temp directories**: Use `os.tmpdir()` for temporary file paths in tests
-**Path separators**: Never hard-code `/` or `\` in paths
63
73
- Use `path.sep` when you need the separator character
64
74
- Use `path.join()` to construct paths correctly
@@ -122,41 +132,48 @@ You are a **Principal Software Engineer** responsible for:
122
132
123
133
## Architecture
124
134
125
-
This is a JavaScript implementation of the Package URL (purl) specification for parsing and constructing package URLs.
135
+
This is a TypeScript implementation of the Package URL (purl) specification for parsing and constructing package URLs, compiled to CommonJS for deployment.
126
136
127
137
### Core Structure
128
-
-**Main entry**: `src/index.js` - Main exports and API
138
+
-**Main entry**: `src/package-url.ts` - Main exports and API (TypeScript)
129
139
-**Parser**: Core parsing logic for purl strings
130
140
-**Normalizer**: Normalization logic for different package types
131
141
-**Validator**: Input validation and sanitization
132
142
-**Types**: Type-specific handling for npm, pypi, maven, etc.
133
143
-**Scripts**: `scripts/` - Build and utility scripts
- High-performance parsing with TypeScript type safety
139
150
- Type-specific normalization
140
151
- Comprehensive validation
141
152
- Extensive test coverage
153
+
- CommonJS-only deployment for maximum compatibility
142
154
143
155
## 🔧 Code Style (MANDATORY)
144
156
145
157
### 📁 File Organization
146
-
-**File extensions**: Use `.js` for JavaScript files, `.mjs` for ES modules
158
+
-**File extensions**: Use `.ts` for TypeScript files, `.js` for JavaScript files, `.mjs` for ES modules
147
159
-**Import order**: Node.js built-ins first, then third-party packages, then local imports
148
160
-**Import grouping**: Group imports by source (Node.js, external packages, local modules)
149
-
-**Type imports**: When using JSDoc, keep type imports organized
161
+
-**Type imports**: 🚨 ALWAYS use separate `import type` statements for TypeScript types, NEVER mix runtime imports with type imports in the same statement
162
+
- ✅ CORRECT: `import { readPackageJson } from '@socketsecurity/registry/lib/packages'` followed by `import type { PackageJson } from '@socketsecurity/registry/lib/packages'`
163
+
- ❌ FORBIDDEN: `import { readPackageJson, type PackageJson } from '@socketsecurity/registry/lib/packages'`
150
164
151
165
### Naming Conventions
152
-
-**Constants**: Use `UPPER_SNAKE_CASE` for constants
153
-
-**Files**: Use kebab-case for filenames
166
+
-**Constants**: Use `UPPER_SNAKE_CASE` for constants (e.g., `CMD_NAME`, `REPORT_LEVEL`)
167
+
-**Files**: Use kebab-case for filenames (e.g., `package-url.ts`, `purl-type.ts`)
154
168
-**Variables**: Use camelCase for variables and functions
155
169
-**Classes**: Use PascalCase for classes
170
+
-**Types/Interfaces**: Use PascalCase for TypeScript types and interfaces
156
171
157
172
### 🏗️ Code Structure (CRITICAL PATTERNS)
173
+
-**Type definitions**: 🚨 ALWAYS use `import type` for better tree-shaking and TypeScript optimization
158
174
-**Error handling**: 🚨 REQUIRED - Use try-catch blocks and handle errors gracefully
159
175
-**Array destructuring**: Use object notation `{ 0: key, 1: data }` instead of array destructuring `[key, data]`
176
+
-**Dynamic imports**: 🚨 FORBIDDEN - Never use dynamic imports (`await import()`). Always use static imports at the top of the file
160
177
-**Comment formatting**: 🚨 MANDATORY - ALL comments MUST follow these rules:
161
178
-**Periods required**: Every comment MUST end with a period, except ESLint disable comments and URLs which are directives/references. This includes single-line, multi-line, inline, and c8 ignore comments.
162
179
-**Sentence structure**: Comments should be complete sentences with proper capitalization and grammar.
@@ -177,18 +194,30 @@ This is a JavaScript implementation of the Package URL (purl) specification for
177
194
-**Existence checks**: Perform simple existence checks first before complex operations
178
195
-**Destructuring order**: Sort destructured properties alphabetically in const declarations
179
196
-**Function ordering**: Place functions in alphabetical order, with private functions first, then exported functions
180
-
-**Object mappings**: Use objects with `__proto__: null` for static mappings to prevent prototype pollution
181
-
-**Array length checks**: Use `!array.length` instead of `array.length === 0`
197
+
-**Object mappings**: Use objects with `__proto__: null` (not `undefined`) for static string-to-string mappings and lookup tables to prevent prototype pollution; use `Map` for dynamic collections that will be mutated
198
+
-**Mapping constants**: Move static mapping objects outside functions as module-level constants with descriptive UPPER_SNAKE_CASE names
199
+
-**Array length checks**: Use `!array.length` instead of `array.length === 0`. For `array.length > 0`, use `!!array.length` when function must return boolean, or `array.length` when used in conditional contexts
182
200
-**Catch parameter naming**: Use `catch (e)` instead of `catch (error)` for consistency
183
-
-**Number formatting**: 🚨 REQUIRED - Use underscore separators (e.g., `20_000`) for large numeric literals
201
+
-**Number formatting**: 🚨 REQUIRED - Use underscore separators (e.g., `20_000`) for large numeric literals. 🚨 FORBIDDEN - Do NOT modify number values inside strings
202
+
-**Node.js fs imports**: 🚨 MANDATORY pattern - `import { someSyncThing, promises as fs } from 'node:fs'`
203
+
-**Process spawning**: 🚨 FORBIDDEN to use Node.js built-in `child_process.spawn` - MUST use `spawn` from `@socketsecurity/registry/lib/spawn`
184
204
185
205
### 🗑️ Safe File Operations (SECURITY CRITICAL)
186
-
-**File deletion**: 🚨 ABSOLUTELY FORBIDDEN - NEVER use `rm -rf`. 🚨 MANDATORY - ALWAYS use `pnpm dlx trash-cli`
206
+
-**Script usage only**: Use `trash` package ONLY in scripts, build files, and utilities - NOT in `/src/` files
207
+
-**Import and use `trash` package**: `import { trash } from 'trash'` then `await trash(paths)` (scripts only)
208
+
-**Source code deletion**: In `/src/` files, use `fs.rm()` with proper error handling when deletion is required
209
+
-**Script deletion operations**: Use `await trash()` for scripts, build processes, and development utilities
210
+
-**Array optimization**: `trash` accepts arrays - collect paths and pass as array
211
+
-**Async requirement**: Always `await trash()` - it's an async operation
212
+
-**NO rmSync**: 🚨 ABSOLUTELY FORBIDDEN - NEVER use `fs.rmSync()` or `rm -rf` commands
187
213
-**Examples**:
188
214
- ❌ CATASTROPHIC: `rm -rf directory` (permanent deletion - DATA LOSS RISK)
0 commit comments