Skip to content

Commit 9b7507b

Browse files
committed
refactor: inline lazy-loading for external modules
Move lazy-loading wrapper functions directly into the modules that use them instead of keeping them in separate external/*.ts files. This simplifies the module structure and avoids confusion with the external re-export .js files. - dlx-package.ts: Add inline getNpmPackageArg() and getPacote() - versions.ts: Add inline getSemver() - Remove src/external/{npm-package-arg,pacote,semver}.ts
1 parent df875bc commit 9b7507b

5 files changed

Lines changed: 27 additions & 64 deletions

File tree

src/dlx-package.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,31 @@ import path from 'node:path'
3636
import { WIN32 } from './constants/platform'
3737
import { getPacoteCachePath } from './constants/packages'
3838
import { generateCacheKey } from './dlx'
39-
import { getNpmPackageArg } from './external/npm-package-arg'
40-
import { getPacote } from './external/pacote'
4139
import { readJsonSync } from './fs'
4240
import { normalizePath } from './path'
4341
import { getSocketDlxDir } from './paths'
4442
import { processLock } from './process-lock'
4543
import type { SpawnExtra, SpawnOptions } from './spawn'
4644
import { spawn } from './spawn'
4745

46+
let _npmPackageArg: typeof import('npm-package-arg') | undefined
47+
/*@__NO_SIDE_EFFECTS__*/
48+
function getNpmPackageArg() {
49+
if (_npmPackageArg === undefined) {
50+
_npmPackageArg = /*@__PURE__*/ require('../external/npm-package-arg')
51+
}
52+
return _npmPackageArg as typeof import('npm-package-arg')
53+
}
54+
55+
let _pacote: typeof import('pacote') | undefined
56+
/*@__NO_SIDE_EFFECTS__*/
57+
function getPacote() {
58+
if (_pacote === undefined) {
59+
_pacote = /*@__PURE__*/ require('../external/pacote')
60+
}
61+
return _pacote as typeof import('pacote')
62+
}
63+
4864
/**
4965
* Regex to check if a version string contains range operators.
5066
* Matches any version with range operators: ~, ^, >, <, =, x, X, *, spaces, or ||.

src/external/npm-package-arg.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/external/pacote.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/external/semver.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/versions.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
/** @fileoverview Version comparison and validation utilities for Socket ecosystem. */
22

3-
import { getSemver } from './external/semver'
3+
let _semver: typeof import('semver') | undefined
4+
/*@__NO_SIDE_EFFECTS__*/
5+
function getSemver() {
6+
if (_semver === undefined) {
7+
// The 'semver' package is browser safe.
8+
_semver = /*@__PURE__*/ require('../external/semver')
9+
}
10+
return _semver as typeof import('semver')
11+
}
412

513
/**
614
* Coerce a version string to valid semver format.

0 commit comments

Comments
 (0)