@socketsecurity/cli-with-sentry 0.15.11 → 0.15.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +6 -6
- package/dist/.config/tsconfig.dts.tsbuildinfo +1 -1
- package/dist/cli.js +5731 -6607
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +274 -305
- package/dist/constants.js.map +1 -1
- package/dist/instrument-with-sentry.js +28 -34
- package/dist/instrument-with-sentry.js.map +1 -1
- package/dist/shadow-bin.js +96 -123
- package/dist/shadow-bin.js.map +1 -1
- package/dist/shadow-inject.js +470 -580
- package/dist/shadow-inject.js.map +1 -1
- package/dist/socket-completion.bash +221 -0
- package/dist/types/cli.d.mts +2 -2
- package/dist/types/commands/analytics/cmd-analytics.d.mts +9 -15
- package/dist/types/commands/analytics/fetch-org-analytics.d.mts +4 -6
- package/dist/types/commands/analytics/fetch-repo-analytics.d.mts +4 -7
- package/dist/types/commands/analytics/handle-analytics.d.mts +9 -15
- package/dist/types/commands/analytics/handle-analytics.d.mts.map +1 -1
- package/dist/types/commands/analytics/output-analytics.d.mts +26 -46
- package/dist/types/commands/analytics/output-analytics.d.mts.map +1 -1
- package/dist/types/commands/audit-log/cmd-audit-log.d.mts +9 -15
- package/dist/types/commands/audit-log/fetch-audit-log.d.mts +10 -16
- package/dist/types/commands/audit-log/fetch-audit-log.d.mts.map +1 -1
- package/dist/types/commands/audit-log/handle-audit-log.d.mts +9 -15
- package/dist/types/commands/audit-log/handle-audit-log.d.mts.map +1 -1
- package/dist/types/commands/audit-log/output-audit-log.d.mts +22 -47
- package/dist/types/commands/audit-log/output-audit-log.d.mts.map +1 -1
- package/dist/types/commands/cdxgen/cmd-cdxgen.d.mts +9 -15
- package/dist/types/commands/cdxgen/cmd-cdxgen.d.mts.map +1 -1
- package/dist/types/commands/cdxgen/handle-cdxgen.d.mts +4 -0
- package/dist/types/commands/cdxgen/handle-cdxgen.d.mts.map +1 -0
- package/dist/types/commands/ci/cmd-ci.d.mts +9 -15
- package/dist/types/commands/ci/fetch-default-org-slug.d.mts +3 -3
- package/dist/types/commands/ci/handle-ci.d.mts +2 -2
- package/dist/types/commands/config/cmd-config-auto.d.mts +9 -15
- package/dist/types/commands/config/cmd-config-get.d.mts +9 -15
- package/dist/types/commands/config/cmd-config-list.d.mts +9 -15
- package/dist/types/commands/config/cmd-config-set.d.mts +9 -15
- package/dist/types/commands/config/cmd-config-unset.d.mts +9 -15
- package/dist/types/commands/config/cmd-config.d.mts +3 -3
- package/dist/types/commands/config/discover-config-value.d.mts +3 -5
- package/dist/types/commands/config/discover-config-value.d.mts.map +1 -1
- package/dist/types/commands/config/handle-config-auto.d.mts +7 -10
- package/dist/types/commands/config/handle-config-auto.d.mts.map +1 -1
- package/dist/types/commands/config/handle-config-get.d.mts +7 -10
- package/dist/types/commands/config/handle-config-get.d.mts.map +1 -1
- package/dist/types/commands/config/handle-config-set.d.mts +8 -12
- package/dist/types/commands/config/handle-config-set.d.mts.map +1 -1
- package/dist/types/commands/config/handle-config-unset.d.mts +7 -10
- package/dist/types/commands/config/handle-config-unset.d.mts.map +1 -1
- package/dist/types/commands/config/output-config-auto.d.mts +4 -8
- package/dist/types/commands/config/output-config-get.d.mts +4 -8
- package/dist/types/commands/config/output-config-list.d.mts +6 -9
- package/dist/types/commands/config/output-config-list.d.mts.map +1 -1
- package/dist/types/commands/config/output-config-set.d.mts +3 -6
- package/dist/types/commands/config/output-config-unset.d.mts +3 -6
- package/dist/types/commands/dependencies/cmd-dependencies.d.mts +9 -15
- package/dist/types/commands/dependencies/fetch-dependencies.d.mts +7 -10
- package/dist/types/commands/dependencies/fetch-dependencies.d.mts.map +1 -1
- package/dist/types/commands/dependencies/handle-dependencies.d.mts +7 -11
- package/dist/types/commands/dependencies/handle-dependencies.d.mts.map +1 -1
- package/dist/types/commands/dependencies/output-dependencies.d.mts +8 -15
- package/dist/types/commands/dependencies/output-dependencies.d.mts.map +1 -1
- package/dist/types/commands/diff-scan/cmd-diff-scan-get.d.mts +9 -15
- package/dist/types/commands/diff-scan/cmd-diff-scan.d.mts +3 -3
- package/dist/types/commands/diff-scan/fetch-diff-scan.d.mts +8 -12
- package/dist/types/commands/diff-scan/fetch-diff-scan.d.mts.map +1 -1
- package/dist/types/commands/diff-scan/handle-diff-scan.d.mts +10 -17
- package/dist/types/commands/diff-scan/handle-diff-scan.d.mts.map +1 -1
- package/dist/types/commands/diff-scan/output-diff-scan.d.mts +8 -15
- package/dist/types/commands/diff-scan/output-diff-scan.d.mts.map +1 -1
- package/dist/types/commands/fix/cmd-fix.d.mts +9 -15
- package/dist/types/commands/fix/git.d.mts +14 -49
- package/dist/types/commands/fix/npm-fix.d.mts +4 -16
- package/dist/types/commands/fix/npm-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/open-pr.d.mts +20 -46
- package/dist/types/commands/fix/open-pr.d.mts.map +1 -1
- package/dist/types/commands/fix/pnpm-fix.d.mts +4 -16
- package/dist/types/commands/fix/pnpm-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/run-fix.d.mts +3 -3
- package/dist/types/commands/fix/shared.d.mts +9 -15
- package/dist/types/commands/fix/types.d.mts +16 -16
- package/dist/types/commands/info/cmd-info.d.mts +9 -15
- package/dist/types/commands/info/fetch-package-info.d.mts +3 -7
- package/dist/types/commands/info/handle-package-info.d.mts +15 -22
- package/dist/types/commands/info/handle-package-info.d.mts.map +1 -1
- package/dist/types/commands/info/output-package-info.d.mts +10 -18
- package/dist/types/commands/info/output-package-info.d.mts.map +1 -1
- package/dist/types/commands/install/cmd-install-completion.d.mts +10 -0
- package/dist/types/commands/install/cmd-install-completion.d.mts.map +1 -0
- package/dist/types/commands/install/cmd-install.d.mts +3 -0
- package/dist/types/commands/install/cmd-install.d.mts.map +1 -0
- package/dist/types/commands/install/handle-install-completion.d.mts +2 -0
- package/dist/types/commands/install/handle-install-completion.d.mts.map +1 -0
- package/dist/types/commands/install/output-install-completion.d.mts +12 -0
- package/dist/types/commands/install/output-install-completion.d.mts.map +1 -0
- package/dist/types/commands/install/setup-tab-completion.d.mts +13 -0
- package/dist/types/commands/install/setup-tab-completion.d.mts.map +1 -0
- package/dist/types/commands/login/apply-login.d.mts +2 -7
- package/dist/types/commands/login/attempt-login.d.mts +2 -5
- package/dist/types/commands/login/attempt-login.d.mts.map +1 -1
- package/dist/types/commands/login/cmd-login.d.mts +9 -15
- package/dist/types/commands/logout/apply-logout.d.mts +2 -2
- package/dist/types/commands/logout/attempt-logout.d.mts +2 -2
- package/dist/types/commands/logout/cmd-logout.d.mts +9 -15
- package/dist/types/commands/manifest/cmd-manifest-auto.d.mts +9 -15
- package/dist/types/commands/manifest/cmd-manifest-cdxgen.d.mts +10 -0
- package/dist/types/commands/manifest/cmd-manifest-cdxgen.d.mts.map +1 -0
- package/dist/types/commands/manifest/cmd-manifest-conda.d.mts +9 -15
- package/dist/types/commands/manifest/cmd-manifest-gradle.d.mts +9 -15
- package/dist/types/commands/manifest/cmd-manifest-kotlin.d.mts +9 -15
- package/dist/types/commands/manifest/cmd-manifest-scala.d.mts +9 -15
- package/dist/types/commands/manifest/cmd-manifest.d.mts +9 -15
- package/dist/types/commands/manifest/cmd-manifest.d.mts.map +1 -1
- package/dist/types/commands/manifest/convert-conda-to-requirements.d.mts +7 -15
- package/dist/types/commands/manifest/convert_gradle_to_maven.d.mts +2 -8
- package/dist/types/commands/manifest/convert_sbt_to_maven.d.mts +2 -8
- package/dist/types/commands/manifest/handle-manifest-conda.d.mts +3 -9
- package/dist/types/commands/manifest/output-requirements.d.mts +6 -10
- package/dist/types/commands/{cdxgen → manifest}/run-cdxgen.d.mts +2 -2
- package/dist/types/commands/manifest/run-cdxgen.d.mts.map +1 -0
- package/dist/types/commands/npm/cmd-npm.d.mts +9 -15
- package/dist/types/commands/npx/cmd-npx.d.mts +9 -15
- package/dist/types/commands/oops/cmd-oops.d.mts +9 -15
- package/dist/types/commands/optimize/add-overrides.d.mts +18 -22
- package/dist/types/commands/optimize/apply-optimization.d.mts +2 -6
- package/dist/types/commands/optimize/cmd-optimize.d.mts +9 -15
- package/dist/types/commands/optimize/deps-includes-by-agent.d.mts +4 -7
- package/dist/types/commands/optimize/get-dependency-entries.d.mts +3 -5
- package/dist/types/commands/optimize/get-overrides-by-agent.d.mts +8 -11
- package/dist/types/commands/optimize/lockfile-includes-by-agent.d.mts +3 -10
- package/dist/types/commands/optimize/ls-by-agent.d.mts +6 -13
- package/dist/types/commands/optimize/shared.d.mts +2 -2
- package/dist/types/commands/optimize/types.d.mts +7 -7
- package/dist/types/commands/optimize/update-lockfile.d.mts +9 -12
- package/dist/types/commands/optimize/update-manifest-by-agent.d.mts +5 -11
- package/dist/types/commands/organization/cmd-organization-list.d.mts +9 -15
- package/dist/types/commands/organization/cmd-organization-policy-license.d.mts +9 -15
- package/dist/types/commands/organization/cmd-organization-policy-security.d.mts +9 -15
- package/dist/types/commands/organization/cmd-organization-policy.d.mts +3 -3
- package/dist/types/commands/organization/cmd-organization-quota.d.mts +9 -15
- package/dist/types/commands/organization/cmd-organization.d.mts +3 -3
- package/dist/types/commands/organization/fetch-license-policy.d.mts +4 -6
- package/dist/types/commands/organization/fetch-organization-list.d.mts +4 -6
- package/dist/types/commands/organization/fetch-quota.d.mts +4 -6
- package/dist/types/commands/organization/fetch-security-policy.d.mts +4 -6
- package/dist/types/commands/organization/handle-license-policy.d.mts +3 -6
- package/dist/types/commands/organization/handle-organization-list.d.mts +3 -5
- package/dist/types/commands/organization/handle-quota.d.mts +3 -3
- package/dist/types/commands/organization/handle-security-policy.d.mts +3 -6
- package/dist/types/commands/organization/output-license-policy.d.mts +4 -7
- package/dist/types/commands/organization/output-organization-list.d.mts +4 -7
- package/dist/types/commands/organization/output-quota.d.mts +4 -7
- package/dist/types/commands/organization/output-security-policy.d.mts +4 -7
- package/dist/types/commands/package/cmd-package-score.d.mts +9 -15
- package/dist/types/commands/package/cmd-package-shallow.d.mts +16 -22
- package/dist/types/commands/package/cmd-package.d.mts +3 -3
- package/dist/types/commands/package/fetch-purl-deep-score.d.mts +49 -51
- package/dist/types/commands/package/fetch-purls-shallow-score.d.mts +4 -6
- package/dist/types/commands/package/handle-purl-deep-score.d.mts +3 -6
- package/dist/types/commands/package/handle-purls-shallow-score.d.mts +6 -9
- package/dist/types/commands/package/handle-purls-shallow-score.d.mts.map +1 -1
- package/dist/types/commands/package/output-purl-score.d.mts +4 -8
- package/dist/types/commands/package/output-purls-shallow-score.d.mts +4 -8
- package/dist/types/commands/package/parse-package-specifiers.d.mts +5 -8
- package/dist/types/commands/raw-npm/cmd-raw-npm.d.mts +9 -15
- package/dist/types/commands/raw-npm/run-raw-npm.d.mts +2 -4
- package/dist/types/commands/raw-npx/cmd-raw-npx.d.mts +9 -15
- package/dist/types/commands/raw-npx/run-raw-npx.d.mts +2 -4
- package/dist/types/commands/report/cmd-report-create.d.mts +9 -15
- package/dist/types/commands/report/cmd-report-view.d.mts +9 -15
- package/dist/types/commands/report/cmd-report.d.mts +3 -3
- package/dist/types/commands/repos/cmd-repos-create.d.mts +9 -15
- package/dist/types/commands/repos/cmd-repos-del.d.mts +9 -15
- package/dist/types/commands/repos/cmd-repos-list.d.mts +9 -15
- package/dist/types/commands/repos/cmd-repos-update.d.mts +9 -15
- package/dist/types/commands/repos/cmd-repos-view.d.mts +9 -15
- package/dist/types/commands/repos/cmd-repos.d.mts +3 -3
- package/dist/types/commands/repos/fetch-create-repo.d.mts +11 -18
- package/dist/types/commands/repos/fetch-create-repo.d.mts.map +1 -1
- package/dist/types/commands/repos/fetch-delete-repo.d.mts +4 -7
- package/dist/types/commands/repos/fetch-list-repos.d.mts +10 -16
- package/dist/types/commands/repos/fetch-list-repos.d.mts.map +1 -1
- package/dist/types/commands/repos/fetch-update-repo.d.mts +11 -18
- package/dist/types/commands/repos/fetch-update-repo.d.mts.map +1 -1
- package/dist/types/commands/repos/fetch-view-repo.d.mts +4 -7
- package/dist/types/commands/repos/handle-create-repo.d.mts +10 -20
- package/dist/types/commands/repos/handle-create-repo.d.mts.map +1 -1
- package/dist/types/commands/repos/handle-delete-repo.d.mts +3 -7
- package/dist/types/commands/repos/handle-list-repos.d.mts +10 -17
- package/dist/types/commands/repos/handle-list-repos.d.mts.map +1 -1
- package/dist/types/commands/repos/handle-update-repo.d.mts +10 -20
- package/dist/types/commands/repos/handle-update-repo.d.mts.map +1 -1
- package/dist/types/commands/repos/handle-view-repo.d.mts +3 -7
- package/dist/types/commands/repos/output-create-repo.d.mts +4 -8
- package/dist/types/commands/repos/output-delete-repo.d.mts +4 -8
- package/dist/types/commands/repos/output-list-repos.d.mts +4 -7
- package/dist/types/commands/repos/output-update-repo.d.mts +4 -8
- package/dist/types/commands/repos/output-view-repo.d.mts +4 -7
- package/dist/types/commands/scan/cmd-scan-create.d.mts +9 -15
- package/dist/types/commands/scan/cmd-scan-del.d.mts +9 -15
- package/dist/types/commands/scan/cmd-scan-diff.d.mts +9 -15
- package/dist/types/commands/scan/cmd-scan-list.d.mts +3 -3
- package/dist/types/commands/scan/cmd-scan-metadata.d.mts +3 -3
- package/dist/types/commands/scan/cmd-scan-report.d.mts +3 -3
- package/dist/types/commands/scan/cmd-scan-view.d.mts +3 -3
- package/dist/types/commands/scan/cmd-scan.d.mts +3 -3
- package/dist/types/commands/scan/fetch-create-org-full-scan.d.mts +11 -26
- package/dist/types/commands/scan/fetch-create-org-full-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-delete-org-full-scan.d.mts +4 -7
- package/dist/types/commands/scan/fetch-diff-scan.d.mts +8 -12
- package/dist/types/commands/scan/fetch-diff-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-list-scans.d.mts +13 -22
- package/dist/types/commands/scan/fetch-list-scans.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-report-data.d.mts +8 -14
- package/dist/types/commands/scan/fetch-scan-metadata.d.mts +4 -7
- package/dist/types/commands/scan/fetch-scan.d.mts +4 -7
- package/dist/types/commands/scan/fetch-supported-scan-file-names.d.mts +4 -6
- package/dist/types/commands/scan/generate-report.d.mts +36 -50
- package/dist/types/commands/scan/generate-report.d.mts.map +1 -1
- package/dist/types/commands/scan/handle-create-new-scan.d.mts +20 -37
- package/dist/types/commands/scan/handle-create-new-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/handle-delete-scan.d.mts +3 -7
- package/dist/types/commands/scan/handle-diff-scan.d.mts +10 -17
- package/dist/types/commands/scan/handle-diff-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/handle-list-scans.d.mts +13 -23
- package/dist/types/commands/scan/handle-list-scans.d.mts.map +1 -1
- package/dist/types/commands/scan/handle-scan-metadata.d.mts +3 -7
- package/dist/types/commands/scan/handle-scan-report.d.mts +12 -21
- package/dist/types/commands/scan/handle-scan-report.d.mts.map +1 -1
- package/dist/types/commands/scan/handle-scan-view.d.mts +3 -8
- package/dist/types/commands/scan/output-create-new-scan.d.mts +4 -8
- package/dist/types/commands/scan/output-delete-scan.d.mts +4 -7
- package/dist/types/commands/scan/output-diff-scan.d.mts +8 -15
- package/dist/types/commands/scan/output-diff-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/output-list-scans.d.mts +4 -7
- package/dist/types/commands/scan/output-scan-metadata.d.mts +4 -8
- package/dist/types/commands/scan/output-scan-report.d.mts +20 -38
- package/dist/types/commands/scan/output-scan-report.d.mts.map +1 -1
- package/dist/types/commands/scan/output-scan-view.d.mts +4 -10
- package/dist/types/commands/scan/stream-scan.d.mts +2 -6
- package/dist/types/commands/scan/suggest-org-slug.d.mts +2 -2
- package/dist/types/commands/scan/suggest-repo-slug.d.mts +4 -4
- package/dist/types/commands/scan/suggest_branch_slug.d.mts +2 -4
- package/dist/types/commands/scan/suggest_target.d.mts +2 -2
- package/dist/types/commands/threat-feed/cmd-threat-feed.d.mts +9 -15
- package/dist/types/commands/threat-feed/fetch-threat-feed.d.mts +10 -16
- package/dist/types/commands/threat-feed/fetch-threat-feed.d.mts.map +1 -1
- package/dist/types/commands/threat-feed/handle-threat-feed.d.mts +10 -17
- package/dist/types/commands/threat-feed/handle-threat-feed.d.mts.map +1 -1
- package/dist/types/commands/threat-feed/output-threat-feed.d.mts +4 -7
- package/dist/types/commands/threat-feed/types.d.mts +12 -12
- package/dist/types/commands/uninstall/cmd-uninstall-completion.d.mts +9 -0
- package/dist/types/commands/uninstall/cmd-uninstall-completion.d.mts.map +1 -0
- package/dist/types/commands/uninstall/cmd-uninstall.d.mts +3 -0
- package/dist/types/commands/uninstall/cmd-uninstall.d.mts.map +1 -0
- package/dist/types/commands/uninstall/handle-uninstall-completion.d.mts +2 -0
- package/dist/types/commands/uninstall/handle-uninstall-completion.d.mts.map +1 -0
- package/dist/types/commands/uninstall/output-uninstall-completion.d.mts +6 -0
- package/dist/types/commands/uninstall/output-uninstall-completion.d.mts.map +1 -0
- package/dist/types/commands/uninstall/teardown-tab-completion.d.mts +6 -0
- package/dist/types/commands/uninstall/teardown-tab-completion.d.mts.map +1 -0
- package/dist/types/commands/wrapper/add-socket-wrapper.d.mts +2 -2
- package/dist/types/commands/wrapper/check-socket-wrapper-setup.d.mts +2 -2
- package/dist/types/commands/wrapper/cmd-wrapper.d.mts +9 -15
- package/dist/types/commands/wrapper/postinstall-wrapper.d.mts +2 -2
- package/dist/types/commands/wrapper/postinstall-wrapper.d.mts.map +1 -1
- package/dist/types/commands/wrapper/remove-socket-wrapper.d.mts +2 -2
- package/dist/types/constants.d.mts +125 -135
- package/dist/types/constants.d.mts.map +1 -1
- package/dist/types/flags.d.mts +14 -17
- package/dist/types/flags.d.mts.map +1 -1
- package/dist/types/instrument-with-sentry.d.mts +2 -2
- package/dist/types/shadow/npm/arborist/index.d.mts +2 -2
- package/dist/types/shadow/npm/arborist/lib/arborist/index.d.mts +19 -24
- package/dist/types/shadow/npm/arborist/lib/arborist/types.d.mts +43 -71
- package/dist/types/shadow/npm/arborist/lib/dep-valid.d.mts +3 -8
- package/dist/types/shadow/npm/arborist/lib/edge.d.mts +58 -71
- package/dist/types/shadow/npm/arborist/lib/node.d.mts +55 -91
- package/dist/types/shadow/npm/arborist/lib/override-set.d.mts +26 -32
- package/dist/types/shadow/npm/arborist-helpers.d.mts +33 -66
- package/dist/types/shadow/npm/arborist-helpers.d.mts.map +1 -1
- package/dist/types/shadow/npm/bin.d.mts +2 -5
- package/dist/types/shadow/npm/inject.d.mts +2 -2
- package/dist/types/shadow/npm/install.d.mts +11 -16
- package/dist/types/shadow/npm/link.d.mts +2 -5
- package/dist/types/shadow/npm/paths.d.mts +7 -7
- package/dist/types/shadow/npm/proc-log/index.d.mts +3 -6
- package/dist/types/types.d.mts +15 -17
- package/dist/types/utils/agent.d.mts +11 -14
- package/dist/types/utils/alert/artifact.d.mts +32 -50
- package/dist/types/utils/alert/fix.d.mts +5 -5
- package/dist/types/utils/alert/severity.d.mts +12 -24
- package/dist/types/utils/alerts-map.d.mts +23 -36
- package/dist/types/utils/api.d.mts +11 -34
- package/dist/types/utils/check-input.d.mts +9 -12
- package/dist/types/utils/cmd.d.mts +4 -4
- package/dist/types/utils/color-or-markdown.d.mts +14 -23
- package/dist/types/utils/color-or-markdown.d.mts.map +1 -1
- package/dist/types/utils/completion.d.mts +11 -0
- package/dist/types/utils/completion.d.mts.map +1 -0
- package/dist/types/utils/config.d.mts +22 -31
- package/dist/types/utils/config.d.mts.map +1 -1
- package/dist/types/utils/determine-org-slug.d.mts +2 -7
- package/dist/types/utils/errors.d.mts +12 -21
- package/dist/types/utils/fail-msg-with-badge.d.mts +2 -5
- package/dist/types/utils/fs.d.mts +21 -52
- package/dist/types/utils/get-output-kind.d.mts +3 -6
- package/dist/types/utils/glob.d.mts +13 -24
- package/dist/types/utils/map-to-object.d.mts +4 -6
- package/dist/types/utils/markdown.d.mts +4 -15
- package/dist/types/utils/meow-with-subcommands.d.mts +34 -46
- package/dist/types/utils/meow-with-subcommands.d.mts.map +1 -1
- package/dist/types/utils/npm-paths.d.mts +7 -7
- package/dist/types/utils/npm-paths.d.mts.map +1 -1
- package/dist/types/utils/objects.d.mts +3 -8
- package/dist/types/utils/output-formatting.d.mts +14 -24
- package/dist/types/utils/package-environment.d.mts +51 -72
- package/dist/types/utils/package-environment.d.mts.map +1 -1
- package/dist/types/utils/path-resolve.d.mts +9 -14
- package/dist/types/utils/pnpm.d.mts +9 -7
- package/dist/types/utils/pnpm.d.mts.map +1 -1
- package/dist/types/utils/sdk.d.mts +8 -12
- package/dist/types/utils/semver.d.mts +5 -17
- package/dist/types/utils/serialize-result-json.d.mts +3 -3
- package/dist/types/utils/socket-package-alert.d.mts +62 -81
- package/dist/types/utils/socket-url.d.mts +9 -15
- package/dist/types/utils/spec.d.mts +4 -7
- package/dist/types/utils/spec.d.mts.map +1 -1
- package/dist/types/utils/strings.d.mts +2 -5
- package/dist/types/utils/translations.d.mts +592 -592
- package/dist/types/utils/walk-nested-map.d.mts +7 -10
- package/dist/utils.js +1531 -1833
- package/dist/utils.js.map +1 -1
- package/dist/vendor.js +38333 -51605
- package/dist/vendor.js.map +1 -1
- package/external/@socketsecurity/registry/external/@npmcli/package-json/index.js +5 -8
- package/external/@socketsecurity/registry/external/@npmcli/promise-spawn.js +2 -4
- package/external/@socketsecurity/registry/external/cacache.js +1 -2
- package/external/@socketsecurity/registry/external/libnpmpack.js +36 -76
- package/external/@socketsecurity/registry/external/make-fetch-happen.js +31 -67
- package/external/@socketsecurity/registry/external/pacote.js +36 -76
- package/external/@socketsecurity/registry/external/tinyglobby.js +3 -6
- package/external/@socketsecurity/registry/external/which.js +2 -4
- package/external/@socketsecurity/registry/lib/logger.d.ts +3 -1
- package/external/@socketsecurity/registry/lib/logger.js +149 -69
- package/external/@socketsecurity/registry/package.json +2 -2
- package/external/blessed/lib/alias.js +475 -468
- package/external/blessed/lib/blessed.js +12 -12
- package/external/blessed/lib/colors.js +234 -194
- package/external/blessed/lib/events.js +64 -70
- package/external/blessed/lib/gpmclient.js +117 -141
- package/external/blessed/lib/helpers.js +89 -94
- package/external/blessed/lib/keys.js +169 -342
- package/external/blessed/lib/program.js +2130 -2365
- package/external/blessed/lib/tput.js +1183 -1276
- package/external/blessed/lib/unicode.js +400 -522
- package/external/blessed/lib/widget.js +14 -14
- package/external/blessed/lib/widgets/ansiimage.js +90 -96
- package/external/blessed/lib/widgets/bigtext.js +91 -102
- package/external/blessed/lib/widgets/box.js +8 -8
- package/external/blessed/lib/widgets/button.js +23 -23
- package/external/blessed/lib/widgets/checkbox.js +50 -54
- package/external/blessed/lib/widgets/element.js +1415 -1716
- package/external/blessed/lib/widgets/filemanager.js +107 -118
- package/external/blessed/lib/widgets/form.js +144 -178
- package/external/blessed/lib/widgets/image.js +26 -36
- package/external/blessed/lib/widgets/input.js +8 -8
- package/external/blessed/lib/widgets/layout.js +103 -119
- package/external/blessed/lib/widgets/line.js +17 -20
- package/external/blessed/lib/widgets/list.js +349 -402
- package/external/blessed/lib/widgets/listbar.js +265 -306
- package/external/blessed/lib/widgets/listtable.js +133 -146
- package/external/blessed/lib/widgets/loading.js +31 -31
- package/external/blessed/lib/widgets/log.js +41 -40
- package/external/blessed/lib/widgets/message.js +64 -86
- package/external/blessed/lib/widgets/node.js +175 -207
- package/external/blessed/lib/widgets/overlayimage.js +360 -437
- package/external/blessed/lib/widgets/progressbar.js +79 -88
- package/external/blessed/lib/widgets/prompt.js +54 -61
- package/external/blessed/lib/widgets/question.js +48 -61
- package/external/blessed/lib/widgets/radiobutton.js +26 -27
- package/external/blessed/lib/widgets/radioset.js +8 -8
- package/external/blessed/lib/widgets/screen.js +1186 -1375
- package/external/blessed/lib/widgets/scrollablebox.js +202 -228
- package/external/blessed/lib/widgets/scrollabletext.js +9 -9
- package/external/blessed/lib/widgets/table.js +187 -216
- package/external/blessed/lib/widgets/terminal.js +258 -298
- package/external/blessed/lib/widgets/text.js +9 -9
- package/external/blessed/lib/widgets/textarea.js +188 -222
- package/external/blessed/lib/widgets/textbox.js +34 -36
- package/external/blessed/lib/widgets/video.js +55 -59
- package/external/blessed/usr/fonts/ter-u14b.json +1 -1
- package/external/blessed/usr/fonts/ter-u14n.json +1 -1
- package/external/blessed/vendor/tng.js +1016 -1144
- package/external/blessed-contrib/lib/layout/grid.js +345 -377
- package/external/blessed-contrib/lib/widget/charts/bar.js +6612 -7139
- package/external/blessed-contrib/lib/widget/charts/line.js +16224 -23941
- package/external/blessed-contrib/lib/widget/table.js +78 -96
- package/package.json +8 -8
- package/dist/types/commands/cdxgen/run-cdxgen.d.mts.map +0 -1
package/dist/utils.js
CHANGED
|
@@ -1,105 +1,93 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vendor = require('./vendor.js');
|
|
4
|
+
var logger = require('../external/@socketsecurity/registry/lib/logger');
|
|
5
|
+
var debug = require('../external/@socketsecurity/registry/lib/debug');
|
|
6
|
+
var path = require('node:path');
|
|
7
|
+
var objects = require('../external/@socketsecurity/registry/lib/objects');
|
|
8
|
+
var path$1 = require('../external/@socketsecurity/registry/lib/path');
|
|
9
|
+
var regexps = require('../external/@socketsecurity/registry/lib/regexps');
|
|
10
|
+
var constants = require('./constants.js');
|
|
11
|
+
var prompts = require('../external/@socketsecurity/registry/lib/prompts');
|
|
12
|
+
var strings = require('../external/@socketsecurity/registry/lib/strings');
|
|
13
|
+
var promises = require('node:timers/promises');
|
|
14
|
+
var arrays = require('../external/@socketsecurity/registry/lib/arrays');
|
|
15
|
+
var fs = require('node:fs');
|
|
16
|
+
var registry = require('../external/@socketsecurity/registry');
|
|
17
|
+
var packages = require('../external/@socketsecurity/registry/lib/packages');
|
|
18
|
+
var sorts = require('../external/@socketsecurity/registry/lib/sorts');
|
|
19
|
+
var Module = require('node:module');
|
|
20
|
+
var spawn = require('../external/@socketsecurity/registry/lib/spawn');
|
|
21
|
+
var npm = require('../external/@socketsecurity/registry/lib/npm');
|
|
22
|
+
var words = require('../external/@socketsecurity/registry/lib/words');
|
|
23
|
+
var fs$1 = require('../external/@socketsecurity/registry/lib/fs');
|
|
24
|
+
|
|
25
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
26
|
+
const {
|
|
27
|
+
NPM: NPM$6,
|
|
28
|
+
PNPM: PNPM$2
|
|
29
|
+
} = constants;
|
|
30
|
+
const PNPM_WORKSPACE = `${PNPM$2}-workspace`;
|
|
29
31
|
const ignoredDirs = [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const ignoredDirPatterns = ignoredDirs.map(i => `**/${i}`)
|
|
32
|
+
// Taken from ignore-by-default:
|
|
33
|
+
// https://github.com/novemberborn/ignore-by-default/blob/v2.1.0/index.js
|
|
34
|
+
'.git',
|
|
35
|
+
// Git repository files, see <https://git-scm.com/>
|
|
36
|
+
'.log',
|
|
37
|
+
// Log files emitted by tools such as `tsserver`, see <https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29>
|
|
38
|
+
'.nyc_output',
|
|
39
|
+
// Temporary directory where nyc stores coverage data, see <https://github.com/bcoe/nyc>
|
|
40
|
+
'.sass-cache',
|
|
41
|
+
// Cache folder for node-sass, see <https://github.com/sass/node-sass>
|
|
42
|
+
'.yarn',
|
|
43
|
+
// Where node modules are installed when using Yarn, see <https://yarnpkg.com/>
|
|
44
|
+
'bower_components',
|
|
45
|
+
// Where Bower packages are installed, see <http://bower.io/>
|
|
46
|
+
'coverage',
|
|
47
|
+
// Standard output directory for code coverage reports, see <https://github.com/gotwarlost/istanbul>
|
|
48
|
+
'node_modules',
|
|
49
|
+
// Where Node modules are installed, see <https://nodejs.org/>
|
|
50
|
+
// Taken from globby:
|
|
51
|
+
// https://github.com/sindresorhus/globby/blob/v14.0.2/ignore.js#L11-L16
|
|
52
|
+
'flow-typed'];
|
|
53
|
+
const ignoredDirPatterns = ignoredDirs.map(i => `**/${i}`);
|
|
53
54
|
async function getWorkspaceGlobs(agent, cwd = process.cwd()) {
|
|
54
|
-
let workspacePatterns
|
|
55
|
+
let workspacePatterns;
|
|
55
56
|
if (agent === PNPM$2) {
|
|
56
|
-
for (const workspacePath of [
|
|
57
|
-
path.join(cwd, `${PNPM_WORKSPACE}.yaml`),
|
|
58
|
-
path.join(cwd, `${PNPM_WORKSPACE}.yml`)
|
|
59
|
-
]) {
|
|
57
|
+
for (const workspacePath of [path.join(cwd, `${PNPM_WORKSPACE}.yaml`), path.join(cwd, `${PNPM_WORKSPACE}.yml`)]) {
|
|
60
58
|
// eslint-disable-next-line no-await-in-loop
|
|
61
|
-
const yml = await safeReadFile(workspacePath)
|
|
59
|
+
const yml = await safeReadFile(workspacePath);
|
|
62
60
|
if (yml) {
|
|
63
61
|
try {
|
|
64
|
-
workspacePatterns = vendor.distExports$1.parse(yml)?.packages
|
|
62
|
+
workspacePatterns = vendor.distExports$1.parse(yml)?.packages;
|
|
65
63
|
} catch {}
|
|
66
64
|
if (workspacePatterns) {
|
|
67
|
-
break
|
|
65
|
+
break;
|
|
68
66
|
}
|
|
69
67
|
}
|
|
70
68
|
}
|
|
71
69
|
} else {
|
|
72
|
-
workspacePatterns = (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
})
|
|
76
|
-
)?.['workspaces']
|
|
70
|
+
workspacePatterns = (await packages.readPackageJson(cwd, {
|
|
71
|
+
throws: false
|
|
72
|
+
}))?.['workspaces'];
|
|
77
73
|
}
|
|
78
|
-
return Array.isArray(workspacePatterns)
|
|
79
|
-
? workspacePatterns
|
|
80
|
-
.filter(strings.isNonEmptyString)
|
|
81
|
-
.map(workspacePatternToGlobPattern)
|
|
82
|
-
: []
|
|
74
|
+
return Array.isArray(workspacePatterns) ? workspacePatterns.filter(strings.isNonEmptyString).map(workspacePatternToGlobPattern) : [];
|
|
83
75
|
}
|
|
84
76
|
function ignoreFileLinesToGlobPatterns(lines, filepath, cwd) {
|
|
85
|
-
const base = path.relative(cwd, path.dirname(filepath)).replace(/\\/g, '/')
|
|
86
|
-
const patterns = []
|
|
87
|
-
for (let i = 0, {
|
|
88
|
-
|
|
77
|
+
const base = path.relative(cwd, path.dirname(filepath)).replace(/\\/g, '/');
|
|
78
|
+
const patterns = [];
|
|
79
|
+
for (let i = 0, {
|
|
80
|
+
length
|
|
81
|
+
} = lines; i < length; i += 1) {
|
|
82
|
+
const pattern = lines[i].trim();
|
|
89
83
|
if (pattern.length > 0 && pattern.charCodeAt(0) !== 35 /*'#'*/) {
|
|
90
|
-
patterns.push(
|
|
91
|
-
ignorePatternToMinimatch(
|
|
92
|
-
pattern.length && pattern.charCodeAt(0) === 33 /*'!'*/
|
|
93
|
-
? `!${path.posix.join(base, pattern.slice(1))}`
|
|
94
|
-
: path.posix.join(base, pattern)
|
|
95
|
-
)
|
|
96
|
-
)
|
|
84
|
+
patterns.push(ignorePatternToMinimatch(pattern.length && pattern.charCodeAt(0) === 33 /*'!'*/ ? `!${path.posix.join(base, pattern.slice(1))}` : path.posix.join(base, pattern)));
|
|
97
85
|
}
|
|
98
86
|
}
|
|
99
|
-
return patterns
|
|
87
|
+
return patterns;
|
|
100
88
|
}
|
|
101
89
|
function ignoreFileToGlobPatterns(content, filepath, cwd) {
|
|
102
|
-
return ignoreFileLinesToGlobPatterns(content.split(/\r?\n/), filepath, cwd)
|
|
90
|
+
return ignoreFileLinesToGlobPatterns(content.split(/\r?\n/), filepath, cwd);
|
|
103
91
|
}
|
|
104
92
|
|
|
105
93
|
// Based on `@eslint/compat` convertIgnorePatternToMinimatch.
|
|
@@ -107,25 +95,16 @@ function ignoreFileToGlobPatterns(content, filepath, cwd) {
|
|
|
107
95
|
// Copyright Nicholas C. Zakas
|
|
108
96
|
// https://github.com/eslint/rewrite/blob/compat-v1.2.1/packages/compat/src/ignore-file.js#L28
|
|
109
97
|
function ignorePatternToMinimatch(pattern) {
|
|
110
|
-
const isNegated = pattern.startsWith('!')
|
|
111
|
-
const negatedPrefix = isNegated ? '!' : ''
|
|
112
|
-
const patternToTest = (isNegated ? pattern.slice(1) : pattern).trimEnd()
|
|
98
|
+
const isNegated = pattern.startsWith('!');
|
|
99
|
+
const negatedPrefix = isNegated ? '!' : '';
|
|
100
|
+
const patternToTest = (isNegated ? pattern.slice(1) : pattern).trimEnd();
|
|
113
101
|
// Special cases.
|
|
114
|
-
if (
|
|
115
|
-
patternToTest
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
)
|
|
120
|
-
return `${negatedPrefix}${patternToTest}`
|
|
121
|
-
}
|
|
122
|
-
const firstIndexOfSlash = patternToTest.indexOf('/')
|
|
123
|
-
const matchEverywherePrefix =
|
|
124
|
-
firstIndexOfSlash === -1 || firstIndexOfSlash === patternToTest.length - 1
|
|
125
|
-
? '**/'
|
|
126
|
-
: ''
|
|
127
|
-
const patternWithoutLeadingSlash =
|
|
128
|
-
firstIndexOfSlash === 0 ? patternToTest.slice(1) : patternToTest
|
|
102
|
+
if (patternToTest === '' || patternToTest === '**' || patternToTest === '/**' || patternToTest === '**') {
|
|
103
|
+
return `${negatedPrefix}${patternToTest}`;
|
|
104
|
+
}
|
|
105
|
+
const firstIndexOfSlash = patternToTest.indexOf('/');
|
|
106
|
+
const matchEverywherePrefix = firstIndexOfSlash === -1 || firstIndexOfSlash === patternToTest.length - 1 ? '**/' : '';
|
|
107
|
+
const patternWithoutLeadingSlash = firstIndexOfSlash === 0 ? patternToTest.slice(1) : patternToTest;
|
|
129
108
|
// Escape `{` and `(` because in gitignore patterns they are just
|
|
130
109
|
// literal characters without any specific syntactic meaning,
|
|
131
110
|
// while in minimatch patterns they can form brace expansion or extglob syntax.
|
|
@@ -133,48 +112,35 @@ function ignorePatternToMinimatch(pattern) {
|
|
|
133
112
|
// For example, gitignore pattern `src/{a,b}.js` ignores file `src/{a,b}.js`.
|
|
134
113
|
// But, the same minimatch pattern `src/{a,b}.js` ignores files `src/a.js` and `src/b.js`.
|
|
135
114
|
// Minimatch pattern `src/\{a,b}.js` is equivalent to gitignore pattern `src/{a,b}.js`.
|
|
136
|
-
const escapedPatternWithoutLeadingSlash =
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
'$1\\$2'
|
|
140
|
-
)
|
|
141
|
-
const matchInsideSuffix = patternToTest.endsWith('/**') ? '/*' : ''
|
|
142
|
-
return `${negatedPrefix}${matchEverywherePrefix}${escapedPatternWithoutLeadingSlash}${matchInsideSuffix}`
|
|
115
|
+
const escapedPatternWithoutLeadingSlash = patternWithoutLeadingSlash.replaceAll(/(?=((?:\\.|[^{(])*))\1([{(])/guy, '$1\\$2');
|
|
116
|
+
const matchInsideSuffix = patternToTest.endsWith('/**') ? '/*' : '';
|
|
117
|
+
return `${negatedPrefix}${matchEverywherePrefix}${escapedPatternWithoutLeadingSlash}${matchInsideSuffix}`;
|
|
143
118
|
}
|
|
144
119
|
function workspacePatternToGlobPattern(workspace) {
|
|
145
|
-
const {
|
|
120
|
+
const {
|
|
121
|
+
length
|
|
122
|
+
} = workspace;
|
|
146
123
|
if (!length) {
|
|
147
|
-
return ''
|
|
124
|
+
return '';
|
|
148
125
|
}
|
|
149
126
|
// If the workspace ends with "/"
|
|
150
127
|
if (workspace.charCodeAt(length - 1) === 47 /*'/'*/) {
|
|
151
|
-
return `${workspace}/*/package.json
|
|
128
|
+
return `${workspace}/*/package.json`;
|
|
152
129
|
}
|
|
153
130
|
// If the workspace ends with "/**"
|
|
154
|
-
if (
|
|
155
|
-
workspace.
|
|
156
|
-
workspace.charCodeAt(length - 2) === 42 /*'*'*/ &&
|
|
157
|
-
workspace.charCodeAt(length - 3) === 47 /*'/'*/
|
|
158
|
-
) {
|
|
159
|
-
return `${workspace}/*/**/package.json`
|
|
131
|
+
if (workspace.charCodeAt(length - 1) === 42 /*'*'*/ && workspace.charCodeAt(length - 2) === 42 /*'*'*/ && workspace.charCodeAt(length - 3) === 47 /*'/'*/) {
|
|
132
|
+
return `${workspace}/*/**/package.json`;
|
|
160
133
|
}
|
|
161
134
|
// Things like "packages/a" or "packages/*"
|
|
162
|
-
return `${workspace}/package.json
|
|
135
|
+
return `${workspace}/package.json`;
|
|
163
136
|
}
|
|
164
137
|
async function filterGlobResultToSupportedFiles(entries, supportedFiles) {
|
|
165
|
-
const patterns = ['golang', NPM$6, 'maven', 'pypi', 'gem', 'nuget'].reduce(
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
: [])
|
|
172
|
-
)
|
|
173
|
-
return r
|
|
174
|
-
},
|
|
175
|
-
[]
|
|
176
|
-
)
|
|
177
|
-
return entries.filter(p => vendor.micromatchExports.some(p, patterns))
|
|
138
|
+
const patterns = ['golang', NPM$6, 'maven', 'pypi', 'gem', 'nuget'].reduce((r, n) => {
|
|
139
|
+
const supported = supportedFiles[n];
|
|
140
|
+
r.push(...(supported ? Object.values(supported).map(p => `**/${p.pattern}`) : []));
|
|
141
|
+
return r;
|
|
142
|
+
}, []);
|
|
143
|
+
return entries.filter(p => vendor.micromatchExports.some(p, patterns));
|
|
178
144
|
}
|
|
179
145
|
async function globWithGitIgnore(patterns, options) {
|
|
180
146
|
const {
|
|
@@ -184,468 +150,421 @@ async function globWithGitIgnore(patterns, options) {
|
|
|
184
150
|
} = {
|
|
185
151
|
__proto__: null,
|
|
186
152
|
...options
|
|
187
|
-
}
|
|
188
|
-
const projectIgnorePaths = socketConfig?.projectIgnorePaths
|
|
153
|
+
};
|
|
154
|
+
const projectIgnorePaths = socketConfig?.projectIgnorePaths;
|
|
189
155
|
const ignoreFiles = await vendor.distExports.glob(['**/.gitignore'], {
|
|
190
156
|
absolute: true,
|
|
191
157
|
cwd,
|
|
192
158
|
expandDirectories: true
|
|
193
|
-
})
|
|
194
|
-
const ignores = [
|
|
195
|
-
|
|
196
|
-
...(Array.isArray(projectIgnorePaths)
|
|
197
|
-
? ignoreFileLinesToGlobPatterns(
|
|
198
|
-
projectIgnorePaths,
|
|
199
|
-
path.join(cwd, '.gitignore'),
|
|
200
|
-
cwd
|
|
201
|
-
)
|
|
202
|
-
: []),
|
|
203
|
-
...(
|
|
204
|
-
await Promise.all(
|
|
205
|
-
ignoreFiles.map(async filepath =>
|
|
206
|
-
ignoreFileToGlobPatterns(
|
|
207
|
-
await fs.promises.readFile(filepath, 'utf8'),
|
|
208
|
-
filepath,
|
|
209
|
-
cwd
|
|
210
|
-
)
|
|
211
|
-
)
|
|
212
|
-
)
|
|
213
|
-
).flat()
|
|
214
|
-
]
|
|
215
|
-
const hasNegatedPattern = ignores.some(p => p.charCodeAt(0) === 33 /*'!'*/)
|
|
159
|
+
});
|
|
160
|
+
const ignores = [...ignoredDirPatterns, ...(Array.isArray(projectIgnorePaths) ? ignoreFileLinesToGlobPatterns(projectIgnorePaths, path.join(cwd, '.gitignore'), cwd) : []), ...(await Promise.all(ignoreFiles.map(async filepath => ignoreFileToGlobPatterns(await fs.promises.readFile(filepath, 'utf8'), filepath, cwd)))).flat()];
|
|
161
|
+
const hasNegatedPattern = ignores.some(p => p.charCodeAt(0) === 33 /*'!'*/);
|
|
216
162
|
const globOptions = {
|
|
217
163
|
absolute: true,
|
|
218
164
|
cwd,
|
|
219
165
|
expandDirectories: false,
|
|
220
166
|
ignore: hasNegatedPattern ? [] : ignores,
|
|
221
167
|
...additionalOptions
|
|
222
|
-
}
|
|
223
|
-
const result = await vendor.distExports.glob(patterns, globOptions)
|
|
168
|
+
};
|
|
169
|
+
const result = await vendor.distExports.glob(patterns, globOptions);
|
|
224
170
|
if (!hasNegatedPattern) {
|
|
225
|
-
return result
|
|
171
|
+
return result;
|
|
226
172
|
}
|
|
227
|
-
const {
|
|
173
|
+
const {
|
|
174
|
+
absolute
|
|
175
|
+
} = globOptions;
|
|
228
176
|
|
|
229
177
|
// Note: the input files must be INSIDE the cwd. If you get strange looking
|
|
230
178
|
// relative path errors here, most likely your path is outside the given cwd.
|
|
231
|
-
const filtered = vendor
|
|
232
|
-
|
|
233
|
-
.add(ignores)
|
|
234
|
-
.filter(absolute ? result.map(p => path.relative(cwd, p)) : result)
|
|
235
|
-
return absolute ? filtered.map(p => path.resolve(cwd, p)) : filtered
|
|
179
|
+
const filtered = vendor.ignoreExports().add(ignores).filter(absolute ? result.map(p => path.relative(cwd, p)) : result);
|
|
180
|
+
return absolute ? filtered.map(p => path.resolve(cwd, p)) : filtered;
|
|
236
181
|
}
|
|
237
182
|
async function globNodeModules(cwd = process.cwd()) {
|
|
238
183
|
return await vendor.distExports.glob('**/node_modules/**', {
|
|
239
184
|
absolute: true,
|
|
240
185
|
cwd
|
|
241
|
-
})
|
|
186
|
+
});
|
|
242
187
|
}
|
|
243
188
|
async function globWorkspace(agent, cwd = process.cwd()) {
|
|
244
|
-
const workspaceGlobs = await getWorkspaceGlobs(agent, cwd)
|
|
245
|
-
return workspaceGlobs.length
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
})
|
|
251
|
-
: []
|
|
189
|
+
const workspaceGlobs = await getWorkspaceGlobs(agent, cwd);
|
|
190
|
+
return workspaceGlobs.length ? await vendor.distExports.glob(workspaceGlobs, {
|
|
191
|
+
absolute: true,
|
|
192
|
+
cwd,
|
|
193
|
+
ignore: ['**/node_modules/**', '**/bower_components/**']
|
|
194
|
+
}) : [];
|
|
252
195
|
}
|
|
253
196
|
function pathsToGlobPatterns(paths) {
|
|
254
197
|
// TODO: Does not support `~/` paths.
|
|
255
|
-
return paths.map(p =>
|
|
198
|
+
return paths.map(p => p === '.' || p === './' ? '**/*' : p);
|
|
256
199
|
}
|
|
257
200
|
|
|
258
|
-
const {
|
|
201
|
+
const {
|
|
202
|
+
abortSignal
|
|
203
|
+
} = constants;
|
|
259
204
|
async function removeNodeModules(cwd = process.cwd()) {
|
|
260
|
-
const nodeModulesPaths = await globNodeModules(cwd)
|
|
261
|
-
await Promise.all(nodeModulesPaths.map(p => fs$1.remove(p)))
|
|
205
|
+
const nodeModulesPaths = await globNodeModules(cwd);
|
|
206
|
+
await Promise.all(nodeModulesPaths.map(p => fs$1.remove(p)));
|
|
262
207
|
}
|
|
263
|
-
async function findUp(name, {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
208
|
+
async function findUp(name, {
|
|
209
|
+
cwd = process.cwd(),
|
|
210
|
+
signal = abortSignal
|
|
211
|
+
}) {
|
|
212
|
+
let dir = path.resolve(cwd);
|
|
213
|
+
const {
|
|
214
|
+
root
|
|
215
|
+
} = path.parse(dir);
|
|
216
|
+
const names = [name].flat();
|
|
267
217
|
while (dir && dir !== root) {
|
|
268
218
|
for (const name of names) {
|
|
269
219
|
if (signal?.aborted) {
|
|
270
|
-
return undefined
|
|
220
|
+
return undefined;
|
|
271
221
|
}
|
|
272
|
-
const filePath = path.join(dir, name)
|
|
222
|
+
const filePath = path.join(dir, name);
|
|
273
223
|
try {
|
|
274
224
|
// eslint-disable-next-line no-await-in-loop
|
|
275
|
-
const stats = await fs.promises.stat(filePath)
|
|
225
|
+
const stats = await fs.promises.stat(filePath);
|
|
276
226
|
if (stats.isFile()) {
|
|
277
|
-
return filePath
|
|
227
|
+
return filePath;
|
|
278
228
|
}
|
|
279
229
|
} catch {}
|
|
280
230
|
}
|
|
281
|
-
dir = path.dirname(dir)
|
|
231
|
+
dir = path.dirname(dir);
|
|
282
232
|
}
|
|
283
|
-
return undefined
|
|
233
|
+
return undefined;
|
|
284
234
|
}
|
|
285
235
|
async function readFileBinary(filepath, options) {
|
|
286
236
|
return await fs.promises.readFile(filepath, {
|
|
287
237
|
signal: abortSignal,
|
|
288
238
|
...options,
|
|
289
239
|
encoding: 'binary'
|
|
290
|
-
})
|
|
240
|
+
});
|
|
291
241
|
}
|
|
292
242
|
async function readFileUtf8(filepath, options) {
|
|
293
243
|
return await fs.promises.readFile(filepath, {
|
|
294
244
|
signal: abortSignal,
|
|
295
245
|
...options,
|
|
296
246
|
encoding: 'utf8'
|
|
297
|
-
})
|
|
247
|
+
});
|
|
298
248
|
}
|
|
299
249
|
async function safeReadFile(filepath, options) {
|
|
300
250
|
try {
|
|
301
251
|
return await fs.promises.readFile(filepath, {
|
|
302
252
|
encoding: 'utf8',
|
|
303
253
|
signal: abortSignal,
|
|
304
|
-
...(typeof options === 'string'
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
: options)
|
|
309
|
-
})
|
|
254
|
+
...(typeof options === 'string' ? {
|
|
255
|
+
encoding: options
|
|
256
|
+
} : options)
|
|
257
|
+
});
|
|
310
258
|
} catch {}
|
|
311
|
-
return undefined
|
|
259
|
+
return undefined;
|
|
312
260
|
}
|
|
313
261
|
function safeReadFileSync(filepath, options) {
|
|
314
262
|
try {
|
|
315
263
|
return fs.readFileSync(filepath, {
|
|
316
264
|
encoding: 'utf8',
|
|
317
|
-
...(typeof options === 'string'
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
: options)
|
|
322
|
-
})
|
|
265
|
+
...(typeof options === 'string' ? {
|
|
266
|
+
encoding: options
|
|
267
|
+
} : options)
|
|
268
|
+
});
|
|
323
269
|
} catch {}
|
|
324
|
-
return undefined
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
const supportedConfigKeys = new Map([
|
|
328
|
-
['apiBaseUrl', 'Base URL of the API endpoint'],
|
|
329
|
-
['apiProxy', 'A proxy through which to access the API'],
|
|
330
|
-
['apiToken', 'The API token required to access most API endpoints'],
|
|
331
|
-
[
|
|
332
|
-
'defaultOrg',
|
|
333
|
-
'The default org slug to use; usually the org your API token has access to. When set, all orgSlug arguments are implied to be this value.'
|
|
334
|
-
],
|
|
335
|
-
[
|
|
336
|
-
'enforcedOrgs',
|
|
337
|
-
'Orgs in this list have their security policies enforced on this machine'
|
|
338
|
-
],
|
|
339
|
-
['isTestingV1', 'For development of testing the next major bump']
|
|
340
|
-
])
|
|
341
|
-
const sensitiveConfigKeys = new Set(['apiToken'])
|
|
342
|
-
let _cachedConfig
|
|
343
|
-
// When using --config or SOCKET_CLI_CONFIG, do not persist the config.
|
|
344
|
-
let _readOnlyConfig = false
|
|
345
|
-
function overrideCachedConfig(jsonConfig) {
|
|
346
|
-
debug.debugLog('Overriding entire config, marking config as read-only')
|
|
347
|
-
let config
|
|
348
|
-
try {
|
|
349
|
-
config = JSON.parse(String(jsonConfig))
|
|
350
|
-
if (!config || typeof config !== 'object') {
|
|
351
|
-
// `null` is valid json, so are primitive values. They're not valid config objects :)
|
|
352
|
-
return {
|
|
353
|
-
ok: false,
|
|
354
|
-
message: 'Could not parse Config as JSON',
|
|
355
|
-
cause:
|
|
356
|
-
"Could not JSON parse the config override. Make sure it's a proper JSON object (double-quoted keys and strings, no unquoted `undefined`) and try again."
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
} catch {
|
|
360
|
-
// Force set an empty config to prevent accidentally using system settings
|
|
361
|
-
_cachedConfig = {}
|
|
362
|
-
_readOnlyConfig = true
|
|
363
|
-
return {
|
|
364
|
-
ok: false,
|
|
365
|
-
message: 'Could not parse Config as JSON',
|
|
366
|
-
cause:
|
|
367
|
-
"Could not JSON parse the config override. Make sure it's a proper JSON object (double-quoted keys and strings, no unquoted `undefined`) and try again."
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
// @ts-ignore Override an illegal object.
|
|
372
|
-
_cachedConfig = config
|
|
373
|
-
_readOnlyConfig = true
|
|
374
|
-
|
|
375
|
-
// Normalize apiKey to apiToken.
|
|
376
|
-
if (_cachedConfig['apiKey']) {
|
|
377
|
-
if (_cachedConfig['apiToken']) {
|
|
378
|
-
logger.logger.warn(
|
|
379
|
-
'Note: The config override had both apiToken and apiKey. Using the apiToken value. Remove the apiKey to get rid of this message.'
|
|
380
|
-
)
|
|
381
|
-
}
|
|
382
|
-
_cachedConfig['apiToken'] = _cachedConfig['apiKey']
|
|
383
|
-
delete _cachedConfig['apiKey']
|
|
384
|
-
}
|
|
385
|
-
return {
|
|
386
|
-
ok: true,
|
|
387
|
-
data: undefined
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
function overrideConfigApiToken(apiToken) {
|
|
391
|
-
debug.debugLog('Overriding API token, marking config as read-only')
|
|
392
|
-
// Set token to the local cached config and mark it read-only so it doesn't persist
|
|
393
|
-
_cachedConfig = {
|
|
394
|
-
...vendor.configExports,
|
|
395
|
-
...(apiToken === undefined
|
|
396
|
-
? {}
|
|
397
|
-
: {
|
|
398
|
-
apiToken: String(apiToken)
|
|
399
|
-
})
|
|
400
|
-
}
|
|
401
|
-
_readOnlyConfig = true
|
|
270
|
+
return undefined;
|
|
402
271
|
}
|
|
272
|
+
|
|
273
|
+
const sensitiveConfigKeys = new Set(['apiToken']);
|
|
274
|
+
const supportedConfigKeys = new Map([['apiBaseUrl', 'Base URL of the API endpoint'], ['apiProxy', 'A proxy through which to access the API'], ['apiToken', 'The API token required to access most API endpoints'], ['defaultOrg', 'The default org slug to use; usually the org your API token has access to. When set, all orgSlug arguments are implied to be this value.'], ['enforcedOrgs', 'Orgs in this list have their security policies enforced on this machine'], ['isTestingV1', 'For development of testing the next major bump']]);
|
|
403
275
|
function getConfigValues() {
|
|
404
276
|
if (_cachedConfig === undefined) {
|
|
405
277
|
// Order: env var > --config flag > file
|
|
406
|
-
_cachedConfig = {}
|
|
407
|
-
// Lazily access constants.
|
|
408
|
-
const {
|
|
409
|
-
|
|
410
|
-
|
|
278
|
+
_cachedConfig = {};
|
|
279
|
+
// Lazily access constants.socketAppDataPath.
|
|
280
|
+
const {
|
|
281
|
+
socketAppDataPath
|
|
282
|
+
} = constants;
|
|
283
|
+
if (socketAppDataPath) {
|
|
284
|
+
const raw = safeReadFileSync(socketAppDataPath);
|
|
411
285
|
if (raw) {
|
|
412
286
|
try {
|
|
413
|
-
Object.assign(
|
|
414
|
-
_cachedConfig,
|
|
415
|
-
JSON.parse(Buffer.from(raw, 'base64').toString())
|
|
416
|
-
)
|
|
287
|
+
Object.assign(_cachedConfig, JSON.parse(Buffer.from(raw, 'base64').toString()));
|
|
417
288
|
} catch {
|
|
418
|
-
logger.logger.warn(`Failed to parse config at ${
|
|
289
|
+
logger.logger.warn(`Failed to parse config at ${socketAppDataPath}`);
|
|
419
290
|
}
|
|
420
291
|
// Normalize apiKey to apiToken and persist it.
|
|
421
292
|
// This is a one time migration per user.
|
|
422
293
|
if (_cachedConfig['apiKey']) {
|
|
423
|
-
const token = _cachedConfig['apiKey']
|
|
424
|
-
delete _cachedConfig['apiKey']
|
|
425
|
-
updateConfigValue('apiToken', token)
|
|
294
|
+
const token = _cachedConfig['apiKey'];
|
|
295
|
+
delete _cachedConfig['apiKey'];
|
|
296
|
+
updateConfigValue('apiToken', token);
|
|
426
297
|
}
|
|
427
298
|
} else {
|
|
428
|
-
fs.mkdirSync(path.dirname(
|
|
299
|
+
fs.mkdirSync(path.dirname(socketAppDataPath), {
|
|
429
300
|
recursive: true
|
|
430
|
-
})
|
|
301
|
+
});
|
|
431
302
|
}
|
|
432
303
|
}
|
|
433
304
|
}
|
|
434
|
-
return _cachedConfig
|
|
305
|
+
return _cachedConfig;
|
|
435
306
|
}
|
|
436
307
|
function normalizeConfigKey(key) {
|
|
437
308
|
// Note: apiKey was the old name of the token. When we load a config with
|
|
438
309
|
// property apiKey, we'll copy that to apiToken and delete the old property.
|
|
439
|
-
const normalizedKey = key === 'apiKey' ? 'apiToken' : key
|
|
310
|
+
const normalizedKey = key === 'apiKey' ? 'apiToken' : key;
|
|
440
311
|
if (!supportedConfigKeys.has(normalizedKey)) {
|
|
441
312
|
return {
|
|
442
313
|
ok: false,
|
|
443
314
|
message: `Invalid config key: ${normalizedKey}`,
|
|
444
315
|
data: undefined
|
|
445
|
-
}
|
|
316
|
+
};
|
|
446
317
|
}
|
|
447
318
|
return {
|
|
448
319
|
ok: true,
|
|
449
320
|
data: key
|
|
450
|
-
}
|
|
321
|
+
};
|
|
451
322
|
}
|
|
452
323
|
function findSocketYmlSync(dir = process.cwd()) {
|
|
453
|
-
let prevDir = null
|
|
324
|
+
let prevDir = null;
|
|
454
325
|
while (dir !== prevDir) {
|
|
455
|
-
let ymlPath = path.join(dir, 'socket.yml')
|
|
456
|
-
let yml = safeReadFileSync(ymlPath)
|
|
326
|
+
let ymlPath = path.join(dir, 'socket.yml');
|
|
327
|
+
let yml = safeReadFileSync(ymlPath);
|
|
457
328
|
if (yml === undefined) {
|
|
458
|
-
ymlPath = path.join(dir, 'socket.yaml')
|
|
459
|
-
yml = safeReadFileSync(ymlPath)
|
|
329
|
+
ymlPath = path.join(dir, 'socket.yaml');
|
|
330
|
+
yml = safeReadFileSync(ymlPath);
|
|
460
331
|
}
|
|
461
332
|
if (typeof yml === 'string') {
|
|
462
333
|
try {
|
|
463
334
|
return {
|
|
464
335
|
path: ymlPath,
|
|
465
336
|
parsed: vendor.configExports.parseSocketConfig(yml)
|
|
466
|
-
}
|
|
337
|
+
};
|
|
467
338
|
} catch {
|
|
468
|
-
throw new Error(`Found file but was unable to parse ${ymlPath}`)
|
|
339
|
+
throw new Error(`Found file but was unable to parse ${ymlPath}`);
|
|
469
340
|
}
|
|
470
341
|
}
|
|
471
|
-
prevDir = dir
|
|
472
|
-
dir = path.join(dir, '..')
|
|
342
|
+
prevDir = dir;
|
|
343
|
+
dir = path.join(dir, '..');
|
|
473
344
|
}
|
|
474
|
-
return null
|
|
345
|
+
return null;
|
|
475
346
|
}
|
|
476
347
|
function getConfigValue(key) {
|
|
477
|
-
const localConfig = getConfigValues()
|
|
478
|
-
const keyResult = normalizeConfigKey(key)
|
|
348
|
+
const localConfig = getConfigValues();
|
|
349
|
+
const keyResult = normalizeConfigKey(key);
|
|
479
350
|
if (!keyResult.ok) {
|
|
480
|
-
return keyResult
|
|
351
|
+
return keyResult;
|
|
481
352
|
}
|
|
482
353
|
return {
|
|
483
354
|
ok: true,
|
|
484
355
|
data: localConfig[keyResult.data]
|
|
485
|
-
}
|
|
356
|
+
};
|
|
486
357
|
}
|
|
358
|
+
|
|
487
359
|
// This version squashes errors, returning undefined instead.
|
|
488
360
|
// Should be used when we can reasonably predict the call can't fail.
|
|
489
361
|
function getConfigValueOrUndef(key) {
|
|
490
|
-
const localConfig = getConfigValues()
|
|
491
|
-
const keyResult = normalizeConfigKey(key)
|
|
362
|
+
const localConfig = getConfigValues();
|
|
363
|
+
const keyResult = normalizeConfigKey(key);
|
|
492
364
|
if (!keyResult.ok) {
|
|
493
|
-
return undefined
|
|
365
|
+
return undefined;
|
|
494
366
|
}
|
|
495
|
-
return localConfig[keyResult.data]
|
|
367
|
+
return localConfig[keyResult.data];
|
|
496
368
|
}
|
|
497
369
|
function isReadOnlyConfig() {
|
|
498
|
-
return _readOnlyConfig
|
|
370
|
+
return _readOnlyConfig;
|
|
499
371
|
}
|
|
500
|
-
|
|
372
|
+
function isTestingV1() {
|
|
373
|
+
return !!getConfigValueOrUndef('isTestingV1');
|
|
374
|
+
}
|
|
375
|
+
let _cachedConfig;
|
|
376
|
+
// When using --config or SOCKET_CLI_CONFIG, do not persist the config.
|
|
377
|
+
let _readOnlyConfig = false;
|
|
378
|
+
function overrideCachedConfig(jsonConfig) {
|
|
379
|
+
debug.debugLog('Overriding entire config, marking config as read-only');
|
|
380
|
+
let config;
|
|
381
|
+
try {
|
|
382
|
+
config = JSON.parse(String(jsonConfig));
|
|
383
|
+
if (!config || typeof config !== 'object') {
|
|
384
|
+
// `null` is valid json, so are primitive values. They're not valid config objects :)
|
|
385
|
+
return {
|
|
386
|
+
ok: false,
|
|
387
|
+
message: 'Could not parse Config as JSON',
|
|
388
|
+
cause: "Could not JSON parse the config override. Make sure it's a proper JSON object (double-quoted keys and strings, no unquoted `undefined`) and try again."
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
} catch {
|
|
392
|
+
// Force set an empty config to prevent accidentally using system settings
|
|
393
|
+
_cachedConfig = {};
|
|
394
|
+
_readOnlyConfig = true;
|
|
395
|
+
return {
|
|
396
|
+
ok: false,
|
|
397
|
+
message: 'Could not parse Config as JSON',
|
|
398
|
+
cause: "Could not JSON parse the config override. Make sure it's a proper JSON object (double-quoted keys and strings, no unquoted `undefined`) and try again."
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// @ts-ignore Override an illegal object.
|
|
403
|
+
_cachedConfig = config;
|
|
404
|
+
_readOnlyConfig = true;
|
|
405
|
+
|
|
406
|
+
// Normalize apiKey to apiToken.
|
|
407
|
+
if (_cachedConfig['apiKey']) {
|
|
408
|
+
if (_cachedConfig['apiToken']) {
|
|
409
|
+
logger.logger.warn('Note: The config override had both apiToken and apiKey. Using the apiToken value. Remove the apiKey to get rid of this message.');
|
|
410
|
+
}
|
|
411
|
+
_cachedConfig['apiToken'] = _cachedConfig['apiKey'];
|
|
412
|
+
delete _cachedConfig['apiKey'];
|
|
413
|
+
}
|
|
414
|
+
return {
|
|
415
|
+
ok: true,
|
|
416
|
+
data: undefined
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
function overrideConfigApiToken(apiToken) {
|
|
420
|
+
debug.debugLog('Overriding API token, marking config as read-only');
|
|
421
|
+
// Set token to the local cached config and mark it read-only so it doesn't persist
|
|
422
|
+
_cachedConfig = {
|
|
423
|
+
...vendor.configExports,
|
|
424
|
+
...(apiToken === undefined ? {} : {
|
|
425
|
+
apiToken: String(apiToken)
|
|
426
|
+
})
|
|
427
|
+
};
|
|
428
|
+
_readOnlyConfig = true;
|
|
429
|
+
}
|
|
430
|
+
let _pendingSave = false;
|
|
501
431
|
function updateConfigValue(key, value) {
|
|
502
|
-
const localConfig = getConfigValues()
|
|
503
|
-
const keyResult = normalizeConfigKey(key)
|
|
432
|
+
const localConfig = getConfigValues();
|
|
433
|
+
const keyResult = normalizeConfigKey(key);
|
|
504
434
|
if (!keyResult.ok) {
|
|
505
|
-
return keyResult
|
|
435
|
+
return keyResult;
|
|
506
436
|
}
|
|
507
|
-
localConfig[keyResult.data] = value
|
|
437
|
+
localConfig[keyResult.data] = value;
|
|
508
438
|
if (_readOnlyConfig) {
|
|
509
439
|
return {
|
|
510
440
|
ok: true,
|
|
511
441
|
message: `Config key '${key}' was updated`,
|
|
512
442
|
data: 'Change applied but not persisted; current config is overridden through env var or flag'
|
|
513
|
-
}
|
|
443
|
+
};
|
|
514
444
|
}
|
|
515
445
|
if (!_pendingSave) {
|
|
516
|
-
_pendingSave = true
|
|
446
|
+
_pendingSave = true;
|
|
517
447
|
process.nextTick(() => {
|
|
518
|
-
_pendingSave = false
|
|
519
|
-
// Lazily access constants.
|
|
520
|
-
const {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
)
|
|
448
|
+
_pendingSave = false;
|
|
449
|
+
// Lazily access constants.socketAppDataPath.
|
|
450
|
+
const {
|
|
451
|
+
socketAppDataPath
|
|
452
|
+
} = constants;
|
|
453
|
+
if (socketAppDataPath) {
|
|
454
|
+
fs.writeFileSync(socketAppDataPath, Buffer.from(JSON.stringify(localConfig)).toString('base64'));
|
|
526
455
|
}
|
|
527
|
-
})
|
|
456
|
+
});
|
|
528
457
|
}
|
|
529
458
|
return {
|
|
530
459
|
ok: true,
|
|
531
460
|
message: `Config key '${key}' was updated`,
|
|
532
461
|
data: undefined
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
function isTestingV1() {
|
|
536
|
-
return !!getConfigValueOrUndef('isTestingV1')
|
|
462
|
+
};
|
|
537
463
|
}
|
|
538
464
|
|
|
539
465
|
const {
|
|
540
466
|
kInternalsSymbol,
|
|
541
|
-
[kInternalsSymbol]: {
|
|
542
|
-
|
|
467
|
+
[kInternalsSymbol]: {
|
|
468
|
+
getSentry
|
|
469
|
+
}
|
|
470
|
+
} = constants;
|
|
543
471
|
class AuthError extends Error {}
|
|
544
472
|
class InputError extends Error {
|
|
545
473
|
constructor(message, body) {
|
|
546
|
-
super(message)
|
|
547
|
-
this.body = body
|
|
474
|
+
super(message);
|
|
475
|
+
this.body = body;
|
|
548
476
|
}
|
|
549
477
|
}
|
|
550
478
|
async function captureException(exception, hint) {
|
|
551
|
-
const result = captureExceptionSync(exception, hint)
|
|
479
|
+
const result = captureExceptionSync(exception, hint);
|
|
552
480
|
// "Sleep" for a second, just in case, hopefully enough time to initiate fetch.
|
|
553
|
-
await promises.setTimeout(1000)
|
|
554
|
-
return result
|
|
481
|
+
await promises.setTimeout(1000);
|
|
482
|
+
return result;
|
|
555
483
|
}
|
|
556
484
|
function captureExceptionSync(exception, hint) {
|
|
557
|
-
const Sentry = getSentry()
|
|
485
|
+
const Sentry = getSentry();
|
|
558
486
|
if (!Sentry) {
|
|
559
|
-
return ''
|
|
487
|
+
return '';
|
|
560
488
|
}
|
|
561
|
-
debug.debugLog('captureException: Sending exception to Sentry')
|
|
562
|
-
return Sentry.captureException(exception, hint)
|
|
489
|
+
debug.debugLog('captureException: Sending exception to Sentry');
|
|
490
|
+
return Sentry.captureException(exception, hint);
|
|
563
491
|
}
|
|
564
492
|
|
|
565
493
|
function failMsgWithBadge(badge, msg) {
|
|
566
|
-
return `${vendor.yoctocolorsCjsExports.bgRed(vendor.yoctocolorsCjsExports.bold(vendor.yoctocolorsCjsExports.white(` ${badge}${msg ? ': ' : ''}`)))}${msg ? ' ' + vendor.yoctocolorsCjsExports.bold(msg) : ''}
|
|
494
|
+
return `${vendor.yoctocolorsCjsExports.bgRed(vendor.yoctocolorsCjsExports.bold(vendor.yoctocolorsCjsExports.white(` ${badge}${msg ? ': ' : ''}`)))}${msg ? ' ' + vendor.yoctocolorsCjsExports.bold(msg) : ''}`;
|
|
567
495
|
}
|
|
568
496
|
|
|
569
|
-
const {
|
|
570
|
-
|
|
571
|
-
|
|
497
|
+
const {
|
|
498
|
+
SOCKET_PUBLIC_API_TOKEN
|
|
499
|
+
} = constants;
|
|
500
|
+
const TOKEN_PREFIX = 'sktsec_';
|
|
501
|
+
const {
|
|
502
|
+
length: TOKEN_PREFIX_LENGTH
|
|
503
|
+
} = TOKEN_PREFIX;
|
|
572
504
|
|
|
573
505
|
// The API server that should be used for operations.
|
|
574
506
|
function getDefaultApiBaseUrl$1() {
|
|
575
507
|
const baseUrl =
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
return strings.isNonEmptyString(baseUrl) ? baseUrl : undefined
|
|
508
|
+
// Lazily access constants.ENV.SOCKET_SECURITY_API_BASE_URL.
|
|
509
|
+
constants.ENV.SOCKET_SECURITY_API_BASE_URL || getConfigValueOrUndef('apiBaseUrl');
|
|
510
|
+
return strings.isNonEmptyString(baseUrl) ? baseUrl : undefined;
|
|
580
511
|
}
|
|
581
512
|
|
|
582
513
|
// The API server that should be used for operations.
|
|
583
514
|
function getDefaultHttpProxy() {
|
|
584
515
|
const apiProxy =
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
return strings.isNonEmptyString(apiProxy) ? apiProxy : undefined
|
|
516
|
+
// Lazily access constants.ENV.SOCKET_SECURITY_API_PROXY.
|
|
517
|
+
constants.ENV.SOCKET_SECURITY_API_PROXY || getConfigValueOrUndef('apiProxy');
|
|
518
|
+
return strings.isNonEmptyString(apiProxy) ? apiProxy : undefined;
|
|
588
519
|
}
|
|
589
520
|
|
|
590
521
|
// This API key should be stored globally for the duration of the CLI execution.
|
|
591
|
-
let _defaultToken
|
|
522
|
+
let _defaultToken;
|
|
592
523
|
function getDefaultToken() {
|
|
593
524
|
// Lazily access constants.ENV.SOCKET_CLI_NO_API_TOKEN.
|
|
594
525
|
if (constants.ENV.SOCKET_CLI_NO_API_TOKEN) {
|
|
595
|
-
_defaultToken = undefined
|
|
526
|
+
_defaultToken = undefined;
|
|
596
527
|
} else {
|
|
597
528
|
const key =
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
_defaultToken
|
|
602
|
-
_defaultToken = strings.isNonEmptyString(key) ? key : undefined
|
|
529
|
+
// Lazily access constants.ENV.SOCKET_SECURITY_API_TOKEN.
|
|
530
|
+
constants.ENV.SOCKET_SECURITY_API_TOKEN || getConfigValueOrUndef('apiToken') || _defaultToken;
|
|
531
|
+
_defaultToken = strings.isNonEmptyString(key) ? key : undefined;
|
|
603
532
|
}
|
|
604
|
-
return _defaultToken
|
|
533
|
+
return _defaultToken;
|
|
605
534
|
}
|
|
606
535
|
function getVisibleTokenPrefix() {
|
|
607
|
-
const apiToken = getDefaultToken()
|
|
608
|
-
return apiToken
|
|
609
|
-
? apiToken.slice(TOKEN_PREFIX_LENGTH, TOKEN_PREFIX_LENGTH + 5)
|
|
610
|
-
: ''
|
|
536
|
+
const apiToken = getDefaultToken();
|
|
537
|
+
return apiToken ? apiToken.slice(TOKEN_PREFIX_LENGTH, TOKEN_PREFIX_LENGTH + 5) : '';
|
|
611
538
|
}
|
|
612
539
|
function hasDefaultToken() {
|
|
613
|
-
return !!getDefaultToken()
|
|
540
|
+
return !!getDefaultToken();
|
|
614
541
|
}
|
|
615
542
|
function getPublicToken() {
|
|
616
543
|
return (
|
|
617
544
|
// Lazily access constants.ENV.SOCKET_SECURITY_API_TOKEN.
|
|
618
|
-
(constants.ENV.SOCKET_SECURITY_API_TOKEN || getDefaultToken()) ??
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
async function setupSdk(
|
|
623
|
-
apiToken = getDefaultToken(),
|
|
624
|
-
apiBaseUrl = getDefaultApiBaseUrl$1(),
|
|
625
|
-
proxy = getDefaultHttpProxy()
|
|
626
|
-
) {
|
|
545
|
+
(constants.ENV.SOCKET_SECURITY_API_TOKEN || getDefaultToken()) ?? SOCKET_PUBLIC_API_TOKEN
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
async function setupSdk(apiToken = getDefaultToken(), apiBaseUrl = getDefaultApiBaseUrl$1(), proxy = getDefaultHttpProxy()) {
|
|
627
549
|
if (typeof apiToken !== 'string' && vendor.isInteractiveExports()) {
|
|
628
550
|
apiToken = await prompts.password({
|
|
629
|
-
message:
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
_defaultToken = apiToken
|
|
551
|
+
message: 'Enter your Socket.dev API key (not saved, use socket login to persist)'
|
|
552
|
+
});
|
|
553
|
+
_defaultToken = apiToken;
|
|
633
554
|
}
|
|
634
555
|
if (!apiToken) {
|
|
635
556
|
return {
|
|
636
557
|
ok: false,
|
|
637
558
|
message: 'Auth Error',
|
|
638
559
|
cause: 'You need to provide an API Token. Run `socket login` first.'
|
|
639
|
-
}
|
|
560
|
+
};
|
|
640
561
|
}
|
|
641
562
|
return {
|
|
642
563
|
ok: true,
|
|
643
564
|
data: new vendor.distExports$2.SocketSdk(apiToken, {
|
|
644
|
-
agent: proxy
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
})
|
|
648
|
-
: undefined,
|
|
565
|
+
agent: proxy ? new vendor.HttpsProxyAgent({
|
|
566
|
+
proxy
|
|
567
|
+
}) : undefined,
|
|
649
568
|
baseUrl: apiBaseUrl,
|
|
650
569
|
userAgent: vendor.distExports$2.createUserAgentFromPkgJson({
|
|
651
570
|
// Lazily access constants.ENV.INLINED_SOCKET_CLI_NAME.
|
|
@@ -656,53 +575,55 @@ async function setupSdk(
|
|
|
656
575
|
homepage: constants.ENV.INLINED_SOCKET_CLI_HOMEPAGE
|
|
657
576
|
})
|
|
658
577
|
})
|
|
659
|
-
}
|
|
578
|
+
};
|
|
660
579
|
}
|
|
661
580
|
|
|
662
581
|
// TODO: this function is removed after v1.0.0
|
|
663
582
|
function handleUnsuccessfulApiResponse(_name, error, cause, status) {
|
|
664
|
-
const message = `${error || 'No error message returned'}${cause ? ` (reason: ${cause})` : ''}
|
|
583
|
+
const message = `${error || 'No error message returned'}${cause ? ` (reason: ${cause})` : ''}`;
|
|
665
584
|
if (status === 401 || status === 403) {
|
|
666
585
|
// Lazily access constants.spinner.
|
|
667
|
-
const {
|
|
668
|
-
|
|
669
|
-
|
|
586
|
+
const {
|
|
587
|
+
spinner
|
|
588
|
+
} = constants;
|
|
589
|
+
spinner.stop();
|
|
590
|
+
throw new AuthError(message);
|
|
670
591
|
}
|
|
671
|
-
logger.logger.fail(failMsgWithBadge('Socket API returned an error', message))
|
|
592
|
+
logger.logger.fail(failMsgWithBadge('Socket API returned an error', message));
|
|
672
593
|
// eslint-disable-next-line n/no-process-exit
|
|
673
|
-
process.exit(1)
|
|
594
|
+
process.exit(1);
|
|
674
595
|
}
|
|
675
596
|
async function handleApiCall(value, fetchingDesc) {
|
|
676
597
|
// Lazily access constants.spinner.
|
|
677
|
-
const {
|
|
678
|
-
|
|
679
|
-
|
|
598
|
+
const {
|
|
599
|
+
spinner
|
|
600
|
+
} = constants;
|
|
601
|
+
spinner.start(`Requesting ${fetchingDesc} from API...`);
|
|
602
|
+
let result;
|
|
680
603
|
try {
|
|
681
|
-
result = await value
|
|
604
|
+
result = await value;
|
|
682
605
|
|
|
683
606
|
// TODO: info, not success (looks weird when response is non-200)
|
|
684
|
-
spinner.successAndStop(
|
|
685
|
-
`Received API response (after requesting ${fetchingDesc}).`
|
|
686
|
-
)
|
|
607
|
+
spinner.successAndStop(`Received API response (after requesting ${fetchingDesc}).`);
|
|
687
608
|
} catch (e) {
|
|
688
|
-
spinner.failAndStop(`An error was thrown while requesting ${fetchingDesc}`)
|
|
689
|
-
debug.debugLog(`handleApiCall(${fetchingDesc}) threw error:\n`, e)
|
|
690
|
-
const message = `${e || 'No error message returned'}
|
|
691
|
-
const cause = `${e || 'No error message returned'}
|
|
609
|
+
spinner.failAndStop(`An error was thrown while requesting ${fetchingDesc}`);
|
|
610
|
+
debug.debugLog(`handleApiCall(${fetchingDesc}) threw error:\n`, e);
|
|
611
|
+
const message = `${e || 'No error message returned'}`;
|
|
612
|
+
const cause = `${e || 'No error message returned'}`;
|
|
692
613
|
return {
|
|
693
614
|
ok: false,
|
|
694
615
|
message: 'Socket API returned an error',
|
|
695
616
|
cause: `${message}${cause ? ` ( Reason: ${cause} )` : ''}`
|
|
696
|
-
}
|
|
617
|
+
};
|
|
697
618
|
} finally {
|
|
698
|
-
spinner.stop()
|
|
619
|
+
spinner.stop();
|
|
699
620
|
}
|
|
700
621
|
|
|
701
622
|
// Note: TS can't narrow down the type of result due to generics
|
|
702
623
|
if (result.success === false) {
|
|
703
|
-
const err = result
|
|
704
|
-
const message = `${err.error || 'No error message returned'}
|
|
705
|
-
debug.debugLog(`handleApiCall(${fetchingDesc}) bad response:\n`, err)
|
|
624
|
+
const err = result;
|
|
625
|
+
const message = `${err.error || 'No error message returned'}`;
|
|
626
|
+
debug.debugLog(`handleApiCall(${fetchingDesc}) bad response:\n`, err);
|
|
706
627
|
return {
|
|
707
628
|
ok: false,
|
|
708
629
|
message: 'Socket API returned an error',
|
|
@@ -710,35 +631,35 @@ async function handleApiCall(value, fetchingDesc) {
|
|
|
710
631
|
data: {
|
|
711
632
|
code: result.status
|
|
712
633
|
}
|
|
713
|
-
}
|
|
634
|
+
};
|
|
714
635
|
} else {
|
|
715
|
-
const ok = result
|
|
636
|
+
const ok = result;
|
|
716
637
|
return {
|
|
717
638
|
ok: true,
|
|
718
639
|
data: ok.data
|
|
719
|
-
}
|
|
640
|
+
};
|
|
720
641
|
}
|
|
721
642
|
}
|
|
722
643
|
async function handleApiCallNoSpinner(value, description) {
|
|
723
|
-
let result
|
|
644
|
+
let result;
|
|
724
645
|
try {
|
|
725
|
-
result = await value
|
|
646
|
+
result = await value;
|
|
726
647
|
} catch (e) {
|
|
727
|
-
debug.debugLog(`handleApiCall(${description}) threw error:\n`, e)
|
|
728
|
-
const message = `${e || 'No error message returned'}
|
|
729
|
-
const cause = `${e || 'No error message returned'}
|
|
648
|
+
debug.debugLog(`handleApiCall(${description}) threw error:\n`, e);
|
|
649
|
+
const message = `${e || 'No error message returned'}`;
|
|
650
|
+
const cause = `${e || 'No error message returned'}`;
|
|
730
651
|
return {
|
|
731
652
|
ok: false,
|
|
732
653
|
message: 'Socket API returned an error',
|
|
733
654
|
cause: `${message}${cause ? ` ( Reason: ${cause} )` : ''}`
|
|
734
|
-
}
|
|
655
|
+
};
|
|
735
656
|
}
|
|
736
657
|
|
|
737
658
|
// Note: TS can't narrow down the type of result due to generics
|
|
738
659
|
if (result.success === false) {
|
|
739
|
-
const err = result
|
|
740
|
-
const message = `${err.error || 'No error message returned'}
|
|
741
|
-
debug.debugLog(`handleApiCall(${description}) bad response:\n`, err)
|
|
660
|
+
const err = result;
|
|
661
|
+
const message = `${err.error || 'No error message returned'}`;
|
|
662
|
+
debug.debugLog(`handleApiCall(${description}) bad response:\n`, err);
|
|
742
663
|
return {
|
|
743
664
|
ok: false,
|
|
744
665
|
message: 'Socket API returned an error',
|
|
@@ -746,145 +667,140 @@ async function handleApiCallNoSpinner(value, description) {
|
|
|
746
667
|
data: {
|
|
747
668
|
code: result.status
|
|
748
669
|
}
|
|
749
|
-
}
|
|
670
|
+
};
|
|
750
671
|
} else {
|
|
751
|
-
const ok = result
|
|
672
|
+
const ok = result;
|
|
752
673
|
return {
|
|
753
674
|
ok: true,
|
|
754
675
|
data: ok.data
|
|
755
|
-
}
|
|
676
|
+
};
|
|
756
677
|
}
|
|
757
678
|
}
|
|
758
679
|
async function getErrorMessageForHttpStatusCode(code) {
|
|
759
680
|
if (code === 400) {
|
|
760
|
-
return 'One of the options passed might be incorrect'
|
|
681
|
+
return 'One of the options passed might be incorrect';
|
|
761
682
|
}
|
|
762
683
|
if (code === 403 || code === 401) {
|
|
763
|
-
return 'Your API token may not have the required permissions for this command or you might be trying to access (data from) an organization that is not linked to the API key you are logged in with'
|
|
684
|
+
return 'Your API token may not have the required permissions for this command or you might be trying to access (data from) an organization that is not linked to the API key you are logged in with';
|
|
764
685
|
}
|
|
765
686
|
if (code === 404) {
|
|
766
|
-
return 'The requested Socket API endpoint was not found (404) or there was no result for the requested parameters. If unexpected, this could be a temporary problem caused by an incident or a bug in the CLI. If the problem persists please let us know.'
|
|
687
|
+
return 'The requested Socket API endpoint was not found (404) or there was no result for the requested parameters. If unexpected, this could be a temporary problem caused by an incident or a bug in the CLI. If the problem persists please let us know.';
|
|
767
688
|
}
|
|
768
689
|
if (code === 500) {
|
|
769
|
-
return 'There was an unknown server side problem with your request. This ought to be temporary. Please let us know if this problem persists.'
|
|
690
|
+
return 'There was an unknown server side problem with your request. This ought to be temporary. Please let us know if this problem persists.';
|
|
770
691
|
}
|
|
771
|
-
return `Server responded with status code ${code}
|
|
692
|
+
return `Server responded with status code ${code}`;
|
|
772
693
|
}
|
|
773
694
|
|
|
774
695
|
// The API server that should be used for operations.
|
|
775
696
|
function getDefaultApiBaseUrl() {
|
|
776
697
|
// Lazily access constants.ENV.SOCKET_SECURITY_API_BASE_URL.
|
|
777
|
-
const SOCKET_SECURITY_API_BASE_URL =
|
|
778
|
-
|
|
779
|
-
const baseUrl =
|
|
780
|
-
SOCKET_SECURITY_API_BASE_URL || getConfigValueOrUndef('apiBaseUrl')
|
|
698
|
+
const SOCKET_SECURITY_API_BASE_URL = constants.ENV.SOCKET_SECURITY_API_BASE_URL;
|
|
699
|
+
const baseUrl = SOCKET_SECURITY_API_BASE_URL || getConfigValueOrUndef('apiBaseUrl');
|
|
781
700
|
if (strings.isNonEmptyString(baseUrl)) {
|
|
782
|
-
return baseUrl
|
|
701
|
+
return baseUrl;
|
|
783
702
|
}
|
|
784
703
|
// Lazily access constants.API_V0_URL.
|
|
785
|
-
const API_V0_URL = constants.API_V0_URL
|
|
786
|
-
return API_V0_URL
|
|
704
|
+
const API_V0_URL = constants.API_V0_URL;
|
|
705
|
+
return API_V0_URL;
|
|
787
706
|
}
|
|
788
707
|
async function queryApi(path, apiToken) {
|
|
789
|
-
const baseUrl = getDefaultApiBaseUrl() || ''
|
|
708
|
+
const baseUrl = getDefaultApiBaseUrl() || '';
|
|
790
709
|
if (!baseUrl) {
|
|
791
|
-
logger.logger.warn(
|
|
792
|
-
'API endpoint is not set and default was empty. Request is likely to fail.'
|
|
793
|
-
)
|
|
710
|
+
logger.logger.warn('API endpoint is not set and default was empty. Request is likely to fail.');
|
|
794
711
|
}
|
|
795
712
|
return await fetch(`${baseUrl}${baseUrl.endsWith('/') ? '' : '/'}${path}`, {
|
|
796
713
|
method: 'GET',
|
|
797
714
|
headers: {
|
|
798
715
|
Authorization: `Basic ${btoa(`${apiToken}:`)}`
|
|
799
716
|
}
|
|
800
|
-
})
|
|
717
|
+
});
|
|
801
718
|
}
|
|
802
719
|
async function queryApiSafeText(path, fetchSpinnerDesc) {
|
|
803
|
-
const apiToken = getDefaultToken()
|
|
720
|
+
const apiToken = getDefaultToken();
|
|
804
721
|
if (!apiToken) {
|
|
805
722
|
return {
|
|
806
723
|
ok: false,
|
|
807
724
|
message: 'Authentication Error',
|
|
808
|
-
cause:
|
|
809
|
-
|
|
810
|
-
}
|
|
725
|
+
cause: 'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.'
|
|
726
|
+
};
|
|
811
727
|
}
|
|
812
728
|
if (fetchSpinnerDesc) {
|
|
813
729
|
// Lazily access constants.spinner.
|
|
814
|
-
const {
|
|
815
|
-
|
|
730
|
+
const {
|
|
731
|
+
spinner
|
|
732
|
+
} = constants;
|
|
733
|
+
spinner.start(`Requesting ${fetchSpinnerDesc} from API...`);
|
|
816
734
|
}
|
|
817
|
-
let result
|
|
735
|
+
let result;
|
|
818
736
|
try {
|
|
819
|
-
result = await queryApi(path, apiToken)
|
|
737
|
+
result = await queryApi(path, apiToken);
|
|
820
738
|
if (fetchSpinnerDesc) {
|
|
821
739
|
// Lazily access constants.spinner.
|
|
822
|
-
const {
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
)
|
|
740
|
+
const {
|
|
741
|
+
spinner
|
|
742
|
+
} = constants;
|
|
743
|
+
spinner.successAndStop(`Received API response (after requesting ${fetchSpinnerDesc}).`);
|
|
826
744
|
}
|
|
827
745
|
} catch (e) {
|
|
828
746
|
if (fetchSpinnerDesc) {
|
|
829
747
|
// Lazily access constants.spinner.
|
|
830
|
-
const {
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
)
|
|
834
|
-
}
|
|
835
|
-
debug.debugLog('Error thrown trying to await queryApi():')
|
|
836
|
-
debug.debugLog(e)
|
|
837
|
-
const msg = e?.message
|
|
748
|
+
const {
|
|
749
|
+
spinner
|
|
750
|
+
} = constants;
|
|
751
|
+
spinner.failAndStop(`An error was thrown while requesting ${fetchSpinnerDesc}`);
|
|
752
|
+
}
|
|
753
|
+
debug.debugLog('Error thrown trying to await queryApi():');
|
|
754
|
+
debug.debugLog(e);
|
|
755
|
+
const msg = e?.message;
|
|
838
756
|
return {
|
|
839
757
|
ok: false,
|
|
840
758
|
message: 'API Request failed to complete',
|
|
841
|
-
...(msg
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
: {})
|
|
846
|
-
}
|
|
759
|
+
...(msg ? {
|
|
760
|
+
cause: msg
|
|
761
|
+
} : {})
|
|
762
|
+
};
|
|
847
763
|
}
|
|
848
764
|
if (!result.ok) {
|
|
849
|
-
const cause = await getErrorMessageForHttpStatusCode(result.status)
|
|
765
|
+
const cause = await getErrorMessageForHttpStatusCode(result.status);
|
|
850
766
|
return {
|
|
851
767
|
ok: false,
|
|
852
768
|
message: 'Socket API returned an error',
|
|
853
769
|
cause: `${result.statusText}${cause ? ` (cause: ${cause})` : ''}`
|
|
854
|
-
}
|
|
770
|
+
};
|
|
855
771
|
}
|
|
856
772
|
try {
|
|
857
|
-
const data = await result.text()
|
|
773
|
+
const data = await result.text();
|
|
858
774
|
return {
|
|
859
775
|
ok: true,
|
|
860
776
|
data
|
|
861
|
-
}
|
|
777
|
+
};
|
|
862
778
|
} catch (e) {
|
|
863
|
-
debug.debugLog('Error thrown trying to await result.text():')
|
|
864
|
-
debug.debugLog(e)
|
|
779
|
+
debug.debugLog('Error thrown trying to await result.text():');
|
|
780
|
+
debug.debugLog(e);
|
|
865
781
|
return {
|
|
866
782
|
ok: false,
|
|
867
783
|
message: 'API Request failed to complete',
|
|
868
784
|
cause: 'There was an unexpected error trying to read the response text'
|
|
869
|
-
}
|
|
785
|
+
};
|
|
870
786
|
}
|
|
871
787
|
}
|
|
872
788
|
async function queryApiSafeJson(path, fetchSpinnerDesc = '') {
|
|
873
|
-
const result = await queryApiSafeText(path, fetchSpinnerDesc)
|
|
789
|
+
const result = await queryApiSafeText(path, fetchSpinnerDesc);
|
|
874
790
|
if (!result.ok) {
|
|
875
|
-
return result
|
|
791
|
+
return result;
|
|
876
792
|
}
|
|
877
793
|
try {
|
|
878
794
|
return {
|
|
879
795
|
ok: true,
|
|
880
796
|
data: JSON.parse(result.data)
|
|
881
|
-
}
|
|
797
|
+
};
|
|
882
798
|
} catch (e) {
|
|
883
799
|
return {
|
|
884
800
|
ok: false,
|
|
885
801
|
message: 'Server returned invalid JSON',
|
|
886
802
|
cause: `Please report this. JSON.parse threw an error over the following response: \`${(result.data?.slice?.(0, 100) || '<empty>').trim() + (result.data?.length > 100 ? '...' : '')}\``
|
|
887
|
-
}
|
|
803
|
+
};
|
|
888
804
|
}
|
|
889
805
|
}
|
|
890
806
|
|
|
@@ -893,129 +809,120 @@ function mdTableStringNumber(title1, title2, obj) {
|
|
|
893
809
|
// | ----------- | ------ |
|
|
894
810
|
// | Header | 201464 |
|
|
895
811
|
// | Paragraph | 18 |
|
|
896
|
-
let mw1 = title1.length
|
|
897
|
-
let mw2 = title2.length
|
|
812
|
+
let mw1 = title1.length;
|
|
813
|
+
let mw2 = title2.length;
|
|
898
814
|
for (const [key, value] of Object.entries(obj)) {
|
|
899
|
-
mw1 = Math.max(mw1, key.length)
|
|
900
|
-
mw2 = Math.max(mw2, String(value ?? '').length)
|
|
815
|
+
mw1 = Math.max(mw1, key.length);
|
|
816
|
+
mw2 = Math.max(mw2, String(value ?? '').length);
|
|
901
817
|
}
|
|
902
|
-
const lines = []
|
|
903
|
-
lines.push(`| ${title1.padEnd(mw1, ' ')} | ${title2.padEnd(mw2)} |`)
|
|
904
|
-
lines.push(`| ${'-'.repeat(mw1)} | ${'-'.repeat(mw2)} |`)
|
|
818
|
+
const lines = [];
|
|
819
|
+
lines.push(`| ${title1.padEnd(mw1, ' ')} | ${title2.padEnd(mw2)} |`);
|
|
820
|
+
lines.push(`| ${'-'.repeat(mw1)} | ${'-'.repeat(mw2)} |`);
|
|
905
821
|
for (const [key, value] of Object.entries(obj)) {
|
|
906
|
-
lines.push(
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
// This is saying "an array of strings and the strings are a valid key of elements of T"
|
|
916
|
-
// In turn, T is defined above as the audit log event type from our OpenAPI docs.
|
|
917
|
-
cols,
|
|
918
|
-
titles = cols
|
|
919
|
-
) {
|
|
822
|
+
lines.push(`| ${key.padEnd(mw1, ' ')} | ${String(value ?? '').padStart(mw2, ' ')} |`);
|
|
823
|
+
}
|
|
824
|
+
lines.push(`| ${'-'.repeat(mw1)} | ${'-'.repeat(mw2)} |`);
|
|
825
|
+
return lines.join('\n');
|
|
826
|
+
}
|
|
827
|
+
function mdTable(logs,
|
|
828
|
+
// This is saying "an array of strings and the strings are a valid key of elements of T"
|
|
829
|
+
// In turn, T is defined above as the audit log event type from our OpenAPI docs.
|
|
830
|
+
cols, titles = cols) {
|
|
920
831
|
// Max col width required to fit all data in that column
|
|
921
|
-
const cws = cols.map(col => col.length)
|
|
832
|
+
const cws = cols.map(col => col.length);
|
|
922
833
|
for (const log of logs) {
|
|
923
|
-
for (let i = 0, {
|
|
834
|
+
for (let i = 0, {
|
|
835
|
+
length
|
|
836
|
+
} = cols; i < length; i += 1) {
|
|
924
837
|
// @ts-ignore
|
|
925
|
-
const val = log[cols[i] ?? ''] ?? ''
|
|
926
|
-
cws[i] = Math.max(
|
|
927
|
-
cws[i] ?? 0,
|
|
928
|
-
String(val).length,
|
|
929
|
-
(titles[i] || '').length
|
|
930
|
-
)
|
|
838
|
+
const val = log[cols[i] ?? ''] ?? '';
|
|
839
|
+
cws[i] = Math.max(cws[i] ?? 0, String(val).length, (titles[i] || '').length);
|
|
931
840
|
}
|
|
932
841
|
}
|
|
933
|
-
let div = '|'
|
|
842
|
+
let div = '|';
|
|
934
843
|
for (const cw of cws) {
|
|
935
|
-
div += ' ' + '-'.repeat(cw) + ' |'
|
|
844
|
+
div += ' ' + '-'.repeat(cw) + ' |';
|
|
936
845
|
}
|
|
937
|
-
let header = '|'
|
|
938
|
-
for (let i = 0, {
|
|
939
|
-
|
|
846
|
+
let header = '|';
|
|
847
|
+
for (let i = 0, {
|
|
848
|
+
length
|
|
849
|
+
} = titles; i < length; i += 1) {
|
|
850
|
+
header += ' ' + String(titles[i]).padEnd(cws[i] ?? 0, ' ') + ' |';
|
|
940
851
|
}
|
|
941
|
-
let body = ''
|
|
852
|
+
let body = '';
|
|
942
853
|
for (const log of logs) {
|
|
943
|
-
body += '|'
|
|
944
|
-
for (let i = 0, {
|
|
854
|
+
body += '|';
|
|
855
|
+
for (let i = 0, {
|
|
856
|
+
length
|
|
857
|
+
} = cols; i < length; i += 1) {
|
|
945
858
|
// @ts-ignore
|
|
946
|
-
const val = log[cols[i] ?? ''] ?? ''
|
|
947
|
-
body += ' ' + String(val).padEnd(cws[i] ?? 0, ' ') + ' |'
|
|
859
|
+
const val = log[cols[i] ?? ''] ?? '';
|
|
860
|
+
body += ' ' + String(val).padEnd(cws[i] ?? 0, ' ') + ' |';
|
|
948
861
|
}
|
|
949
|
-
body += '\n'
|
|
862
|
+
body += '\n';
|
|
950
863
|
}
|
|
951
|
-
return [div, header, div, body.trim(), div].filter(s => !!s.trim()).join('\n')
|
|
864
|
+
return [div, header, div, body.trim(), div].filter(s => !!s.trim()).join('\n');
|
|
952
865
|
}
|
|
953
|
-
function mdTableOfPairs(
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
cols
|
|
958
|
-
) {
|
|
866
|
+
function mdTableOfPairs(arr,
|
|
867
|
+
// This is saying "an array of strings and the strings are a valid key of elements of T"
|
|
868
|
+
// In turn, T is defined above as the audit log event type from our OpenAPI docs.
|
|
869
|
+
cols) {
|
|
959
870
|
// Max col width required to fit all data in that column
|
|
960
|
-
const cws = cols.map(col => col.length)
|
|
871
|
+
const cws = cols.map(col => col.length);
|
|
961
872
|
for (const [key, val] of arr) {
|
|
962
|
-
cws[0] = Math.max(cws[0] ?? 0, String(key).length)
|
|
963
|
-
cws[1] = Math.max(cws[1] ?? 0, String(val ?? '').length)
|
|
873
|
+
cws[0] = Math.max(cws[0] ?? 0, String(key).length);
|
|
874
|
+
cws[1] = Math.max(cws[1] ?? 0, String(val ?? '').length);
|
|
964
875
|
}
|
|
965
|
-
let div = '|'
|
|
876
|
+
let div = '|';
|
|
966
877
|
for (const cw of cws) {
|
|
967
|
-
div += ' ' + '-'.repeat(cw) + ' |'
|
|
878
|
+
div += ' ' + '-'.repeat(cw) + ' |';
|
|
968
879
|
}
|
|
969
|
-
let header = '|'
|
|
970
|
-
for (let i = 0, {
|
|
971
|
-
|
|
880
|
+
let header = '|';
|
|
881
|
+
for (let i = 0, {
|
|
882
|
+
length
|
|
883
|
+
} = cols; i < length; i += 1) {
|
|
884
|
+
header += ' ' + String(cols[i]).padEnd(cws[i] ?? 0, ' ') + ' |';
|
|
972
885
|
}
|
|
973
|
-
let body = ''
|
|
886
|
+
let body = '';
|
|
974
887
|
for (const [key, val] of arr) {
|
|
975
|
-
body += '|'
|
|
976
|
-
body += ' ' + String(key).padEnd(cws[0] ?? 0, ' ') + ' |'
|
|
977
|
-
body += ' ' + String(val ?? '').padEnd(cws[1] ?? 0, ' ') + ' |'
|
|
978
|
-
body += '\n'
|
|
888
|
+
body += '|';
|
|
889
|
+
body += ' ' + String(key).padEnd(cws[0] ?? 0, ' ') + ' |';
|
|
890
|
+
body += ' ' + String(val ?? '').padEnd(cws[1] ?? 0, ' ') + ' |';
|
|
891
|
+
body += '\n';
|
|
979
892
|
}
|
|
980
|
-
return [div, header, div, body.trim(), div].filter(s => !!s.trim()).join('\n')
|
|
893
|
+
return [div, header, div, body.trim(), div].filter(s => !!s.trim()).join('\n');
|
|
981
894
|
}
|
|
982
895
|
|
|
983
896
|
// Serialize the final result object before printing it
|
|
984
897
|
// All commands that support the --json flag should call this before printing
|
|
985
898
|
function serializeResultJson(data) {
|
|
986
899
|
if (typeof data !== 'object' || !data) {
|
|
987
|
-
process.exitCode = 1
|
|
900
|
+
process.exitCode = 1;
|
|
988
901
|
// We should not allow to expect the json value to be "null", or a boolean/number/string, even if they are valid "json".
|
|
989
|
-
const msg =
|
|
990
|
-
|
|
991
|
-
debug.debugLog('typeof data=', typeof data)
|
|
902
|
+
const msg = 'There was a problem converting the data set to JSON. The JSON was not an object. Please try again without --json';
|
|
903
|
+
debug.debugLog('typeof data=', typeof data);
|
|
992
904
|
if (typeof data !== 'object' && data) {
|
|
993
|
-
debug.debugLog('data:\n', data)
|
|
905
|
+
debug.debugLog('data:\n', data);
|
|
994
906
|
}
|
|
995
|
-
return (
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
}).trim() + '\n'
|
|
1001
|
-
)
|
|
907
|
+
return JSON.stringify({
|
|
908
|
+
ok: false,
|
|
909
|
+
message: 'Unable to serialize JSON',
|
|
910
|
+
data: msg
|
|
911
|
+
}).trim() + '\n';
|
|
1002
912
|
}
|
|
1003
913
|
try {
|
|
1004
|
-
return JSON.stringify(data, null, 2).trim() + '\n'
|
|
914
|
+
return JSON.stringify(data, null, 2).trim() + '\n';
|
|
1005
915
|
} catch (e) {
|
|
1006
|
-
debug.debugLog('Error:\n', e)
|
|
1007
|
-
process.exitCode = 1
|
|
916
|
+
debug.debugLog('Error:\n', e);
|
|
917
|
+
process.exitCode = 1;
|
|
1008
918
|
// This could be caused by circular references, which is an "us" problem
|
|
1009
|
-
const msg =
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
JSON
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
data: msg
|
|
1017
|
-
}).trim() + '\n'
|
|
1018
|
-
)
|
|
919
|
+
const msg = 'There was a problem converting the data set to JSON. Please try again without --json';
|
|
920
|
+
logger.logger.fail(msg);
|
|
921
|
+
return JSON.stringify({
|
|
922
|
+
ok: false,
|
|
923
|
+
message: 'Unable to serialize JSON',
|
|
924
|
+
data: msg
|
|
925
|
+
}).trim() + '\n';
|
|
1019
926
|
}
|
|
1020
927
|
}
|
|
1021
928
|
|
|
@@ -1050,7 +957,7 @@ const commonFlags = {
|
|
|
1050
957
|
shortFlag: 's',
|
|
1051
958
|
description: 'Make the CLI less chatty'
|
|
1052
959
|
}
|
|
1053
|
-
}
|
|
960
|
+
};
|
|
1054
961
|
const outputFlags = {
|
|
1055
962
|
json: {
|
|
1056
963
|
type: 'boolean',
|
|
@@ -1064,7 +971,7 @@ const outputFlags = {
|
|
|
1064
971
|
default: false,
|
|
1065
972
|
description: 'Output result as markdown'
|
|
1066
973
|
}
|
|
1067
|
-
}
|
|
974
|
+
};
|
|
1068
975
|
const validationFlags = {
|
|
1069
976
|
all: {
|
|
1070
977
|
type: 'boolean',
|
|
@@ -1076,95 +983,86 @@ const validationFlags = {
|
|
|
1076
983
|
default: false,
|
|
1077
984
|
description: 'Exits with an error code if any matching issues are found'
|
|
1078
985
|
}
|
|
1079
|
-
}
|
|
986
|
+
};
|
|
1080
987
|
|
|
1081
988
|
function checkCommandInput(outputKind, ...checks) {
|
|
1082
989
|
if (checks.every(d => d.test)) {
|
|
1083
|
-
return true
|
|
990
|
+
return true;
|
|
1084
991
|
}
|
|
1085
|
-
const msg = ['Please review the input requirements and try again', '']
|
|
992
|
+
const msg = ['Please review the input requirements and try again', ''];
|
|
1086
993
|
for (const d of checks) {
|
|
1087
994
|
// If nook, then ignore when test is ok
|
|
1088
995
|
if (d.nook && d.test) {
|
|
1089
|
-
continue
|
|
996
|
+
continue;
|
|
1090
997
|
}
|
|
1091
|
-
const lines = d.message.split('\n')
|
|
1092
|
-
const {
|
|
998
|
+
const lines = d.message.split('\n');
|
|
999
|
+
const {
|
|
1000
|
+
length: lineCount
|
|
1001
|
+
} = lines;
|
|
1093
1002
|
if (!lineCount) {
|
|
1094
|
-
continue
|
|
1003
|
+
continue;
|
|
1095
1004
|
}
|
|
1096
1005
|
// If the message has newlines then format the first line with the input
|
|
1097
1006
|
// expectation and the rest indented below it.
|
|
1098
|
-
msg.push(
|
|
1099
|
-
` - ${lines[0]} (${d.test ? vendor.yoctocolorsCjsExports.green(d.pass) : vendor.yoctocolorsCjsExports.red(d.fail)})`
|
|
1100
|
-
)
|
|
1007
|
+
msg.push(` - ${lines[0]} (${d.test ? vendor.yoctocolorsCjsExports.green(d.pass) : vendor.yoctocolorsCjsExports.red(d.fail)})`);
|
|
1101
1008
|
if (lineCount > 1) {
|
|
1102
|
-
msg.push(...lines.slice(1).map(str => ` ${str}`))
|
|
1009
|
+
msg.push(...lines.slice(1).map(str => ` ${str}`));
|
|
1103
1010
|
}
|
|
1104
|
-
msg.push('')
|
|
1011
|
+
msg.push('');
|
|
1105
1012
|
}
|
|
1106
1013
|
|
|
1107
1014
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
1108
1015
|
// options or missing arguments.
|
|
1109
1016
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
1110
|
-
process.exitCode = 2
|
|
1017
|
+
process.exitCode = 2;
|
|
1111
1018
|
if (outputKind === 'json') {
|
|
1112
|
-
logger.logger.log(
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
})
|
|
1118
|
-
)
|
|
1019
|
+
logger.logger.log(serializeResultJson({
|
|
1020
|
+
ok: false,
|
|
1021
|
+
message: 'Input error',
|
|
1022
|
+
data: msg.join('\n')
|
|
1023
|
+
}));
|
|
1119
1024
|
} else {
|
|
1120
|
-
logger.logger.fail(failMsgWithBadge('Input error', msg.join('\n')))
|
|
1025
|
+
logger.logger.fail(failMsgWithBadge('Input error', msg.join('\n')));
|
|
1121
1026
|
}
|
|
1122
|
-
return false
|
|
1027
|
+
return false;
|
|
1123
1028
|
}
|
|
1124
1029
|
|
|
1125
1030
|
function getOutputKind(json, markdown) {
|
|
1126
1031
|
if (json) {
|
|
1127
|
-
return 'json'
|
|
1032
|
+
return 'json';
|
|
1128
1033
|
}
|
|
1129
1034
|
if (markdown) {
|
|
1130
|
-
return 'markdown'
|
|
1035
|
+
return 'markdown';
|
|
1131
1036
|
}
|
|
1132
|
-
return 'text'
|
|
1037
|
+
return 'text';
|
|
1133
1038
|
}
|
|
1134
1039
|
|
|
1135
|
-
function getFlagListOutput(list, indent, {
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
)
|
|
1152
|
-
let result = ''
|
|
1153
|
-
const names = Object.keys(list).sort()
|
|
1040
|
+
function getFlagListOutput(list, indent, {
|
|
1041
|
+
keyPrefix = '--',
|
|
1042
|
+
padName
|
|
1043
|
+
} = {}) {
|
|
1044
|
+
return getHelpListOutput({
|
|
1045
|
+
...list
|
|
1046
|
+
}, indent, {
|
|
1047
|
+
keyPrefix,
|
|
1048
|
+
padName
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
function getHelpListOutput(list, indent, {
|
|
1052
|
+
keyPrefix = '',
|
|
1053
|
+
padName = 18
|
|
1054
|
+
} = {}) {
|
|
1055
|
+
let result = '';
|
|
1056
|
+
const names = Object.keys(list).sort();
|
|
1154
1057
|
for (const name of names) {
|
|
1155
|
-
const entry = list[name]
|
|
1058
|
+
const entry = list[name];
|
|
1156
1059
|
if (entry && 'hidden' in entry && entry?.hidden) {
|
|
1157
|
-
continue
|
|
1060
|
+
continue;
|
|
1158
1061
|
}
|
|
1159
|
-
const description =
|
|
1160
|
-
|
|
1161
|
-
result +=
|
|
1162
|
-
''.padEnd(indent) +
|
|
1163
|
-
(keyPrefix + name).padEnd(padName) +
|
|
1164
|
-
description +
|
|
1165
|
-
'\n'
|
|
1062
|
+
const description = (typeof entry === 'object' ? entry.description : entry) || '';
|
|
1063
|
+
result += ''.padEnd(indent) + (keyPrefix + name).padEnd(padName) + description + '\n';
|
|
1166
1064
|
}
|
|
1167
|
-
return result.trim() || '(none)'
|
|
1065
|
+
return result.trim() || '(none)';
|
|
1168
1066
|
}
|
|
1169
1067
|
|
|
1170
1068
|
async function meowWithSubcommands(subcommands, options) {
|
|
@@ -1178,30 +1076,26 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1178
1076
|
} = {
|
|
1179
1077
|
__proto__: null,
|
|
1180
1078
|
...options
|
|
1181
|
-
}
|
|
1182
|
-
const [commandOrAliasName_, ...rawCommandArgv] = argv
|
|
1183
|
-
let commandOrAliasName = commandOrAliasName_
|
|
1079
|
+
};
|
|
1080
|
+
const [commandOrAliasName_, ...rawCommandArgv] = argv;
|
|
1081
|
+
let commandOrAliasName = commandOrAliasName_;
|
|
1184
1082
|
if (!commandOrAliasName && defaultSub) {
|
|
1185
|
-
commandOrAliasName = defaultSub
|
|
1083
|
+
commandOrAliasName = defaultSub;
|
|
1186
1084
|
}
|
|
1187
1085
|
const flags = {
|
|
1188
1086
|
...commonFlags,
|
|
1189
1087
|
...additionalOptions.flags
|
|
1190
|
-
}
|
|
1088
|
+
};
|
|
1191
1089
|
|
|
1192
1090
|
// No further args or first arg is a flag (shrug)
|
|
1193
|
-
if (
|
|
1194
|
-
name === 'socket' &&
|
|
1195
|
-
(!commandOrAliasName || commandOrAliasName?.startsWith('-'))
|
|
1196
|
-
) {
|
|
1091
|
+
if (name === 'socket' && (!commandOrAliasName || commandOrAliasName?.startsWith('-'))) {
|
|
1197
1092
|
flags['dryRun'] = {
|
|
1198
1093
|
type: 'boolean',
|
|
1199
1094
|
default: false,
|
|
1200
1095
|
hidden: false,
|
|
1201
1096
|
// Only show on root
|
|
1202
|
-
description:
|
|
1203
|
-
|
|
1204
|
-
}
|
|
1097
|
+
description: 'Do input validation for a command and exit 0 when input is ok. Every command should support this flag (not shown on help screens)'
|
|
1098
|
+
};
|
|
1205
1099
|
}
|
|
1206
1100
|
|
|
1207
1101
|
// This is basically a dry-run parse of cli args and flags. We use this to
|
|
@@ -1216,130 +1110,113 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1216
1110
|
// We will emit help when we're ready
|
|
1217
1111
|
// Plus, if we allow this then meow() can just exit here.
|
|
1218
1112
|
autoHelp: false
|
|
1219
|
-
})
|
|
1113
|
+
});
|
|
1220
1114
|
|
|
1221
1115
|
// Hard override the config if instructed to do so.
|
|
1222
1116
|
// The env var overrides the --flag, which overrides the persisted config
|
|
1223
1117
|
// Also, when either of these are used, config updates won't persist.
|
|
1224
|
-
let configOverrideResult
|
|
1118
|
+
let configOverrideResult;
|
|
1225
1119
|
// Lazily access constants.ENV.SOCKET_CLI_CONFIG.
|
|
1226
1120
|
if (constants.ENV.SOCKET_CLI_CONFIG) {
|
|
1227
1121
|
configOverrideResult = overrideCachedConfig(
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
)
|
|
1122
|
+
// Lazily access constants.ENV.SOCKET_CLI_CONFIG.
|
|
1123
|
+
constants.ENV.SOCKET_CLI_CONFIG);
|
|
1231
1124
|
} else if (cli1.flags['config']) {
|
|
1232
|
-
configOverrideResult = overrideCachedConfig(
|
|
1233
|
-
String(cli1.flags['config'] || '')
|
|
1234
|
-
)
|
|
1125
|
+
configOverrideResult = overrideCachedConfig(String(cli1.flags['config'] || ''));
|
|
1235
1126
|
}
|
|
1236
1127
|
|
|
1237
1128
|
// Lazily access constants.ENV.SOCKET_CLI_NO_API_TOKEN.
|
|
1238
1129
|
if (constants.ENV.SOCKET_CLI_NO_API_TOKEN) {
|
|
1239
1130
|
// This overrides the config override and even the explicit token env var.
|
|
1240
1131
|
// The config will be marked as readOnly to prevent persisting it.
|
|
1241
|
-
overrideConfigApiToken(undefined)
|
|
1132
|
+
overrideConfigApiToken(undefined);
|
|
1242
1133
|
} else {
|
|
1243
1134
|
// Lazily access constants.ENV.SOCKET_SECURITY_API_TOKEN.
|
|
1244
|
-
const tokenOverride = constants.ENV.SOCKET_SECURITY_API_TOKEN
|
|
1135
|
+
const tokenOverride = constants.ENV.SOCKET_SECURITY_API_TOKEN;
|
|
1245
1136
|
if (tokenOverride) {
|
|
1246
1137
|
// This will set the token (even if there was a config override) and
|
|
1247
1138
|
// set it to readOnly, making sure the temp token won't be persisted.
|
|
1248
|
-
overrideConfigApiToken(tokenOverride)
|
|
1139
|
+
overrideConfigApiToken(tokenOverride);
|
|
1249
1140
|
}
|
|
1250
1141
|
}
|
|
1251
1142
|
if (configOverrideResult?.ok === false) {
|
|
1252
|
-
emitBanner(name)
|
|
1253
|
-
logger.logger.fail(configOverrideResult.message)
|
|
1254
|
-
process.exitCode = 2
|
|
1255
|
-
return
|
|
1143
|
+
emitBanner(name);
|
|
1144
|
+
logger.logger.fail(configOverrideResult.message);
|
|
1145
|
+
process.exitCode = 2;
|
|
1146
|
+
return;
|
|
1256
1147
|
}
|
|
1257
1148
|
|
|
1258
1149
|
// If we got at least some args, then lets find out if we can find a command.
|
|
1259
1150
|
if (commandOrAliasName) {
|
|
1260
|
-
const alias = aliases[commandOrAliasName]
|
|
1151
|
+
const alias = aliases[commandOrAliasName];
|
|
1261
1152
|
// First: Resolve argv data from alias if its an alias that's been given.
|
|
1262
|
-
const [commandName, ...commandArgv] = alias
|
|
1263
|
-
? [...alias.argv, ...rawCommandArgv]
|
|
1264
|
-
: [commandOrAliasName, ...rawCommandArgv]
|
|
1153
|
+
const [commandName, ...commandArgv] = alias ? [...alias.argv, ...rawCommandArgv] : [commandOrAliasName, ...rawCommandArgv];
|
|
1265
1154
|
// Second: Find a command definition using that data.
|
|
1266
|
-
const commandDefinition = commandName ? subcommands[commandName] : undefined
|
|
1155
|
+
const commandDefinition = commandName ? subcommands[commandName] : undefined;
|
|
1267
1156
|
// Third: If a valid command has been found, then we run it...
|
|
1268
1157
|
if (commandDefinition) {
|
|
1269
1158
|
return await commandDefinition.run(commandArgv, importMeta, {
|
|
1270
1159
|
parentName: name
|
|
1271
|
-
})
|
|
1160
|
+
});
|
|
1272
1161
|
}
|
|
1273
1162
|
}
|
|
1274
1163
|
if (isTestingV1()) {
|
|
1275
|
-
delete subcommands['diff-scan']
|
|
1276
|
-
delete subcommands['info']
|
|
1277
|
-
delete subcommands['report']
|
|
1164
|
+
delete subcommands['diff-scan'];
|
|
1165
|
+
delete subcommands['info'];
|
|
1166
|
+
delete subcommands['report'];
|
|
1278
1167
|
}
|
|
1279
1168
|
|
|
1280
1169
|
// Parse it again. Config overrides should now be applied (may affect help).
|
|
1281
|
-
const cli2 = vendor.meow(
|
|
1282
|
-
`
|
|
1170
|
+
const cli2 = vendor.meow(`
|
|
1283
1171
|
Usage
|
|
1284
1172
|
$ ${name} <command>
|
|
1285
1173
|
|
|
1286
1174
|
Commands
|
|
1287
|
-
${getHelpListOutput(
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
return subcommand && !subcommand.hidden
|
|
1303
|
-
})
|
|
1304
|
-
)
|
|
1305
|
-
)
|
|
1306
|
-
},
|
|
1307
|
-
6
|
|
1308
|
-
)}
|
|
1175
|
+
${getHelpListOutput({
|
|
1176
|
+
...objects.toSortedObject(Object.fromEntries(Object.entries(subcommands).filter(({
|
|
1177
|
+
1: subcommand
|
|
1178
|
+
}) => !subcommand.hidden))),
|
|
1179
|
+
...objects.toSortedObject(Object.fromEntries(Object.entries(aliases).filter(({
|
|
1180
|
+
1: alias
|
|
1181
|
+
}) => {
|
|
1182
|
+
const {
|
|
1183
|
+
hidden
|
|
1184
|
+
} = alias;
|
|
1185
|
+
const cmdName = hidden ? '' : alias.argv[0];
|
|
1186
|
+
const subcommand = cmdName ? subcommands[cmdName] : undefined;
|
|
1187
|
+
return subcommand && !subcommand.hidden;
|
|
1188
|
+
})))
|
|
1189
|
+
}, 6)}
|
|
1309
1190
|
|
|
1310
1191
|
Options
|
|
1311
1192
|
${getFlagListOutput(flags, 6)}
|
|
1312
1193
|
|
|
1313
1194
|
Examples
|
|
1314
1195
|
$ ${name} --help
|
|
1315
|
-
`,
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
}
|
|
1327
|
-
)
|
|
1196
|
+
`, {
|
|
1197
|
+
argv,
|
|
1198
|
+
importMeta,
|
|
1199
|
+
...additionalOptions,
|
|
1200
|
+
flags,
|
|
1201
|
+
// Do not strictly check for flags here.
|
|
1202
|
+
allowUnknownFlags: true,
|
|
1203
|
+
// We will emit help when we're ready
|
|
1204
|
+
// Plus, if we allow this then meow() can just exit here.
|
|
1205
|
+
autoHelp: false
|
|
1206
|
+
});
|
|
1328
1207
|
|
|
1329
1208
|
// ...else we provide basic instructions and help.
|
|
1330
1209
|
if (!cli2.flags['silent']) {
|
|
1331
|
-
emitBanner(name)
|
|
1210
|
+
emitBanner(name);
|
|
1332
1211
|
}
|
|
1333
1212
|
if (!cli2.flags['help'] && cli2.flags['dryRun']) {
|
|
1334
|
-
process.exitCode = 0
|
|
1213
|
+
process.exitCode = 0;
|
|
1335
1214
|
// Lazily access constants.DRY_RUN_LABEL.
|
|
1336
|
-
logger.logger.log(
|
|
1337
|
-
`${constants.DRY_RUN_LABEL}: No-op, call a sub-command; ok`
|
|
1338
|
-
)
|
|
1215
|
+
logger.logger.log(`${constants.DRY_RUN_LABEL}: No-op, call a sub-command; ok`);
|
|
1339
1216
|
} else {
|
|
1340
1217
|
// When you explicitly request --help, the command should be successful
|
|
1341
1218
|
// so we exit(0). If we do it because we need more input, we exit(2).
|
|
1342
|
-
cli2.showHelp(cli2.flags['help'] ? 0 : 2)
|
|
1219
|
+
cli2.showHelp(cli2.flags['help'] ? 0 : 2);
|
|
1343
1220
|
}
|
|
1344
1221
|
}
|
|
1345
1222
|
|
|
@@ -1354,7 +1231,7 @@ function meowOrExit({
|
|
|
1354
1231
|
importMeta,
|
|
1355
1232
|
parentName
|
|
1356
1233
|
}) {
|
|
1357
|
-
const command = `${parentName} ${config.commandName}
|
|
1234
|
+
const command = `${parentName} ${config.commandName}`;
|
|
1358
1235
|
|
|
1359
1236
|
// This exits if .printHelp() is called either by meow itself or by us.
|
|
1360
1237
|
const cli = vendor.meow({
|
|
@@ -1366,9 +1243,9 @@ function meowOrExit({
|
|
|
1366
1243
|
allowUnknownFlags: true,
|
|
1367
1244
|
// meow will exit(1) before printing the banner
|
|
1368
1245
|
autoHelp: false // meow will exit(0) before printing the banner
|
|
1369
|
-
})
|
|
1246
|
+
});
|
|
1370
1247
|
if (!cli.flags['silent']) {
|
|
1371
|
-
emitBanner(command)
|
|
1248
|
+
emitBanner(command);
|
|
1372
1249
|
}
|
|
1373
1250
|
if (!allowUnknownFlags) {
|
|
1374
1251
|
// Run meow specifically with the flag setting. It will exit(2) if an
|
|
@@ -1381,15 +1258,15 @@ function meowOrExit({
|
|
|
1381
1258
|
flags: config.flags,
|
|
1382
1259
|
allowUnknownFlags: false,
|
|
1383
1260
|
autoHelp: false
|
|
1384
|
-
})
|
|
1261
|
+
});
|
|
1385
1262
|
}
|
|
1386
1263
|
if (cli.flags['help']) {
|
|
1387
|
-
cli.showHelp(0)
|
|
1264
|
+
cli.showHelp(0);
|
|
1388
1265
|
}
|
|
1389
1266
|
// Now test for help state. Run meow again. If it exits now, it must be due
|
|
1390
1267
|
// to wanting to print the help screen. But it would exit(0) and we want a
|
|
1391
1268
|
// consistent exit(2) for that case (missing input). TODO: move away from meow
|
|
1392
|
-
process.exitCode = 2
|
|
1269
|
+
process.exitCode = 2;
|
|
1393
1270
|
vendor.meow({
|
|
1394
1271
|
argv,
|
|
1395
1272
|
description: config.description,
|
|
@@ -1398,10 +1275,10 @@ function meowOrExit({
|
|
|
1398
1275
|
flags: config.flags,
|
|
1399
1276
|
allowUnknownFlags: Boolean(allowUnknownFlags),
|
|
1400
1277
|
autoHelp: false
|
|
1401
|
-
})
|
|
1278
|
+
});
|
|
1402
1279
|
// Ok, no help, reset to default.
|
|
1403
|
-
process.exitCode = 0
|
|
1404
|
-
return cli
|
|
1280
|
+
process.exitCode = 0;
|
|
1281
|
+
return cli;
|
|
1405
1282
|
}
|
|
1406
1283
|
function emitBanner(name) {
|
|
1407
1284
|
// Print a banner at the top of each command.
|
|
@@ -1412,375 +1289,330 @@ function emitBanner(name) {
|
|
|
1412
1289
|
// and pipe the result to other tools. By emitting the banner over stderr
|
|
1413
1290
|
// you can do something like `socket scan view xyz | jq | process`.
|
|
1414
1291
|
// The spinner also emits over stderr for example.
|
|
1415
|
-
logger.logger.error(getAsciiHeader(name))
|
|
1292
|
+
logger.logger.error(getAsciiHeader(name));
|
|
1416
1293
|
}
|
|
1417
1294
|
function getAsciiHeader(command) {
|
|
1418
1295
|
// Note: In tests we return <redacted> because otherwise snapshots will fail.
|
|
1419
|
-
const {
|
|
1296
|
+
const {
|
|
1297
|
+
REDACTED
|
|
1298
|
+
} = constants;
|
|
1420
1299
|
// Lazily access constants.ENV.VITEST.
|
|
1421
|
-
const redacting = constants.ENV.VITEST
|
|
1422
|
-
const cliVersion = redacting
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
const
|
|
1427
|
-
const
|
|
1428
|
-
const
|
|
1429
|
-
const
|
|
1430
|
-
const
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
)
|
|
1434
|
-
: ''
|
|
1435
|
-
const shownToken = redacting ? REDACTED : getVisibleTokenPrefix() || 'no'
|
|
1436
|
-
const relCwd = redacting
|
|
1437
|
-
? REDACTED
|
|
1438
|
-
: path$1.normalizePath(
|
|
1439
|
-
process
|
|
1440
|
-
.cwd()
|
|
1441
|
-
.replace(
|
|
1442
|
-
new RegExp(
|
|
1443
|
-
`^${regexps.escapeRegExp(constants.homePath)}(?:${path.sep}|$)`,
|
|
1444
|
-
'i'
|
|
1445
|
-
),
|
|
1446
|
-
'~/'
|
|
1447
|
-
)
|
|
1448
|
-
)
|
|
1449
|
-
let nodeVerWarn = ''
|
|
1300
|
+
const redacting = constants.ENV.VITEST;
|
|
1301
|
+
const cliVersion = redacting ? REDACTED :
|
|
1302
|
+
// Lazily access constants.ENV.INLINED_SOCKET_CLI_VERSION_HASH.
|
|
1303
|
+
constants.ENV.INLINED_SOCKET_CLI_VERSION_HASH;
|
|
1304
|
+
const nodeVersion = redacting ? REDACTED : process.version;
|
|
1305
|
+
const defaultOrg = getConfigValueOrUndef('defaultOrg');
|
|
1306
|
+
const readOnlyConfig = isReadOnlyConfig() ? '*' : '.';
|
|
1307
|
+
const v1test = isTestingV1() ? ' (is testing v1)' : '';
|
|
1308
|
+
const feedback = isTestingV1() ? vendor.yoctocolorsCjsExports.green(' (Thank you for testing the v1 bump! Please send us any feedback you might have!)\n') : '';
|
|
1309
|
+
const shownToken = redacting ? REDACTED : getVisibleTokenPrefix() || 'no';
|
|
1310
|
+
const relCwd = redacting ? REDACTED : path$1.normalizePath(process.cwd().replace(new RegExp(`^${regexps.escapeRegExp(constants.homePath)}(?:${path.sep}|$)`, 'i'), '~/'));
|
|
1311
|
+
let nodeVerWarn = '';
|
|
1450
1312
|
if ((vendor.semverExports.parse(constants.NODE_VERSION)?.major ?? 0) < 20) {
|
|
1451
|
-
nodeVerWarn += vendor.yoctocolorsCjsExports.bold(
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
nodeVerWarn += '\n'
|
|
1455
|
-
nodeVerWarn +=
|
|
1456
|
-
' Soon after the Socket CLI will require NodeJS version 20 or higher.'
|
|
1457
|
-
nodeVerWarn += '\n'
|
|
1313
|
+
nodeVerWarn += vendor.yoctocolorsCjsExports.bold(` ${vendor.yoctocolorsCjsExports.red('Warning:')} NodeJS version 19 and lower will be ${vendor.yoctocolorsCjsExports.red('unsupported')} after April 30th, 2025.`);
|
|
1314
|
+
nodeVerWarn += '\n';
|
|
1315
|
+
nodeVerWarn += ' Soon after the Socket CLI will require NodeJS version 20 or higher.';
|
|
1316
|
+
nodeVerWarn += '\n';
|
|
1458
1317
|
}
|
|
1459
1318
|
const body = `
|
|
1460
1319
|
_____ _ _ /---------------
|
|
1461
1320
|
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver ${cliVersion}${v1test}
|
|
1462
1321
|
|__ | ${readOnlyConfig} | _| '_| -_| _| | Node: ${nodeVersion}, API token set: ${shownToken}${defaultOrg ? `, default org: ${redacting ? REDACTED : defaultOrg}` : ''}
|
|
1463
|
-
|_____|___|___|_,_|___|_|.dev | Command: \`${command}\`, cwd: ${relCwd}`.trimStart()
|
|
1464
|
-
return ` ${body}\n${nodeVerWarn}${feedback}
|
|
1322
|
+
|_____|___|___|_,_|___|_|.dev | Command: \`${command}\`, cwd: ${relCwd}`.trimStart();
|
|
1323
|
+
return ` ${body}\n${nodeVerWarn}${feedback}`;
|
|
1465
1324
|
}
|
|
1466
1325
|
|
|
1467
1326
|
async function suggestOrgSlug() {
|
|
1468
|
-
const sockSdkResult = await setupSdk()
|
|
1327
|
+
const sockSdkResult = await setupSdk();
|
|
1469
1328
|
if (!sockSdkResult.ok) {
|
|
1470
|
-
return
|
|
1329
|
+
return;
|
|
1471
1330
|
}
|
|
1472
|
-
const sockSdk = sockSdkResult.data
|
|
1473
|
-
const result = await handleApiCall(
|
|
1474
|
-
sockSdk.getOrganizations(),
|
|
1475
|
-
'list of organizations'
|
|
1476
|
-
)
|
|
1331
|
+
const sockSdk = sockSdkResult.data;
|
|
1332
|
+
const result = await handleApiCall(sockSdk.getOrganizations(), 'list of organizations');
|
|
1477
1333
|
|
|
1478
1334
|
// Ignore a failed request here. It was not the primary goal of
|
|
1479
1335
|
// running this command and reporting it only leads to end-user confusion.
|
|
1480
1336
|
if (result.ok) {
|
|
1481
1337
|
const proceed = await prompts.select({
|
|
1482
|
-
message:
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
description:
|
|
1497
|
-
'Do not use any of these organizations (will end in a no-op)'
|
|
1498
|
-
}
|
|
1499
|
-
]
|
|
1500
|
-
})
|
|
1338
|
+
message: 'Missing org name; do you want to use any of these orgs for this scan?',
|
|
1339
|
+
choices: [...Object.values(result.data.organizations).map(org => {
|
|
1340
|
+
const name = org.name ?? org.slug;
|
|
1341
|
+
return {
|
|
1342
|
+
name: `Yes [${name}]`,
|
|
1343
|
+
value: name,
|
|
1344
|
+
description: `Use "${name}" as the organization`
|
|
1345
|
+
};
|
|
1346
|
+
}), {
|
|
1347
|
+
name: 'No',
|
|
1348
|
+
value: '',
|
|
1349
|
+
description: 'Do not use any of these organizations (will end in a no-op)'
|
|
1350
|
+
}]
|
|
1351
|
+
});
|
|
1501
1352
|
if (proceed) {
|
|
1502
|
-
return proceed
|
|
1353
|
+
return proceed;
|
|
1503
1354
|
}
|
|
1504
1355
|
} else {
|
|
1505
|
-
logger.logger.fail(
|
|
1506
|
-
'Failed to lookup organization list from API, unable to suggest'
|
|
1507
|
-
)
|
|
1356
|
+
logger.logger.fail('Failed to lookup organization list from API, unable to suggest');
|
|
1508
1357
|
}
|
|
1509
1358
|
}
|
|
1510
1359
|
|
|
1511
1360
|
async function determineOrgSlug(orgFlag, firstArg, interactive, dryRun) {
|
|
1512
|
-
const defaultOrgSlug = getConfigValueOrUndef('defaultOrg')
|
|
1513
|
-
let orgSlug = String(orgFlag || defaultOrgSlug || '')
|
|
1361
|
+
const defaultOrgSlug = getConfigValueOrUndef('defaultOrg');
|
|
1362
|
+
let orgSlug = String(orgFlag || defaultOrgSlug || '');
|
|
1514
1363
|
if (!orgSlug) {
|
|
1515
1364
|
if (isTestingV1()) {
|
|
1516
1365
|
// ask from server
|
|
1517
|
-
logger.logger.
|
|
1518
|
-
|
|
1519
|
-
)
|
|
1520
|
-
logger.logger.error(
|
|
1521
|
-
'Note: you can set the default org slug to prevent this issue. You can also override all that with the --org flag.'
|
|
1522
|
-
)
|
|
1366
|
+
logger.logger.warn('Missing the org slug and no --org flag set. Trying to auto-discover the org now...');
|
|
1367
|
+
logger.logger.info('Note: you can set the default org slug to prevent this issue. You can also override all that with the --org flag.');
|
|
1523
1368
|
if (dryRun) {
|
|
1524
|
-
logger.logger.fail('Skipping auto-discovery of org in dry-run mode')
|
|
1369
|
+
logger.logger.fail('Skipping auto-discovery of org in dry-run mode');
|
|
1525
1370
|
} else if (!interactive) {
|
|
1526
|
-
logger.logger.fail(
|
|
1527
|
-
'Skipping auto-discovery of org when interactive = false'
|
|
1528
|
-
)
|
|
1371
|
+
logger.logger.fail('Skipping auto-discovery of org when interactive = false');
|
|
1529
1372
|
} else {
|
|
1530
|
-
orgSlug = (await suggestOrgSlug()) || ''
|
|
1373
|
+
orgSlug = (await suggestOrgSlug()) || '';
|
|
1531
1374
|
}
|
|
1532
1375
|
} else {
|
|
1533
|
-
orgSlug = firstArg || ''
|
|
1376
|
+
orgSlug = firstArg || '';
|
|
1534
1377
|
}
|
|
1535
1378
|
}
|
|
1536
|
-
return [orgSlug, defaultOrgSlug]
|
|
1379
|
+
return [orgSlug, defaultOrgSlug];
|
|
1537
1380
|
}
|
|
1538
1381
|
|
|
1539
|
-
const {
|
|
1382
|
+
const {
|
|
1383
|
+
NODE_MODULES: NODE_MODULES$1,
|
|
1384
|
+
NPM: NPM$5,
|
|
1385
|
+
shadowBinPath
|
|
1386
|
+
} = constants;
|
|
1540
1387
|
function findBinPathDetailsSync(binName) {
|
|
1541
|
-
const binPaths =
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
let
|
|
1547
|
-
let
|
|
1548
|
-
|
|
1549
|
-
|
|
1388
|
+
const binPaths = vendor.libExports$1.sync(binName, {
|
|
1389
|
+
all: true,
|
|
1390
|
+
nothrow: true
|
|
1391
|
+
}) ?? [];
|
|
1392
|
+
let shadowIndex = -1;
|
|
1393
|
+
let theBinPath;
|
|
1394
|
+
for (let i = 0, {
|
|
1395
|
+
length
|
|
1396
|
+
} = binPaths; i < length; i += 1) {
|
|
1397
|
+
const binPath = binPaths[i];
|
|
1550
1398
|
// Skip our bin directory if it's in the front.
|
|
1551
1399
|
if (path.dirname(binPath) === shadowBinPath) {
|
|
1552
|
-
shadowIndex = i
|
|
1400
|
+
shadowIndex = i;
|
|
1553
1401
|
} else {
|
|
1554
|
-
theBinPath = npm.resolveBinPath(binPath)
|
|
1555
|
-
break
|
|
1402
|
+
theBinPath = npm.resolveBinPath(binPath);
|
|
1403
|
+
break;
|
|
1556
1404
|
}
|
|
1557
1405
|
}
|
|
1558
1406
|
return {
|
|
1559
1407
|
name: binName,
|
|
1560
1408
|
path: theBinPath,
|
|
1561
1409
|
shadowed: shadowIndex !== -1
|
|
1562
|
-
}
|
|
1410
|
+
};
|
|
1563
1411
|
}
|
|
1564
1412
|
function findNpmPathSync(npmBinPath) {
|
|
1565
1413
|
// Lazily access constants.WIN32.
|
|
1566
|
-
const {
|
|
1567
|
-
|
|
1414
|
+
const {
|
|
1415
|
+
WIN32
|
|
1416
|
+
} = constants;
|
|
1417
|
+
let thePath = npmBinPath;
|
|
1568
1418
|
while (true) {
|
|
1569
|
-
const libNmNpmPath = path.join(thePath, 'lib', NODE_MODULES$1, NPM$5)
|
|
1419
|
+
const libNmNpmPath = path.join(thePath, 'lib', NODE_MODULES$1, NPM$5);
|
|
1570
1420
|
// mise puts its npm bin in a path like:
|
|
1571
1421
|
// /Users/SomeUsername/.local/share/mise/installs/node/vX.X.X/bin/npm.
|
|
1572
1422
|
// HOWEVER, the location of the npm install is:
|
|
1573
1423
|
// /Users/SomeUsername/.local/share/mise/installs/node/vX.X.X/lib/node_modules/npm.
|
|
1574
1424
|
if (
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
) {
|
|
1585
|
-
thePath = path.join(libNmNpmPath, NPM$5)
|
|
1586
|
-
}
|
|
1587
|
-
const nmPath = path.join(thePath, NODE_MODULES$1)
|
|
1425
|
+
// Use existsSync here because statsSync, even with { throwIfNoEntry: false },
|
|
1426
|
+
// will throw an ENOTDIR error for paths like ./a-file-that-exists/a-directory-that-does-not.
|
|
1427
|
+
// See https://github.com/nodejs/node/issues/56993.
|
|
1428
|
+
fs.existsSync(libNmNpmPath) && fs.statSync(libNmNpmPath, {
|
|
1429
|
+
throwIfNoEntry: false
|
|
1430
|
+
})?.isDirectory()) {
|
|
1431
|
+
thePath = path.join(libNmNpmPath, NPM$5);
|
|
1432
|
+
}
|
|
1433
|
+
const nmPath = path.join(thePath, NODE_MODULES$1);
|
|
1588
1434
|
if (
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
) {
|
|
1610
|
-
return thePath
|
|
1611
|
-
}
|
|
1612
|
-
const parent = path.dirname(thePath)
|
|
1435
|
+
// npm bin paths may look like:
|
|
1436
|
+
// /usr/local/share/npm/bin/npm
|
|
1437
|
+
// /Users/SomeUsername/.nvm/versions/node/vX.X.X/bin/npm
|
|
1438
|
+
// C:\Users\SomeUsername\AppData\Roaming\npm\bin\npm.cmd
|
|
1439
|
+
// OR
|
|
1440
|
+
// C:\Program Files\nodejs\npm.cmd
|
|
1441
|
+
//
|
|
1442
|
+
// In practically all cases the npm path contains a node_modules folder:
|
|
1443
|
+
// /usr/local/share/npm/bin/npm/node_modules
|
|
1444
|
+
// C:\Program Files\nodejs\node_modules
|
|
1445
|
+
fs.existsSync(nmPath) && fs.statSync(nmPath, {
|
|
1446
|
+
throwIfNoEntry: false
|
|
1447
|
+
})?.isDirectory() && (
|
|
1448
|
+
// Optimistically look for the default location.
|
|
1449
|
+
path.basename(thePath) === NPM$5 ||
|
|
1450
|
+
// Chocolatey installs npm bins in the same directory as node bins.
|
|
1451
|
+
WIN32 && fs.existsSync(path.join(thePath, `${NPM$5}.cmd`)))) {
|
|
1452
|
+
return thePath;
|
|
1453
|
+
}
|
|
1454
|
+
const parent = path.dirname(thePath);
|
|
1613
1455
|
if (parent === thePath) {
|
|
1614
|
-
return undefined
|
|
1456
|
+
return undefined;
|
|
1615
1457
|
}
|
|
1616
|
-
thePath = parent
|
|
1458
|
+
thePath = parent;
|
|
1617
1459
|
}
|
|
1618
1460
|
}
|
|
1619
1461
|
async function getPackageFilesForScan(cwd, inputPaths, supportedFiles, config) {
|
|
1620
|
-
debug.debugLog(
|
|
1621
|
-
`getPackageFilesForScan: resolving ${inputPaths.length} paths:\n`,
|
|
1622
|
-
inputPaths
|
|
1623
|
-
)
|
|
1462
|
+
debug.debugLog(`getPackageFilesForScan: resolving ${inputPaths.length} paths:\n`, inputPaths);
|
|
1624
1463
|
|
|
1625
1464
|
// Lazily access constants.spinner.
|
|
1626
|
-
const {
|
|
1627
|
-
|
|
1628
|
-
|
|
1465
|
+
const {
|
|
1466
|
+
spinner
|
|
1467
|
+
} = constants;
|
|
1468
|
+
const patterns = pathsToGlobPatterns(inputPaths);
|
|
1469
|
+
spinner.start('Searching for local files to include in scan...');
|
|
1629
1470
|
const entries = await globWithGitIgnore(patterns, {
|
|
1630
1471
|
cwd,
|
|
1631
1472
|
socketConfig: config
|
|
1632
|
-
})
|
|
1473
|
+
});
|
|
1633
1474
|
if (debug.isDebug()) {
|
|
1634
|
-
spinner.stop()
|
|
1635
|
-
debug.debugLog(
|
|
1636
|
-
|
|
1637
|
-
entries
|
|
1638
|
-
)
|
|
1639
|
-
spinner.start('Searching for files now...')
|
|
1475
|
+
spinner.stop();
|
|
1476
|
+
debug.debugLog(`Resolved ${inputPaths.length} paths to ${entries.length} local paths:\n`, entries);
|
|
1477
|
+
spinner.start('Searching for files now...');
|
|
1640
1478
|
} else {
|
|
1641
|
-
spinner.start(
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
}
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
const { NODE_MODULES, NPM: NPM$4, NPX, SOCKET_CLI_ISSUES_URL } = constants
|
|
1479
|
+
spinner.start(`Resolved ${inputPaths.length} paths to ${entries.length} local paths, searching for files now...`);
|
|
1480
|
+
}
|
|
1481
|
+
const packageFiles = await filterGlobResultToSupportedFiles(entries, supportedFiles);
|
|
1482
|
+
spinner.successAndStop(`Found ${packageFiles.length} local ${words.pluralize('file', packageFiles.length)}`);
|
|
1483
|
+
debug.debugLog('Absolute paths:\n', packageFiles);
|
|
1484
|
+
return packageFiles;
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
const {
|
|
1488
|
+
NODE_MODULES,
|
|
1489
|
+
NPM: NPM$4,
|
|
1490
|
+
NPX,
|
|
1491
|
+
SOCKET_CLI_ISSUES_URL
|
|
1492
|
+
} = constants;
|
|
1657
1493
|
function exitWithBinPathError(binName) {
|
|
1658
|
-
logger.logger.fail(
|
|
1659
|
-
`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable`
|
|
1660
|
-
)
|
|
1494
|
+
logger.logger.fail(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable`);
|
|
1661
1495
|
// The exit code 127 indicates that the command or binary being executed
|
|
1662
1496
|
// could not be found.
|
|
1663
1497
|
// eslint-disable-next-line n/no-process-exit
|
|
1664
|
-
process.exit(127)
|
|
1498
|
+
process.exit(127);
|
|
1665
1499
|
}
|
|
1666
|
-
let _npmBinPathDetails
|
|
1500
|
+
let _npmBinPathDetails;
|
|
1667
1501
|
function getNpmBinPathDetails() {
|
|
1668
1502
|
if (_npmBinPathDetails === undefined) {
|
|
1669
|
-
_npmBinPathDetails = findBinPathDetailsSync(NPM$4)
|
|
1503
|
+
_npmBinPathDetails = findBinPathDetailsSync(NPM$4);
|
|
1670
1504
|
}
|
|
1671
|
-
return _npmBinPathDetails
|
|
1505
|
+
return _npmBinPathDetails;
|
|
1672
1506
|
}
|
|
1673
|
-
let _npxBinPathDetails
|
|
1507
|
+
let _npxBinPathDetails;
|
|
1674
1508
|
function getNpxBinPathDetails() {
|
|
1675
1509
|
if (_npxBinPathDetails === undefined) {
|
|
1676
|
-
_npxBinPathDetails = findBinPathDetailsSync(NPX)
|
|
1510
|
+
_npxBinPathDetails = findBinPathDetailsSync(NPX);
|
|
1677
1511
|
}
|
|
1678
|
-
return _npxBinPathDetails
|
|
1512
|
+
return _npxBinPathDetails;
|
|
1679
1513
|
}
|
|
1680
1514
|
function isNpmBinPathShadowed() {
|
|
1681
|
-
return getNpmBinPathDetails().shadowed
|
|
1515
|
+
return getNpmBinPathDetails().shadowed;
|
|
1682
1516
|
}
|
|
1683
1517
|
function isNpxBinPathShadowed() {
|
|
1684
|
-
return getNpxBinPathDetails().shadowed
|
|
1518
|
+
return getNpxBinPathDetails().shadowed;
|
|
1685
1519
|
}
|
|
1686
|
-
let _npmBinPath
|
|
1520
|
+
let _npmBinPath;
|
|
1687
1521
|
function getNpmBinPath() {
|
|
1688
1522
|
if (_npmBinPath === undefined) {
|
|
1689
|
-
_npmBinPath = getNpmBinPathDetails().path
|
|
1523
|
+
_npmBinPath = getNpmBinPathDetails().path;
|
|
1690
1524
|
if (!_npmBinPath) {
|
|
1691
|
-
exitWithBinPathError(NPM$4)
|
|
1525
|
+
exitWithBinPathError(NPM$4);
|
|
1692
1526
|
}
|
|
1693
1527
|
}
|
|
1694
|
-
return _npmBinPath
|
|
1528
|
+
return _npmBinPath;
|
|
1695
1529
|
}
|
|
1696
|
-
let _npmPath
|
|
1530
|
+
let _npmPath;
|
|
1697
1531
|
function getNpmPath() {
|
|
1698
1532
|
if (_npmPath === undefined) {
|
|
1699
|
-
const npmBinPath = getNpmBinPath()
|
|
1700
|
-
_npmPath = npmBinPath ? findNpmPathSync(npmBinPath) : undefined
|
|
1533
|
+
const npmBinPath = getNpmBinPath();
|
|
1534
|
+
_npmPath = npmBinPath ? findNpmPathSync(npmBinPath) : undefined;
|
|
1701
1535
|
if (!_npmPath) {
|
|
1702
|
-
let message = 'Unable to find npm CLI install directory.'
|
|
1536
|
+
let message = 'Unable to find npm CLI install directory.';
|
|
1703
1537
|
if (npmBinPath) {
|
|
1704
|
-
message += `\nSearched parent directories of ${path.dirname(npmBinPath)}
|
|
1538
|
+
message += `\nSearched parent directories of ${path.dirname(npmBinPath)}.`;
|
|
1705
1539
|
}
|
|
1706
|
-
message += `\n\nThis is may be a bug with socket-npm related to changes to the npm CLI.\nPlease report to ${SOCKET_CLI_ISSUES_URL}
|
|
1707
|
-
logger.logger.fail(message)
|
|
1540
|
+
message += `\n\nThis is may be a bug with socket-npm related to changes to the npm CLI.\nPlease report to ${SOCKET_CLI_ISSUES_URL}.`;
|
|
1541
|
+
logger.logger.fail(message);
|
|
1708
1542
|
// The exit code 127 indicates that the command or binary being executed
|
|
1709
1543
|
// could not be found.
|
|
1710
1544
|
// eslint-disable-next-line n/no-process-exit
|
|
1711
|
-
process.exit(127)
|
|
1545
|
+
process.exit(127);
|
|
1712
1546
|
}
|
|
1713
1547
|
}
|
|
1714
|
-
return _npmPath
|
|
1548
|
+
return _npmPath;
|
|
1715
1549
|
}
|
|
1716
|
-
let _npmRequire
|
|
1550
|
+
let _npmRequire;
|
|
1717
1551
|
function getNpmRequire() {
|
|
1718
1552
|
if (_npmRequire === undefined) {
|
|
1719
|
-
const npmPath = getNpmPath()
|
|
1720
|
-
const npmNmPath = path.join(npmPath, NODE_MODULES, NPM$4)
|
|
1721
|
-
_npmRequire = Module.createRequire(
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
)
|
|
1727
|
-
}
|
|
1728
|
-
return _npmRequire
|
|
1729
|
-
}
|
|
1730
|
-
let _npxBinPath
|
|
1553
|
+
const npmPath = getNpmPath();
|
|
1554
|
+
const npmNmPath = path.join(npmPath, NODE_MODULES, NPM$4);
|
|
1555
|
+
_npmRequire = Module.createRequire(path.join(fs.existsSync(npmNmPath) ? npmNmPath : npmPath, '<dummy-basename>'));
|
|
1556
|
+
}
|
|
1557
|
+
return _npmRequire;
|
|
1558
|
+
}
|
|
1559
|
+
let _npxBinPath;
|
|
1731
1560
|
function getNpxBinPath() {
|
|
1732
1561
|
if (_npxBinPath === undefined) {
|
|
1733
|
-
_npxBinPath = getNpxBinPathDetails().path
|
|
1562
|
+
_npxBinPath = getNpxBinPathDetails().path;
|
|
1734
1563
|
if (!_npxBinPath) {
|
|
1735
|
-
exitWithBinPathError(NPX)
|
|
1564
|
+
exitWithBinPathError(NPX);
|
|
1736
1565
|
}
|
|
1737
1566
|
}
|
|
1738
|
-
return _npxBinPath
|
|
1567
|
+
return _npxBinPath;
|
|
1739
1568
|
}
|
|
1740
1569
|
|
|
1741
|
-
const helpFlags = new Set(['--help', '-h'])
|
|
1570
|
+
const helpFlags = new Set(['--help', '-h']);
|
|
1742
1571
|
function cmdFlagsToString(args) {
|
|
1743
|
-
const result = []
|
|
1744
|
-
for (let i = 0, {
|
|
1572
|
+
const result = [];
|
|
1573
|
+
for (let i = 0, {
|
|
1574
|
+
length
|
|
1575
|
+
} = args; i < length; i += 1) {
|
|
1745
1576
|
if (args[i].startsWith('--')) {
|
|
1746
1577
|
// Check if the next item exists and is NOT another flag.
|
|
1747
1578
|
if (i + 1 < length && !args[i + 1].startsWith('--')) {
|
|
1748
|
-
result.push(`${args[i]}=${args[i + 1]}`)
|
|
1749
|
-
i += 1
|
|
1579
|
+
result.push(`${args[i]}=${args[i + 1]}`);
|
|
1580
|
+
i += 1;
|
|
1750
1581
|
} else {
|
|
1751
|
-
result.push(args[i])
|
|
1582
|
+
result.push(args[i]);
|
|
1752
1583
|
}
|
|
1753
1584
|
}
|
|
1754
1585
|
}
|
|
1755
|
-
return result.join(' ')
|
|
1586
|
+
return result.join(' ');
|
|
1756
1587
|
}
|
|
1757
1588
|
function cmdPrefixMessage(cmdName, text) {
|
|
1758
|
-
const cmdPrefix = cmdName ? `${cmdName}: ` : ''
|
|
1759
|
-
return `${cmdPrefix}${text}
|
|
1589
|
+
const cmdPrefix = cmdName ? `${cmdName}: ` : '';
|
|
1590
|
+
return `${cmdPrefix}${text}`;
|
|
1760
1591
|
}
|
|
1761
1592
|
function isHelpFlag(cmdArg) {
|
|
1762
|
-
return helpFlags.has(cmdArg)
|
|
1593
|
+
return helpFlags.has(cmdArg);
|
|
1763
1594
|
}
|
|
1764
1595
|
|
|
1765
|
-
const {
|
|
1596
|
+
const {
|
|
1597
|
+
SOCKET_WEBSITE_URL
|
|
1598
|
+
} = constants;
|
|
1766
1599
|
function getPkgFullNameFromPurlObj(purlObj) {
|
|
1767
|
-
const {
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1600
|
+
const {
|
|
1601
|
+
name,
|
|
1602
|
+
namespace
|
|
1603
|
+
} = purlObj;
|
|
1604
|
+
return namespace ? `${namespace}${purlObj.type === 'maven' ? ':' : '/'}${name}` : name;
|
|
1771
1605
|
}
|
|
1772
1606
|
function getSocketDevAlertUrl(alertType) {
|
|
1773
|
-
return `${SOCKET_WEBSITE_URL}/alerts/${alertType}
|
|
1607
|
+
return `${SOCKET_WEBSITE_URL}/alerts/${alertType}`;
|
|
1774
1608
|
}
|
|
1775
1609
|
function getSocketDevPackageOverviewUrlFromPurl(purlObj) {
|
|
1776
|
-
const fullName = getPkgFullNameFromPurlObj(purlObj)
|
|
1777
|
-
return getSocketDevPackageOverviewUrl(purlObj.type, fullName, purlObj.version)
|
|
1610
|
+
const fullName = getPkgFullNameFromPurlObj(purlObj);
|
|
1611
|
+
return getSocketDevPackageOverviewUrl(purlObj.type, fullName, purlObj.version);
|
|
1778
1612
|
}
|
|
1779
1613
|
function getSocketDevPackageOverviewUrl(ecosystem, fullName, version) {
|
|
1780
|
-
const url = `${SOCKET_WEBSITE_URL}/${ecosystem}/package/${fullName}
|
|
1781
|
-
return ecosystem === 'go'
|
|
1782
|
-
? `${url}${version ? `?section=overview&version=${version}` : ''}`
|
|
1783
|
-
: `${url}${version ? `/overview/${version}` : ''}`
|
|
1614
|
+
const url = `${SOCKET_WEBSITE_URL}/${ecosystem}/package/${fullName}`;
|
|
1615
|
+
return ecosystem === 'go' ? `${url}${version ? `?section=overview&version=${version}` : ''}` : `${url}${version ? `/overview/${version}` : ''}`;
|
|
1784
1616
|
}
|
|
1785
1617
|
|
|
1786
1618
|
/**
|
|
@@ -1788,23 +1620,18 @@ function getSocketDevPackageOverviewUrl(ecosystem, fullName, version) {
|
|
|
1788
1620
|
* The goal is to serialize it with JSON.stringify, which Map can't do.
|
|
1789
1621
|
*/
|
|
1790
1622
|
function mapToObject(map) {
|
|
1791
|
-
return Object.fromEntries(
|
|
1792
|
-
Array.from(map.entries()).map(([k, v]) => [
|
|
1793
|
-
k,
|
|
1794
|
-
v instanceof Map ? mapToObject(v) : v
|
|
1795
|
-
])
|
|
1796
|
-
)
|
|
1623
|
+
return Object.fromEntries(Array.from(map.entries()).map(([k, v]) => [k, v instanceof Map ? mapToObject(v) : v]));
|
|
1797
1624
|
}
|
|
1798
1625
|
|
|
1799
1626
|
function* walkNestedMap(map, keys = []) {
|
|
1800
1627
|
for (const [key, value] of map.entries()) {
|
|
1801
1628
|
if (value instanceof Map) {
|
|
1802
|
-
yield* walkNestedMap(value, keys.concat(key))
|
|
1629
|
+
yield* walkNestedMap(value, keys.concat(key));
|
|
1803
1630
|
} else {
|
|
1804
1631
|
yield {
|
|
1805
1632
|
keys: keys.concat(key),
|
|
1806
1633
|
value: value
|
|
1807
|
-
}
|
|
1634
|
+
};
|
|
1808
1635
|
}
|
|
1809
1636
|
}
|
|
1810
1637
|
}
|
|
@@ -1814,48 +1641,47 @@ const {
|
|
|
1814
1641
|
ALERT_TYPE_CVE,
|
|
1815
1642
|
ALERT_TYPE_MEDIUM_CVE,
|
|
1816
1643
|
ALERT_TYPE_MILD_CVE
|
|
1817
|
-
} = constants
|
|
1644
|
+
} = constants;
|
|
1818
1645
|
function isArtifactAlertCve(alert) {
|
|
1819
|
-
const {
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
type === ALERT_TYPE_MILD_CVE ||
|
|
1824
|
-
type === ALERT_TYPE_CRITICAL_CVE
|
|
1825
|
-
)
|
|
1646
|
+
const {
|
|
1647
|
+
type
|
|
1648
|
+
} = alert;
|
|
1649
|
+
return type === ALERT_TYPE_CVE || type === ALERT_TYPE_MEDIUM_CVE || type === ALERT_TYPE_MILD_CVE || type === ALERT_TYPE_CRITICAL_CVE;
|
|
1826
1650
|
}
|
|
1827
1651
|
|
|
1828
1652
|
function createEnum(obj) {
|
|
1829
1653
|
return Object.freeze({
|
|
1830
1654
|
__proto__: null,
|
|
1831
1655
|
...obj
|
|
1832
|
-
})
|
|
1656
|
+
});
|
|
1833
1657
|
}
|
|
1834
1658
|
function pick(input, keys) {
|
|
1835
|
-
const result = {}
|
|
1659
|
+
const result = {};
|
|
1836
1660
|
for (const key of keys) {
|
|
1837
|
-
result[key] = input[key]
|
|
1661
|
+
result[key] = input[key];
|
|
1838
1662
|
}
|
|
1839
|
-
return result
|
|
1663
|
+
return result;
|
|
1840
1664
|
}
|
|
1841
1665
|
|
|
1842
1666
|
const ALERT_FIX_TYPE = createEnum({
|
|
1843
1667
|
cve: 'cve',
|
|
1844
1668
|
remove: 'remove',
|
|
1845
1669
|
upgrade: 'upgrade'
|
|
1846
|
-
})
|
|
1670
|
+
});
|
|
1847
1671
|
|
|
1848
1672
|
function stringJoinWithSeparateFinalSeparator(list, separator = ' and ') {
|
|
1849
|
-
const values = list.filter(Boolean)
|
|
1850
|
-
const {
|
|
1673
|
+
const values = list.filter(Boolean);
|
|
1674
|
+
const {
|
|
1675
|
+
length
|
|
1676
|
+
} = values;
|
|
1851
1677
|
if (!length) {
|
|
1852
|
-
return ''
|
|
1678
|
+
return '';
|
|
1853
1679
|
}
|
|
1854
1680
|
if (length === 1) {
|
|
1855
|
-
return values[0]
|
|
1681
|
+
return values[0];
|
|
1856
1682
|
}
|
|
1857
|
-
const finalValue = values.pop()
|
|
1858
|
-
return `${values.join(', ')}${separator}${finalValue}
|
|
1683
|
+
const finalValue = values.pop();
|
|
1684
|
+
return `${values.join(', ')}${separator}${finalValue}`;
|
|
1859
1685
|
}
|
|
1860
1686
|
|
|
1861
1687
|
const ALERT_SEVERITY = createEnum({
|
|
@@ -1863,129 +1689,147 @@ const ALERT_SEVERITY = createEnum({
|
|
|
1863
1689
|
high: 'high',
|
|
1864
1690
|
middle: 'middle',
|
|
1865
1691
|
low: 'low'
|
|
1866
|
-
})
|
|
1692
|
+
});
|
|
1867
1693
|
// Ordered from most severe to least.
|
|
1868
|
-
const ALERT_SEVERITIES_SORTED = Object.freeze([
|
|
1869
|
-
'critical',
|
|
1870
|
-
'high',
|
|
1871
|
-
'middle',
|
|
1872
|
-
'low'
|
|
1873
|
-
])
|
|
1694
|
+
const ALERT_SEVERITIES_SORTED = Object.freeze(['critical', 'high', 'middle', 'low']);
|
|
1874
1695
|
function getDesiredSeverities(lowestToInclude) {
|
|
1875
|
-
const result = []
|
|
1696
|
+
const result = [];
|
|
1876
1697
|
for (const severity of ALERT_SEVERITIES_SORTED) {
|
|
1877
|
-
result.push(severity)
|
|
1698
|
+
result.push(severity);
|
|
1878
1699
|
if (severity === lowestToInclude) {
|
|
1879
|
-
break
|
|
1700
|
+
break;
|
|
1880
1701
|
}
|
|
1881
1702
|
}
|
|
1882
|
-
return result
|
|
1703
|
+
return result;
|
|
1883
1704
|
}
|
|
1884
1705
|
function formatSeverityCount(severityCount) {
|
|
1885
|
-
const summary = []
|
|
1706
|
+
const summary = [];
|
|
1886
1707
|
for (const severity of ALERT_SEVERITIES_SORTED) {
|
|
1887
1708
|
if (severityCount[severity]) {
|
|
1888
|
-
summary.push(`${severityCount[severity]} ${severity}`)
|
|
1709
|
+
summary.push(`${severityCount[severity]} ${severity}`);
|
|
1889
1710
|
}
|
|
1890
1711
|
}
|
|
1891
|
-
return stringJoinWithSeparateFinalSeparator(summary)
|
|
1712
|
+
return stringJoinWithSeparateFinalSeparator(summary);
|
|
1892
1713
|
}
|
|
1893
1714
|
function getSeverityCount(issues, lowestToInclude) {
|
|
1894
|
-
const severityCount = pick(
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
},
|
|
1901
|
-
getDesiredSeverities(lowestToInclude)
|
|
1902
|
-
)
|
|
1715
|
+
const severityCount = pick({
|
|
1716
|
+
low: 0,
|
|
1717
|
+
middle: 0,
|
|
1718
|
+
high: 0,
|
|
1719
|
+
critical: 0
|
|
1720
|
+
}, getDesiredSeverities(lowestToInclude));
|
|
1903
1721
|
for (const issue of issues) {
|
|
1904
|
-
const {
|
|
1722
|
+
const {
|
|
1723
|
+
value
|
|
1724
|
+
} = issue;
|
|
1905
1725
|
if (!value) {
|
|
1906
|
-
continue
|
|
1726
|
+
continue;
|
|
1907
1727
|
}
|
|
1908
|
-
const {
|
|
1728
|
+
const {
|
|
1729
|
+
severity
|
|
1730
|
+
} = value;
|
|
1909
1731
|
if (severityCount[severity] !== undefined) {
|
|
1910
|
-
severityCount[severity] += 1
|
|
1732
|
+
severityCount[severity] += 1;
|
|
1911
1733
|
}
|
|
1912
1734
|
}
|
|
1913
|
-
return severityCount
|
|
1735
|
+
return severityCount;
|
|
1914
1736
|
}
|
|
1915
1737
|
|
|
1916
1738
|
class ColorOrMarkdown {
|
|
1917
1739
|
constructor(useMarkdown) {
|
|
1918
|
-
this.useMarkdown = !!useMarkdown
|
|
1740
|
+
this.useMarkdown = !!useMarkdown;
|
|
1919
1741
|
}
|
|
1920
1742
|
bold(text) {
|
|
1921
|
-
return this.useMarkdown
|
|
1922
|
-
? `**${text}**`
|
|
1923
|
-
: vendor.yoctocolorsCjsExports.bold(`${text}`)
|
|
1743
|
+
return this.useMarkdown ? `**${text}**` : vendor.yoctocolorsCjsExports.bold(`${text}`);
|
|
1924
1744
|
}
|
|
1925
1745
|
header(text, level = 1) {
|
|
1926
|
-
return this.useMarkdown
|
|
1927
|
-
? `\n${''.padStart(level, '#')} ${text}\n`
|
|
1928
|
-
: vendor.yoctocolorsCjsExports.underline(
|
|
1929
|
-
`\n${level === 1 ? vendor.yoctocolorsCjsExports.bold(text) : text}\n`
|
|
1930
|
-
)
|
|
1746
|
+
return this.useMarkdown ? `\n${''.padStart(level, '#')} ${text}\n` : vendor.yoctocolorsCjsExports.underline(`\n${level === 1 ? vendor.yoctocolorsCjsExports.bold(text) : text}\n`);
|
|
1931
1747
|
}
|
|
1932
|
-
hyperlink(text, url, {
|
|
1748
|
+
hyperlink(text, url, {
|
|
1749
|
+
fallback = true,
|
|
1750
|
+
fallbackToUrl
|
|
1751
|
+
} = {}) {
|
|
1933
1752
|
if (url) {
|
|
1934
|
-
return this.useMarkdown
|
|
1935
|
-
?
|
|
1936
|
-
|
|
1937
|
-
fallback: fallbackToUrl ? (_text, url) => url : fallback
|
|
1938
|
-
})
|
|
1753
|
+
return this.useMarkdown ? `[${text}](${url})` : vendor.terminalLinkExports(text, url, {
|
|
1754
|
+
fallback: fallbackToUrl ? (_text, url) => url : fallback
|
|
1755
|
+
});
|
|
1939
1756
|
}
|
|
1940
|
-
return text
|
|
1757
|
+
return text;
|
|
1941
1758
|
}
|
|
1942
1759
|
indent(...args) {
|
|
1943
|
-
return vendor.indentStringExports(...args)
|
|
1760
|
+
return vendor.indentStringExports(...args);
|
|
1944
1761
|
}
|
|
1945
1762
|
italic(text) {
|
|
1946
|
-
return this.useMarkdown
|
|
1947
|
-
? `_${text}_`
|
|
1948
|
-
: vendor.yoctocolorsCjsExports.italic(`${text}`)
|
|
1763
|
+
return this.useMarkdown ? `_${text}_` : vendor.yoctocolorsCjsExports.italic(`${text}`);
|
|
1949
1764
|
}
|
|
1950
1765
|
json(value) {
|
|
1951
|
-
return this.useMarkdown
|
|
1952
|
-
? '```json\n' + JSON.stringify(value) + '\n```'
|
|
1953
|
-
: JSON.stringify(value)
|
|
1766
|
+
return this.useMarkdown ? '```json\n' + JSON.stringify(value) + '\n```' : JSON.stringify(value);
|
|
1954
1767
|
}
|
|
1955
1768
|
list(items) {
|
|
1956
|
-
const indentedContent = items.map(item => this.indent(item).trimStart())
|
|
1957
|
-
return this.useMarkdown
|
|
1958
|
-
? `* ${indentedContent.join('\n* ')}\n`
|
|
1959
|
-
: `${indentedContent.join('\n')}\n`
|
|
1769
|
+
const indentedContent = items.map(item => this.indent(item).trimStart());
|
|
1770
|
+
return this.useMarkdown ? `* ${indentedContent.join('\n* ')}\n` : `${indentedContent.join('\n')}\n`;
|
|
1960
1771
|
}
|
|
1961
1772
|
}
|
|
1962
1773
|
|
|
1963
|
-
const require$1 =
|
|
1964
|
-
|
|
1965
|
-
)
|
|
1966
|
-
let _translations
|
|
1774
|
+
const require$1 =Module.createRequire(require('u' + 'rl').pathToFileURL(__filename).href)
|
|
1775
|
+
let _translations;
|
|
1967
1776
|
function getTranslations() {
|
|
1968
1777
|
if (_translations === undefined) {
|
|
1969
1778
|
_translations = require$1(
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
)
|
|
1779
|
+
// Lazily access constants.rootPath.
|
|
1780
|
+
path.join(constants.rootPath, 'translations.json'));
|
|
1973
1781
|
}
|
|
1974
|
-
return _translations
|
|
1782
|
+
return _translations;
|
|
1975
1783
|
}
|
|
1976
1784
|
|
|
1977
|
-
function
|
|
1978
|
-
|
|
1785
|
+
async function extractPurlsFromPnpmLockfile(lockfile) {
|
|
1786
|
+
const packages = lockfile?.packages ?? {};
|
|
1787
|
+
const seen = new Set();
|
|
1788
|
+
const visit = pkgPath => {
|
|
1789
|
+
if (seen.has(pkgPath)) {
|
|
1790
|
+
return;
|
|
1791
|
+
}
|
|
1792
|
+
const pkg = packages[pkgPath];
|
|
1793
|
+
if (!pkg) {
|
|
1794
|
+
return;
|
|
1795
|
+
}
|
|
1796
|
+
seen.add(pkgPath);
|
|
1797
|
+
const deps = {
|
|
1798
|
+
__proto__: null,
|
|
1799
|
+
...pkg.dependencies,
|
|
1800
|
+
...pkg.optionalDependencies,
|
|
1801
|
+
...pkg.devDependencies
|
|
1802
|
+
};
|
|
1803
|
+
for (const depName in deps) {
|
|
1804
|
+
const ref = deps[depName];
|
|
1805
|
+
const subKey = isPnpmDepPath(ref) ? ref : `/${depName}@${ref}`;
|
|
1806
|
+
visit(subKey);
|
|
1807
|
+
}
|
|
1808
|
+
};
|
|
1809
|
+
for (const pkgPath of Object.keys(packages)) {
|
|
1810
|
+
visit(pkgPath);
|
|
1811
|
+
}
|
|
1812
|
+
return [...seen].map(p => idToPurl(stripPnpmPeerSuffix(stripLeadingPnpmDepPathSlash(p))));
|
|
1813
|
+
}
|
|
1814
|
+
function isPnpmDepPath(maybeDepPath) {
|
|
1815
|
+
return maybeDepPath.length > 0 && maybeDepPath.charCodeAt(0) === 47; /*'/'*/
|
|
1816
|
+
}
|
|
1817
|
+
function parsePnpmLockfileVersion(version) {
|
|
1818
|
+
return vendor.semverExports.coerce(version);
|
|
1819
|
+
}
|
|
1820
|
+
async function readPnpmLockfile(lockfilePath) {
|
|
1821
|
+
return fs.existsSync(lockfilePath) ? vendor.jsYaml.load(strings.stripBom(await readFileUtf8(lockfilePath))) : null;
|
|
1979
1822
|
}
|
|
1980
|
-
function
|
|
1981
|
-
return
|
|
1823
|
+
function stripLeadingPnpmDepPathSlash(depPath) {
|
|
1824
|
+
return isPnpmDepPath(depPath) ? depPath.slice(1) : depPath;
|
|
1982
1825
|
}
|
|
1983
|
-
function
|
|
1984
|
-
|
|
1826
|
+
function stripPnpmPeerSuffix(depPath) {
|
|
1827
|
+
const index = depPath.indexOf('(');
|
|
1828
|
+
return index === -1 ? depPath : depPath.slice(0, index);
|
|
1985
1829
|
}
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
return
|
|
1830
|
+
|
|
1831
|
+
function idToPurl(id) {
|
|
1832
|
+
return `pkg:npm/${id}`;
|
|
1989
1833
|
}
|
|
1990
1834
|
|
|
1991
1835
|
const ALERT_SEVERITY_COLOR = createEnum({
|
|
@@ -1993,51 +1837,38 @@ const ALERT_SEVERITY_COLOR = createEnum({
|
|
|
1993
1837
|
high: 'red',
|
|
1994
1838
|
middle: 'yellow',
|
|
1995
1839
|
low: 'white'
|
|
1996
|
-
})
|
|
1840
|
+
});
|
|
1997
1841
|
const ALERT_SEVERITY_ORDER = createEnum({
|
|
1998
1842
|
critical: 0,
|
|
1999
1843
|
high: 1,
|
|
2000
1844
|
middle: 2,
|
|
2001
1845
|
low: 3,
|
|
2002
1846
|
none: 4
|
|
2003
|
-
})
|
|
2004
|
-
const {
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
const
|
|
1847
|
+
});
|
|
1848
|
+
const {
|
|
1849
|
+
CVE_ALERT_PROPS_FIRST_PATCHED_VERSION_IDENTIFIER,
|
|
1850
|
+
NPM: NPM$3
|
|
1851
|
+
} = constants;
|
|
1852
|
+
const MIN_ABOVE_THE_FOLD_COUNT = 3;
|
|
1853
|
+
const MIN_ABOVE_THE_FOLD_ALERT_COUNT = 1;
|
|
1854
|
+
const format = new ColorOrMarkdown(false);
|
|
2009
1855
|
function alertsHaveBlocked(alerts) {
|
|
2010
|
-
return alerts.find(a => a.blocked) !== undefined
|
|
1856
|
+
return alerts.find(a => a.blocked) !== undefined;
|
|
2011
1857
|
}
|
|
2012
1858
|
function alertsHaveSeverity(alerts, severity) {
|
|
2013
|
-
return alerts.find(a => a.raw.severity === severity) !== undefined
|
|
1859
|
+
return alerts.find(a => a.raw.severity === severity) !== undefined;
|
|
2014
1860
|
}
|
|
2015
1861
|
function alertSeverityComparator(a, b) {
|
|
2016
|
-
return getAlertSeverityOrder(a) - getAlertSeverityOrder(b)
|
|
1862
|
+
return getAlertSeverityOrder(a) - getAlertSeverityOrder(b);
|
|
2017
1863
|
}
|
|
2018
1864
|
function getAlertSeverityOrder(alert) {
|
|
2019
|
-
const {
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
? 1
|
|
2024
|
-
: severity === ALERT_SEVERITY.middle
|
|
2025
|
-
? 2
|
|
2026
|
-
: severity === ALERT_SEVERITY.low
|
|
2027
|
-
? 3
|
|
2028
|
-
: 4
|
|
1865
|
+
const {
|
|
1866
|
+
severity
|
|
1867
|
+
} = alert.raw;
|
|
1868
|
+
return severity === ALERT_SEVERITY.critical ? 0 : severity === ALERT_SEVERITY.high ? 1 : severity === ALERT_SEVERITY.middle ? 2 : severity === ALERT_SEVERITY.low ? 3 : 4;
|
|
2029
1869
|
}
|
|
2030
1870
|
function getAlertsSeverityOrder(alerts) {
|
|
2031
|
-
return alertsHaveBlocked(alerts) ||
|
|
2032
|
-
alertsHaveSeverity(alerts, ALERT_SEVERITY.critical)
|
|
2033
|
-
? 0
|
|
2034
|
-
: alertsHaveSeverity(alerts, ALERT_SEVERITY.high)
|
|
2035
|
-
? 1
|
|
2036
|
-
: alertsHaveSeverity(alerts, ALERT_SEVERITY.middle)
|
|
2037
|
-
? 2
|
|
2038
|
-
: alertsHaveSeverity(alerts, ALERT_SEVERITY.low)
|
|
2039
|
-
? 3
|
|
2040
|
-
: 4
|
|
1871
|
+
return alertsHaveBlocked(alerts) || alertsHaveSeverity(alerts, ALERT_SEVERITY.critical) ? 0 : alertsHaveSeverity(alerts, ALERT_SEVERITY.high) ? 1 : alertsHaveSeverity(alerts, ALERT_SEVERITY.middle) ? 2 : alertsHaveSeverity(alerts, ALERT_SEVERITY.low) ? 3 : 4;
|
|
2041
1872
|
}
|
|
2042
1873
|
function getHiddenRiskCounts(hiddenAlerts) {
|
|
2043
1874
|
const riskCounts = {
|
|
@@ -2045,48 +1876,48 @@ function getHiddenRiskCounts(hiddenAlerts) {
|
|
|
2045
1876
|
high: 0,
|
|
2046
1877
|
middle: 0,
|
|
2047
1878
|
low: 0
|
|
2048
|
-
}
|
|
1879
|
+
};
|
|
2049
1880
|
for (const alert of hiddenAlerts) {
|
|
2050
1881
|
switch (getAlertSeverityOrder(alert)) {
|
|
2051
1882
|
case ALERT_SEVERITY_ORDER.critical:
|
|
2052
|
-
riskCounts.critical += 1
|
|
2053
|
-
break
|
|
1883
|
+
riskCounts.critical += 1;
|
|
1884
|
+
break;
|
|
2054
1885
|
case ALERT_SEVERITY_ORDER.high:
|
|
2055
|
-
riskCounts.high += 1
|
|
2056
|
-
break
|
|
1886
|
+
riskCounts.high += 1;
|
|
1887
|
+
break;
|
|
2057
1888
|
case ALERT_SEVERITY_ORDER.middle:
|
|
2058
|
-
riskCounts.middle += 1
|
|
2059
|
-
break
|
|
1889
|
+
riskCounts.middle += 1;
|
|
1890
|
+
break;
|
|
2060
1891
|
case ALERT_SEVERITY_ORDER.low:
|
|
2061
|
-
riskCounts.low += 1
|
|
2062
|
-
break
|
|
1892
|
+
riskCounts.low += 1;
|
|
1893
|
+
break;
|
|
2063
1894
|
}
|
|
2064
1895
|
}
|
|
2065
|
-
return riskCounts
|
|
1896
|
+
return riskCounts;
|
|
2066
1897
|
}
|
|
2067
1898
|
function getHiddenRisksDescription(riskCounts) {
|
|
2068
|
-
const descriptions = []
|
|
1899
|
+
const descriptions = [];
|
|
2069
1900
|
if (riskCounts.critical) {
|
|
2070
|
-
descriptions.push(`${riskCounts.critical} ${getSeverityLabel('critical')}`)
|
|
1901
|
+
descriptions.push(`${riskCounts.critical} ${getSeverityLabel('critical')}`);
|
|
2071
1902
|
}
|
|
2072
1903
|
if (riskCounts.high) {
|
|
2073
|
-
descriptions.push(`${riskCounts.high} ${getSeverityLabel('high')}`)
|
|
1904
|
+
descriptions.push(`${riskCounts.high} ${getSeverityLabel('high')}`);
|
|
2074
1905
|
}
|
|
2075
1906
|
if (riskCounts.middle) {
|
|
2076
|
-
descriptions.push(`${riskCounts.middle} ${getSeverityLabel('middle')}`)
|
|
1907
|
+
descriptions.push(`${riskCounts.middle} ${getSeverityLabel('middle')}`);
|
|
2077
1908
|
}
|
|
2078
1909
|
if (riskCounts.low) {
|
|
2079
|
-
descriptions.push(`${riskCounts.low} ${getSeverityLabel('low')}`)
|
|
1910
|
+
descriptions.push(`${riskCounts.low} ${getSeverityLabel('low')}`);
|
|
2080
1911
|
}
|
|
2081
|
-
return `(${descriptions.join('; ')})
|
|
1912
|
+
return `(${descriptions.join('; ')})`;
|
|
2082
1913
|
}
|
|
2083
1914
|
function getSeverityLabel(severity) {
|
|
2084
|
-
return severity === 'middle' ? 'moderate' : severity
|
|
1915
|
+
return severity === 'middle' ? 'moderate' : severity;
|
|
2085
1916
|
}
|
|
2086
1917
|
async function addArtifactToAlertsMap(artifact, alertsByPkgId, options) {
|
|
2087
1918
|
// Make TypeScript happy.
|
|
2088
1919
|
if (!artifact.name || !artifact.version || !artifact.alerts?.length) {
|
|
2089
|
-
return alertsByPkgId
|
|
1920
|
+
return alertsByPkgId;
|
|
2090
1921
|
}
|
|
2091
1922
|
const {
|
|
2092
1923
|
consolidate = false,
|
|
@@ -2095,7 +1926,7 @@ async function addArtifactToAlertsMap(artifact, alertsByPkgId, options) {
|
|
|
2095
1926
|
} = {
|
|
2096
1927
|
__proto__: null,
|
|
2097
1928
|
...options
|
|
2098
|
-
}
|
|
1929
|
+
};
|
|
2099
1930
|
const include = {
|
|
2100
1931
|
__proto__: null,
|
|
2101
1932
|
blocked: true,
|
|
@@ -2104,41 +1935,34 @@ async function addArtifactToAlertsMap(artifact, alertsByPkgId, options) {
|
|
|
2104
1935
|
unfixable: true,
|
|
2105
1936
|
upgradable: false,
|
|
2106
1937
|
..._include
|
|
2107
|
-
}
|
|
2108
|
-
const name = packages.resolvePackageName(artifact)
|
|
2109
|
-
const {
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
const
|
|
1938
|
+
};
|
|
1939
|
+
const name = packages.resolvePackageName(artifact);
|
|
1940
|
+
const {
|
|
1941
|
+
version
|
|
1942
|
+
} = artifact;
|
|
1943
|
+
const pkgId = `${name}@${version}`;
|
|
1944
|
+
const major = vendor.semverExports.major(version);
|
|
1945
|
+
const socketYml = findSocketYmlSync();
|
|
2113
1946
|
const enabledState = {
|
|
2114
1947
|
__proto__: null,
|
|
2115
1948
|
...socketYml?.parsed.issueRules
|
|
2116
|
-
}
|
|
2117
|
-
let sockPkgAlerts = []
|
|
1949
|
+
};
|
|
1950
|
+
let sockPkgAlerts = [];
|
|
2118
1951
|
for (const alert of artifact.alerts) {
|
|
2119
|
-
const action = alert.action ?? ''
|
|
2120
|
-
const enabledFlag = enabledState[alert.type]
|
|
2121
|
-
if (
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
const
|
|
2128
|
-
const
|
|
2129
|
-
const
|
|
2130
|
-
const
|
|
2131
|
-
const
|
|
2132
|
-
|
|
2133
|
-
const fixable = fixableCve || fixableUpgrade
|
|
2134
|
-
const upgradable = fixableUpgrade && !objects.hasOwn(overrides, name)
|
|
2135
|
-
if (
|
|
2136
|
-
(include.blocked && blocked) ||
|
|
2137
|
-
(include.critical && critical) ||
|
|
2138
|
-
(include.cve && cve) ||
|
|
2139
|
-
(include.unfixable && !fixable) ||
|
|
2140
|
-
(include.upgradable && upgradable)
|
|
2141
|
-
) {
|
|
1952
|
+
const action = alert.action ?? '';
|
|
1953
|
+
const enabledFlag = enabledState[alert.type];
|
|
1954
|
+
if (action === 'ignore' && enabledFlag !== true || enabledFlag === false) {
|
|
1955
|
+
continue;
|
|
1956
|
+
}
|
|
1957
|
+
const blocked = action === 'error';
|
|
1958
|
+
const critical = alert.severity === ALERT_SEVERITY.critical;
|
|
1959
|
+
const cve = isArtifactAlertCve(alert);
|
|
1960
|
+
const fixType = alert.fix?.type ?? '';
|
|
1961
|
+
const fixableCve = fixType === ALERT_FIX_TYPE.cve;
|
|
1962
|
+
const fixableUpgrade = fixType === ALERT_FIX_TYPE.upgrade;
|
|
1963
|
+
const fixable = fixableCve || fixableUpgrade;
|
|
1964
|
+
const upgradable = fixableUpgrade && !objects.hasOwn(overrides, name);
|
|
1965
|
+
if (include.blocked && blocked || include.critical && critical || include.cve && cve || include.unfixable && !fixable || include.upgradable && upgradable) {
|
|
2142
1966
|
sockPkgAlerts.push({
|
|
2143
1967
|
name,
|
|
2144
1968
|
version,
|
|
@@ -2149,376 +1973,315 @@ async function addArtifactToAlertsMap(artifact, alertsByPkgId, options) {
|
|
|
2149
1973
|
fixable,
|
|
2150
1974
|
raw: alert,
|
|
2151
1975
|
upgradable
|
|
2152
|
-
})
|
|
1976
|
+
});
|
|
2153
1977
|
}
|
|
2154
1978
|
}
|
|
2155
1979
|
if (!sockPkgAlerts.length) {
|
|
2156
|
-
return alertsByPkgId
|
|
1980
|
+
return alertsByPkgId;
|
|
2157
1981
|
}
|
|
2158
1982
|
if (consolidate) {
|
|
2159
|
-
const highestForCve = new Map()
|
|
2160
|
-
const highestForUpgrade = new Map()
|
|
2161
|
-
const unfixableAlerts = []
|
|
1983
|
+
const highestForCve = new Map();
|
|
1984
|
+
const highestForUpgrade = new Map();
|
|
1985
|
+
const unfixableAlerts = [];
|
|
2162
1986
|
for (const sockPkgAlert of sockPkgAlerts) {
|
|
2163
|
-
const alert = sockPkgAlert.raw
|
|
2164
|
-
const fixType = alert.fix?.type ?? ''
|
|
1987
|
+
const alert = sockPkgAlert.raw;
|
|
1988
|
+
const fixType = alert.fix?.type ?? '';
|
|
2165
1989
|
if (fixType === ALERT_FIX_TYPE.cve) {
|
|
2166
|
-
const patchedVersion =
|
|
2167
|
-
|
|
2168
|
-
const
|
|
2169
|
-
const
|
|
2170
|
-
const highest = oldHighest?.version ?? '0.0.0'
|
|
1990
|
+
const patchedVersion = alert.props[CVE_ALERT_PROPS_FIRST_PATCHED_VERSION_IDENTIFIER];
|
|
1991
|
+
const patchedMajor = vendor.semverExports.major(patchedVersion);
|
|
1992
|
+
const oldHighest = highestForCve.get(patchedMajor);
|
|
1993
|
+
const highest = oldHighest?.version ?? '0.0.0';
|
|
2171
1994
|
if (vendor.semverExports.gt(patchedVersion, highest)) {
|
|
2172
1995
|
highestForCve.set(patchedMajor, {
|
|
2173
1996
|
alert: sockPkgAlert,
|
|
2174
1997
|
version: patchedVersion
|
|
2175
|
-
})
|
|
1998
|
+
});
|
|
2176
1999
|
}
|
|
2177
2000
|
} else if (fixType === ALERT_FIX_TYPE.upgrade) {
|
|
2178
|
-
const oldHighest = highestForUpgrade.get(major)
|
|
2179
|
-
const highest = oldHighest?.version ?? '0.0.0'
|
|
2001
|
+
const oldHighest = highestForUpgrade.get(major);
|
|
2002
|
+
const highest = oldHighest?.version ?? '0.0.0';
|
|
2180
2003
|
if (vendor.semverExports.gt(version, highest)) {
|
|
2181
2004
|
highestForUpgrade.set(major, {
|
|
2182
2005
|
alert: sockPkgAlert,
|
|
2183
2006
|
version
|
|
2184
|
-
})
|
|
2007
|
+
});
|
|
2185
2008
|
}
|
|
2186
2009
|
} else {
|
|
2187
|
-
unfixableAlerts.push(sockPkgAlert)
|
|
2010
|
+
unfixableAlerts.push(sockPkgAlert);
|
|
2188
2011
|
}
|
|
2189
2012
|
}
|
|
2190
|
-
sockPkgAlerts = [
|
|
2191
|
-
...unfixableAlerts,
|
|
2192
|
-
...[...highestForCve.values()].map(d => d.alert),
|
|
2193
|
-
...[...highestForUpgrade.values()].map(d => d.alert)
|
|
2194
|
-
]
|
|
2013
|
+
sockPkgAlerts = [...unfixableAlerts, ...[...highestForCve.values()].map(d => d.alert), ...[...highestForUpgrade.values()].map(d => d.alert)];
|
|
2195
2014
|
}
|
|
2196
2015
|
if (sockPkgAlerts.length) {
|
|
2197
|
-
sockPkgAlerts.sort((a, b) => sorts.naturalCompare(a.type, b.type))
|
|
2198
|
-
alertsByPkgId.set(pkgId, sockPkgAlerts)
|
|
2016
|
+
sockPkgAlerts.sort((a, b) => sorts.naturalCompare(a.type, b.type));
|
|
2017
|
+
alertsByPkgId.set(pkgId, sockPkgAlerts);
|
|
2199
2018
|
}
|
|
2200
|
-
return alertsByPkgId
|
|
2019
|
+
return alertsByPkgId;
|
|
2201
2020
|
}
|
|
2202
2021
|
function getCveInfoFromAlertsMap(alertsMap, options) {
|
|
2203
|
-
const {
|
|
2022
|
+
const {
|
|
2023
|
+
exclude: _exclude,
|
|
2024
|
+
limit = Infinity
|
|
2025
|
+
} = {
|
|
2204
2026
|
__proto__: null,
|
|
2205
2027
|
...options
|
|
2206
|
-
}
|
|
2028
|
+
};
|
|
2207
2029
|
const exclude = {
|
|
2208
2030
|
__proto__: null,
|
|
2209
2031
|
upgradable: true,
|
|
2210
2032
|
..._exclude
|
|
2211
|
-
}
|
|
2212
|
-
let count = 0
|
|
2213
|
-
let infoByPkgName = null
|
|
2033
|
+
};
|
|
2034
|
+
let count = 0;
|
|
2035
|
+
let infoByPkgName = null;
|
|
2214
2036
|
alertsMapLoop: for (const [pkgId, sockPkgAlerts] of alertsMap) {
|
|
2215
|
-
const purlObj = vendor.packageurlJsExports.PackageURL.fromString(
|
|
2216
|
-
|
|
2217
|
-
)
|
|
2218
|
-
const name = packages.resolvePackageName(purlObj)
|
|
2037
|
+
const purlObj = vendor.packageurlJsExports.PackageURL.fromString(idToPurl(pkgId));
|
|
2038
|
+
const name = packages.resolvePackageName(purlObj);
|
|
2219
2039
|
for (const sockPkgAlert of sockPkgAlerts) {
|
|
2220
|
-
const alert = sockPkgAlert.raw
|
|
2221
|
-
if (
|
|
2222
|
-
|
|
2223
|
-
(exclude.upgradable && registry.getManifestData(NPM$3, name))
|
|
2224
|
-
) {
|
|
2225
|
-
continue
|
|
2040
|
+
const alert = sockPkgAlert.raw;
|
|
2041
|
+
if (alert.fix?.type !== ALERT_FIX_TYPE.cve || exclude.upgradable && registry.getManifestData(NPM$3, name)) {
|
|
2042
|
+
continue;
|
|
2226
2043
|
}
|
|
2227
2044
|
if (!infoByPkgName) {
|
|
2228
|
-
infoByPkgName = new Map()
|
|
2045
|
+
infoByPkgName = new Map();
|
|
2229
2046
|
}
|
|
2230
|
-
let infos = infoByPkgName.get(name)
|
|
2047
|
+
let infos = infoByPkgName.get(name);
|
|
2231
2048
|
if (!infos) {
|
|
2232
|
-
infos = new Map()
|
|
2233
|
-
infoByPkgName.set(name, infos)
|
|
2049
|
+
infos = new Map();
|
|
2050
|
+
infoByPkgName.set(name, infos);
|
|
2234
2051
|
}
|
|
2235
|
-
const {
|
|
2052
|
+
const {
|
|
2053
|
+
key
|
|
2054
|
+
} = alert;
|
|
2236
2055
|
if (!infos.has(key)) {
|
|
2237
|
-
const {
|
|
2238
|
-
|
|
2056
|
+
const {
|
|
2057
|
+
firstPatchedVersionIdentifier,
|
|
2058
|
+
vulnerableVersionRange
|
|
2059
|
+
} = alert.props;
|
|
2239
2060
|
try {
|
|
2240
2061
|
infos.set(key, {
|
|
2241
2062
|
firstPatchedVersionIdentifier,
|
|
2242
2063
|
vulnerableVersionRange: new vendor.semverExports.Range(
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
})
|
|
2064
|
+
// Replace ', ' in a range like '>= 1.0.0, < 1.8.2' with ' ' so that
|
|
2065
|
+
// semver.Range will parse it without erroring.
|
|
2066
|
+
vulnerableVersionRange.replace(/, +/g, ' ')).format()
|
|
2067
|
+
});
|
|
2248
2068
|
if (++count >= limit) {
|
|
2249
|
-
break alertsMapLoop
|
|
2069
|
+
break alertsMapLoop;
|
|
2250
2070
|
}
|
|
2251
2071
|
} catch (e) {
|
|
2252
2072
|
debug.debugLog('getCveInfoFromAlertsMap', {
|
|
2253
2073
|
firstPatchedVersionIdentifier,
|
|
2254
2074
|
vulnerableVersionRange
|
|
2255
|
-
})
|
|
2256
|
-
debug.debugLog(e)
|
|
2075
|
+
});
|
|
2076
|
+
debug.debugLog(e);
|
|
2257
2077
|
}
|
|
2258
2078
|
}
|
|
2259
2079
|
}
|
|
2260
2080
|
}
|
|
2261
|
-
return infoByPkgName
|
|
2081
|
+
return infoByPkgName;
|
|
2262
2082
|
}
|
|
2263
2083
|
function logAlertsMap(alertsMap, options) {
|
|
2264
|
-
const {
|
|
2084
|
+
const {
|
|
2085
|
+
hideAt = 'middle',
|
|
2086
|
+
output = process.stderr
|
|
2087
|
+
} = {
|
|
2265
2088
|
__proto__: null,
|
|
2266
2089
|
...options
|
|
2267
|
-
}
|
|
2268
|
-
const translations = getTranslations()
|
|
2269
|
-
const sortedEntries = [...alertsMap.entries()].sort(
|
|
2270
|
-
|
|
2271
|
-
)
|
|
2272
|
-
const
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
const {
|
|
2277
|
-
|
|
2090
|
+
};
|
|
2091
|
+
const translations = getTranslations();
|
|
2092
|
+
const sortedEntries = [...alertsMap.entries()].sort((a, b) => getAlertsSeverityOrder(a[1]) - getAlertsSeverityOrder(b[1]));
|
|
2093
|
+
const aboveTheFoldPkgIds = new Set();
|
|
2094
|
+
const viewableAlertsByPkgId = new Map();
|
|
2095
|
+
const hiddenAlertsByPkgId = new Map();
|
|
2096
|
+
for (let i = 0, {
|
|
2097
|
+
length
|
|
2098
|
+
} = sortedEntries; i < length; i += 1) {
|
|
2099
|
+
const {
|
|
2100
|
+
0: pkgId,
|
|
2101
|
+
1: alerts
|
|
2102
|
+
} = sortedEntries[i];
|
|
2103
|
+
const hiddenAlerts = [];
|
|
2278
2104
|
const viewableAlerts = alerts.filter(a => {
|
|
2279
|
-
const keep =
|
|
2280
|
-
a.blocked || getAlertSeverityOrder(a) < ALERT_SEVERITY_ORDER[hideAt]
|
|
2105
|
+
const keep = a.blocked || getAlertSeverityOrder(a) < ALERT_SEVERITY_ORDER[hideAt];
|
|
2281
2106
|
if (!keep) {
|
|
2282
|
-
hiddenAlerts.push(a)
|
|
2107
|
+
hiddenAlerts.push(a);
|
|
2283
2108
|
}
|
|
2284
|
-
return keep
|
|
2285
|
-
})
|
|
2109
|
+
return keep;
|
|
2110
|
+
});
|
|
2286
2111
|
if (hiddenAlerts.length) {
|
|
2287
|
-
hiddenAlertsByPkgId.set(pkgId, hiddenAlerts.sort(alertSeverityComparator))
|
|
2112
|
+
hiddenAlertsByPkgId.set(pkgId, hiddenAlerts.sort(alertSeverityComparator));
|
|
2288
2113
|
}
|
|
2289
2114
|
if (!viewableAlerts.length) {
|
|
2290
|
-
continue
|
|
2115
|
+
continue;
|
|
2291
2116
|
}
|
|
2292
|
-
viewableAlerts.sort(alertSeverityComparator)
|
|
2293
|
-
viewableAlertsByPkgId.set(pkgId, viewableAlerts)
|
|
2294
|
-
if (
|
|
2295
|
-
|
|
2296
|
-
a => a.blocked || getAlertSeverityOrder(a) < ALERT_SEVERITY_ORDER.middle
|
|
2297
|
-
)
|
|
2298
|
-
) {
|
|
2299
|
-
aboveTheFoldPkgIds.add(pkgId)
|
|
2117
|
+
viewableAlerts.sort(alertSeverityComparator);
|
|
2118
|
+
viewableAlertsByPkgId.set(pkgId, viewableAlerts);
|
|
2119
|
+
if (viewableAlerts.find(a => a.blocked || getAlertSeverityOrder(a) < ALERT_SEVERITY_ORDER.middle)) {
|
|
2120
|
+
aboveTheFoldPkgIds.add(pkgId);
|
|
2300
2121
|
}
|
|
2301
2122
|
}
|
|
2302
2123
|
|
|
2303
2124
|
// If MIN_ABOVE_THE_FOLD_COUNT is NOT met add more from viewable pkg ids.
|
|
2304
|
-
for (const {
|
|
2125
|
+
for (const {
|
|
2126
|
+
0: pkgId
|
|
2127
|
+
} of viewableAlertsByPkgId.entries()) {
|
|
2305
2128
|
if (aboveTheFoldPkgIds.size >= MIN_ABOVE_THE_FOLD_COUNT) {
|
|
2306
|
-
break
|
|
2129
|
+
break;
|
|
2307
2130
|
}
|
|
2308
|
-
aboveTheFoldPkgIds.add(pkgId)
|
|
2131
|
+
aboveTheFoldPkgIds.add(pkgId);
|
|
2309
2132
|
}
|
|
2310
2133
|
// If MIN_ABOVE_THE_FOLD_COUNT is STILL NOT met add more from hidden pkg ids.
|
|
2311
|
-
for (const {
|
|
2134
|
+
for (const {
|
|
2135
|
+
0: pkgId,
|
|
2136
|
+
1: hiddenAlerts
|
|
2137
|
+
} of hiddenAlertsByPkgId.entries()) {
|
|
2312
2138
|
if (aboveTheFoldPkgIds.size >= MIN_ABOVE_THE_FOLD_COUNT) {
|
|
2313
|
-
break
|
|
2139
|
+
break;
|
|
2314
2140
|
}
|
|
2315
|
-
aboveTheFoldPkgIds.add(pkgId)
|
|
2316
|
-
const viewableAlerts = viewableAlertsByPkgId.get(pkgId) ?? []
|
|
2141
|
+
aboveTheFoldPkgIds.add(pkgId);
|
|
2142
|
+
const viewableAlerts = viewableAlertsByPkgId.get(pkgId) ?? [];
|
|
2317
2143
|
if (viewableAlerts.length < MIN_ABOVE_THE_FOLD_ALERT_COUNT) {
|
|
2318
|
-
const neededCount = MIN_ABOVE_THE_FOLD_ALERT_COUNT - viewableAlerts.length
|
|
2319
|
-
let removedHiddenAlerts
|
|
2144
|
+
const neededCount = MIN_ABOVE_THE_FOLD_ALERT_COUNT - viewableAlerts.length;
|
|
2145
|
+
let removedHiddenAlerts;
|
|
2320
2146
|
if (hiddenAlerts.length - neededCount > 0) {
|
|
2321
|
-
removedHiddenAlerts = hiddenAlerts.splice(
|
|
2322
|
-
0,
|
|
2323
|
-
MIN_ABOVE_THE_FOLD_ALERT_COUNT
|
|
2324
|
-
)
|
|
2147
|
+
removedHiddenAlerts = hiddenAlerts.splice(0, MIN_ABOVE_THE_FOLD_ALERT_COUNT);
|
|
2325
2148
|
} else {
|
|
2326
|
-
removedHiddenAlerts = hiddenAlerts
|
|
2327
|
-
hiddenAlertsByPkgId.delete(pkgId)
|
|
2149
|
+
removedHiddenAlerts = hiddenAlerts;
|
|
2150
|
+
hiddenAlertsByPkgId.delete(pkgId);
|
|
2328
2151
|
}
|
|
2329
|
-
viewableAlertsByPkgId.set(pkgId, [
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
i < length;
|
|
2342
|
-
i += 1
|
|
2343
|
-
) {
|
|
2344
|
-
const { 0: pkgId, 1: alerts } = entries[i]
|
|
2345
|
-
const lines = new Set()
|
|
2152
|
+
viewableAlertsByPkgId.set(pkgId, [...viewableAlerts, ...removedHiddenAlerts]);
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
const mentionedPkgIdsWithHiddenAlerts = new Set();
|
|
2156
|
+
for (let i = 0, prevAboveTheFold = true, entries = [...viewableAlertsByPkgId.entries()], {
|
|
2157
|
+
length
|
|
2158
|
+
} = entries; i < length; i += 1) {
|
|
2159
|
+
const {
|
|
2160
|
+
0: pkgId,
|
|
2161
|
+
1: alerts
|
|
2162
|
+
} = entries[i];
|
|
2163
|
+
const lines = new Set();
|
|
2346
2164
|
for (const alert of alerts) {
|
|
2347
|
-
const {
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
getSeverityLabel(severity)
|
|
2354
|
-
)
|
|
2355
|
-
]
|
|
2356
|
-
: []),
|
|
2357
|
-
...(alert.blocked
|
|
2358
|
-
? [
|
|
2359
|
-
vendor.yoctocolorsCjsExports.bold(
|
|
2360
|
-
vendor.yoctocolorsCjsExports.red('blocked')
|
|
2361
|
-
)
|
|
2362
|
-
]
|
|
2363
|
-
: []),
|
|
2364
|
-
...(alert.fixable ? ['fixable'] : [])
|
|
2365
|
-
]
|
|
2366
|
-
const maybeAttributes = attributes.length
|
|
2367
|
-
? ` ${vendor.yoctocolorsCjsExports.italic(`(${attributes.join('; ')})`)}`
|
|
2368
|
-
: ''
|
|
2165
|
+
const {
|
|
2166
|
+
type
|
|
2167
|
+
} = alert;
|
|
2168
|
+
const severity = alert.raw.severity ?? '';
|
|
2169
|
+
const attributes = [...(severity ? [vendor.yoctocolorsCjsExports[ALERT_SEVERITY_COLOR[severity]](getSeverityLabel(severity))] : []), ...(alert.blocked ? [vendor.yoctocolorsCjsExports.bold(vendor.yoctocolorsCjsExports.red('blocked'))] : []), ...(alert.fixable ? ['fixable'] : [])];
|
|
2170
|
+
const maybeAttributes = attributes.length ? ` ${vendor.yoctocolorsCjsExports.italic(`(${attributes.join('; ')})`)}` : '';
|
|
2369
2171
|
// Based data from { pageProps: { alertTypes } } of:
|
|
2370
2172
|
// https://socket.dev/_next/data/94666139314b6437ee4491a0864e72b264547585/en-US.json
|
|
2371
|
-
const info = translations.alerts[type]
|
|
2372
|
-
const title = info?.title ?? type
|
|
2373
|
-
const maybeDesc = info?.description ? ` - ${info.description}` : ''
|
|
2374
|
-
const content = `${title}${maybeAttributes}${maybeDesc}
|
|
2173
|
+
const info = translations.alerts[type];
|
|
2174
|
+
const title = info?.title ?? type;
|
|
2175
|
+
const maybeDesc = info?.description ? ` - ${info.description}` : '';
|
|
2176
|
+
const content = `${title}${maybeAttributes}${maybeDesc}`;
|
|
2375
2177
|
// TODO: emoji seems to mis-align terminals sometimes
|
|
2376
|
-
lines.add(` ${content}`)
|
|
2377
|
-
}
|
|
2378
|
-
const purlObj = vendor.packageurlJsExports.PackageURL.fromString(
|
|
2379
|
-
|
|
2380
|
-
)
|
|
2381
|
-
const hyperlink = format.hyperlink(
|
|
2382
|
-
pkgId,
|
|
2383
|
-
getSocketDevPackageOverviewUrl(
|
|
2384
|
-
NPM$3,
|
|
2385
|
-
packages.resolvePackageName(purlObj),
|
|
2386
|
-
purlObj.version
|
|
2387
|
-
)
|
|
2388
|
-
)
|
|
2389
|
-
const isAboveTheFold = aboveTheFoldPkgIds.has(pkgId)
|
|
2178
|
+
lines.add(` ${content}`);
|
|
2179
|
+
}
|
|
2180
|
+
const purlObj = vendor.packageurlJsExports.PackageURL.fromString(idToPurl(pkgId));
|
|
2181
|
+
const hyperlink = format.hyperlink(pkgId, getSocketDevPackageOverviewUrl(NPM$3, packages.resolvePackageName(purlObj), purlObj.version));
|
|
2182
|
+
const isAboveTheFold = aboveTheFoldPkgIds.has(pkgId);
|
|
2390
2183
|
if (isAboveTheFold) {
|
|
2391
|
-
aboveTheFoldPkgIds.add(pkgId)
|
|
2392
|
-
output.write(`${i ? '\n' : ''}${hyperlink}:\n`)
|
|
2184
|
+
aboveTheFoldPkgIds.add(pkgId);
|
|
2185
|
+
output.write(`${i ? '\n' : ''}${hyperlink}:\n`);
|
|
2393
2186
|
} else {
|
|
2394
|
-
output.write(`${prevAboveTheFold ? '\n' : ''}${hyperlink}:\n`)
|
|
2187
|
+
output.write(`${prevAboveTheFold ? '\n' : ''}${hyperlink}:\n`);
|
|
2395
2188
|
}
|
|
2396
2189
|
for (const line of lines) {
|
|
2397
|
-
output.write(`${line}\n`)
|
|
2190
|
+
output.write(`${line}\n`);
|
|
2398
2191
|
}
|
|
2399
|
-
const hiddenAlerts = hiddenAlertsByPkgId.get(pkgId) ?? []
|
|
2400
|
-
const {
|
|
2192
|
+
const hiddenAlerts = hiddenAlertsByPkgId.get(pkgId) ?? [];
|
|
2193
|
+
const {
|
|
2194
|
+
length: hiddenAlertsCount
|
|
2195
|
+
} = hiddenAlerts;
|
|
2401
2196
|
if (hiddenAlertsCount) {
|
|
2402
|
-
mentionedPkgIdsWithHiddenAlerts.add(pkgId)
|
|
2197
|
+
mentionedPkgIdsWithHiddenAlerts.add(pkgId);
|
|
2403
2198
|
if (hiddenAlertsCount === 1) {
|
|
2404
|
-
output.write(
|
|
2405
|
-
` ${vendor.yoctocolorsCjsExports.dim(`+1 Hidden ${getSeverityLabel(hiddenAlerts[0].raw.severity ?? 'low')} risk alert`)}\n`
|
|
2406
|
-
)
|
|
2199
|
+
output.write(` ${vendor.yoctocolorsCjsExports.dim(`+1 Hidden ${getSeverityLabel(hiddenAlerts[0].raw.severity ?? 'low')} risk alert`)}\n`);
|
|
2407
2200
|
} else {
|
|
2408
|
-
output.write(
|
|
2409
|
-
` ${vendor.yoctocolorsCjsExports.dim(`+${hiddenAlertsCount} Hidden alerts ${vendor.yoctocolorsCjsExports.italic(getHiddenRisksDescription(getHiddenRiskCounts(hiddenAlerts)))}`)}\n`
|
|
2410
|
-
)
|
|
2201
|
+
output.write(` ${vendor.yoctocolorsCjsExports.dim(`+${hiddenAlertsCount} Hidden alerts ${vendor.yoctocolorsCjsExports.italic(getHiddenRisksDescription(getHiddenRiskCounts(hiddenAlerts)))}`)}\n`);
|
|
2411
2202
|
}
|
|
2412
2203
|
}
|
|
2413
|
-
prevAboveTheFold = isAboveTheFold
|
|
2204
|
+
prevAboveTheFold = isAboveTheFold;
|
|
2414
2205
|
}
|
|
2415
|
-
const additionalHiddenCount =
|
|
2416
|
-
hiddenAlertsByPkgId.size - mentionedPkgIdsWithHiddenAlerts.size
|
|
2206
|
+
const additionalHiddenCount = hiddenAlertsByPkgId.size - mentionedPkgIdsWithHiddenAlerts.size;
|
|
2417
2207
|
if (additionalHiddenCount) {
|
|
2418
2208
|
const totalRiskCounts = {
|
|
2419
2209
|
critical: 0,
|
|
2420
2210
|
high: 0,
|
|
2421
2211
|
middle: 0,
|
|
2422
2212
|
low: 0
|
|
2423
|
-
}
|
|
2424
|
-
for (const {
|
|
2213
|
+
};
|
|
2214
|
+
for (const {
|
|
2215
|
+
0: pkgId,
|
|
2216
|
+
1: alerts
|
|
2217
|
+
} of hiddenAlertsByPkgId.entries()) {
|
|
2425
2218
|
if (mentionedPkgIdsWithHiddenAlerts.has(pkgId)) {
|
|
2426
|
-
continue
|
|
2219
|
+
continue;
|
|
2427
2220
|
}
|
|
2428
|
-
const riskCounts = getHiddenRiskCounts(alerts)
|
|
2429
|
-
totalRiskCounts.critical += riskCounts.critical
|
|
2430
|
-
totalRiskCounts.high += riskCounts.high
|
|
2431
|
-
totalRiskCounts.middle += riskCounts.middle
|
|
2432
|
-
totalRiskCounts.low += riskCounts.low
|
|
2221
|
+
const riskCounts = getHiddenRiskCounts(alerts);
|
|
2222
|
+
totalRiskCounts.critical += riskCounts.critical;
|
|
2223
|
+
totalRiskCounts.high += riskCounts.high;
|
|
2224
|
+
totalRiskCounts.middle += riskCounts.middle;
|
|
2225
|
+
totalRiskCounts.low += riskCounts.low;
|
|
2433
2226
|
}
|
|
2434
|
-
output.write(
|
|
2435
|
-
`${aboveTheFoldPkgIds.size ? '\n' : ''}${vendor.yoctocolorsCjsExports.dim(`${aboveTheFoldPkgIds.size ? '+' : ''}${additionalHiddenCount} Packages with hidden alerts ${vendor.yoctocolorsCjsExports.italic(getHiddenRisksDescription(totalRiskCounts))}`)}\n`
|
|
2436
|
-
)
|
|
2227
|
+
output.write(`${aboveTheFoldPkgIds.size ? '\n' : ''}${vendor.yoctocolorsCjsExports.dim(`${aboveTheFoldPkgIds.size ? '+' : ''}${additionalHiddenCount} Packages with hidden alerts ${vendor.yoctocolorsCjsExports.italic(getHiddenRisksDescription(totalRiskCounts))}`)}\n`);
|
|
2437
2228
|
}
|
|
2438
|
-
output.write('\n')
|
|
2229
|
+
output.write('\n');
|
|
2439
2230
|
}
|
|
2440
2231
|
|
|
2441
|
-
const RangeStyles = ['caret', 'gt', 'lt', 'pin', 'preserve', 'tilde']
|
|
2232
|
+
const RangeStyles = ['caret', 'gt', 'lt', 'pin', 'preserve', 'tilde'];
|
|
2442
2233
|
function applyRange(refRange, version, style = 'preserve') {
|
|
2443
2234
|
switch (style) {
|
|
2444
2235
|
case 'caret':
|
|
2445
|
-
return `^${version}
|
|
2236
|
+
return `^${version}`;
|
|
2446
2237
|
case 'gt':
|
|
2447
|
-
return `>${version}
|
|
2238
|
+
return `>${version}`;
|
|
2448
2239
|
case 'gte':
|
|
2449
|
-
return `>=${version}
|
|
2240
|
+
return `>=${version}`;
|
|
2450
2241
|
case 'lt':
|
|
2451
|
-
return `<${version}
|
|
2242
|
+
return `<${version}`;
|
|
2452
2243
|
case 'lte':
|
|
2453
|
-
return `<=${version}
|
|
2454
|
-
case 'preserve':
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
const
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
}
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2244
|
+
return `<=${version}`;
|
|
2245
|
+
case 'preserve':
|
|
2246
|
+
{
|
|
2247
|
+
const range = new vendor.semverExports.Range(refRange);
|
|
2248
|
+
const {
|
|
2249
|
+
raw
|
|
2250
|
+
} = range;
|
|
2251
|
+
const comparators = [...range.set].flat();
|
|
2252
|
+
const {
|
|
2253
|
+
length
|
|
2254
|
+
} = comparators;
|
|
2255
|
+
if (length === 1) {
|
|
2256
|
+
const char = /^[<>]=?/.exec(raw)?.[0];
|
|
2257
|
+
if (char) {
|
|
2258
|
+
return `${char}${version}`;
|
|
2259
|
+
}
|
|
2260
|
+
} else if (length === 2) {
|
|
2261
|
+
const char = /^[~^]/.exec(raw)?.[0];
|
|
2262
|
+
if (char) {
|
|
2263
|
+
return `${char}${version}`;
|
|
2264
|
+
}
|
|
2468
2265
|
}
|
|
2266
|
+
return version;
|
|
2469
2267
|
}
|
|
2470
|
-
return version
|
|
2471
|
-
}
|
|
2472
2268
|
case 'tilde':
|
|
2473
|
-
return `~${version}
|
|
2269
|
+
return `~${version}`;
|
|
2474
2270
|
case 'pin':
|
|
2475
2271
|
default:
|
|
2476
|
-
return version
|
|
2272
|
+
return version;
|
|
2477
2273
|
}
|
|
2478
2274
|
}
|
|
2479
2275
|
function getMajor(version) {
|
|
2480
|
-
const coerced = vendor.semverExports.coerce(version)
|
|
2276
|
+
const coerced = vendor.semverExports.coerce(version);
|
|
2481
2277
|
if (coerced) {
|
|
2482
2278
|
try {
|
|
2483
|
-
return vendor.semverExports.major(coerced)
|
|
2279
|
+
return vendor.semverExports.major(coerced);
|
|
2484
2280
|
} catch (e) {
|
|
2485
|
-
debug.debugLog(`Error parsing '${version}':\n`, e)
|
|
2486
|
-
}
|
|
2487
|
-
}
|
|
2488
|
-
return null
|
|
2489
|
-
}
|
|
2490
|
-
|
|
2491
|
-
async function extractPurlsFromPnpmLockfile(lockfile) {
|
|
2492
|
-
const packages = lockfile?.packages ?? {}
|
|
2493
|
-
const seen = new Set()
|
|
2494
|
-
const visit = pkgPath => {
|
|
2495
|
-
if (seen.has(pkgPath)) {
|
|
2496
|
-
return
|
|
2497
|
-
}
|
|
2498
|
-
const pkg = packages[pkgPath]
|
|
2499
|
-
if (!pkg) {
|
|
2500
|
-
return
|
|
2281
|
+
debug.debugLog(`Error parsing '${version}':\n`, e);
|
|
2501
2282
|
}
|
|
2502
|
-
seen.add(pkgPath)
|
|
2503
|
-
const deps = {
|
|
2504
|
-
__proto__: null,
|
|
2505
|
-
...pkg.dependencies,
|
|
2506
|
-
...pkg.optionalDependencies,
|
|
2507
|
-
...pkg.devDependencies
|
|
2508
|
-
}
|
|
2509
|
-
for (const depName in deps) {
|
|
2510
|
-
const ref = deps[depName]
|
|
2511
|
-
const subKey = isDepPath(ref) ? ref : `/${depName}@${ref}`
|
|
2512
|
-
visit(subKey)
|
|
2513
|
-
}
|
|
2514
|
-
}
|
|
2515
|
-
for (const pkgPath of Object.keys(packages)) {
|
|
2516
|
-
visit(pkgPath)
|
|
2517
2283
|
}
|
|
2518
|
-
return
|
|
2519
|
-
}
|
|
2520
|
-
function parsePnpmLockfileVersion(version) {
|
|
2521
|
-
return vendor.semverExports.coerce(version)
|
|
2284
|
+
return null;
|
|
2522
2285
|
}
|
|
2523
2286
|
|
|
2524
2287
|
async function getAlertsMapFromPnpmLockfile(lockfile, options_) {
|
|
@@ -2528,12 +2291,12 @@ async function getAlertsMapFromPnpmLockfile(lockfile, options_) {
|
|
|
2528
2291
|
limit: Infinity,
|
|
2529
2292
|
nothrow: false,
|
|
2530
2293
|
...options_
|
|
2531
|
-
}
|
|
2532
|
-
const purls = await extractPurlsFromPnpmLockfile(lockfile)
|
|
2294
|
+
};
|
|
2295
|
+
const purls = await extractPurlsFromPnpmLockfile(lockfile);
|
|
2533
2296
|
return await getAlertsMapFromPurls(purls, {
|
|
2534
2297
|
overrides: lockfile.overrides,
|
|
2535
2298
|
...options
|
|
2536
|
-
})
|
|
2299
|
+
});
|
|
2537
2300
|
}
|
|
2538
2301
|
async function getAlertsMapFromPurls(purls, options_) {
|
|
2539
2302
|
const options = {
|
|
@@ -2541,7 +2304,7 @@ async function getAlertsMapFromPurls(purls, options_) {
|
|
|
2541
2304
|
consolidate: false,
|
|
2542
2305
|
nothrow: false,
|
|
2543
2306
|
...options_
|
|
2544
|
-
}
|
|
2307
|
+
};
|
|
2545
2308
|
const include = {
|
|
2546
2309
|
__proto__: null,
|
|
2547
2310
|
actions: undefined,
|
|
@@ -2552,69 +2315,60 @@ async function getAlertsMapFromPurls(purls, options_) {
|
|
|
2552
2315
|
unfixable: true,
|
|
2553
2316
|
upgradable: false,
|
|
2554
2317
|
...options.include
|
|
2555
|
-
}
|
|
2556
|
-
const {
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
const
|
|
2318
|
+
};
|
|
2319
|
+
const {
|
|
2320
|
+
spinner
|
|
2321
|
+
} = options;
|
|
2322
|
+
const uniqPurls = arrays.arrayUnique(purls);
|
|
2323
|
+
let {
|
|
2324
|
+
length: remaining
|
|
2325
|
+
} = uniqPurls;
|
|
2326
|
+
const alertsByPkgId = new Map();
|
|
2560
2327
|
if (!remaining) {
|
|
2561
|
-
return alertsByPkgId
|
|
2328
|
+
return alertsByPkgId;
|
|
2562
2329
|
}
|
|
2563
|
-
const getText = () => `Looking up data for ${remaining} packages
|
|
2564
|
-
spinner?.start(getText())
|
|
2565
|
-
const sockSdkResult = await setupSdk(getPublicToken())
|
|
2330
|
+
const getText = () => `Looking up data for ${remaining} packages`;
|
|
2331
|
+
spinner?.start(getText());
|
|
2332
|
+
const sockSdkResult = await setupSdk(getPublicToken());
|
|
2566
2333
|
if (!sockSdkResult.ok) {
|
|
2567
|
-
throw new Error('Auth error: Try to run `socket login` first')
|
|
2334
|
+
throw new Error('Auth error: Try to run `socket login` first');
|
|
2568
2335
|
}
|
|
2569
|
-
const sockSdk = sockSdkResult.data
|
|
2336
|
+
const sockSdk = sockSdkResult.data;
|
|
2570
2337
|
const toAlertsMapOptions = {
|
|
2571
2338
|
overrides: options.overrides,
|
|
2572
2339
|
consolidate: options.consolidate,
|
|
2573
2340
|
include,
|
|
2574
2341
|
spinner
|
|
2575
|
-
}
|
|
2576
|
-
for await (const batchResult of sockSdk.batchPackageStream(
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
},
|
|
2591
|
-
{
|
|
2592
|
-
components: uniqPurls.map(purl => ({
|
|
2593
|
-
purl
|
|
2594
|
-
}))
|
|
2595
|
-
}
|
|
2596
|
-
)) {
|
|
2342
|
+
};
|
|
2343
|
+
for await (const batchResult of sockSdk.batchPackageStream({
|
|
2344
|
+
alerts: 'true',
|
|
2345
|
+
compact: 'true',
|
|
2346
|
+
...(include.actions ? {
|
|
2347
|
+
actions: include.actions.join(',')
|
|
2348
|
+
} : {}),
|
|
2349
|
+
...(include.unfixable ? {} : {
|
|
2350
|
+
fixable: 'true'
|
|
2351
|
+
})
|
|
2352
|
+
}, {
|
|
2353
|
+
components: uniqPurls.map(purl => ({
|
|
2354
|
+
purl
|
|
2355
|
+
}))
|
|
2356
|
+
})) {
|
|
2597
2357
|
if (batchResult.success) {
|
|
2598
|
-
await addArtifactToAlertsMap(
|
|
2599
|
-
batchResult.data,
|
|
2600
|
-
alertsByPkgId,
|
|
2601
|
-
toAlertsMapOptions
|
|
2602
|
-
)
|
|
2358
|
+
await addArtifactToAlertsMap(batchResult.data, alertsByPkgId, toAlertsMapOptions);
|
|
2603
2359
|
} else if (!options.nothrow) {
|
|
2604
|
-
const statusCode = batchResult.status ?? 'unknown'
|
|
2605
|
-
const statusMessage = batchResult.error ?? 'No status message'
|
|
2606
|
-
throw new Error(
|
|
2607
|
-
`Socket API server error (${statusCode}): ${statusMessage}`
|
|
2608
|
-
)
|
|
2360
|
+
const statusCode = batchResult.status ?? 'unknown';
|
|
2361
|
+
const statusMessage = batchResult.error ?? 'No status message';
|
|
2362
|
+
throw new Error(`Socket API server error (${statusCode}): ${statusMessage}`);
|
|
2609
2363
|
}
|
|
2610
|
-
remaining -= 1
|
|
2364
|
+
remaining -= 1;
|
|
2611
2365
|
if (spinner && remaining > 0) {
|
|
2612
|
-
spinner.start()
|
|
2613
|
-
spinner.setText(getText())
|
|
2366
|
+
spinner.start();
|
|
2367
|
+
spinner.setText(getText());
|
|
2614
2368
|
}
|
|
2615
2369
|
}
|
|
2616
|
-
spinner?.stop()
|
|
2617
|
-
return alertsByPkgId
|
|
2370
|
+
spinner?.stop();
|
|
2371
|
+
return alertsByPkgId;
|
|
2618
2372
|
}
|
|
2619
2373
|
|
|
2620
2374
|
const {
|
|
@@ -2622,7 +2376,7 @@ const {
|
|
|
2622
2376
|
SOCKET_CLI_SAFE_BIN,
|
|
2623
2377
|
SOCKET_CLI_SAFE_PROGRESS,
|
|
2624
2378
|
SOCKET_IPC_HANDSHAKE
|
|
2625
|
-
} = constants
|
|
2379
|
+
} = constants;
|
|
2626
2380
|
function safeNpmInstall(options) {
|
|
2627
2381
|
const {
|
|
2628
2382
|
agentExecPath = getNpmBinPath(),
|
|
@@ -2633,77 +2387,60 @@ function safeNpmInstall(options) {
|
|
|
2633
2387
|
} = {
|
|
2634
2388
|
__proto__: null,
|
|
2635
2389
|
...options
|
|
2636
|
-
}
|
|
2390
|
+
};
|
|
2637
2391
|
// Lazily access constants.ENV.NODE_COMPILE_CACHE
|
|
2638
|
-
const {
|
|
2639
|
-
|
|
2640
|
-
|
|
2392
|
+
const {
|
|
2393
|
+
NODE_COMPILE_CACHE
|
|
2394
|
+
} = constants.ENV;
|
|
2395
|
+
let stdio = spawnOptions.stdio;
|
|
2396
|
+
const useIpc = objects.isObject(ipc);
|
|
2641
2397
|
// Include 'ipc' in the spawnOptions.stdio when an options.ipc object is provided.
|
|
2642
2398
|
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
2643
2399
|
// and https://github.com/nodejs/node/blob/v23.6.0/lib/internal/child_process.js#L238.
|
|
2644
2400
|
if (typeof stdio === 'string') {
|
|
2645
|
-
stdio = useIpc ? [stdio, stdio, stdio, 'ipc'] : [stdio, stdio, stdio]
|
|
2401
|
+
stdio = useIpc ? [stdio, stdio, stdio, 'ipc'] : [stdio, stdio, stdio];
|
|
2646
2402
|
} else if (useIpc && Array.isArray(stdio) && !stdio.includes('ipc')) {
|
|
2647
|
-
stdio = stdio.concat('ipc')
|
|
2648
|
-
}
|
|
2649
|
-
const useDebug = debug.isDebug()
|
|
2650
|
-
const terminatorPos = args.indexOf('--')
|
|
2651
|
-
const rawBinArgs = terminatorPos === -1 ? args : args.slice(0, terminatorPos)
|
|
2652
|
-
const progressArg =
|
|
2653
|
-
|
|
2654
|
-
const
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos)
|
|
2658
|
-
const isSilent = !useDebug && !binArgs.some(npm.isLoglevelFlag)
|
|
2659
|
-
const logLevelArgs = isSilent ? ['--loglevel', 'silent'] : []
|
|
2403
|
+
stdio = stdio.concat('ipc');
|
|
2404
|
+
}
|
|
2405
|
+
const useDebug = debug.isDebug();
|
|
2406
|
+
const terminatorPos = args.indexOf('--');
|
|
2407
|
+
const rawBinArgs = terminatorPos === -1 ? args : args.slice(0, terminatorPos);
|
|
2408
|
+
const progressArg = rawBinArgs.findLast(npm.isProgressFlag) !== '--no-progress';
|
|
2409
|
+
const binArgs = rawBinArgs.filter(a => !npm.isAuditFlag(a) && !npm.isFundFlag(a) && !npm.isProgressFlag(a));
|
|
2410
|
+
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos);
|
|
2411
|
+
const isSilent = !useDebug && !binArgs.some(npm.isLoglevelFlag);
|
|
2412
|
+
const logLevelArgs = isSilent ? ['--loglevel', 'silent'] : [];
|
|
2660
2413
|
const spawnPromise = spawn.spawn(
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
...
|
|
2689
|
-
...binArgs,
|
|
2690
|
-
...otherArgs
|
|
2691
|
-
],
|
|
2692
|
-
{
|
|
2693
|
-
spinner,
|
|
2694
|
-
...spawnOptions,
|
|
2695
|
-
stdio,
|
|
2696
|
-
env: {
|
|
2697
|
-
...process.env,
|
|
2698
|
-
...(NODE_COMPILE_CACHE
|
|
2699
|
-
? {
|
|
2700
|
-
NODE_COMPILE_CACHE
|
|
2701
|
-
}
|
|
2702
|
-
: undefined),
|
|
2703
|
-
...spawnOptions.env
|
|
2704
|
-
}
|
|
2414
|
+
// Lazily access constants.execPath.
|
|
2415
|
+
constants.execPath, [
|
|
2416
|
+
// Lazily access constants.nodeHardenFlags.
|
|
2417
|
+
...constants.nodeHardenFlags,
|
|
2418
|
+
// Lazily access constants.nodeNoWarningsFlags.
|
|
2419
|
+
...constants.nodeNoWarningsFlags,
|
|
2420
|
+
// Lazily access constants.ENV.INLINED_SOCKET_CLI_SENTRY_BUILD.
|
|
2421
|
+
...(constants.ENV.INLINED_SOCKET_CLI_SENTRY_BUILD ? ['--require',
|
|
2422
|
+
// Lazily access constants.distInstrumentWithSentryPath.
|
|
2423
|
+
constants.distInstrumentWithSentryPath] : []), '--require',
|
|
2424
|
+
// Lazily access constants.distShadowInjectPath.
|
|
2425
|
+
constants.distShadowInjectPath, npm.realExecPathSync(agentExecPath), 'install',
|
|
2426
|
+
// Avoid code paths for 'audit' and 'fund'.
|
|
2427
|
+
'--no-audit', '--no-fund',
|
|
2428
|
+
// Add '--no-progress' to fix input being swallowed by the npm spinner.
|
|
2429
|
+
'--no-progress',
|
|
2430
|
+
// Add '--loglevel=silent' if a loglevel flag is not provided and the
|
|
2431
|
+
// SOCKET_CLI_DEBUG environment variable is not truthy.
|
|
2432
|
+
...logLevelArgs, ...binArgs, ...otherArgs], {
|
|
2433
|
+
spinner,
|
|
2434
|
+
...spawnOptions,
|
|
2435
|
+
stdio,
|
|
2436
|
+
env: {
|
|
2437
|
+
...process.env,
|
|
2438
|
+
...(NODE_COMPILE_CACHE ? {
|
|
2439
|
+
NODE_COMPILE_CACHE
|
|
2440
|
+
} : undefined),
|
|
2441
|
+
...spawnOptions.env
|
|
2705
2442
|
}
|
|
2706
|
-
)
|
|
2443
|
+
});
|
|
2707
2444
|
if (useIpc) {
|
|
2708
2445
|
spawnPromise.process.send({
|
|
2709
2446
|
[SOCKET_IPC_HANDSHAKE]: {
|
|
@@ -2711,20 +2448,26 @@ function safeNpmInstall(options) {
|
|
|
2711
2448
|
[SOCKET_CLI_SAFE_PROGRESS]: progressArg,
|
|
2712
2449
|
...ipc
|
|
2713
2450
|
}
|
|
2714
|
-
})
|
|
2451
|
+
});
|
|
2715
2452
|
}
|
|
2716
|
-
return spawnPromise
|
|
2453
|
+
return spawnPromise;
|
|
2717
2454
|
}
|
|
2718
2455
|
|
|
2719
|
-
const {
|
|
2456
|
+
const {
|
|
2457
|
+
NPM: NPM$1,
|
|
2458
|
+
PNPM: PNPM$1
|
|
2459
|
+
} = constants;
|
|
2720
2460
|
function runAgentInstall(pkgEnvDetails, options) {
|
|
2721
|
-
const {
|
|
2461
|
+
const {
|
|
2462
|
+
agent,
|
|
2463
|
+
agentExecPath
|
|
2464
|
+
} = pkgEnvDetails;
|
|
2722
2465
|
// All package managers support the "install" command.
|
|
2723
2466
|
if (agent === NPM$1) {
|
|
2724
2467
|
return safeNpmInstall({
|
|
2725
2468
|
agentExecPath,
|
|
2726
2469
|
...options
|
|
2727
|
-
})
|
|
2470
|
+
});
|
|
2728
2471
|
}
|
|
2729
2472
|
const {
|
|
2730
2473
|
args = [],
|
|
@@ -2733,9 +2476,8 @@ function runAgentInstall(pkgEnvDetails, options) {
|
|
|
2733
2476
|
} = {
|
|
2734
2477
|
__proto__: null,
|
|
2735
2478
|
...options
|
|
2736
|
-
}
|
|
2737
|
-
const skipNodeHardenFlags =
|
|
2738
|
-
agent === PNPM$1 && pkgEnvDetails.agentVersion.major < 11
|
|
2479
|
+
};
|
|
2480
|
+
const skipNodeHardenFlags = agent === PNPM$1 && pkgEnvDetails.agentVersion.major < 11;
|
|
2739
2481
|
return spawn.spawn(agentExecPath, ['install', ...args], {
|
|
2740
2482
|
// Lazily access constants.WIN32.
|
|
2741
2483
|
shell: constants.WIN32,
|
|
@@ -2744,17 +2486,14 @@ function runAgentInstall(pkgEnvDetails, options) {
|
|
|
2744
2486
|
...spawnOptions,
|
|
2745
2487
|
env: {
|
|
2746
2488
|
...process.env,
|
|
2747
|
-
NODE_OPTIONS: cmdFlagsToString([
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
// Lazily access constants.nodeNoWarningsFlags.
|
|
2753
|
-
...constants.nodeNoWarningsFlags
|
|
2754
|
-
]),
|
|
2489
|
+
NODE_OPTIONS: cmdFlagsToString([...(skipNodeHardenFlags ? [] :
|
|
2490
|
+
// Lazily access constants.nodeHardenFlags.
|
|
2491
|
+
constants.nodeHardenFlags),
|
|
2492
|
+
// Lazily access constants.nodeNoWarningsFlags.
|
|
2493
|
+
...constants.nodeNoWarningsFlags]),
|
|
2755
2494
|
...spawnOptions.env
|
|
2756
2495
|
}
|
|
2757
|
-
})
|
|
2496
|
+
});
|
|
2758
2497
|
}
|
|
2759
2498
|
|
|
2760
2499
|
const {
|
|
@@ -2770,49 +2509,37 @@ const {
|
|
|
2770
2509
|
YARN,
|
|
2771
2510
|
YARN_BERRY,
|
|
2772
2511
|
YARN_CLASSIC
|
|
2773
|
-
} = constants
|
|
2774
|
-
const AGENTS =
|
|
2775
|
-
const binByAgent = new Map([
|
|
2776
|
-
[BUN, BUN],
|
|
2777
|
-
[NPM, NPM],
|
|
2778
|
-
[PNPM, PNPM],
|
|
2779
|
-
[YARN_BERRY, YARN],
|
|
2780
|
-
[YARN_CLASSIC, YARN],
|
|
2781
|
-
[VLT, VLT]
|
|
2782
|
-
])
|
|
2512
|
+
} = constants;
|
|
2513
|
+
const AGENTS = [BUN, NPM, PNPM, YARN_BERRY, YARN_CLASSIC, VLT];
|
|
2514
|
+
const binByAgent = new Map([[BUN, BUN], [NPM, NPM], [PNPM, PNPM], [YARN_BERRY, YARN], [YARN_CLASSIC, YARN], [VLT, VLT]]);
|
|
2783
2515
|
async function getAgentExecPath(agent) {
|
|
2784
|
-
const binName = binByAgent.get(agent)
|
|
2516
|
+
const binName = binByAgent.get(agent);
|
|
2785
2517
|
if (binName === NPM) {
|
|
2786
2518
|
// Lazily access constants.npmExecPath.
|
|
2787
|
-
return constants.npmExecPath
|
|
2519
|
+
return constants.npmExecPath;
|
|
2788
2520
|
}
|
|
2789
|
-
return (
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
})) ?? binName
|
|
2793
|
-
)
|
|
2521
|
+
return (await vendor.libExports$1(binName, {
|
|
2522
|
+
nothrow: true
|
|
2523
|
+
})) ?? binName;
|
|
2794
2524
|
}
|
|
2795
2525
|
async function getAgentVersion(agentExecPath, cwd) {
|
|
2796
|
-
let result
|
|
2526
|
+
let result;
|
|
2797
2527
|
try {
|
|
2798
2528
|
result =
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
})
|
|
2810
|
-
).stdout
|
|
2811
|
-
) ?? undefined
|
|
2529
|
+
// Coerce version output into a valid semver version by passing it through
|
|
2530
|
+
// semver.coerce which strips leading v's, carets (^), comparators (<,<=,>,>=,=),
|
|
2531
|
+
// and tildes (~).
|
|
2532
|
+
vendor.semverExports.coerce(
|
|
2533
|
+
// All package managers support the "--version" flag.
|
|
2534
|
+
(await spawn.spawn(agentExecPath, ['--version'], {
|
|
2535
|
+
cwd,
|
|
2536
|
+
// Lazily access constants.WIN32.
|
|
2537
|
+
shell: constants.WIN32
|
|
2538
|
+
})).stdout) ?? undefined;
|
|
2812
2539
|
} catch (e) {
|
|
2813
|
-
debug.debugLog('getAgentVersion error:\n', e)
|
|
2540
|
+
debug.debugLog('getAgentVersion error:\n', e);
|
|
2814
2541
|
}
|
|
2815
|
-
return result
|
|
2542
|
+
return result;
|
|
2816
2543
|
}
|
|
2817
2544
|
|
|
2818
2545
|
// The order of LOCKS properties IS significant as it affects iteration order.
|
|
@@ -2835,195 +2562,147 @@ const LOCKS = {
|
|
|
2835
2562
|
// Unlike the other LOCKS keys this key contains a directory AND filename so
|
|
2836
2563
|
// it has to be handled differently.
|
|
2837
2564
|
'node_modules/.package-lock.json': NPM
|
|
2838
|
-
}
|
|
2565
|
+
};
|
|
2839
2566
|
const readLockFileByAgent = (() => {
|
|
2840
2567
|
function wrapReader(reader) {
|
|
2841
2568
|
return async (...args) => {
|
|
2842
2569
|
try {
|
|
2843
|
-
return await reader(...args)
|
|
2570
|
+
return await reader(...args);
|
|
2844
2571
|
} catch {}
|
|
2845
|
-
return undefined
|
|
2846
|
-
}
|
|
2847
|
-
}
|
|
2848
|
-
const binaryReader = wrapReader(readFileBinary)
|
|
2849
|
-
const defaultReader = wrapReader(
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
shell: constants.WIN32
|
|
2875
|
-
})
|
|
2876
|
-
).stdout.trim()
|
|
2877
|
-
}
|
|
2878
|
-
return undefined
|
|
2879
|
-
})
|
|
2880
|
-
],
|
|
2881
|
-
[NPM, defaultReader],
|
|
2882
|
-
[PNPM, defaultReader],
|
|
2883
|
-
[VLT, defaultReader],
|
|
2884
|
-
[YARN_BERRY, defaultReader],
|
|
2885
|
-
[YARN_CLASSIC, defaultReader]
|
|
2886
|
-
])
|
|
2887
|
-
})()
|
|
2572
|
+
return undefined;
|
|
2573
|
+
};
|
|
2574
|
+
}
|
|
2575
|
+
const binaryReader = wrapReader(readFileBinary);
|
|
2576
|
+
const defaultReader = wrapReader(async lockPath => await readFileUtf8(lockPath));
|
|
2577
|
+
return new Map([[BUN, wrapReader(async (lockPath, agentExecPath, cwd = process.cwd()) => {
|
|
2578
|
+
const ext = path.extname(lockPath);
|
|
2579
|
+
if (ext === LOCK_EXT) {
|
|
2580
|
+
return await defaultReader(lockPath);
|
|
2581
|
+
}
|
|
2582
|
+
if (ext === BINARY_LOCK_EXT) {
|
|
2583
|
+
const lockBuffer = await binaryReader(lockPath);
|
|
2584
|
+
if (lockBuffer) {
|
|
2585
|
+
try {
|
|
2586
|
+
return vendor.hyrious__bun_lockbExports.parse(lockBuffer);
|
|
2587
|
+
} catch {}
|
|
2588
|
+
}
|
|
2589
|
+
// To print a Yarn lockfile to your console without writing it to disk
|
|
2590
|
+
// use `bun bun.lockb`.
|
|
2591
|
+
// https://bun.sh/guides/install/yarnlock
|
|
2592
|
+
return (await spawn.spawn(agentExecPath, [lockPath], {
|
|
2593
|
+
cwd,
|
|
2594
|
+
// Lazily access constants.WIN32.
|
|
2595
|
+
shell: constants.WIN32
|
|
2596
|
+
})).stdout.trim();
|
|
2597
|
+
}
|
|
2598
|
+
return undefined;
|
|
2599
|
+
})], [NPM, defaultReader], [PNPM, defaultReader], [VLT, defaultReader], [YARN_BERRY, defaultReader], [YARN_CLASSIC, defaultReader]]);
|
|
2600
|
+
})();
|
|
2888
2601
|
async function detectPackageEnvironment({
|
|
2889
2602
|
cwd = process.cwd(),
|
|
2890
2603
|
onUnknown
|
|
2891
2604
|
} = {}) {
|
|
2892
2605
|
let lockPath = await findUp(Object.keys(LOCKS), {
|
|
2893
2606
|
cwd
|
|
2894
|
-
})
|
|
2895
|
-
let lockName = lockPath ? path.basename(lockPath) : undefined
|
|
2896
|
-
const isHiddenLockFile = lockName === HIDDEN_PACKAGE_LOCK_JSON
|
|
2897
|
-
const pkgJsonPath = lockPath
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
:
|
|
2903
|
-
|
|
2904
|
-
})
|
|
2905
|
-
const pkgPath =
|
|
2906
|
-
pkgJsonPath && fs.existsSync(pkgJsonPath)
|
|
2907
|
-
? path.dirname(pkgJsonPath)
|
|
2908
|
-
: undefined
|
|
2909
|
-
const editablePkgJson = pkgPath
|
|
2910
|
-
? await packages.readPackageJson(pkgPath, {
|
|
2911
|
-
editable: true
|
|
2912
|
-
})
|
|
2913
|
-
: undefined
|
|
2607
|
+
});
|
|
2608
|
+
let lockName = lockPath ? path.basename(lockPath) : undefined;
|
|
2609
|
+
const isHiddenLockFile = lockName === HIDDEN_PACKAGE_LOCK_JSON;
|
|
2610
|
+
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../${PACKAGE_JSON}`) : await findUp(PACKAGE_JSON, {
|
|
2611
|
+
cwd
|
|
2612
|
+
});
|
|
2613
|
+
const pkgPath = pkgJsonPath && fs.existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
|
|
2614
|
+
const editablePkgJson = pkgPath ? await packages.readPackageJson(pkgPath, {
|
|
2615
|
+
editable: true
|
|
2616
|
+
}) : undefined;
|
|
2914
2617
|
// Read Corepack `packageManager` field in package.json:
|
|
2915
2618
|
// https://nodejs.org/api/packages.html#packagemanager
|
|
2916
|
-
const pkgManager = strings.isNonEmptyString(
|
|
2917
|
-
|
|
2918
|
-
)
|
|
2919
|
-
? editablePkgJson.content.packageManager
|
|
2920
|
-
: undefined
|
|
2921
|
-
let agent
|
|
2619
|
+
const pkgManager = strings.isNonEmptyString(editablePkgJson?.content?.packageManager) ? editablePkgJson.content.packageManager : undefined;
|
|
2620
|
+
let agent;
|
|
2922
2621
|
if (pkgManager) {
|
|
2923
2622
|
// A valid "packageManager" field value is "<package manager name>@<version>".
|
|
2924
2623
|
// https://nodejs.org/api/packages.html#packagemanager
|
|
2925
|
-
const atSignIndex = pkgManager.lastIndexOf('@')
|
|
2624
|
+
const atSignIndex = pkgManager.lastIndexOf('@');
|
|
2926
2625
|
if (atSignIndex !== -1) {
|
|
2927
|
-
const name = pkgManager.slice(0, atSignIndex)
|
|
2928
|
-
const version = pkgManager.slice(atSignIndex + 1)
|
|
2929
|
-
if (version && AGENTS.
|
|
2930
|
-
agent = name
|
|
2626
|
+
const name = pkgManager.slice(0, atSignIndex);
|
|
2627
|
+
const version = pkgManager.slice(atSignIndex + 1);
|
|
2628
|
+
if (version && AGENTS.includes(name)) {
|
|
2629
|
+
agent = name;
|
|
2931
2630
|
}
|
|
2932
2631
|
}
|
|
2933
2632
|
}
|
|
2934
|
-
if (
|
|
2935
|
-
agent
|
|
2936
|
-
!isHiddenLockFile &&
|
|
2937
|
-
typeof pkgJsonPath === 'string' &&
|
|
2938
|
-
typeof lockName === 'string'
|
|
2939
|
-
) {
|
|
2940
|
-
agent = LOCKS[lockName]
|
|
2633
|
+
if (agent === undefined && !isHiddenLockFile && typeof pkgJsonPath === 'string' && typeof lockName === 'string') {
|
|
2634
|
+
agent = LOCKS[lockName];
|
|
2941
2635
|
}
|
|
2942
2636
|
if (agent === undefined) {
|
|
2943
|
-
agent = NPM
|
|
2944
|
-
onUnknown?.(pkgManager)
|
|
2637
|
+
agent = NPM;
|
|
2638
|
+
onUnknown?.(pkgManager);
|
|
2945
2639
|
}
|
|
2946
|
-
const agentExecPath = await getAgentExecPath(agent)
|
|
2947
|
-
const agentVersion = await getAgentVersion(agentExecPath, cwd)
|
|
2640
|
+
const agentExecPath = await getAgentExecPath(agent);
|
|
2641
|
+
const agentVersion = await getAgentVersion(agentExecPath, cwd);
|
|
2948
2642
|
if (agent === YARN_CLASSIC && (agentVersion?.major ?? 0) > 1) {
|
|
2949
|
-
agent = YARN_BERRY
|
|
2643
|
+
agent = YARN_BERRY;
|
|
2950
2644
|
}
|
|
2951
2645
|
// Lazily access constants.maintainedNodeVersions.
|
|
2952
|
-
const {
|
|
2646
|
+
const {
|
|
2647
|
+
maintainedNodeVersions
|
|
2648
|
+
} = constants;
|
|
2953
2649
|
// Lazily access constants.minimumVersionByAgent.
|
|
2954
|
-
const minSupportedAgentVersion = constants.minimumVersionByAgent.get(agent)
|
|
2955
|
-
const minSupportedNodeVersion = maintainedNodeVersions.last
|
|
2956
|
-
const nodeVersion = vendor.semverExports.coerce(process.version)
|
|
2957
|
-
let lockSrc
|
|
2958
|
-
let pkgAgentRange
|
|
2959
|
-
let pkgNodeRange
|
|
2960
|
-
let pkgMinAgentVersion = minSupportedAgentVersion
|
|
2961
|
-
let pkgMinNodeVersion = minSupportedNodeVersion
|
|
2650
|
+
const minSupportedAgentVersion = constants.minimumVersionByAgent.get(agent);
|
|
2651
|
+
const minSupportedNodeVersion = maintainedNodeVersions.last;
|
|
2652
|
+
const nodeVersion = vendor.semverExports.coerce(process.version);
|
|
2653
|
+
let lockSrc;
|
|
2654
|
+
let pkgAgentRange;
|
|
2655
|
+
let pkgNodeRange;
|
|
2656
|
+
let pkgMinAgentVersion = minSupportedAgentVersion;
|
|
2657
|
+
let pkgMinNodeVersion = minSupportedNodeVersion;
|
|
2962
2658
|
if (editablePkgJson?.content) {
|
|
2963
|
-
const {
|
|
2964
|
-
|
|
2965
|
-
|
|
2659
|
+
const {
|
|
2660
|
+
engines
|
|
2661
|
+
} = editablePkgJson.content;
|
|
2662
|
+
const engineAgentRange = engines?.[agent];
|
|
2663
|
+
const engineNodeRange = engines?.['node'];
|
|
2966
2664
|
if (strings.isNonEmptyString(engineAgentRange)) {
|
|
2967
|
-
pkgAgentRange = engineAgentRange
|
|
2665
|
+
pkgAgentRange = engineAgentRange;
|
|
2968
2666
|
// Roughly check agent range as semver.coerce will strip leading
|
|
2969
2667
|
// v's, carets (^), comparators (<,<=,>,>=,=), and tildes (~).
|
|
2970
|
-
const coerced = vendor.semverExports.coerce(pkgAgentRange)
|
|
2668
|
+
const coerced = vendor.semverExports.coerce(pkgAgentRange);
|
|
2971
2669
|
if (coerced && vendor.semverExports.lt(coerced, pkgMinAgentVersion)) {
|
|
2972
|
-
pkgMinAgentVersion = coerced.version
|
|
2670
|
+
pkgMinAgentVersion = coerced.version;
|
|
2973
2671
|
}
|
|
2974
2672
|
}
|
|
2975
2673
|
if (strings.isNonEmptyString(engineNodeRange)) {
|
|
2976
|
-
pkgNodeRange = engineNodeRange
|
|
2674
|
+
pkgNodeRange = engineNodeRange;
|
|
2977
2675
|
// Roughly check Node range as semver.coerce will strip leading
|
|
2978
2676
|
// v's, carets (^), comparators (<,<=,>,>=,=), and tildes (~).
|
|
2979
|
-
const coerced = vendor.semverExports.coerce(pkgNodeRange)
|
|
2677
|
+
const coerced = vendor.semverExports.coerce(pkgNodeRange);
|
|
2980
2678
|
if (coerced && vendor.semverExports.lt(coerced, pkgMinNodeVersion)) {
|
|
2981
|
-
pkgMinNodeVersion = coerced.version
|
|
2679
|
+
pkgMinNodeVersion = coerced.version;
|
|
2982
2680
|
}
|
|
2983
2681
|
}
|
|
2984
|
-
const browserslistQuery = editablePkgJson.content['browserslist']
|
|
2682
|
+
const browserslistQuery = editablePkgJson.content['browserslist'];
|
|
2985
2683
|
if (Array.isArray(browserslistQuery)) {
|
|
2986
2684
|
// List Node targets in ascending version order.
|
|
2987
|
-
const browserslistNodeTargets = vendor
|
|
2988
|
-
.browserslistExports(browserslistQuery)
|
|
2989
|
-
.filter(v => /^node /i.test(v))
|
|
2990
|
-
.map(v => v.slice(5 /*'node '.length*/))
|
|
2991
|
-
.sort(sorts.naturalCompare)
|
|
2685
|
+
const browserslistNodeTargets = vendor.browserslistExports(browserslistQuery).filter(v => /^node /i.test(v)).map(v => v.slice(5 /*'node '.length*/)).sort(sorts.naturalCompare);
|
|
2992
2686
|
if (browserslistNodeTargets.length) {
|
|
2993
2687
|
// browserslistNodeTargets[0] is the lowest Node target version.
|
|
2994
|
-
const coerced = vendor.semverExports.coerce(browserslistNodeTargets[0])
|
|
2688
|
+
const coerced = vendor.semverExports.coerce(browserslistNodeTargets[0]);
|
|
2995
2689
|
if (coerced && vendor.semverExports.lt(coerced, pkgMinNodeVersion)) {
|
|
2996
|
-
pkgMinNodeVersion = coerced.version
|
|
2690
|
+
pkgMinNodeVersion = coerced.version;
|
|
2997
2691
|
}
|
|
2998
2692
|
}
|
|
2999
2693
|
}
|
|
3000
|
-
lockSrc =
|
|
3001
|
-
typeof lockPath === 'string'
|
|
3002
|
-
? await readLockFileByAgent.get(agent)(lockPath, agentExecPath, cwd)
|
|
3003
|
-
: undefined
|
|
2694
|
+
lockSrc = typeof lockPath === 'string' ? await readLockFileByAgent.get(agent)(lockPath, agentExecPath, cwd) : undefined;
|
|
3004
2695
|
} else {
|
|
3005
|
-
lockName = undefined
|
|
3006
|
-
lockPath = undefined
|
|
2696
|
+
lockName = undefined;
|
|
2697
|
+
lockPath = undefined;
|
|
3007
2698
|
}
|
|
3008
2699
|
// Does the system agent version meet our minimum supported agent version?
|
|
3009
|
-
const agentSupported =
|
|
3010
|
-
!!agentVersion &&
|
|
3011
|
-
vendor.semverExports.satisfies(
|
|
3012
|
-
agentVersion,
|
|
3013
|
-
`>=${minSupportedAgentVersion}`
|
|
3014
|
-
)
|
|
2700
|
+
const agentSupported = !!agentVersion && vendor.semverExports.satisfies(agentVersion, `>=${minSupportedAgentVersion}`);
|
|
3015
2701
|
|
|
3016
2702
|
// Does the system Node version meet our minimum supported Node version?
|
|
3017
|
-
const nodeSupported = vendor.semverExports.satisfies(
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
)
|
|
3021
|
-
const npmExecPath =
|
|
3022
|
-
agent === NPM ? agentExecPath : await getAgentExecPath(NPM)
|
|
3023
|
-
const npmBuggyOverrides =
|
|
3024
|
-
agent === NPM &&
|
|
3025
|
-
!!agentVersion &&
|
|
3026
|
-
vendor.semverExports.lt(agentVersion, NPM_BUGGY_OVERRIDES_PATCHED_VERSION)
|
|
2703
|
+
const nodeSupported = vendor.semverExports.satisfies(nodeVersion, `>=${minSupportedNodeVersion}`);
|
|
2704
|
+
const npmExecPath = agent === NPM ? agentExecPath : await getAgentExecPath(NPM);
|
|
2705
|
+
const npmBuggyOverrides = agent === NPM && !!agentVersion && vendor.semverExports.lt(agentVersion, NPM_BUGGY_OVERRIDES_PATCHED_VERSION);
|
|
3027
2706
|
return {
|
|
3028
2707
|
agent,
|
|
3029
2708
|
agentExecPath,
|
|
@@ -3046,16 +2725,11 @@ async function detectPackageEnvironment({
|
|
|
3046
2725
|
},
|
|
3047
2726
|
pkgSupports: {
|
|
3048
2727
|
// Does our minimum supported agent version meet the package's requirements?
|
|
3049
|
-
agent: vendor.semverExports.satisfies(
|
|
3050
|
-
minSupportedAgentVersion,
|
|
3051
|
-
`>=${pkgMinAgentVersion}`
|
|
3052
|
-
),
|
|
2728
|
+
agent: vendor.semverExports.satisfies(minSupportedAgentVersion, `>=${pkgMinAgentVersion}`),
|
|
3053
2729
|
// Does our supported Node versions meet the package's requirements?
|
|
3054
|
-
node: maintainedNodeVersions.some(v =>
|
|
3055
|
-
vendor.semverExports.satisfies(v, `>=${pkgMinNodeVersion}`)
|
|
3056
|
-
)
|
|
2730
|
+
node: maintainedNodeVersions.some(v => vendor.semverExports.satisfies(v, `>=${pkgMinNodeVersion}`))
|
|
3057
2731
|
}
|
|
3058
|
-
}
|
|
2732
|
+
};
|
|
3059
2733
|
}
|
|
3060
2734
|
async function detectAndValidatePackageEnvironment(cwd, options) {
|
|
3061
2735
|
const {
|
|
@@ -3065,177 +2739,201 @@ async function detectAndValidatePackageEnvironment(cwd, options) {
|
|
|
3065
2739
|
} = {
|
|
3066
2740
|
__proto__: null,
|
|
3067
2741
|
...options
|
|
3068
|
-
}
|
|
2742
|
+
};
|
|
3069
2743
|
const details = await detectPackageEnvironment({
|
|
3070
2744
|
cwd,
|
|
3071
2745
|
onUnknown(pkgManager) {
|
|
3072
|
-
logger?.warn(
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
}
|
|
3080
|
-
const
|
|
3081
|
-
const agentVersion = details.agentVersion ?? 'unknown'
|
|
2746
|
+
logger?.warn(cmdPrefixMessage(cmdName, `Unknown package manager${pkgManager ? ` ${pkgManager}` : ''}, defaulting to npm`));
|
|
2747
|
+
}
|
|
2748
|
+
});
|
|
2749
|
+
const {
|
|
2750
|
+
agent,
|
|
2751
|
+
nodeVersion,
|
|
2752
|
+
pkgRequirements
|
|
2753
|
+
} = details;
|
|
2754
|
+
const agentVersion = details.agentVersion ?? 'unknown';
|
|
3082
2755
|
if (!details.agentSupported) {
|
|
3083
|
-
const minVersion = constants.minimumVersionByAgent.get(agent)
|
|
3084
|
-
logger?.fail(
|
|
3085
|
-
|
|
3086
|
-
cmdName,
|
|
3087
|
-
`Requires ${agent} >=${minVersion}. Current version: ${agentVersion}.`
|
|
3088
|
-
)
|
|
3089
|
-
)
|
|
3090
|
-
return
|
|
2756
|
+
const minVersion = constants.minimumVersionByAgent.get(agent);
|
|
2757
|
+
logger?.fail(cmdPrefixMessage(cmdName, `Requires ${agent} >=${minVersion}. Current version: ${agentVersion}.`));
|
|
2758
|
+
return;
|
|
3091
2759
|
}
|
|
3092
2760
|
if (!details.nodeSupported) {
|
|
3093
|
-
const minVersion = constants.maintainedNodeVersions.last
|
|
3094
|
-
logger?.fail(
|
|
3095
|
-
|
|
3096
|
-
cmdName,
|
|
3097
|
-
`Requires Node >=${minVersion}. Current version: ${nodeVersion}.`
|
|
3098
|
-
)
|
|
3099
|
-
)
|
|
3100
|
-
return
|
|
2761
|
+
const minVersion = constants.maintainedNodeVersions.last;
|
|
2762
|
+
logger?.fail(cmdPrefixMessage(cmdName, `Requires Node >=${minVersion}. Current version: ${nodeVersion}.`));
|
|
2763
|
+
return;
|
|
3101
2764
|
}
|
|
3102
2765
|
if (!details.pkgSupports.agent) {
|
|
3103
|
-
logger?.fail(
|
|
3104
|
-
|
|
3105
|
-
cmdName,
|
|
3106
|
-
`Package engine "${agent}" requires ${pkgRequirements.agent}. Current version: ${agentVersion}`
|
|
3107
|
-
)
|
|
3108
|
-
)
|
|
3109
|
-
return
|
|
2766
|
+
logger?.fail(cmdPrefixMessage(cmdName, `Package engine "${agent}" requires ${pkgRequirements.agent}. Current version: ${agentVersion}`));
|
|
2767
|
+
return;
|
|
3110
2768
|
}
|
|
3111
2769
|
if (!details.pkgSupports.node) {
|
|
3112
|
-
logger?.fail(
|
|
3113
|
-
|
|
3114
|
-
cmdName,
|
|
3115
|
-
`Package engine "node" requires ${pkgRequirements.node}. Current version: ${nodeVersion}`
|
|
3116
|
-
)
|
|
3117
|
-
)
|
|
3118
|
-
return
|
|
2770
|
+
logger?.fail(cmdPrefixMessage(cmdName, `Package engine "node" requires ${pkgRequirements.node}. Current version: ${nodeVersion}`));
|
|
2771
|
+
return;
|
|
3119
2772
|
}
|
|
3120
2773
|
if (agent === VLT) {
|
|
3121
|
-
logger?.fail(
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
)
|
|
3126
|
-
)
|
|
3127
|
-
return
|
|
3128
|
-
}
|
|
3129
|
-
const lockName = details.lockName ?? 'lock file'
|
|
2774
|
+
logger?.fail(cmdPrefixMessage(cmdName, `${agent} does not support overrides. Soon, though ⚡`));
|
|
2775
|
+
return;
|
|
2776
|
+
}
|
|
2777
|
+
const lockName = details.lockName ?? 'lock file';
|
|
3130
2778
|
if (details.lockName === undefined || details.lockSrc === undefined) {
|
|
3131
|
-
logger?.fail(cmdPrefixMessage(cmdName, `No ${lockName} found`))
|
|
3132
|
-
return
|
|
2779
|
+
logger?.fail(cmdPrefixMessage(cmdName, `No ${lockName} found`));
|
|
2780
|
+
return;
|
|
3133
2781
|
}
|
|
3134
2782
|
if (details.lockSrc.trim() === '') {
|
|
3135
|
-
logger?.fail(cmdPrefixMessage(cmdName, `${lockName} is empty`))
|
|
3136
|
-
return
|
|
2783
|
+
logger?.fail(cmdPrefixMessage(cmdName, `${lockName} is empty`));
|
|
2784
|
+
return;
|
|
3137
2785
|
}
|
|
3138
2786
|
if (details.pkgPath === undefined) {
|
|
3139
|
-
logger?.fail(cmdPrefixMessage(cmdName, `No ${PACKAGE_JSON} found`))
|
|
3140
|
-
return
|
|
2787
|
+
logger?.fail(cmdPrefixMessage(cmdName, `No ${PACKAGE_JSON} found`));
|
|
2788
|
+
return;
|
|
3141
2789
|
}
|
|
3142
2790
|
if (prod && (agent === BUN || agent === YARN_BERRY)) {
|
|
3143
|
-
logger?.fail(
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
)
|
|
3148
|
-
)
|
|
3149
|
-
return
|
|
3150
|
-
}
|
|
3151
|
-
if (
|
|
3152
|
-
details.lockPath &&
|
|
3153
|
-
path.relative(cwd, details.lockPath).startsWith('.')
|
|
3154
|
-
) {
|
|
2791
|
+
logger?.fail(cmdPrefixMessage(cmdName, `--prod not supported for ${agent}${agentVersion ? `@${agentVersion}` : ''}`));
|
|
2792
|
+
return;
|
|
2793
|
+
}
|
|
2794
|
+
if (details.lockPath && path.relative(cwd, details.lockPath).startsWith('.')) {
|
|
3155
2795
|
// Note: In tests we return <redacted> because otherwise snapshots will fail.
|
|
3156
|
-
const {
|
|
2796
|
+
const {
|
|
2797
|
+
REDACTED
|
|
2798
|
+
} = constants;
|
|
3157
2799
|
// Lazily access constants.ENV.VITEST.
|
|
3158
|
-
const redacting = constants.ENV.VITEST
|
|
3159
|
-
logger?.warn(
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
exports.
|
|
3226
|
-
exports.
|
|
3227
|
-
exports.
|
|
3228
|
-
exports.
|
|
3229
|
-
exports.
|
|
3230
|
-
exports.
|
|
3231
|
-
exports.
|
|
3232
|
-
exports.
|
|
3233
|
-
exports.
|
|
3234
|
-
exports.
|
|
3235
|
-
exports.
|
|
3236
|
-
exports.
|
|
3237
|
-
exports.
|
|
3238
|
-
exports.
|
|
3239
|
-
exports.
|
|
3240
|
-
|
|
2800
|
+
const redacting = constants.ENV.VITEST;
|
|
2801
|
+
logger?.warn(cmdPrefixMessage(cmdName, `Package ${lockName} found at ${redacting ? REDACTED : details.lockPath}`));
|
|
2802
|
+
}
|
|
2803
|
+
return details;
|
|
2804
|
+
}
|
|
2805
|
+
|
|
2806
|
+
const COMPLETION_CMD_PREFIX = 'complete -F _socket_completion';
|
|
2807
|
+
function getCompletionSourcingCommand() {
|
|
2808
|
+
// Note: this is exported to distPath in .config/rollup.dist.config.mjs
|
|
2809
|
+
const completionScriptExportPath = path.join(
|
|
2810
|
+
// Lazily access constants.distPath.
|
|
2811
|
+
constants.distPath, 'socket-completion.bash');
|
|
2812
|
+
if (!fs.existsSync(completionScriptExportPath)) {
|
|
2813
|
+
return {
|
|
2814
|
+
ok: false,
|
|
2815
|
+
message: 'Tab Completion script not found',
|
|
2816
|
+
cause: `Expected to find completion script at \`${completionScriptExportPath}\` but it was not there`
|
|
2817
|
+
};
|
|
2818
|
+
}
|
|
2819
|
+
return {
|
|
2820
|
+
ok: true,
|
|
2821
|
+
data: `source ${completionScriptExportPath}`
|
|
2822
|
+
};
|
|
2823
|
+
}
|
|
2824
|
+
function getBashrcDetails(targetCommandName) {
|
|
2825
|
+
const sourcingCommand = getCompletionSourcingCommand();
|
|
2826
|
+
if (!sourcingCommand.ok) {
|
|
2827
|
+
return sourcingCommand;
|
|
2828
|
+
}
|
|
2829
|
+
|
|
2830
|
+
// Lazily access constants.socketAppDataPath.
|
|
2831
|
+
const {
|
|
2832
|
+
socketAppDataPath
|
|
2833
|
+
} = constants;
|
|
2834
|
+
if (!socketAppDataPath) {
|
|
2835
|
+
return {
|
|
2836
|
+
ok: false,
|
|
2837
|
+
message: 'Could not determine config directory',
|
|
2838
|
+
cause: 'Failed to get config path'
|
|
2839
|
+
};
|
|
2840
|
+
}
|
|
2841
|
+
|
|
2842
|
+
// _socket_completion is the function defined in our completion bash script
|
|
2843
|
+
const completionCommand = `${COMPLETION_CMD_PREFIX} ${targetCommandName}`;
|
|
2844
|
+
|
|
2845
|
+
// Location of completion script in config after installing
|
|
2846
|
+
const completionScriptPath = path.join(path.dirname(socketAppDataPath), 'completion', 'socket-completion.bash');
|
|
2847
|
+
const bashrcContent = `# Socket CLI completion for "${targetCommandName}"
|
|
2848
|
+
if [ -f "${completionScriptPath}" ]; then
|
|
2849
|
+
# Load the tab completion script
|
|
2850
|
+
source "${completionScriptPath}"
|
|
2851
|
+
# Tell bash to use this function for tab completion of this function
|
|
2852
|
+
${completionCommand}
|
|
2853
|
+
fi
|
|
2854
|
+
`;
|
|
2855
|
+
return {
|
|
2856
|
+
ok: true,
|
|
2857
|
+
data: {
|
|
2858
|
+
sourcingCommand: sourcingCommand.data,
|
|
2859
|
+
completionCommand,
|
|
2860
|
+
toAddToBashrc: bashrcContent,
|
|
2861
|
+
targetName: targetCommandName,
|
|
2862
|
+
targetPath: completionScriptPath
|
|
2863
|
+
}
|
|
2864
|
+
};
|
|
2865
|
+
}
|
|
2866
|
+
|
|
2867
|
+
exports.ALERT_SEVERITY = ALERT_SEVERITY;
|
|
2868
|
+
exports.AuthError = AuthError;
|
|
2869
|
+
exports.COMPLETION_CMD_PREFIX = COMPLETION_CMD_PREFIX;
|
|
2870
|
+
exports.ColorOrMarkdown = ColorOrMarkdown;
|
|
2871
|
+
exports.InputError = InputError;
|
|
2872
|
+
exports.RangeStyles = RangeStyles;
|
|
2873
|
+
exports.applyRange = applyRange;
|
|
2874
|
+
exports.captureException = captureException;
|
|
2875
|
+
exports.checkCommandInput = checkCommandInput;
|
|
2876
|
+
exports.cmdFlagsToString = cmdFlagsToString;
|
|
2877
|
+
exports.cmdPrefixMessage = cmdPrefixMessage;
|
|
2878
|
+
exports.commonFlags = commonFlags;
|
|
2879
|
+
exports.createEnum = createEnum;
|
|
2880
|
+
exports.detectAndValidatePackageEnvironment = detectAndValidatePackageEnvironment;
|
|
2881
|
+
exports.determineOrgSlug = determineOrgSlug;
|
|
2882
|
+
exports.failMsgWithBadge = failMsgWithBadge;
|
|
2883
|
+
exports.formatSeverityCount = formatSeverityCount;
|
|
2884
|
+
exports.getAlertsMapFromPnpmLockfile = getAlertsMapFromPnpmLockfile;
|
|
2885
|
+
exports.getAlertsMapFromPurls = getAlertsMapFromPurls;
|
|
2886
|
+
exports.getBashrcDetails = getBashrcDetails;
|
|
2887
|
+
exports.getConfigValue = getConfigValue;
|
|
2888
|
+
exports.getConfigValueOrUndef = getConfigValueOrUndef;
|
|
2889
|
+
exports.getCveInfoFromAlertsMap = getCveInfoFromAlertsMap;
|
|
2890
|
+
exports.getFlagListOutput = getFlagListOutput;
|
|
2891
|
+
exports.getMajor = getMajor;
|
|
2892
|
+
exports.getNpmBinPath = getNpmBinPath;
|
|
2893
|
+
exports.getNpmRequire = getNpmRequire;
|
|
2894
|
+
exports.getNpxBinPath = getNpxBinPath;
|
|
2895
|
+
exports.getOutputKind = getOutputKind;
|
|
2896
|
+
exports.getPackageFilesForScan = getPackageFilesForScan;
|
|
2897
|
+
exports.getPkgFullNameFromPurlObj = getPkgFullNameFromPurlObj;
|
|
2898
|
+
exports.getPublicToken = getPublicToken;
|
|
2899
|
+
exports.getSeverityCount = getSeverityCount;
|
|
2900
|
+
exports.getSocketDevAlertUrl = getSocketDevAlertUrl;
|
|
2901
|
+
exports.getSocketDevPackageOverviewUrl = getSocketDevPackageOverviewUrl;
|
|
2902
|
+
exports.getSocketDevPackageOverviewUrlFromPurl = getSocketDevPackageOverviewUrlFromPurl;
|
|
2903
|
+
exports.getVisibleTokenPrefix = getVisibleTokenPrefix;
|
|
2904
|
+
exports.globWorkspace = globWorkspace;
|
|
2905
|
+
exports.handleApiCall = handleApiCall;
|
|
2906
|
+
exports.handleApiCallNoSpinner = handleApiCallNoSpinner;
|
|
2907
|
+
exports.handleUnsuccessfulApiResponse = handleUnsuccessfulApiResponse;
|
|
2908
|
+
exports.hasDefaultToken = hasDefaultToken;
|
|
2909
|
+
exports.idToPurl = idToPurl;
|
|
2910
|
+
exports.isHelpFlag = isHelpFlag;
|
|
2911
|
+
exports.isNpmBinPathShadowed = isNpmBinPathShadowed;
|
|
2912
|
+
exports.isNpxBinPathShadowed = isNpxBinPathShadowed;
|
|
2913
|
+
exports.isReadOnlyConfig = isReadOnlyConfig;
|
|
2914
|
+
exports.isTestingV1 = isTestingV1;
|
|
2915
|
+
exports.logAlertsMap = logAlertsMap;
|
|
2916
|
+
exports.mapToObject = mapToObject;
|
|
2917
|
+
exports.mdTable = mdTable;
|
|
2918
|
+
exports.mdTableOfPairs = mdTableOfPairs;
|
|
2919
|
+
exports.mdTableStringNumber = mdTableStringNumber;
|
|
2920
|
+
exports.meowOrExit = meowOrExit;
|
|
2921
|
+
exports.meowWithSubcommands = meowWithSubcommands;
|
|
2922
|
+
exports.outputFlags = outputFlags;
|
|
2923
|
+
exports.parsePnpmLockfileVersion = parsePnpmLockfileVersion;
|
|
2924
|
+
exports.queryApiSafeJson = queryApiSafeJson;
|
|
2925
|
+
exports.queryApiSafeText = queryApiSafeText;
|
|
2926
|
+
exports.readPnpmLockfile = readPnpmLockfile;
|
|
2927
|
+
exports.removeNodeModules = removeNodeModules;
|
|
2928
|
+
exports.runAgentInstall = runAgentInstall;
|
|
2929
|
+
exports.safeReadFile = safeReadFile;
|
|
2930
|
+
exports.sensitiveConfigKeys = sensitiveConfigKeys;
|
|
2931
|
+
exports.serializeResultJson = serializeResultJson;
|
|
2932
|
+
exports.setupSdk = setupSdk;
|
|
2933
|
+
exports.suggestOrgSlug = suggestOrgSlug;
|
|
2934
|
+
exports.supportedConfigKeys = supportedConfigKeys;
|
|
2935
|
+
exports.updateConfigValue = updateConfigValue;
|
|
2936
|
+
exports.validationFlags = validationFlags;
|
|
2937
|
+
exports.walkNestedMap = walkNestedMap;
|
|
2938
|
+
//# debugId=8743d856-59d2-4e34-8527-7a1be1f6157f
|
|
3241
2939
|
//# sourceMappingURL=utils.js.map
|