@socketsecurity/cli-with-sentry 0.15.33 → 0.15.34
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/cli.js +106 -83
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +3 -3
- package/dist/constants.js.map +1 -1
- package/dist/shadow-inject.js.map +1 -1
- package/dist/utils.js +34 -28
- package/dist/utils.js.map +1 -1
- package/external/@socketsecurity/registry/lib/debug.js +37 -9
- package/package.json +4 -4
package/dist/cli.js
CHANGED
|
@@ -630,7 +630,7 @@ ${table}
|
|
|
630
630
|
process.exitCode = 1;
|
|
631
631
|
logger.logger.fail('There was a problem converting the logs to Markdown, please try the `--json` flag');
|
|
632
632
|
if (debug.isDebug()) {
|
|
633
|
-
debug.debugFn('
|
|
633
|
+
debug.debugFn('catch: unexpected\n', e);
|
|
634
634
|
}
|
|
635
635
|
return '';
|
|
636
636
|
}
|
|
@@ -1151,7 +1151,7 @@ async function run$O(argv, importMeta, {
|
|
|
1151
1151
|
async function getDefaultOrgSlug() {
|
|
1152
1152
|
const defaultOrgResult = utils.getConfigValueOrUndef('defaultOrg');
|
|
1153
1153
|
if (defaultOrgResult) {
|
|
1154
|
-
debug.debugFn('
|
|
1154
|
+
debug.debugFn('use: default org', defaultOrgResult);
|
|
1155
1155
|
return {
|
|
1156
1156
|
ok: true,
|
|
1157
1157
|
data: defaultOrgResult
|
|
@@ -1183,7 +1183,7 @@ async function getDefaultOrgSlug() {
|
|
|
1183
1183
|
data: `Was unable to determine the default organization for the current API token. Unable to continue.`
|
|
1184
1184
|
};
|
|
1185
1185
|
}
|
|
1186
|
-
debug.debugFn('
|
|
1186
|
+
debug.debugFn('resolve: org', slug);
|
|
1187
1187
|
return {
|
|
1188
1188
|
ok: true,
|
|
1189
1189
|
message: 'Retrieved default org from server',
|
|
@@ -1287,7 +1287,7 @@ async function fetchReportData(orgSlug, scanId, includeLicensePolicy) {
|
|
|
1287
1287
|
return JSON.parse(line);
|
|
1288
1288
|
} catch {
|
|
1289
1289
|
ok = false;
|
|
1290
|
-
debug.debugFn('
|
|
1290
|
+
debug.debugFn('fail: parse NDJSON\n', line);
|
|
1291
1291
|
return;
|
|
1292
1292
|
}
|
|
1293
1293
|
});
|
|
@@ -3737,7 +3737,7 @@ async function gitCreateAndPushBranch(branch, commitMsg, filepaths, options) {
|
|
|
3737
3737
|
await spawn.spawn('git', ['push', '--force', '--set-upstream', 'origin', branch], stdioIgnoreOptions);
|
|
3738
3738
|
return true;
|
|
3739
3739
|
} catch (e) {
|
|
3740
|
-
debug.debugFn('
|
|
3740
|
+
debug.debugFn('catch: unexpected\n', e);
|
|
3741
3741
|
}
|
|
3742
3742
|
try {
|
|
3743
3743
|
// Will throw with exit code 1 if branch does not exist.
|
|
@@ -3767,7 +3767,7 @@ async function gitEnsureIdentity(name, email, cwd = process.cwd()) {
|
|
|
3767
3767
|
try {
|
|
3768
3768
|
await spawn.spawn('git', ['config', prop, value], stdioIgnoreOptions);
|
|
3769
3769
|
} catch (e) {
|
|
3770
|
-
debug.debugFn('
|
|
3770
|
+
debug.debugFn('catch: unexpected\n', e);
|
|
3771
3771
|
}
|
|
3772
3772
|
}
|
|
3773
3773
|
}));
|
|
@@ -3807,7 +3807,7 @@ async function gitUnstagedModifiedFiles(cwd = process.cwd()) {
|
|
|
3807
3807
|
data: rawFiles.map(relPath => path$1.normalizePath(relPath))
|
|
3808
3808
|
};
|
|
3809
3809
|
} catch (e) {
|
|
3810
|
-
debug.debugFn('
|
|
3810
|
+
debug.debugFn('catch: git diff --name-only failed\n', e);
|
|
3811
3811
|
return {
|
|
3812
3812
|
ok: false,
|
|
3813
3813
|
message: 'Git Error',
|
|
@@ -3904,14 +3904,14 @@ async function cleanupOpenPrs(owner, repo, newVersion, options) {
|
|
|
3904
3904
|
pull_number: prNum,
|
|
3905
3905
|
state: 'closed'
|
|
3906
3906
|
});
|
|
3907
|
-
debug.debugFn(`
|
|
3907
|
+
debug.debugFn(`close: ${prRef} for ${prToVersion}`);
|
|
3908
3908
|
// Remove entry from parent object.
|
|
3909
3909
|
context.parent.splice(context.index, 1);
|
|
3910
3910
|
// Mark cache to be saved.
|
|
3911
3911
|
cachesToSave.set(context.cacheKey, context.data);
|
|
3912
3912
|
return null;
|
|
3913
3913
|
} catch (e) {
|
|
3914
|
-
debug.debugFn(`
|
|
3914
|
+
debug.debugFn(`fail: close ${prRef}\n`, e?.message || 'unknown error');
|
|
3915
3915
|
}
|
|
3916
3916
|
}
|
|
3917
3917
|
// Update stale PRs.
|
|
@@ -3924,7 +3924,7 @@ async function cleanupOpenPrs(owner, repo, newVersion, options) {
|
|
|
3924
3924
|
base: match.headRefName,
|
|
3925
3925
|
head: match.baseRefName
|
|
3926
3926
|
});
|
|
3927
|
-
debug.debugFn(
|
|
3927
|
+
debug.debugFn('update: stale', prRef);
|
|
3928
3928
|
// Update entry entry.
|
|
3929
3929
|
if (context.apiType === 'graphql') {
|
|
3930
3930
|
context.entry.mergeStateStatus = 'CLEAN';
|
|
@@ -3935,7 +3935,7 @@ async function cleanupOpenPrs(owner, repo, newVersion, options) {
|
|
|
3935
3935
|
cachesToSave.set(context.cacheKey, context.data);
|
|
3936
3936
|
} catch (e) {
|
|
3937
3937
|
const message = e?.message || 'Unknown error';
|
|
3938
|
-
debug.debugFn(`
|
|
3938
|
+
debug.debugFn(`fail: update ${prRef} - ${message}`);
|
|
3939
3939
|
}
|
|
3940
3940
|
}
|
|
3941
3941
|
return match;
|
|
@@ -4002,6 +4002,9 @@ function getGitHubEnvRepoInfo() {
|
|
|
4002
4002
|
repo: ownerSlashRepo.slice(slashIndex + 1)
|
|
4003
4003
|
};
|
|
4004
4004
|
}
|
|
4005
|
+
async function getOpenSocketPrs(owner, repo, options) {
|
|
4006
|
+
return (await getOpenSocketPrsWithContext(owner, repo, options)).map(d => d.match);
|
|
4007
|
+
}
|
|
4005
4008
|
async function getOpenSocketPrsWithContext(owner, repo, options_) {
|
|
4006
4009
|
const options = {
|
|
4007
4010
|
__proto__: null,
|
|
@@ -4124,7 +4127,7 @@ async function openPr(owner, repo, branch, purl, newVersion, options) {
|
|
|
4124
4127
|
};
|
|
4125
4128
|
// Lazily access constants.ENV.GITHUB_ACTIONS.
|
|
4126
4129
|
if (!constants.ENV.GITHUB_ACTIONS) {
|
|
4127
|
-
debug.debugFn('
|
|
4130
|
+
debug.debugFn('miss: GITHUB_ACTIONS env var');
|
|
4128
4131
|
return null;
|
|
4129
4132
|
}
|
|
4130
4133
|
const octokit = getOctokit();
|
|
@@ -4173,7 +4176,7 @@ async function setGitRemoteGitHubRepoUrl(owner, repo, token, cwd = process.cwd()
|
|
|
4173
4176
|
try {
|
|
4174
4177
|
await spawn.spawn('git', ['remote', 'set-url', 'origin', url], stdioIgnoreOptions);
|
|
4175
4178
|
} catch (e) {
|
|
4176
|
-
debug.debugFn('
|
|
4179
|
+
debug.debugFn('catch: unexpected\n', e);
|
|
4177
4180
|
}
|
|
4178
4181
|
}
|
|
4179
4182
|
|
|
@@ -4228,10 +4231,24 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4228
4231
|
const {
|
|
4229
4232
|
spinner
|
|
4230
4233
|
} = constants;
|
|
4231
|
-
spinner?.start();
|
|
4232
4234
|
const {
|
|
4233
4235
|
pkgPath: rootPath
|
|
4234
4236
|
} = pkgEnvDetails;
|
|
4237
|
+
|
|
4238
|
+
// Lazily access constants.ENV properties.
|
|
4239
|
+
const gitEmail = constants.ENV.SOCKET_CLI_GIT_USER_EMAIL;
|
|
4240
|
+
const gitUser = constants.ENV.SOCKET_CLI_GIT_USER_NAME;
|
|
4241
|
+
const githubToken = constants.ENV.SOCKET_CLI_GITHUB_TOKEN;
|
|
4242
|
+
const isCi = !!(constants.ENV.CI && constants.ENV.GITHUB_ACTIONS && constants.ENV.GITHUB_REPOSITORY && gitEmail && gitUser && githubToken);
|
|
4243
|
+
spinner?.start();
|
|
4244
|
+
let count = 0;
|
|
4245
|
+
let repoInfo = null;
|
|
4246
|
+
if (isCi) {
|
|
4247
|
+
repoInfo = getGitHubEnvRepoInfo();
|
|
4248
|
+
count += (await getOpenSocketPrs(repoInfo.owner, repoInfo.repo, {
|
|
4249
|
+
author: gitUser
|
|
4250
|
+
})).length;
|
|
4251
|
+
}
|
|
4235
4252
|
const arb = new shadowInject.Arborist({
|
|
4236
4253
|
path: rootPath,
|
|
4237
4254
|
...shadowInject.SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES
|
|
@@ -4248,8 +4265,7 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4248
4265
|
}));
|
|
4249
4266
|
} catch (e) {
|
|
4250
4267
|
spinner?.stop();
|
|
4251
|
-
debug.debugFn('
|
|
4252
|
-
debug.debugFn(e);
|
|
4268
|
+
debug.debugFn('catch: PURL API\n', e);
|
|
4253
4269
|
return {
|
|
4254
4270
|
ok: false,
|
|
4255
4271
|
message: 'API Error',
|
|
@@ -4269,17 +4285,14 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4269
4285
|
}
|
|
4270
4286
|
};
|
|
4271
4287
|
}
|
|
4272
|
-
|
|
4273
|
-
// Lazily access constants.ENV properties.
|
|
4274
|
-
const token = constants.ENV.SOCKET_CLI_GITHUB_TOKEN;
|
|
4275
|
-
const isCi = !!(constants.ENV.CI && constants.ENV.GITHUB_ACTIONS && constants.ENV.GITHUB_REPOSITORY && token);
|
|
4276
4288
|
const baseBranch = isCi ? getBaseGitBranch() : '';
|
|
4277
4289
|
const workspacePkgJsonPaths = await utils.globWorkspace(pkgEnvDetails.agent, rootPath);
|
|
4278
4290
|
const pkgJsonPaths = [...workspacePkgJsonPaths,
|
|
4279
4291
|
// Process the workspace root last since it will add an override to package.json.
|
|
4280
4292
|
pkgEnvDetails.editablePkgJson.filename];
|
|
4293
|
+
const sortedInfoEntries = [...infoByPkgName.entries()].sort((a, b) => sorts.naturalCompare(a[0], b[0]));
|
|
4281
4294
|
const handleInstallFail = () => {
|
|
4282
|
-
debug.debugFn(`
|
|
4295
|
+
debug.debugFn(`fail: ${pkgEnvDetails.agent} install\n`);
|
|
4283
4296
|
logger.logger.dedent();
|
|
4284
4297
|
spinner?.dedent();
|
|
4285
4298
|
return {
|
|
@@ -4289,8 +4302,6 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4289
4302
|
};
|
|
4290
4303
|
};
|
|
4291
4304
|
spinner?.stop();
|
|
4292
|
-
let count = 0;
|
|
4293
|
-
const sortedInfoEntries = [...infoByPkgName.entries()].sort((a, b) => sorts.naturalCompare(a[0], b[0]));
|
|
4294
4305
|
infoEntriesLoop: for (let i = 0, {
|
|
4295
4306
|
length
|
|
4296
4307
|
} = sortedInfoEntries; i < length; i += 1) {
|
|
@@ -4303,7 +4314,7 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4303
4314
|
logger.logger.indent();
|
|
4304
4315
|
spinner?.indent();
|
|
4305
4316
|
if (registry.getManifestData(NPM$a, name)) {
|
|
4306
|
-
debug.debugFn(`Socket Optimize
|
|
4317
|
+
debug.debugFn(`found: Socket Optimize variant for ${name}`);
|
|
4307
4318
|
}
|
|
4308
4319
|
// eslint-disable-next-line no-await-in-loop
|
|
4309
4320
|
const packument = await packages.fetchPackagePackument(name);
|
|
@@ -4327,7 +4338,7 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4327
4338
|
const workspace = isWorkspaceRoot ? 'root' : path.relative(rootPath, pkgPath);
|
|
4328
4339
|
const oldVersions = arrays.arrayUnique(shadowInject.findPackageNodes(actualTree, name).map(n => n.target?.version ?? n.version).filter(Boolean));
|
|
4329
4340
|
if (!oldVersions.length) {
|
|
4330
|
-
debug.debugFn(
|
|
4341
|
+
debug.debugFn(`skip: ${name} not found\n`);
|
|
4331
4342
|
// Skip to next package.
|
|
4332
4343
|
logger.logger.dedent();
|
|
4333
4344
|
spinner?.dedent();
|
|
@@ -4343,7 +4354,7 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4343
4354
|
let hasAnnouncedWorkspace = false;
|
|
4344
4355
|
let workspaceLogCallCount = logger.logger.logCallCount;
|
|
4345
4356
|
if (debug.isDebug()) {
|
|
4346
|
-
debug.debugFn(`
|
|
4357
|
+
debug.debugFn(`check: workspace ${workspace}`);
|
|
4347
4358
|
hasAnnouncedWorkspace = true;
|
|
4348
4359
|
workspaceLogCallCount = logger.logger.logCallCount;
|
|
4349
4360
|
}
|
|
@@ -4352,7 +4363,7 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4352
4363
|
const oldPurl = utils.idToPurl(oldId);
|
|
4353
4364
|
const node = shadowInject.findPackageNode(actualTree, name, oldVersion);
|
|
4354
4365
|
if (!node) {
|
|
4355
|
-
debug.debugFn(
|
|
4366
|
+
debug.debugFn(`skip: ${oldId} not found`);
|
|
4356
4367
|
continue oldVersionsLoop;
|
|
4357
4368
|
}
|
|
4358
4369
|
infosLoop: for (const {
|
|
@@ -4360,7 +4371,7 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4360
4371
|
vulnerableVersionRange
|
|
4361
4372
|
} of infos.values()) {
|
|
4362
4373
|
if (vendor.semverExports.gte(oldVersion, firstPatchedVersionIdentifier)) {
|
|
4363
|
-
debug.debugFn(
|
|
4374
|
+
debug.debugFn(`skip: ${oldId} is >= ${firstPatchedVersionIdentifier}`);
|
|
4364
4375
|
continue infosLoop;
|
|
4365
4376
|
}
|
|
4366
4377
|
const newVersion = shadowInject.findBestPatchVersion(node, availableVersions, vulnerableVersionRange);
|
|
@@ -4396,7 +4407,7 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4396
4407
|
if (!(await editablePkgJson.save({
|
|
4397
4408
|
ignoreWhitespace: true
|
|
4398
4409
|
}))) {
|
|
4399
|
-
debug.debugFn(
|
|
4410
|
+
debug.debugFn(`skip: ${workspace}/package.json unchanged`);
|
|
4400
4411
|
// Reset things just in case.
|
|
4401
4412
|
if (isCi) {
|
|
4402
4413
|
// eslint-disable-next-line no-await-in-loop
|
|
@@ -4454,23 +4465,24 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4454
4465
|
logger.logger.warn('Unexpected condition: Nothing to commit, skipping PR creation.');
|
|
4455
4466
|
continue infosLoop;
|
|
4456
4467
|
}
|
|
4457
|
-
const repoInfo = getGitHubEnvRepoInfo();
|
|
4458
4468
|
const branch = getSocketBranchName(oldPurl, newVersion, workspace);
|
|
4459
4469
|
let skipPr = false;
|
|
4460
4470
|
if (
|
|
4461
4471
|
// eslint-disable-next-line no-await-in-loop
|
|
4462
4472
|
await prExistForBranch(repoInfo.owner, repoInfo.repo, branch)) {
|
|
4463
4473
|
skipPr = true;
|
|
4464
|
-
debug.debugFn(`
|
|
4474
|
+
debug.debugFn(`skip: branch "${branch}" exists`);
|
|
4465
4475
|
}
|
|
4466
4476
|
// eslint-disable-next-line no-await-in-loop
|
|
4467
4477
|
else if (await gitRemoteBranchExists(branch, cwd)) {
|
|
4468
4478
|
skipPr = true;
|
|
4469
|
-
debug.debugFn(`
|
|
4479
|
+
debug.debugFn(`skip: remote branch "${branch}" exists`);
|
|
4470
4480
|
} else if (
|
|
4471
4481
|
// eslint-disable-next-line no-await-in-loop
|
|
4472
4482
|
!(await gitCreateAndPushBranch(branch, getSocketCommitMessage(oldPurl, newVersion, workspace), moddedFilepaths, {
|
|
4473
|
-
cwd
|
|
4483
|
+
cwd,
|
|
4484
|
+
email: gitEmail,
|
|
4485
|
+
user: gitUser
|
|
4474
4486
|
}))) {
|
|
4475
4487
|
skipPr = true;
|
|
4476
4488
|
logger.logger.warn('Unexpected condition: Push failed, skipping PR creation.');
|
|
@@ -4491,7 +4503,7 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4491
4503
|
}
|
|
4492
4504
|
|
|
4493
4505
|
// eslint-disable-next-line no-await-in-loop
|
|
4494
|
-
await Promise.allSettled([setGitRemoteGitHubRepoUrl(repoInfo.owner, repoInfo.repo,
|
|
4506
|
+
await Promise.allSettled([setGitRemoteGitHubRepoUrl(repoInfo.owner, repoInfo.repo, githubToken, cwd), cleanupOpenPrs(repoInfo.owner, repoInfo.repo, newVersion, {
|
|
4495
4507
|
purl: oldPurl,
|
|
4496
4508
|
workspace
|
|
4497
4509
|
})]);
|
|
@@ -4652,7 +4664,21 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4652
4664
|
const {
|
|
4653
4665
|
pkgPath: rootPath
|
|
4654
4666
|
} = pkgEnvDetails;
|
|
4667
|
+
|
|
4668
|
+
// Lazily access constants.ENV properties.
|
|
4669
|
+
const gitEmail = constants.ENV.SOCKET_CLI_GIT_USER_EMAIL;
|
|
4670
|
+
const gitUser = constants.ENV.SOCKET_CLI_GIT_USER_NAME;
|
|
4671
|
+
const githubToken = constants.ENV.SOCKET_CLI_GITHUB_TOKEN;
|
|
4672
|
+
const isCi = !!(constants.ENV.CI && constants.ENV.GITHUB_ACTIONS && constants.ENV.GITHUB_REPOSITORY && gitEmail && gitUser && githubToken);
|
|
4655
4673
|
spinner?.start();
|
|
4674
|
+
let count = 0;
|
|
4675
|
+
let repoInfo = null;
|
|
4676
|
+
if (isCi) {
|
|
4677
|
+
repoInfo = getGitHubEnvRepoInfo();
|
|
4678
|
+
count += (await getOpenSocketPrs(repoInfo.owner, repoInfo.repo, {
|
|
4679
|
+
author: gitUser
|
|
4680
|
+
})).length;
|
|
4681
|
+
}
|
|
4656
4682
|
let actualTree;
|
|
4657
4683
|
const lockfilePath = path.join(rootPath, 'pnpm-lock.yaml');
|
|
4658
4684
|
let lockfileContent = await utils.readPnpmLockfile(lockfilePath);
|
|
@@ -4707,8 +4733,7 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4707
4733
|
}));
|
|
4708
4734
|
} catch (e) {
|
|
4709
4735
|
spinner?.stop();
|
|
4710
|
-
debug.debugFn('
|
|
4711
|
-
debug.debugFn(e);
|
|
4736
|
+
debug.debugFn('catch: PURL API\n', e);
|
|
4712
4737
|
return {
|
|
4713
4738
|
ok: false,
|
|
4714
4739
|
message: 'API Error',
|
|
@@ -4728,15 +4753,12 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4728
4753
|
}
|
|
4729
4754
|
};
|
|
4730
4755
|
}
|
|
4731
|
-
|
|
4732
|
-
// Lazily access constants.ENV properties.
|
|
4733
|
-
const token = constants.ENV.SOCKET_CLI_GITHUB_TOKEN;
|
|
4734
|
-
const isCi = !!(constants.ENV.CI && constants.ENV.GITHUB_ACTIONS && constants.ENV.GITHUB_REPOSITORY && token);
|
|
4735
4756
|
const baseBranch = isCi ? getBaseGitBranch() : '';
|
|
4736
4757
|
const workspacePkgJsonPaths = await utils.globWorkspace(pkgEnvDetails.agent, rootPath);
|
|
4737
4758
|
const pkgJsonPaths = [...workspacePkgJsonPaths,
|
|
4738
4759
|
// Process the workspace root last since it will add an override to package.json.
|
|
4739
4760
|
pkgEnvDetails.editablePkgJson.filename];
|
|
4761
|
+
const sortedInfoEntries = [...infoByPkgName.entries()].sort((a, b) => sorts.naturalCompare(a[0], b[0]));
|
|
4740
4762
|
const handleInstallFail = () => {
|
|
4741
4763
|
logger.logger.dedent();
|
|
4742
4764
|
spinner?.dedent();
|
|
@@ -4747,8 +4769,6 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4747
4769
|
};
|
|
4748
4770
|
};
|
|
4749
4771
|
spinner?.stop();
|
|
4750
|
-
let count = 0;
|
|
4751
|
-
const sortedInfoEntries = [...infoByPkgName.entries()].sort((a, b) => sorts.naturalCompare(a[0], b[0]));
|
|
4752
4772
|
infoEntriesLoop: for (let i = 0, {
|
|
4753
4773
|
length
|
|
4754
4774
|
} = sortedInfoEntries; i < length; i += 1) {
|
|
@@ -4761,7 +4781,7 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4761
4781
|
logger.logger.indent();
|
|
4762
4782
|
spinner?.indent();
|
|
4763
4783
|
if (registry.getManifestData(NPM$9, name)) {
|
|
4764
|
-
debug.debugFn(`Socket Optimize
|
|
4784
|
+
debug.debugFn(`found: Socket Optimize variant for ${name}`);
|
|
4765
4785
|
}
|
|
4766
4786
|
// eslint-disable-next-line no-await-in-loop
|
|
4767
4787
|
const packument = await packages.fetchPackagePackument(name);
|
|
@@ -4786,6 +4806,10 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4786
4806
|
|
|
4787
4807
|
// actualTree may not be defined on the first iteration of pkgJsonPathsLoop.
|
|
4788
4808
|
if (!actualTree) {
|
|
4809
|
+
if (!isCi) {
|
|
4810
|
+
// eslint-disable-next-line no-await-in-loop
|
|
4811
|
+
await utils.removeNodeModules(cwd);
|
|
4812
|
+
}
|
|
4789
4813
|
const maybeActualTree = isCi && fs$1.existsSync(path.join(rootPath, 'node_modules')) ?
|
|
4790
4814
|
// eslint-disable-next-line no-await-in-loop
|
|
4791
4815
|
await getActualTree(cwd) :
|
|
@@ -4808,7 +4832,7 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4808
4832
|
}
|
|
4809
4833
|
const oldVersions = arrays.arrayUnique(shadowInject.findPackageNodes(actualTree, name).map(n => n.version).filter(Boolean));
|
|
4810
4834
|
if (!oldVersions.length) {
|
|
4811
|
-
debug.debugFn(
|
|
4835
|
+
debug.debugFn(`skip: ${name} not found\n`);
|
|
4812
4836
|
// Skip to next package.
|
|
4813
4837
|
logger.logger.dedent();
|
|
4814
4838
|
spinner?.dedent();
|
|
@@ -4827,7 +4851,7 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4827
4851
|
let hasAnnouncedWorkspace = false;
|
|
4828
4852
|
let workspaceLogCallCount = logger.logger.logCallCount;
|
|
4829
4853
|
if (debug.isDebug()) {
|
|
4830
|
-
debug.debugFn(`
|
|
4854
|
+
debug.debugFn(`check: workspace ${workspace}`);
|
|
4831
4855
|
hasAnnouncedWorkspace = true;
|
|
4832
4856
|
workspaceLogCallCount = logger.logger.logCallCount;
|
|
4833
4857
|
}
|
|
@@ -4836,7 +4860,7 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4836
4860
|
const oldPurl = utils.idToPurl(oldId);
|
|
4837
4861
|
const node = shadowInject.findPackageNode(actualTree, name, oldVersion);
|
|
4838
4862
|
if (!node) {
|
|
4839
|
-
debug.debugFn(
|
|
4863
|
+
debug.debugFn(`skip: ${oldId} not found`);
|
|
4840
4864
|
continue oldVersionsLoop;
|
|
4841
4865
|
}
|
|
4842
4866
|
infosLoop: for (const {
|
|
@@ -4844,7 +4868,7 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4844
4868
|
vulnerableVersionRange
|
|
4845
4869
|
} of infos.values()) {
|
|
4846
4870
|
if (vendor.semverExports.gte(oldVersion, firstPatchedVersionIdentifier)) {
|
|
4847
|
-
debug.debugFn(
|
|
4871
|
+
debug.debugFn(`skip: ${oldId} is >= ${firstPatchedVersionIdentifier}`);
|
|
4848
4872
|
continue infosLoop;
|
|
4849
4873
|
}
|
|
4850
4874
|
const newVersion = shadowInject.findBestPatchVersion(node, availableVersions, vulnerableVersionRange);
|
|
@@ -4902,7 +4926,7 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4902
4926
|
if (!(await editablePkgJson.save({
|
|
4903
4927
|
ignoreWhitespace: true
|
|
4904
4928
|
}))) {
|
|
4905
|
-
debug.debugFn(
|
|
4929
|
+
debug.debugFn(`skip: ${workspace}/package.json unchanged`);
|
|
4906
4930
|
// Reset things just in case.
|
|
4907
4931
|
if (isCi) {
|
|
4908
4932
|
// eslint-disable-next-line no-await-in-loop
|
|
@@ -4977,23 +5001,24 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4977
5001
|
logger.logger.warn('Unexpected condition: Nothing to commit, skipping PR creation.');
|
|
4978
5002
|
continue infosLoop;
|
|
4979
5003
|
}
|
|
4980
|
-
const repoInfo = getGitHubEnvRepoInfo();
|
|
4981
5004
|
const branch = getSocketBranchName(oldPurl, newVersion, workspace);
|
|
4982
5005
|
let skipPr = false;
|
|
4983
5006
|
if (
|
|
4984
5007
|
// eslint-disable-next-line no-await-in-loop
|
|
4985
5008
|
await prExistForBranch(repoInfo.owner, repoInfo.repo, branch)) {
|
|
4986
5009
|
skipPr = true;
|
|
4987
|
-
debug.debugFn(`
|
|
5010
|
+
debug.debugFn(`skip: branch "${branch}" exists`);
|
|
4988
5011
|
}
|
|
4989
5012
|
// eslint-disable-next-line no-await-in-loop
|
|
4990
5013
|
else if (await gitRemoteBranchExists(branch, cwd)) {
|
|
4991
5014
|
skipPr = true;
|
|
4992
|
-
debug.debugFn(`
|
|
5015
|
+
debug.debugFn(`skip: remote branch "${branch}" exists`);
|
|
4993
5016
|
} else if (
|
|
4994
5017
|
// eslint-disable-next-line no-await-in-loop
|
|
4995
5018
|
!(await gitCreateAndPushBranch(branch, getSocketCommitMessage(oldPurl, newVersion, workspace), moddedFilepaths, {
|
|
4996
|
-
cwd
|
|
5019
|
+
cwd,
|
|
5020
|
+
email: gitEmail,
|
|
5021
|
+
user: gitUser
|
|
4997
5022
|
}))) {
|
|
4998
5023
|
skipPr = true;
|
|
4999
5024
|
logger.logger.warn('Unexpected condition: Push failed, skipping PR creation.');
|
|
@@ -5019,7 +5044,7 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
5019
5044
|
}
|
|
5020
5045
|
|
|
5021
5046
|
// eslint-disable-next-line no-await-in-loop
|
|
5022
|
-
await Promise.allSettled([setGitRemoteGitHubRepoUrl(repoInfo.owner, repoInfo.repo,
|
|
5047
|
+
await Promise.allSettled([setGitRemoteGitHubRepoUrl(repoInfo.owner, repoInfo.repo, githubToken, cwd), cleanupOpenPrs(repoInfo.owner, repoInfo.repo, newVersion, {
|
|
5023
5048
|
purl: oldPurl,
|
|
5024
5049
|
workspace
|
|
5025
5050
|
})]);
|
|
@@ -5130,12 +5155,14 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
5130
5155
|
spinner?.dedent();
|
|
5131
5156
|
}
|
|
5132
5157
|
spinner?.stop();
|
|
5158
|
+
|
|
5159
|
+
// Or, did we change anything?
|
|
5133
5160
|
return {
|
|
5134
5161
|
ok: true,
|
|
5135
5162
|
data: {
|
|
5136
5163
|
fixed: true
|
|
5137
5164
|
}
|
|
5138
|
-
};
|
|
5165
|
+
};
|
|
5139
5166
|
}
|
|
5140
5167
|
|
|
5141
5168
|
const {
|
|
@@ -5634,9 +5661,9 @@ async function setupTabCompletion(targetName) {
|
|
|
5634
5661
|
|
|
5635
5662
|
// Target dir is something like ~/.local/share/socket/settings/completion (linux)
|
|
5636
5663
|
const targetDir = path.dirname(targetPath);
|
|
5637
|
-
debug.debugFn('
|
|
5664
|
+
debug.debugFn('target: path + dir', targetPath, targetDir);
|
|
5638
5665
|
if (!fs$1.existsSync(targetDir)) {
|
|
5639
|
-
debug.debugFn('
|
|
5666
|
+
debug.debugFn('create: target dir');
|
|
5640
5667
|
fs$1.mkdirSync(targetDir, {
|
|
5641
5668
|
recursive: true
|
|
5642
5669
|
});
|
|
@@ -8016,7 +8043,7 @@ async function updateLockfile(pkgEnvDetails, options) {
|
|
|
8016
8043
|
}
|
|
8017
8044
|
} catch (e) {
|
|
8018
8045
|
spinner?.stop();
|
|
8019
|
-
debug.debugFn(e);
|
|
8046
|
+
debug.debugFn('fail: update\n', e);
|
|
8020
8047
|
return {
|
|
8021
8048
|
ok: false,
|
|
8022
8049
|
message: 'Update failed',
|
|
@@ -9859,7 +9886,7 @@ async function fetchListAllRepos({
|
|
|
9859
9886
|
page: String(nextPage)
|
|
9860
9887
|
}), 'list of repositories');
|
|
9861
9888
|
if (!result.ok) {
|
|
9862
|
-
debug.debugFn('
|
|
9889
|
+
debug.debugFn('fail: fetch repo\n', result);
|
|
9863
9890
|
return result;
|
|
9864
9891
|
}
|
|
9865
9892
|
result.data.results.forEach(row => rows.push(row));
|
|
@@ -11366,7 +11393,7 @@ async function scanOneRepo(repoSlug, {
|
|
|
11366
11393
|
};
|
|
11367
11394
|
}
|
|
11368
11395
|
const tmpDir = fs$1.mkdtempSync(path.join(os.tmpdir(), repoSlug));
|
|
11369
|
-
debug.debugFn('
|
|
11396
|
+
debug.debugFn('init: temp dir for scan root', tmpDir);
|
|
11370
11397
|
const downloadResult = await testAndDownloadManifestFiles({
|
|
11371
11398
|
files,
|
|
11372
11399
|
tmpDir,
|
|
@@ -11479,7 +11506,7 @@ async function testAndDownloadManifestFile({
|
|
|
11479
11506
|
repoApiUrl,
|
|
11480
11507
|
tmpDir
|
|
11481
11508
|
}) {
|
|
11482
|
-
debug.debugFn('
|
|
11509
|
+
debug.debugFn('test: file', file);
|
|
11483
11510
|
if (!SUPPORTED_FILE_PATTERNS.some(regex => regex.test(file))) {
|
|
11484
11511
|
// Not an error.
|
|
11485
11512
|
return {
|
|
@@ -11489,7 +11516,7 @@ async function testAndDownloadManifestFile({
|
|
|
11489
11516
|
}
|
|
11490
11517
|
};
|
|
11491
11518
|
}
|
|
11492
|
-
debug.
|
|
11519
|
+
debug.debugFn('found: manifest file', file);
|
|
11493
11520
|
const result = await downloadManifestFile({
|
|
11494
11521
|
file,
|
|
11495
11522
|
tmpDir,
|
|
@@ -11497,15 +11524,12 @@ async function testAndDownloadManifestFile({
|
|
|
11497
11524
|
repoApiUrl,
|
|
11498
11525
|
githubToken
|
|
11499
11526
|
});
|
|
11500
|
-
|
|
11501
|
-
return result;
|
|
11502
|
-
}
|
|
11503
|
-
return {
|
|
11527
|
+
return result.ok ? {
|
|
11504
11528
|
ok: true,
|
|
11505
11529
|
data: {
|
|
11506
11530
|
isManifest: true
|
|
11507
11531
|
}
|
|
11508
|
-
};
|
|
11532
|
+
} : result;
|
|
11509
11533
|
}
|
|
11510
11534
|
async function downloadManifestFile({
|
|
11511
11535
|
defaultBranch,
|
|
@@ -11514,34 +11538,33 @@ async function downloadManifestFile({
|
|
|
11514
11538
|
repoApiUrl,
|
|
11515
11539
|
tmpDir
|
|
11516
11540
|
}) {
|
|
11517
|
-
debug.
|
|
11541
|
+
debug.debugFn('request: download url from GitHub');
|
|
11518
11542
|
const fileUrl = `${repoApiUrl}/contents/${file}?ref=${defaultBranch}`;
|
|
11519
|
-
debug.debugFn('
|
|
11543
|
+
debug.debugFn('url: file', fileUrl);
|
|
11520
11544
|
const downloadUrlResponse = await fetch(fileUrl, {
|
|
11521
11545
|
method: 'GET',
|
|
11522
11546
|
headers: {
|
|
11523
11547
|
Authorization: `Bearer ${githubToken}`
|
|
11524
11548
|
}
|
|
11525
11549
|
});
|
|
11526
|
-
debug.
|
|
11550
|
+
debug.debugFn('complete: request');
|
|
11527
11551
|
const downloadUrlText = await downloadUrlResponse.text();
|
|
11528
|
-
debug.debugFn('
|
|
11552
|
+
debug.debugFn('response: raw download url', downloadUrlText);
|
|
11529
11553
|
let downloadUrl;
|
|
11530
11554
|
try {
|
|
11531
11555
|
downloadUrl = JSON.parse(downloadUrlText).download_url;
|
|
11532
11556
|
} catch {
|
|
11533
11557
|
logger.logger.fail(`GitHub response contained invalid JSON for download url for: ${file}`);
|
|
11534
|
-
debug.
|
|
11535
|
-
debug.debugLog(downloadUrlText);
|
|
11558
|
+
debug.debugFn('content: raw (not JSON)', downloadUrlText);
|
|
11536
11559
|
return {
|
|
11537
11560
|
ok: false,
|
|
11538
11561
|
message: 'Invalid JSON response',
|
|
11539
11562
|
cause: `Server responded with invalid JSON for download url ${downloadUrl}`
|
|
11540
11563
|
};
|
|
11541
11564
|
}
|
|
11542
|
-
debug.
|
|
11565
|
+
debug.debugFn('download: manifest file');
|
|
11543
11566
|
const localPath = path.join(tmpDir, file);
|
|
11544
|
-
debug.debugFn('
|
|
11567
|
+
debug.debugFn('download:', downloadUrl, '->', localPath);
|
|
11545
11568
|
|
|
11546
11569
|
// Now stream the file to that file...
|
|
11547
11570
|
|
|
@@ -11628,14 +11651,14 @@ async function getLastCommitDetails({
|
|
|
11628
11651
|
}) {
|
|
11629
11652
|
logger.logger.info(`Requesting last commit for default branch ${defaultBranch} for ${orgGithub}/${repoSlug}...`);
|
|
11630
11653
|
const commitApiUrl = `${repoApiUrl}/commits?sha=${defaultBranch}&per_page=1`;
|
|
11631
|
-
debug.debugFn('
|
|
11654
|
+
debug.debugFn('url: commit', commitApiUrl);
|
|
11632
11655
|
const commitResponse = await fetch(commitApiUrl, {
|
|
11633
11656
|
headers: {
|
|
11634
11657
|
Authorization: `Bearer ${githubToken}`
|
|
11635
11658
|
}
|
|
11636
11659
|
});
|
|
11637
11660
|
const commitText = await commitResponse.text();
|
|
11638
|
-
debug.debugFn('
|
|
11661
|
+
debug.debugFn('response: commit', commitText);
|
|
11639
11662
|
let lastCommit;
|
|
11640
11663
|
try {
|
|
11641
11664
|
lastCommit = JSON.parse(commitText)?.[0];
|
|
@@ -11722,7 +11745,7 @@ async function getRepoDetails({
|
|
|
11722
11745
|
repoSlug
|
|
11723
11746
|
}) {
|
|
11724
11747
|
const repoApiUrl = `${githubApiUrl}/repos/${orgGithub}/${repoSlug}`;
|
|
11725
|
-
debug.debugFn('
|
|
11748
|
+
debug.debugFn('url: repo', repoApiUrl);
|
|
11726
11749
|
const repoDetailsResponse = await fetch(repoApiUrl, {
|
|
11727
11750
|
method: 'GET',
|
|
11728
11751
|
headers: {
|
|
@@ -11731,7 +11754,7 @@ async function getRepoDetails({
|
|
|
11731
11754
|
});
|
|
11732
11755
|
logger.logger.success(`Request completed.`);
|
|
11733
11756
|
const repoDetailsText = await repoDetailsResponse.text();
|
|
11734
|
-
debug.debugFn('
|
|
11757
|
+
debug.debugFn('response: repo', repoDetailsText);
|
|
11735
11758
|
let repoDetails;
|
|
11736
11759
|
try {
|
|
11737
11760
|
repoDetails = JSON.parse(repoDetailsText);
|
|
@@ -11770,7 +11793,7 @@ async function getRepoBranchTree({
|
|
|
11770
11793
|
}) {
|
|
11771
11794
|
logger.logger.info(`Requesting default branch file tree; branch \`${defaultBranch}\`, repo \`${orgGithub}/${repoSlug}\`...`);
|
|
11772
11795
|
const treeApiUrl = `${repoApiUrl}/git/trees/${defaultBranch}?recursive=1`;
|
|
11773
|
-
debug.debugFn('
|
|
11796
|
+
debug.debugFn('url: tree', treeApiUrl);
|
|
11774
11797
|
const treeResponse = await fetch(treeApiUrl, {
|
|
11775
11798
|
method: 'GET',
|
|
11776
11799
|
headers: {
|
|
@@ -11778,7 +11801,7 @@ async function getRepoBranchTree({
|
|
|
11778
11801
|
}
|
|
11779
11802
|
});
|
|
11780
11803
|
const treeText = await treeResponse.text();
|
|
11781
|
-
debug.debugFn('
|
|
11804
|
+
debug.debugFn('response: tree', treeText);
|
|
11782
11805
|
let treeDetails;
|
|
11783
11806
|
try {
|
|
11784
11807
|
treeDetails = JSON.parse(treeText);
|
|
@@ -12555,7 +12578,7 @@ async function fetchScan(orgSlug, scanId) {
|
|
|
12555
12578
|
return JSON.parse(line);
|
|
12556
12579
|
} catch {
|
|
12557
12580
|
ok = false;
|
|
12558
|
-
debug.debugFn('
|
|
12581
|
+
debug.debugFn('fail: parse NDJSON\n', line);
|
|
12559
12582
|
return null;
|
|
12560
12583
|
}
|
|
12561
12584
|
});
|
|
@@ -13340,7 +13363,7 @@ Do you want to install "safe npm" (this will create an alias to the socket-npm c
|
|
|
13340
13363
|
}
|
|
13341
13364
|
}
|
|
13342
13365
|
} catch (e) {
|
|
13343
|
-
debug.debugFn('
|
|
13366
|
+
debug.debugFn('fail: setup tab completion\n', e);
|
|
13344
13367
|
// Ignore. Skip tab completion setup.
|
|
13345
13368
|
}
|
|
13346
13369
|
if (!updatedTabCompletion) {
|
|
@@ -13582,5 +13605,5 @@ void (async () => {
|
|
|
13582
13605
|
await utils.captureException(e);
|
|
13583
13606
|
}
|
|
13584
13607
|
})();
|
|
13585
|
-
//# debugId=
|
|
13608
|
+
//# debugId=7e206930-1632-4ae3-b9bc-0c092c388970
|
|
13586
13609
|
//# sourceMappingURL=cli.js.map
|