Source:
public static void ensurePnpm(String baseDir) { if (isPnpmTooOldOrAbsent(baseDir)) { File packageJson = new File(baseDir, "package.json"); File tempFile = null; boolean packageJsonExists = packageJson.canRead(); if (packageJsonExists) { try { tempFile = File.createTempFile("package", "json"); FileUtils.copyFile(packageJson, tempFile); } catch (IOException exception) { throw new IllegalStateException( "Couldn't make a copy of package.json file", exception); } packageJson.delete(); } try { JsonObject pkgJson = Json.createObject(); pkgJson.put("name", "temp"); pkgJson.put("license", "UNLICENSED"); pkgJson.put("repository", "npm/npm"); pkgJson.put("description", "Temporary package for pnpm installation"); FileUtils.writeLines(packageJson, Collections.singletonList(pkgJson.toJson())); JsonObject lockJson = Json.createObject(); lockJson.put("lockfileVersion", 1); FileUtils.writeLines(new File(baseDir, "package-lock.json"), Collections.singletonList(lockJson.toJson())); } catch (IOException e) { getLogger().warn("Couldn't create temporary package.json"); } LoggerFactory.getLogger("dev-updater").info( "Installing pnpm v{} locally. It is suggested to install it globally using 'npm add -g pnpm@{}'", DEFAULT_PNPM_VERSION, DEFAULT_PNPM_VERSION); installPnpm(baseDir, getNpmExecutable(baseDir, false)); new File(baseDir, "package-lock.json").delete(); if (packageJsonExists && tempFile != null) { try { FileUtils.copyFile(tempFile, packageJson); } catch (IOException exception) { throw new IllegalStateException( "Couldn't restore package.json file back", exception); } tempFile.delete(); } else { packageJson.delete(); } } }

Target:
public static void ensurePnpm(String baseDir) { if (isPnpmTooOldOrAbsent(baseDir)) { File packageJson = new File(baseDir, "package.json"); File tempFile = null; boolean packageJsonExists = packageJson.canRead(); if (packageJsonExists) { try { tempFile = File.createTempFile("package", "json"); FileUtils.copyFile(packageJson, tempFile); } catch (IOException exception) { throw new IllegalStateException( "Couldn't make a copy of package.json file", exception); } packageJson.delete(); } try { JsonObject pkgJson = Json.createObject(); pkgJson.put("name", "temp"); pkgJson.put("license", "UNLICENSED"); pkgJson.put("repository", "npm/npm"); pkgJson.put("description", "Temporary package for pnpm installation"); FileUtils.writeLines(packageJson, Collections.singletonList(pkgJson.toJson())); JsonObject lockJson = Json.createObject(); lockJson.put("lockfileVersion", 1); FileUtils.writeLines(new File(baseDir, "package-lock.json"), Collections.singletonList(lockJson.toJson())); } catch (IOException e) { getLogger().warn("Couldn't create temporary package.json"); } LoggerFactory.getLogger("dev-updater").info( "Installing pnpm v{} locally. It is suggested to install it globally using 'npm add -g pnpm@{}'", DEFAULT_PNPM_VERSION, DEFAULT_PNPM_VERSION); installPnpm(baseDir, getNpmExecutable(baseDir, false)); new File(baseDir, "package-lock.json").delete(); if (packageJsonExists && tempFile != null) { try { FileUtils.copyFile(tempFile, packageJson); } catch (IOException exception) { throw new IllegalStateException( "Couldn't restore package.json file back", exception); } tempFile.delete(); } } }