Skip to content

Commit 5ee922f

Browse files
committed
refactor: add .js extensions to external require calls
Add explicit .js extensions to all require('./external/...) calls for better module resolution and consistency. This improves compatibility with modern bundlers and makes the module system more explicit. Updated 18 require calls across 10 files: - src/bin.ts (which) - src/cacache.ts (cacache) - src/dlx-package.ts (npm-package-arg, libnpmexec, pacote, @npmcli/arborist) - src/fs.ts (del) - src/globs.ts (picomatch, fast-glob) - src/package-default-node-range.ts (semver) - src/package-extensions.ts (@yarnpkg/extensions) - src/sorts.ts (fast-sort, semver) - src/spawn.ts (@npmcli/promise-spawn) - src/spinner.ts (yoctocolors-cjs) - src/streams.ts (streaming-iterables) - src/versions.ts (semver)
1 parent a312de3 commit 5ee922f

File tree

12 files changed

+18
-18
lines changed

12 files changed

+18
-18
lines changed

src/bin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ let _which: typeof import('which') | undefined
4747
/*@__NO_SIDE_EFFECTS__*/
4848
function getWhich() {
4949
if (_which === undefined) {
50-
_which = /*@__PURE__*/ require('./external/which')
50+
_which = /*@__PURE__*/ require('./external/which.js')
5151
}
5252
return _which!
5353
}

src/cacache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface RemoveOptions {
4242
* Get the cacache module for cache operations.
4343
*/
4444
export function getCacache() {
45-
return /*@__PURE__*/ require('./external/cacache')
45+
return /*@__PURE__*/ require('./external/cacache.js')
4646
}
4747

4848
/**

src/dlx-package.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ let _npmPackageArg: typeof import('npm-package-arg') | undefined
6464
/*@__NO_SIDE_EFFECTS__*/
6565
function getNpmPackageArg() {
6666
if (_npmPackageArg === undefined) {
67-
_npmPackageArg = /*@__PURE__*/ require('./external/npm-package-arg')
67+
_npmPackageArg = /*@__PURE__*/ require('./external/npm-package-arg.js')
6868
}
6969
return _npmPackageArg as typeof import('npm-package-arg')
7070
}
@@ -73,7 +73,7 @@ let _libnpmexec: typeof import('./external/libnpmexec') | undefined
7373
/*@__NO_SIDE_EFFECTS__*/
7474
function getLibnpmexec() {
7575
if (_libnpmexec === undefined) {
76-
_libnpmexec = /*@__PURE__*/ require('./external/libnpmexec')
76+
_libnpmexec = /*@__PURE__*/ require('./external/libnpmexec.js')
7777
}
7878
return _libnpmexec!
7979
}
@@ -82,7 +82,7 @@ let _pacote: typeof import('pacote') | undefined
8282
/*@__NO_SIDE_EFFECTS__*/
8383
function getPacote() {
8484
if (_pacote === undefined) {
85-
_pacote = /*@__PURE__*/ require('./external/pacote')
85+
_pacote = /*@__PURE__*/ require('./external/pacote.js')
8686
}
8787
return _pacote as typeof import('pacote')
8888
}
@@ -91,7 +91,7 @@ let _arborist: typeof import('@npmcli/arborist') | undefined
9191
/*@__NO_SIDE_EFFECTS__*/
9292
function getArborist() {
9393
if (_arborist === undefined) {
94-
_arborist = /*@__PURE__*/ require('./external/@npmcli/arborist')
94+
_arborist = /*@__PURE__*/ require('./external/@npmcli/arborist.js')
9595
}
9696
return _arborist!
9797
}

src/fs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ export async function safeDelete(
11541154
filepath: PathLike | PathLike[],
11551155
options?: RemoveOptions | undefined,
11561156
) {
1157-
const { deleteAsync } = /*@__PURE__*/ require('./external/del')
1157+
const { deleteAsync } = /*@__PURE__*/ require('./external/del.js')
11581158
const opts = { __proto__: null, ...options } as RemoveOptions
11591159
const patterns = isArray(filepath)
11601160
? filepath.map(pathLikeToString)
@@ -1227,7 +1227,7 @@ export function safeDeleteSync(
12271227
filepath: PathLike | PathLike[],
12281228
options?: RemoveOptions | undefined,
12291229
) {
1230-
const { deleteSync } = /*@__PURE__*/ require('./external/del')
1230+
const { deleteSync } = /*@__PURE__*/ require('./external/del.js')
12311231
const opts = { __proto__: null, ...options } as RemoveOptions
12321232
const patterns = isArray(filepath)
12331233
? filepath.map(pathLikeToString)

src/globs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ let _picomatch: typeof import('picomatch') | undefined
9191
function getPicomatch() {
9292
if (_picomatch === undefined) {
9393
// The 'picomatch' package is browser safe.
94-
_picomatch = /*@__PURE__*/ require('./external/picomatch')
94+
_picomatch = /*@__PURE__*/ require('./external/picomatch.js')
9595
}
9696
return _picomatch as typeof import('picomatch')
9797
}
@@ -104,7 +104,7 @@ let _fastGlob: typeof import('fast-glob') | undefined
104104
/*@__NO_SIDE_EFFECTS__*/
105105
function getFastGlob() {
106106
if (_fastGlob === undefined) {
107-
_fastGlob = /*@__PURE__*/ require('./external/fast-glob')
107+
_fastGlob = /*@__PURE__*/ require('./external/fast-glob.js')
108108
}
109109
return _fastGlob as typeof import('fast-glob')
110110
}

src/package-default-node-range.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
const { maintainedNodeVersions } = require('#lib/maintained-node-versions')
6-
const semver = require('./external/semver')
6+
const semver = require('./external/semver.js')
77

88
const packageDefaultNodeRange = `>=${semver.parse(maintainedNodeVersions.last).major}`
99

src/package-extensions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
const { freeze: ObjectFreeze } = Object
99

10-
const yarnPkgExtensions = require('./external/@yarnpkg/extensions')
10+
const yarnPkgExtensions = require('./external/@yarnpkg/extensions.js')
1111

1212
const packageExtensions = ObjectFreeze(
1313
[

src/sorts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function naturalSorter<T>(
5757
): ReturnType<FastSortFunction> {
5858
if (_naturalSorter === undefined) {
5959
const fastSort =
60-
/*@__PURE__*/ require('./external/fast-sort') as typeof import('fast-sort')
60+
/*@__PURE__*/ require('./external/fast-sort.js') as typeof import('fast-sort')
6161
_naturalSorter = fastSort.createNewSortInstance({
6262
comparer: naturalCompare,
6363
}) as FastSortFunction
@@ -79,7 +79,7 @@ export function compareStr(a: string, b: string): number {
7979
/*@__NO_SIDE_EFFECTS__*/
8080
export function compareSemver(a: string, b: string): number {
8181
const semver =
82-
/*@__PURE__*/ require('./external/semver') as typeof import('semver')
82+
/*@__PURE__*/ require('./external/semver.js') as typeof import('semver')
8383
const validA: string | null = semver.valid(a)
8484
const validB: string | null = semver.valid(b)
8585

src/spawn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ let _npmCliPromiseSpawn:
132132
/*@__NO_SIDE_EFFECTS__*/
133133
function getNpmcliPromiseSpawn() {
134134
if (_npmCliPromiseSpawn === undefined) {
135-
_npmCliPromiseSpawn = /*@__PURE__*/ require('./external/@npmcli/promise-spawn')
135+
_npmCliPromiseSpawn = /*@__PURE__*/ require('./external/@npmcli/promise-spawn.js')
136136
}
137137
return _npmCliPromiseSpawn as unknown as typeof import('@npmcli/promise-spawn')
138138
}

src/spinner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ function renderProgressBar(percentage: number, width: number = 20): string {
309309
const bar = '█'.repeat(filled) + '░'.repeat(empty)
310310
// Use cyan color for the progress bar
311311
const colors =
312-
/*@__PURE__*/ require('./external/yoctocolors-cjs') as typeof import('yoctocolors-cjs')
312+
/*@__PURE__*/ require('./external/yoctocolors-cjs.js') as typeof import('yoctocolors-cjs')
313313
return colors.cyan(bar)
314314
}
315315

0 commit comments

Comments
 (0)