Search in sources :

Example 6 with YarnLock

use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock in project synopsys-detect by blackducksoftware.

the class YarnTransformerTest method buildTestYarnLockResult.

@NotNull
private YarnLockResult buildTestYarnLockResult(List<NameVersion> workspacesThatAreDependencies, List<NameVersion> workspacesThatAreNotDependencies, boolean yarn1project) {
    PackageJson rawPackageJson = new PackageJson();
    rawPackageJson.dependencies = new HashMap<>();
    rawPackageJson.dependencies.put("foo", "fooFuzzyVersion-1.0");
    for (NameVersion workspace : workspacesThatAreDependencies) {
        rawPackageJson.dependencies.put(workspace.getName(), workspace.getVersion());
    }
    rawPackageJson.devDependencies.put("bar", "barFuzzyVersion-1.0");
    NullSafePackageJson packageJson = new NullSafePackageJson(rawPackageJson);
    // yarn.lock: foo and bar both depend on yarn
    List<YarnLockEntryId> yarnLockEntryIdsFoo = Collections.singletonList(new YarnLockEntryId("foo", "fooFuzzyVersion-1.0"));
    List<YarnLockEntryId> yarnLockEntryIdsBar = Collections.singletonList(new YarnLockEntryId("bar", "barFuzzyVersion-1.0"));
    List<YarnLockEntryId> yarnLockEntryIdsYarn = Collections.singletonList(new YarnLockEntryId("yarn", "^1.22.4"));
    List<YarnLockDependency> dependencyRefToYarn = Collections.singletonList(new YarnLockDependency("yarn", "^1.22.4", false));
    List<YarnLockEntry> yarnLockEntries = new LinkedList<>();
    if (!yarn1project) {
        List<YarnLockEntryId> projectEntryIds = Collections.singletonList(new YarnLockEntryId("project", "1.0.0"));
        List<YarnLockDependency> projectDependencies = new LinkedList<>();
        projectDependencies.add(new YarnLockDependency("foo", "fooFuzzyVersion-1.0", false));
        projectDependencies.add(new YarnLockDependency("bar", "barFuzzyVersion-1.0", false));
        for (NameVersion workspaceThatIsDependency : workspacesThatAreDependencies) {
            projectDependencies.add(new YarnLockDependency(workspaceThatIsDependency.getName(), workspaceThatIsDependency.getVersion(), false));
        }
        yarnLockEntries.add(new YarnLockEntry(false, projectEntryIds, "1.0.0", projectDependencies));
    }
    Collection<YarnWorkspace> workspacesByName = new LinkedList<>();
    List<NameVersion> allWorkspaces = new LinkedList<>(workspacesThatAreDependencies);
    allWorkspaces.addAll(workspacesThatAreNotDependencies);
    for (NameVersion workspace : allWorkspaces) {
        String workspaceDepName = workspace.getName() + WORKSPACE_DEP_SUFFIX;
        String workspaceDevDepName = workspace.getName() + "-dev" + WORKSPACE_DEP_SUFFIX;
        addWorkspacePackageJson(workspacesByName, workspace, workspaceDepName, workspaceDevDepName);
        if (!yarn1project) {
            addWorkspaceToYarnLockEntries(yarnLockEntries, workspace, workspaceDepName);
        }
        addDependencyOfWorkspaceToYarnLockEntries(yarnLockEntries, workspace, workspaceDepName);
        addDependencyOfWorkspaceToYarnLockEntries(yarnLockEntries, workspace, workspaceDevDepName);
    }
    yarnLockEntries.add(new YarnLockEntry(false, yarnLockEntryIdsFoo, "1.0", dependencyRefToYarn));
    yarnLockEntries.add(new YarnLockEntry(false, yarnLockEntryIdsBar, "1.0", dependencyRefToYarn));
    yarnLockEntries.add(new YarnLockEntry(false, yarnLockEntryIdsYarn, "1.22.5", new LinkedList<>()));
    String yarnLockVersion = null;
    if (!yarn1project) {
        yarnLockVersion = "4";
    }
    YarnLock yarnLock = new YarnLock(yarnLockVersion, yarn1project, yarnLockEntries);
    YarnWorkspaces workspaceData = new YarnWorkspaces(workspacesByName);
    return new YarnLockResult(packageJson, workspaceData, yarnLock);
}
Also used : NameVersion(com.synopsys.integration.util.NameVersion) NullSafePackageJson(com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson) LinkedList(java.util.LinkedList) YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) YarnLockResult(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockResult) YarnLockEntryId(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId) YarnLockEntry(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry) YarnLockDependency(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency) YarnWorkspaces(com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspaces) NullSafePackageJson(com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson) WorkspacePackageJson(com.synopsys.integration.detectable.detectables.yarn.packagejson.WorkspacePackageJson) PackageJson(com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson) YarnWorkspace(com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspace) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with YarnLock

use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock in project synopsys-detect by blackducksoftware.

the class YarnLockParserTest method testThatYarnLockVersionsResolveAsExpected.

