@socketsecurity/cli-with-sentry 1.16.1 → 1.17.1
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/CHANGELOG.md +18 -0
- package/LICENSE +87 -0
- package/README.md +13 -13
- package/bin/cli.js +9 -9
- package/dist/.config/tsconfig.dts.tsbuildinfo +1 -1
- package/dist/cli.js +2114 -4292
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +71 -87
- package/dist/constants.js.map +1 -1
- package/dist/env-helpers.js +63 -0
- package/dist/env-helpers.js.map +1 -0
- package/dist/instrument-with-sentry.js +7 -7
- package/dist/instrument-with-sentry.js.map +1 -1
- package/dist/manifest-scripts/dotnet-tool/Microsoft.Build.Locator.dll +0 -0
- package/dist/manifest-scripts/dotnet-tool/socket-facts-dotnet.deps.json +2 -2
- package/dist/manifest-scripts/dotnet-tool/socket-facts-dotnet.dll +0 -0
- package/dist/manifest-scripts/maven-extension/coana-maven-extension.jar +0 -0
- package/dist/runtime-constants.js +345 -0
- package/dist/runtime-constants.js.map +1 -0
- package/dist/shadow-npm-bin2.js +9 -13
- package/dist/shadow-npm-bin2.js.map +1 -1
- package/dist/shadow-npm-inject.js +10 -15
- package/dist/shadow-npm-inject.js.map +1 -1
- package/dist/shadow-npx-bin.js.map +1 -1
- package/dist/shadow-pnpm-bin2.js +21 -25
- package/dist/shadow-pnpm-bin2.js.map +1 -1
- package/dist/shadow-yarn-bin.js +4 -6
- package/dist/shadow-yarn-bin.js.map +1 -1
- package/dist/socket-completion.bash +0 -0
- package/dist/spawn-sync.js +47 -0
- package/dist/spawn-sync.js.map +1 -0
- package/dist/spinner.js +182 -0
- package/dist/spinner.js.map +1 -0
- package/dist/types/commands/fix/generated-socket-facts.d.mts +5 -2
- package/dist/types/commands/fix/handle-fix.d.mts +1 -1
- package/dist/types/commands/fix/types.d.mts +1 -1
- package/dist/types/commands/manifest/bazel/process.d.mts +2 -2
- package/dist/types/commands/manifest/convert-dotnet-to-facts.d.mts +3 -6
- package/dist/types/commands/manifest/discover-manifest-roots.d.mts +10 -11
- package/dist/types/commands/manifest/generate-recursive-manifests.d.mts +16 -30
- package/dist/types/commands/manifest/generate_auto_manifest.d.mts +6 -11
- package/dist/types/commands/manifest/load-build.d.mts +3 -11
- package/dist/types/commands/manifest/run-manifest-facts.d.mts +88 -29
- package/dist/types/commands/manifest/scripts/build-tool.d.mts +2 -0
- package/dist/types/commands/optimize/add-overrides.d.mts +2 -2
- package/dist/types/commands/optimize/get-dependency-entries.d.mts +1 -1
- package/dist/types/commands/optimize/get-overrides-by-agent.d.mts +16 -7
- package/dist/types/commands/optimize/update-lockfile.d.mts +2 -2
- package/dist/types/commands/optimize/update-manifest-by-agent.d.mts +4 -2
- package/dist/types/commands/package/fetch-purls-shallow-score.d.mts +2 -2
- package/dist/types/commands/scan/fetch-supported-scan-file-names.d.mts +1 -1
- package/dist/types/commands/scan/generate-report.d.mts +1 -1
- package/dist/types/commands/scan/handle-create-new-scan.d.mts +5 -1
- package/dist/types/commands/scan/output-create-new-scan.d.mts +1 -1
- package/dist/types/commands/scan/output-diff-scan.d.mts +4 -2
- package/dist/types/commands/scan/perform-reachability-analysis.d.mts +4 -5
- package/dist/types/commands/scan/run-dynamic-sbom-inference.d.mts +7 -15
- package/dist/types/constants/runtime.d.mts +417 -0
- package/dist/types/constants.d.mts +9 -10
- package/dist/types/paths/coana.d.mts +5 -0
- package/dist/types/paths/uv.d.mts +2 -0
- package/dist/types/sea/adapters/cdxgen-worker.d.mts +1 -0
- package/dist/types/sea/adapters/synp-worker.d.mts +1 -0
- package/dist/types/sea/build/cdxgen-fixture.d.mts +4 -0
- package/dist/types/sea/build/smoke-test.d.mts +2 -0
- package/dist/types/sea/build-sea.d.mts +4 -2
- package/dist/types/sea/download-bytes.d.mts +0 -1
- package/dist/types/sea/paths/archive.d.mts +3 -0
- package/dist/types/sea/paths/coana-cache.d.mts +1 -0
- package/dist/types/sea/paths/native-tools.d.mts +13 -0
- package/dist/types/sea/pnpm-lock.d.mts +22 -0
- package/dist/types/sea/rollup-workers.d.mts +1 -0
- package/dist/types/sea/runtime.d.mts +4 -3
- package/dist/types/sea/vfs-digest.d.mts +2 -0
- package/dist/types/shadow/common.d.mts +1 -1
- package/dist/types/shadow/npm/arborist-helpers.d.mts +1 -1
- package/dist/types/shadow/npm/bin.d.mts +1 -1
- package/dist/types/shadow/npm/install.d.mts +3 -3
- package/dist/types/shadow/npm-base.d.mts +1 -1
- package/dist/types/shadow/npx/bin.d.mts +1 -1
- package/dist/types/shadow/pnpm/bin.d.mts +1 -1
- package/dist/types/shadow/yarn/bin.d.mts +1 -1
- package/dist/types/test/mocks/socket-auth.d.mts +40 -39
- package/dist/types/utils/agent.d.mts +6 -1
- package/dist/types/utils/alert/artifact.d.mts +1 -1
- package/dist/types/utils/alerts-map.d.mts +1 -1
- package/dist/types/utils/api.d.mts +1 -1
- package/dist/types/utils/arrays.d.mts +6 -0
- package/dist/types/utils/bin.d.mts +26 -0
- package/dist/types/utils/{coana-release.d.mts → coana/release.d.mts} +5 -3
- package/dist/types/utils/debug.d.mts +23 -49
- package/dist/types/utils/dlx.d.mts +1 -1
- package/dist/types/utils/ecosystem.d.mts +1 -9
- package/dist/types/utils/env.d.mts +24 -0
- package/dist/types/utils/errors.d.mts +2 -2
- package/dist/types/utils/escape-regexp.d.mts +6 -0
- package/dist/types/utils/fs.d.mts +33 -0
- package/dist/types/utils/github.d.mts +1 -1
- package/dist/types/utils/globs.d.mts +1 -0
- package/dist/types/utils/logger.d.mts +51 -0
- package/dist/types/utils/objects.d.mts +11 -0
- package/dist/types/utils/package-environment.d.mts +3 -3
- package/dist/types/utils/packages.d.mts +65 -0
- package/dist/types/utils/path.d.mts +3 -0
- package/dist/types/utils/promises.d.mts +23 -0
- package/dist/types/utils/prompts.d.mts +25 -0
- package/dist/types/utils/purl.d.mts +4 -1
- package/dist/types/utils/socket-package-alert.d.mts +1 -1
- package/dist/types/utils/socket-url.d.mts +1 -1
- package/dist/types/utils/sorts.d.mts +1 -0
- package/dist/types/utils/spawn-sync.d.mts +3 -0
- package/dist/types/utils/spawn.d.mts +67 -0
- package/dist/types/utils/spec.d.mts +1 -1
- package/dist/types/utils/spinner.d.mts +46 -0
- package/dist/types/utils/streams.d.mts +3 -0
- package/dist/types/utils/strings.d.mts +6 -0
- package/dist/types/utils/url.d.mts +2 -0
- package/dist/types/utils/words.d.mts +1 -0
- package/dist/utils.js +4475 -803
- package/dist/utils.js.map +1 -1
- package/dist/vendor.js +39737 -41318
- package/external/blessed-contrib/lib/widget/charts/line.js +172 -149
- package/package.json +41 -37
- package/shadow-bin/npm +0 -0
- package/shadow-bin/npx +0 -0
- package/shadow-bin/pnpm +0 -0
- package/shadow-bin/yarn +0 -0
- package/dist/types/commands/manifest/convert-gradle-to-facts.d.mts +0 -19
- package/dist/types/commands/manifest/convert-maven-to-facts.d.mts +0 -19
- package/dist/types/commands/manifest/convert-sbt-to-facts.d.mts +0 -22
- package/dist/types/commands/manifest/enumerate-workspaces.d.mts +0 -22
- package/dist/types/commands/manifest/expand-env-var-refs.d.mts +0 -9
- package/dist/types/sea/archive-paths.d.mts +0 -6
- package/external/@socketsecurity/registry/LICENSE +0 -21
- package/external/@socketsecurity/registry/README.md +0 -9
- package/external/@socketsecurity/registry/extensions.json +0 -28
- package/external/@socketsecurity/registry/external/@inquirer/confirm.js +0 -3165
- package/external/@socketsecurity/registry/external/@inquirer/input.js +0 -3202
- package/external/@socketsecurity/registry/external/@inquirer/password.js +0 -3307
- package/external/@socketsecurity/registry/external/@inquirer/search.js +0 -3519
- package/external/@socketsecurity/registry/external/@inquirer/select.js +0 -3655
- package/external/@socketsecurity/registry/external/@npmcli/package-json/index.js +0 -21406
- package/external/@socketsecurity/registry/external/@npmcli/package-json/lib/read-package.js +0 -183
- package/external/@socketsecurity/registry/external/@npmcli/package-json/lib/sort.js +0 -274
- package/external/@socketsecurity/registry/external/@npmcli/promise-spawn.js +0 -704
- package/external/@socketsecurity/registry/external/@socketregistry/is-unicode-supported.js +0 -54
- package/external/@socketsecurity/registry/external/@socketregistry/packageurl-js.js +0 -4516
- package/external/@socketsecurity/registry/external/@socketregistry/yocto-spinner.js +0 -453
- package/external/@socketsecurity/registry/external/@yarnpkg/extensions.js +0 -1406
- package/external/@socketsecurity/registry/external/browserslist.js +0 -20496
- package/external/@socketsecurity/registry/external/cacache.js +0 -16208
- package/external/@socketsecurity/registry/external/debug.js +0 -1163
- package/external/@socketsecurity/registry/external/fast-glob.js +0 -7994
- package/external/@socketsecurity/registry/external/fast-sort.js +0 -181
- package/external/@socketsecurity/registry/external/libnpmpack.js +0 -106271
- package/external/@socketsecurity/registry/external/make-fetch-happen.js +0 -38997
- package/external/@socketsecurity/registry/external/normalize-package-data.js +0 -5343
- package/external/@socketsecurity/registry/external/npm-package-arg.js +0 -5773
- package/external/@socketsecurity/registry/external/pacote.js +0 -74109
- package/external/@socketsecurity/registry/external/picomatch.js +0 -2307
- package/external/@socketsecurity/registry/external/semver.js +0 -2618
- package/external/@socketsecurity/registry/external/signal-exit.js +0 -336
- package/external/@socketsecurity/registry/external/spdx-correct.js +0 -1457
- package/external/@socketsecurity/registry/external/spdx-expression-parse.js +0 -1043
- package/external/@socketsecurity/registry/external/streaming-iterables.js +0 -326
- package/external/@socketsecurity/registry/external/validate-npm-package-name.js +0 -108
- package/external/@socketsecurity/registry/external/which.js +0 -405
- package/external/@socketsecurity/registry/external/yoctocolors-cjs.js +0 -101
- package/external/@socketsecurity/registry/index.js +0 -31
- package/external/@socketsecurity/registry/lib/agent.js +0 -390
- package/external/@socketsecurity/registry/lib/arrays.js +0 -89
- package/external/@socketsecurity/registry/lib/bin.js +0 -650
- package/external/@socketsecurity/registry/lib/constants/abort-controller.js +0 -15
- package/external/@socketsecurity/registry/lib/constants/abort-signal.js +0 -27
- package/external/@socketsecurity/registry/lib/constants/at-latest.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/biome-json.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/bun-lock.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/bun-lockb.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/bun.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/ci.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/column-limit.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/copy-left-licenses.js +0 -27
- package/external/@socketsecurity/registry/lib/constants/darwin.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/dot-git-dir.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/dot-package-lock-json.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/dot-socket-dir.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/empty-file.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/empty-value.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/env.js +0 -59
- package/external/@socketsecurity/registry/lib/constants/eslint-config-js.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/esnext.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/exec-path.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/ext-cjs.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/ext-cmd.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/ext-cts.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/ext-dts.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/ext-js.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/ext-json.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/ext-lock.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/ext-lockb.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/ext-md.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/ext-mjs.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/ext-mts.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/ext-ps1.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/ext-yaml.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/ext-yml.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/extensions-json.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/extensions.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/get-ipc.js +0 -10
- package/external/@socketsecurity/registry/lib/constants/gitignore.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/index.js +0 -139
- package/external/@socketsecurity/registry/lib/constants/ipc-handler.js +0 -19
- package/external/@socketsecurity/registry/lib/constants/ipc-object.js +0 -6
- package/external/@socketsecurity/registry/lib/constants/ipc-promise.js +0 -47
- package/external/@socketsecurity/registry/lib/constants/ipc-target.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/k-internals-symbol.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/latest.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/license-glob-recursive.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/license-glob.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/license-original-glob-recursive.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/license-original-glob.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/license-original.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/license.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/lifecycle-script-names.js +0 -18
- package/external/@socketsecurity/registry/lib/constants/loop-sentinel.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/maintained-node-versions.js +0 -47
- package/external/@socketsecurity/registry/lib/constants/manifest-json.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/mit.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/node-auth-token.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/node-debug-flags.js +0 -9
- package/external/@socketsecurity/registry/lib/constants/node-env.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/node-harden-flags.js +0 -29
- package/external/@socketsecurity/registry/lib/constants/node-modules-glob-recursive.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/node-modules.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/node-no-warnings-flags.js +0 -16
- package/external/@socketsecurity/registry/lib/constants/node-version.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/npm-exec-path.js +0 -5
- package/external/@socketsecurity/registry/lib/constants/npm-real-exec-path.js +0 -6
- package/external/@socketsecurity/registry/lib/constants/npm-shrinkwrap-json.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/npm.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/npx.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/overrides.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/package-default-node-range.js +0 -6
- package/external/@socketsecurity/registry/lib/constants/package-default-socket-categories.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/package-default-version.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/package-extensions.js +0 -47
- package/external/@socketsecurity/registry/lib/constants/package-json.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/package-lock-json.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/packument-cache.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/pacote-cache-path.js +0 -9
- package/external/@socketsecurity/registry/lib/constants/pnpm-exec-path.js +0 -5
- package/external/@socketsecurity/registry/lib/constants/pnpm-lock-yaml.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/pnpm.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/pre-commit.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/readme-glob-recursive.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/readme-glob.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/readme-md.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/registry-scope-delimiter.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/registry.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/resolutions.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/socket-github-org.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/socket-ipc-handshake.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/socket-override-scope.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/socket-public-api-token.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/socket-registry-npm-org.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/socket-registry-package-name.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/socket-registry-repo-name.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/socket-registry-scope.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/socket-security-scope.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/spinner.js +0 -4
- package/external/@socketsecurity/registry/lib/constants/supports-node-compile-cache-api.js +0 -8
- package/external/@socketsecurity/registry/lib/constants/supports-node-compile-cache-env-var.js +0 -8
- package/external/@socketsecurity/registry/lib/constants/supports-node-disable-warning-flag.js +0 -8
- package/external/@socketsecurity/registry/lib/constants/supports-node-permission-flag.js +0 -8
- package/external/@socketsecurity/registry/lib/constants/supports-node-require-module.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/supports-node-run.js +0 -8
- package/external/@socketsecurity/registry/lib/constants/supports-process-send.js +0 -5
- package/external/@socketsecurity/registry/lib/constants/ts-libs-available.js +0 -22
- package/external/@socketsecurity/registry/lib/constants/ts-types-available.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/tsconfig-json.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/undefined-token.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/unknown-error.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/unknown-value.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/unlicenced.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/unlicensed.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/utf8.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/vitest.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/vlt-lock-json.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/vlt.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/win32.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/yarn-berry.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/yarn-classic.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/yarn-exec-path.js +0 -5
- package/external/@socketsecurity/registry/lib/constants/yarn-lock.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/yarn.js +0 -3
- package/external/@socketsecurity/registry/lib/debug.js +0 -264
- package/external/@socketsecurity/registry/lib/env.js +0 -62
- package/external/@socketsecurity/registry/lib/fs.js +0 -556
- package/external/@socketsecurity/registry/lib/functions.js +0 -20
- package/external/@socketsecurity/registry/lib/globs.js +0 -145
- package/external/@socketsecurity/registry/lib/json.js +0 -69
- package/external/@socketsecurity/registry/lib/logger.js +0 -534
- package/external/@socketsecurity/registry/lib/objects.js +0 -422
- package/external/@socketsecurity/registry/lib/packages.js +0 -1379
- package/external/@socketsecurity/registry/lib/path.js +0 -231
- package/external/@socketsecurity/registry/lib/promises.js +0 -286
- package/external/@socketsecurity/registry/lib/prompts.js +0 -63
- package/external/@socketsecurity/registry/lib/regexps.js +0 -23
- package/external/@socketsecurity/registry/lib/sorts.js +0 -70
- package/external/@socketsecurity/registry/lib/spawn.js +0 -252
- package/external/@socketsecurity/registry/lib/spinner.js +0 -205
- package/external/@socketsecurity/registry/lib/streams.js +0 -84
- package/external/@socketsecurity/registry/lib/strings.js +0 -235
- package/external/@socketsecurity/registry/lib/url.js +0 -68
- package/external/@socketsecurity/registry/lib/words.js +0 -45
- package/external/@socketsecurity/registry/manifest.json +0 -1875
|
@@ -1,1379 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { isArray: ArrayIsArray } = Array
|
|
4
|
-
const { hasOwn: ObjectHasOwn } = Object
|
|
5
|
-
|
|
6
|
-
const abortSignal = /*@__PURE__*/ require('./constants/abort-signal')
|
|
7
|
-
const copyLeftLicenses = /*@__PURE__*/ require('./constants/copy-left-licenses')
|
|
8
|
-
const LOOP_SENTINEL = /*@__PURE__*/ require('./constants/loop-sentinel')
|
|
9
|
-
const PACKAGE_DEFAULT_SOCKET_CATEGORIES = /*@__PURE__*/ require('./constants/package-default-socket-categories')
|
|
10
|
-
const packumentCache = /*@__PURE__*/ require('./constants/packument-cache')
|
|
11
|
-
const REGISTRY_SCOPE_DELIMITER = /*@__PURE__*/ require('./constants/registry-scope-delimiter')
|
|
12
|
-
const SOCKET_GITHUB_ORG = /*@__PURE__*/ require('./constants/socket-github-org')
|
|
13
|
-
const SOCKET_REGISTRY_REPO_NAME = /*@__PURE__*/ require('./constants/socket-registry-repo-name')
|
|
14
|
-
const SOCKET_REGISTRY_SCOPE = /*@__PURE__*/ require('./constants/socket-registry-scope')
|
|
15
|
-
const { readJson, readJsonSync } = /*@__PURE__*/ require('./fs')
|
|
16
|
-
const {
|
|
17
|
-
getOwnPropertyValues,
|
|
18
|
-
isObject,
|
|
19
|
-
isObjectObject,
|
|
20
|
-
merge,
|
|
21
|
-
objectEntries
|
|
22
|
-
} = /*@__PURE__*/ require('./objects')
|
|
23
|
-
const { isNodeModules, normalizePath } = /*@__PURE__*/ require('./path')
|
|
24
|
-
const { escapeRegExp } = /*@__PURE__*/ require('./regexps')
|
|
25
|
-
const { isNonEmptyString } = /*@__PURE__*/ require('./strings')
|
|
26
|
-
|
|
27
|
-
const BINARY_OPERATION_NODE_TYPE = 'BinaryOperation'
|
|
28
|
-
const LICENSE_NODE_TYPE = 'License'
|
|
29
|
-
|
|
30
|
-
const escapedScopeRegExp = new RegExp(
|
|
31
|
-
`^[^${escapeRegExp(REGISTRY_SCOPE_DELIMITER[0])}]+${escapeRegExp(REGISTRY_SCOPE_DELIMITER)}(?!${escapeRegExp(REGISTRY_SCOPE_DELIMITER[0])})`
|
|
32
|
-
)
|
|
33
|
-
const fileReferenceRegExp = /^SEE LICEN[CS]E IN (.+)$/
|
|
34
|
-
const pkgScopePrefixRegExp = /^@socketregistry\//
|
|
35
|
-
|
|
36
|
-
const identSymbol = Symbol.for('indent')
|
|
37
|
-
const newlineSymbol = Symbol.for('newline')
|
|
38
|
-
|
|
39
|
-
let _cacache
|
|
40
|
-
/**
|
|
41
|
-
* Get the cacache module for cache operations.
|
|
42
|
-
* @returns {Object} The cacache module.
|
|
43
|
-
* @private
|
|
44
|
-
*/
|
|
45
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
46
|
-
function getCacache() {
|
|
47
|
-
if (_cacache === undefined) {
|
|
48
|
-
_cacache = /*@__PURE__*/ require('../external/cacache')
|
|
49
|
-
}
|
|
50
|
-
return _cacache
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let _EditablePackageJsonClass
|
|
54
|
-
/**
|
|
55
|
-
* Get the EditablePackageJson class for package.json manipulation.
|
|
56
|
-
* @returns {Class} The EditablePackageJson class.
|
|
57
|
-
* @private
|
|
58
|
-
*/
|
|
59
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
60
|
-
function getEditablePackageJsonClass() {
|
|
61
|
-
if (_EditablePackageJsonClass === undefined) {
|
|
62
|
-
const EditablePackageJsonBase = /*@__PURE__*/ require('../external/@npmcli/package-json')
|
|
63
|
-
const {
|
|
64
|
-
parse,
|
|
65
|
-
read
|
|
66
|
-
} = /*@__PURE__*/ require('../external/@npmcli/package-json/lib/read-package')
|
|
67
|
-
const {
|
|
68
|
-
packageSort
|
|
69
|
-
} = /*@__PURE__*/ require('../external/@npmcli/package-json/lib/sort')
|
|
70
|
-
_EditablePackageJsonClass = class EditablePackageJson extends (
|
|
71
|
-
EditablePackageJsonBase
|
|
72
|
-
) {
|
|
73
|
-
static fixSteps = EditablePackageJsonBase.fixSteps
|
|
74
|
-
static normalizeSteps = EditablePackageJsonBase.normalizeSteps
|
|
75
|
-
static prepareSteps = EditablePackageJsonBase.prepareSteps
|
|
76
|
-
|
|
77
|
-
_canSave = true
|
|
78
|
-
_path = undefined
|
|
79
|
-
_readFileContent = ''
|
|
80
|
-
_readFileJson = null
|
|
81
|
-
|
|
82
|
-
static async create(path, opts = {}) {
|
|
83
|
-
const p = new _EditablePackageJsonClass()
|
|
84
|
-
await p.create(path)
|
|
85
|
-
return opts.data ? p.update(opts.data) : p
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
static async fix(path, opts) {
|
|
89
|
-
const p = new _EditablePackageJsonClass()
|
|
90
|
-
await p.load(path, true)
|
|
91
|
-
return p.fix(opts)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
static async load(path, opts = {}) {
|
|
95
|
-
const p = new _EditablePackageJsonClass()
|
|
96
|
-
// Avoid try/catch if we aren't going to create
|
|
97
|
-
if (!opts.create) {
|
|
98
|
-
return await p.load(path)
|
|
99
|
-
}
|
|
100
|
-
try {
|
|
101
|
-
return await p.load(path)
|
|
102
|
-
} catch (err) {
|
|
103
|
-
if (!err.message.startsWith('Could not read package.json')) {
|
|
104
|
-
throw err
|
|
105
|
-
}
|
|
106
|
-
return await p.create(path)
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
static async normalize(path, opts) {
|
|
111
|
-
const p = new _EditablePackageJsonClass()
|
|
112
|
-
await p.load(path)
|
|
113
|
-
return await p.normalize(opts)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
static async prepare(path, opts) {
|
|
117
|
-
const p = new _EditablePackageJsonClass()
|
|
118
|
-
await p.load(path, true)
|
|
119
|
-
return await p.prepare(opts)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
create(path) {
|
|
123
|
-
super.create(path)
|
|
124
|
-
this._path = path
|
|
125
|
-
return this
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async fix(opts = {}) {
|
|
129
|
-
await super.fix(opts)
|
|
130
|
-
return this
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
fromComment(data) {
|
|
134
|
-
super.fromComment(data)
|
|
135
|
-
return this
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
fromContent(data) {
|
|
139
|
-
super.fromContent(data)
|
|
140
|
-
this._canSave = false
|
|
141
|
-
return this
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
fromJSON(data) {
|
|
145
|
-
super.fromJSON(data)
|
|
146
|
-
return this
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async load(path, parseIndex) {
|
|
150
|
-
this._path = path
|
|
151
|
-
const { promises: fsPromises } = getFs()
|
|
152
|
-
let parseErr
|
|
153
|
-
try {
|
|
154
|
-
this._readFileContent = await read(this.filename)
|
|
155
|
-
} catch (err) {
|
|
156
|
-
if (!parseIndex) {
|
|
157
|
-
throw err
|
|
158
|
-
}
|
|
159
|
-
parseErr = err
|
|
160
|
-
}
|
|
161
|
-
if (parseErr) {
|
|
162
|
-
const indexFile = path.resolve(this.path, 'index.js')
|
|
163
|
-
let indexFileContent
|
|
164
|
-
try {
|
|
165
|
-
indexFileContent = await fsPromises.readFile(indexFile, 'utf8')
|
|
166
|
-
} catch {
|
|
167
|
-
throw parseErr
|
|
168
|
-
}
|
|
169
|
-
try {
|
|
170
|
-
this.fromComment(indexFileContent)
|
|
171
|
-
} catch {
|
|
172
|
-
throw parseErr
|
|
173
|
-
}
|
|
174
|
-
// This wasn't a package.json so prevent saving
|
|
175
|
-
this._canSave = false
|
|
176
|
-
return this
|
|
177
|
-
}
|
|
178
|
-
this.fromJSON(this._readFileContent)
|
|
179
|
-
// Add AFTER fromJSON is called in case it errors.
|
|
180
|
-
this._readFileJson = parse(this._readFileContent)
|
|
181
|
-
return this
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
async normalize(opts = {}) {
|
|
185
|
-
await super.normalize(opts)
|
|
186
|
-
return this
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
get path() {
|
|
190
|
-
return this._path
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
async prepare(opts = {}) {
|
|
194
|
-
await super.prepare(opts)
|
|
195
|
-
return this
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async save(options) {
|
|
199
|
-
if (!this._canSave || this.content === undefined) {
|
|
200
|
-
throw new Error('No package.json to save to')
|
|
201
|
-
}
|
|
202
|
-
const { ignoreWhitespace = false, sort = false } = {
|
|
203
|
-
__proto__: null,
|
|
204
|
-
...options
|
|
205
|
-
}
|
|
206
|
-
const {
|
|
207
|
-
[identSymbol]: indent,
|
|
208
|
-
[newlineSymbol]: newline,
|
|
209
|
-
...rest
|
|
210
|
-
} = this.content
|
|
211
|
-
const content = sort ? packageSort(rest) : rest
|
|
212
|
-
const {
|
|
213
|
-
[identSymbol]: _indent,
|
|
214
|
-
[newlineSymbol]: _newline,
|
|
215
|
-
...origContent
|
|
216
|
-
} = this._readFileJson
|
|
217
|
-
|
|
218
|
-
if (
|
|
219
|
-
ignoreWhitespace &&
|
|
220
|
-
getUtil().isDeepStrictEqual(content, origContent)
|
|
221
|
-
) {
|
|
222
|
-
return false
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const format = this._readFileJson?.[identSymbol] ?? indent ?? ' '
|
|
226
|
-
const eol = this._readFileJson?.[newlineSymbol] ?? newline ?? '\n'
|
|
227
|
-
const bom = this._readFileContent.charCodeAt(0) === 0xfeff ? '\uFEFF' : ''
|
|
228
|
-
const fileContent = bom + `${JSON.stringify(
|
|
229
|
-
content,
|
|
230
|
-
null,
|
|
231
|
-
format
|
|
232
|
-
)}\n`.replace(/\n/g, eol)
|
|
233
|
-
|
|
234
|
-
if (
|
|
235
|
-
!ignoreWhitespace &&
|
|
236
|
-
fileContent.trim() === this._readFileContent.trim()
|
|
237
|
-
) {
|
|
238
|
-
return false
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const { promises: fsPromises } = getFs()
|
|
242
|
-
await fsPromises.writeFile(this.filename, fileContent)
|
|
243
|
-
this._readFileContent = fileContent
|
|
244
|
-
this._readFileJson = parse(fileContent)
|
|
245
|
-
return true
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
async saveSync(options) {
|
|
249
|
-
if (!this._canSave || this.content === undefined) {
|
|
250
|
-
throw new Error('No package.json to save to')
|
|
251
|
-
}
|
|
252
|
-
const { ignoreWhitespace = false, sort = false } = {
|
|
253
|
-
__proto__: null,
|
|
254
|
-
...options
|
|
255
|
-
}
|
|
256
|
-
const {
|
|
257
|
-
[Symbol.for('indent')]: indent,
|
|
258
|
-
[Symbol.for('newline')]: newline,
|
|
259
|
-
...rest
|
|
260
|
-
} = this.content
|
|
261
|
-
const content = sort ? packageSort(rest) : rest
|
|
262
|
-
|
|
263
|
-
if (
|
|
264
|
-
ignoreWhitespace &&
|
|
265
|
-
getUtil().isDeepStrictEqual(content, this._readFileJson)
|
|
266
|
-
) {
|
|
267
|
-
return false
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const format = this._readFileJson?.[identSymbol] ?? indent ?? ' '
|
|
271
|
-
const eol = this._readFileJson?.[newlineSymbol] ?? newline ?? '\n'
|
|
272
|
-
const bom = this._readFileContent.charCodeAt(0) === 0xfeff ? '\uFEFF' : ''
|
|
273
|
-
const fileContent = bom + `${JSON.stringify(
|
|
274
|
-
content,
|
|
275
|
-
null,
|
|
276
|
-
format
|
|
277
|
-
)}\n`.replace(/\n/g, eol)
|
|
278
|
-
|
|
279
|
-
if (
|
|
280
|
-
!ignoreWhitespace &&
|
|
281
|
-
fileContent.trim() === this._readFileContent.trim()
|
|
282
|
-
) {
|
|
283
|
-
return false
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const fs = getFs()
|
|
287
|
-
fs.writeFileSync(this.filename, fileContent)
|
|
288
|
-
this._readFileContent = fileContent
|
|
289
|
-
this._readFileJson = parse(fileContent)
|
|
290
|
-
return true
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
update(content) {
|
|
294
|
-
super.update(content)
|
|
295
|
-
return this
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
willSave(options) {
|
|
299
|
-
const { ignoreWhitespace = false, sort = false } = {
|
|
300
|
-
__proto__: null,
|
|
301
|
-
...options
|
|
302
|
-
}
|
|
303
|
-
if (!this._canSave || this.content === undefined) {
|
|
304
|
-
return false
|
|
305
|
-
}
|
|
306
|
-
const {
|
|
307
|
-
[Symbol.for('indent')]: indent,
|
|
308
|
-
[Symbol.for('newline')]: newline,
|
|
309
|
-
...rest
|
|
310
|
-
} = this.content
|
|
311
|
-
const content = sort ? packageSort(rest) : rest
|
|
312
|
-
|
|
313
|
-
if (
|
|
314
|
-
ignoreWhitespace &&
|
|
315
|
-
getUtil().isDeepStrictEqual(content, this._readFileJson)
|
|
316
|
-
) {
|
|
317
|
-
return false
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
const format = this._readFileJson?.[identSymbol] ?? indent ?? ' '
|
|
321
|
-
const eol = this._readFileJson?.[newlineSymbol] ?? newline ?? '\n'
|
|
322
|
-
const bom = this._readFileContent.charCodeAt(0) === 0xfeff ? '\uFEFF' : ''
|
|
323
|
-
const fileContent = bom + `${JSON.stringify(
|
|
324
|
-
content,
|
|
325
|
-
null,
|
|
326
|
-
format
|
|
327
|
-
)}\n`.replace(/\n/g, eol)
|
|
328
|
-
|
|
329
|
-
if (
|
|
330
|
-
!ignoreWhitespace &&
|
|
331
|
-
fileContent.trim() === this._readFileContent.trim()
|
|
332
|
-
) {
|
|
333
|
-
return false
|
|
334
|
-
}
|
|
335
|
-
return true
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return _EditablePackageJsonClass
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
let _fetcher
|
|
343
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
344
|
-
function getFetcher() {
|
|
345
|
-
if (_fetcher === undefined) {
|
|
346
|
-
const makeFetchHappen = /*@__PURE__*/ require('../external/make-fetch-happen')
|
|
347
|
-
_fetcher = makeFetchHappen.defaults({
|
|
348
|
-
cachePath: /*@__PURE__*/ require('./constants/pacote-cache-path'),
|
|
349
|
-
// Prefer-offline: Staleness checks for cached data will be bypassed, but
|
|
350
|
-
// missing data will be requested from the server.
|
|
351
|
-
// https://github.com/npm/make-fetch-happen?tab=readme-ov-file#--optscache
|
|
352
|
-
cache: 'force-cache'
|
|
353
|
-
})
|
|
354
|
-
}
|
|
355
|
-
return _fetcher
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
let _fs
|
|
359
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
360
|
-
function getFs() {
|
|
361
|
-
if (_fs === undefined) {
|
|
362
|
-
// Use non-'node:' prefixed require to avoid Webpack errors.
|
|
363
|
-
// eslint-disable-next-line n/prefer-node-protocol
|
|
364
|
-
_fs = /*@__PURE__*/ require('fs')
|
|
365
|
-
}
|
|
366
|
-
return _fs
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
let _normalizePackageData
|
|
370
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
371
|
-
function getNormalizePackageData() {
|
|
372
|
-
if (_normalizePackageData === undefined) {
|
|
373
|
-
_normalizePackageData = /*@__PURE__*/ require('../external/normalize-package-data')
|
|
374
|
-
}
|
|
375
|
-
return _normalizePackageData
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
let _npmPackageArg
|
|
379
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
380
|
-
function getNpmPackageArg() {
|
|
381
|
-
if (_npmPackageArg === undefined) {
|
|
382
|
-
_npmPackageArg = /*@__PURE__*/ require('../external/npm-package-arg')
|
|
383
|
-
}
|
|
384
|
-
return _npmPackageArg
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
let _pack
|
|
388
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
389
|
-
function getPack() {
|
|
390
|
-
if (_pack === undefined) {
|
|
391
|
-
_pack = /*@__PURE__*/ require('../external/libnpmpack')
|
|
392
|
-
}
|
|
393
|
-
return _pack
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
let _PackageURL
|
|
397
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
398
|
-
function getPackageURL() {
|
|
399
|
-
if (_PackageURL === undefined) {
|
|
400
|
-
// The 'packageurl-js' package is browser safe.
|
|
401
|
-
const packageUrlJs = /*@__PURE__*/ require('../external/@socketregistry/packageurl-js')
|
|
402
|
-
_PackageURL = packageUrlJs.PackageURL
|
|
403
|
-
}
|
|
404
|
-
return _PackageURL
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
let _pacote
|
|
408
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
409
|
-
function getPacote() {
|
|
410
|
-
if (_pacote === undefined) {
|
|
411
|
-
_pacote = /*@__PURE__*/ require('../external/pacote')
|
|
412
|
-
}
|
|
413
|
-
return _pacote
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
let _path
|
|
417
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
418
|
-
function getPath() {
|
|
419
|
-
if (_path === undefined) {
|
|
420
|
-
// Use non-'node:' prefixed require to avoid Webpack errors.
|
|
421
|
-
// eslint-disable-next-line n/prefer-node-protocol
|
|
422
|
-
_path = /*@__PURE__*/ require('path')
|
|
423
|
-
}
|
|
424
|
-
return _path
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
let _semver
|
|
428
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
429
|
-
function getSemver() {
|
|
430
|
-
if (_semver === undefined) {
|
|
431
|
-
// The 'semver' package is browser safe.
|
|
432
|
-
_semver = /*@__PURE__*/ require('../external/semver')
|
|
433
|
-
}
|
|
434
|
-
return _semver
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
let _spdxCorrect
|
|
438
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
439
|
-
function getSpdxCorrect() {
|
|
440
|
-
if (_spdxCorrect === undefined) {
|
|
441
|
-
// The 'spdx-correct' package is browser safe.
|
|
442
|
-
_spdxCorrect = /*@__PURE__*/ require('../external/spdx-correct')
|
|
443
|
-
}
|
|
444
|
-
return _spdxCorrect
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
let _spdxExpParse
|
|
448
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
449
|
-
function getSpdxExpParse() {
|
|
450
|
-
if (_spdxExpParse === undefined) {
|
|
451
|
-
// The 'spdx-expression-parse' package is browser safe.
|
|
452
|
-
_spdxExpParse = /*@__PURE__*/ require('../external/spdx-expression-parse')
|
|
453
|
-
}
|
|
454
|
-
return _spdxExpParse
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
let _util
|
|
458
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
459
|
-
function getUtil() {
|
|
460
|
-
if (_util === undefined) {
|
|
461
|
-
// Use non-'node:' prefixed require to avoid Webpack errors.
|
|
462
|
-
// eslint-disable-next-line n/prefer-node-protocol
|
|
463
|
-
_util = /*@__PURE__*/ require('util')
|
|
464
|
-
}
|
|
465
|
-
return _util
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
let _validateNpmPackageName
|
|
469
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
470
|
-
function getValidateNpmPackageName() {
|
|
471
|
-
if (_validateNpmPackageName === undefined) {
|
|
472
|
-
_validateNpmPackageName = /*@__PURE__*/ require('../external/validate-npm-package-name')
|
|
473
|
-
}
|
|
474
|
-
return _validateNpmPackageName
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Collect licenses that are incompatible (copyleft).
|
|
479
|
-
* @param {Object[]} licenseNodes - Array of license nodes.
|
|
480
|
-
* @returns {Object[]} Array of incompatible license nodes.
|
|
481
|
-
*/
|
|
482
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
483
|
-
function collectIncompatibleLicenses(licenseNodes) {
|
|
484
|
-
const result = []
|
|
485
|
-
for (let i = 0, { length } = licenseNodes; i < length; i += 1) {
|
|
486
|
-
const node = licenseNodes[i]
|
|
487
|
-
if (copyLeftLicenses.has(node.license)) {
|
|
488
|
-
result.push(node)
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
return result
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
/**
|
|
495
|
-
* Collect warnings from license nodes.
|
|
496
|
-
* @param {Object[]} licenseNodes - Array of license nodes.
|
|
497
|
-
* @returns {string[]} Array of warning messages.
|
|
498
|
-
*/
|
|
499
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
500
|
-
function collectLicenseWarnings(licenseNodes) {
|
|
501
|
-
const warnings = new Map()
|
|
502
|
-
for (let i = 0, { length } = licenseNodes; i < length; i += 1) {
|
|
503
|
-
const node = licenseNodes[i]
|
|
504
|
-
const { license } = node
|
|
505
|
-
if (license === 'UNLICENSED') {
|
|
506
|
-
warnings.set('UNLICENSED', `Package is unlicensed`)
|
|
507
|
-
} else if (node.inFile !== undefined) {
|
|
508
|
-
warnings.set('IN_FILE', `License terms specified in ${node.inFile}`)
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
return [...warnings.values()]
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* Create an AST node from a raw node.
|
|
516
|
-
* @param {Object} rawNode - Raw node data.
|
|
517
|
-
* @returns {Object} AST node.
|
|
518
|
-
*/
|
|
519
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
520
|
-
function createAstNode(rawNode) {
|
|
521
|
-
return ObjectHasOwn(rawNode, 'license')
|
|
522
|
-
? createLicenseNode(rawNode)
|
|
523
|
-
: createBinaryOperationNode(rawNode)
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* Create a binary operation AST node.
|
|
528
|
-
* @param {Object} rawNode - Raw node with left, right, and conjunction.
|
|
529
|
-
* @returns {Object} Binary operation node.
|
|
530
|
-
*/
|
|
531
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
532
|
-
function createBinaryOperationNode(rawNode) {
|
|
533
|
-
let left
|
|
534
|
-
let right
|
|
535
|
-
let { left: rawLeft, right: rawRight } = rawNode
|
|
536
|
-
const { conjunction } = rawNode
|
|
537
|
-
rawNode = undefined
|
|
538
|
-
return {
|
|
539
|
-
__proto__: null,
|
|
540
|
-
type: BINARY_OPERATION_NODE_TYPE,
|
|
541
|
-
get left() {
|
|
542
|
-
if (left === undefined) {
|
|
543
|
-
left = createAstNode(rawLeft)
|
|
544
|
-
rawLeft = undefined
|
|
545
|
-
}
|
|
546
|
-
return left
|
|
547
|
-
},
|
|
548
|
-
conjunction,
|
|
549
|
-
get right() {
|
|
550
|
-
if (right === undefined) {
|
|
551
|
-
right = createAstNode(rawRight)
|
|
552
|
-
rawRight = undefined
|
|
553
|
-
}
|
|
554
|
-
return right
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* Create a license AST node.
|
|
561
|
-
* @param {Object} rawNode - Raw license node data.
|
|
562
|
-
* @returns {Object} License node.
|
|
563
|
-
*/
|
|
564
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
565
|
-
function createLicenseNode(rawNode) {
|
|
566
|
-
return { __proto__: null, ...rawNode, type: LICENSE_NODE_TYPE }
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
/**
|
|
570
|
-
* Create a package.json object for a Socket registry package.
|
|
571
|
-
* @param {string} sockRegPkgName - Socket registry package name.
|
|
572
|
-
* @param {string} directory - Directory path.
|
|
573
|
-
* @param {Object} [options] - Creation options.
|
|
574
|
-
* @returns {Object} Package.json object.
|
|
575
|
-
*/
|
|
576
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
577
|
-
function createPackageJson(sockRegPkgName, directory, options) {
|
|
578
|
-
const {
|
|
579
|
-
dependencies,
|
|
580
|
-
description,
|
|
581
|
-
engines,
|
|
582
|
-
exports: entryExportsRaw,
|
|
583
|
-
files,
|
|
584
|
-
keywords,
|
|
585
|
-
main,
|
|
586
|
-
overrides,
|
|
587
|
-
resolutions,
|
|
588
|
-
sideEffects,
|
|
589
|
-
socket,
|
|
590
|
-
type,
|
|
591
|
-
version
|
|
592
|
-
} = { __proto__: null, ...options }
|
|
593
|
-
const PACKAGE_DEFAULT_NODE_RANGE = /*@__PURE__*/ require('./constants/package-default-node-range')
|
|
594
|
-
const name = `@socketregistry/${sockRegPkgName.replace(pkgScopePrefixRegExp, '')}`
|
|
595
|
-
const entryExports = resolvePackageJsonEntryExports(entryExportsRaw)
|
|
596
|
-
const githubUrl = `https://github.com/${SOCKET_GITHUB_ORG}/${SOCKET_REGISTRY_REPO_NAME}`
|
|
597
|
-
return {
|
|
598
|
-
__proto__: null,
|
|
599
|
-
name,
|
|
600
|
-
version,
|
|
601
|
-
license: 'MIT',
|
|
602
|
-
description,
|
|
603
|
-
keywords,
|
|
604
|
-
homepage: `${githubUrl}/tree/main/${directory}`,
|
|
605
|
-
repository: {
|
|
606
|
-
type: 'git',
|
|
607
|
-
url: `git+${githubUrl}.git`,
|
|
608
|
-
directory
|
|
609
|
-
},
|
|
610
|
-
...(type ? { type } : {}),
|
|
611
|
-
...(entryExports ? { exports: { ...entryExports } } : {}),
|
|
612
|
-
...(entryExports ? {} : { main: `${main ?? './index.js'}` }),
|
|
613
|
-
sideEffects: sideEffects !== undefined && !!sideEffects,
|
|
614
|
-
...(isObjectObject(dependencies)
|
|
615
|
-
? { dependencies: { ...dependencies } }
|
|
616
|
-
: {}),
|
|
617
|
-
...(isObjectObject(overrides) ? { overrides: { ...overrides } } : {}),
|
|
618
|
-
...(isObjectObject(resolutions) ? { resolutions: { ...resolutions } } : {}),
|
|
619
|
-
...(isObjectObject(engines)
|
|
620
|
-
? {
|
|
621
|
-
engines: Object.fromEntries(
|
|
622
|
-
objectEntries(engines).map(pair => {
|
|
623
|
-
if (pair[0] === 'node') {
|
|
624
|
-
const semver = getSemver()
|
|
625
|
-
const { 1: range } = pair
|
|
626
|
-
if (
|
|
627
|
-
!semver.satisfies(
|
|
628
|
-
// Roughly check Node range as semver.coerce will strip leading
|
|
629
|
-
// v's, carets (^), comparators (<,<=,>,>=,=), and tildes (~).
|
|
630
|
-
semver.coerce(range),
|
|
631
|
-
PACKAGE_DEFAULT_NODE_RANGE
|
|
632
|
-
)
|
|
633
|
-
) {
|
|
634
|
-
pair[1] = PACKAGE_DEFAULT_NODE_RANGE
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
return pair
|
|
638
|
-
})
|
|
639
|
-
)
|
|
640
|
-
}
|
|
641
|
-
: { engines: { node: PACKAGE_DEFAULT_NODE_RANGE } }),
|
|
642
|
-
files: ArrayIsArray(files) ? files.slice() : ['*.d.ts', '*.js'],
|
|
643
|
-
...(isObjectObject(socket)
|
|
644
|
-
? { socket: { ...socket } }
|
|
645
|
-
: {
|
|
646
|
-
socket: {
|
|
647
|
-
// Valid categories are: cleanup, levelup, speedup, tuneup
|
|
648
|
-
categories: PACKAGE_DEFAULT_SOCKET_CATEGORIES
|
|
649
|
-
}
|
|
650
|
-
})
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
/**
|
|
655
|
-
* Extract a package to a destination directory.
|
|
656
|
-
* @param {string} pkgNameOrId - Package name or identifier.
|
|
657
|
-
* @param {Object} [options] - Extraction options.
|
|
658
|
-
* @param {Function} [callback] - Callback to execute after extraction.
|
|
659
|
-
* @returns {Promise<void>} Resolves when extraction is complete.
|
|
660
|
-
*/
|
|
661
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
662
|
-
async function extractPackage(pkgNameOrId, options, callback) {
|
|
663
|
-
if (arguments.length === 2 && typeof options === 'function') {
|
|
664
|
-
callback = options
|
|
665
|
-
options = undefined
|
|
666
|
-
}
|
|
667
|
-
const { dest, tmpPrefix, ...extractOptions_ } = {
|
|
668
|
-
__proto__: null,
|
|
669
|
-
...options
|
|
670
|
-
}
|
|
671
|
-
const extractOptions = {
|
|
672
|
-
__proto__: null,
|
|
673
|
-
packumentCache,
|
|
674
|
-
preferOffline: true,
|
|
675
|
-
...extractOptions_
|
|
676
|
-
}
|
|
677
|
-
const pacote = getPacote()
|
|
678
|
-
if (typeof dest === 'string') {
|
|
679
|
-
await pacote.extract(pkgNameOrId, dest, extractOptions)
|
|
680
|
-
if (typeof callback === 'function') {
|
|
681
|
-
await callback(dest)
|
|
682
|
-
}
|
|
683
|
-
} else {
|
|
684
|
-
// The DefinitelyTyped types for cacache.tmp.withTmp are incorrect.
|
|
685
|
-
// It DOES returns a promise.
|
|
686
|
-
const cacache = getCacache()
|
|
687
|
-
await cacache.tmp.withTmp(
|
|
688
|
-
/*@__PURE__*/ require('./constants/pacote-cache-path'),
|
|
689
|
-
{ tmpPrefix },
|
|
690
|
-
async tmpDirPath => {
|
|
691
|
-
await pacote.extract(pkgNameOrId, tmpDirPath, extractOptions)
|
|
692
|
-
if (typeof callback === 'function') {
|
|
693
|
-
await callback(tmpDirPath)
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
)
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
/**
|
|
701
|
-
* Fetch the manifest for a package.
|
|
702
|
-
* @param {string} pkgNameOrId - Package name or identifier.
|
|
703
|
-
* @param {Object} [options] - Fetch options.
|
|
704
|
-
* @returns {Promise<Object|null>} Package manifest or null if failed.
|
|
705
|
-
*/
|
|
706
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
707
|
-
async function fetchPackageManifest(pkgNameOrId, options) {
|
|
708
|
-
const pacoteOptions = {
|
|
709
|
-
__proto__: null,
|
|
710
|
-
signal: abortSignal,
|
|
711
|
-
...options,
|
|
712
|
-
packumentCache,
|
|
713
|
-
preferOffline: true
|
|
714
|
-
}
|
|
715
|
-
const { signal } = pacoteOptions
|
|
716
|
-
if (signal?.aborted) {
|
|
717
|
-
return null
|
|
718
|
-
}
|
|
719
|
-
const pacote = getPacote()
|
|
720
|
-
let result
|
|
721
|
-
try {
|
|
722
|
-
result = await pacote.manifest(pkgNameOrId, pacoteOptions)
|
|
723
|
-
} catch {}
|
|
724
|
-
if (signal?.aborted) {
|
|
725
|
-
return null
|
|
726
|
-
}
|
|
727
|
-
if (result) {
|
|
728
|
-
const npmPackageArg = getNpmPackageArg()
|
|
729
|
-
const spec = npmPackageArg(pkgNameOrId, pacoteOptions.where)
|
|
730
|
-
if (isRegistryFetcherType(spec.type)) {
|
|
731
|
-
return result
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
// Convert a manifest not fetched by RegistryFetcher to one that is.
|
|
735
|
-
return result
|
|
736
|
-
? fetchPackageManifest(`${result.name}@${result.version}`, pacoteOptions)
|
|
737
|
-
: null
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
/**
|
|
741
|
-
* Fetch the packument (package document) for a package.
|
|
742
|
-
* @param {string} pkgNameOrId - Package name or identifier.
|
|
743
|
-
* @param {Object} [options] - Fetch options.
|
|
744
|
-
* @returns {Promise<Object|null>} Package packument or null if failed.
|
|
745
|
-
*/
|
|
746
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
747
|
-
async function fetchPackagePackument(pkgNameOrId, options) {
|
|
748
|
-
const pacote = getPacote()
|
|
749
|
-
try {
|
|
750
|
-
return await pacote.packument(pkgNameOrId, {
|
|
751
|
-
__proto__: null,
|
|
752
|
-
signal: abortSignal,
|
|
753
|
-
...options,
|
|
754
|
-
packumentCache,
|
|
755
|
-
preferOffline: true
|
|
756
|
-
})
|
|
757
|
-
} catch {}
|
|
758
|
-
return null
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
/**
|
|
762
|
-
* Find package extensions for a given package.
|
|
763
|
-
* @param {string} pkgName - Package name.
|
|
764
|
-
* @param {string} pkgVer - Package version.
|
|
765
|
-
* @returns {Object} Package extensions.
|
|
766
|
-
*/
|
|
767
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
768
|
-
function findPackageExtensions(pkgName, pkgVer) {
|
|
769
|
-
let result
|
|
770
|
-
const packageExtensions = /*@__PURE__*/ require('./constants/package-extensions')
|
|
771
|
-
for (const { 0: selector, 1: ext } of packageExtensions) {
|
|
772
|
-
const lastAtSignIndex = selector.lastIndexOf('@')
|
|
773
|
-
const name = selector.slice(0, lastAtSignIndex)
|
|
774
|
-
if (pkgName === name) {
|
|
775
|
-
const semver = getSemver()
|
|
776
|
-
const range = selector.slice(lastAtSignIndex + 1)
|
|
777
|
-
if (semver.satisfies(pkgVer, range)) {
|
|
778
|
-
if (result === undefined) {
|
|
779
|
-
result = {}
|
|
780
|
-
}
|
|
781
|
-
merge(result, ext)
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
return result
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
/**
|
|
789
|
-
* Find types for a subpath in package exports.
|
|
790
|
-
* @param {Object} entryExports - Package exports object.
|
|
791
|
-
* @param {string} subpath - Subpath to find types for.
|
|
792
|
-
* @returns {string|undefined} Types path if found.
|
|
793
|
-
*/
|
|
794
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
795
|
-
function findTypesForSubpath(entryExports, subpath) {
|
|
796
|
-
const queue = [entryExports]
|
|
797
|
-
let pos = 0
|
|
798
|
-
while (pos < queue.length) {
|
|
799
|
-
if (pos === LOOP_SENTINEL) {
|
|
800
|
-
throw new Error(
|
|
801
|
-
'Detected infinite loop in entry exports crawl of getTypesForSubpath'
|
|
802
|
-
)
|
|
803
|
-
}
|
|
804
|
-
const value = queue[pos++]
|
|
805
|
-
if (ArrayIsArray(value)) {
|
|
806
|
-
for (let i = 0, { length } = value; i < length; i += 1) {
|
|
807
|
-
const item = value[i]
|
|
808
|
-
if (item === subpath) {
|
|
809
|
-
return value.types
|
|
810
|
-
}
|
|
811
|
-
if (isObject(item)) {
|
|
812
|
-
queue.push(item)
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
} else if (isObject(value)) {
|
|
816
|
-
const keys = Object.getOwnPropertyNames(value)
|
|
817
|
-
for (let i = 0, { length } = keys; i < length; i += 1) {
|
|
818
|
-
const item = value[keys[i]]
|
|
819
|
-
if (item === subpath) {
|
|
820
|
-
return value.types
|
|
821
|
-
}
|
|
822
|
-
if (isObject(item)) {
|
|
823
|
-
queue.push(item)
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
return undefined
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
/**
|
|
832
|
-
* Get the release tag for a version.
|
|
833
|
-
* @param {string} version - Version string.
|
|
834
|
-
* @returns {string} Release tag.
|
|
835
|
-
*/
|
|
836
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
837
|
-
function getReleaseTag(version) {
|
|
838
|
-
const semver = getSemver()
|
|
839
|
-
return semver.prerelease(version)?.join('.') ?? 'latest'
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
/**
|
|
843
|
-
* Extract details from a repository URL.
|
|
844
|
-
* @param {string} [repoUrl=''] - Repository URL.
|
|
845
|
-
* @returns {Object} Repository details with host, user, and project.
|
|
846
|
-
*/
|
|
847
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
848
|
-
function getRepoUrlDetails(repoUrl = '') {
|
|
849
|
-
const userAndRepo = repoUrl.replace(/^.+github.com\//, '').split('/')
|
|
850
|
-
const { 0: user } = userAndRepo
|
|
851
|
-
const project =
|
|
852
|
-
userAndRepo.length > 1 ? userAndRepo[1].slice(0, -'.git'.length) : ''
|
|
853
|
-
return { user, project }
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
/**
|
|
857
|
-
* Get subpaths from package exports.
|
|
858
|
-
* @param {Object} entryExports - Package exports object.
|
|
859
|
-
* @returns {string[]} Array of subpaths.
|
|
860
|
-
*/
|
|
861
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
862
|
-
function getSubpaths(entryExports) {
|
|
863
|
-
const result = []
|
|
864
|
-
const queue = getOwnPropertyValues(entryExports)
|
|
865
|
-
let pos = 0
|
|
866
|
-
while (pos < queue.length) {
|
|
867
|
-
if (pos === LOOP_SENTINEL) {
|
|
868
|
-
throw new Error(
|
|
869
|
-
'Detected infinite loop in entry exports crawl of getSubpaths'
|
|
870
|
-
)
|
|
871
|
-
}
|
|
872
|
-
const value = queue[pos++]
|
|
873
|
-
if (typeof value === 'string') {
|
|
874
|
-
result.push(value)
|
|
875
|
-
} else if (ArrayIsArray(value)) {
|
|
876
|
-
queue.push(...value)
|
|
877
|
-
} else if (isObject(value)) {
|
|
878
|
-
queue.push(...getOwnPropertyValues(value))
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
return result
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
885
|
-
function gitHubTagRefUrl(user, project, tag) {
|
|
886
|
-
return `https://api.github.com/repos/${user}/${project}/git/ref/tags/${tag}`
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
890
|
-
function gitHubTgzUrl(user, project, sha) {
|
|
891
|
-
return `https://github.com/${user}/${project}/archive/${sha}.tar.gz`
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
895
|
-
function isBlessedPackageName(name) {
|
|
896
|
-
return (
|
|
897
|
-
typeof name === 'string' &&
|
|
898
|
-
(name === 'socket' ||
|
|
899
|
-
name.startsWith('@socketoverride/') ||
|
|
900
|
-
name.startsWith('@socketregistry/') ||
|
|
901
|
-
name.startsWith('@socketsecurity/'))
|
|
902
|
-
)
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
906
|
-
function isConditionalExports(entryExports) {
|
|
907
|
-
if (!isObjectObject(entryExports)) {
|
|
908
|
-
return false
|
|
909
|
-
}
|
|
910
|
-
const keys = Object.getOwnPropertyNames(entryExports)
|
|
911
|
-
const { length } = keys
|
|
912
|
-
if (!length) {
|
|
913
|
-
return false
|
|
914
|
-
}
|
|
915
|
-
// Conditional entry exports do NOT contain keys starting with '.'.
|
|
916
|
-
// Entry exports cannot contain some keys starting with '.' and some not.
|
|
917
|
-
// The exports object MUST either be an object of package subpath keys OR
|
|
918
|
-
// an object of main entry condition name keys only.
|
|
919
|
-
for (let i = 0; i < length; i += 1) {
|
|
920
|
-
const key = keys[i]
|
|
921
|
-
if (key.length > 0 && key.charCodeAt(0) === 46 /*'.'*/) {
|
|
922
|
-
return false
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
return true
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
929
|
-
function isGitHubTgzSpec(spec, where) {
|
|
930
|
-
let parsedSpec
|
|
931
|
-
if (isObjectObject(spec)) {
|
|
932
|
-
parsedSpec = spec
|
|
933
|
-
} else {
|
|
934
|
-
const npmPackageArg = getNpmPackageArg()
|
|
935
|
-
parsedSpec = npmPackageArg(spec, where)
|
|
936
|
-
}
|
|
937
|
-
return (
|
|
938
|
-
parsedSpec.type === 'remote' && !!parsedSpec.saveSpec?.endsWith('.tar.gz')
|
|
939
|
-
)
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
943
|
-
function isGitHubUrlSpec(spec, where) {
|
|
944
|
-
let parsedSpec
|
|
945
|
-
if (isObjectObject(spec)) {
|
|
946
|
-
parsedSpec = spec
|
|
947
|
-
} else {
|
|
948
|
-
const npmPackageArg = getNpmPackageArg()
|
|
949
|
-
parsedSpec = npmPackageArg(spec, where)
|
|
950
|
-
}
|
|
951
|
-
return (
|
|
952
|
-
parsedSpec.type === 'git' &&
|
|
953
|
-
parsedSpec.hosted?.domain === 'github.com' &&
|
|
954
|
-
isNonEmptyString(parsedSpec.gitCommittish)
|
|
955
|
-
)
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
959
|
-
function isRegistryFetcherType(type) {
|
|
960
|
-
// RegistryFetcher spec.type check based on:
|
|
961
|
-
// https://github.com/npm/pacote/blob/v19.0.0/lib/fetcher.js#L467-L488
|
|
962
|
-
return (
|
|
963
|
-
type === 'alias' || type === 'range' || type === 'tag' || type === 'version'
|
|
964
|
-
)
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
968
|
-
function isSubpathExports(entryExports) {
|
|
969
|
-
if (isObjectObject(entryExports)) {
|
|
970
|
-
const keys = Object.getOwnPropertyNames(entryExports)
|
|
971
|
-
for (let i = 0, { length } = keys; i < length; i += 1) {
|
|
972
|
-
// Subpath entry exports contain keys starting with '.'.
|
|
973
|
-
// Entry exports cannot contain some keys starting with '.' and some not.
|
|
974
|
-
// The exports object MUST either be an object of package subpath keys OR
|
|
975
|
-
// an object of main entry condition name keys only.
|
|
976
|
-
if (keys[i].charCodeAt(0) === 46 /*'.'*/) {
|
|
977
|
-
return true
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
return false
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
985
|
-
function isValidPackageName(name) {
|
|
986
|
-
const validateNpmPackageName = getValidateNpmPackageName()
|
|
987
|
-
return validateNpmPackageName(name).validForOldPackages
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
991
|
-
function pkgJsonToEditable(pkgJson, options) {
|
|
992
|
-
const { normalize, ...normalizeOptions } = { __proto__: null, ...options }
|
|
993
|
-
const EditablePackageJson = getEditablePackageJsonClass()
|
|
994
|
-
return new EditablePackageJson().fromContent(
|
|
995
|
-
normalize ? normalizePackageJson(pkgJson, normalizeOptions) : pkgJson
|
|
996
|
-
)
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1000
|
-
function normalizePackageJson(pkgJson, options) {
|
|
1001
|
-
const { preserve } = { __proto__: null, ...options }
|
|
1002
|
-
const preserved = [
|
|
1003
|
-
['_id', undefined],
|
|
1004
|
-
['readme', undefined],
|
|
1005
|
-
...(ObjectHasOwn(pkgJson, 'bugs') ? [] : [['bugs', undefined]]),
|
|
1006
|
-
...(ObjectHasOwn(pkgJson, 'homepage') ? [] : [['homepage', undefined]]),
|
|
1007
|
-
...(ObjectHasOwn(pkgJson, 'name') ? [] : [['name', undefined]]),
|
|
1008
|
-
...(ObjectHasOwn(pkgJson, 'version') ? [] : [['version', undefined]]),
|
|
1009
|
-
...(ArrayIsArray(preserve)
|
|
1010
|
-
? preserve.map(k => [
|
|
1011
|
-
k,
|
|
1012
|
-
ObjectHasOwn(pkgJson, k) ? pkgJson[k] : undefined
|
|
1013
|
-
])
|
|
1014
|
-
: [])
|
|
1015
|
-
]
|
|
1016
|
-
const normalizePackageData = getNormalizePackageData()
|
|
1017
|
-
normalizePackageData(pkgJson)
|
|
1018
|
-
merge(pkgJson, findPackageExtensions(pkgJson.name, pkgJson.version))
|
|
1019
|
-
// Revert/remove properties we don't care to have normalized.
|
|
1020
|
-
// Properties with undefined values are omitted when saved as JSON.
|
|
1021
|
-
for (const { 0: key, 1: value } of preserved) {
|
|
1022
|
-
pkgJson[key] = value
|
|
1023
|
-
}
|
|
1024
|
-
return pkgJson
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1028
|
-
async function packPackage(spec, options) {
|
|
1029
|
-
const pack = getPack()
|
|
1030
|
-
return await pack(spec, {
|
|
1031
|
-
__proto__: null,
|
|
1032
|
-
signal: abortSignal,
|
|
1033
|
-
...options,
|
|
1034
|
-
packumentCache,
|
|
1035
|
-
preferOffline: true
|
|
1036
|
-
})
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1040
|
-
function parseSpdxExp(spdxExp) {
|
|
1041
|
-
const spdxExpParse = getSpdxExpParse()
|
|
1042
|
-
try {
|
|
1043
|
-
return spdxExpParse(spdxExp)
|
|
1044
|
-
} catch {}
|
|
1045
|
-
const spdxCorrect = getSpdxCorrect()
|
|
1046
|
-
const corrected = spdxCorrect(spdxExp)
|
|
1047
|
-
return corrected ? spdxExpParse(corrected) : null
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1051
|
-
async function readPackageJson(filepath, options) {
|
|
1052
|
-
const { editable, normalize, throws, ...normalizeOptions } = {
|
|
1053
|
-
__proto__: null,
|
|
1054
|
-
...options
|
|
1055
|
-
}
|
|
1056
|
-
const pkgJson = await readJson(resolvePackageJsonPath(filepath), { throws })
|
|
1057
|
-
if (pkgJson) {
|
|
1058
|
-
return editable
|
|
1059
|
-
? await toEditablePackageJson(pkgJson, {
|
|
1060
|
-
path: filepath,
|
|
1061
|
-
normalize,
|
|
1062
|
-
...normalizeOptions
|
|
1063
|
-
})
|
|
1064
|
-
: normalize
|
|
1065
|
-
? normalizePackageJson(pkgJson, normalizeOptions)
|
|
1066
|
-
: pkgJson
|
|
1067
|
-
}
|
|
1068
|
-
return null
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1072
|
-
function readPackageJsonSync(filepath, options) {
|
|
1073
|
-
const { editable, normalize, throws, ...normalizeOptions } = {
|
|
1074
|
-
__proto__: null,
|
|
1075
|
-
...options
|
|
1076
|
-
}
|
|
1077
|
-
const pkgJson = readJsonSync(resolvePackageJsonPath(filepath), { throws })
|
|
1078
|
-
if (pkgJson) {
|
|
1079
|
-
return editable
|
|
1080
|
-
? toEditablePackageJsonSync(pkgJson, {
|
|
1081
|
-
path: filepath,
|
|
1082
|
-
normalize,
|
|
1083
|
-
...normalizeOptions
|
|
1084
|
-
})
|
|
1085
|
-
: normalize
|
|
1086
|
-
? normalizePackageJson(pkgJson, normalizeOptions)
|
|
1087
|
-
: pkgJson
|
|
1088
|
-
}
|
|
1089
|
-
return null
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1093
|
-
function resolveEscapedScope(sockRegPkgName) {
|
|
1094
|
-
return escapedScopeRegExp.exec(sockRegPkgName)?.[0] ?? ''
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1098
|
-
async function resolveGitHubTgzUrl(pkgNameOrId, where) {
|
|
1099
|
-
const whereIsPkgJson = isObjectObject(where)
|
|
1100
|
-
const pkgJson = whereIsPkgJson
|
|
1101
|
-
? where
|
|
1102
|
-
: await readPackageJson(where, { normalize: true })
|
|
1103
|
-
const { version } = pkgJson
|
|
1104
|
-
const npmPackageArg = getNpmPackageArg()
|
|
1105
|
-
const parsedSpec = npmPackageArg(
|
|
1106
|
-
pkgNameOrId,
|
|
1107
|
-
whereIsPkgJson ? undefined : where
|
|
1108
|
-
)
|
|
1109
|
-
const isTarballUrl = isGitHubTgzSpec(parsedSpec)
|
|
1110
|
-
if (isTarballUrl) {
|
|
1111
|
-
return parsedSpec.saveSpec
|
|
1112
|
-
}
|
|
1113
|
-
const isGitHubUrl = isGitHubUrlSpec(parsedSpec)
|
|
1114
|
-
const { project, user } = isGitHubUrl
|
|
1115
|
-
? parsedSpec.hosted
|
|
1116
|
-
: getRepoUrlDetails(pkgJson.repository?.url)
|
|
1117
|
-
|
|
1118
|
-
if (user && project) {
|
|
1119
|
-
let apiUrl = ''
|
|
1120
|
-
if (isGitHubUrl) {
|
|
1121
|
-
apiUrl = gitHubTagRefUrl(user, project, parsedSpec.gitCommittish)
|
|
1122
|
-
} else {
|
|
1123
|
-
const fetcher = getFetcher()
|
|
1124
|
-
// First try to resolve the sha for a tag starting with "v", e.g. v1.2.3.
|
|
1125
|
-
apiUrl = gitHubTagRefUrl(user, project, `v${version}`)
|
|
1126
|
-
if (!(await fetcher(apiUrl, { method: 'head' })).ok) {
|
|
1127
|
-
// If a sha isn't found, try again with the "v" removed, e.g. 1.2.3.
|
|
1128
|
-
apiUrl = gitHubTagRefUrl(user, project, version)
|
|
1129
|
-
if (!(await fetcher(apiUrl, { method: 'head' })).ok) {
|
|
1130
|
-
apiUrl = ''
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
if (apiUrl) {
|
|
1135
|
-
const fetcher = getFetcher()
|
|
1136
|
-
const resp = await fetcher(apiUrl)
|
|
1137
|
-
const json = await resp.json()
|
|
1138
|
-
const sha = json?.object?.sha
|
|
1139
|
-
if (sha) {
|
|
1140
|
-
return gitHubTgzUrl(user, project, sha)
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
return ''
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1148
|
-
function resolveOriginalPackageName(sockRegPkgName) {
|
|
1149
|
-
const name = sockRegPkgName.startsWith(`${SOCKET_REGISTRY_SCOPE}/`)
|
|
1150
|
-
? sockRegPkgName.slice(SOCKET_REGISTRY_SCOPE.length + 1)
|
|
1151
|
-
: sockRegPkgName
|
|
1152
|
-
const escapedScope = resolveEscapedScope(name)
|
|
1153
|
-
return escapedScope
|
|
1154
|
-
? `${unescapeScope(escapedScope)}/${name.slice(escapedScope.length)}`
|
|
1155
|
-
: name
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1159
|
-
function resolvePackageJsonDirname(filepath) {
|
|
1160
|
-
if (filepath.endsWith('package.json')) {
|
|
1161
|
-
const path = getPath()
|
|
1162
|
-
return path.dirname(filepath)
|
|
1163
|
-
}
|
|
1164
|
-
return filepath
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1168
|
-
function resolvePackageJsonEntryExports(entryExports) {
|
|
1169
|
-
// If conditional exports main sugar
|
|
1170
|
-
// https://nodejs.org/api/packages.html#exports-sugar
|
|
1171
|
-
if (typeof entryExports === 'string' || ArrayIsArray(entryExports)) {
|
|
1172
|
-
return { '.': entryExports }
|
|
1173
|
-
}
|
|
1174
|
-
if (isConditionalExports(entryExports)) {
|
|
1175
|
-
return entryExports
|
|
1176
|
-
}
|
|
1177
|
-
return isObject(entryExports) ? entryExports : undefined
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1181
|
-
function resolvePackageJsonPath(filepath) {
|
|
1182
|
-
if (filepath.endsWith('package.json')) {
|
|
1183
|
-
return filepath
|
|
1184
|
-
}
|
|
1185
|
-
const path = getPath()
|
|
1186
|
-
return path.join(filepath, 'package.json')
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1190
|
-
function resolvePackageLicenses(licenseFieldValue, where) {
|
|
1191
|
-
// Based off of validate-npm-package-license which npm, by way of normalize-package-data,
|
|
1192
|
-
// uses to validate license field values:
|
|
1193
|
-
// https://github.com/kemitchell/validate-npm-package-license.js/blob/v3.0.4/index.js#L40-L41
|
|
1194
|
-
if (
|
|
1195
|
-
licenseFieldValue === 'UNLICENSED' ||
|
|
1196
|
-
licenseFieldValue === 'UNLICENCED'
|
|
1197
|
-
) {
|
|
1198
|
-
return [{ license: 'UNLICENSED' }]
|
|
1199
|
-
}
|
|
1200
|
-
// Match "SEE LICENSE IN <relativeFilepathToLicense>"
|
|
1201
|
-
// https://github.com/kemitchell/validate-npm-package-license.js/blob/v3.0.4/index.js#L48-L53
|
|
1202
|
-
const match = fileReferenceRegExp.exec(licenseFieldValue)
|
|
1203
|
-
if (match) {
|
|
1204
|
-
const path = getPath()
|
|
1205
|
-
return [
|
|
1206
|
-
{
|
|
1207
|
-
license: licenseFieldValue,
|
|
1208
|
-
inFile: normalizePath(path.relative(where, match[1]))
|
|
1209
|
-
}
|
|
1210
|
-
]
|
|
1211
|
-
}
|
|
1212
|
-
const licenseNodes = []
|
|
1213
|
-
const ast = parseSpdxExp(licenseFieldValue)
|
|
1214
|
-
if (ast) {
|
|
1215
|
-
// SPDX expressions are valid, too except if they contain "LicenseRef" or
|
|
1216
|
-
// "DocumentRef". If the licensing terms cannot be described with standardized
|
|
1217
|
-
// SPDX identifiers, then the terms should be put in a file in the package
|
|
1218
|
-
// and the license field should point users there, e.g. "SEE LICENSE IN LICENSE.txt".
|
|
1219
|
-
// https://github.com/kemitchell/validate-npm-package-license.js/blob/v3.0.4/index.js#L18-L24
|
|
1220
|
-
visitLicenses(ast, {
|
|
1221
|
-
__proto__: null,
|
|
1222
|
-
License(node) {
|
|
1223
|
-
const { license } = node
|
|
1224
|
-
if (
|
|
1225
|
-
license.startsWith('LicenseRef') ||
|
|
1226
|
-
license.startsWith('DocumentRef')
|
|
1227
|
-
) {
|
|
1228
|
-
licenseNodes.length = 0
|
|
1229
|
-
return false
|
|
1230
|
-
}
|
|
1231
|
-
licenseNodes.push(node)
|
|
1232
|
-
}
|
|
1233
|
-
})
|
|
1234
|
-
}
|
|
1235
|
-
return licenseNodes
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1239
|
-
function resolvePackageName(purlObj, delimiter = '/') {
|
|
1240
|
-
const { name, namespace } = purlObj
|
|
1241
|
-
return `${namespace ? `${namespace}${delimiter}` : ''}${name}`
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1245
|
-
function resolveRegistryPackageName(pkgName) {
|
|
1246
|
-
const purlObj = getPackageURL().fromString(`pkg:npm/${pkgName}`)
|
|
1247
|
-
return purlObj.namespace
|
|
1248
|
-
? `${purlObj.namespace.slice(1)}${REGISTRY_SCOPE_DELIMITER}${purlObj.name}`
|
|
1249
|
-
: pkgName
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1253
|
-
async function toEditablePackageJson(pkgJson, options) {
|
|
1254
|
-
const { path: filepath, ...pkgJsonToEditableOptions } = {
|
|
1255
|
-
__proto__: null,
|
|
1256
|
-
...options
|
|
1257
|
-
}
|
|
1258
|
-
const { normalize, ...normalizeOptions } = pkgJsonToEditableOptions
|
|
1259
|
-
if (typeof filepath !== 'string') {
|
|
1260
|
-
return pkgJsonToEditable(pkgJson, pkgJsonToEditableOptions)
|
|
1261
|
-
}
|
|
1262
|
-
const EditablePackageJson = getEditablePackageJsonClass()
|
|
1263
|
-
const pkgJsonPath = resolvePackageJsonDirname(filepath)
|
|
1264
|
-
return (
|
|
1265
|
-
await EditablePackageJson.load(pkgJsonPath, { create: true })
|
|
1266
|
-
).fromJSON(
|
|
1267
|
-
`${JSON.stringify(
|
|
1268
|
-
normalize
|
|
1269
|
-
? normalizePackageJson(pkgJson, {
|
|
1270
|
-
__proto__: null,
|
|
1271
|
-
...(isNodeModules(pkgJsonPath) ? {} : { preserve: ['repository'] }),
|
|
1272
|
-
...normalizeOptions
|
|
1273
|
-
})
|
|
1274
|
-
: pkgJson,
|
|
1275
|
-
null,
|
|
1276
|
-
2
|
|
1277
|
-
)}\n`
|
|
1278
|
-
)
|
|
1279
|
-
}
|
|
1280
|
-
|
|
1281
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1282
|
-
function toEditablePackageJsonSync(pkgJson, options) {
|
|
1283
|
-
const { path: filepath, ...pkgJsonToEditableOptions } = {
|
|
1284
|
-
__proto__: null,
|
|
1285
|
-
...options
|
|
1286
|
-
}
|
|
1287
|
-
const { normalize, ...normalizeOptions } = pkgJsonToEditableOptions
|
|
1288
|
-
if (typeof filepath !== 'string') {
|
|
1289
|
-
return pkgJsonToEditable(pkgJson, pkgJsonToEditableOptions)
|
|
1290
|
-
}
|
|
1291
|
-
const EditablePackageJson = getEditablePackageJsonClass()
|
|
1292
|
-
const pkgJsonPath = resolvePackageJsonDirname(filepath)
|
|
1293
|
-
return new EditablePackageJson().create(pkgJsonPath).fromJSON(
|
|
1294
|
-
`${JSON.stringify(
|
|
1295
|
-
normalize
|
|
1296
|
-
? normalizePackageJson(pkgJson, {
|
|
1297
|
-
__proto__: null,
|
|
1298
|
-
...(isNodeModules(pkgJsonPath) ? {} : { preserve: ['repository'] }),
|
|
1299
|
-
...normalizeOptions
|
|
1300
|
-
})
|
|
1301
|
-
: pkgJson,
|
|
1302
|
-
null,
|
|
1303
|
-
2
|
|
1304
|
-
)}\n`
|
|
1305
|
-
)
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1309
|
-
function unescapeScope(escapedScope) {
|
|
1310
|
-
return `@${escapedScope.slice(0, -REGISTRY_SCOPE_DELIMITER.length)}`
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
|
-
/*@__NO_SIDE_EFFECTS__*/
|
|
1314
|
-
function visitLicenses(ast, visitor) {
|
|
1315
|
-
const queue = [[createAstNode(ast), undefined]]
|
|
1316
|
-
let pos = 0
|
|
1317
|
-
let { length: queueLength } = queue
|
|
1318
|
-
while (pos < queueLength) {
|
|
1319
|
-
if (pos === LOOP_SENTINEL) {
|
|
1320
|
-
throw new Error('Detected infinite loop in ast crawl of visitLicenses')
|
|
1321
|
-
}
|
|
1322
|
-
// AST nodes can be a license node which looks like
|
|
1323
|
-
// {
|
|
1324
|
-
// license: string
|
|
1325
|
-
// plus?: boolean
|
|
1326
|
-
// exception?: string
|
|
1327
|
-
// }
|
|
1328
|
-
// or a binary operation node which looks like
|
|
1329
|
-
// {
|
|
1330
|
-
// left: License | BinaryOperation
|
|
1331
|
-
// conjunction: string
|
|
1332
|
-
// right: License | BinaryOperation
|
|
1333
|
-
// }
|
|
1334
|
-
const { 0: node, 1: parent } = queue[pos++]
|
|
1335
|
-
const { type } = node
|
|
1336
|
-
if (visitor[type]?.(node, parent) === false) {
|
|
1337
|
-
break
|
|
1338
|
-
}
|
|
1339
|
-
if (type === BINARY_OPERATION_NODE_TYPE) {
|
|
1340
|
-
queue[queueLength++] = [node.left, node]
|
|
1341
|
-
queue[queueLength++] = [node.right, node]
|
|
1342
|
-
}
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
|
|
1346
|
-
module.exports = {
|
|
1347
|
-
collectIncompatibleLicenses,
|
|
1348
|
-
collectLicenseWarnings,
|
|
1349
|
-
createPackageJson,
|
|
1350
|
-
extractPackage,
|
|
1351
|
-
fetchPackageManifest,
|
|
1352
|
-
fetchPackagePackument,
|
|
1353
|
-
findTypesForSubpath,
|
|
1354
|
-
getReleaseTag,
|
|
1355
|
-
getRepoUrlDetails,
|
|
1356
|
-
getSubpaths,
|
|
1357
|
-
isBlessedPackageName,
|
|
1358
|
-
isConditionalExports,
|
|
1359
|
-
isGitHubTgzSpec,
|
|
1360
|
-
isGitHubUrlSpec,
|
|
1361
|
-
isSubpathExports,
|
|
1362
|
-
isValidPackageName,
|
|
1363
|
-
normalizePackageJson,
|
|
1364
|
-
packPackage,
|
|
1365
|
-
readPackageJson,
|
|
1366
|
-
readPackageJsonSync,
|
|
1367
|
-
resolveEscapedScope,
|
|
1368
|
-
resolveGitHubTgzUrl,
|
|
1369
|
-
resolveOriginalPackageName,
|
|
1370
|
-
resolvePackageJsonDirname,
|
|
1371
|
-
resolvePackageJsonEntryExports,
|
|
1372
|
-
resolvePackageJsonPath,
|
|
1373
|
-
resolvePackageLicenses,
|
|
1374
|
-
resolvePackageName,
|
|
1375
|
-
resolveRegistryPackageName,
|
|
1376
|
-
toEditablePackageJson,
|
|
1377
|
-
toEditablePackageJsonSync,
|
|
1378
|
-
unescapeScope
|
|
1379
|
-
}
|