Skip to content

Commit 7a20f39

Browse files
committed
refactor(dlx): rename isNodeJsExtension to isJsFilepath
1 parent c2fc236 commit 7a20f39

File tree

3 files changed

+45
-31
lines changed

3 files changed

+45
-31
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [5.4.2](https://github.com/SocketDev/socket-lib/releases/tag/v5.4.2) - 2026-01-12
9+
10+
### Added
11+
12+
- **dlx/detect**: Executable type detection utilities for DLX cache and local file paths
13+
- `detectExecutableType()`: Generic entry point that routes to appropriate detection strategy
14+
- `detectDlxExecutableType()`: Detects Node.js packages vs native binaries in DLX cache by checking for node_modules/ directory
15+
- `detectLocalExecutableType()`: Detects executables on local filesystem by checking package.json bin field or file extension
16+
- `isJsFilePath()`: Validates if a file path has .js, .mjs, or .cjs extension
17+
- `isNodePackage()`: Simplified helper that returns true for Node.js packages
18+
- `isNativeBinary()`: Simplified helper that returns true for native binary executables
19+
20+
### Fixed
21+
22+
- **releases/github**: Sort releases by published_at to reliably find latest release instead of relying on creation order
23+
824
## [5.4.1](https://github.com/SocketDev/socket-lib/releases/tag/v5.4.1) - 2026-01-10
925

1026
### Fixed

src/dlx/detect.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ export function detectLocalExecutableType(
135135
filePath: string,
136136
): ExecutableDetectionResult {
137137
const fs = getFs()
138-
const path = getPath()
139138

140139
// Check 1: Look for package.json with bin field.
141140
const packageJsonPath = findPackageJson(filePath)
@@ -157,12 +156,11 @@ export function detectLocalExecutableType(
157156
}
158157

159158
// Check 2: File extension fallback.
160-
const ext = path.extname(filePath).toLowerCase()
161-
if (NODE_JS_EXTENSIONS.has(ext as '.js' | '.mjs' | '.cjs')) {
159+
if (isJsFilePath(filePath)) {
162160
return {
163-
type: 'package',
164-
method: 'file-extension',
165161
inDlxCache: false,
162+
method: 'file-extension',
163+
type: 'package',
166164
}
167165
}
168166

@@ -199,33 +197,33 @@ function findPackageJson(filePath: string): string | undefined {
199197
}
200198

201199
/**
202-
* Check if a file extension indicates a Node.js script.
200+
* Check if a file path indicates a Node.js script.
203201
*
204202
* @param filePath - Path to check
205203
* @returns True if file has .js, .mjs, or .cjs extension
206204
*/
207-
export function isNodeJsExtension(filePath: string): boolean {
205+
export function isJsFilePath(filePath: string): boolean {
208206
const path = getPath()
209207
const ext = path.extname(filePath).toLowerCase()
210208
return NODE_JS_EXTENSIONS.has(ext as '.js' | '.mjs' | '.cjs')
211209
}
212210

213211
/**
214-
* Simplified helper: Is this a Node.js package?
212+
* Simplified helper: Is this a native binary executable?
215213
*
216214
* @param filePath - Path to check
217-
* @returns True if detected as Node.js package
215+
* @returns True if detected as native binary (not Node.js package)
218216
*/
219-
export function isNodePackage(filePath: string): boolean {
220-
return detectExecutableType(filePath).type === 'package'
217+
export function isNativeBinary(filePath: string): boolean {
218+
return detectExecutableType(filePath).type === 'binary'
221219
}
222220

223221
/**
224-
* Simplified helper: Is this a native binary executable?
222+
* Simplified helper: Is this a Node.js package?
225223
*
226224
* @param filePath - Path to check
227-
* @returns True if detected as native binary (not Node.js package)
225+
* @returns True if detected as Node.js package
228226
*/
229-
export function isNativeBinary(filePath: string): boolean {
230-
return detectExecutableType(filePath).type === 'binary'
227+
export function isNodePackage(filePath: string): boolean {
228+
return detectExecutableType(filePath).type === 'package'
231229
}

test/unit/dlx-detect.test.mts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* - detectExecutableType() generic entry point routing
66
* - detectDlxExecutableType() detects packages vs binaries in DLX cache
77
* - detectLocalExecutableType() detects via package.json and file extensions
8-
* - isNodeJsExtension() validates .js, .mjs, .cjs extensions
8+
* - isJsFilePath() validates .js, .mjs, .cjs file paths
99
* - isNodePackage() simplified helper for package detection
1010
* - isNativeBinary() simplified helper for binary detection
1111
*
@@ -34,8 +34,8 @@ import {
3434
detectDlxExecutableType,
3535
detectExecutableType,
3636
detectLocalExecutableType,
37+
isJsFilePath,
3738
isNativeBinary,
38-
isNodeJsExtension,
3939
isNodePackage,
4040
} from '@socketsecurity/lib/dlx/detect'
4141
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
@@ -281,33 +281,33 @@ describe('DLX Executable Type Detection', () => {
281281
})
282282
})
283283

284-
describe('isNodeJsExtension', () => {
284+
describe('isJsFilePath', () => {
285285
it('should return true for .js files', () => {
286-
expect(isNodeJsExtension('/path/to/file.js')).toBe(true)
287-
expect(isNodeJsExtension('file.js')).toBe(true)
286+
expect(isJsFilePath('/path/to/file.js')).toBe(true)
287+
expect(isJsFilePath('file.js')).toBe(true)
288288
})
289289

290290
it('should return true for .mjs files', () => {
291-
expect(isNodeJsExtension('/path/to/module.mjs')).toBe(true)
292-
expect(isNodeJsExtension('module.mjs')).toBe(true)
291+
expect(isJsFilePath('/path/to/module.mjs')).toBe(true)
292+
expect(isJsFilePath('module.mjs')).toBe(true)
293293
})
294294

295295
it('should return true for .cjs files', () => {
296-
expect(isNodeJsExtension('/path/to/common.cjs')).toBe(true)
297-
expect(isNodeJsExtension('common.cjs')).toBe(true)
296+
expect(isJsFilePath('/path/to/common.cjs')).toBe(true)
297+
expect(isJsFilePath('common.cjs')).toBe(true)
298298
})
299299

300300
it('should be case-insensitive', () => {
301-
expect(isNodeJsExtension('FILE.JS')).toBe(true)
302-
expect(isNodeJsExtension('MODULE.MJS')).toBe(true)
303-
expect(isNodeJsExtension('COMMON.CJS')).toBe(true)
301+
expect(isJsFilePath('FILE.JS')).toBe(true)
302+
expect(isJsFilePath('MODULE.MJS')).toBe(true)
303+
expect(isJsFilePath('COMMON.CJS')).toBe(true)
304304
})
305305

306306
it('should return false for non-Node.js extensions', () => {
307-
expect(isNodeJsExtension('/path/to/binary')).toBe(false)
308-
expect(isNodeJsExtension('/path/to/file.py')).toBe(false)
309-
expect(isNodeJsExtension('/path/to/file.sh')).toBe(false)
310-
expect(isNodeJsExtension('/path/to/file.exe')).toBe(false)
307+
expect(isJsFilePath('/path/to/binary')).toBe(false)
308+
expect(isJsFilePath('/path/to/file.py')).toBe(false)
309+
expect(isJsFilePath('/path/to/file.sh')).toBe(false)
310+
expect(isJsFilePath('/path/to/file.exe')).toBe(false)
311311
})
312312
})
313313

0 commit comments

Comments
 (0)