dependabot-npm_and_yarn 0.214.0 → 0.216.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/build +1 -1
  3. data/helpers/lib/yarn/subdependency-updater.js +15 -44
  4. data/helpers/package-lock.json +2584 -1559
  5. data/helpers/package.json +7 -8
  6. data/helpers/test/npm6/conflicting-dependency-parser.test.js +1 -2
  7. data/helpers/test/npm6/fixtures/conflicting-dependency-parser/deeply-nested/package-lock.json +3 -3
  8. data/helpers/test/npm6/updater.test.js +1 -2
  9. data/helpers/test/yarn/conflicting-dependency-parser.test.js +1 -2
  10. data/helpers/test/yarn/fixtures/conflicting-dependency-parser/deeply-nested/yarn.lock +3 -3
  11. data/helpers/test/yarn/updater.test.js +1 -2
  12. data/lib/dependabot/npm_and_yarn/file_fetcher.rb +26 -38
  13. data/lib/dependabot/npm_and_yarn/file_parser/json_lock.rb +86 -0
  14. data/lib/dependabot/npm_and_yarn/file_parser/lockfile_parser.rb +21 -183
  15. data/lib/dependabot/npm_and_yarn/file_parser/yarn_lock.rb +80 -0
  16. data/lib/dependabot/npm_and_yarn/file_parser.rb +23 -36
  17. data/lib/dependabot/npm_and_yarn/file_updater/npm_lockfile_updater.rb +58 -31
  18. data/lib/dependabot/npm_and_yarn/file_updater/yarn_lockfile_updater.rb +43 -16
  19. data/lib/dependabot/npm_and_yarn/file_updater.rb +1 -4
  20. data/lib/dependabot/npm_and_yarn/helpers.rb +17 -4
  21. data/lib/dependabot/npm_and_yarn/native_helpers.rb +15 -2
  22. data/lib/dependabot/npm_and_yarn/update_checker/dependency_files_builder.rb +6 -0
  23. data/lib/dependabot/npm_and_yarn/update_checker/subdependency_version_resolver.rb +5 -4
  24. data/lib/dependabot/npm_and_yarn/update_checker/version_resolver.rb +20 -13
  25. data/lib/dependabot/npm_and_yarn/update_checker.rb +7 -24
  26. data/lib/dependabot/npm_and_yarn/version.rb +13 -2
  27. metadata +37 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f056274186e20cfd09b6ed8bbf84249b6676461533bb76de51ecf4025e189a6
4
- data.tar.gz: 4e30b85987104e3d79fb89d62d51e2dbff8c57337700b6a646633feaae47aadf
3
+ metadata.gz: a8f2067adcff622e13e15f0f69b0af6a37040740153e7259d7a8b10716b21b25
4
+ data.tar.gz: a6d6ec0f7f3575d681d1e55dffe7d02e573d6733e0a4d1ef2ae85c90064dcd04
5
5
  SHA512:
6
- metadata.gz: fa8d78e12bb014909be03e084887d429f9bd2295d69f6cff6df0f9058c4a8e49e19c465470659010917be9c13c7a95a57ad970b2875e0be8fb2b050755b89a84
7
- data.tar.gz: 54d9510b40145d16a62453ef2613503fcc87f336c14bd5a0809c71dfa99242cc91c3722504d87d737af3a0213ecc2383081a129a459124dc2079df91009a4ac9
6
+ metadata.gz: ab002df13a3712244ce2cba0498d92750a84f89316dcd6809d28a793eda2525c073252797104ac7bdf1b4f13e597ca5e75db14a488cc622fd71e3e2892269ef9
7
+ data.tar.gz: e2c83d55d329b47796f02a0c4894f64df7d56c1b1ef0a2e8cdb051419a108031a7f86d0d5c77caaf67d8bbd3c22e3b270bcfde232ed1ad3b40cba36876d679fa
data/helpers/build CHANGED
@@ -22,4 +22,4 @@ cp -r \
22
22
  "$install_dir"
23
23
 
24
24
  cd "$install_dir"
25
- npm ci --no-audit --fetch-timeout=600000 --fetch-retries=5
25
+ npm ci --no-audit --fetch-timeout=600000 --fetch-retries=5 --no-dry-run
@@ -5,7 +5,7 @@ const Config = require("@dependabot/yarn-lib/lib/config").default;
5
5
  const { EventReporter } = require("@dependabot/yarn-lib/lib/reporters");
