Skip to content

Commit 4fb48b1

Browse files
committed
Nudge folks to file an issue for some errors
1 parent cbd797f commit 4fb48b1

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

src/commands/optimize.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import { escapeRegExp } from '@socketsecurity/registry/lib/regexps'
2525
import { isNonEmptyString } from '@socketsecurity/registry/lib/strings'
2626
import { pluralize } from '@socketsecurity/registry/lib/words'
2727

28-
import { distPath } from '../constants'
28+
import {
29+
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE,
30+
distPath
31+
} from '../constants'
2932
import { commonFlags } from '../flags'
3033
import { printFlagList } from '../utils/formatting'
3134
import { existsSync } from '../utils/fs'
@@ -44,6 +47,7 @@ type PackageJson = Awaited<ReturnType<typeof readPackageJson>>
4447

4548
const COMMAND_TITLE = 'Socket Optimize'
4649
const OVERRIDES_FIELD_NAME = 'overrides'
50+
const NPM_OVERRIDE_PR_URL = 'https://github.com/npm/cli/pull/7025'
4751
const PNPM_FIELD_NAME = 'pnpm'
4852
const PNPM_WORKSPACE = 'pnpm-workspace'
4953
const RESOLUTIONS_FIELD_NAME = 'resolutions'
@@ -898,7 +902,7 @@ export const optimize: CliSubcommand = {
898902
stdio: 'ignore',
899903
env: {
900904
...process.env,
901-
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: '1'
905+
[UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE]: '1'
902906
}
903907
}
904908
)
@@ -909,7 +913,7 @@ export const optimize: CliSubcommand = {
909913
spinner.stop()
910914
if (isNpm) {
911915
console.log(
912-
`💡 Re-run ${COMMAND_TITLE} whenever ${lockName} changes.\n This can be skipped once npm ships https://github.com/npm/cli/pull/7025.`
916+
`💡 Re-run ${COMMAND_TITLE} whenever ${lockName} changes.\n This can be skipped once npm ships ${NPM_OVERRIDE_PR_URL}.`
913917
)
914918
}
915919
} catch {

src/constants.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,23 @@ export const API_V0_URL = 'https://api.socket.dev/v0'
1616

1717
export const DIST_TYPE = SUPPORTS_SYNC_ESM ? 'module-sync' : 'require'
1818

19+
export const LOOP_SENTINEL = 1_000_000
20+
21+
export const NPM_REGISTRY_URL = 'https://registry.npmjs.org'
22+
23+
export const SOCKET_CLI_ISSUES_URL =
24+
'https://github.com/SocketDev/socket-cli/issues'
25+
26+
export const UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE =
27+
'UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE'
28+
1929
export const ENV = Object.freeze({
2030
// Flag set by the optimize command to bypass the packagesHaveRiskyIssues check.
21-
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: envAsBoolean(
22-
process.env['UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE']
31+
[UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE]: envAsBoolean(
32+
process.env[UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE]
2333
)
2434
})
2535

26-
export const LOOP_SENTINEL = 1_000_000
27-
28-
export const NPM_REGISTRY_URL = 'https://registry.npmjs.org'
29-
3036
// Dynamically detect the rootPath so constants.ts can be used in tests.
3137
export const rootPath = (() => {
3238
let oldPath
@@ -50,7 +56,9 @@ export const rootPath = (() => {
5056
oldPath = currPath
5157
currPath = path.dirname(currPath)
5258
}
53-
throw new TypeError('rootPath cannot be resolved.')
59+
throw new TypeError(
60+
`Socket CLI initialization error: rootPath cannot be resolved.\n\nPlease report to ${SOCKET_CLI_ISSUES_URL}.`
61+
)
5462
})()
5563
export const rootDistPath = path.join(rootPath, 'dist')
5664
export const rootBinPath = path.join(rootPath, 'bin')

src/shadow/arborist.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
ENV,
2121
LOOP_SENTINEL,
2222
NPM_REGISTRY_URL,
23+
SOCKET_CLI_ISSUES_URL,
24+
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE,
2325
rootPath
2426
} from '../constants'
2527
import { ColorOrMarkdown } from '../utils/color-or-markdown'
@@ -155,8 +157,7 @@ type RequireTransformer<T extends keyof KnownModules> = (
155157
mod: KnownModules[T]
156158
) => KnownModules[T]
157159

158-
const POTENTIALLY_BUG_ERROR_SNIPPET =
159-
'this is potentially a bug with socket-npm caused by changes to the npm cli'
160+
const POTENTIAL_BUG_ERROR_MESSAGE = `This is may be a bug with socket-npm related to changes to the npm CLI.\nPlease report to ${SOCKET_CLI_ISSUES_URL}.`
160161

161162
const npmEntrypoint = realpathSync(process.argv[1]!)
162163
const npmRootPath = findRoot(path.dirname(npmEntrypoint))
@@ -188,9 +189,8 @@ function tryRequire<T extends keyof KnownModules>(
188189

189190
if (npmRootPath === undefined) {
190191
console.error(
191-
`Unable to find npm cli install directory, ${POTENTIALLY_BUG_ERROR_SNIPPET}.`
192+
`Unable to find npm CLI install directory.\nSearched parent directories of ${npmEntrypoint}.\n\n${POTENTIAL_BUG_ERROR_MESSAGE}`
192193
)
193-
console.error(`Searched parent directories of ${npmEntrypoint}`)
194194
process.exit(127)
195195
}
196196

@@ -218,7 +218,7 @@ const log = tryRequire(
218218

219219
if (log === undefined) {
220220
console.error(
221-
`Unable to integrate with npm cli logging infrastructure, ${POTENTIALLY_BUG_ERROR_SNIPPET}.`
221+
`Unable to integrate with npm CLI logging infrastructure.\n\n${POTENTIAL_BUG_ERROR_MESSAGE}.`
222222
)
223223
process.exit(127)
224224
}
@@ -1299,7 +1299,7 @@ export class SafeArborist extends Arborist {
12991299
if (diff.findIndex(c => c.repository_url === NPM_REGISTRY_URL) === -1) {
13001300
return await this[kRiskyReify](...args)
13011301
}
1302-
let proceed = ENV.UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE
1302+
let proceed = ENV[UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE]
13031303
if (!proceed) {
13041304
proceed = await ttyServer.captureTTY(async (input, output) => {
13051305
if (input && output) {

0 commit comments

Comments
 (0)