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 ability to ignore peer depdenencies from package.json #1163

Merged
merged 1 commit into from
Oct 16, 2019
Merged

Add ability to ignore peer depdenencies from package.json #1163

merged 1 commit into from
Oct 16, 2019

Conversation

bweston92
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Feature (please, look at the "Scope of the project" section in the README.md file)

What is the current behavior?

Issue Number: #1162

What is the new behavior?

Ability to pass a canIgnore list of strings containing peer dependency names that can be ignored.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This is one implementation, we could make it so we can pass it via the *_install rule instead if it might be cleaner.

@buildsize
Copy link

buildsize bot commented Sep 20, 2019

File name Previous Size New Size Change
release.tar.gz 1.03 MB 1.03 MB -1.79 KB (0%)

findDeps(dep.dependencies, () => true, 'dependency');
findDeps(dep.peerDependencies, (targetDep) => {
// if it is not in the can ignore then is is required
return canIgnore.indexOf(targetDep) === -1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

so the field canIgnore is a list in the user's package.json? a new field you're adding?

Would be good to have some doc change so users can figure out how to use this, along with some test (can just be that you find a way to reproduce the failure in this repo by not installing a peer dep, then use your new feature to fix that breakage)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, canIgnore is a string list in the package.json, I was going to add documentation but I don't know whether or not to do it this way, we also have an alternative of putting in a rule attribute, which would you prefer?

Choose a reason for hiding this comment

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

I'd prefer an attribute over a new key added to the package.json

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Toxicable I personally think I am with you, it was something I thought about after I wrote this but will amend asap.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah it's a behavior of npm_install/yarn_install so seems like it should go there. I think the default should be to act like npm and yarn which means we should print peerDep warnings but proceed. Offer users a strictPeerDependencies boolean option. (I guess you could have a list of specific peerDep warnings to whitelist in strict mode)

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 have changed the way it is done, will check when at work again tomorrow to make sure it still works if so I will add documentation if it is ok with you?

Copy link

@Toxicable Toxicable left a comment

Choose a reason for hiding this comment

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

Awesome! I'm liking this imp a lot better, I think the docs could be a bit improved though

@@ -89,6 +89,10 @@ which are installed, but failures on installation are ignored.
"exclude_packages": attr.string_list(
doc = """DEPRECATED. This attribute is no longer used.""",
),
"ignore_peer_dependencies": attr.string_list(
default = [],
doc = """A list of peer depedencies that can be ignored.""",

Choose a reason for hiding this comment

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

Could you add to this doc that strict_peer_dependencies must be set for you to use this?
Or maybe change the logic a little bit so that you can set this without needing strict_peer_dependencies

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How would you suggest a change the logic which can have the following 3 use cases:

a = strict_peer_dependencies
b = ignore_peer_dependencies

  1. You want to ignore peer dependencies. (a = False, b = [])
  2. You want to have strict dependencies and ignore a few of them. (a = True, b = ['dep1', 'dep2'])
  3. You want to have strict dependencies and ignore none of them. (a = True, b = [])

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you find any other popular tooling that gives a strict mode for peer deps? I would like to follow some precedent rather than invent something new.

If there is no precedent at all, maybe we shouldn't even have a strict mode - that should be someone else's job, orthogonal to whether the package manager is run by bazel

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 don't really know of any, Yarn and NPM both give warning but nothing more.

Choose a reason for hiding this comment

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

Yeah tha's a good point @alexeagle I don't know of any that have strict deps.
Maybe we should just remove the checks, if anything it should be yarn checking things like this right, not us?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok so should I revert it all and put the “true” to “false” for required?

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 have reverted and set the peer dependencies as a non requirement altogether. Is that ok?

Choose a reason for hiding this comment

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

Yeah sounds good to me, sorry for all the back and forward.
We appciate you taking the time here!

@alexeagle
Copy link
Collaborator

Could you rebase past the conflict, squash commits and update commit message to pass the .commitlint check (seems like your precommit hooks are not working?)
If that's hard for you I can do it

@bweston92
Copy link
Contributor Author

@alexeagle is that ok?

@alexeagle
Copy link
Collaborator

I think you've done something wrong, did you look at the resulting diff? This PR now proposes editing only two lines which can't be right.
https://github.com/bazelbuild/rules_nodejs/pull/1163/files

I guess I'll grab your earlier snapshot and just fix this for you...

@bweston92
Copy link
Contributor Author

That is right, before we wanted to allow us to ignore some of the peer dependencies, now we're just turning off the flag which makes peer dependencies required in the first place.

@alexeagle alexeagle merged commit bd2f108 into bazel-contrib:master Oct 16, 2019
@bweston92 bweston92 deleted the feature/1162-add-ability-to-ignore-peer-dependencies branch October 16, 2019 20:45
@httpete
Copy link

httpete commented Nov 25, 2019

For anyone struggling, it seems that optionalDependencies in your package.json works to bypass it.

"optionalDependencies": { "popper.js": "latest", "jquery": "latest", "@types/prismjs": "latest", "karma-firefox-launcher": "latest" }

@bweston92
Copy link
Contributor Author

@httpete yes it does since this PR, prior to this PR peerDepedencies where strictly required by rules_nodejs.

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

Successfully merging this pull request may close these issues.

5 participants