Skip to content

Commit 229cb0f

Browse files
committed
refactor: hoist getDefaultLogger() calls to const logger
Transforms direct getDefaultLogger().method() calls to hoisted logger constant for better performance and code clarity: - Modified 98 files with 944 replacements - Added module-scoped const logger = getDefaultLogger() where appropriate - Fixed logger scope issues in with-subcommands.mts Benefits: - Single logger initialization per module/function - Clearer code intent - Slightly better performance (no repeated function calls)
1 parent 7800556 commit 229cb0f

File tree

107 files changed

+1178
-988
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+1178
-988
lines changed

packages/bootstrap/src/bootstrap-npm.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ main()
2424
process.exit(exitCode)
2525
})
2626
.catch((e) => {
27-
getDefaultLogger().error(`Bootstrap error: ${e instanceof Error ? e.message : String(e)}`)
27+
const logger = getDefaultLogger()
28+
logger.error(`Bootstrap error: ${e instanceof Error ? e.message : String(e)}`)
2829
process.exit(1)
2930
})

packages/build-infra/lib/extraction-cache.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ export async function shouldExtract({
7373
}
7474

7575
// Cache hit!
76-
getDefaultLogger().log(`✓ Using cached ${outputPath}`)
76+
const logger = getDefaultLogger()
77+
logger.log(`✓ Using cached ${outputPath}`)
7778
return false
7879
} catch {
7980
// Any error, regenerate.

packages/build-infra/lib/fetch-with-retry.mjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export async function fetchWithRetry(url, options = {}, retryOptions = {}) {
3636
// Success!
3737
if (response.ok) {
3838
if (attempt > 1 && !silent) {
39-
getDefaultLogger().log(`✓ Request succeeded on attempt ${attempt}`)
39+
const logger = getDefaultLogger()
40+
logger.log(`✓ Request succeeded on attempt ${attempt}`)
4041
}
4142
return response
4243
}
@@ -63,10 +64,10 @@ export async function fetchWithRetry(url, options = {}, retryOptions = {}) {
6364
if (attempt < retries) {
6465
const delay = Math.min(initialDelay * 2 ** (attempt - 1), maxDelay)
6566
if (!silent) {
66-
getDefaultLogger().warn(
67+
logger.warn(
6768
`✗ Attempt ${attempt}/${retries} failed: ${response.status} ${response.statusText}`,
6869
)
69-
getDefaultLogger().log(` Retrying in ${delay}ms...`)
70+
logger.log(` Retrying in ${delay}ms...`)
7071
}
7172
await sleep(delay)
7273
}
@@ -79,8 +80,8 @@ export async function fetchWithRetry(url, options = {}, retryOptions = {}) {
7980
if (attempt < retries) {
8081
const delay = Math.min(initialDelay * 2 ** (attempt - 1), maxDelay)
8182
if (!silent) {
82-
getDefaultLogger().warn(`✗ Attempt ${attempt}/${retries} failed: ${error.message}`)
83-
getDefaultLogger().log(` Retrying in ${delay}ms...`)
83+
logger.warn(`✗ Attempt ${attempt}/${retries} failed: ${error.message}`)
84+
logger.log(` Retrying in ${delay}ms...`)
8485
}
8586
await sleep(delay)
8687
continue

packages/build-infra/lib/preflight-checks.mjs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ export async function runPreflightChecks(options = {}) {
4242
const failures = []
4343

4444
if (!quiet) {
45-
getDefaultLogger().step('Running preflight checks')
46-
getDefaultLogger().log('')
45+
const logger = getDefaultLogger()
46+
logger.step('Running preflight checks')
47+
logger.log('')
4748
}
4849

4950
// Check disk space.
@@ -96,10 +97,10 @@ export async function runPreflightChecks(options = {}) {
9697
if (!quiet) {
9798
if (!failures.length) {
9899
printSuccess('All preflight checks passed')
99-
getDefaultLogger().log('')
100+
logger.log('')
100101
} else {
101102
printError(`${failures.length} preflight check(s) failed`)
102-
getDefaultLogger().log('')
103+
logger.log('')
103104
}
104105
}
105106

@@ -120,9 +121,9 @@ export async function runPreflightChecksOrExit(options = {}) {
120121

121122
if (!result.passed) {
122123
if (!options.quiet) {
123-
getDefaultLogger().error('Preflight checks failed')
124+
logger.error('Preflight checks failed')
124125
for (const failure of result.failures) {
125-
getDefaultLogger().error(` - ${failure}`)
126+
logger.error(` - ${failure}`)
126127
}
127128
}
128129
process.exit(1)

packages/build-infra/lib/script-runner.mjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export async function runPnpmScriptAll(scriptName, args = [], options = {}) {
5858
export async function runSequence(commands, globalOptions = {}) {
5959
for (const { args = [], command, description, options = {} } of commands) {
6060
if (description) {
61-
getDefaultLogger().step(description)
61+
const logger = getDefaultLogger()
62+
logger.step(description)
6263
}
6364

6465
const result = await spawn(command, args, {
@@ -121,7 +122,7 @@ export const pnpm = {
121122
* Run pnpm install with frozen lockfile.
122123
*/
123124
install: async (options = {}) => {
124-
getDefaultLogger().step('Installing dependencies')
125+
logger.step('Installing dependencies')
125126
return spawn('pnpm', ['install', '--frozen-lockfile'], {
126127
shell: WIN32,
127128
stdio: 'inherit',
@@ -133,7 +134,7 @@ export const pnpm = {
133134
* Build all packages or specific package.
134135
*/
135136
build: async (packageName = null, options = {}) => {
136-
getDefaultLogger().step(packageName ? `Building ${packageName}` : 'Building packages')
137+
logger.step(packageName ? `Building ${packageName}` : 'Building packages')
137138
const args = packageName
138139
? ['--filter', packageName, 'run', 'build']
139140
: ['run', '-r', 'build']
@@ -149,7 +150,7 @@ export const pnpm = {
149150
* Run tests in specific package or all packages.
150151
*/
151152
test: async (packageName = null, options = {}) => {
152-
getDefaultLogger().step(packageName ? `Testing ${packageName}` : 'Running tests')
153+
logger.step(packageName ? `Testing ${packageName}` : 'Running tests')
153154
const args = packageName
154155
? ['--filter', packageName, 'run', 'test']
155156
: ['run', '-r', 'test']

packages/cli-with-sentry/scripts/build.mjs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ async function main() {
2121
const cliPath = path.join(rootPath, '..', 'cli')
2222

2323
// Build CLI bundle.
24-
getDefaultLogger().info('Building CLI bundle...')
24+
const logger = getDefaultLogger()
25+
logger.info('Building CLI bundle...')
2526
let result = await spawn('node', ['.config/esbuild.config.mjs'], {
2627
shell: WIN32,
2728
stdio: 'inherit',
@@ -34,10 +35,10 @@ async function main() {
3435
if (result.code !== 0) {
3536
throw new Error(`CLI bundle build failed with exit code ${result.code}`)
3637
}
37-
getDefaultLogger().success('Built CLI bundle')
38+
logger.success('Built CLI bundle')
3839

3940
// Build index loader.
40-
getDefaultLogger().info('Building index loader...')
41+
logger.info('Building index loader...')
4142
result = await spawn('node', ['.config/esbuild.index.config.mjs'], {
4243
shell: WIN32,
4344
stdio: 'inherit',
@@ -46,10 +47,10 @@ async function main() {
4647
if (result.code !== 0) {
4748
throw new Error(`Index loader build failed with exit code ${result.code}`)
4849
}
49-
getDefaultLogger().success('Built index loader')
50+
logger.success('Built index loader')
5051

5152
// Build shadow npm inject.
52-
getDefaultLogger().info('Building shadow npm inject...')
53+
logger.info('Building shadow npm inject...')
5354
result = await spawn('node', ['.config/esbuild.inject.config.mjs'], {
5455
shell: WIN32,
5556
stdio: 'inherit',
@@ -58,10 +59,10 @@ async function main() {
5859
if (result.code !== 0) {
5960
throw new Error(`Shadow npm inject build failed with exit code ${result.code}`)
6061
}
61-
getDefaultLogger().success('Built shadow npm inject')
62+
logger.success('Built shadow npm inject')
6263

6364
// Compress CLI.
64-
getDefaultLogger().info('Compressing CLI...')
65+
logger.info('Compressing CLI...')
6566
result = await spawn('node', ['scripts/compress-cli.mjs'], {
6667
shell: WIN32,
6768
stdio: 'inherit',
@@ -70,17 +71,17 @@ async function main() {
7071
if (result.code !== 0) {
7172
throw new Error(`CLI compression failed with exit code ${result.code}`)
7273
}
73-
getDefaultLogger().success('Compressed CLI')
74+
logger.success('Compressed CLI')
7475

7576
// Copy data directory from packages/cli.
76-
getDefaultLogger().info('Copying data/ from packages/cli...')
77+
logger.info('Copying data/ from packages/cli...')
7778
await fs.cp(path.join(cliPath, 'data'), path.join(rootPath, 'data'), {
7879
recursive: true,
7980
})
80-
getDefaultLogger().success('Copied data/')
81+
logger.success('Copied data/')
8182

8283
// Copy files from repo root.
83-
getDefaultLogger().info('Copying files from repo root...')
84+
logger.info('Copying files from repo root...')
8485
const filesToCopy = [
8586
'CHANGELOG.md',
8687
'LICENSE',
@@ -90,9 +91,9 @@ async function main() {
9091
for (const file of filesToCopy) {
9192
await fs.cp(path.join(repoRoot, file), path.join(rootPath, file))
9293
}
93-
getDefaultLogger().success('Copied files from repo root')
94+
logger.success('Copied files from repo root')
9495
} catch (error) {
95-
getDefaultLogger().error(`Build failed: ${error.message}`)
96+
logger.error(`Build failed: ${error.message}`)
9697
process.exitCode = 1
9798
}
9899
}

packages/cli-with-sentry/scripts/compress-cli.mjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ const distPath = path.join(rootPath, 'dist')
2222
const cliPath = path.join(buildPath, 'cli.js')
2323
const cliBzPath = path.join(distPath, 'cli.js.bz')
2424

25-
getDefaultLogger().log('')
26-
getDefaultLogger().step('Compressing CLI with brotli...')
25+
const logger = getDefaultLogger()
26+
logger.log('')
27+
logger.step('Compressing CLI with brotli...')
2728

2829
// Ensure dist/ directory exists.
2930
mkdirSync(distPath, { recursive: true })
@@ -44,8 +45,8 @@ const compressedSize = compressed.length
4445
writeFileSync(cliBzPath, compressed)
4546

4647
const compressionRatio = ((1 - compressedSize / originalSize) * 100).toFixed(1)
47-
getDefaultLogger().success(
48+
logger.success(
4849
`Compressed: ${(originalSize / 1024 / 1024).toFixed(2)} MB → ${(compressedSize / 1024 / 1024).toFixed(2)} MB (${compressionRatio}% reduction)`,
4950
)
5051

51-
getDefaultLogger().log('')
52+
logger.log('')

packages/cli-with-sentry/scripts/verify-package.mjs

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,22 @@ async function fileExists(filePath) {
2626
* Main validation function.
2727
*/
2828
async function validate() {
29-
getDefaultLogger().log('')
30-
getDefaultLogger().log('='.repeat(60))
31-
getDefaultLogger().log(`${colors.blue('CLI with Sentry Package Validation')}`)
32-
getDefaultLogger().log('='.repeat(60))
33-
getDefaultLogger().log('')
29+
const logger = getDefaultLogger()
30+
logger.log('')
31+
logger.log('='.repeat(60))
32+
logger.log(`${colors.blue('CLI with Sentry Package Validation')}`)
33+
logger.log('='.repeat(60))
34+
logger.log('')
3435

3536
const errors = []
3637

3738
// Check package.json exists and validate Sentry configuration.
38-
getDefaultLogger().info('Checking package.json...')
39+
logger.info('Checking package.json...')
3940
const pkgPath = path.join(packageRoot, 'package.json')
4041
if (!(await fileExists(pkgPath))) {
4142
errors.push('package.json does not exist')
4243
} else {
43-
getDefaultLogger().success('package.json exists')
44+
logger.success('package.json exists')
4445

4546
// Validate package.json configuration.
4647
const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf-8'))
@@ -49,7 +50,7 @@ async function validate() {
4950
if (!pkg.dependencies?.['@sentry/node']) {
5051
errors.push('package.json missing @sentry/node in dependencies')
5152
} else {
52-
getDefaultLogger().success('@sentry/node is in dependencies')
53+
logger.success('@sentry/node is in dependencies')
5354
}
5455

5556
// Validate files array.
@@ -67,99 +68,99 @@ async function validate() {
6768
}
6869
}
6970
if (errors.length === 0) {
70-
getDefaultLogger().success('package.json files array is correct')
71+
logger.success('package.json files array is correct')
7172
}
7273
}
7374

7475
// Check root files exist (LICENSE, CHANGELOG.md).
7576
const rootFiles = ['LICENSE', 'CHANGELOG.md']
7677
for (const file of rootFiles) {
77-
getDefaultLogger().info(`Checking ${file}...`)
78+
logger.info(`Checking ${file}...`)
7879
const filePath = path.join(packageRoot, file)
7980
if (!(await fileExists(filePath))) {
8081
errors.push(`${file} does not exist`)
8182
} else {
82-
getDefaultLogger().success(`${file} exists`)
83+
logger.success(`${file} exists`)
8384
}
8485
}
8586

8687
// Check dist files exist and validate Sentry integration.
8788
const distFiles = ['index.js', 'cli.js.bz', 'shadow-npm-inject.js']
8889
for (const file of distFiles) {
89-
getDefaultLogger().info(`Checking dist/${file}...`)
90+
logger.info(`Checking dist/${file}...`)
9091
const filePath = path.join(packageRoot, 'dist', file)
9192
if (!(await fileExists(filePath))) {
9293
errors.push(`dist/${file} does not exist`)
9394
} else {
94-
getDefaultLogger().success(`dist/${file} exists`)
95+
logger.success(`dist/${file} exists`)
9596
}
9697
}
9798

9899
// Verify Sentry is referenced in the build (check for @sentry/node require).
99-
getDefaultLogger().info('Checking for Sentry integration in build...')
100+
logger.info('Checking for Sentry integration in build...')
100101
const buildPath = path.join(packageRoot, 'build', 'cli.js')
101102
if (await fileExists(buildPath)) {
102103
const buildContent = await fs.readFile(buildPath, 'utf-8')
103104
if (!buildContent.includes('@sentry/node')) {
104105
errors.push('Sentry integration not found in build/cli.js')
105106
} else {
106-
getDefaultLogger().success('Sentry integration found in build')
107+
logger.success('Sentry integration found in build')
107108
}
108109
} else {
109110
errors.push('build/cli.js does not exist (required for Sentry validation)')
110111
}
111112

112113
// Check data directory exists.
113-
getDefaultLogger().info('Checking data directory...')
114+
logger.info('Checking data directory...')
114115
const dataPath = path.join(packageRoot, 'data')
115116
if (!(await fileExists(dataPath))) {
116117
errors.push('data directory does not exist')
117118
} else {
118-
getDefaultLogger().success('data directory exists')
119+
logger.success('data directory exists')
119120

120121
// Check data files.
121122
const dataFiles = [
122123
'alert-translations.json',
123124
'command-api-requirements.json',
124125
]
125126
for (const file of dataFiles) {
126-
getDefaultLogger().info(`Checking data/${file}...`)
127+
logger.info(`Checking data/${file}...`)
127128
const filePath = path.join(dataPath, file)
128129
if (!(await fileExists(filePath))) {
129130
errors.push(`data/${file} does not exist`)
130131
} else {
131-
getDefaultLogger().success(`data/${file} exists`)
132+
logger.success(`data/${file} exists`)
132133
}
133134
}
134135
}
135136

136137
// Print summary.
137-
getDefaultLogger().log('')
138-
getDefaultLogger().log('='.repeat(60))
139-
getDefaultLogger().log(`${colors.blue('Validation Summary')}`)
140-
getDefaultLogger().log('='.repeat(60))
141-
getDefaultLogger().log('')
138+
logger.log('')
139+
logger.log('='.repeat(60))
140+
logger.log(`${colors.blue('Validation Summary')}`)
141+
logger.log('='.repeat(60))
142+
logger.log('')
142143

143144
if (errors.length > 0) {
144-
getDefaultLogger().log(`${colors.red('Errors:')}`)
145+
logger.log(`${colors.red('Errors:')}`)
145146
for (const err of errors) {
146-
getDefaultLogger().fail(` ${err}`)
147+
logger.fail(` ${err}`)
147148
}
148-
getDefaultLogger().log('')
149-
getDefaultLogger().fail('Package validation FAILED')
150-
getDefaultLogger().log('')
149+
logger.log('')
150+
logger.fail('Package validation FAILED')
151+
logger.log('')
151152
process.exit(1)
152153
}
153154

154-
getDefaultLogger().success('Package validation PASSED')
155-
getDefaultLogger().log('')
155+
logger.success('Package validation PASSED')
156+
logger.log('')
156157
process.exit(0)
157158
}
158159

159160
// Run validation.
160161
validate().catch(e => {
161-
getDefaultLogger().error('')
162-
getDefaultLogger().fail(`Unexpected error: ${e.message}`)
163-
getDefaultLogger().error('')
162+
logger.error('')
163+
logger.fail(`Unexpected error: ${e.message}`)
164+
logger.error('')
164165
process.exit(1)
165166
})

0 commit comments

Comments
 (0)