dependabot-npm_and_yarn 0.366.0 → 0.367.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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/.prettierignore +2 -0
  3. data/helpers/.prettierrc.json +3 -0
  4. data/helpers/README.md +57 -9
  5. data/helpers/build +4 -1
  6. data/helpers/eslint.config.js +29 -19
  7. data/helpers/jest.config.js +7 -0
  8. data/helpers/lib/npm/conflicting-dependency-parser.ts +94 -0
  9. data/helpers/lib/npm/index.ts +7 -0
  10. data/helpers/lib/npm/vulnerability-auditor.ts +437 -0
  11. data/helpers/lib/npm6/helpers.ts +25 -0
  12. data/helpers/lib/npm6/index.ts +4 -0
  13. data/helpers/lib/npm6/{peer-dependency-checker.js → peer-dependency-checker.ts} +26 -18
  14. data/helpers/lib/npm6/remove-dependencies-from-lockfile.ts +28 -0
  15. data/helpers/lib/npm6/{subdependency-updater.js → subdependency-updater.ts} +21 -14
  16. data/helpers/lib/npm6/types.ts +17 -0
  17. data/helpers/lib/pnpm/index.ts +3 -0
  18. data/helpers/lib/pnpm/lockfile-parser.ts +116 -0
  19. data/helpers/lib/yarn/{conflicting-dependency-parser.js → conflicting-dependency-parser.ts} +67 -27
  20. data/helpers/lib/yarn/{fix-duplicates.js → fix-duplicates.ts} +38 -19
  21. data/helpers/lib/yarn/{helpers.js → helpers.ts} +28 -12
  22. data/helpers/lib/yarn/index.ts +13 -0
  23. data/helpers/lib/yarn/lockfile-parser.ts +28 -0
  24. data/helpers/lib/yarn/{peer-dependency-checker.js → peer-dependency-checker.ts} +41 -25
  25. data/helpers/lib/yarn/{replace-lockfile-declaration.js → replace-lockfile-declaration.ts} +26 -19
  26. data/helpers/lib/yarn/{subdependency-updater.js → subdependency-updater.ts} +42 -25
  27. data/helpers/lib/yarn/{updater.js → updater.ts} +60 -43
  28. data/helpers/package-lock.json +1491 -89
  29. data/helpers/package.json +19 -6
  30. data/helpers/run.ts +53 -0
  31. data/helpers/test/npm/helpers.ts +19 -0
  32. data/helpers/test/npm/{vulnerability-auditor.test.js → vulnerability-auditor.test.ts} +34 -41
  33. data/helpers/test/npm6/{conflicting-dependency-parser.test.js → conflicting-dependency-parser.test.ts} +6 -8
  34. data/helpers/test/npm6/helpers.ts +19 -0
  35. data/helpers/test/pnpm/lockfile-parser.test.ts +58 -0
  36. data/helpers/test/yarn/{conflicting-dependency-parser.test.js → conflicting-dependency-parser.test.ts} +7 -9
  37. data/helpers/test/yarn/helpers.ts +16 -0
  38. data/helpers/test/yarn/{updater.test.js → updater.test.ts} +26 -26
  39. data/helpers/tsconfig.build.json +5 -0
  40. data/helpers/tsconfig.json +17 -0
  41. data/lib/dependabot/npm_and_yarn/dependency_grapher.rb +5 -5
  42. data/lib/dependabot/npm_and_yarn/file_updater/package_json_updater.rb +75 -6
  43. data/lib/dependabot/npm_and_yarn/file_updater.rb +23 -2
  44. data/lib/dependabot/npm_and_yarn/native_helpers.rb +1 -1
  45. data/lib/dependabot/npm_and_yarn/update_checker.rb +31 -11
  46. metadata +37 -37
  47. data/helpers/lib/npm/conflicting-dependency-parser.js +0 -78
  48. data/helpers/lib/npm/index.js +0 -9
  49. data/helpers/lib/npm/vulnerability-auditor.js +0 -335
  50. data/helpers/lib/npm6/helpers.js +0 -25
  51. data/helpers/lib/npm6/index.js +0 -9
  52. data/helpers/lib/npm6/remove-dependencies-from-lockfile.js +0 -22
  53. data/helpers/lib/npm6/updater.js +0 -198
  54. data/helpers/lib/pnpm/index.js +0 -5
  55. data/helpers/lib/pnpm/lockfile-parser.js +0 -82
  56. data/helpers/lib/yarn/index.js +0 -14
  57. data/helpers/lib/yarn/lockfile-parser.js +0 -21
  58. data/helpers/run.js +0 -30
  59. data/helpers/test/npm/helpers.js +0 -21
  60. data/helpers/test/npm6/fixtures/updater/original/package-lock.json +0 -16
  61. data/helpers/test/npm6/fixtures/updater/original/package.json +0 -9
  62. data/helpers/test/npm6/fixtures/updater/updated/package-lock.json +0 -16
  63. data/helpers/test/npm6/helpers.js +0 -21
  64. data/helpers/test/npm6/updater.test.js +0 -30
  65. data/helpers/test/pnpm/lockfile-parser.test.js +0 -62
  66. data/helpers/test/yarn/helpers.js +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b0212799f2a2fa21c0bc9be370dbfb944652e9a34711e846e22608a05561060
