@socketsecurity/cli-with-sentry 0.14.56 → 0.14.57

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.
Files changed (38) hide show
  1. package/bin/cli.js +8 -10
  2. package/bin/npm-cli.js +1 -1
  3. package/bin/npx-cli.js +3 -1
  4. package/dist/constants.d.ts +19 -6
  5. package/dist/constants.js +47 -21
  6. package/dist/constants.js.map +1 -1
  7. package/dist/instrument-with-sentry.js +3 -3
  8. package/dist/instrument-with-sentry.js.map +1 -1
  9. package/dist/module-sync/cli.js +332 -272
  10. package/dist/module-sync/cli.js.map +1 -1
  11. package/dist/module-sync/color-or-markdown.d.ts +16 -0
  12. package/dist/module-sync/edge.d.ts +1 -1
  13. package/dist/module-sync/index.d.ts +3 -172
  14. package/dist/module-sync/node.d.ts +1 -1
  15. package/dist/module-sync/override-set.d.ts +37 -0
  16. package/dist/module-sync/shadow-bin.js +8 -8
  17. package/dist/module-sync/shadow-bin.js.map +1 -1
  18. package/dist/module-sync/{index.js → shadow-npm-inject.js} +29 -22
  19. package/dist/module-sync/shadow-npm-inject.js.map +1 -0
  20. package/dist/module-sync/{npm-paths.js → shadow-npm-paths.js} +4 -4
  21. package/dist/module-sync/shadow-npm-paths.js.map +1 -0
  22. package/dist/module-sync/socket-url.d.ts +3 -0
  23. package/dist/require/cli.js +332 -272
  24. package/dist/require/cli.js.map +1 -1
  25. package/dist/require/shadow-npm-inject.js +3 -0
  26. package/dist/require/shadow-npm-paths.js +3 -0
  27. package/package.json +4 -3
  28. package/dist/module-sync/index.js.map +0 -1
  29. package/dist/module-sync/npm-injection.js +0 -26
  30. package/dist/module-sync/npm-injection.js.map +0 -1
  31. package/dist/module-sync/npm-paths.js.map +0 -1
  32. package/dist/module-sync/proc-log.d.ts +0 -3
  33. package/dist/module-sync/reify.d.ts +0 -1020
  34. package/dist/require/index.js +0 -3
  35. package/dist/require/npm-injection.js +0 -3
  36. package/dist/require/npm-paths.js +0 -3
  37. /package/dist/module-sync/{npm-injection.d.ts → shadow-npm-inject.d.ts} +0 -0
  38. /package/dist/module-sync/{npm-paths.d.ts → shadow-npm-paths.d.ts} +0 -0
@@ -0,0 +1,16 @@
1
+ import indentString from '@socketregistry/indent-string/index.cjs';
2
+ declare class ColorOrMarkdown {
3
+ useMarkdown: boolean;
4
+ constructor(useMarkdown: boolean);
5
+ bold(text: string): string;
6
+ header(text: string, level?: number): string;
7
+ hyperlink(text: string, url: string | undefined, { fallback, fallbackToUrl }?: {
8
+ fallback?: boolean | undefined;
9
+ fallbackToUrl?: boolean | undefined;
10
+ }): string;
11
+ indent(...args: Parameters<typeof indentString>): ReturnType<typeof indentString>;
12
+ italic(text: string): string;
13
+ json(value: any): string;
14
+ list(items: string[]): string;
15
+ }
16
+ export { ColorOrMarkdown };
@@ -1,6 +1,6 @@
1
1
  /// <reference types="npmcli__arborist" />
2
2
  import { SafeNode } from "./node.js";
3
- import { SafeOverrideSet } from "./index.js";
3
+ import { SafeOverrideSet } from "./override-set.js";
4
4
  import { DependencyProblem } from '@npmcli/arborist';
5
5
  import { Edge as BaseEdge } from "@npmcli/arborist";
