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: support multiple node_modules roots in require_patch #3051

Conversation

tcarrio
Copy link

@tcarrio tcarrio commented Oct 29, 2021

Refs: #266

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?

When referencing multiple node_modules from (npm|yarn)_install targets in a nodejs_(binary|target), you won't be able to resolve modules from all node_modules roots.

For example, having a separate yarn_install:

# setup stencil spec test dependencies
yarn_install(
    name = "npm_stencil_spec",
    exports_directories_only = True,
    frozen_lockfile = True,
    package_json = "//tools//stencil:spec/package.json",
    package_path = "tools/stencil/spec",
    yarn_lock = "//tools/stencil:spec/yarn.lock",
)

alongside the root:

yarn_install(
    name = "npm",
    data = ["//:.npmrc"],
    exports_directories_only = True,
    frozen_lockfile = True,
    package_json = "//:package.json",
    yarn_lock = "//:yarn.lock",
)

and referring to both of them in a test rule:

nodejs_test(
    name = "test",
    args = [
        "test",
    ],
    chdir = native.package_name(),
    data = [
        "@npm//@stencil/core",
        "@npm_stencil_spec//jest",
    ],
    entry_point = stencil_cli_path,
)

would result in the test run not being able to access the jest module.

Issue Number: #266

What is the new behavior?

Resolution of a require call will be done against all node_modules roots. The behavior is the same if it is not found.

Does this PR introduce a breaking change?

  • Yes
  • No

The prior behavior would have allowed for node_modules to be included without being able to be imported. Due to this, if anyone were relying on this undefined behavior to include node_modules data where importing that would have thrown an error, but I can't imagine a use case where this would be useful behavior to rely on.

Other information

Some minor adjustments to test case names such as "mode" updated to "module".

@google-cla
Copy link

google-cla bot commented Oct 29, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no label Oct 29, 2021
@tcarrio tcarrio force-pushed the feature/multiple-node-modules-roots branch from e1f24aa to 75e8c8a Compare November 1, 2021 04:33
@google-cla
Copy link

google-cla bot commented Nov 1, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@tcarrio tcarrio force-pushed the feature/multiple-node-modules-roots branch from 75e8c8a to ae1aa6a Compare November 1, 2021 05:22
@google-cla
Copy link

google-cla bot commented Nov 1, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@tcarrio
Copy link
Author

tcarrio commented Nov 1, 2021

I will need to add some documentation around this feature. The limitation currently is that you must define the two node modules roots under different paths with package_path since they can't be combined into a single directory implicitly. This makes sense, but it would be nice to note it somewhere.

@tcarrio tcarrio force-pushed the feature/multiple-node-modules-roots branch from ae1aa6a to 1dd9de2 Compare November 1, 2021 05:36
@google-cla
Copy link

google-cla bot commented Nov 1, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@tcarrio tcarrio force-pushed the feature/multiple-node-modules-roots branch from 1dd9de2 to 9764cbf Compare November 1, 2021 05:39
@google-cla
Copy link

google-cla bot commented Nov 1, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@tcarrio tcarrio closed this Nov 1, 2021
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.

1 participant