@Test
void testThatYarnLockVersionsResolveAsExpected() {
    List<String> yarnLockText = new ArrayList<>();
    yarnLockText.add("http-proxy@^1.8.1:");
    yarnLockText.add("  version \"1.16.2\"");
    yarnLockText.add("  resolved \"http://nexus.fr.murex.com/nexus3/repository/npm-all/http-proxy/-/http-proxy-1.16.2.tgz#06dff292952bf64dbe8471fa9df73066d4f37742\"");
    yarnLockText.add("  dependencies:");
    yarnLockText.add("    eventemitter3 \"1.x.x\"");
    yarnLockText.add("    requires-port \"1.x.x\"");
    yarnLockText.add("http-server@^0.9.0:");
    yarnLockText.add("  version \"0.9.0\"");
    yarnLockText.add("  resolved \"http://nexus.fr.murex.com/nexus3/repository/npm-all/http-server/-/http-server-0.9.0.tgz#8f1b06bdc733618d4dc42831c7ba1aff4e06001a\"");
    YarnLockParser yarnLockParser = createYarnLockParser();
    YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockText);
    assertEntry(yarnLock, "http-proxy", "^1.8.1", "1.16.2", new YarnLockDependency("eventemitter3", "1.x.x", false), new YarnLockDependency("requires-port", "1.x.x", false));
    assertEntry(yarnLock, "http-server", "^0.9.0", "0.9.0");
}
Also used : YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) YarnLockParser(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser) ArrayList(java.util.ArrayList) YarnLockDependency(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 8 with YarnLock

use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock in project synopsys-detect by blackducksoftware.

the class YarnLockParserTest method testThatDependenciesWithQuotesAreResolvedCorrectly.

@Test
void testThatDependenciesWithQuotesAreResolvedCorrectly() {
    List<String> yarnLockText = new ArrayList<>();
    yarnLockText.add("\"cssstyle@>= 0.2.37 < 0.3.0\":");
    yarnLockText.add("  version \"0.2.37\"");
    yarnLockText.add("  resolved \"http://nexus/nexus3/repository/npm-all/cssstyle/-/cssstyle-0.2.37.tgz#541097234cb2513c83ceed3acddc27ff27987d54\"");
    yarnLockText.add("  dependencies:");
    yarnLockText.add("    cssom \"0.3.x\"");
    YarnLockParser yarnLockParser = createYarnLockParser();
    YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockText);
    assertEntry(yarnLock, "cssstyle", ">= 0.2.37 < 0.3.0", "0.2.37", new YarnLockDependency("cssom", "0.3.x", false));
}
Also used : YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) YarnLockParser(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser) ArrayList(java.util.ArrayList) YarnLockDependency(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 9 with YarnLock

use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock in project synopsys-detect by blackducksoftware.

the class YarnLockParserTest method testThatYarnLockPeerNotAdded.

@Test
void testThatYarnLockPeerNotAdded() {
    List<String> yarnLockText = Arrays.asList("any-root-dep@1:", // must have a version to create an entry
    "  version: 1", "  peerDependencies:", "    some-peer: ^10.0.0", "  peerDependenciesMeta:", "    some-peer:", "      optional: true");
    YarnLockParser yarnLockParser = createYarnLockParser();
    YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockText);
    Assertions.assertEquals(1, yarnLock.getEntries().size());
    YarnLockEntry first = yarnLock.getEntries().get(0);
    Assertions.assertEquals(0, first.getDependencies().size());
}
Also used : YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) YarnLockEntry(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry) YarnLockParser(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 10 with YarnLock

use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock in project synopsys-detect by blackducksoftware.

the class YarnLockParserTest method testThatMultipleDepsPerLineCanBeHandledCorrectly.

@Test
void testThatMultipleDepsPerLineCanBeHandledCorrectly() {
    List<String> yarnLockText = new ArrayList<>();
    yarnLockText.add("debug@2, debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@~2.6.4, debug@~2.6.6:");
    yarnLockText.add("  version \"2.6.9\"");
    yarnLockText.add("  resolved \"http://nexus/nexus3/repository/npm-all/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f\"");
    yarnLockText.add("  dependencies:");
    yarnLockText.add("    ms \"2.0.0\"");
    YarnLockParser yarnLockParser = createYarnLockParser();
    YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockText);
    assertEntry(yarnLock, "debug", "2", "2.6.9", new YarnLockDependency("ms", "2.0.0", false));
    assertEntry(yarnLock, "debug", "2.6.9", "2.6.9", new YarnLockDependency("ms", "2.0.0", false));
    assertEntry(yarnLock, "debug", "^2.2.0", "2.6.9", new YarnLockDependency("ms", "2.0.0", false));
    assertEntry(yarnLock, "debug", "^2.3.3", "2.6.9", new YarnLockDependency("ms", "2.0.0", false));
    assertEntry(yarnLock, "debug", "~2.6.4", "2.6.9", new YarnLockDependency("ms", "2.0.0", false));
    assertEntry(yarnLock, "debug", "~2.6.6", "2.6.9", new YarnLockDependency("ms", "2.0.0", false));
}
Also used : YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) YarnLockParser(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser) ArrayList(java.util.ArrayList) YarnLockDependency(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Aggregations

YarnLock (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock)14 Test (org.junit.jupiter.api.Test)12 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)11 YarnLockParser (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser)11 YarnLockDependency (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency)10 YarnLockEntry (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry)6 ArrayList (java.util.ArrayList)6 NullSafePackageJson (com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson)3 PackageJson (com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson)2 WorkspacePackageJson (com.synopsys.integration.detectable.detectables.yarn.packagejson.WorkspacePackageJson)2 YarnLockResult (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockResult)2 YarnLockEntryId (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId)2 YarnWorkspaces (com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspaces)2 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 YarnLockLineAnalyzer (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockLineAnalyzer)1 YarnLockEntryParser (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryParser)1 YarnLockDependencySpecParser (com.synopsys.integration.detectable.detectables.yarn.parse.entry.section.YarnLockDependencySpecParser)1 YarnLockEntrySectionParserSet (com.synopsys.integration.detectable.detectables.yarn.parse.entry.section.YarnLockEntrySectionParserSet)1