Skip to content

Commit 9fac3cd

Browse files
committed
refactor(cli-with-sentry): use logger helper methods in verify-package script
- Replace manual color formatting with logger.info(), logger.success(), logger.fail() - Remove duplicate helper functions (success, error, info) that reimplemented logger methods - Cleaner, more maintainable code with consistent output formatting This is the first of several scripts that should be updated to use logger methods instead of manual color formatting. See related files that need similar updates: - packages/cli/scripts/verify-package.mjs - packages/socket/scripts/verify-package.mjs - scripts/build.mjs (partial - complex formatting) - And ~20 other build/test scripts
1 parent e9af9e6 commit 9fac3cd

File tree

1 file changed

+18
-39
lines changed

1 file changed

+18
-39
lines changed

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

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,6 @@ const __filename = fileURLToPath(import.meta.url)
1010
const __dirname = path.dirname(__filename)
1111
const packageRoot = path.resolve(__dirname, '..')
1212

13-
/**
14-
* Format a success message.
15-
*/
16-
function success(msg) {
17-
return `${colors.green('✓')} ${msg}`
18-
}
19-
20-
/**
21-
* Format an error message.
22-
*/
23-
function error(msg) {
24-
return `${colors.red('✗')} ${msg}`
25-
}
26-
27-
/**
28-
* Format an info message.
29-
*/
30-
function info(msg) {
31-
return `${colors.blue('ℹ')} ${msg}`
32-
}
33-
3413
/**
3514
* Check if a file exists and is readable.
3615
*/
@@ -56,12 +35,12 @@ async function validate() {
5635
const errors = []
5736

5837
// Check package.json exists and validate Sentry configuration.
59-
logger.log(info('Checking package.json...'))
38+
logger.info('Checking package.json...')
6039
const pkgPath = path.join(packageRoot, 'package.json')
6140
if (!(await fileExists(pkgPath))) {
6241
errors.push('package.json does not exist')
6342
} else {
64-
logger.log(success('package.json exists'))
43+
logger.success('package.json exists')
6544

6645
// Validate package.json configuration.
6746
const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf-8'))
@@ -70,7 +49,7 @@ async function validate() {
7049
if (!pkg.dependencies?.['@sentry/node']) {
7150
errors.push('package.json missing @sentry/node in dependencies')
7251
} else {
73-
logger.log(success('@sentry/node is in dependencies'))
52+
logger.success('@sentry/node is in dependencies')
7453
}
7554

7655
// Validate files array.
@@ -88,68 +67,68 @@ async function validate() {
8867
}
8968
}
9069
if (errors.length === 0) {
91-
logger.log(success('package.json files array is correct'))
70+
logger.success('package.json files array is correct')
9271
}
9372
}
9473

9574
// Check root files exist (LICENSE, CHANGELOG.md).
9675
const rootFiles = ['LICENSE', 'CHANGELOG.md']
9776
for (const file of rootFiles) {
98-
logger.log(info(`Checking ${file}...`))
77+
logger.info(`Checking ${file}...`)
9978
const filePath = path.join(packageRoot, file)
10079
if (!(await fileExists(filePath))) {
10180
errors.push(`${file} does not exist`)
10281
} else {
103-
logger.log(success(`${file} exists`))
82+
logger.success(`${file} exists`)
10483
}
10584
}
10685

10786
// Check dist files exist and validate Sentry integration.
10887
const distFiles = ['index.js', 'cli.js.bz', 'shadow-npm-inject.js']
10988
for (const file of distFiles) {
110-
logger.log(info(`Checking dist/${file}...`))
89+
logger.info(`Checking dist/${file}...`)
11190
const filePath = path.join(packageRoot, 'dist', file)
11291
if (!(await fileExists(filePath))) {
11392
errors.push(`dist/${file} does not exist`)
11493
} else {
115-
logger.log(success(`dist/${file} exists`))
94+
logger.success(`dist/${file} exists`)
11695
}
11796
}
11897

11998
// Verify Sentry is referenced in the build (check for @sentry/node require).
120-
logger.log(info('Checking for Sentry integration in build...'))
99+
logger.info('Checking for Sentry integration in build...')
121100
const buildPath = path.join(packageRoot, 'build', 'cli.js')
122101
if (await fileExists(buildPath)) {
123102
const buildContent = await fs.readFile(buildPath, 'utf-8')
124103
if (!buildContent.includes('@sentry/node')) {
125104
errors.push('Sentry integration not found in build/cli.js')
126105
} else {
127-
logger.log(success('Sentry integration found in build'))
106+
logger.success('Sentry integration found in build')
128107
}
129108
} else {
130109
errors.push('build/cli.js does not exist (required for Sentry validation)')
131110
}
132111

133112
// Check data directory exists.
134-
logger.log(info('Checking data directory...'))
113+
logger.info('Checking data directory...')
135114
const dataPath = path.join(packageRoot, 'data')
136115
if (!(await fileExists(dataPath))) {
137116
errors.push('data directory does not exist')
138117
} else {
139-
logger.log(success('data directory exists'))
118+
logger.success('data directory exists')
140119

141120
// Check data files.
142121
const dataFiles = [
143122
'alert-translations.json',
144123
'command-api-requirements.json',
145124
]
146125
for (const file of dataFiles) {
147-
logger.log(info(`Checking data/${file}...`))
126+
logger.info(`Checking data/${file}...`)
148127
const filePath = path.join(dataPath, file)
149128
if (!(await fileExists(filePath))) {
150129
errors.push(`data/${file} does not exist`)
151130
} else {
152-
logger.log(success(`data/${file} exists`))
131+
logger.success(`data/${file} exists`)
153132
}
154133
}
155134
}
@@ -164,23 +143,23 @@ async function validate() {
164143
if (errors.length > 0) {
165144
logger.log(`${colors.red('Errors:')}`)
166145
for (const err of errors) {
167-
logger.log(` ${error(err)}`)
146+
logger.fail(` ${err}`)
168147
}
169148
logger.log('')
170-
logger.log(error('Package validation FAILED'))
149+
logger.fail('Package validation FAILED')
171150
logger.log('')
172151
process.exit(1)
173152
}
174153

175-
logger.log(success('Package validation PASSED'))
154+
logger.success('Package validation PASSED')
176155
logger.log('')
177156
process.exit(0)
178157
}
179158

180159
// Run validation.
181160
validate().catch(e => {
182161
logger.error('')
183-
logger.error(error(`Unexpected error: ${e.message}`))
162+
logger.fail(`Unexpected error: ${e.message}`)
184163
logger.error('')
185164
process.exit(1)
186165
})

0 commit comments

Comments
 (0)