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

[Feature] allow ignore .pnp.cjs from current (or parent) dirs to allow creating self contained application with pnp #6684

Open
2 tasks done
adrian-gierakowski opened this issue Feb 11, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@adrian-gierakowski
Copy link

adrian-gierakowski commented Feb 11, 2025

  • I'd be willing to implement this feature (contributing guide)
  • This feature is important to have in this repository; a contrib plugin wouldn't do

Describe the user story

I'm packaging internal cli applications for my team, using yarn and pnp. Each application uses following wrapper script to execute a nodejs script:

#!/usr/bin/env bash

rootDir=$(dirname "$0")
nodeOptions="--loader $rootDir/.pnp.loader.mjs --require $rootDir/.pnp.cjs"
export NODE_OPTIONS="$NODE_OPTIONS $nodeOptions"

exec node ./index.js "$@"

These are then added to PATH so that they could be executed from anywhere in the developer's shell. It's been working fine, however I recently ran into an ERR_WORKER_OUT_OF_MEMORY error, which lead me to discovering that all of these scripts would also load .pnp.cjs from current working directory in which they are executed (the issue didn't manifest in CI, where .pnp.cjs was not present which is how I discovered the root cause).

The local .pnp.cjs has nothing to contribute to the correct execution of such script and therefore it is not desirable to load it.

Describe the solution you'd like

Some way of specifying that CWD (and it's parents) should not be searched for additional .pnp.cjs files.

Describe the drawbacks of your solution

not sure

Describe alternatives you've considered

Not use pnp to package such applications. Maybe there are other recommended ways of achieving desired result but I'm not aware of those.

@adrian-gierakowski adrian-gierakowski added the enhancement New feature or request label Feb 11, 2025
@adrian-gierakowski
Copy link
Author

Initial investigation lead me these two lines of code in .pnp.loader.mjs:

berry/.pnp.loader.mjs

Lines 2020 to 2021 in df5fabe

const issuer = parentURL && tryParseURL(parentURL)?.protocol === `file:` ? fileURLToPath(parentURL) : process.cwd();
const pnpapi = findPnpApi(issuer) ?? (url ? findPnpApi(specifier) : null);

and replacing process.cwd() with null fixes the problem for me:

  const issuer = parentURL && tryParseURL(parentURL)?.protocol === `file:` ? fileURLToPath(parentURL) : null;
  const pnpapi = (issuer && findPnpApi(issuer)) ?? (url ? findPnpApi(specifier) : null);

so maybe an ENV var switch fallback to process.cwd() could be a solution

not sure if it could have any further implication since I've done only a limited amount of testing

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

No branches or pull requests

1 participant