4
- data.tar.gz: 6a71485492ddf512478859078e298df9c5bf4e58826fe3098867504786c02242
3
+ metadata.gz: bd642987850077bbb8f9db021a67d28d12aa0d0274f8a544fee343a94b1305cf
4
+ data.tar.gz: 6cac0fa8ba502e9add46b664963d05f1014244aaf682958dc9f0788b60684077
5
5
  SHA512:
6
- metadata.gz: 43e6578bbc6940db3460dd2fe91751a1d986cde35fc648de8f408079da32fe94bd074c889fdfac65d7dda40f8575bbcb219681f8449a157226e98b8a96d2905c
7
- data.tar.gz: 3798ea8bee4eb841638f9f3a5ceaeaab4603f5635c2387a02bff98cd35c3eb1a6434225dd2dc89c5c0abf1ed59640e257ec6a8cbbd75b15af0874120fe977ff6
6
+ metadata.gz: 328b4b756719e6865bc4a3f2b5f180b69505827b6ce06764e8c3c8a266b56367bc034cbfca1f1ea916fb53700b21aff58f130f3ccd4795bdd8ab500dda767c0c
7
+ data.tar.gz: 45857c428d9744dc94744674ebe2951f92f4e07f914c4ad8c7e5dd67fe649e0864e246bb96a6203d443e0d96cdf9ca44f64a902d72bb1d7b32977155501c51e8
@@ -0,0 +1,2 @@
1
+ dist/
2
+ test/pnpm/fixtures/**/pnpm-lock.yaml
@@ -0,0 +1,3 @@
1
+ {
2
+ "trailingComma": "es5"
3
+ }
data/helpers/README.md CHANGED
@@ -1,22 +1,70 @@
1
- Native JavaScript helpers
2
- -------------------------
1
+ ## Native TypeScript helpers
3
2
 
4
- This directory contains helper functions for npm and yarn, natively written in
5
- Javascript so that we can utilize the package managers internal APIs and other
3
+ This directory contains helper functions for npm, yarn, and pnpm, written in
4
+ TypeScript, so that we can utilize the package managers' internal APIs and other
6
5
  native tooling for these ecosystems.
7
6
 
8
- These helpers are called from the Ruby code via `run.js`, they are passed
7
+ These helpers are called from the Ruby code via `run.ts`, they are passed
9
8
  arguments via stdin and return JSON data to stdout.
10
9
 
