socket 0.15.32 → 0.15.33
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 +200 -67
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +3 -3
- package/dist/constants.js.map +1 -1
- package/dist/utils.js +96 -69
- package/dist/utils.js.map +1 -1
- package/external/@socketsecurity/registry/external/@inquirer/confirm.js +0 -1
- package/external/@socketsecurity/registry/external/@inquirer/input.js +0 -1
- package/external/@socketsecurity/registry/external/@inquirer/password.js +0 -1
- package/external/@socketsecurity/registry/external/@inquirer/search.js +0 -1
- package/external/@socketsecurity/registry/external/@inquirer/select.js +0 -1
- package/external/@socketsecurity/registry/external/@npmcli/package-json/index.js +0 -1
- package/external/@socketsecurity/registry/external/@npmcli/package-json/lib/read-package.js +0 -1
- package/external/@socketsecurity/registry/external/@npmcli/package-json/lib/sort.js +0 -1
- package/external/@socketsecurity/registry/external/@npmcli/promise-spawn.js +0 -1
- package/external/@socketsecurity/registry/external/@socketregistry/is-unicode-supported.js +0 -1
- package/external/@socketsecurity/registry/external/@socketregistry/packageurl-js.js +0 -1
- package/external/@socketsecurity/registry/external/@socketregistry/yocto-spinner.js +0 -1
- package/external/@socketsecurity/registry/external/@yarnpkg/extensions.js +0 -1
- package/external/@socketsecurity/registry/external/browserslist.js +0 -1
- package/external/@socketsecurity/registry/external/cacache.js +0 -1
- package/external/@socketsecurity/registry/external/fast-sort.js +0 -1
- package/external/@socketsecurity/registry/external/libnpmpack.js +0 -1
- package/external/@socketsecurity/registry/external/make-fetch-happen.js +0 -1
- package/external/@socketsecurity/registry/external/normalize-package-data.js +0 -1
- package/external/@socketsecurity/registry/external/npm-package-arg.js +0 -1
- package/external/@socketsecurity/registry/external/pacote.js +0 -1
- package/external/@socketsecurity/registry/external/picomatch.js +0 -1
- package/external/@socketsecurity/registry/external/semver.js +0 -1
- package/external/@socketsecurity/registry/external/signal-exit.js +0 -1
- package/external/@socketsecurity/registry/external/spdx-correct.js +0 -1
- package/external/@socketsecurity/registry/external/spdx-expression-parse.js +0 -1
- package/external/@socketsecurity/registry/external/tinyglobby.js +0 -1
- package/external/@socketsecurity/registry/external/validate-npm-package-name.js +0 -1
- package/external/@socketsecurity/registry/external/which.js +0 -1
- package/external/@socketsecurity/registry/external/yoctocolors-cjs.js +0 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -3711,6 +3711,7 @@ async function gitCleanFdx(cwd = process.cwd()) {
|
|
|
3711
3711
|
cwd,
|
|
3712
3712
|
stdio: 'ignore'
|
|
3713
3713
|
};
|
|
3714
|
+
// TODO: propagate CResult?
|
|
3714
3715
|
await spawn.spawn('git', ['clean', '-fdx'], stdioIgnoreOptions);
|
|
3715
3716
|
}
|
|
3716
3717
|
async function gitCreateAndPushBranch(branch, commitMsg, filepaths, options) {
|
|
@@ -3795,12 +3796,24 @@ async function gitResetHard(branch = 'HEAD', cwd = process.cwd()) {
|
|
|
3795
3796
|
await spawn.spawn('git', ['reset', '--hard', branch], stdioIgnoreOptions);
|
|
3796
3797
|
}
|
|
3797
3798
|
async function gitUnstagedModifiedFiles(cwd = process.cwd()) {
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3799
|
+
try {
|
|
3800
|
+
const stdioPipeOptions = {
|
|
3801
|
+
cwd
|
|
3802
|
+
};
|
|
3803
|
+
const stdout = (await spawn.spawn('git', ['diff', '--name-only'], stdioPipeOptions)).stdout.trim();
|
|
3804
|
+
const rawFiles = stdout.split('\n') ?? [];
|
|
3805
|
+
return {
|
|
3806
|
+
ok: true,
|
|
3807
|
+
data: rawFiles.map(relPath => path$1.normalizePath(relPath))
|
|
3808
|
+
};
|
|
3809
|
+
} catch (e) {
|
|
3810
|
+
debug.debugFn('Unexpected error trying to run git diff --name-only');
|
|
3811
|
+
return {
|
|
3812
|
+
ok: false,
|
|
3813
|
+
message: 'Git Error',
|
|
3814
|
+
cause: 'Unexpected error while trying to ask git whether repo is dirty'
|
|
3815
|
+
};
|
|
3816
|
+
}
|
|
3804
3817
|
}
|
|
3805
3818
|
|
|
3806
3819
|
let _octokit;
|
|
@@ -4235,8 +4248,13 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4235
4248
|
}));
|
|
4236
4249
|
} catch (e) {
|
|
4237
4250
|
spinner?.stop();
|
|
4238
|
-
|
|
4239
|
-
|
|
4251
|
+
debug.debugFn('API Error thrown:');
|
|
4252
|
+
debug.debugFn(e);
|
|
4253
|
+
return {
|
|
4254
|
+
ok: false,
|
|
4255
|
+
message: 'API Error',
|
|
4256
|
+
cause: e?.message || 'Unknown Socket batch PURL API error.'
|
|
4257
|
+
};
|
|
4240
4258
|
}
|
|
4241
4259
|
const infoByPkgName = utils.getCveInfoFromAlertsMap(alertsMap, {
|
|
4242
4260
|
limit
|
|
@@ -4244,7 +4262,12 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4244
4262
|
if (!infoByPkgName) {
|
|
4245
4263
|
spinner?.stop();
|
|
4246
4264
|
logger.logger.info('No fixable vulns found.');
|
|
4247
|
-
return
|
|
4265
|
+
return {
|
|
4266
|
+
ok: true,
|
|
4267
|
+
data: {
|
|
4268
|
+
fixed: false
|
|
4269
|
+
}
|
|
4270
|
+
};
|
|
4248
4271
|
}
|
|
4249
4272
|
|
|
4250
4273
|
// Lazily access constants.ENV properties.
|
|
@@ -4256,9 +4279,14 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4256
4279
|
// Process the workspace root last since it will add an override to package.json.
|
|
4257
4280
|
pkgEnvDetails.editablePkgJson.filename];
|
|
4258
4281
|
const handleInstallFail = () => {
|
|
4259
|
-
|
|
4282
|
+
debug.debugFn(`Unexpected condition: ${pkgEnvDetails.agent} install failed.\n`);
|
|
4260
4283
|
logger.logger.dedent();
|
|
4261
4284
|
spinner?.dedent();
|
|
4285
|
+
return {
|
|
4286
|
+
ok: false,
|
|
4287
|
+
message: 'Installation failure',
|
|
4288
|
+
cause: `Unexpected condition: ${pkgEnvDetails.agent} install failed.`
|
|
4289
|
+
};
|
|
4262
4290
|
};
|
|
4263
4291
|
spinner?.stop();
|
|
4264
4292
|
let count = 0;
|
|
@@ -4410,9 +4438,15 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4410
4438
|
spinner?.stop();
|
|
4411
4439
|
if (!errored && isCi) {
|
|
4412
4440
|
try {
|
|
4413
|
-
const moddedFilepaths =
|
|
4414
4441
|
// eslint-disable-next-line no-await-in-loop
|
|
4415
|
-
|
|
4442
|
+
const result = await gitUnstagedModifiedFiles(cwd);
|
|
4443
|
+
if (!result.ok) {
|
|
4444
|
+
// Do we fail if this fails? If this git command
|
|
4445
|
+
// fails then probably other git commands do too?
|
|
4446
|
+
logger.logger.warn('Unexpected condition: Nothing to commit, skipping PR creation.');
|
|
4447
|
+
continue infosLoop;
|
|
4448
|
+
}
|
|
4449
|
+
const moddedFilepaths = result.data.filter(p => {
|
|
4416
4450
|
const basename = path.basename(p);
|
|
4417
4451
|
return basename === 'package.json' || basename === 'package-lock.json';
|
|
4418
4452
|
});
|
|
@@ -4450,8 +4484,7 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4450
4484
|
});
|
|
4451
4485
|
if (!maybeActualTree) {
|
|
4452
4486
|
// Exit early if install fails.
|
|
4453
|
-
handleInstallFail();
|
|
4454
|
-
return;
|
|
4487
|
+
return handleInstallFail();
|
|
4455
4488
|
}
|
|
4456
4489
|
actualTree = maybeActualTree;
|
|
4457
4490
|
continue infosLoop;
|
|
@@ -4527,8 +4560,7 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4527
4560
|
spinner?.stop();
|
|
4528
4561
|
if (!maybeActualTree) {
|
|
4529
4562
|
// Exit early if install fails.
|
|
4530
|
-
handleInstallFail();
|
|
4531
|
-
return;
|
|
4563
|
+
return handleInstallFail();
|
|
4532
4564
|
}
|
|
4533
4565
|
actualTree = maybeActualTree;
|
|
4534
4566
|
}
|
|
@@ -4555,6 +4587,12 @@ async function npmFix(pkgEnvDetails, {
|
|
|
4555
4587
|
spinner?.dedent();
|
|
4556
4588
|
}
|
|
4557
4589
|
spinner?.stop();
|
|
4590
|
+
return {
|
|
4591
|
+
ok: true,
|
|
4592
|
+
data: {
|
|
4593
|
+
fixed: true
|
|
4594
|
+
}
|
|
4595
|
+
}; // true? did we actually change anything?
|
|
4558
4596
|
}
|
|
4559
4597
|
|
|
4560
4598
|
const {
|
|
@@ -4654,8 +4692,11 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4654
4692
|
// Check !lockfileContent to make TypeScript happy.
|
|
4655
4693
|
if (!lockfile || !lockfileContent) {
|
|
4656
4694
|
spinner?.stop();
|
|
4657
|
-
|
|
4658
|
-
|
|
4695
|
+
return {
|
|
4696
|
+
ok: false,
|
|
4697
|
+
message: 'Missing lockfile',
|
|
4698
|
+
cause: 'Required pnpm-lock.yaml not found or usable'
|
|
4699
|
+
};
|
|
4659
4700
|
}
|
|
4660
4701
|
let alertsMap;
|
|
4661
4702
|
try {
|
|
@@ -4666,8 +4707,13 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4666
4707
|
}));
|
|
4667
4708
|
} catch (e) {
|
|
4668
4709
|
spinner?.stop();
|
|
4669
|
-
|
|
4670
|
-
|
|
4710
|
+
debug.debugFn('Unexpected Socket batch PURL API error:');
|
|
4711
|
+
debug.debugFn(e);
|
|
4712
|
+
return {
|
|
4713
|
+
ok: false,
|
|
4714
|
+
message: 'API Error',
|
|
4715
|
+
cause: e?.message || 'Unknown Socket batch PURL API error.'
|
|
4716
|
+
};
|
|
4671
4717
|
}
|
|
4672
4718
|
const infoByPkgName = utils.getCveInfoFromAlertsMap(alertsMap, {
|
|
4673
4719
|
limit
|
|
@@ -4675,7 +4721,12 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4675
4721
|
if (!infoByPkgName) {
|
|
4676
4722
|
spinner?.stop();
|
|
4677
4723
|
logger.logger.info('No fixable vulns found.');
|
|
4678
|
-
return
|
|
4724
|
+
return {
|
|
4725
|
+
ok: true,
|
|
4726
|
+
data: {
|
|
4727
|
+
fixed: false
|
|
4728
|
+
}
|
|
4729
|
+
};
|
|
4679
4730
|
}
|
|
4680
4731
|
|
|
4681
4732
|
// Lazily access constants.ENV properties.
|
|
@@ -4687,9 +4738,13 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4687
4738
|
// Process the workspace root last since it will add an override to package.json.
|
|
4688
4739
|
pkgEnvDetails.editablePkgJson.filename];
|
|
4689
4740
|
const handleInstallFail = () => {
|
|
4690
|
-
logger.logger.error(`Unexpected condition: ${pkgEnvDetails.agent} install failed.\n`);
|
|
4691
4741
|
logger.logger.dedent();
|
|
4692
4742
|
spinner?.dedent();
|
|
4743
|
+
return {
|
|
4744
|
+
ok: false,
|
|
4745
|
+
message: 'Install failed',
|
|
4746
|
+
cause: `Unexpected condition: ${pkgEnvDetails.agent} install failed`
|
|
4747
|
+
};
|
|
4693
4748
|
};
|
|
4694
4749
|
spinner?.stop();
|
|
4695
4750
|
let count = 0;
|
|
@@ -4749,8 +4804,7 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4749
4804
|
}
|
|
4750
4805
|
if (!actualTree) {
|
|
4751
4806
|
// Exit early if install fails.
|
|
4752
|
-
handleInstallFail();
|
|
4753
|
-
return;
|
|
4807
|
+
return handleInstallFail();
|
|
4754
4808
|
}
|
|
4755
4809
|
const oldVersions = arrays.arrayUnique(shadowInject.findPackageNodes(actualTree, name).map(n => n.version).filter(Boolean));
|
|
4756
4810
|
if (!oldVersions.length) {
|
|
@@ -4909,9 +4963,13 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4909
4963
|
spinner?.stop();
|
|
4910
4964
|
if (!errored && isCi) {
|
|
4911
4965
|
try {
|
|
4912
|
-
const moddedFilepaths =
|
|
4913
4966
|
// eslint-disable-next-line no-await-in-loop
|
|
4914
|
-
|
|
4967
|
+
const result = await gitUnstagedModifiedFiles(cwd);
|
|
4968
|
+
if (!result.ok) {
|
|
4969
|
+
logger.logger.warn('Unexpected condition: Nothing to commit, skipping PR creation.');
|
|
4970
|
+
continue;
|
|
4971
|
+
}
|
|
4972
|
+
const moddedFilepaths = result.data.filter(p => {
|
|
4915
4973
|
const basename = path.basename(p);
|
|
4916
4974
|
return basename === 'package.json' || basename === 'pnpm-lock.yaml';
|
|
4917
4975
|
});
|
|
@@ -4957,8 +5015,7 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
4957
5015
|
continue infosLoop;
|
|
4958
5016
|
}
|
|
4959
5017
|
// Exit early if install fails.
|
|
4960
|
-
handleInstallFail();
|
|
4961
|
-
return;
|
|
5018
|
+
return handleInstallFail();
|
|
4962
5019
|
}
|
|
4963
5020
|
|
|
4964
5021
|
// eslint-disable-next-line no-await-in-loop
|
|
@@ -5043,11 +5100,14 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
5043
5100
|
lockfileContent = maybeLockfileContent;
|
|
5044
5101
|
} else {
|
|
5045
5102
|
// Exit early if install fails.
|
|
5046
|
-
handleInstallFail();
|
|
5047
|
-
return;
|
|
5103
|
+
return handleInstallFail();
|
|
5048
5104
|
}
|
|
5049
5105
|
}
|
|
5050
|
-
|
|
5106
|
+
return {
|
|
5107
|
+
ok: false,
|
|
5108
|
+
message: 'Update failed',
|
|
5109
|
+
cause: `Update failed for ${oldId} in ${workspace}${error ? '; ' + error : ''}`
|
|
5110
|
+
};
|
|
5051
5111
|
}
|
|
5052
5112
|
if (++count >= limit) {
|
|
5053
5113
|
logger.logger.dedent();
|
|
@@ -5070,6 +5130,12 @@ async function pnpmFix(pkgEnvDetails, {
|
|
|
5070
5130
|
spinner?.dedent();
|
|
5071
5131
|
}
|
|
5072
5132
|
spinner?.stop();
|
|
5133
|
+
return {
|
|
5134
|
+
ok: true,
|
|
5135
|
+
data: {
|
|
5136
|
+
fixed: true
|
|
5137
|
+
}
|
|
5138
|
+
}; // or, did we change anything?
|
|
5073
5139
|
}
|
|
5074
5140
|
|
|
5075
5141
|
const {
|
|
@@ -5085,11 +5151,14 @@ async function runFix({
|
|
|
5085
5151
|
test,
|
|
5086
5152
|
testScript
|
|
5087
5153
|
}) {
|
|
5088
|
-
|
|
5089
|
-
const pkgEnvDetails = await utils.detectAndValidatePackageEnvironment(cwd, {
|
|
5154
|
+
const result = await utils.detectAndValidatePackageEnvironment(cwd, {
|
|
5090
5155
|
cmdName: CMD_NAME$1,
|
|
5091
5156
|
logger: logger.logger
|
|
5092
5157
|
});
|
|
5158
|
+
if (!result.ok) {
|
|
5159
|
+
return result;
|
|
5160
|
+
}
|
|
5161
|
+
const pkgEnvDetails = result.data;
|
|
5093
5162
|
if (!pkgEnvDetails) {
|
|
5094
5163
|
return {
|
|
5095
5164
|
ok: false,
|
|
@@ -5102,8 +5171,7 @@ async function runFix({
|
|
|
5102
5171
|
agent
|
|
5103
5172
|
} = pkgEnvDetails;
|
|
5104
5173
|
if (agent === NPM$8) {
|
|
5105
|
-
|
|
5106
|
-
await npmFix(pkgEnvDetails, {
|
|
5174
|
+
return await npmFix(pkgEnvDetails, {
|
|
5107
5175
|
autoMerge,
|
|
5108
5176
|
cwd,
|
|
5109
5177
|
limit,
|
|
@@ -5113,8 +5181,7 @@ async function runFix({
|
|
|
5113
5181
|
testScript
|
|
5114
5182
|
});
|
|
5115
5183
|
} else if (agent === PNPM$6) {
|
|
5116
|
-
|
|
5117
|
-
await pnpmFix(pkgEnvDetails, {
|
|
5184
|
+
return await pnpmFix(pkgEnvDetails, {
|
|
5118
5185
|
autoMerge,
|
|
5119
5186
|
cwd,
|
|
5120
5187
|
limit,
|
|
@@ -5130,10 +5197,6 @@ async function runFix({
|
|
|
5130
5197
|
cause: `${agent} is not supported by this command at the moment.`
|
|
5131
5198
|
};
|
|
5132
5199
|
}
|
|
5133
|
-
return {
|
|
5134
|
-
ok: true,
|
|
5135
|
-
data: undefined
|
|
5136
|
-
};
|
|
5137
5200
|
}
|
|
5138
5201
|
|
|
5139
5202
|
async function handleFix({
|
|
@@ -5218,10 +5281,14 @@ const config$F = {
|
|
|
5218
5281
|
},
|
|
5219
5282
|
help: (command, config) => `
|
|
5220
5283
|
Usage
|
|
5221
|
-
$ ${command}
|
|
5284
|
+
$ ${command} [options] [CWD=.]
|
|
5222
5285
|
|
|
5223
5286
|
Options
|
|
5224
5287
|
${utils.getFlagListOutput(config.flags, 6)}
|
|
5288
|
+
|
|
5289
|
+
Examples
|
|
5290
|
+
$ ${command}
|
|
5291
|
+
$ ${command} ./proj/tree --autoMerge
|
|
5225
5292
|
`
|
|
5226
5293
|
};
|
|
5227
5294
|
const cmdFix = {
|
|
@@ -5248,7 +5315,6 @@ async function run$F(argv, importMeta, {
|
|
|
5248
5315
|
rangeStyle,
|
|
5249
5316
|
test
|
|
5250
5317
|
} = cli.flags;
|
|
5251
|
-
// TODO: impl json/md further
|
|
5252
5318
|
const outputKind = utils.getOutputKind(json, markdown);
|
|
5253
5319
|
let [cwd = '.'] = cli.input;
|
|
5254
5320
|
// Note: path.resolve vs .join:
|
|
@@ -7950,34 +8016,43 @@ async function updateLockfile(pkgEnvDetails, options) {
|
|
|
7950
8016
|
}
|
|
7951
8017
|
} catch (e) {
|
|
7952
8018
|
spinner?.stop();
|
|
7953
|
-
|
|
7954
|
-
|
|
8019
|
+
debug.debugFn(e);
|
|
8020
|
+
return {
|
|
8021
|
+
ok: false,
|
|
8022
|
+
message: 'Update failed',
|
|
8023
|
+
cause: utils.cmdPrefixMessage(cmdName, `${pkgEnvDetails.agent} install failed to update ${pkgEnvDetails.lockName}`)
|
|
8024
|
+
};
|
|
7955
8025
|
}
|
|
7956
8026
|
if (isSpinning) {
|
|
7957
8027
|
spinner?.start();
|
|
7958
8028
|
} else {
|
|
7959
8029
|
spinner?.stop();
|
|
7960
8030
|
}
|
|
8031
|
+
return {
|
|
8032
|
+
ok: true,
|
|
8033
|
+
data: undefined
|
|
8034
|
+
};
|
|
7961
8035
|
}
|
|
7962
8036
|
|
|
7963
8037
|
const {
|
|
7964
8038
|
VLT
|
|
7965
8039
|
} = constants;
|
|
7966
|
-
function createActionMessage(verb, overrideCount, workspaceCount) {
|
|
7967
|
-
return `${verb} ${overrideCount} Socket.dev optimized ${words.pluralize('override', overrideCount)}${workspaceCount ? ` in ${workspaceCount} ${words.pluralize('workspace', workspaceCount)}` : ''}`;
|
|
7968
|
-
}
|
|
7969
8040
|
async function applyOptimization(cwd, pin, prod) {
|
|
7970
|
-
const
|
|
8041
|
+
const result = await utils.detectAndValidatePackageEnvironment(cwd, {
|
|
7971
8042
|
cmdName: CMD_NAME,
|
|
7972
8043
|
logger: logger.logger,
|
|
7973
8044
|
prod
|
|
7974
8045
|
});
|
|
7975
|
-
if (!
|
|
7976
|
-
return;
|
|
8046
|
+
if (!result.ok) {
|
|
8047
|
+
return result;
|
|
7977
8048
|
}
|
|
8049
|
+
const pkgEnvDetails = result.data;
|
|
7978
8050
|
if (pkgEnvDetails.agent === VLT) {
|
|
7979
|
-
|
|
7980
|
-
|
|
8051
|
+
return {
|
|
8052
|
+
ok: false,
|
|
8053
|
+
message: 'Unsupported',
|
|
8054
|
+
cause: utils.cmdPrefixMessage(CMD_NAME, `${VLT} does not support overrides. Soon, though ⚡`)
|
|
8055
|
+
};
|
|
7981
8056
|
}
|
|
7982
8057
|
|
|
7983
8058
|
// Lazily access constants.spinner.
|
|
@@ -7995,22 +8070,66 @@ async function applyOptimization(cwd, pin, prod) {
|
|
|
7995
8070
|
const updatedCount = state.updated.size;
|
|
7996
8071
|
const pkgJsonChanged = addedCount > 0 || updatedCount > 0;
|
|
7997
8072
|
if (pkgJsonChanged || pkgEnvDetails.features.npmBuggyOverrides) {
|
|
7998
|
-
await updateLockfile(pkgEnvDetails, {
|
|
8073
|
+
const result = await updateLockfile(pkgEnvDetails, {
|
|
7999
8074
|
cmdName: CMD_NAME,
|
|
8000
8075
|
logger: logger.logger,
|
|
8001
8076
|
spinner
|
|
8002
8077
|
});
|
|
8078
|
+
if (!result.ok) {
|
|
8079
|
+
return result;
|
|
8080
|
+
}
|
|
8003
8081
|
}
|
|
8004
8082
|
spinner.stop();
|
|
8005
|
-
|
|
8006
|
-
|
|
8083
|
+
return {
|
|
8084
|
+
ok: true,
|
|
8085
|
+
data: {
|
|
8086
|
+
addedCount,
|
|
8087
|
+
updatedCount,
|
|
8088
|
+
pkgJsonChanged,
|
|
8089
|
+
updatedInWorkspaces: state.updatedInWorkspaces.size,
|
|
8090
|
+
addedInWorkspaces: state.addedInWorkspaces.size
|
|
8091
|
+
}
|
|
8092
|
+
};
|
|
8093
|
+
}
|
|
8094
|
+
|
|
8095
|
+
async function outputOptimizeResult(result, outputKind) {
|
|
8096
|
+
if (!result.ok) {
|
|
8097
|
+
process.exitCode = result.code ?? 1;
|
|
8098
|
+
}
|
|
8099
|
+
if (outputKind === 'json') {
|
|
8100
|
+
logger.logger.log(utils.serializeResultJson(result));
|
|
8101
|
+
return;
|
|
8102
|
+
}
|
|
8103
|
+
if (!result.ok) {
|
|
8104
|
+
logger.logger.fail(utils.failMsgWithBadge(result.message, result.cause));
|
|
8105
|
+
return;
|
|
8106
|
+
}
|
|
8107
|
+
const data = result.data;
|
|
8108
|
+
if (data.updatedCount > 0) {
|
|
8109
|
+
logger.logger?.log(`${createActionMessage('Updated', data.updatedCount, data.updatedInWorkspaces)}${data.addedCount ? '.' : '🚀'}`);
|
|
8007
8110
|
}
|
|
8008
|
-
if (addedCount > 0) {
|
|
8009
|
-
logger.logger?.log(`${createActionMessage('Added', addedCount,
|
|
8111
|
+
if (data.addedCount > 0) {
|
|
8112
|
+
logger.logger?.log(`${createActionMessage('Added', data.addedCount, data.addedInWorkspaces)} 🚀`);
|
|
8010
8113
|
}
|
|
8011
|
-
if (!pkgJsonChanged) {
|
|
8114
|
+
if (!data.pkgJsonChanged) {
|
|
8012
8115
|
logger.logger?.log('Scan complete. No Socket.dev optimized overrides applied.');
|
|
8013
8116
|
}
|
|
8117
|
+
logger.logger.log('');
|
|
8118
|
+
logger.logger.success('Finished!');
|
|
8119
|
+
logger.logger.log('');
|
|
8120
|
+
}
|
|
8121
|
+
function createActionMessage(verb, overrideCount, workspaceCount) {
|
|
8122
|
+
return `${verb} ${overrideCount} Socket.dev optimized ${words.pluralize('override', overrideCount)}${workspaceCount ? ` in ${workspaceCount} ${words.pluralize('workspace', workspaceCount)}` : ''}`;
|
|
8123
|
+
}
|
|
8124
|
+
|
|
8125
|
+
async function handleOptimize({
|
|
8126
|
+
cwd,
|
|
8127
|
+
outputKind,
|
|
8128
|
+
pin,
|
|
8129
|
+
prod
|
|
8130
|
+
}) {
|
|
8131
|
+
const result = await applyOptimization(cwd, pin, prod);
|
|
8132
|
+
await outputOptimizeResult(result, outputKind);
|
|
8014
8133
|
}
|
|
8015
8134
|
|
|
8016
8135
|
const {
|
|
@@ -8035,14 +8154,14 @@ const config$q = {
|
|
|
8035
8154
|
},
|
|
8036
8155
|
help: (command, config) => `
|
|
8037
8156
|
Usage
|
|
8038
|
-
$ ${command}
|
|
8157
|
+
$ ${command} [options] [CWD=.]
|
|
8039
8158
|
|
|
8040
8159
|
Options
|
|
8041
8160
|
${utils.getFlagListOutput(config.flags, 6)}
|
|
8042
8161
|
|
|
8043
8162
|
Examples
|
|
8044
8163
|
$ ${command}
|
|
8045
|
-
$ ${command} --pin
|
|
8164
|
+
$ ${command} ./proj/tree --pin
|
|
8046
8165
|
`
|
|
8047
8166
|
};
|
|
8048
8167
|
const cmdOptimize = {
|
|
@@ -8059,15 +8178,29 @@ async function run$q(argv, importMeta, {
|
|
|
8059
8178
|
importMeta,
|
|
8060
8179
|
parentName
|
|
8061
8180
|
});
|
|
8062
|
-
|
|
8063
|
-
|
|
8064
|
-
|
|
8065
|
-
|
|
8181
|
+
const {
|
|
8182
|
+
json,
|
|
8183
|
+
markdown
|
|
8184
|
+
} = cli.flags;
|
|
8185
|
+
const {
|
|
8186
|
+
pin,
|
|
8187
|
+
prod
|
|
8188
|
+
} = cli.flags;
|
|
8189
|
+
const outputKind = utils.getOutputKind(json, markdown);
|
|
8190
|
+
let [cwd = '.'] = cli.input;
|
|
8191
|
+
// Note: path.resolve vs .join:
|
|
8192
|
+
// If given path is absolute then cwd should not affect it.
|
|
8193
|
+
cwd = path.resolve(process.cwd(), cwd);
|
|
8066
8194
|
if (cli.flags['dryRun']) {
|
|
8067
8195
|
logger.logger.log(DRY_RUN_BAILING_NOW$o);
|
|
8068
8196
|
return;
|
|
8069
8197
|
}
|
|
8070
|
-
await
|
|
8198
|
+
await handleOptimize({
|
|
8199
|
+
cwd,
|
|
8200
|
+
pin: Boolean(pin),
|
|
8201
|
+
outputKind,
|
|
8202
|
+
prod: Boolean(prod)
|
|
8203
|
+
});
|
|
8071
8204
|
}
|
|
8072
8205
|
|
|
8073
8206
|
async function fetchOrganization() {
|
|
@@ -13449,5 +13582,5 @@ void (async () => {
|
|
|
13449
13582
|
await utils.captureException(e);
|
|
13450
13583
|
}
|
|
13451
13584
|
})();
|
|
13452
|
-
//# debugId=
|
|
13585
|
+
//# debugId=2fd0bc0c-3a6c-42d6-8ccd-1745d5682e7e
|
|
13453
13586
|
//# sourceMappingURL=cli.js.map
|