Skip to content

Commit 14ad213

Browse files
author
Johannes Eriksson
committed
fix: Slow npm warning when no package-lock (#13047)
Log an additional warning when package-lock.json is missing. Fixes #12825.
1 parent 94728d3 commit 14ad213

5 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎flow-server/src/main/java/com/vaadin/flow/server/Constants.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ public final class Constants implements Serializable {
237237
*/
238238
public static final String PACKAGE_JSON = "package.json";
239239

240+
/**
241+
* Name of the <code>npm</code> version locking ile.
242+
*/
243+
244+
public static final String PACKAGE_LOCK_JSON = "package-lock.json";
245+
240246
/**
241247
* Target folder constant.
242248
*/

‎flow-server/src/main/java/com/vaadin/flow/server/frontend/NodeUpdater.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
import static com.vaadin.flow.server.Constants.COMPATIBILITY_RESOURCES_FRONTEND_DEFAULT;
5353
import static com.vaadin.flow.server.Constants.PACKAGE_JSON;
54+
import static com.vaadin.flow.server.Constants.PACKAGE_LOCK_JSON;
5455
import static com.vaadin.flow.server.Constants.RESOURCES_FRONTEND_DEFAULT;
5556
import static com.vaadin.flow.server.frontend.FrontendUtils.FLOW_NPM_PACKAGE_NAME;
5657
import static com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES;
@@ -168,10 +169,14 @@ protected NodeUpdater(ClassFinder finder,
168169
this.featureFlags = featureFlags;
169170
}
170171

171-
private File getPackageJsonFile() {
172+
protected File getPackageJsonFile() {
172173
return new File(npmFolder, PACKAGE_JSON);
173174
}
174175

176+
protected File getPackageLockFile() {
177+
return new File(npmFolder, PACKAGE_LOCK_JSON);
178+
}
179+
175180
/**
176181
* Gets the platform pinned versions that are not overridden by the user in
177182
* package.json.

‎flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskRunNpmInstall.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,19 @@ public class TaskRunNpmInstall implements FallibleCommand {
144144
public void execute() throws ExecutionFailedException {
145145
String toolName = enablePnpm ? "pnpm" : "npm";
146146
if (packageUpdater.modified || shouldRunNpmInstall()) {
147+
// Log a stronger request for patience if package-lock.json is
148+
// missing as "npm install" in this case can take minutes
149+
// https://github.com/vaadin/flow/issues/12825
150+
File packageLockFile = packageUpdater.getPackageLockFile();
147151
packageUpdater.log().info("Running `" + toolName + " install` to "
148152
+ "resolve and optionally download frontend dependencies. "
149153
+ "This may take a moment, please stand by...");
154+
if (!enablePnpm && !packageLockFile.exists()) {
155+
packageUpdater.log().warn("Missing package-lock.json may cause "
156+
+ "npm package installation to take several minutes; "
157+
+ "it is recommended to keep this file persistently "
158+
+ "in your project");
159+
}
150160
runNpmInstall();
151161

152162
updateLocalHash();

‎flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskUpdateImports.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.vaadin.experimental.FeatureFlags;
3737
import com.vaadin.flow.component.dependency.JsModule;
3838
import com.vaadin.flow.function.SerializableFunction;
39+
import com.vaadin.flow.server.Constants;
3940
import com.vaadin.flow.server.frontend.scanner.ClassFinder;
4041
import com.vaadin.flow.server.frontend.scanner.CssData;
4142
import com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner;
@@ -493,7 +494,8 @@ private JsonObject makeCssJson(CssData data) {
493494
}
494495

495496
private String getAbsentPackagesMessage() {
496-
String lockFile = enablePnpm ? "pnpm-lock.yaml" : "package-lock.json";
497+
String lockFile = enablePnpm ? "pnpm-lock.yaml"
498+
: Constants.PACKAGE_LOCK_JSON;
497499
String command = enablePnpm ? "pnpm" : "npm";
498500
String note = "";
499501
if (enablePnpm) {

‎flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskUpdatePackages.java‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,6 @@ private JsonObject getPackageLockDependencies() throws IOException {
497497
return dependencies;
498498
}
499499

500-
private File getPackageLockFile() {
501-
return new File(npmFolder, "package-lock.json");
502-
}
503-
504500
private String getShrinkWrapVersion(JsonObject packageJson) {
505501
if (packageJson == null) {
506502
return null;

0 commit comments

Comments
 (0)