snyk 1.1135.0 → 1.1137.0

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.
@@ -153984,6 +153984,7 @@ const dep_graph_1 = __webpack_require__(53789);
153984
153984
  const util_1 = __webpack_require__(46200);
153985
153985
  const errors_1 = __webpack_require__(1706);
153986
153986
  const parsers_1 = __webpack_require__(75873);
153987
+ const semver = __webpack_require__(50460);
153987
153988
  const micromatch = __webpack_require__(65465);
153988
153989
  const pathUtil = __webpack_require__(85622);
153989
153990
  const parseNpmLockV2Project = (pkgJsonContent, pkgLockContent, options) => {
@@ -154057,7 +154058,7 @@ const dfsVisit = (depGraphBuilder, node, visitedMap, npmLockPkgs, strictOutOfSyn
154057
154058
  }
154058
154059
  };
154059
154060
  const getChildNode = (name, depInfo, pkgs, strictOutOfSync, includeDevDeps, includeOptionalDeps, ancestry, pkgKeysByName) => {
154060
- let childNodeKey = (0, exports.getChildNodeKey)(name, ancestry, pkgs, pkgKeysByName); //
154061
+ let childNodeKey = (0, exports.getChildNodeKey)(name, depInfo.version, ancestry, pkgs, pkgKeysByName);
154061
154062
  if (!childNodeKey) {
154062
154063
  if (strictOutOfSync) {
154063
154064
  throw new errors_1.OutOfSyncError(`${name}@${depInfo.version}`, parsers_1.LockfileType.npm);
@@ -154106,55 +154107,62 @@ const getChildNode = (name, depInfo, pkgs, strictOutOfSync, includeDevDeps, incl
154106
154107
  key: childNodeKey,
154107
154108
  };
154108
154109
  };
154109
- const getChildNodeKey = (name, ancestry, pkgs, pkgKeysByName) => {
154110
+ const getChildNodeKey = (name, version, ancestry, pkgs, pkgKeysByName) => {
154111
+ // This is a list of all our possible options for the childKey
154110
154112
  const candidateKeys = pkgKeysByName.get(name);
154111
154113
  // Lockfile missing entry
154112
154114
  if (!candidateKeys) {
154113
154115
  return undefined;
154114
154116
  }
154115
- // Only one candidate then just take it
154117
+ // If we only have one candidate then we just take it
154116
154118
  if (candidateKeys.length === 1) {
154117
154119
  return candidateKeys[0];
154118
154120
  }
154119
- // If we are a bundled dep we have to choose candidate carefully
154120
- if (ancestry.length && ancestry[ancestry.length - 1].inBundle) {
154121
- const bundleRootIdx = ancestry.findIndex((el) => el.inBundle === true) - 1;
154122
- const ancestryFromBundleId = [
154123
- ...ancestry.slice(bundleRootIdx).map((el) => el.name),
154124
- name,
154125
- ];
154126
- const candidateAncestries = candidateKeys.map((el) => el.replace('node_modules/', '').split('/node_modules/'));
154127
- const filteredCandidates = candidateKeys.filter((candidate, idx) => {
154128
- return candidateAncestries[idx].every((pkg) => {
154129
- return ancestryFromBundleId.includes(pkg);
154130
- });
154121
+ // If we are bundled we assume we are scoped by the bundle root at least
154122
+ // otherwise the ancestry root is the root ignoring the true root
154123
+ const isBundled = ancestry[ancestry.length - 1].inBundle;
154124
+ const rootOperatingIdx = isBundled
154125
+ ? ancestry.findIndex((el) => el.inBundle === true) - 1
154126
+ : 1;
154127
+ const ancestryFromRootOperatingIdx = [
154128
+ ...ancestry.slice(rootOperatingIdx).map((el) => el.name),
154129
+ name,
154130
+ ];
154131
+ // We filter on a number of cases
154132
+ let filteredCandidates = candidateKeys.filter((candidate) => {
154133
+ // This is splitting the candidate that looks like
154134
+ // `node_modules/a/node_modules/b` into ["a", "b"]
154135
+ // To do this we remove the first node_modules substring
154136
+ // and then split on the rest
154137
+ const candidateAncestry = candidate
154138
+ .replace('node_modules/', '')
154139
+ .split('/node_modules/');
154140
+ // Check the ancestry of the candidate is a subset of
154141
+ // the current pkg. If it is not then it can't be a
154142
+ // valid key.
154143
+ const isCandidateAncestryIsSubsetOfPkgAncestry = candidateAncestry.every((pkg) => {
154144
+ return ancestryFromRootOperatingIdx.includes(pkg);
154131
154145
  });
154132
- if (filteredCandidates.length === 1) {
154133
- return filteredCandidates[0];
154134
- }
154135
- const sortedKeys = filteredCandidates.sort((a, b) => b.split('/node_modules/').length - a.split('/node_modules/').length);
154136
- const longestPathLength = sortedKeys[0].split('/node_modules/').length;
154137
- const onlyLongestKeys = sortedKeys.filter((key) => key.split('/node_modules/').length === longestPathLength);
154138
- if (onlyLongestKeys.length === 1) {
154139
- return onlyLongestKeys[0];
154140
- }
154141
- // Here we go through parents keys to see if any are the branch point
154142
- // we could have done this sooner but the above work as good short circuits
154143
- let keysFilteredByParentKey = onlyLongestKeys;
154144
- const reversedAncestry = ancestry.reverse();
154145
- for (let parentIndex = 0; parentIndex < reversedAncestry.length; parentIndex++) {
154146
- const parentKey = reversedAncestry[parentIndex].key;
154147
- const possibleFilteredKeys = keysFilteredByParentKey.filter((key) => key.includes(parentKey));
154148
- if (possibleFilteredKeys.length === 1) {
154149
- return possibleFilteredKeys[0];
154150
- }
154151
- if (possibleFilteredKeys.length === 0) {
154152
- continue;
154146
+ if (isCandidateAncestryIsSubsetOfPkgAncestry === false) {
154147
+ return false;
154148
+ }
154149
+ // If we are bundled we assume the bundle root is the first value
154150
+ // in the candidates scoping
154151
+ if (isBundled) {
154152
+ const doesBundledPkgShareBundleRoot = candidateAncestry[0] === ancestryFromRootOperatingIdx[0];
154153
+ if (doesBundledPkgShareBundleRoot === false) {
154154
+ return false;
154153
154155
  }
154154
- keysFilteredByParentKey = possibleFilteredKeys;
154155
154156
  }
154157
+ // So now we can check semver to filter out some values
154158
+ const candidatePkgVersion = pkgs[candidate].version;
154159
+ const doesVersionSatisfySemver = semver.satisfies(candidatePkgVersion, version);
154160
+ return doesVersionSatisfySemver;
154161
+ });
154162
+ if (filteredCandidates.length === 1) {
154163
+ return filteredCandidates[0];
154156
154164
  }
154157
- let ancestry_names = ancestry.map((el) => el.name).concat(name);
154165
+ const ancestry_names = ancestry.map((el) => el.name).concat(name);
154158
154166
  while (ancestry_names.length > 0) {
154159
154167
  const possible_key = `node_modules/${ancestry_names.join('/node_modules/')}`;
154160
154168
  if (pkgs[possible_key]) {
@@ -154162,16 +154170,19 @@ const getChildNodeKey = (name, ancestry, pkgs, pkgKeysByName) => {
154162
154170
  }
154163
154171
  ancestry_names.shift();
154164
154172
  }
154165
- // This is similar to fetching permutations in the isBundle logic
154166
- ancestry_names = ancestry.map((el) => el.name).concat(name);
154167
- const candidateAncestries = candidateKeys.map((el) => el.replace('node_modules/', '').split('/node_modules/'));
154168
- const filteredCandidates = candidateKeys.filter((candidate, idx) => {
154169
- return candidateAncestries[idx].every((pkg) => {
154170
- return ancestry_names.includes(pkg);
154171
- });
154172
- });
154173
- if (filteredCandidates.length === 1) {
154174
- return filteredCandidates[0];
154173
+ // Here we go through th eancestry backwards to find the nearest
154174
+ // ancestor package
154175
+ const reversedAncestry = ancestry.reverse();
154176
+ for (let parentIndex = 0; parentIndex < reversedAncestry.length; parentIndex++) {
154177
+ const parentKey = reversedAncestry[parentIndex].key;
154178
+ const possibleFilteredKeys = filteredCandidates.filter((key) => key.includes(parentKey));
154179
+ if (possibleFilteredKeys.length === 1) {
154180
+ return possibleFilteredKeys[0];
154181
+ }
154182
+ if (possibleFilteredKeys.length === 0) {
154183
+ continue;
154184
+ }
154185
+ filteredCandidates = possibleFilteredKeys;
154175
154186
  }
154176
154187
  return undefined;
154177
154188
  };