• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 18680241255

21 Oct 2025 10:03AM UTC coverage: 68.407% (-0.1%) from 68.522%
18680241255

Pull #1529

github

web-flow
Merge 6c92cf30d into 03c8a307b
Pull Request #1529: #1521: Use wiremock for npm repository.

3457 of 5541 branches covered (62.39%)

Branch coverage included in aggregate %.

9045 of 12735 relevant lines covered (71.02%)

3.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.41
cli/src/main/java/com/devonfw/tools/ide/tool/repository/NpmRepository.java
1
package com.devonfw.tools.ide.tool.repository;
2

3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.Set;
6

7
import com.devonfw.tools.ide.context.IdeContext;
8
import com.devonfw.tools.ide.json.JsonMapping;
9
import com.devonfw.tools.ide.npm.NpmJsonObject;
10
import com.devonfw.tools.ide.tool.ToolCommandlet;
11
import com.devonfw.tools.ide.tool.node.NodeBasedCommandlet;
12
import com.devonfw.tools.ide.tool.npm.NpmArtifact;
13
import com.devonfw.tools.ide.version.VersionIdentifier;
14
import com.fasterxml.jackson.core.JsonProcessingException;
15
import com.fasterxml.jackson.databind.ObjectMapper;
16

17
/**
18
 * Implementation of {@link AbstractToolRepository} for node-based artifacts. Actually {@link com.devonfw.tools.ide.tool.npm.Npm npm} was the first famous
19
 * package manager for {@link com.devonfw.tools.ide.tool.node.Node node.js}. Meanwhile, there are others like {@link com.devonfw.tools.ide.tool.yarn.Yarn Yarn}.
20
 * Since the registry is <a href="https://www.npmjs.com/">npmjs.com</a> it is not called node-repository but npm-repository.
21
 */
22
public class NpmRepository extends ArtifactToolRepository<NpmArtifact, NpmArtifactMetadata> {
23

24
  /** The base URL of the npm registry. */
25
  public static final String REGISTRY_URL = "https://registry.npmjs.org/";
26

27
  private static final ObjectMapper MAPPER = JsonMapping.create();
3✔
28

29
  /** The {@link #getId() repository ID}. */
30
  public static final String ID = "npm";
31

32
  /**
33
   * The constructor.
34
   *
35
   * @param context the {@link IdeContext}.
36
   */
37
  public NpmRepository(IdeContext context) {
38
    super(context);
3✔
39
  }
1✔
40

41
  @Override
42
  public String getId() {
43

44
    return ID;
×
45
  }
46

47
  @Override
48
  protected NpmArtifact resolveArtifact(String tool, String edition, VersionIdentifier version, ToolCommandlet toolCommandlet) {
49

50
    if (toolCommandlet instanceof NodeBasedCommandlet nodeBasedCommandlet) {
6!
51
      String name = nodeBasedCommandlet.getPackageName();
3✔
52
      if (version == null) {
2!
53
        version = VersionIdentifier.LATEST;
2✔
54
      }
55
      return new NpmArtifact(name, version.toString());
7✔
56
    }
57
    throw new UnsupportedOperationException("Tool '" + tool + "' is not supported by npm repository.");
×
58
  }
59

60
  @Override
61
  protected List<VersionIdentifier> fetchVersions(NpmArtifact artifact) {
62

63
    String url = getRegistryUrl() + artifact.getName();
6✔
64
    String json = this.context.getFileAccess().download(url);
6✔
65
    try {
66
      NpmJsonObject npmJsonObject = MAPPER.readValue(json, NpmJsonObject.class);
6✔
67
      Set<String> versionSet = npmJsonObject.versions().getVersionMap().keySet();
5✔
68
      List<VersionIdentifier> versions = new ArrayList<>(versionSet.size());
6✔
69
      for (String version : versionSet) {
10✔
70
        versions.add(VersionIdentifier.of(version));
5✔
71
      }
1✔
72
      return versions;
2✔
73
    } catch (JsonProcessingException e) {
×
74
      throw new RuntimeException("Failed to process JSON from " + url, e);
×
75
    }
76
  }
77

78
  /**
79
   * @return the registry URL.
80
   */
81
  public String getRegistryUrl() {
82
    return REGISTRY_URL;
×
83
  }
84

85
  @Override
86
  public NpmArtifactMetadata getMetadata(NpmArtifact artifact, String tool, String edition) {
87

88
    return new NpmArtifactMetadata(artifact, tool, edition);
×
89
  }
90
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc