Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary imports added in 7.9.4 #25739

Closed
mraible opened this issue Apr 4, 2024 · 6 comments · Fixed by jhipster/generator-jhipster-migrate#6
Closed

Unnecessary imports added in 7.9.4 #25739

mraible opened this issue Apr 4, 2024 · 6 comments · Fixed by jhipster/generator-jhipster-migrate#6

Comments

@mraible
Copy link
Contributor

mraible commented Apr 4, 2024

Overview of the issue

I upgraded my 21-Points Health application using jhipster-migrate --verbose and specifying 7.9.4 as the target version. However, this adds a bunch of unnecessary imports.

In SearchRepositories:

import org.springframework.scheduling.annotation.Async;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

In Resources:

import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

In ResourceITs:

import java.util.Collections;
import org.springframework.data.domain.PageRequest;
Motivation for or Use Case

Unused imports should not be added to classes.

Reproduce the error

Upgrade a 7.9.3 app to 7.9.4 and you'll see the errors.

Related issues

mraible/21-points#248

JHipster Version(s)
[email protected] /Users/mraible/dev/21-points
├─┬ [email protected]
│ └── [email protected] deduped
└── [email protected]

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "applicationType": "monolith",
    "authenticationType": "jwt",
    "baseName": "TwentyOnePoints",
    "blueprints": [],
    "buildTool": "gradle",
    "cacheProvider": "ehcache",
    "clientFramework": "angularX",
    "clientPackageManager": "npm",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "creationTimestamp": 1662997089611,
    "cypressAudit": false,
    "cypressCoverage": false,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "devServerPort": 4200,
    "dtoSuffix": "DTO",
    "enableGradleEnterprise": false,
    "enableHibernateCache": true,
    "enableSwaggerCodegen": false,
    "enableTranslation": true,
    "entities": ["Points", "Weight", "BloodPressure", "Preferences"],
    "entitySuffix": "",
    "herokuAppName": "health-by-points",
    "herokuDeployType": "git",
    "herokuJavaVersion": "11",
    "jhiPrefix": "jhi",
    "jhipsterVersion": "7.9.4",
    "jwtSecretKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
    "languages": ["en", "fr"],
    "lastLiquibaseTimestamp": 1667866821000,
    "messageBroker": false,
    "microfrontend": false,
    "microfrontends": [],
    "nativeLanguage": "en",
    "otherModules": [],
    "packageName": "org.jhipster.health",
    "pages": [],
    "prodDatabaseType": "postgresql",
    "reactive": false,
    "searchEngine": "elasticsearch",
    "serverPort": "8080",
    "serverSideOptions": ["searchEngine:elasticsearch"],
    "serviceDiscoveryType": "no",
    "skipCheckLengthOfIdentifier": false,
    "skipClient": false,
    "skipFakeData": false,
    "skipUserManagement": false,
    "testFrameworks": ["cypress"],
    "websocket": false,
    "withAdminUi": true
  }
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity Points {
  date LocalDate required
  exercise Integer
  meals Integer
  alcohol Integer
  notes String maxlength(140)
}
entity Weight {
  timestamp ZonedDateTime required
  weight Double required
}
entity BloodPressure {
  timestamp ZonedDateTime required
  systolic Integer required
  diastolic Integer required
}
entity Preferences {
  weeklyGoal Integer required min(10) max(21)
  weightUnits Units required
}
enum Units {
  KG,
  LB
}

relationship OneToOne {
  Preferences{user(login)} to User
}
relationship ManyToOne {
  Points{user(login)} to User
  Weight{user(login)} to User
  BloodPressure{user(login)} to User
}

paginate Points with pagination
paginate Weight, BloodPressure with infinite-scroll

Environment and Tools

openjdk version "21.0.2" 2024-01-16
OpenJDK Runtime Environment GraalVM CE 21.0.2+13.1 (build 21.0.2+13-jvmci-23.1-b30)
OpenJDK 64-Bit Server VM GraalVM CE 21.0.2+13.1 (build 21.0.2+13-jvmci-23.1-b30, mixed mode, sharing)

git version 2.39.3 (Apple Git-146)

node: v16.20.2

npm: 8.19.4

Docker version 25.0.3, build 4debf41

Docker Compose version v2.24.6-desktop.1

@mraible
Copy link
Contributor Author

mraible commented Apr 4, 2024

I'll update this issue after upgrading to 8.2.1 or close it if it's no longer valid.

@mshima
Copy link
Member

mshima commented Apr 4, 2024

This is a jhipster-migrate issue.

@mraible
Copy link
Contributor Author

mraible commented Apr 4, 2024

I finished a first pass at upgrading to JHipster 8.2.1 today. First, I upgraded to 7.9.4 and everything works. Then, I upgraded to 8.2.1.

The v8 upgrade is still in progress. First, there's an error when running npm test. This seems to be caused by ng2-charts, but I'm not sure how to fix.

FAIL src/main/webapp/app/home/home.component.spec.ts
  ● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

    Details:

    /Users/mraible/dev/21-points/node_modules/lodash-es/lodash.js:10
    export { default as add } from './add.js';
    ^^^^^^

    SyntaxError: Unexpected token 'export'

      16 | import { IWeight, IWeightByPeriod } from '../entities/weight/weight.model';
      17 |
    > 18 | import { BaseChartDirective } from 'ng2-charts';
         | ^
      19 | import { ChartConfiguration, ChartOptions } from 'chart.js';
      20 | import dayjs from 'dayjs/esm';
      21 |

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
      at Object.<anonymous> (node_modules/ng2-charts/fesm2022/ng2-charts.mjs:4:23)
      at Object.require (src/main/webapp/app/home/home.component.ts:18:1)
      at Object.<anonymous> (src/main/webapp/app/home/home.component.spec.ts:11:1)

Other issues:

  1. On startup, the browser hangs. In Chrome, it isn't easy to open developer tools because it consumes so much memory. Once it's open, you can see a continuous loop of navigation errors.
  2. I'm not certain the search security logic is correct (filtering by user.login when not admin). I'm not able to test it because of the first issue.

@mraible
Copy link
Contributor Author

mraible commented Apr 4, 2024

I was able to fix the home.component.spec.ts by adding lodash-es to transformIgnorePatterns in jest.conf.js. mraible/21-points@ef3dc78

@mraible
Copy link
Contributor Author

mraible commented Apr 4, 2024

Safari allows me to see what the error is in its JavaScript console.

Screenshot 2024-04-04 at 4 06 28 PM

@mraible
Copy link
Contributor Author

mraible commented Apr 5, 2024

Closing this issue as it doesn't seem to be a problem with 8.2.1. I'll continue fixes in mraible/21-points#249.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants