Repository: jhipster/jhipster-lite
Pull request #9899 (2024-05-24 20:04:38)

feat: generate clients with a .npmrc config for forcing saving exact versions of npm dependencies
This is already in place for the generator, and this enforces a good practice


Patch:
diff --git a/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactory.java
index d46b3996c..7b776ea45 100644
--- a/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactory.java
+++ b/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactory.java
@@ -1,7 +1,7 @@
 package tech.jhipster.lite.generator.client.angular.core.domain;
 
 import static tech.jhipster.lite.module.domain.JHipsterModule.*;
-import static tech.jhipster.lite.module.domain.packagejson.VersionSource.*;
+import static tech.jhipster.lite.module.domain.packagejson.VersionSource.ANGULAR;
 
 import tech.jhipster.lite.generator.client.common.domain.ClientsModulesFactory;
 import tech.jhipster.lite.module.domain.Indentation;
@@ -14,7 +14,7 @@ public class AngularModuleFactory {
 
   private static final JHipsterSource SOURCE = from("client/angular/core");
 
-  private static final JHipsterSource COMMON_ESLINT = from("client/common/eslint");
+  private static final JHipsterSource COMMON = from("client/common");
 
   private static final String ENGINES_NEEDLE = "  \"engines\":";
   private static final PackageName ANGULAR_CORE_PACKAGE = packageName("@angular/core");
@@ -75,7 +75,10 @@ public class AngularModuleFactory {
         .add(SOURCE.file("tsconfig.json"), to("tsconfig.json"))
         .add(SOURCE.file("tsconfig.app.json"), to("tsconfig.app.json"))
         .add(SOURCE.file(".eslintrc.json"), to(".eslintrc.json"))
-        .add(COMMON_ESLINT.file(".eslintignore"), to(".eslintignore"))
+        .batch(COMMON, to("."))
+          .addFile(".eslintignore")
+          .addFile(".npmrc")
+          .and()
         .batch(SOURCE, to("."))
           .addTemplate("proxy.conf.json")
           .addTemplate("jest.conf.js")
diff --git a/src/main/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactory.java b/src/main/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactory.java
index b14061e5f..8694ea02c 100644
--- a/src/main/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactory.java
+++ b/src/main/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactory.java
@@ -14,7 +14,7 @@ public class ReactCoreModulesFactory {
   private static final JHipsterSource SOURCE = from("client/react");
 
   private static final JHipsterSource WEBAPP_SOURCE = SOURCE.append("src/main/webapp");
-  private static final JHipsterSource COMMON_ESLINT = from("client/common/eslint");
+  private static final JHipsterSource COMMON = from("client/common");
   private static final JHipsterDestination WEBAPP_DESTINATION = to("src/main/webapp");
 
   private static final JHipsterSource APP_SOURCE = WEBAPP_SOURCE.append("app");
@@ -67,8 +67,9 @@ public class ReactCoreModulesFactory {
           .addTemplate("vitest.config.ts")
           .addFile(".eslintrc.cjs")
           .and()
-        .batch(COMMON_ESLINT, to("."))
+        .batch(COMMON, to("."))
           .addFile(".eslintignore")
+          .addFile(".npmrc")
           .and()
         .batch(APP_SOURCE, APP_DESTINATION)
           .addTemplate("index.css")
diff --git a/src/main/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteModuleFactory.java
index 971ef30a4..7e296c18d 100644
--- a/src/main/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteModuleFactory.java
+++ b/src/main/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteModuleFactory.java
@@ -1,8 +1,8 @@
 package tech.jhipster.lite.generator.client.svelte.core.domain;
 
-import static tech.jhipster.lite.generator.client.common.domain.ClientsModulesFactory.*;
+import static tech.jhipster.lite.generator.client.common.domain.ClientsModulesFactory.clientModuleBuilder;
 import static tech.jhipster.lite.module.domain.JHipsterModule.*;
-import static tech.jhipster.lite.module.domain.packagejson.VersionSource.*;
+import static tech.jhipster.lite.module.domain.packagejson.VersionSource.SVELTE;
 
 import tech.jhipster.lite.module.domain.Indentation;
 import tech.jhipster.lite.module.domain.JHipsterModule;
@@ -19,7 +19,7 @@ public class SvelteModuleFactory {
 
   private static final JHipsterSource PRIMARY_MAIN_SOURCE = SOURCE.append("src/main/webapp/app/common/primary/app");
   private static final JHipsterDestination PRIMARY_MAIN_DESTINATION = to("src/main/webapp/app/common/primary/app");
-  private static final JHipsterSource COMMON_ESLINT = from("client/common/eslint");
+  private static final JHipsterSource COMMON = from("client/common");
 
   private static final JHipsterSource PRIMARY_TEST_SOURCE = SOURCE.append("src/test/spec/common/primary/app");
   private static final JHipsterDestination PRIMARY_TEST_DESTINATION = to("src/test/javascript/spec/common/primary/app");
@@ -85,7 +85,10 @@ public class SvelteModuleFactory {
         .add(SOURCE.append("src/main/webapp/routes").template("+page.svelte"), to("src/main/webapp/routes/+page.svelte"))
         .add(PRIMARY_MAIN_SOURCE.template("App.svelte"), PRIMARY_MAIN_DESTINATION.append("App.svelte"))
         .add(PRIMARY_TEST_SOURCE.template("App.spec.ts"), PRIMARY_TEST_DESTINATION.append("App.spec.ts"))
-        .add(COMMON_ESLINT.file(".eslintignore"), to(".eslintignore"))
+        .batch(COMMON, to("."))
+          .addFile(".eslintignore")
+          .addFile(".npmrc")
+          .and()
         .move(path(".lintstagedrc.js"), to(".lintstagedrc.cjs"))
         .batch(SOURCE, to("."))
           .addTemplate("svelte.config.js")
diff --git a/src/main/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactory.java b/src/main/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactory.java
index 79f3febb0..63b271273 100644
--- a/src/main/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactory.java
+++ b/src/main/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactory.java
@@ -18,7 +18,7 @@ public class VueModulesFactory {
   private static final JHipsterSource IMAGE_SOURCE = SOURCE.append("webapp/content/images");
   private static final JHipsterSource COMMON_PRIMARY_SOURCE = SOURCE.append("webapp/app/common/primary");
   private static final JHipsterSource COMMON_PRIMARY_TEST_SOURCE = SOURCE.append("test/spec/common/primary");
-  private static final JHipsterSource COMMON_ESLINT = from("client/common/eslint");
+  private static final JHipsterSource COMMON = from("client/common");
 
   private static final JHipsterDestination MAIN_DESTINATION = to("src/main/webapp/app");
   private static final JHipsterDestination TEST_DESTINATION = to("src/test/javascript/spec");
@@ -81,7 +81,10 @@ public class VueModulesFactory {
           .addTemplate("vite.config.mts")
           .addTemplate("vitest.config.mts")
           .and()
-        .add(COMMON_ESLINT.file(".eslintignore"), to(".eslintignore"))
+        .batch(COMMON, to("."))
+          .addFile(".eslintignore")
+          .addFile(".npmrc")
+          .and()
         .batch(SOURCE.file("test/spec/http"), to("src/test/javascript/spec/http"))
           .addTemplate("AxiosHttp.spec.ts")
           .addTemplate("AxiosHttpStub.ts")
diff --git a/src/main/resources/generator/client/common/eslint/.eslintignore b/src/main/resources/generator/client/common/.eslintignore
similarity index 100%
rename from src/main/resources/generator/client/common/eslint/.eslintignore
rename to src/main/resources/generator/client/common/.eslintignore
diff --git a/src/main/resources/generator/client/common/.npmrc b/src/main/resources/generator/client/common/.npmrc
new file mode 100644
index 000000000..cffe8cdef
--- /dev/null
+++ b/src/main/resources/generator/client/common/.npmrc
@@ -0,0 +1,1 @@
+save-exact=true


Test patch:
diff --git a/src/test/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactoryTest.java
index 341eacf6a..943f8a334 100644
--- a/src/test/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactoryTest.java
+++ b/src/test/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactoryTest.java
@@ -81,6 +81,7 @@ class AngularModuleFactoryTest {
         "tsconfig.app.json",
         "tsconfig.spec.json",
         "proxy.conf.json",
+        ".npmrc",
         ".eslintignore",
         ".eslintrc.json"
       )
diff --git a/src/test/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactoryTest.java
index 8da9471ec..9231f2c0e 100644
--- a/src/test/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactoryTest.java
+++ b/src/test/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactoryTest.java
@@ -59,7 +59,7 @@ class ReactCoreModulesFactoryTest {
         """
       )
       .and()
-      .hasFiles("tsconfig.json", "vite.config.ts", "vitest.config.ts", ".eslintignore", ".eslintrc.cjs")
+      .hasFiles("tsconfig.json", "vite.config.ts", "vitest.config.ts", ".npmrc", ".eslintignore", ".eslintrc.cjs")
       .hasFiles("src/main/webapp/index.html")
       .hasPrefixedFiles("src/main/webapp/app", "index.css", "index.tsx", "vite-env.d.ts")
       .hasFiles("src/test/javascript/spec/common/primary/app/App.spec.tsx")
diff --git a/src/test/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteModuleFactoryTest.java
index 7ed52d881..54ed17f42 100644
--- a/src/test/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteModuleFactoryTest.java
+++ b/src/test/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteModuleFactoryTest.java
@@ -66,7 +66,7 @@ class SvelteModuleFactoryTest {
         .containing(nodeScript("test:watch", "vitest --"))
         .containing("\"type\": \"module\"")
         .and()
-      .hasFiles(".eslintignore", ".eslintrc.cjs", "tsconfig.json", "svelte.config.js", "vite.config.js", "vitest.config.ts")
+      .hasFiles(".eslintignore", ".eslintrc.cjs", ".npmrc", "tsconfig.json", "svelte.config.js", "vite.config.js", "vitest.config.ts")
       .hasPrefixedFiles("src/main/webapp", "app.html", "app.d.ts")
       .hasPrefixedFiles("src/main/webapp/routes", "+page.svelte")
       .hasPrefixedFiles("src/test/javascript/spec/common/primary/app", "App.spec.ts")
diff --git a/src/test/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactoryTest.java
index 61ee593ae..03db397e3 100644
--- a/src/test/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactoryTest.java
+++ b/src/test/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactoryTest.java
@@ -65,7 +65,7 @@ class VueModulesFactoryTest {
             """
         )
       .and()
-      .hasPrefixedFiles("", ".eslintignore", ".eslintrc.js", "tsconfig.json", "tsconfig.build.json", "vite.config.mts", "vitest.config.mts")
+      .hasPrefixedFiles("", ".eslintignore", ".npmrc", ".eslintrc.js", "tsconfig.json", "tsconfig.build.json", "vite.config.mts", "vitest.config.mts")
       .hasFiles("src/main/webapp/app/http/AxiosHttp.ts")
       .hasPrefixedFiles("src/test/javascript/spec/http", "AxiosHttp.spec.ts", "AxiosHttpStub.ts", "AxiosStub.ts")
       .hasFiles("src/main/webapp/index.html")