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: add public_hoist_packages attribute to npm_translate_lock to emulate .npmrc public-hoist-pattern[] #222

Merged
merged 1 commit into from
Jun 17, 2022

Conversation

gregmagolan
Copy link
Member

@gregmagolan gregmagolan commented Jun 17, 2022

Turns out pnpm does not encode what it hoists in its lockfile. It is a link time decision in the implementation.

This lays the foundation for supporting https://pnpm.io/npmrc#public-hoist-pattern and https://pnpm.io/npmrc#shamefully-hoist.

Follow-ups to this would be to support globs to get closer to what users can do with .npmrc. For example,

.npmrc:

public-hoist-pattern[]=*eslint*
public-hoist-pattern[]=*prettier*
public-hoist-pattern[]=*plugin*

could be emulated with

    public_hoist_packages = {
        "*eslint*": [""],
        "*prettier*": [""],
        "*plugin*": [""],
    },

and

.npmrc:

shamefully-hoist=true

with

    public_hoist_packages = {
        "*": [""],
    },

Once we can do that then we could just let users use the .npmrc file as the source of truth instead:

npm_translate_lock(
    name = "npm",
    npmrc = "//:.npmrc",
    ...
)

NB: .npmrc is an INI file https://en.wikipedia.org/wiki/INI_file

@gregmagolan gregmagolan requested a review from alexeagle June 17, 2022 20:28
@gregmagolan gregmagolan force-pushed the public_hoist_packages branch 3 times, most recently from bd619f5 to 123f64b Compare June 17, 2022 20:35
@@ -1,3 +1,4 @@
# Set a custom registry for a scope that is picked up by pnpm when resolving packages;
# This affects the lockfile format and is here to cover this case.
@types:registry=https://registry.yarnpkg.com
public-hoist-pattern[]=ms
Copy link
Member

Choose a reason for hiding this comment

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

comment that bazel / rules_js won't actually see this yet, it only has effect for pnpm i

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -210,3 +210,24 @@ uvu_test(
":uvu_spec",
],
)

#######################################
# Use case 6: depend on a hoisted npm package that wasn't a direct dependency package.json
Copy link
Member

Choose a reason for hiding this comment

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

would be nice to say which direct dependency has the ms dependency

Copy link
Member Author

Choose a reason for hiding this comment

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

public_hoist_packages.extend(attr.public_hoist_packages.get(friendly_name, []))
if unfriendly_name:
public_hoist_packages.extend(attr.patches.get(unfriendly_name, []))
for public_hoist_package in public_hoist_packages:
Copy link
Member

Choose a reason for hiding this comment

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

nice short code change is a good sign that the abstractions will endure more feature sprawl :)

Copy link
Member Author

Choose a reason for hiding this comment

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

🌮

@gregmagolan gregmagolan force-pushed the public_hoist_packages branch 2 times, most recently from 176722b to 6bfc884 Compare June 17, 2022 21:58
@gregmagolan gregmagolan force-pushed the public_hoist_packages branch from 6bfc884 to 852b690 Compare June 17, 2022 21:59
@gregmagolan gregmagolan merged commit db88926 into aspect-build:main Jun 17, 2022
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.

2 participants