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

Add prettier and eslint #638

Closed
wants to merge 4 commits into from

Conversation

theimbender
Copy link
Contributor

  • Adds prettier and eslint with pre-commit hooks so that relevant files are linted and formatted during commit
  • Latest version of Encore now supports latest version of sass-loader, so bump all dependencies
  • Remove the one usage of optional chaining, it wasn't needed and violates the new eslint rules
  • Remove unused popper.js dependency
  • Expose script for composer test so you can run the project's tests with the same version of PHPUnit that the CI checks will use

@theimbender theimbender force-pushed the dependency-update branch 2 times, most recently from c13bf0d to 8e57fcc Compare February 15, 2021 14:31
@theimbender
Copy link
Contributor Author

Was also thinking of introducing codsniffer linting, what standards does this project follow? Just PSR2?

@theimbender
Copy link
Contributor Author

Ah, never mind, I just noticed the cs fixer config

@theimbender theimbender force-pushed the dependency-update branch 3 times, most recently from 9d1d01d to b292c49 Compare February 15, 2021 15:27
@alcohol
Copy link
Member

alcohol commented Feb 16, 2021

Do you reckon there is anything we can do about the following? I know some are indirect dependencies, but some are root dependencies.

npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated eslint-loader@4.0.2: This loader has been deprecated. Please use eslint-webpack-plugin
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1

"popper.js": "^1.14.3",
"sass": "^1.32.6",
"sass-loader": "^10.0.0"
"eslint-loader": "^4.0.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

please don't use the deprecated loader here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about that but encore doesn't yet have first class support for eslint-webpack-plugin. Would be better to write a custom rule for that now and remove it later on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eh, it's just eventually replacing two lines of code with one hopefully, let me add that so it makes sense

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, then maybe wait for Encore to support it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I already pushed a new commit that adds the plugin for that, that should continue to work even after encore supports it natively. Gonna be cleanup either way so might as well use a dependency that isn't deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, i was committing too fast

Copy link
Contributor

Choose a reason for hiding this comment

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

well, as that's simple enough, it is fine with me

@stof
Copy link
Contributor

stof commented Feb 16, 2021

popper.js is not an unused dependency. It satisfies the peerDependency of bootstrap

@alcohol for the warnings, the popper.js one can only be solved once Bootstrap 5.0 is released (and Satis upgrades to use it) as it is the one migrating to the new @popperjs/core
for har-validator and request, this looks like a bug in the way the lock file was updated after switching from node-sass to sass, as they are dependencies of node-sass which is still there in the lock file.
For resolve-url and urix, they are dependencies of rework, which is used optionally by the resolve-url-loader. This is being worked on at bholloway/resolve-url-loader#160 for the upcoming v4 of the loader.

@stof
Copy link
Contributor

stof commented Feb 16, 2021

OK, I understood it. npm 7 is installing peer dependencies by default, even when they are optional peer dependencies (which looks weird to me as there is no way to omit them then)

@theimbender
Copy link
Contributor Author

Maybe that was why popper.js was explicitly in package.json before? Because npm wasn't previously installing that entire dependency chain so it needed to be there or Bootstrap wouldn't work?

@stof
Copy link
Contributor

stof commented Feb 16, 2021

yeah, and that's actually the expected way for peer dependencies to work (neither pnpm nor yarn are automatically installing missing peer dependencies, and npm 6 was not doing it either)

@alcohol
Copy link
Member

alcohol commented Feb 16, 2021

Since I seem unable to push to your branch, I added some changes here: https://github.com/composer/satis/tree/theimbender-dependency-update

Any idea why npm ci fails on npm 6.x but not on 7.x ?

@theimbender
Copy link
Contributor Author

Probably the peer dependency thing, let me add back popper

@alcohol
Copy link
Member

alcohol commented Feb 16, 2021

@alcohol
Copy link
Member

alcohol commented Feb 16, 2021

Seems resolved though now that I updated to node 15.

@alcohol
Copy link
Member

alcohol commented Feb 16, 2021

Also if I run npm install locally from scratch I get quite a different lock file / set of dependencies:

$ npm --version
7.5.3
$ rm -rf node_modules package-lock.json 
$ npm i
npm WARN ERESOLVE overriding peer dependency
npm WARN Found: webpack@5.22.0
npm WARN node_modules/webpack
npm WARN   webpack@"^5.12" from @symfony/webpack-encore@1.1.0
npm WARN   node_modules/@symfony/webpack-encore
npm WARN     dev @symfony/webpack-encore@"^1.1.0" from the root project
npm WARN   7 more (eslint-loader, sass-loader, assets-webpack-plugin, ...)
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer webpack@"^4.0.0" from friendly-errors-webpack-plugin@2.0.0-beta.2
npm WARN node_modules/friendly-errors-webpack-plugin
npm WARN   friendly-errors-webpack-plugin@"^2.0.0-beta.1" from @symfony/webpack-encore@1.1.0
npm WARN   node_modules/@symfony/webpack-encore
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated eslint-loader@4.0.2: This loader has been deprecated. Please use eslint-webpack-plugin
npm WARN deprecated popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1

> prepare
> husky install

husky - Git hooks installed

added 1218 packages, and audited 1219 packages in 29s

97 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

@stof
Copy link
Contributor

stof commented Feb 16, 2021

Any idea why npm ci fails on npm 6.x but not on 7.x ?

that's because your package-lock.json uses the v2 format introduced in npm 7.x

@alcohol
Copy link
Member

alcohol commented Feb 16, 2021

I see. Is there a way to specify what node/npm version our project uses, like composer can reference what php version we support?

@theimbender
Copy link
Contributor Author

@theimbender
Copy link
Contributor Author

Should i require npm 7.x?

@alcohol
Copy link
Member

alcohol commented Feb 16, 2021

Great, any recommendations?

@alcohol
Copy link
Member

alcohol commented Feb 16, 2021

If 7.x introduces changes that are not BC with 6.x, then yes I would prefer to target the latest versions from here on forwards.

@stof
Copy link
Contributor

stof commented Feb 16, 2021

if we use a npm 7.x lock file, we should indeed require npm 7 in the package.json to avoid weird issues.

@alcohol
Copy link
Member

alcohol commented Feb 16, 2021

Ok I rebased https://github.com/composer/satis/tree/theimbender-dependency-update

But if I locally run rm -rf node_modules package-lock.json && npm install I still get quite a different result. Not sure if that is because I am on Linux and you are on Mac, or because the dependencies desynced based on adjustments you made that somehow didn't propagate properly.

@theimbender
Copy link
Contributor Author

ok, let me run that exact same command because there might be something wonky with my node_modules then

@theimbender
Copy link
Contributor Author

yeah i'm gonna just do that every time i commit any change involving a lock file, less headache. The command npm run build didn't generate any different output for me, so just the lock file needed to be fixed. Does this have the same output as your local?

@alcohol
Copy link
Member

alcohol commented Feb 16, 2021

Yep! I just get the one expected diff now:

$ git diff
diff --git i/package-lock.json w/package-lock.json
index 5647063..a5e4f1c 100644
--- i/package-lock.json
+++ w/package-lock.json
@@ -2467,7 +2467,6 @@
       "dependencies": {
         "anymatch": "~3.1.1",
         "braces": "~3.0.2",
-        "fsevents": "~2.3.1",
         "glob-parent": "~5.1.0",
         "is-binary-path": "~2.1.0",
         "is-glob": "~4.0.1",

Nothing else. 👍

@alcohol
Copy link
Member

alcohol commented Feb 16, 2021

Merged via aba12d6...ff2da4f

@alcohol alcohol closed this Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants