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

Use npm instead of Yarn #3173

Merged
merged 16 commits into from
Sep 6, 2024
Merged

Use npm instead of Yarn #3173

merged 16 commits into from
Sep 6, 2024

Conversation

alanorth
Copy link
Contributor

@alanorth alanorth commented Jul 8, 2024

References

Description

Simplify the project by using npm (which ships with Node.js) instead of Yarn (an extra global dependency and prerequisite).

The original reasons for using Yarn (dependency install speed and robust lockfiles) are no longer as compelling. In the past few years npm has improved in both of these areas. Furthermore, we are using Yarn 1.x "classic", which has been deprecated for several years and migration to Yarn 2, which is not backwards compatible, will require us to do some work anyway.

Instructions for Reviewers

Please add a more detailed description of the changes made by your PR. At a minimum, providing a bulleted list of changes in your PR is helpful to reviewers.

List of changes in this PR:

  • Remove yarn.lock
  • Update package.json to use npm run for all scripts
  • Add package-lock.json
  • Update several dependencies to fix lint errors
  • Update Dockerfiles to use npm
  • Update README.md with new instructions for npm

Include guidance for how to test or review your PR.

Try installing dependencies and building the application in dev and production mode:

$ rm -rf node_modules && npm install
$ npm run build
$ npm start

Checklist

This checklist provides a reminder of what we are going to look for when reviewing your PR. You need not complete this checklist prior to creating your PR (draft PRs are always welcome).
However, reviewers may request that you complete any actions in this list if you have not done so. If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!

  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes ESLint validation using npm run lint
  • My PR doesn't introduce circular dependencies (verified via npm run check-circ-deps)
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • My PR aligns with Accessibility guidelines if it makes changes to the user interface.
  • My PR uses i18n (internationalization) keys instead of hardcoded English text, to allow for translations.
  • My PR includes details on how to test it. I've provided clear instructions to reviewers on how to successfully test this fix or feature.
  • If my PR includes new libraries/dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR includes new features or configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

@alanorth alanorth added improvement dependencies Pull requests that update a dependency file needs documentation PR is missing documentation. All new features and config changes require documentation. labels Jul 8, 2024
@alanorth alanorth requested a review from artlowel July 8, 2024 12:40
@tdonohue tdonohue requested review from atarix83 and tdonohue July 9, 2024 14:19
@tdonohue
Copy link
Member

Thanks for this work @alanorth ! I can see we'll need to do more work here to update other areas where yarn is used (namely the GitHub Actions, Docker scripts & README). But, this looks like a good start!

I've linked this over to the 9.0 brainstorms we've started gathering for Steering to discuss. I see this as a task which can help with the "Easier Installation" idea (by removing a prerequisite in yarn).

@artlowel and @atarix83 : I added you both as reviewers here as I'd appreciate your feedback on this idea. I'd be willing to help @alanorth to get the GitHub Actions / Docker scripts updated, assuming we all agree with the goal of removing usage of yarn in favor of npm. So, please let me know if you have immediate objections/concerns.

@pnbecker
Copy link
Member

I like this idea a lot.

Copy link
Member

@artlowel artlowel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alanorth!

I agree, getting rid of yarn 1 is a good idea.

This PR does seem to break our lint step (On github you see the yarn version, but I get the same issue running lint with npm). Since it won't compile, perhaps eslint resolves to a different version now?

You can get rid of the resolutions section in package.json, it's something unique to yarn, to force to use a certain version of a dependency when there are conflicts. Since the project builds fine, it looks like these particular resolutions are no longer necessary anyway.

I do think we should add the npm equivalent, which is called overrides, and solve any conflict we have with peerDependencies in there, rather than instructing people to run npm install with --legacy-peer-deps

We'll also need to update the github workflows to use npm instead of yarn, as well as the Dockerfile

@alanorth
Copy link
Contributor Author

alanorth commented Aug 29, 2024

Thanks @artlowel!

This PR does seem to break our lint step (On github you see the yarn version, but I get the same issue running lint with npm). Since it won't compile, perhaps eslint resolves to a different version now?

Oh I'm not sure, that needs more investigation. Appreciate any advice.

You can get rid of the resolutions section in package.json, it's something unique to yarn, to force to use a certain version of a dependency when their are conflicts. Since the project builds fine, it looks like these particular resolutions are no longer necessary anyway.

Done, thanks.

I do think we should add the npm equivalent, which is called overrides, and solve any conflict we have with peerDependencies in there, rather than instructing people to run npm install with --legacy-peer-deps

Oh that is nice to know. I have worked through the conflicting dependencies and added overrides for each. Now we can install with npm install!

We'll also need to update the github workflows to use npm instead of yarn, as well as the Dockerfile

Ah yes, true. Should be easy. I will take a look soon.

Copy link

Hi @alanorth,
Conflicts have been detected against the base branch.
Please resolve these conflicts as soon as you can. Thanks!

Copy link

github-actions bot commented Sep 3, 2024

