Skip to content

Commit dff3ec6

Browse files
committed
style: apply linter auto-fixes to library utilities
1 parent 2f3527a commit dff3ec6

File tree

15 files changed

+123
-75
lines changed

15 files changed

+123
-75
lines changed

registry/src/lib/agent.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,23 +335,26 @@ export function execScript(
335335
const useNodeRun = !prepost && SUPPORTS_NODE_RUN
336336

337337
// Detect package manager based on lockfile by traversing up from current directory.
338-
const cwd = getOwn(spawnOptions, 'cwd') ?? process.cwd()
338+
const cwd =
339+
(getOwn(spawnOptions, 'cwd') as string | undefined) ?? process.cwd()
339340

340341
// Check for pnpm-lock.yaml.
341-
const pnpmLockPath = findUpSync(PNPM_LOCK_YAML, { cwd })
342+
const pnpmLockPath = findUpSync(PNPM_LOCK_YAML, { cwd }) as string | undefined
342343
if (pnpmLockPath) {
343344
return execPnpm(['run', scriptName, ...args], spawnOptions)
344345
}
345346

346347
// Check for package-lock.json.
347348
// When in an npm workspace, use npm run to ensure workspace binaries are available.
348-
const packageLockPath = findUpSync(PACKAGE_LOCK_JSON, { cwd })
349+
const packageLockPath = findUpSync(PACKAGE_LOCK_JSON, { cwd }) as
350+
| string
351+
| undefined
349352
if (packageLockPath) {
350353
return execNpm(['run', scriptName, ...args], spawnOptions)
351354
}
352355

353356
// Check for yarn.lock.
354-
const yarnLockPath = findUpSync(YARN_LOCK, { cwd })
357+
const yarnLockPath = findUpSync(YARN_LOCK, { cwd }) as string | undefined
355358
if (yarnLockPath) {
356359
return execYarn(['run', scriptName, ...args], spawnOptions)
357360
}

registry/src/lib/bin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import ENV from './constants/ENV'
7+
import { getWhich as getWhichDep } from './dependencies/index'
78
import { readJsonSync } from './fs'
89
import { getOwn } from './objects'
910
import { isPath, normalizePath } from './path'
@@ -44,7 +45,7 @@ let _which: typeof import('which') | undefined
4445
/*@__NO_SIDE_EFFECTS__*/
4546
function getWhich() {
4647
if (_which === undefined) {
47-
_which = /*@__PURE__*/ require('../external/which')
48+
_which = /*@__PURE__*/ getWhichDep()
4849
}
4950
return _which!
5051
}

registry/src/lib/cacache.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** @fileoverview Cacache utilities for Socket ecosystem shared content-addressable cache. */
22

3+
import { getCacache as getCacacheDep } from './dependencies/index'
34
import { getSocketCacacheDir } from './paths'
45

56
export interface GetOptions {
@@ -25,16 +26,11 @@ export interface CacheEntry {
2526
time: number
2627
}
2728

28-
let _cacache: typeof import('../external/cacache') | undefined
29-
3029
/**
3130
* Get the cacache module for cache operations.
3231
*/
3332
function getCacache() {
34-
if (_cacache === undefined) {
35-
_cacache = /*@__PURE__*/ require('../external/cacache')
36-
}
37-
return _cacache!
33+
return getCacacheDep()
3834
}
3935

4036
/**
@@ -53,7 +49,7 @@ export async function get(
5349
key: string,
5450
options?: GetOptions | undefined,
5551
): Promise<CacheEntry> {
56-
const cacache = getCacache()
52+
const cacache = getCacache() as any
5753
return await cacache.get(getSocketCacacheDir(), key, options)
5854
}
5955

@@ -72,8 +68,8 @@ export async function put(
7268
/**
7369
* Remove an entry from the Socket shared cache by key.
7470
*/
75-
export async function remove(key: string) {
76-
const cacache = getCacache()
71+
export async function remove(key: string): Promise<unknown> {
72+
const cacache = getCacache() as any
7773
return await cacache.rm.entry(getSocketCacacheDir(), key)
7874
}
7975

registry/src/lib/debug.ts

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
*/
55

66
import ENV from './constants/ENV'
7+
import {
8+
getDebug,
9+
getIsUnicodeSupported,
10+
getLogger,
11+
getSpinner,
12+
} from './dependencies/index'
713
import { hasOwn } from './objects'
814
import { applyLinePrefix } from './strings'
915

@@ -30,21 +36,6 @@ interface InspectOptions {
3036

3137
export type { DebugOptions, NamespacesOrOptions, InspectOptions }
3238

33-
let _debugJs: typeof import('debug') | undefined
34-
/**
35-
* Lazily load the debug module.
36-
* @private
37-
*/
38-
/*@__NO_SIDE_EFFECTS__*/
39-
function getDebugJs() {
40-
if (_debugJs === undefined) {
41-
// The 'debug' package is browser safe.
42-
const debugExport = /*@__PURE__*/ require('../external/debug')
43-
_debugJs = debugExport.default
44-
}
45-
return _debugJs!
46-
}
47-
4839
const debugByNamespace = new Map()
4940
/**
5041
* Get or create a debug instance for a namespace.
@@ -56,7 +47,7 @@ function getDebugJsInstance(namespace: string) {
5647
if (inst) {
5748
return inst
5849
}
59-
const debugJs = getDebugJs()
50+
const debugJs = getDebug()
6051
if (
6152
!ENV.DEBUG &&
6253
ENV.SOCKET_CLI_DEBUG &&
@@ -91,8 +82,8 @@ function getUtil() {
9182
*/
9283
/*@__NO_SIDE_EFFECTS__*/
9384
function customLog() {
94-
const { logger } = /*@__PURE__*/ require('./logger.js')
95-
const debugJs = getDebugJs()
85+
const logger = getLogger()
86+
const debugJs = getDebug()
9687
const util = getUtil()
9788
const inspectOpts = debugJs.inspectOpts
9889
? {
@@ -118,10 +109,10 @@ function customLog() {
118109
* @private
119110
*/
120111
/*@__NO_SIDE_EFFECTS__*/
121-
function extractOptions(namespaces: NamespacesOrOptions) {
112+
function extractOptions(namespaces: NamespacesOrOptions): DebugOptions {
122113
return namespaces !== null && typeof namespaces === 'object'
123-
? { __proto__: null, ...namespaces }
124-
: { __proto__: null, namespaces }
114+
? ({ __proto__: null, ...namespaces } as DebugOptions)
115+
: ({ __proto__: null, namespaces } as DebugOptions)
125116
}
126117

127118
/**
@@ -166,11 +157,11 @@ function debugDirNs(
166157
) {
167158
const options = extractOptions(namespacesOrOpts)
168159
const { namespaces } = options
169-
if (!isEnabled(namespaces)) {
160+
if (!isEnabled(namespaces as string)) {
170161
return
171162
}
172163
if (inspectOpts === undefined) {
173-
const debugJs = getDebugJs()
164+
const debugJs = getDebug()
174165
const opts = debugJs.inspectOpts
175166
if (opts) {
176167
inspectOpts = {
@@ -183,10 +174,10 @@ function debugDirNs(
183174
} as InspectOptions
184175
}
185176
}
186-
const { spinner = /*@__PURE__*/ require('./constants/spinner.js') } = options
177+
const spinner = options.spinner || getSpinner()
187178
const wasSpinning = spinner.isSpinning
188179
spinner.stop()
189-
const { logger } = /*@__PURE__*/ require('./logger.js')
180+
const logger = getLogger()
190181
logger.dir(obj, inspectOpts)
191182
if (wasSpinning) {
192183
spinner.start()
@@ -201,7 +192,7 @@ let pointingTriangle: string | undefined
201192
function debugFnNs(namespacesOrOpts: NamespacesOrOptions, ...args: unknown[]) {
202193
const options = extractOptions(namespacesOrOpts)
203194
const { namespaces } = options
204-
if (!isEnabled(namespaces)) {
195+
if (!isEnabled(namespaces as string)) {
205196
return
206197
}
207198
const { stack } = new Error()
@@ -240,8 +231,8 @@ function debugFnNs(namespacesOrOpts: NamespacesOrOptions, ...args: unknown[]) {
240231
}
241232
}
242233
if (pointingTriangle === undefined) {
243-
const supported =
244-
/*@__PURE__*/ require('../external/@socketregistry/is-unicode-supported')()
234+
const isUnicodeSupported = getIsUnicodeSupported()
235+
const supported = isUnicodeSupported()
245236
pointingTriangle = supported ? '▸' : '>'
246237
}
247238
const text = args.at(0)
@@ -255,10 +246,10 @@ function debugFnNs(namespacesOrOpts: NamespacesOrOptions, ...args: unknown[]) {
255246
...args.slice(1),
256247
]
257248
: args
258-
const { spinner = /*@__PURE__*/ require('./constants/spinner.js') } = options
249+
const spinner = options.spinner || getSpinner()
259250
const wasSpinning = spinner.isSpinning
260251
spinner.stop()
261-
const { logger } = /*@__PURE__*/ require('./logger.js')
252+
const logger = getLogger()
262253
ReflectApply(logger.info, logger, logArgs)
263254
if (wasSpinning) {
264255
spinner.start()
@@ -272,10 +263,10 @@ function debugFnNs(namespacesOrOpts: NamespacesOrOptions, ...args: unknown[]) {
272263
function debugLogNs(namespacesOrOpts: NamespacesOrOptions, ...args: unknown[]) {
273264
const options = extractOptions(namespacesOrOpts)
274265
const { namespaces } = options
275-
if (!isEnabled(namespaces)) {
266+
if (!isEnabled(namespaces as string)) {
276267
return
277268
}
278-
const { spinner = /*@__PURE__*/ require('./constants/spinner.js') } = options
269+
const spinner = options.spinner || getSpinner()
279270
const wasSpinning = spinner.isSpinning
280271
spinner.stop()
281272
ReflectApply(customLog, undefined, args)

registry/src/lib/download-lock.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,14 @@ async function acquireLock(
9898
try {
9999
// Try to read existing lock
100100
if (existsSync(lockPath)) {
101+
// eslint-disable-next-line no-await-in-loop
101102
const lockContent = await readFile(lockPath, 'utf8')
102103
const lockInfo: DownloadLockInfo = JSON.parse(lockContent)
103104

104105
// Check if lock is stale
105106
if (isLockStale(lockInfo, staleTimeout)) {
106107
// Remove stale lock
108+
// eslint-disable-next-line no-await-in-loop
107109
await rm(lockPath, { force: true })
108110
} else {
109111
// Lock is valid, check timeout
@@ -114,6 +116,7 @@ async function acquireLock(
114116
}
115117

116118
// Wait and retry
119+
// eslint-disable-next-line no-await-in-loop
117120
await new Promise(resolve => setTimeout(resolve, pollInterval))
118121
continue
119122
}
@@ -126,6 +129,7 @@ async function acquireLock(
126129
url,
127130
}
128131

132+
// eslint-disable-next-line no-await-in-loop
129133
await writeFile(lockPath, JSON.stringify(lockInfo, null, 2), {
130134
// Use 'wx' flag to fail if file exists (atomic operation)
131135
flag: 'wx',
@@ -139,6 +143,7 @@ async function acquireLock(
139143
if (Date.now() - startTime > lockTimeout) {
140144
throw new Error(`Lock acquisition timed out after ${lockTimeout}ms`)
141145
}
146+
// eslint-disable-next-line no-await-in-loop
142147
await new Promise(resolve => setTimeout(resolve, pollInterval))
143148
continue
144149
}

registry/src/lib/fs.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import abortSignal from './constants/abort-signal'
7+
import { getDel } from './dependencies'
78
import { defaultIgnore, getGlobMatcher } from './globs'
89
import { jsonParse } from './json'
910
import { normalizePath, pathLikeToString } from './path'
@@ -566,7 +567,7 @@ export async function remove(
566567
filepath: PathLike | PathLike[],
567568
options?: RemoveOptions | undefined,
568569
) {
569-
const del = /*@__PURE__*/ require('../external/del')
570+
const del = /*@__PURE__*/ getDel() as any
570571
const { deleteAsync } = del
571572
const opts = { __proto__: null, ...options } as RemoveOptions
572573
const patterns = ArrayIsArray(filepath)
@@ -591,7 +592,7 @@ export function removeSync(
591592
filepath: PathLike | PathLike[],
592593
options?: RemoveOptions | undefined,
593594
) {
594-
const del = /*@__PURE__*/ require('../external/del')
595+
const del = /*@__PURE__*/ getDel() as any
595596
const { deleteSync } = del
596597
const opts = { __proto__: null, ...options } as RemoveOptions
597598
const patterns = ArrayIsArray(filepath)

registry/src/lib/globs.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
*/
55

66
// IMPORTANT: Do not use destructuring here - use direct assignment instead.
7+
import {
8+
getFastGlob as getFastGlobDep,
9+
getPicomatch as getPicomatchDep,
10+
} from './dependencies/index'
711
// tsgo has a bug that incorrectly transpiles destructured exports, resulting in
812
// `exports.SomeName = void 0;` which causes runtime errors.
913
// See: https://github.com/SocketDev/socket-packageurl-js/issues/3
@@ -94,7 +98,7 @@ let _picomatch: typeof import('picomatch') | undefined
9498
function getPicomatch() {
9599
if (_picomatch === undefined) {
96100
// The 'picomatch' package is browser safe.
97-
_picomatch = /*@__PURE__*/ require('../external/picomatch')
101+
_picomatch = /*@__PURE__*/ getPicomatchDep()
98102
}
99103
return _picomatch!
100104
}
@@ -107,7 +111,7 @@ let _fastGlob: typeof import('fast-glob') | undefined
107111
/*@__NO_SIDE_EFFECTS__*/
108112
function getFastGlob() {
109113
if (_fastGlob === undefined) {
110-
_fastGlob = /*@__PURE__*/ require('../external/fast-glob')
114+
_fastGlob = /*@__PURE__*/ getFastGlobDep()
111115
}
112116
return _fastGlob!
113117
}

registry/src/lib/http-request.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ async function httpRequestAttempt(
184184
)
185185
},
186186
body: responseBody,
187-
headers: res.headers as Record<string, string | string[] | undefined>,
187+
headers: res.headers as Record<
188+
string,
189+
string | string[] | undefined
190+
>,
188191
json<T = unknown>(): T {
189192
return JSON.parse(responseBody.toString('utf8')) as T
190193
},

registry/src/lib/objects.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export function getOwn(obj: unknown, propKey: PropertyKey): unknown {
245245
if (obj === null || obj === undefined) {
246246
return undefined
247247
}
248-
return ObjectHasOwn(obj, propKey)
248+
return ObjectHasOwn(obj as object, propKey)
249249
? (obj as Record<PropertyKey, unknown>)[propKey]
250250
: undefined
251251
}
@@ -277,8 +277,8 @@ export function hasKeys(obj: unknown): obj is PropertyBag {
277277
if (obj === null || obj === undefined) {
278278
return false
279279
}
280-
for (const key in obj) {
281-
if (ObjectHasOwn(obj, key)) {
280+
for (const key in obj as object) {
281+
if (ObjectHasOwn(obj as object, key)) {
282282
return true
283283
}
284284
}
@@ -296,7 +296,7 @@ export function hasOwn(
296296
if (obj === null || obj === undefined) {
297297
return false
298298
}
299-
return ObjectHasOwn(obj, propKey)
299+
return ObjectHasOwn(obj as object, propKey)
300300
}
301301

302302
/**
@@ -331,7 +331,7 @@ export function objectEntries(obj: unknown): Array<[PropertyKey, unknown]> {
331331
if (obj === null || obj === undefined) {
332332
return []
333333
}
334-
const keys = ReflectOwnKeys(obj)
334+
const keys = ReflectOwnKeys(obj as object)
335335
const { length } = keys
336336
const entries = Array(length)
337337
const record = obj as Record<PropertyKey, unknown>

0 commit comments

Comments
 (0)