Skip to content

Commit e32cfcf

Browse files
committed
Replace process.exit() with error throwing in binary path utilities
1 parent 66d61a5 commit e32cfcf

Some content is hidden

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

47 files changed

+904
-821
lines changed

.config/rollup.dist.config.mjs

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
// import assert from 'node:assert'
21
import { promises as fs } from 'node:fs'
32
import os from 'node:os'
43
import path from 'node:path'
5-
// import util from 'node:util'
64

5+
import { deleteAsync } from 'del'
76
import fastGlob from 'fast-glob'
8-
import trash from 'trash'
97

108
import { isDirEmptySync } from '@socketsecurity/registry/lib/fs'
119
// import { hasKeys } from '@socketsecurity/registry/lib/objects'
@@ -241,7 +239,7 @@ async function copyPublishFiles() {
241239
}
242240

243241
async function removeEmptyDirs(thePath) {
244-
await trash(
242+
await deleteAsync(
245243
(
246244
await fastGlob.glob(['**/'], {
247245
ignore: [NODE_MODULES_GLOB_RECURSIVE],
@@ -258,66 +256,19 @@ async function removeEmptyDirs(thePath) {
258256

259257
async function removeFiles(thePath, options) {
260258
const { exclude } = { __proto__: null, ...options }
261-
const ignore = Array.isArray(exclude) ? exclude : exclude ? [exclude] : []
262-
return await trash(
259+
return await deleteAsync(
263260
await fastGlob.glob(['**/*'], {
264261
absolute: true,
265262
onlyFiles: true,
266263
cwd: thePath,
267264
dot: true,
268-
ignore,
265+
ignore: Array.isArray(exclude)
266+
? exclude
267+
: (exclude ? [exclude] : []),
269268
}),
270269
)
271270
}
272271

273-
// function resetBin(bin) {
274-
// const tmpBin = {
275-
// [SOCKET_CLI_BIN_NAME]:
276-
// bin?.[SOCKET_CLI_BIN_NAME] ?? bin?.[SOCKET_CLI_SENTRY_BIN_NAME],
277-
// [SOCKET_CLI_NPM_BIN_NAME]:
278-
// bin?.[SOCKET_CLI_NPM_BIN_NAME] ?? bin?.[SOCKET_CLI_SENTRY_NPM_BIN_NAME],
279-
// [SOCKET_CLI_NPX_BIN_NAME]:
280-
// bin?.[SOCKET_CLI_NPX_BIN_NAME] ?? bin?.[SOCKET_CLI_SENTRY_NPX_BIN_NAME],
281-
// [SOCKET_CLI_PNPM_BIN_NAME]:
282-
// bin?.[SOCKET_CLI_PNPM_BIN_NAME] ?? bin?.[SOCKET_CLI_SENTRY_PNPM_BIN_NAME],
283-
// [SOCKET_CLI_YARN_BIN_NAME]:
284-
// bin?.[SOCKET_CLI_YARN_BIN_NAME] ?? bin?.[SOCKET_CLI_SENTRY_YARN_BIN_NAME],
285-
// }
286-
// const newBin = {
287-
// ...(tmpBin[SOCKET_CLI_BIN_NAME]
288-
// ? { [SOCKET_CLI_BIN_NAME]: tmpBin.socket }
289-
// : {}),
290-
// ...(tmpBin[SOCKET_CLI_NPM_BIN_NAME]
291-
// ? { [SOCKET_CLI_NPM_BIN_NAME]: tmpBin[SOCKET_CLI_NPM_BIN_NAME] }
292-
// : {}),
293-
// ...(tmpBin[SOCKET_CLI_NPX_BIN_NAME]
294-
// ? { [SOCKET_CLI_NPX_BIN_NAME]: tmpBin[SOCKET_CLI_NPX_BIN_NAME] }
295-
// : {}),
296-
// ...(tmpBin[SOCKET_CLI_PNPM_BIN_NAME]
297-
// ? { [SOCKET_CLI_PNPM_BIN_NAME]: tmpBin[SOCKET_CLI_PNPM_BIN_NAME] }
298-
// : {}),
299-
// ...(tmpBin[SOCKET_CLI_YARN_BIN_NAME]
300-
// ? { [SOCKET_CLI_YARN_BIN_NAME]: tmpBin[SOCKET_CLI_YARN_BIN_NAME] }
301-
// : {}),
302-
// }
303-
// assert(
304-
// util.isDeepStrictEqual(Object.keys(newBin).sort(naturalCompare), [
305-
// SOCKET_CLI_BIN_NAME,
306-
// SOCKET_CLI_NPM_BIN_NAME,
307-
// SOCKET_CLI_NPX_BIN_NAME,
308-
// SOCKET_CLI_PNPM_BIN_NAME,
309-
// SOCKET_CLI_YARN_BIN_NAME,
310-
// ]),
311-
// "Update the rollup Legacy and Sentry build's .bin to match the default build.",
312-
// )
313-
// return newBin
314-
// }
315-
316-
// function resetDependencies(deps) {
317-
// const { [SENTRY_NODE]: _ignored, ...newDeps } = { ...deps }
318-
// return newDeps
319-
// }
320-
321272
export default async () => {
322273
const { distPath, rootPath, srcPath } = constants
323274
const constantsSrcPath = normalizePath(path.join(srcPath, 'constants.mts'))

package.json

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,14 @@
3636
"build": "node scripts/build.mjs",
3737
"publish:sea": "node scripts/publish-sea.mjs",
3838
"check": "node scripts/check.mjs",
39-
"check:lint": "node scripts/lint-affected.mjs --all",
40-
"check:tsc": "tsgo --noEmit",
41-
"check-ci": "pnpm run check:lint",
39+
"check-ci": "pnpm run check",
4240
"lint": "node scripts/lint.mjs",
43-
"lint-ci": "pnpm run check:lint",
44-
"type-ci": "pnpm run check:tsc",
41+
"lint-ci": "pnpm run check --lint",
42+
"type-ci": "pnpm run check --type",
4543
"cover": "node scripts/cover.mjs",
4644
"clean": "node scripts/clean.mjs",
47-
"fix": "node scripts/lint.mjs --fix",
48-
"lint-staged": "lint-staged",
49-
"precommit": "lint-staged",
45+
"fix": "pnpm run lint --fix",
46+
"precommit": "pnpm run lint --staged",
5047
"prepare": "husky",
5148
"bs": "pnpm run build --src; pnpm exec socket --",
5249
"s": "pnpm exec socket --",
@@ -119,6 +116,7 @@
119116
"browserslist": "4.25.4",
120117
"chalk-table": "1.0.2",
121118
"cmd-shim": "7.0.0",
119+
"del": "8.0.1",
122120
"del-cli": "6.0.0",
123121
"dev-null-cli": "2.0.0",
124122
"esbuild": "0.25.10",
@@ -183,12 +181,11 @@
183181
"requirements.json",
184182
"translations.json"
185183
],
186-
"lint-staged": {
187-
"*.{cjs,cts,js,json,md,mjs,mts,ts}": [
188-
"biome format --log-level=none --fix --no-errors-on-unmatched --files-ignore-unknown=true --colors=off"
189-
]
190-
},
191184
"pnpm": {
185+
"ignoredBuiltDependencies": [
186+
"esbuild",
187+
"unrs-resolver"
188+
],
192189
"overrides": {
193190
"@octokit/graphql": "$@octokit/graphql",
194191
"@octokit/request-error": "$@octokit/request-error",
@@ -254,8 +251,5 @@
254251
"ignore-type-assertion": true,
255252
"ignore-files": "test/*",
256253
"strict": true
257-
},
258-
"dependencies": {
259-
"lodash": "4.17.21"
260254
}
261255
}

pnpm-lock.yaml

Lines changed: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/build.mjs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,38 @@
55

66
import { existsSync } from 'node:fs'
77
import path from 'node:path'
8+
import { fileURLToPath } from 'node:url'
89
import { parseArgs } from 'node:util'
910

10-
import {
11-
getRootPath,
12-
isQuiet,
13-
log,
14-
printFooter,
15-
printHeader,
16-
printHelpHeader
17-
} from './utils/common.mjs'
11+
import colors from 'yoctocolors-cjs'
12+
13+
import { printDivider, printFooter, printHeader, printHelpHeader } from './print.mjs'
1814
import { runCommand, runSequence } from './utils/run-command.mjs'
1915

20-
const rootPath = getRootPath(import.meta.url)
16+
// Simple inline logger.
17+
const log = {
18+
info: msg => console.log(msg),
19+
error: msg => console.error(`${colors.red('✗')} ${msg}`),
20+
success: msg => console.log(`${colors.green('✓')} ${msg}`),
21+
step: msg => console.log(`\n${msg}`),
22+
substep: msg => console.log(` ${msg}`),
23+
progress: msg => process.stdout.write(` ∴ ${msg}`),
24+
done: msg => {
25+
process.stdout.write('\r\x1b[K')
26+
console.log(` ${colors.green('✓')} ${msg}`)
27+
},
28+
failed: msg => {
29+
process.stdout.write('\r\x1b[K')
30+
console.log(` ${colors.red('✗')} ${msg}`)
31+
}
32+
}
33+
34+
// Inline utilities.
35+
const isQuiet = values => values.quiet || values.silent
36+
37+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
38+
39+
const rootPath = path.join(__dirname, '..')
2140

2241
/**
2342
* Build source code with Rollup.

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,26 @@ import { copyFile, mkdir, readFile, writeFile } from 'node:fs/promises'
1010
import { dirname, join } from 'node:path'
1111
import { fileURLToPath } from 'node:url'
1212

13-
import { getRootPath, log, printFooter, printHeader } from '../utils/common.mjs'
13+
import colors from 'yoctocolors-cjs'
14+
15+
import { printFooter, printHeader } from '../print.mjs'
1416
import { runCommand, runSequence } from '../utils/run-command.mjs'
1517

18+
// Simple logger
19+
const log = {
20+
progress: msg => process.stdout.write(` ∴ ${msg}`),
21+
done: msg => {
22+
process.stdout.write('\r\x1b[K')
23+
console.log(` ${colors.green('✓')} ${msg}`)
24+
},
25+
failed: msg => {
26+
process.stdout.write('\r\x1b[K')
27+
console.log(` ${colors.red('✗')} ${msg}`)
28+
},
29+
error: msg => console.error(`${colors.red('✗')} ${msg}`),
30+
step: msg => console.log(`\n${msg}`)
31+
}
32+
1633
const __filename = fileURLToPath(import.meta.url)
1734
const __dirname = dirname(__filename)
1835
const ROOT_DIR = join(__dirname, '../..')

scripts/build/build-socket-package.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,26 @@ import { existsSync } from 'node:fs'
99
import { dirname, join } from 'node:path'
1010
import { fileURLToPath } from 'node:url'
1111

12-
import { getRootPath, log, printFooter, printHeader } from '../utils/common.mjs'
12+
import colors from 'yoctocolors-cjs'
13+
14+
import { printFooter, printHeader } from '../print.mjs'
1315
import { runCommand, runSequence } from '../utils/run-command.mjs'
1416

17+
// Simple logger
18+
const log = {
19+
progress: msg => process.stdout.write(` ∴ ${msg}`),
20+
done: msg => {
21+
process.stdout.write('\r\x1b[K')
22+
console.log(` ${colors.green('✓')} ${msg}`)
23+
},
24+
failed: msg => {
25+
process.stdout.write('\r\x1b[K')
26+
console.log(` ${colors.red('✗')} ${msg}`)
27+
},
28+
error: msg => console.error(`${colors.red('✗')} ${msg}`),
29+
step: msg => console.log(`\n${msg}`)
30+
}
31+
1532
const __filename = fileURLToPath(import.meta.url)
1633
const __dirname = dirname(__filename)
1734
const ROOT_DIR = join(__dirname, '../..')

scripts/build/build-socketsecurity-cli.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,26 @@ import { copyFile, mkdir, readFile, rm, writeFile } from 'node:fs/promises'
1111
import { dirname, join } from 'node:path'
1212
import { fileURLToPath } from 'node:url'
1313

14-
import { getRootPath, log, printFooter, printHeader } from '../utils/common.mjs'
14+
import colors from 'yoctocolors-cjs'
15+
16+
import { printFooter, printHeader } from '../print.mjs'
1517
import { runCommand, runSequence } from '../utils/run-command.mjs'
1618

19+
// Simple logger
20+
const log = {
21+
progress: msg => process.stdout.write(` ∴ ${msg}`),
22+
done: msg => {
23+
process.stdout.write('\r\x1b[K')
24+
console.log(` ${colors.green('✓')} ${msg}`)
25+
},
26+
failed: msg => {
27+
process.stdout.write('\r\x1b[K')
28+
console.log(` ${colors.red('✗')} ${msg}`)
29+
},
30+
error: msg => console.error(`${colors.red('✗')} ${msg}`),
31+
step: msg => console.log(`\n${msg}`)
32+
}
33+
1734
const __filename = fileURLToPath(import.meta.url)
1835
const __dirname = dirname(__filename)
1936
const ROOT_DIR = join(__dirname, '../..')

0 commit comments

Comments
 (0)