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

fix(core): set npm_package_json environment variable when running scripts #4546

Merged
merged 9 commits into from
Jul 12, 2022
Merged

Conversation

uhop
Copy link
Contributor

@uhop uhop commented Jun 13, 2022

What's the problem this PR addresses?

Implements $npm_package_json. Closes #2436

How did you fix it?

Updated scriptUtils.makeScriptEnv to populate the npm_package_json environment variable.

The location of every package root, where package.json resides, is already calculated. I added a way to expose it as $npm_package_json:
* makeScriptEnv() of scriptUtils.ts gets an optional parameter packageLocation.
* If it is supplied, it is joined using ppath.join() with package.json and exposed as $npm_package_json.
* packageLocation comes from initializePackageEnvironment() (the same file), where it finds it using linker.findPackageLocation().

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

@uhop uhop requested a review from arcanis as a code owner June 13, 2022 03:14
@merceyz merceyz changed the title [Feature] support $npm_package_json fix(core): set npm_package_json environment variable when running scripts Jun 13, 2022
packages/gatsby/content/advanced/lifecycle-scripts.md Outdated Show resolved Hide resolved
packages/yarnpkg-core/sources/scriptUtils.ts Outdated Show resolved Hide resolved
@Fuzzyma
Copy link

Fuzzyma commented Jul 4, 2022

@merceyz @uhop how far are you with getting this merged? I don't want to let it slide under the rug again where it hides forever :D

@uhop
Copy link
Contributor Author

uhop commented Jul 6, 2022

@Fuzzyma I am waiting for instructions (see my suggestions and concerns above) from @merceyz or @arcanis or whoever has the authority to accept PRs. If they select an implementation plan acceptable to them, I’ll do it in a jiffy.

@merceyz
Copy link
Member

merceyz commented Jul 12, 2022

I've updated the implementation to get the packageLocation using the linkers to make sure the value is consistently set when a locator and project is provided.

merceyz
merceyz previously approved these changes Jul 12, 2022
@uhop
Copy link
Contributor Author

uhop commented Jul 12, 2022

@merceyz @arcanis — thank you, guys! Many of my users wanted this compatibility feature because they are yarn fans.

If I can help you with merging it in any way — just ask.

@arcanis arcanis merged commit 7c6055b into yarnpkg:master Jul 12, 2022
@arcanis
Copy link
Member

arcanis commented Jul 12, 2022

All good - thanks @uhop ! 🌟

merceyz added a commit that referenced this pull request Jul 20, 2022
…cripts (#4546)

* Added `packageLocation` as a base for `npm_package_json`.

* Added docs.

* The release decisions.

* chore: versions

* Update packages/gatsby/content/advanced/lifecycle-scripts.md

Co-authored-by: Kristoffer K. <[email protected]>

* refactor: get `packageLocation` from the linkers

* test: update expected script environment variables

* chore: changelog

* Update scriptUtils.ts

Co-authored-by: merceyz <[email protected]>
Co-authored-by: Maël Nison <[email protected]>
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.

[Feature] support $npm_package_json
4 participants