Skip to content

Commit 89c4f80

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

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

src/dlx/detect.ts

Lines changed: 5 additions & 7 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,12 +197,12 @@ 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')

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)