11
- ## Testing
10
+ ## Development
11
+
12
+ Install dependencies:
13
+
14
+ ```
15
+ npm install
16
+ ```
17
+
18
+ ### Building
19
+
20
+ The helpers are compiled from TypeScript to JavaScript before being used at
21
+ runtime. To build:
22
+
23
+ ```
24
+ npm run build
25
+ ```
26
+
27
+ The compiled output goes to `dist/`.
28
+
29
+ ### Type checking
30
+
31
+ Run the TypeScript compiler in check-only mode (no output):
32
+
33
+ ```
34
+ npm run typecheck
35
+ ```
36
+
37
+ ### Linting
38
+
39
+ ESLint is used for code quality checks:
40
+
41
+ ```
42
+ npm run lint
43
+ ```
44
+
45
+ ### Formatting
46
+
47
+ Prettier is used for code formatting. To check for formatting issues:
48
+
49
+ ```
50
+ npm run format
51
+ ```
52
+
53
+ To auto-fix formatting:
54
+
55
+ ```
56
+ npm run format:fix
57
+ ```
58
+
59
+ ### Testing
12
60
 
13
61
  When working on these helpers, it's convenient to write some high level tests in
14
- JavaScript to make it easier to debug the code.
62
+ TypeScript to make it easier to debug the code.
15
63
 
16
- You can now run the tests from this directory by running:
64
+ Run the tests from this directory:
17
65
 
18
66
  ```
19
- yarn test path/to/test.js
67
+ npm test
20
68
  ```
21
69
 
22
70
  ### Debugging
data/helpers/build CHANGED
@@ -14,7 +14,9 @@ helpers_dir="$(dirname "${BASH_SOURCE[0]}")"
14
14
  cp -r \
15
15
  "$helpers_dir/lib" \
16
16
  "$helpers_dir/test" \
17
- "$helpers_dir/run.js" \
17
+ "$helpers_dir/run.ts" \
18
+ "$helpers_dir/tsconfig.json" \
19
+ "$helpers_dir/tsconfig.build.json" \
18
20
  "$helpers_dir/eslint.config.js" \
19
21
  "$helpers_dir/jest.config.js" \
20
22
  "$helpers_dir/package.json" \
@@ -24,3 +26,4 @@ cp -r \
24
26
 
25
27
  cd "$install_dir"
26
28
  npm ci --fetch-timeout=600000 --fetch-retries=5
29
+ npm run build
@@ -1,27 +1,37 @@
1
1
  const globals = require("globals");
2
2
  const { defineConfig } = require("eslint/config");
3
3
  const js = require("@eslint/js");
4
+ const tseslint = require("typescript-eslint");
4
5
  const eslintConfigPrettier = require("eslint-config-prettier/flat");
5
6
 