6
6
  const Lockfile = require("@dependabot/yarn-lib/lib/lockfile").default;
7
7
  const fixDuplicates = require("./fix-duplicates");
8
- const { LightweightAdd, LightweightInstall } = require("./helpers");
8
+ const { LightweightInstall, LOCKFILE_ENTRY_REGEX } = require("./helpers");
9
9
  const { parse } = require("./lockfile-parser");
10
10
  const stringify =
11
11
  require("@dependabot/yarn-lib/lib/lockfile/stringify").default;
@@ -21,43 +21,10 @@ function recoverVersionComments(oldLockfile, newLockfile) {
21
21
  .replace(nodeRegex, () => oldMatch(nodeRegex) || "");
22
22
  }
23
23
 
24
- // Installs exact version and returns lockfile entry
25
- async function getLockfileEntryForUpdate(depName, depVersion) {
26
- const directory = fs.mkdtempSync(`${os.tmpdir()}${path.sep}`);
27
- const readFile = (fileName) =>
28
- fs.readFileSync(path.join(directory, fileName)).toString();
29
-
30
- const flags = {
31
- ignoreScripts: true,
32
- ignoreWorkspaceRootCheck: true,
33
- ignoreEngines: true,
34
- ignorePlatform: true,
35
- };
36
- const reporter = new EventReporter();
37
- const config = new Config(reporter);
38
- await config.init({
39
- cwd: directory,
40
- nonInteractive: true,
41
- enableDefaultRc: true,
42
- extraneousYarnrcFiles: [".yarnrc"],
43
- });
44
-
45
- // Empty lockfile
46
- const lockfile = await Lockfile.fromDirectory(directory, reporter);
47
-
48
- const arg = [`${depName}@${depVersion}`];
49
- await new LightweightAdd(arg, flags, config, reporter, lockfile).init();
50
-
51
- const lockfileObject = await parse(directory);
52
- const noHeader = true;
53
- const enableLockfileVersions = false;
54
- return stringify(lockfileObject, noHeader, enableLockfileVersions);
55
- }
56
-
57
24
  async function updateDependencyFile(
58
25
  directory,
59
26
  lockfileName,
60
- updatedDependency
27
+ dependencies
61
28
  ) {
62
29
  const readFile = (fileName) =>
63
30
  fs.readFileSync(path.join(directory, fileName)).toString();
@@ -76,23 +43,27 @@ async function updateDependencyFile(
76
43
  enableDefaultRc: true,
77
44
  extraneousYarnrcFiles: [".yarnrc"],
78
45
  });
46
+ const noHeader = !Boolean(originalYarnLock.match(/^# THIS IS AN AU/m));
79
47
  config.enableLockfileVersions = Boolean(originalYarnLock.match(/^# yarn v/m));
80
- const depName = updatedDependency && updatedDependency.name;
81
- const depVersion = updatedDependency && updatedDependency.version;
82
48
 
83
49
  // SubDependencyVersionResolver relies on the install finding the latest
84
50
  // version of a sub-dependency that's been removed from the lockfile
85
51
  // YarnLockFileUpdater passes a specific version to be updated
86
- if (depName && depVersion) {
87
- const lockfileEntryForUpdate = await getLockfileEntryForUpdate(
88
- depName,
89
- depVersion
52
+ const lockfileObject = await parse(directory);
53
+ for (const [entry, pkg] of Object.entries(lockfileObject)) {
54
+ const [_, depName] = entry.match(
55
+ LOCKFILE_ENTRY_REGEX
90
56
  );
91
- const lockfileContent = `${originalYarnLock}\n${lockfileEntryForUpdate}`;
57
+ if (dependencies.some(dependency => dependency.name === depName)) {
58
+ delete lockfileObject[entry];
59
+ }
60
+ }
92
61
 
93
- const dedupedYarnLock = fixDuplicates(lockfileContent, depName);
94
- fs.writeFileSync(path.join(directory, lockfileName), dedupedYarnLock);
62
+ let newLockFileContent = await stringify(lockfileObject, noHeader, config.enableLockfileVersions);
63
+ for (const dependency of dependencies) {
64
+ newLockFileContent = fixDuplicates(newLockFileContent, dependency.name);
95
65
  }
66
+ fs.writeFileSync(path.join(directory, lockfileName), newLockFileContent);
96
67
 
97
68
  const lockfile = await Lockfile.fromDirectory(directory, reporter);
98
69
  const install = new LightweightInstall(flags, config, reporter, lockfile);