Skip to content

Commit 891010e

Browse files
committed
fix: resolve quality scan issues
Critical fixes: - Add try-catch for JSON.parse in releases/github.ts (2 instances) - Fix lastIndexOf('@') edge case in package-extensions.ts External bundles fixes: - Bundle debug, which, signal-exit, supports-color inline - Eliminates hidden requires that would fail without node_modules Workflow fixes: - Replace process.exit() with throw in cover.mjs and filter.mjs - Replace process.exit(1) with process.exitCode in main.mjs catch handler GitHub Actions improvements: - Add concurrency limits to CI workflow - Document all workflow permissions with inline comments Documentation fixes: - Fix incorrect function names in README.md (readJsonFile → readJson) - Fix non-existent constant in README.md (NODE_MODULES → PACKAGE, LATEST) - Update CLAUDE.md directory structure, path aliases, build scripts, exports
1 parent 70de2be commit 891010e

13 files changed

Lines changed: 97 additions & 80 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: ⚡ CI
33
# Dependencies:
44
# - SocketDev/socket-registry/.github/workflows/ci.yml
55

6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.ref }}
8+
cancel-in-progress: true
9+
610
on:
711
push:
812
branches: [main]

.github/workflows/claude-auto-review.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ on:
99
workflow_dispatch:
1010

1111
permissions:
12-
contents: read
13-
id-token: write
14-
pull-requests: read
12+
contents: read # Read repository code for analysis
13+
id-token: write # Generate OIDC token for Anthropic API authentication
14+
pull-requests: read # Read PR metadata and diff for review
1515

1616
jobs:
1717
auto-review:

.github/workflows/claude.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ on:
1515
workflow_dispatch:
1616

1717
permissions:
18-
contents: read
19-
id-token: write
20-
issues: write
21-
pull-requests: write
18+
contents: read # Read repository code for Claude analysis
19+
id-token: write # Generate OIDC token for Anthropic API authentication
20+
issues: write # Post Claude responses to issues
21+
pull-requests: write # Post Claude responses to PR comments
2222

2323
jobs:
2424
claude:

.github/workflows/provenance.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ on:
1616
- '1'
1717

1818
permissions:
19-
contents: write
20-
id-token: write
19+
contents: write # Push git tags and create GitHub releases
20+
id-token: write # NPM trusted publishing via OIDC
2121

2222
jobs:
2323
publish:

.github/workflows/socket-auto-pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ on:
1919
- '1'
2020

2121
permissions:
22-
contents: write
23-
pull-requests: write
22+
contents: write # Commit dependency updates to branches
23+
pull-requests: write # Create automated Socket.dev security PRs
2424

2525
jobs:
2626
socket-auto-pr:

CLAUDE.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ src/
112112
├── types.ts # TypeScript type definitions
113113
├── constants/ # Node.js, npm, package manager constants
114114
├── env/ # Typed environment variable access
115-
├── lib/ # Core utility functions
116-
│ └── packages/ # Package management utilities
115+
├── packages/ # Package management utilities
117116
├── external/ # Vendored external dependencies
118117
└── utils/ # Shared utilities
119118
@@ -125,19 +124,19 @@ scripts/ # Build and development scripts
125124
test/ # Test files
126125
```
127126

128-
**Path aliases**:
127+
**Path aliases** (defined in `.config/tsconfig.external-aliases.json`):
129128
```
130129
#constants/* → src/constants/*
131130
#env/* → src/env/*
132-
#lib/* → src/lib/*
133-
#packages/* → src/lib/packages/*
131+
#lib/* → src/*
132+
#packages/* → src/packages/*
134133
#types → src/types
135134
#utils/* → src/utils/*
136135
```
137136

138137
### Commands
139138
- **Build**: `pnpm build` (production build)
140-
- **Watch**: `pnpm run build:watch` or `pnpm run dev` (development mode)
139+
- **Watch**: `pnpm run dev` (development mode)
141140
- **Test**: `pnpm test` (run tests)
142141
- **Type check**: `pnpm run check` (TypeScript type checking)
143142
- **Lint**: `pnpm run lint` (Biome linting)
@@ -149,26 +148,29 @@ test/ # Test files
149148

150149
#### Compilation
151150
- **Target**: TypeScript → CommonJS (ES2022)
152-
- **Builder**: esbuild via `scripts/build-js.mjs`
151+
- **Builder**: esbuild via `scripts/build/js.mjs`
153152
- **Type generation**: tsgo (TypeScript Native Preview)
154153
- **Output**: `dist/` directory
155154

156155
#### Build Scripts
157-
All build scripts are Node.js modules (`.mjs`):
158-
- `build-js.mjs` - Main JavaScript compilation
159-
- `build-externals.mjs` - External dependency bundling
160-
- `fix-commonjs-exports.mjs` - Post-build CommonJS export fixes
161-
- `fix-default-imports.mjs` - Fix default import patterns
162-
- `generate-package-exports.mjs` - Auto-generate package.json exports
156+
All build scripts are Node.js modules (`.mjs`) in `scripts/`:
157+
- `build/js.mjs` - Main JavaScript compilation
158+
- `build/externals.mjs` - External dependency bundling
159+
- `fix/commonjs-exports.mjs` - Post-build CommonJS export fixes
160+
- `fix/external-imports.mjs` - Fix external import patterns
161+
- `fix/generate-package-exports.mjs` - Auto-generate package.json exports
163162

164163
🚨 **FORBIDDEN**: Shell scripts (`.sh`) - Always use Node.js scripts
165164

166165
#### Build Process
167-
1. Clean previous build: `pnpm run clean`
168-
2. Compile JavaScript: `pnpm run build:js`
169-
3. Generate types: `pnpm run build:types`
170-
4. Bundle externals: `pnpm run build:externals`
171-
5. Fix exports: `pnpm run fix:exports`
166+
The main build command (`pnpm build`) orchestrates via `scripts/build/main.mjs`:
167+
1. Clean previous build
168+
2. Build in parallel: source code, types, and externals
169+
3. Fix exports via `scripts/fix/main.mjs`
170+
171+
Individual commands:
172+
- `pnpm run clean` - Clean build artifacts only
173+
- `pnpm build` - Full build (default)
172174

173175
### Code Style - Lib-Specific
174176

@@ -250,8 +252,8 @@ Blank lines between groups, alphabetical within groups.
250252
All modules are exported via `package.json` exports field:
251253
- **Constants**: `./constants/<name>``dist/constants/<name>.js`
252254
- **Environment**: `./env/<name>``dist/env/<name>.js`
253-
- **Libraries**: `./<name>``dist/lib/<name>.js`
254-
- **Packages**: `./packages/<name>``dist/lib/packages/<name>.js`
255+
- **Libraries**: `./<name>``dist/<name>.js`
256+
- **Packages**: `./packages/<name>``dist/packages/<name>.js`
255257
- **Types**: `./types``dist/types.js`
256258

257259
#### Adding New Exports
@@ -351,7 +353,7 @@ path: |
351353
3. `pnpm test` - Run tests (or `pnpm run cover` for coverage)
352354

353355
#### Watch Mode
354-
Use `pnpm run build:watch` or `pnpm run dev` for development with automatic rebuilds.
356+
Use `pnpm run dev` for development with automatic rebuilds.
355357

356358
#### Adding New Utilities
357359
1. Create utility in appropriate `src/` subdirectory

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ pnpm add @socketsecurity/lib
2020
```typescript
2121
// Tree-shakeable exports
2222
import { Spinner } from '@socketsecurity/lib/spinner'
23-
import { readJsonFile } from '@socketsecurity/lib/fs'
24-
import { NODE_MODULES } from '@socketsecurity/lib/constants/packages'
23+
import { readJson } from '@socketsecurity/lib/fs'
24+
import { PACKAGE, LATEST } from '@socketsecurity/lib/constants/packages'
2525