6
- // Rules not included before upgrading to ESLint 9. Can be enabled later
7
- const temporaryDisabledRules = {
7
+ module.exports = defineConfig([
8
+ js.configs.recommended,
9
+ tseslint.configs.recommended,
10
+ {
11
+ languageOptions: {
12
+ globals: {
13
+ ...globals.node,
14
+ ...globals.jest,
15
+ },
16
+ },
17
+ },
18
+ {
8
19
  rules: {
9
- "no-unused-vars": "off",
10
- "no-extra-boolean-cast": "off",
11
- "no-undef": "off"
20
+ "@typescript-eslint/no-unused-vars": [
21
+ "error",
22
+ { argsIgnorePattern: "^_", destructuredArrayIgnorePattern: "^_" },
23
+ ],
24
+ "@typescript-eslint/consistent-type-imports": "error",
12
25
  },
13
- }
14
-
15
- module.exports = defineConfig([
16
- js.configs.recommended,
17
- {
18
- languageOptions: {
19
- globals: {
20
- ...globals.node,
21
- ...globals.jest
22
- }
23
- },
26
+ },
27
+ eslintConfigPrettier,
28
+ {
29
+ files: ["**/*.js"],
30
+ rules: {
31
+ "@typescript-eslint/no-require-imports": "off",
24
32
  },
25
- temporaryDisabledRules,
26
- eslintConfigPrettier
27
- ])
33
+ },
34
+ {
35
+ ignores: ["dist/**"],
36
+ },
37
+ ]);
@@ -2,4 +2,11 @@ module.exports = {
2
2
  verbose: true,
3
3
  rootDir: "test",
4
4
  testEnvironment: "node",
5
+ transform: {
6
+ "^.+\\.ts$": "ts-jest",
7
+ },
8
+ moduleFileExtensions: ["ts", "js", "json"],
9
+ moduleNameMapper: {
10
+ "^(\\.{1,2}/.*)\\.js$": "$1",
11
+ },
5
12
  };
@@ -0,0 +1,94 @@
1
+ /* Conflicting dependency parser for npm
2
+ *
3
+ * Inputs:
4
+ * - directory containing a package.json and a yarn.lock
5
+ * - dependency name
6
+ * - target dependency version
7
+ *
8
+ * Outputs:
9
+ * - An array of objects with conflicting dependencies
10
+ */
11
+
12
+ import Arborist from "@npmcli/arborist";
13
+ import semver from "semver";
14
+
15
+ interface ConflictingDependency {
16
+ explanation: string;
17
+ name: string;
18
+ version: string;
19
+ requirement: string;
20
+ }
21
+
22
+ export async function findConflictingDependencies(
23
+ directory: string,
24
+ depName: string,
25
+ targetVersion: string
26
+ ): Promise<ConflictingDependency[]> {
27
+ const arb = new Arborist({
28
+ path: directory,
29
+ dryRun: true,
30
+ ignoreScripts: true,
31
+ });
32
+
33
+ return await arb.loadVirtual().then((tree) => {
34
+ const parents: ConflictingDependency[] = [];
35
+ for (const node of tree.inventory.query("name", depName)) {
36
+ for (const edge of node.edgesIn) {
37
+ if (!semver.satisfies(targetVersion, edge.spec)) {
38
+ findTopLevelEdges(edge).forEach((topLevel) => {
39
+ const explanation = buildExplanation(node, edge, topLevel);
40
+
41
+ parents.push({
42
+ explanation: explanation,
43
+ name: edge.from!.name,
44
+ version: edge.from!.version,
45
+ requirement: edge.spec,
46
+ });
47
+ });
48
+ }
49
+ }
50
+ }
51
+
52
+ return parents;
53
+ });
54
+ }
55
+
56
+ function buildExplanation(
57
+ node: Arborist.Node,
58
+ directEdge: Arborist.Edge,
59
+ topLevelEdge: Arborist.Edge
60
+ ): string {
61
+ if (directEdge.from === topLevelEdge.to) {
62
+ // The nodes parent is top-level
63
+ return `${directEdge.from!.name}@${directEdge.from!.version} requires ${directEdge.to!.name}@${directEdge.spec}`;
64
+ } else if (topLevelEdge.to!.edgesOut.has(directEdge.from!.name)) {
65
+ // The nodes parent is a direct dependency of the top-level dependency
66
+ return (
67
+ `${topLevelEdge.to!.name}@${topLevelEdge.to!.version} requires ${directEdge.to!.name}@${directEdge.spec} ` +
68
+ `via ${directEdge.from!.name}@${directEdge.from!.version}`
69
+ );
70
+ } else {
71
+ // The nodes parent is a transitive dependency of the top-level dependency
72
+ return (
73
+ `${topLevelEdge.to!.name}@${topLevelEdge.to!.version} requires ${directEdge.to!.name}@${directEdge.spec} ` +
74
+ `via a transitive dependency on ${directEdge.from!.name}@${directEdge.from!.version}`
75
+ );
76
+ }
77
+ }
78
+
79
+ function findTopLevelEdges(
80
+ edge: Arborist.Edge,
81
+ parents: Arborist.Edge[] = []
82
+ ): Arborist.Edge[] {
83
+ edge.from!.edgesIn.forEach((parent) => {
84
+ if (parent.from!.edgesIn.size === 0) {
85
+ if (!parents.includes(parent)) {
86
+ parents.push(parent);
87
+ }
88
+ } else {
89
+ findTopLevelEdges(parent, parents);
90
+ }
91
+ });
92
+
93
+ return parents;
94
+ }
@@ -0,0 +1,7 @@
1
+ import { findConflictingDependencies } from "./conflicting-dependency-parser.js";
2
+ import { findVulnerableDependencies } from "./vulnerability-auditor.js";
3
+
4
+ export {
5
+ findConflictingDependencies,
6
+ findVulnerableDependencies as vulnerabilityAuditor,
7
+ };