Hi @alanorth,
Conflicts have been detected against the base branch.
Please resolve these conflicts as soon as you can. Thanks!

@kshepherd
Copy link
Member

kshepherd commented Sep 4, 2024

@alanorth I fixed the lint errors with an update to the unused-imports plugin (this was causing the problem, not the spec test itself) - "eslint-plugin-unused-imports": "^4.1.3", does it, though note that the documentation says 4.x.x is for eslint 9, eslint-plugins 8-5 (we are behind this right?), so I think to be sure we should review all the eslint versions and see what we can update?

doc:
https://www.npmjs.com/package/eslint-plugin-unused-imports

Copy link

github-actions bot commented Sep 4, 2024

Hi @alanorth,
Conflicts have been detected against the base branch.
Please resolve these conflicts as soon as you can. Thanks!

Instead of using the Yarn link protocol, we can use npm's built-in
support for local dependencies using "file:".
@alanorth
Copy link
Contributor Author

alanorth commented Sep 5, 2024

Thanks @kshepherd! You're right, the eslint-plugin-unused-imports say this:

  • Version 4.1.x is for eslint 9 with @typescript-eslint/eslint-plugin v8 to v5
  • Version 3.x.x is for eslint 8 with @typescript-eslint/eslint-plugin 6 - 7
  • Version 2.x.x is for eslint 8 with @typescript-eslint/eslint-plugin 5

We are using 2.x.x currently, but according to this we should be using 3.x.x. It fixes the lint error, though I'm not sure why we don't hit that issue with yarn. 🤔

All scripts should use "npm run" instead of "yarn".
Now that we are using npm we need to commit this.
These are a yarn-specific concept that we don't need for npm.
Add overrides for conflicting peer dependencies. In yarn these were
handled less noisily, but in npm we need to add explicit overrides
for each. This allows us to use `npm install` without forcing or
using `--legacy-peer-deps`.
@alanorth alanorth force-pushed the use-npm branch 4 times, most recently from 7610a49 to d9be88d Compare September 5, 2024 10:14
@alanorth alanorth requested a review from artlowel September 5, 2024 10:15
Copy link
Member

@artlowel artlowel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alanorth!

This is looking good to me now, I have one more minor inline comment.

It would be good if someone with more experience with Docker could give those changes a more thorough test though

.github/workflows/build.yml Outdated Show resolved Hide resolved
Use npm instead of yarn in GitHub Actions.
Fix error in lint:

> lint/src/util/structure.ts:16:20 - error TS2314: Generic type 'RuleMetaData<MessageIds, Options>' requires 2 type argument(s).
>
> 16 export type Meta = RuleMetaData<string>;
Fix lint error. According to the docs we should be using v3.x.x:

> * Version 3.x.x is for eslint 8 with @typescript-eslint/eslint-plugin 6 - 7
> * Version 2.x.x is for eslint 8 with @typescript-eslint/eslint-plugin 5

See: https://www.npmjs.com/package/eslint-plugin-unused-imports
There is a minor difference in syntax when starting the application
with `npm run serve`. We use `--` to make sure npm doesn't try to
parse the `--host 0.0.0.0` as an option, allowing it instead to be
read by Angular CLI (ng).

Also, there is no direct npm equivalent to yarn's --network-timeout
option so I will remove it. If we need something similar later we
might be able to use these config options:

    npm config set fetch-retry-mintimeout 300000
    npm config set fetch-retry-maxtimeout 300000
This was the only Angular package not using a "^" to specify the
semver range.
We need this now that we are using npm instead of yarn.
Use npm instead of yarn. Mostly a search and replace, minus some
changes in terminology, for example "yarn add" vs "npm install".
@tdonohue tdonohue added this to the 9.0 milestone Sep 5, 2024
Copy link
Member

@kshepherd kshepherd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 looks good, tests well (I use docker and all seems good in my environment), thanks @alanorth

@alanorth
Copy link
Contributor Author

alanorth commented Sep 6, 2024

Thanks for testing @artlowel and @kshepherd. This is at +2 now. As far as I can see the only thing remaining is to update the DSpace wiki, though the section for DSpace 9 doesn't exist yet.

Copy link
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks @alanorth ! This was waiting on me to do a quick review. This looks GREAT! It's working well for me. I noticed on minor thing (and already fixed it), where the yarn.lock should now be listed in our .gitignore and .dockerignore in order to ensure it's no longer added back to our codebase.

Overall, this is ready to merge for 9.0. I'll leave the needs documentation flag in place until we create the new 9.0 wiki space, as we'll need to (eventually) update the docs there.

@tdonohue tdonohue merged commit ba05b22 into DSpace:main Sep 6, 2024
13 checks passed
@tdonohue tdonohue mentioned this pull request Sep 6, 2024
11 tasks
@alanorth alanorth deleted the use-npm branch September 7, 2024 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file high priority improvement needs documentation PR is missing documentation. All new features and config changes require documentation.
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Upgrade to Yarn v2 or switch back to npm
5 participants