2626
const spinner = Spinner({ text: 'Loading...' })
2727
spinner.start()
28-
const pkg = await readJsonFile('./package.json')
28+
const pkg = await readJson('./package.json')
2929
spinner.stop()
3030
```
3131

scripts/build-externals/esbuild-config.mjs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function createStubPlugin(stubMap = STUB_MAP) {
153153
}
154154

155155
// Shared dependencies bundled in external-pack that should be marked external in other bundles.
156-
const EXTERNAL_PACK_DEPS = [
156+
const _EXTERNAL_PACK_DEPS = [
157157
'has-flag',
158158
'signal-exit',
159159
'supports-color',
@@ -178,8 +178,8 @@ export function getPackageSpecificOptions(packageName) {
178178
// Zod has localization files we don't need.
179179
opts.external = [...(opts.external || []), './locales/*']
180180
} else if (packageName === 'debug') {
181-
// Mark shared deps as external - they're bundled in external-pack.
182-
opts.external = [...(opts.external || []), ...EXTERNAL_PACK_DEPS]
181+
// Bundle supports-color inline to avoid external dependency.
182+
// This makes debug.js fully self-contained.
183183
} else if (packageName === 'external-pack') {
184184
// Inquirer packages have heavy dependencies we can exclude.
185185
opts.external = [...(opts.external || []), 'rxjs/operators']
@@ -189,14 +189,8 @@ export function getPackageSpecificOptions(packageName) {
189189
js: 'if (module.exports && module.exports.default && Object.keys(module.exports).length === 1) { module.exports = module.exports.default; }',
190190
}
191191
} else if (packageName === 'npm-pack') {
192-
// Mark shared deps as external - they're bundled in external-pack.
193-
// Also mark debug and which as external since they have their own bundles.
194-
opts.external = [
195-
...(opts.external || []),
196-
...EXTERNAL_PACK_DEPS,
197-
'debug',
198-
'which',
199-
]
192+
// Bundle all deps inline to make npm-pack.js fully self-contained.
193+
// This avoids hidden requires to debug, which, signal-exit, supports-color.
200194
} else if (packageName === '@socketregistry/packageurl-js') {
201195
// packageurl-js imports from socket-lib, creating a circular dependency.
202196
// Mark socket-lib imports as external to avoid bundling issues.

scripts/test/cover.mjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ const buildResult = await spawn('node', ['scripts/build/main.mjs'], {
4242
},
4343
})
4444
if (buildResult.code !== 0) {
45-
logger.error('Build with source maps failed')
46-
process.exitCode = 1
47-
process.exit(1)
45+
throw new Error('Build with source maps failed')
4846
}
4947

5048
// Run vitest with coverage enabled, capturing output

scripts/test/filter.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ const projectRoot = path.resolve(__dirname, '..')
2020
// Find all coverage JSON files
2121
const coverageDir = path.join(projectRoot, 'coverage')
2222
if (!fs.existsSync(coverageDir)) {
23-
logger.error('Coverage directory not found:', coverageDir)
24-
process.exit(1)
23+
throw new Error(`Coverage directory not found: ${coverageDir}`)
2524
}
2625

2726
const coverageFinalPath = path.join(coverageDir, 'coverage-final.json')

0 commit comments

Comments
 (0)