Skip to content

Commit 6b35b1f

Browse files
committed
refactor: move const declarations below static imports
Ensure all static imports precede variable declarations to maintain consistent module organization and prevent potential initialization issues. Files updated: - src/debug.ts: Move logger declaration after imports - src/fs.ts: Move abortSignal declaration after imports - src/packages/manifest.ts: Move const declarations after imports - src/packages/operations.ts: Move const declarations after imports - src/spawn.ts: Move const declarations after imports - src/stdio/prompts.ts: Reorder imports before const declarations
1 parent ae3cd44 commit 6b35b1f

File tree

6 files changed

+26
-28
lines changed

6 files changed

+26
-28
lines changed

src/debug.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import { getDefaultLogger } from './logger'
1313
import { hasOwn } from './objects'
1414
import { applyLinePrefix } from './strings'
1515

16-
const logger = getDefaultLogger()
17-
1816
// IMPORTANT: Do not use destructuring here - use direct assignment instead.
1917
// tsgo has a bug that incorrectly transpiles destructured exports, resulting in
2018
// `exports.SomeName = void 0;` which causes runtime errors.
2119
// See: https://github.com/SocketDev/socket-packageurl-js/issues/3
2220
const ReflectApply = Reflect.apply
2321

22+
const logger = getDefaultLogger()
23+
2424
// Type definitions
2525
interface DebugOptions {
2626
namespaces?: string

src/fs.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ import { getAbortSignal } from './constants/process'
1919

2020
import { isArray } from './arrays'
2121
import { deleteAsync, deleteSync } from './external/del'
22-
23-
const abortSignal = getAbortSignal()
24-
2522
import { defaultIgnore, getGlobMatcher } from './globs'
2623
import type { JsonReviver } from './json'
2724
import { jsonParse } from './json'
@@ -35,6 +32,8 @@ import {
3532
} from './paths/socket'
3633
import { naturalCompare } from './sorts'
3734

35+
const abortSignal = getAbortSignal()
36+
3837
/**
3938
* Supported text encodings for Node.js Buffers.
4039
* Includes ASCII, UTF-8/16, base64, binary, and hexadecimal encodings.

src/packages/manifest.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ import {
1313
SOCKET_REGISTRY_REPO_NAME,
1414
} from '../constants/socket'
1515

16-
const abortSignal = getAbortSignal()
17-
const packageDefaultNodeRange = getPackageDefaultNodeRange()
18-
const PACKAGE_DEFAULT_SOCKET_CATEGORIES = getPackageDefaultSocketCategories()
19-
const packumentCache = getPackumentCache()
20-
2116
import npmPackageArg from '../external/npm-package-arg'
2217
import pacote from '../external/pacote'
2318
import semver from '../external/semver'
@@ -28,6 +23,11 @@ import type { PackageJson, PacoteOptions } from '../packages'
2823
import { resolvePackageJsonEntryExports } from './exports'
2924
import { isRegistryFetcherType } from './validation'
3025

26+
const abortSignal = getAbortSignal()
27+
const packageDefaultNodeRange = getPackageDefaultNodeRange()
28+
const PACKAGE_DEFAULT_SOCKET_CATEGORIES = getPackageDefaultSocketCategories()
29+
const packumentCache = getPackumentCache()
30+
3131
const pkgScopePrefixRegExp = /^@socketregistry\//
3232

3333
/**

src/packages/operations.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,6 @@ import { PackageURL } from '../external/@socketregistry/packageurl-js'
1818
import pacote from '../external/pacote'
1919
import * as semver from '../external/semver'
2020

21-
const abortSignal = getAbortSignal()
22-
const packageExtensions = getPackageExtensions()
23-
const packumentCache = getPackumentCache()
24-
const pacoteCachePath = getPacoteCachePath()
25-
26-
// Initialize fetcher with cache settings
27-
const fetcher = makeFetchHappen.defaults({
28-
cachePath: pacoteCachePath,
29-
// Prefer-offline: Staleness checks for cached data will be bypassed, but
30-
// missing data will be requested from the server.
31-
// https://github.com/npm/make-fetch-happen?tab=readme-ov-file#--optscache
32-
cache: 'force-cache',
33-
})
34-
3521
import { readJson, readJsonSync } from '../fs'
3622
import { isObjectObject, merge } from '../objects'
3723
import type {
@@ -52,6 +38,20 @@ import {
5238
} from './specs'
5339
import { toEditablePackageJson, toEditablePackageJsonSync } from './editable'
5440

41+
const abortSignal = getAbortSignal()
42+
const packageExtensions = getPackageExtensions()
43+
const packumentCache = getPackumentCache()
44+
const pacoteCachePath = getPacoteCachePath()
45+
46+
// Initialize fetcher with cache settings
47+
const fetcher = makeFetchHappen.defaults({
48+
cachePath: pacoteCachePath,
49+
// Prefer-offline: Staleness checks for cached data will be bypassed, but
50+
// missing data will be requested from the server.
51+
// https://github.com/npm/make-fetch-happen?tab=readme-ov-file#--optscache
52+
cache: 'force-cache',
53+
})
54+
5555
/**
5656
* Extract a package to a destination directory.
5757
*/

src/spawn.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ import path from 'node:path'
3434
import { isArray } from './arrays'
3535
import { whichSync } from './bin'
3636
import { isPath } from './paths/normalize'
37+
import { getOwn, hasOwn } from './objects'
38+
import { stripAnsi } from './strings'
3739

3840
const abortSignal = getAbortSignal()
3941
const spinner = getSpinner()
4042

41-
import { getOwn, hasOwn } from './objects'
42-
import { stripAnsi } from './strings'
43-
4443
// Define BufferEncoding type for TypeScript compatibility.
4544
type BufferEncoding = globalThis.BufferEncoding
4645

src/stdio/prompts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import inputRaw from '../external/@inquirer/input'
1111
import passwordRaw from '../external/@inquirer/password'
1212
import * as searchModule from '../external/@inquirer/search'
1313
import * as selectModuleImport from '../external/@inquirer/select'
14+
import yoctocolorsCjs from '../external/yoctocolors-cjs'
1415

1516
import type { ColorValue } from '../colors'
1617
import { getTheme } from '../themes/context'
1718
import { THEMES, type ThemeName } from '../themes/themes'
1819
import type { Theme } from '../themes/types'
1920
import { resolveColor } from '../themes/utils'
20-
import yoctocolorsCjs from '../external/yoctocolors-cjs'
2121

2222
const abortSignal = getAbortSignal()
2323
const spinner = getSpinner()

0 commit comments

Comments
 (0)