6
6
  type EdgeClass = Omit<BaseEdge, 'accept' | 'detach' | 'optional' | 'overrides' | 'peer' | 'peerConflicted' | 'rawSpec' | 'reload' | 'satisfiedBy' | 'spec' | 'to'> & {
@@ -1,175 +1,6 @@
1
- /// <reference types="node" />
2
- import { SafeEdge } from "./edge.js";
1
+ import { kRiskyReify } from "./shadow-npm-inject.js";
2
+ import { ArboristClass } from "./types.js";
3
3
  import { SafeNode } from "./node.js";
4
- import indentString from "@socketregistry/indent-string/index.cjs";
5
- import { LogSymbols } from "@socketsecurity/registry/lib/logger";
6
- import { SocketSdkResultType } from "@socketsecurity/sdk";
7
- import { Diff, ArboristClass } from "./types.js";
8
- import { ObjectEncodingOptions, OpenMode, PathLike } from "node:fs";
9
- import { promises as fs } from "node:fs";
10
- import { readFileSync as fsReadFileSync } from "node:fs";
11
- import { Abortable } from "node:events";
12
- import { FileHandle } from "node:fs/promises";
13
- import { kRiskyReify } from "./reify.js";
14
- interface OverrideSetClass {
15
- children: Map<string, SafeOverrideSet>;
16
- key: string | undefined;
17
- keySpec: string | undefined;
18
- name: string | undefined;
19
- parent: SafeOverrideSet | undefined;
20
- value: string | undefined;
21
- version: string | undefined;
22
- // eslint-disable-next-line @typescript-eslint/no-misused-new
23
- new (...args: any[]): OverrideSetClass;
24
- get isRoot(): boolean;
25
- get ruleset(): Map<string, SafeOverrideSet>;
26
- ancestry(): Generator<SafeOverrideSet>;
27
- childrenAreEqual(otherOverrideSet: SafeOverrideSet | undefined): boolean;
28
- getEdgeRule(edge: SafeEdge): SafeOverrideSet;
29
- getNodeRule(node: SafeNode): SafeOverrideSet;
30
- getMatchingRule(node: SafeNode): SafeOverrideSet | null;
31
- isEqual(otherOverrideSet: SafeOverrideSet | undefined): boolean;
32
- }
33
- declare const OverrideSet: OverrideSetClass;
34
- // Implementation code not related to patch https://github.com/npm/cli/pull/8089
35
- // is based on https://github.com/npm/cli/blob/v11.0.0/workspaces/arborist/lib/override-set.js:
36
- declare class SafeOverrideSet extends OverrideSet {
37
- // Patch adding doOverrideSetsConflict is based on
38
- // https://github.com/npm/cli/pull/8089.
39
- static doOverrideSetsConflict(first: SafeOverrideSet | undefined, second: SafeOverrideSet | undefined): boolean;
40
- // Patch adding findSpecificOverrideSet is based on
41
- // https://github.com/npm/cli/pull/8089.
42
- static findSpecificOverrideSet(first: SafeOverrideSet | undefined, second: SafeOverrideSet | undefined): SafeOverrideSet | undefined;
43
- // Patch adding childrenAreEqual is based on
44
- // https://github.com/npm/cli/pull/8089.
45
- childrenAreEqual(otherOverrideSet: SafeOverrideSet): boolean;
46
- getEdgeRule(edge: SafeEdge): SafeOverrideSet;
47
- // Patch adding isEqual is based on
48
- // https://github.com/npm/cli/pull/8089.
49
- isEqual(otherOverrideSet: SafeOverrideSet | undefined): boolean;
50
- }
51
- declare const depValid: (child: SafeNode, requested: string, accept: string | undefined, requester: SafeNode) => boolean;
52
- declare function getSocketDevAlertUrl(alertType: string): string;
53
- declare function getSocketDevPackageOverviewUrl(eco: string, name: string, version?: string | undefined): string;
54
- declare class ColorOrMarkdown {
55
- useMarkdown: boolean;
56
- constructor(useMarkdown: boolean);
57
- bold(text: string): string;
58
- header(text: string, level?: number): string;
59
- hyperlink(text: string, url: string | undefined, { fallback, fallbackToUrl }?: {
60
- fallback?: boolean | undefined;
61
- fallbackToUrl?: boolean | undefined;
62
- }): string;
63
- indent(...args: Parameters<typeof indentString>): ReturnType<typeof indentString>;
64
- italic(text: string): string;
65
- json(value: any): string;
66
- list(items: string[]): string;
67
- get logSymbols(): LogSymbols;
68
- }
69
- type AlertUxLookup = ReturnType<typeof createAlertUXLookup>;
70
- type AlertUxLookupSettings = Parameters<AlertUxLookup>[0];
71
- type AlertUxLookupResult = ReturnType<AlertUxLookup>;
72
- type RuleActionUX = {
73
- block: boolean;
74
- display: boolean;
75
- };
76
- type SettingsType = (SocketSdkResultType<"postSettings"> & {
77
- success: true;
78
- })["data"];
79
- declare function createAlertUXLookup(settings: SettingsType): (context: {
80
- package: {
81
- name: string;
82
- version: string;
83
- };
84
- alert: {
85
- type: string;
86
- };
87
- }) => RuleActionUX;
88
- declare function uxLookup(settings: AlertUxLookupSettings): Promise<AlertUxLookupResult>;
89
- type CveAlertType = "cve" | "mediumCVE" | "mildCVE" | "criticalCVE";
90
- type ArtifactAlertCveFixable = Omit<SocketArtifactAlert, "props" | "title"> & {
91
- type: CveAlertType;
92
- props: {
93
- firstPatchedVersionIdentifier: string;
94
- vulnerableVersionRange: string;
95
- [key: string]: any;
96
- };
97
- };
98
- type ArtifactAlertFixable = ArtifactAlertCveFixable & {
99
- type: CveAlertType | "socketUpgradeAvailable";
100
- };
101
- type SocketArtifactAlert = {
102
- key: string;
103
- type: string;
104
- severity: string;
105
- category: string;
106
- action?: string | undefined;
107
- actionPolicyIndex?: number | undefined;
108
- file?: string | undefined;
109
- props?: any | undefined;
110
- start?: number | undefined;
111
- end?: number | undefined;
112
- };
113
- type SocketArtifact = {
114
- type: string;
115
- name: string;
116
- namespace?: string | undefined;
117
- version?: string | undefined;
118
- subpath?: string | undefined;
119
- release?: string | undefined;
120
- id?: string | undefined;
121
- author?: string[];
122
- license?: string | undefined;
123
- licenseDetails?: Array<{
124
- spdxDisj: string;
125
- provenance: string;
126
- filepath: string;
127
- match_strength: number;
128
- }>;
129
- licenseAttrib?: Array<{
130
- attribText: string;
131
- attribData: Array<{
132
- purl: string;
133
- foundInFilepath: string;
134
- spdxExpr: string;
135
- foundAuthors: string[];
136
- }>;
137
- }>;
138
- score?: {
139
- supplyChain: number;
140
- quality: number;
141
- maintenance: number;
142
- vulnerability: number;
143
- license: number;
144
- overall: number;
145
- };
146
- alerts?: SocketArtifactAlert[];
147
- size?: number | undefined;
148
- batchIndex?: number | undefined;
149
- };
150
- declare function batchScan(pkgIds: string[], concurrencyLimit?: number): AsyncGenerator<SocketArtifact>;
151
- declare function isArtifactAlertCveFixable(alert: SocketArtifactAlert): alert is ArtifactAlertCveFixable;
152
- declare function isArtifactAlertUpgradeFixable(alert: SocketArtifactAlert): alert is ArtifactAlertFixable;
153
- declare function isArtifactAlertFixable(alert: SocketArtifactAlert): alert is ArtifactAlertFixable;
154
- type PackageDetail = {
155
- node: SafeNode;
156
- existing?: SafeNode | undefined;
157
- };
158
- type GetPackagesToQueryFromDiffOptions = {
159
- includeUnchanged?: boolean | undefined;
160
- includeUnknownOrigin?: boolean | undefined;
161
- };
162
- declare function getPackagesToQueryFromDiff(diff_: Diff | null, options?: GetPackagesToQueryFromDiffOptions | undefined): PackageDetail[];
163
- declare function findUp(name: string | string[], { cwd }: {
164
- cwd: string;
165
- }): Promise<string | undefined>;
166
- type ReadFileOptions = ObjectEncodingOptions & Abortable & {
167
- flag?: OpenMode | undefined;
168
- };
169
- declare function readFileBinary(filepath: PathLike | FileHandle, options?: ReadFileOptions | undefined): Promise<Buffer>;
170
- declare function readFileUtf8(filepath: PathLike | FileHandle, options?: ReadFileOptions | undefined): Promise<string>;
171
- declare function safeReadFile(...args: Parameters<typeof fs.readFile>): ReturnType<typeof fs.readFile> | undefined;
172
- declare function safeReadFileSync(...args: Parameters<typeof fsReadFileSync>): ReturnType<typeof fsReadFileSync> | undefined;
173
4
  declare const Arborist: ArboristClass;
174
5
  declare const SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES: {
175
6
  __proto__: null;
@@ -188,4 +19,4 @@ declare class SafeArborist extends Arborist {
188
19
  // @ts-ignore Incorrectly typed.
189
20
  reify(this: SafeArborist, ...args: Parameters<InstanceType<ArboristClass>['reify']>): Promise<SafeNode>;
190
21
  }
191
- export { SafeOverrideSet, depValid, getSocketDevAlertUrl, getSocketDevPackageOverviewUrl, ColorOrMarkdown, createAlertUXLookup, uxLookup, CveAlertType, ArtifactAlertCveFixable, ArtifactAlertFixable, SocketArtifactAlert, SocketArtifact, batchScan, isArtifactAlertCveFixable, isArtifactAlertUpgradeFixable, isArtifactAlertFixable, PackageDetail, getPackagesToQueryFromDiff, findUp, ReadFileOptions, readFileBinary, readFileUtf8, safeReadFile, safeReadFileSync, Arborist, SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES, SafeArborist };
22
+ export { Arborist, SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES, SafeArborist };
@@ -1,5 +1,5 @@
1
1
  /// <reference types="npmcli__arborist" />
2
- import { SafeOverrideSet } from "./index.js";
2
+ import { SafeOverrideSet } from "./override-set.js";
3
3
  import { SafeEdge } from "./edge.js";
4
4
  import { Link } from '@npmcli/arborist';
5
5
  import { Node as BaseNode } from "@npmcli/arborist";
@@ -0,0 +1,37 @@
1
+ import { SafeEdge } from "./edge.js";
2
+ import { SafeNode } from "./node.js";
3
+ interface OverrideSetClass {
4
+ children: Map<string, SafeOverrideSet>;
5
+ key: string | undefined;
6
+ keySpec: string | undefined;
7
+ name: string | undefined;
8
+ parent: SafeOverrideSet | undefined;
9
+ value: string | undefined;
10
+ version: string | undefined;
11
+ new (...args: any[]): OverrideSetClass;
12
+ get isRoot(): boolean;
13
+ get ruleset(): Map<string, SafeOverrideSet>;
14
+ ancestry(): Generator<SafeOverrideSet>;
15
+ childrenAreEqual(otherOverrideSet: SafeOverrideSet | undefined): boolean;
16
+ getEdgeRule(edge: SafeEdge): SafeOverrideSet;
17
+ getNodeRule(node: SafeNode): SafeOverrideSet;
18
+ getMatchingRule(node: SafeNode): SafeOverrideSet | null;
19
+ isEqual(otherOverrideSet: SafeOverrideSet | undefined): boolean;
20
+ }
21
+ declare const OverrideSet: OverrideSetClass;
22
+ declare class SafeOverrideSet extends OverrideSet {
23
+ // Patch adding doOverrideSetsConflict is based on
24
+ // https://github.com/npm/cli/pull/8089.
25
+ static doOverrideSetsConflict(first: SafeOverrideSet | undefined, second: SafeOverrideSet | undefined): boolean;
26
+ // Patch adding findSpecificOverrideSet is based on
27
+ // https://github.com/npm/cli/pull/8089.
28
+ static findSpecificOverrideSet(first: SafeOverrideSet | undefined, second: SafeOverrideSet | undefined): SafeOverrideSet | undefined;
29
+ // Patch adding childrenAreEqual is based on
30
+ // https://github.com/npm/cli/pull/8089.
31
+ childrenAreEqual(otherOverrideSet: SafeOverrideSet): boolean;
32
+ getEdgeRule(edge: SafeEdge): SafeOverrideSet;
33
+ // Patch adding isEqual is based on
34
+ // https://github.com/npm/cli/pull/8089.
35
+ isEqual(otherOverrideSet: SafeOverrideSet | undefined): boolean;
36
+ }
37
+ export { SafeOverrideSet };
@@ -14,7 +14,7 @@ var npm = require('@socketsecurity/registry/lib/npm');
14
14
  var spawn = require('@socketsecurity/registry/lib/spawn');
15
15
  var path = require('node:path');
16
16
  var cmdShim = _socketInterop(require('cmd-shim'));
17
- var npmPaths = require('./npm-paths.js');
17
+ var shadowNpmPaths = require('./shadow-npm-paths.js');
18
18
  var constants = require('./constants.js');
19
19
 
20
20
  const {
@@ -24,7 +24,7 @@ const {
24
24
  async function installLinks(realBinPath, binName) {
25
25
  const isNpx = binName === NPX;
26
26
  // Find package manager being shadowed by this process.
27
- const binPath = isNpx ? npmPaths.getNpxBinPath() : npmPaths.getNpmBinPath();
27
+ const binPath = isNpx ? shadowNpmPaths.getNpxBinPath() : shadowNpmPaths.getNpmBinPath();
28
28
  // Lazily access constants.WIN32.
29
29
  const {
30
30
  WIN32
@@ -33,7 +33,7 @@ async function installLinks(realBinPath, binName) {
33
33
  if (WIN32 && binPath) {
34
34
  return binPath;
35
35
  }
36
- const shadowed = isNpx ? npmPaths.isNpxBinPathShadowed() : npmPaths.isNpmBinPathShadowed();
36
+ const shadowed = isNpx ? shadowNpmPaths.isNpxBinPathShadowed() : shadowNpmPaths.isNpmBinPathShadowed();
37
37
  // Move our bin directory to front of PATH so its found first.
38
38
  if (!shadowed) {
39
39
  if (WIN32) {
@@ -63,10 +63,10 @@ async function shadowBin(binName, args = process.argv.slice(2), level = 1) {
63
63
  ...constants.nodeNoWarningsFlags,
64
64
  // Lazily access constants.ENV[SOCKET_CLI_SENTRY_BUILD].
65
65
  ...(constants.ENV[SOCKET_CLI_SENTRY_BUILD] ? ['--require',
66
- // Lazily access constants.instrumentWithSentryPath.
67
- constants.instrumentWithSentryPath] : []), '--require',
68
- // Lazily access constants.npmInjectionPath.
69
- constants.npmInjectionPath,
66
+ // Lazily access constants.distInstrumentWithSentryPath.
67
+ constants.distInstrumentWithSentryPath] : []), '--require',
68
+ // Lazily access constants.distShadowNpmInjectPath.
69
+ constants.distShadowNpmInjectPath,
70
70
  // Lazily access constants.shadowBinPath.
71
71
  await installLinks(constants.shadowBinPath, binName),
72
72
  // Add `--no-progress` and `--loglevel=error` flags to fix input being
@@ -94,5 +94,5 @@ async function shadowBin(binName, args = process.argv.slice(2), level = 1) {
94
94
  }
95
95
 
96
96
  module.exports = shadowBin;
97
- //# debugId=6bb6d502-939a-444f-a22e-07a531d3b61f
97
+ //# debugId=c58c4335-92d0-4ad1-86bf-6eb5428f654a
98
98
  //# sourceMappingURL=shadow-bin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shadow-bin.js","sources":["../../src/shadow/link.ts","../../src/shadow/shadow-bin.ts"],"sourcesContent":["import path from 'node:path'\nimport process from 'node:process'\n\nimport cmdShim from 'cmd-shim'\n\nimport {\n getNpmBinPath,\n getNpxBinPath,\n isNpmBinPathShadowed,\n isNpxBinPathShadowed\n} from './npm-paths'\nimport constants from '../constants'\n\nconst { CLI, NPX } = constants\n\nexport async function installLinks(\n realBinPath: string,\n binName: 'npm' | 'npx'\n): Promise<string> {\n const isNpx = binName === NPX\n // Find package manager being shadowed by this process.\n const binPath = isNpx ? getNpxBinPath() : getNpmBinPath()\n // Lazily access constants.WIN32.\n const { WIN32 } = constants\n // TODO: Is this early exit needed?\n if (WIN32 && binPath) {\n return binPath\n }\n const shadowed = isNpx ? isNpxBinPathShadowed() : isNpmBinPathShadowed()\n // Move our bin directory to front of PATH so its found first.\n if (!shadowed) {\n if (WIN32) {\n await cmdShim(\n // Lazily access constants.rootDistPath.\n path.join(constants.rootDistPath, `${binName}-${CLI}.js`),\n path.join(realBinPath, binName)\n )\n }\n process.env['PATH'] =\n `${realBinPath}${path.delimiter}${process.env['PATH']}`\n }\n return binPath\n}\n","import process from 'node:process'\n\nimport {\n isLoglevelFlag,\n isProgressFlag\n} from '@socketsecurity/registry/lib/npm'\nimport { spawn } from '@socketsecurity/registry/lib/spawn'\n\nimport { installLinks } from './link'\nimport constants from '../constants'\n\nconst {\n SOCKET_CLI_SAFE_WRAPPER,\n SOCKET_CLI_SENTRY_BUILD,\n SOCKET_IPC_HANDSHAKE\n} = constants\n\nexport default async function shadowBin(\n binName: 'npm' | 'npx',\n args = process.argv.slice(2),\n level = 1\n) {\n process.exitCode = 1\n const terminatorPos = args.indexOf('--')\n const binArgs = (\n terminatorPos === -1 ? args : args.slice(0, terminatorPos)\n ).filter(a => !isProgressFlag(a))\n const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos)\n const spawnPromise = spawn(\n // Lazily access constants.execPath.\n constants.execPath,\n [\n // Lazily access constants.nodeNoWarningsFlags.\n ...constants.nodeNoWarningsFlags,\n // Lazily access constants.ENV[SOCKET_CLI_SENTRY_BUILD].\n ...(constants.ENV[SOCKET_CLI_SENTRY_BUILD]\n ? [\n '--require',\n // Lazily access constants.instrumentWithSentryPath.\n constants.instrumentWithSentryPath\n ]\n : []),\n '--require',\n // Lazily access constants.npmInjectionPath.\n constants.npmInjectionPath,\n // Lazily access constants.shadowBinPath.\n await installLinks(constants.shadowBinPath, binName),\n // Add `--no-progress` and `--loglevel=error` flags to fix input being\n // swallowed by the npm spinner.\n '--no-progress',\n // Add the '--loglevel=error' flag if a loglevel flag is not provided.\n ...(binArgs.some(isLoglevelFlag) ? [] : ['--loglevel', 'error']),\n ...binArgs,\n ...otherArgs\n ],\n {\n // 'inherit' + 'ipc'\n stdio: [0, 1, 2, 'ipc']\n }\n )\n // See https://nodejs.org/api/all.html#all_child_process_event-exit.\n spawnPromise.process.on('exit', (code, signalName) => {\n if (signalName) {\n process.kill(process.pid, signalName)\n } else if (code !== null) {\n process.exit(code)\n }\n })\n spawnPromise.process.send({\n [SOCKET_IPC_HANDSHAKE]: {\n [SOCKET_CLI_SAFE_WRAPPER]: level\n }\n })\n await spawnPromise\n}\n"],"names":["NPX","WIN32","process","SOCKET_IPC_HANDSHAKE","constants","spawnPromise"],"mappings":";;;;;;;;;;;;;;;;;;;AAaA;;AAAaA;AAAI;AAEV;AAIL;AACA;;AAEA;;AACQC;AAAM;AACd;;AAEE;AACF;;AAEA;;AAEE;AACE;AACE;;AAIJ;AACAC;AAEF;AACA;AACF;;AC/BA;;;AAGEC;AACF;AAEe;;AAMb;AACA;AAGA;;AAEE;;AAGE;;AAEA;;AAIM;AACAC;AAIN;AACAA;AACA;AACA;AACA;AACA;;AAEA;;AAMA;;AAEF;AAEF;;AAEE;;AAEA;AACEF;AACF;AACF;AACAG;AACE;AACE;AACF;AACF;AACA;AACF;;","debugId":"6bb6d502-939a-444f-a22e-07a531d3b61f"}
1
+ {"version":3,"file":"shadow-bin.js","sources":["../../src/shadow/npm/link.ts","../../src/shadow/npm/bin.ts"],"sourcesContent":["import path from 'node:path'\nimport process from 'node:process'\n\nimport cmdShim from 'cmd-shim'\n\nimport {\n getNpmBinPath,\n getNpxBinPath,\n isNpmBinPathShadowed,\n isNpxBinPathShadowed\n} from './paths'\nimport constants from '../../constants'\n\nconst { CLI, NPX } = constants\n\nexport async function installLinks(\n realBinPath: string,\n binName: 'npm' | 'npx'\n): Promise<string> {\n const isNpx = binName === NPX\n // Find package manager being shadowed by this process.\n const binPath = isNpx ? getNpxBinPath() : getNpmBinPath()\n // Lazily access constants.WIN32.\n const { WIN32 } = constants\n // TODO: Is this early exit needed?\n if (WIN32 && binPath) {\n return binPath\n }\n const shadowed = isNpx ? isNpxBinPathShadowed() : isNpmBinPathShadowed()\n // Move our bin directory to front of PATH so its found first.\n if (!shadowed) {\n if (WIN32) {\n await cmdShim(\n // Lazily access constants.rootDistPath.\n path.join(constants.rootDistPath, `${binName}-${CLI}.js`),\n path.join(realBinPath, binName)\n )\n }\n process.env['PATH'] =\n `${realBinPath}${path.delimiter}${process.env['PATH']}`\n }\n return binPath\n}\n","import process from 'node:process'\n\nimport {\n isLoglevelFlag,\n isProgressFlag\n} from '@socketsecurity/registry/lib/npm'\nimport { spawn } from '@socketsecurity/registry/lib/spawn'\n\nimport { installLinks } from './link'\nimport constants from '../../constants'\n\nconst {\n SOCKET_CLI_SAFE_WRAPPER,\n SOCKET_CLI_SENTRY_BUILD,\n SOCKET_IPC_HANDSHAKE\n} = constants\n\nexport default async function shadowBin(\n binName: 'npm' | 'npx',\n args = process.argv.slice(2),\n level = 1\n) {\n process.exitCode = 1\n const terminatorPos = args.indexOf('--')\n const binArgs = (\n terminatorPos === -1 ? args : args.slice(0, terminatorPos)\n ).filter(a => !isProgressFlag(a))\n const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos)\n const spawnPromise = spawn(\n // Lazily access constants.execPath.\n constants.execPath,\n [\n // Lazily access constants.nodeNoWarningsFlags.\n ...constants.nodeNoWarningsFlags,\n // Lazily access constants.ENV[SOCKET_CLI_SENTRY_BUILD].\n ...(constants.ENV[SOCKET_CLI_SENTRY_BUILD]\n ? [\n '--require',\n // Lazily access constants.distInstrumentWithSentryPath.\n constants.distInstrumentWithSentryPath\n ]\n : []),\n '--require',\n // Lazily access constants.distShadowNpmInjectPath.\n constants.distShadowNpmInjectPath,\n // Lazily access constants.shadowBinPath.\n await installLinks(constants.shadowBinPath, binName),\n // Add `--no-progress` and `--loglevel=error` flags to fix input being\n // swallowed by the npm spinner.\n '--no-progress',\n // Add the '--loglevel=error' flag if a loglevel flag is not provided.\n ...(binArgs.some(isLoglevelFlag) ? [] : ['--loglevel', 'error']),\n ...binArgs,\n ...otherArgs\n ],\n {\n // 'inherit' + 'ipc'\n stdio: [0, 1, 2, 'ipc']\n }\n )\n // See https://nodejs.org/api/all.html#all_child_process_event-exit.\n spawnPromise.process.on('exit', (code, signalName) => {\n if (signalName) {\n process.kill(process.pid, signalName)\n } else if (code !== null) {\n process.exit(code)\n }\n })\n spawnPromise.process.send({\n [SOCKET_IPC_HANDSHAKE]: {\n [SOCKET_CLI_SAFE_WRAPPER]: level\n }\n })\n await spawnPromise\n}\n"],"names":["NPX","WIN32","process","SOCKET_IPC_HANDSHAKE","constants","spawnPromise"],"mappings":";;;;;;;;;;;;;;;;;;;AAaA;;AAAaA;AAAI;AAEV;AAIL;AACA;;AAEA;;AACQC;AAAM;AACd;;AAEE;AACF;;AAEA;;AAEE;AACE;AACE;;AAIJ;AACAC;AAEF;AACA;AACF;;AC/BA;;;AAGEC;AACF;AAEe;;AAMb;AACA;AAGA;;AAEE;;AAGE;;AAEA;;AAIM;AACAC;AAIN;AACAA;AACA;AACA;AACA;AACA;;AAEA;;AAMA;;AAEF;AAEF;;AAEE;;AAEA;AACEF;AACF;AACF;AACAG;AACE;AACE;AACF;AACF;AACA;AACF;;","debugId":"c58c4335-92d0-4ad1-86bf-6eb5428f654a"}
@@ -38,7 +38,7 @@ var logger = require('@socketsecurity/registry/lib/logger');
38
38
  var terminalLink = _socketInterop(require('terminal-link'));
39
39
  var colors = _socketInterop(require('yoctocolors-cjs'));
40
40
  var indentString = require('@socketregistry/indent-string/index.cjs');
41
- var npmPaths = require('./npm-paths.js');
41
+ var shadowNpmPaths = require('./shadow-npm-paths.js');
42
42
  var npa = _socketInterop(require('npm-package-arg'));
43
43
 
44
44
  const {
@@ -700,13 +700,6 @@ void (async () => {
700
700
  _uxLookup = createAlertUXLookup(settings);
701
701
  })();
702
702
 
703
- const markdownLogSymbols = Object.freeze({
704
- __proto__: null,
705
- info: ':information_source:',
706
- error: ':stop_sign:',
707
- success: ':white_check_mark:',
708
- warning: ':warning:'
709
- });
710
703
  class ColorOrMarkdown {
711
704
  constructor(useMarkdown) {
712
705
  this.useMarkdown = !!useMarkdown;
@@ -741,9 +734,6 @@ class ColorOrMarkdown {
741
734
  const indentedContent = items.map(item => this.indent(item).trimStart());
742
735
  return this.useMarkdown ? `* ${indentedContent.join('\n* ')}\n` : `${indentedContent.join('\n')}\n`;
743
736
  }
744
- get logSymbols() {
745
- return this.useMarkdown ? markdownLogSymbols : logger.Logger.LOG_SYMBOLS;
746
- }
747
737
  }
748
738
 
749
739
  function getSocketDevAlertUrl(alertType) {
@@ -753,7 +743,7 @@ function getSocketDevPackageOverviewUrl(eco, name, version) {
753
743
  return `https://socket.dev/${eco}/package/${name}${version ? `/overview/${version}` : ''}`;
754
744
  }
755
745
 
756
- const depValid = require(npmPaths.getArboristDepValidPath());
746
+ const depValid = require(shadowNpmPaths.getArboristDepValidPath());
757
747
 
758
748
  const {
759
749
  UNDEFINED_TOKEN
@@ -783,7 +773,7 @@ function tryRequire(req, ...ids) {
783
773
  let _log = UNDEFINED_TOKEN;
784
774
  function getLogger() {
785
775
  if (_log === UNDEFINED_TOKEN) {
786
- _log = tryRequire(npmPaths.getNpmRequire(), ['proc-log/lib/index.js',
776
+ _log = tryRequire(shadowNpmPaths.getNpmRequire(), ['proc-log/lib/index.js',
787
777
  // The proc-log DefinitelyTyped definition is incorrect. The type definition
788
778
  // is really that of its export log.
789
779
  mod => mod.log], 'npmlog/lib/log.js');
@@ -791,7 +781,7 @@ function getLogger() {
791
781
  return _log;
792
782
  }
793
783
 
794
- const OverrideSet = require(npmPaths.getArboristOverrideSetClassPath());
784
+ const OverrideSet = require(shadowNpmPaths.getArboristOverrideSetClassPath());
795
785
 
796
786
  // Implementation code not related to patch https://github.com/npm/cli/pull/8089
797
787
  // is based on https://github.com/npm/cli/blob/v11.0.0/workspaces/arborist/lib/override-set.js:
@@ -909,7 +899,7 @@ class SafeOverrideSet extends OverrideSet {
909
899
  }
910
900
  }
911
901
 
912
- const Node = require(npmPaths.getArboristNodeClassPath());
902
+ const Node = require(shadowNpmPaths.getArboristNodeClassPath());
913
903
 
914
904
  // Implementation code not related to patch https://github.com/npm/cli/pull/8089
915
905
  // is based on https://github.com/npm/cli/blob/v11.0.0/workspaces/arborist/lib/node.js:
@@ -1205,7 +1195,7 @@ class SafeNode extends Node {
1205
1195
  }
1206
1196
  }
1207
1197
 
1208
- const Edge = require(npmPaths.getArboristEdgeClassPath());
1198
+ const Edge = require(shadowNpmPaths.getArboristEdgeClassPath());
1209
1199
 
1210
1200
  // The Edge class makes heavy use of private properties which subclasses do NOT
1211
1201
  // have access to. So we have to recreate any functionality that relies on those
@@ -1783,7 +1773,7 @@ const {
1783
1773
  getIPC
1784
1774
  }
1785
1775
  } = constants;
1786
- const Arborist = require(npmPaths.getArboristClassPath());
1776
+ const Arborist = require(shadowNpmPaths.getArboristClassPath());
1787
1777
  const SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES = {
1788
1778
  __proto__: null,
1789
1779
  audit: false,
@@ -1847,15 +1837,32 @@ class SafeArborist extends Arborist {
1847
1837
  }
1848
1838
  }
1849
1839
 
1840
+ function installSafeArborist() {
1841
+ // Override '@npmcli/arborist' module exports with patched variants based on
1842
+ // https://github.com/npm/cli/pull/8089.
1843
+ const cache = require.cache;
1844
+ cache[shadowNpmPaths.getArboristClassPath()] = {
1845
+ exports: SafeArborist
1846
+ };
1847
+ cache[shadowNpmPaths.getArboristEdgeClassPath()] = {
1848
+ exports: SafeEdge
1849
+ };
1850
+ cache[shadowNpmPaths.getArboristNodeClassPath()] = {
1851
+ exports: SafeNode
1852
+ };
1853
+ cache[shadowNpmPaths.getArboristOverrideSetClassPath()] = {
1854
+ exports: SafeOverrideSet
1855
+ };
1856
+ }
1857
+
1858
+ installSafeArborist();
1859
+
1850
1860
  exports.Arborist = Arborist;
1851
1861
  exports.AuthError = AuthError;
1852
1862
  exports.ColorOrMarkdown = ColorOrMarkdown;
1853
1863
  exports.InputError = InputError;
1854
1864
  exports.SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES = SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES;
1855
1865
  exports.SafeArborist = SafeArborist;
1856
- exports.SafeEdge = SafeEdge;
1857
- exports.SafeNode = SafeNode;
1858
- exports.SafeOverrideSet = SafeOverrideSet;
1859
1866
  exports.captureException = captureException;
1860
1867
  exports.findPackageNodes = findPackageNodes;
1861
1868
  exports.findUp = findUp;
@@ -1872,5 +1879,5 @@ exports.safeReadFile = safeReadFile;
1872
1879
  exports.setupSdk = setupSdk;
1873
1880
  exports.updateNode = updateNode;
1874
1881
  exports.updateSetting = updateSetting;
1875
- //# debugId=32696061-6e8b-4f74-95c9-9ae9ce6c9c1c
1876
- //# sourceMappingURL=index.js.map
1882
+ //# debugId=a2461f74-6908-4fea-b499-5d8392a553ba
1883
+ //# sourceMappingURL=shadow-npm-inject.js.map