Skip to content

Commit 8a56a67

Browse files
authored
refactor: apply lint formatting to scripts and hooks folders (#3669)
* refactor: rename script files to kebab-case convention Renames files from underscore to hyphen naming: - scripts/postrelease/install_scripts.js → install-scripts.js - scripts/utils/_version.js → version.js This aligns with the project's file naming standards. * refactor: apply lint formatting to scripts and hooks folders Applies ESLint formatting fixes to scripts and hooks folders: - Reorder imports to follow style guide (node: prefixed imports first, then external, then internal) - Use node: prefix for Node.js built-in modules (node:path, node:child_process, etc.) - Change from `import * as` to default imports where appropriate - Add proper error handling with try-catch blocks in postrelease scripts - Remove unnecessary semicolons and apply consistent formatting This brings the scripts and hooks folders in line with the shared ESLint configuration.
1 parent eb9b040 commit 8a56a67

17 files changed

Lines changed: 124 additions & 117 deletions
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env node
2+
3+
import execa from 'execa'
4+
import path from 'node:path'
5+
import {fileURLToPath} from 'node:url'
6+
import qq from 'qqjs'
7+
8+
import getHerokuS3Bucket from '../utils/get-heroku-s3-bucket.js'
9+
import isStableRelease from '../utils/is-stable-release.js'
10+
11+
const __filename = fileURLToPath(import.meta.url)
12+
const __dirname = path.dirname(__filename)
13+
14+
const opts = {
15+
cwd: path.join(__dirname, '..', '..'),
16+
stdio: 'inherit',
17+
}
18+
19+
qq.config.silent = false
20+
21+
try {
22+
await qq.run(async () => {
23+
const {GITHUB_REF_NAME, GITHUB_REF_TYPE} = process.env
24+
25+
if (isStableRelease(GITHUB_REF_TYPE, GITHUB_REF_NAME)) {
26+
const HEROKU_S3_BUCKET = await getHerokuS3Bucket()
27+
await execa.command(`aws s3 cp --content-type text/plain --cache-control max-age=604800 ./install-standalone.sh s3://${HEROKU_S3_BUCKET}/install-standalone.sh`, opts)
28+
await execa.command(`aws s3 cp --content-type text/plain --cache-control max-age=604800 ./install-standalone.sh s3://${HEROKU_S3_BUCKET}/install.sh`, opts)
29+
await execa.command(`aws s3 cp --content-type text/plain --cache-control max-age=604800 ./install-ubuntu.sh s3://${HEROKU_S3_BUCKET}/install-ubuntu.sh`, opts)
30+
} else {
31+
console.log('Not on stable release, skipping updating install scripts')
32+
// eslint-disable-next-line n/no-process-exit
33+
process.exit(0)
34+
}
35+
})
36+
} catch (error) {
37+
console.error(error)
38+
// eslint-disable-next-line n/no-process-exit
39+
process.exit(1)
40+
}

scripts/postrelease/install_scripts.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

scripts/release/homebrew.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
import fs from 'fs'
21
import execa from 'execa'
3-
import path from 'path'
4-
import { fileURLToPath } from 'url'
5-
import { rimrafSync } from 'rimraf'
6-
import { promisify } from 'util'
7-
import { pipeline } from 'stream'
8-
import crypto from 'crypto'
2+
import crypto from 'node:crypto'
3+
import fs from 'node:fs'
4+
import path from 'node:path'
5+
import {pipeline} from 'node:stream'
6+
import {fileURLToPath} from 'node:url'
7+
import {promisify} from 'node:util'
8+
import {rimrafSync} from 'rimraf'
9+
910
import getHerokuS3Bucket from '../utils/get-heroku-s3-bucket.js'
1011
import isStableRelease from '../utils/is-stable-release.js'
1112

1213
const __filename = fileURLToPath(import.meta.url)
1314
const __dirname = path.dirname(__filename)
1415

15-
const {GITHUB_SHA_SHORT, GITHUB_REF_TYPE, GITHUB_REF_NAME} = process.env
16-
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'package.json'), 'utf-8'))
16+
const {GITHUB_REF_NAME, GITHUB_REF_TYPE, GITHUB_SHA_SHORT} = process.env
17+
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'package.json'), 'utf8'))
1718
const VERSION = packageJson.version
1819

