FrontendTools { public String forceAlternativeNodeExecutable() { Pair<String, String> nodeCommands = getNodeCommands(); String dir = getAlternativeDir(); File file = new File(dir, nodeCommands.getSecond()); if (file.exists()) { if (!frontendToolsLocator.verifyTool(file)) { throw new IllegalStateException( String.format(LOCAL_NODE_NOT_FOUND, dir, dir, file.getAbsolutePath())); } return file.getAbsolutePath(); } else { getLogger().info("Node not found in {}. Installing node {}.", dir, nodeVersion); return installNode(nodeVersion, nodeDownloadRoot); } } FrontendTools(String baseDir,
            Supplier<String> alternativeDirGetter);  FrontendTools(String baseDir,
                         Supplier<String> alternativeDirGetter,
                         String nodeVersion,
                         URI nodeDownloadRoot);   FrontendTools(String baseDir, Supplier<String> alternativeDirGetter,
            String nodeVersion, URI nodeDownloadRoot,
            boolean ignoreVersionChecks); String getNodeExecutable(); String forceAlternativeNodeExecutable(); List<String> getNpmExecutable(); List<String> getPnpmExecutable(); void ensurePnpm(); void validateNodeAndNpmVersion(); static final String DEFAULT_NODE_VERSION; static final String DEFAULT_PNPM_VERSION; static final String INSTALL_NODE_LOCALLY; static final int SUPPORTED_PNPM_MAJOR_VERSION; static final int SUPPORTED_PNPM_MINOR_VERSION; }
@Test public void installNodeFromFileSystem_ForceAlternativeNodeExecutableInstallsToTargetDirectory() throws Exception{ Assert.assertFalse("npm should not yet be present", new File(vaadinHomeDir, "node/node_modules/npm/bin/npm") .exists()); tools = new FrontendTools(baseDir, () -> vaadinHomeDir, "v12.10.0", new File(baseDir).toURI()); prepareNodeDownloadableZipAt(baseDir, "v12.10.0"); tools.forceAlternativeNodeExecutable(); Assert.assertTrue("npm should have been copied to node_modules", new File(vaadinHomeDir, "node/node_modules/npm/bin/npm") .exists()); }
@Test(expected = IllegalStateException.class) public void ensureNodeExecutableInHome_vaadinHomeNodeIsAFolder_throws() throws IOException { File node = new File(vaadinHomeDir, FrontendUtils.isWindows() ? "node/node.exe" : "node/node"); FileUtils.forceMkdir(node); tools.forceAlternativeNodeExecutable(); }