socket 0.14.40 → 0.14.41
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/dist/module-sync/cli.js +83 -129
- package/dist/module-sync/npm-injection.js +208 -261
- package/dist/module-sync/settings.d.ts +6 -1
- package/dist/module-sync/socket-url.d.ts +17 -1
- package/dist/module-sync/socket-url.js +81 -2
- package/dist/require/cli.js +83 -129
- package/package.json +26 -20
package/dist/module-sync/cli.js
CHANGED
|
@@ -31,7 +31,6 @@ var socketUrl = require('./socket-url.js');
|
|
|
31
31
|
var terminalLink = _socketInterop(require('terminal-link'));
|
|
32
32
|
var isInteractive = require('@socketregistry/is-interactive/index.cjs');
|
|
33
33
|
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
34
|
-
var fs$1 = require('node:fs/promises');
|
|
35
34
|
var npa = _socketInterop(require('npm-package-arg'));
|
|
36
35
|
var semver = _socketInterop(require('semver'));
|
|
37
36
|
var tinyglobby = _socketInterop(require('tinyglobby'));
|
|
@@ -44,6 +43,7 @@ var strings = require('@socketsecurity/registry/lib/strings');
|
|
|
44
43
|
var browserslist = _socketInterop(require('browserslist'));
|
|
45
44
|
var which = _socketInterop(require('which'));
|
|
46
45
|
var index_cjs = require('@socketregistry/hyrious__bun.lockb/index.cjs');
|
|
46
|
+
var sorts = require('@socketsecurity/registry/lib/sorts');
|
|
47
47
|
var betterAjvErrors = _socketInterop(require('@apideck/better-ajv-errors'));
|
|
48
48
|
var config = require('@socketsecurity/config');
|
|
49
49
|
var os = require('node:os');
|
|
@@ -51,6 +51,7 @@ var readline = require('node:readline');
|
|
|
51
51
|
var readline$1 = require('node:readline/promises');
|
|
52
52
|
var open = _socketInterop(require('open'));
|
|
53
53
|
var chalkTable = _socketInterop(require('chalk-table'));
|
|
54
|
+
var fs$1 = require('node:fs/promises');
|
|
54
55
|
var ScreenWidget = _socketInterop(require('blessed/lib/widgets/screen'));
|
|
55
56
|
var GridLayout = _socketInterop(require('blessed-contrib/lib/layout/grid'));
|
|
56
57
|
var BarChart = _socketInterop(require('blessed-contrib/lib/widget/charts/bar'));
|
|
@@ -238,10 +239,10 @@ function shadowNpmInstall(opts) {
|
|
|
238
239
|
constants.execPath, [
|
|
239
240
|
// Lazily access constants.rootBinPath.
|
|
240
241
|
path.join(constants.rootBinPath, 'npm-cli.js'), 'install',
|
|
241
|
-
// Even though the 'silent' flag is passed npm will still run through
|
|
242
|
-
// paths for 'audit' and 'fund' unless '--no-audit' and '--no-fund'
|
|
243
|
-
// are passed.
|
|
244
|
-
...(useDebug ? ['--no-audit', '--no-fund'] : ['silent', '--no-audit', '--no-fund']), ...flags], {
|
|
242
|
+
// Even though the '--silent' flag is passed npm will still run through
|
|
243
|
+
// code paths for 'audit' and 'fund' unless '--no-audit' and '--no-fund'
|
|
244
|
+
// flags are passed.
|
|
245
|
+
...(useDebug ? ['--no-audit', '--no-fund'] : ['--silent', '--no-audit', '--no-fund']), ...flags], {
|
|
245
246
|
signal: abortSignal$3,
|
|
246
247
|
// Set stdio to include 'ipc'.
|
|
247
248
|
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
@@ -335,47 +336,6 @@ const validationFlags = {
|
|
|
335
336
|
}
|
|
336
337
|
};
|
|
337
338
|
|
|
338
|
-
const {
|
|
339
|
-
API_V0_URL
|
|
340
|
-
} = constants;
|
|
341
|
-
function handleUnsuccessfulApiResponse(_name, result, spinner) {
|
|
342
|
-
// SocketSdkErrorType['error'] is not typed.
|
|
343
|
-
const resultErrorMessage = result.error?.message;
|
|
344
|
-
const message = typeof resultErrorMessage === 'string' ? resultErrorMessage : 'No error message returned';
|
|
345
|
-
if (result.status === 401 || result.status === 403) {
|
|
346
|
-
spinner.stop();
|
|
347
|
-
throw new socketUrl.AuthError(message);
|
|
348
|
-
}
|
|
349
|
-
spinner.error(`${colors.bgRed(colors.white('API returned an error:'))} ${message}`);
|
|
350
|
-
process$1.exit(1);
|
|
351
|
-
}
|
|
352
|
-
async function handleApiCall(value, description) {
|
|
353
|
-
let result;
|
|
354
|
-
try {
|
|
355
|
-
result = await value;
|
|
356
|
-
} catch (cause) {
|
|
357
|
-
throw new ponyCause.ErrorWithCause(`Failed ${description}`, {
|
|
358
|
-
cause
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
return result;
|
|
362
|
-
}
|
|
363
|
-
async function handleAPIError(code) {
|
|
364
|
-
if (code === 400) {
|
|
365
|
-
return 'One of the options passed might be incorrect.';
|
|
366
|
-
} else if (code === 403) {
|
|
367
|
-
return 'You might be trying to access an organization that is not linked to the API key you are logged in with.';
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
async function queryAPI(path, apiKey) {
|
|
371
|
-
return await fetch(`${API_V0_URL}/${path}`, {
|
|
372
|
-
method: 'GET',
|
|
373
|
-
headers: {
|
|
374
|
-
Authorization: `Basic ${btoa(`${apiKey}:${apiKey}`)}`
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
|
|
379
339
|
function objectSome(obj) {
|
|
380
340
|
for (const key in obj) {
|
|
381
341
|
if (obj[key]) {
|
|
@@ -392,31 +352,6 @@ function pick(input, keys) {
|
|
|
392
352
|
return result;
|
|
393
353
|
}
|
|
394
354
|
|
|
395
|
-
function getFlagListOutput(list, indent, {
|
|
396
|
-
keyPrefix = '--',
|
|
397
|
-
padName
|
|
398
|
-
} = {}) {
|
|
399
|
-
return getHelpListOutput({
|
|
400
|
-
...list
|
|
401
|
-
}, indent, {
|
|
402
|
-
keyPrefix,
|
|
403
|
-
padName
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
function getHelpListOutput(list, indent, {
|
|
407
|
-
keyPrefix = '',
|
|
408
|
-
padName = 18
|
|
409
|
-
} = {}) {
|
|
410
|
-
let result = '';
|
|
411
|
-
const names = Object.keys(list).sort();
|
|
412
|
-
for (const name of names) {
|
|
413
|
-
const rawDescription = list[name];
|
|
414
|
-
const description = (typeof rawDescription === 'object' ? rawDescription.description : rawDescription) || '';
|
|
415
|
-
result += ''.padEnd(indent) + (keyPrefix + name).padEnd(padName) + description + '\n';
|
|
416
|
-
}
|
|
417
|
-
return result.trim();
|
|
418
|
-
}
|
|
419
|
-
|
|
420
355
|
function stringJoinWithSeparateFinalSeparator(list, separator = ' and ') {
|
|
421
356
|
const values = list.filter(Boolean);
|
|
422
357
|
const {
|
|
@@ -432,6 +367,7 @@ function stringJoinWithSeparateFinalSeparator(list, separator = ' and ') {
|
|
|
432
367
|
return `${values.join(', ')}${separator}${finalValue}`;
|
|
433
368
|
}
|
|
434
369
|
|
|
370
|
+
// Ordered from most severe to least.
|
|
435
371
|
const SEVERITIES_BY_ORDER = ['critical', 'high', 'middle', 'low'];
|
|
436
372
|
function getDesiredSeverities(lowestToInclude) {
|
|
437
373
|
const result = [];
|
|
@@ -473,6 +409,72 @@ function getSeverityCount(issues, lowestToInclude) {
|
|
|
473
409
|
return severityCount;
|
|
474
410
|
}
|
|
475
411
|
|
|
412
|
+
const {
|
|
413
|
+
API_V0_URL
|
|
414
|
+
} = constants;
|
|
415
|
+
function handleUnsuccessfulApiResponse(_name, result, spinner) {
|
|
416
|
+
// SocketSdkErrorType['error'] is not typed.
|
|
417
|
+
const resultErrorMessage = result.error?.message;
|
|
418
|
+
const message = typeof resultErrorMessage === 'string' ? resultErrorMessage : 'No error message returned';
|
|
419
|
+
if (result.status === 401 || result.status === 403) {
|
|
420
|
+
spinner.stop();
|
|
421
|
+
throw new socketUrl.AuthError(message);
|
|
422
|
+
}
|
|
423
|
+
spinner.error(`${colors.bgRed(colors.white('API returned an error:'))} ${message}`);
|
|
424
|
+
process$1.exit(1);
|
|
425
|
+
}
|
|
426
|
+
async function handleApiCall(value, description) {
|
|
427
|
+
let result;
|
|
428
|
+
try {
|
|
429
|
+
result = await value;
|
|
430
|
+
} catch (cause) {
|
|
431
|
+
throw new ponyCause.ErrorWithCause(`Failed ${description}`, {
|
|
432
|
+
cause
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
return result;
|
|
436
|
+
}
|
|
437
|
+
async function handleAPIError(code) {
|
|
438
|
+
if (code === 400) {
|
|
439
|
+
return 'One of the options passed might be incorrect.';
|
|
440
|
+
} else if (code === 403) {
|
|
441
|
+
return 'You might be trying to access an organization that is not linked to the API key you are logged in with.';
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
async function queryAPI(path, apiKey) {
|
|
445
|
+
return await fetch(`${API_V0_URL}/${path}`, {
|
|
446
|
+
method: 'GET',
|
|
447
|
+
headers: {
|
|
448
|
+
Authorization: `Basic ${btoa(`${apiKey}:${apiKey}`)}`
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function getFlagListOutput(list, indent, {
|
|
454
|
+
keyPrefix = '--',
|
|
455
|
+
padName
|
|
456
|
+
} = {}) {
|
|
457
|
+
return getHelpListOutput({
|
|
458
|
+
...list
|
|
459
|
+
}, indent, {
|
|
460
|
+
keyPrefix,
|
|
461
|
+
padName
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
function getHelpListOutput(list, indent, {
|
|
465
|
+
keyPrefix = '',
|
|
466
|
+
padName = 18
|
|
467
|
+
} = {}) {
|
|
468
|
+
let result = '';
|
|
469
|
+
const names = Object.keys(list).sort();
|
|
470
|
+
for (const name of names) {
|
|
471
|
+
const rawDescription = list[name];
|
|
472
|
+
const description = (typeof rawDescription === 'object' ? rawDescription.description : rawDescription) || '';
|
|
473
|
+
result += ''.padEnd(indent) + (keyPrefix + name).padEnd(padName) + description + '\n';
|
|
474
|
+
}
|
|
475
|
+
return result.trim();
|
|
476
|
+
}
|
|
477
|
+
|
|
476
478
|
const {
|
|
477
479
|
NPM: NPM$4
|
|
478
480
|
} = registryConstants;
|
|
@@ -834,48 +836,6 @@ const npx = {
|
|
|
834
836
|
}
|
|
835
837
|
};
|
|
836
838
|
|
|
837
|
-
function existsSync(filepath) {
|
|
838
|
-
try {
|
|
839
|
-
return filepath ? fs.existsSync(filepath) : false;
|
|
840
|
-
} catch {}
|
|
841
|
-
return false;
|
|
842
|
-
}
|
|
843
|
-
async function findUp(name, {
|
|
844
|
-
cwd = process$1.cwd()
|
|
845
|
-
}) {
|
|
846
|
-
let dir = path.resolve(cwd);
|
|
847
|
-
const {
|
|
848
|
-
root
|
|
849
|
-
} = path.parse(dir);
|
|
850
|
-
const names = [name].flat();
|
|
851
|
-
while (dir && dir !== root) {
|
|
852
|
-
for (const name of names) {
|
|
853
|
-
const filePath = path.join(dir, name);
|
|
854
|
-
try {
|
|
855
|
-
// eslint-disable-next-line no-await-in-loop
|
|
856
|
-
const stats = await fs.promises.stat(filePath);
|
|
857
|
-
if (stats.isFile()) {
|
|
858
|
-
return filePath;
|
|
859
|
-
}
|
|
860
|
-
} catch {}
|
|
861
|
-
}
|
|
862
|
-
dir = path.dirname(dir);
|
|
863
|
-
}
|
|
864
|
-
return undefined;
|
|
865
|
-
}
|
|
866
|
-
async function readFileBinary(filepath, options) {
|
|
867
|
-
return await fs.promises.readFile(filepath, {
|
|
868
|
-
...options,
|
|
869
|
-
encoding: 'binary'
|
|
870
|
-
});
|
|
871
|
-
}
|
|
872
|
-
async function readFileUtf8(filepath, options) {
|
|
873
|
-
return await fs.promises.readFile(filepath, {
|
|
874
|
-
...options,
|
|
875
|
-
encoding: 'utf8'
|
|
876
|
-
});
|
|
877
|
-
}
|
|
878
|
-
|
|
879
839
|
const {
|
|
880
840
|
BINARY_LOCK_EXT,
|
|
881
841
|
BUN: BUN$1,
|
|
@@ -888,12 +848,6 @@ const {
|
|
|
888
848
|
YARN_CLASSIC: YARN_CLASSIC$1
|
|
889
849
|
} = constants;
|
|
890
850
|
const AGENTS = [BUN$1, NPM$2, PNPM$1, YARN_BERRY$1, YARN_CLASSIC$1, VLT$1];
|
|
891
|
-
const {
|
|
892
|
-
compare: alphanumericComparator
|
|
893
|
-
} = new Intl.Collator(undefined, {
|
|
894
|
-
numeric: true,
|
|
895
|
-
sensitivity: 'base'
|
|
896
|
-
});
|
|
897
851
|
const binByAgent = {
|
|
898
852
|
__proto__: null,
|
|
899
853
|
[BUN$1]: BUN$1,
|
|
@@ -951,8 +905,8 @@ const readLockFileByAgent = (() => {
|
|
|
951
905
|
return undefined;
|
|
952
906
|
};
|
|
953
907
|
}
|
|
954
|
-
const binaryReader = wrapReader(readFileBinary);
|
|
955
|
-
const defaultReader = wrapReader(async lockPath => await readFileUtf8(lockPath));
|
|
908
|
+
const binaryReader = wrapReader(socketUrl.readFileBinary);
|
|
909
|
+
const defaultReader = wrapReader(async lockPath => await socketUrl.readFileUtf8(lockPath));
|
|
956
910
|
return {
|
|
957
911
|
[BUN$1]: wrapReader(async (lockPath, agentExecPath) => {
|
|
958
912
|
const ext = path.extname(lockPath);
|
|
@@ -984,15 +938,15 @@ async function detect({
|
|
|
984
938
|
cwd = process$1.cwd(),
|
|
985
939
|
onUnknown
|
|
986
940
|
} = {}) {
|
|
987
|
-
let lockPath = await findUp(Object.keys(LOCKS), {
|
|
941
|
+
let lockPath = await socketUrl.findUp(Object.keys(LOCKS), {
|
|
988
942
|
cwd
|
|
989
943
|
});
|
|
990
944
|
let lockBasename = lockPath ? path.basename(lockPath) : undefined;
|
|
991
945
|
const isHiddenLockFile = lockBasename === '.package-lock.json';
|
|
992
|
-
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../package.json`) : await findUp('package.json', {
|
|
946
|
+
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../package.json`) : await socketUrl.findUp('package.json', {
|
|
993
947
|
cwd
|
|
994
948
|
});
|
|
995
|
-
const pkgPath = existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
|
|
949
|
+
const pkgPath = pkgJsonPath && fs.existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
|
|
996
950
|
const editablePkgJson = pkgPath ? await packages.readPackageJson(pkgPath, {
|
|
997
951
|
editable: true
|
|
998
952
|
}) : undefined;
|
|
@@ -1049,7 +1003,7 @@ async function detect({
|
|
|
1049
1003
|
}
|
|
1050
1004
|
const browserslistQuery = pkgJson['browserslist'];
|
|
1051
1005
|
if (Array.isArray(browserslistQuery)) {
|
|
1052
|
-
const browserslistTargets = browserslist(browserslistQuery).map(s => s.toLowerCase()).sort(
|
|
1006
|
+
const browserslistTargets = browserslist(browserslistQuery).map(s => s.toLowerCase()).sort(sorts.naturalCompare);
|
|
1053
1007
|
const browserslistNodeTargets = browserslistTargets.filter(v => v.startsWith('node ')).map(v => v.slice(5 /*'node '.length*/));
|
|
1054
1008
|
if (!targets.browser && browserslistTargets.length) {
|
|
1055
1009
|
targets.browser = browserslistTargets.length !== browserslistNodeTargets.length;
|
|
@@ -1475,11 +1429,11 @@ async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
|
|
|
1475
1429
|
let workspacePatterns;
|
|
1476
1430
|
if (agent === PNPM) {
|
|
1477
1431
|
for (const workspacePath of [path.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), path.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
|
|
1478
|
-
|
|
1432
|
+
// eslint-disable-next-line no-await-in-loop
|
|
1433
|
+
const yml = await socketUrl.safeReadFile(workspacePath, 'utf8');
|
|
1434
|
+
if (yml) {
|
|
1479
1435
|
try {
|
|
1480
|
-
workspacePatterns = yaml.parse(
|
|
1481
|
-
// eslint-disable-next-line no-await-in-loop
|
|
1482
|
-
await fs$1.readFile(workspacePath, 'utf8'))?.packages;
|
|
1436
|
+
workspacePatterns = yaml.parse(yml)?.packages;
|
|
1483
1437
|
} catch {}
|
|
1484
1438
|
if (workspacePatterns) {
|
|
1485
1439
|
break;
|