1920
if (!isStableRelease(GITHUB_REF_TYPE, GITHUB_REF_NAME)) {
2021
console.log('Not on stable release; skipping releasing homebrew')
22+
// eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
2123
process.exit(0)
2224
}
2325

@@ -44,7 +46,7 @@ function downloadFileFromS3(s3Path, fileName, downloadPath) {
4446

4547
async function updateHerokuFormula(brewDir) {
4648
const templatePath = path.join(TEMPLATES, 'heroku.rb')
47-
const template = fs.readFileSync(templatePath).toString('utf-8')
49+
const template = fs.readFileSync(templatePath).toString('utf8')
4850
const formulaPath = path.join(brewDir, 'Formula', 'heroku.rb')
4951

5052
const fileNamePrefix = `heroku-v${VERSION}-${GITHUB_SHA_SHORT}`
@@ -69,8 +71,8 @@ async function updateHerokuFormula(brewDir) {
6971
const sha256LinuxIntel = await calculateSHA256(path.join(__dirname, fileNameLinuxIntel))
7072
const sha256LinuxArm = await calculateSHA256(path.join(__dirname, fileNameLinuxArm))
7173

72-
const templateReplaced =
73-
template
74+
const templateReplaced
75+
= template
7476
.replace('__CLI_VERSION__', VERSION)
7577

7678
.replace('__CLI_MAC_INTEL_DOWNLOAD_URL__', `${urlPrefix}/${fileNameMacIntel}`)
@@ -106,7 +108,8 @@ async function updateHomebrew() {
106108
await setupGit()
107109

108110
console.log(`cloning https://github.com/heroku/homebrew-brew to ${homebrewDir}`)
109-
await execa('git',
111+
await execa(
112+
'git',
110113
[
111114
'clone',
112115
'git@github.com:heroku/homebrew-brew.git',
@@ -132,7 +135,10 @@ async function updateHomebrew() {
132135
}
133136
}
134137

135-
updateHomebrew().catch(error => {
138+
try {
139+
await updateHomebrew()
140+
} catch (error) {
136141
console.error('error running scripts/release/homebrew.js', error)
142+
// eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
137143
process.exit(1)
138-
})
144+
}

scripts/release/win

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

33
import qq from 'qqjs'
4-
import getVersion from '../utils/_version.js'
4+
import getVersion from '../utils/version.js'
55

66
qq.config.silent = false
77
qq.run(async () => {
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
import fs from 'fs'
2-
import { exec } from 'child_process'
1+
import {exec} from 'node:child_process'
2+
import fs from 'node:fs'
33

4-
fs.readdirSync('.')
4+
for (const c of fs.readdirSync('.')
55
.filter(f => f.startsWith('heroku-v') && f.endsWith('.exe'))
66
.flatMap(f =>
7-
[process.env.STAMPY_UNSIGNED_BUCKET, process.env.STAMPY_SIGNED_BUCKET].map(b => `aws s3 rm ${b}/${f}`),
8-
)
9-
.forEach(c => {
10-
exec(c, (error, stdout) => {
11-
if (error) {
12-
console.error(`exec error: ${error}`)
13-
return
14-
}
7+
[process.env.STAMPY_UNSIGNED_BUCKET, process.env.STAMPY_SIGNED_BUCKET].map(b => `aws s3 rm ${b}/${f}`))) {
8+
exec(c, (error, stdout) => {
9+
if (error) {
10+
console.error(`exec error: ${error}`)
11+
return
12+
}
1513

16-
console.log(stdout)
17-
})
14+
console.log(stdout)
1815
})
16+
}

scripts/stampy/upload-stampy-signed.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
import fs from 'fs'
2-
import { exec } from 'child_process'
1+
import {exec} from 'node:child_process'
2+
import fs from 'node:fs'
33

44
fs.readdirSync('.')
55
.filter(f => f.startsWith('heroku-v') && f.endsWith('.exe'))
66
.map(f => ({
7-
filename: f,
87
cli: f.split('-')[0],
8+
filename: f,
99
// do it from the end to account for the possibility of the version having a hyphen in it like 2.2.2-beta.0
1010
sha: f.split('-').at(-2),
1111
}))
1212
.map(f => ({...f, shaIndex: f.filename.split('-').indexOf(f.sha)}))
1313
// version is the part between the cli and the sha
1414
.map(f => ({...f, version: f.filename.split('-').slice(1, f.shaIndex).join('-').replace('v', '')}))
15-
.map(
16-
f =>
17-
`aws s3 cp ${f.filename} s3://heroku-cli-assets/versions/${f.version}/${f.sha}/${f.filename}`,
18-
)
15+
.map(f =>
16+
`aws s3 cp ${f.filename} s3://heroku-cli-assets/versions/${f.version}/${f.sha}/${f.filename}`)
1917
.map(f => {
2018
exec(f, (error, stdout) => {
2119
if (error) {

scripts/utils/_version.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

scripts/utils/get-heroku-s3-bucket.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import path from 'path'
2-
import { fileURLToPath } from 'url'
3-
import fs from 'fs'
1+
import fs from 'node:fs'
2+
import path from 'node:path'
3+
import {fileURLToPath} from 'node:url'
44

55
const __filename = fileURLToPath(import.meta.url)
66
const __dirname = path.dirname(__filename)
77

88
const getHerokuS3Bucket = async () => {
99
const packageJsonPath = path.join(__dirname, '..', '..', 'package.json')
10-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'))
10+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
1111
const bucket = packageJson.oclif?.update?.s3?.bucket
1212

1313
if (!bucket) {

scripts/utils/version.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import fs from 'node:fs'
2+
import path from 'node:path'
3+
import {fileURLToPath} from 'node:url'
4+
import qq from 'qqjs'
5+
6+
const __filename = fileURLToPath(import.meta.url)
7+
const __dirname = path.dirname(__filename)
8+
9+
export default async function getVersion() {
10+
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'package.json'), 'utf8'))
11+
let {version} = packageJson
12+
if (version.includes('-')) {
13+
const channel = version.split('-')[1].split('.')[0]
14+
const sha = await qq.x.stdout('git', ['rev-parse', '--short', 'HEAD'])
15+
version = `${version.split('-')[0]}-${channel}.${sha}`
16+
}
17+
18+
return version
19+
}

src/hooks/command_not_found/setup-otel-telemetry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Hook} from '@oclif/core/hooks'
22

33
const performance_analytics: Hook<'command_not_found'> = async function () {
4-
const {isTelemetryEnabled, getTelemetryDisabledReason, telemetryDebug} = await import('../../lib/analytics-telemetry/telemetry-utils.js')
4+
const {getTelemetryDisabledReason, isTelemetryEnabled, telemetryDebug} = await import('../../lib/analytics-telemetry/telemetry-utils.js')
55

66
// Use the consolidated telemetry check
77
if (!isTelemetryEnabled()) {
@@ -12,7 +12,7 @@ const performance_analytics: Hook<'command_not_found'> = async function () {
1212

1313
telemetryDebug('Telemetry enabled: command_not_found hook setting up telemetry for invalid command')
1414
const {telemetryManager} = await import('../../lib/analytics-telemetry/telemetry-manager.js')
15-
const globalAny = global as any
15+
const globalAny = globalThis as any
1616
globalAny.cliTelemetry = telemetryManager.reportCmdNotFound(this.config)
1717
}
1818

0 commit comments

Comments
 (0)