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

feat: create symlink for build files present on node modules installed with relative paths #2330

Merged

Conversation

mistic
Copy link
Contributor

@mistic mistic commented Dec 3, 2020

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?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Currently if a local module installed with npm contains a BUILD file we generate the usual BUILD file content and just append the one found on the BUILD file.

Issue Number: #2131

What is the new behavior?

With this PR the BUILD file inside an installed local module will be symlinked instead of generated and get its content appended.

Does this PR introduce a breaking change?

  • Yes
  • No

It is really unlikely that the current behaviour is being useful to someone who relies on having a BUILD file in a local installed npm module as it introduces a race condition. However, the migration path would be to rewrite their BUILD files inside such modules to contain the expected generated targets by npm_install/yarn_install rules like *-module__contents or *--module__files and also add the extra targets they have previously defined on the BUILD file.

HINT: In order to don't have to manually writ *-module__contents or *--module__files we can remove the BUILD file, run the npm_install/yarn_install rules and just grasp the generated BUILD file content.

Other information

@alexeagle
Copy link
Collaborator

Awesome, this looks good to me. Thanks! I think I agree that no one really should rely on the current behavior but @gregmagolan added that and has a better memory than I do.

@gregmagolan
Copy link
Collaborator

gregmagolan commented Dec 4, 2020

This looks great. I read through the issue and the code and agree that this is the right thing to do if the node_module is a symlink to inside the workspace. It's a clever way to consume 1st party deps. The only thing I'd add is to update the yarn_install & npm_install docs to document this feature & the reasoning.

As an aside, why use this method instead of js_library with package_name to link 1st party deps? End result of a symlink in node_modules to the 1st party dep seems the same tho the js_library with package_name would use the linker to achieve it.

@mistic
Copy link
Contributor Author

mistic commented Dec 5, 2020

@gregmagolan Thanks for reviewing this as you are one of the few people well positioned and with enough knowledge to validate the idea. Regarding your question, js_library with package_name could be used to solve almost every situation. The problem arises when a local package consumed by the monorepo also gets published into the npm registry and starts being used by other node_module that you also have installed in your monorepo. That will cause a race condition that will make you not being able to use the linked node_module correctly as the generated BUILD file is not updated yet. If you run npm/yarn install a second time it will succeed because the BUILD file on the second run gots updated. Fixing the legacy behaviour of appending BUILD file contents and link instead will empower us to cover all the situations we could end up having in a node environment.

@mistic
Copy link
Contributor Author

mistic commented Dec 5, 2020

@alexeagle I've also added some content both to the yarn_install and npm_install rules about that new behaviour. Can you take a look and review it please?

I've also squashed the commits into a single one with a meaningful commit message for the feature.

@mistic mistic changed the title feat: create symlink for build files present on local installed npm modules feat: create symlink for build files present on node modules installed with relative paths Dec 5, 2020
… installed with relative paths

test(builtin): test setup attempt for support local linked packages

chore(builtin): format fix

chore(builtin): format fix

chore(builtin): format fix

chore(builtin): put back unintended changes

test(builtin): correct test implementation

feat(builtin): include warning log about not found build file

chore(builtin): use specific workspace on local-module one for each package manager

fix(builtin): only symlink package if it is inside the workspace

chore(builtin): add note about corner case as suggested in the pr review

docs(builtin): add docs for new behaviour on npm_install and yarn_install rules
@mistic mistic force-pushed the fix-npm-install-for-local-linked-modules-3.x branch from 06c2e2f to ea599a5 Compare December 5, 2020 23:59
@alexeagle
Copy link
Collaborator

I'm still not sure this use case of bazel -> bazel dependency makes sense, even given your problem description I still think you should have a js_library with package_name as the dependency of any Bazel code. That should be orthogonal to whether some non-Bazel dependencies in your repo still depend on the npm-built package.

docs/Built-ins.md Outdated Show resolved Hide resolved
@google-cla
Copy link

google-cla bot commented Dec 16, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no and removed cla: yes labels Dec 16, 2020
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.

3 participants