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(publish): make npm-publish apply publishConfig overrides, closes #404 #410

Conversation

artechventure
Copy link
Contributor

Description

Make npm-publish function to ovveride manifest by publishConfig.

Motivation and Context

#404

As described in an issue above, yarn and pnpm has it's own logic to overwrite publishConfig to manifest.
So I added that logic into npm-publish function.
Added ones doesn't effect existing publishConfig related logics.

How Has This Been Tested?

Added an test code.

Types of changes

  • Chore (change that has absolutely no effect on users)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov
Copy link

codecov bot commented Nov 9, 2022

Codecov Report

Merging #410 (48c9a6b) into main (ec49df4) will decrease coverage by 0.22%.
The diff coverage is 44.45%.

@@            Coverage Diff             @@
##             main     #410      +/-   ##
==========================================
- Coverage   97.31%   97.09%   -0.21%     
==========================================
  Files         146      146              
  Lines        4335     4353      +18     
  Branches     1004     1008       +4     
==========================================
+ Hits         4218     4226       +8     
- Misses        117      127      +10     
Impacted Files Coverage Δ
packages/publish/src/lib/pack-directory.ts 81.49% <44.45%> (-18.51%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

'os',
];

async function overwritePublishConfig(manifestLocation: string) {
Copy link
Member

@ghiscoding ghiscoding Nov 9, 2022

Choose a reason for hiding this comment

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

I would prefer "override" instead of "overwrite" because the latter can be confused by thinking it's overwriting the entire file which is far from the reality. Also, pnpm wrote something similar in their docs

It is possible to override some fields in the manifest before the package is packed. The following fields may be overridden:

@@ -69,6 +73,47 @@ export async function packDirectory(_pkg: Package, dir: string, options: PackCon
);
}

export const PUBLISH_CONFIG_FIELDS = [
Copy link
Member

Choose a reason for hiding this comment

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

it looks like there's also a "typesVersion" that pnpm can also override as defined in their docs
https://pnpm.io/package_json#publishconfig

PUBLISH_CONFIG_FIELDS.forEach((key) => {
if (key in publishConfig) {
manifest[key] = publishConfig[key];
delete publishConfig[key];
Copy link
Member

Choose a reason for hiding this comment

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

I didn't test the code but I wonder what's the reason that you have to delete the object property? I see you're also deleting a few lines below as well

@ghiscoding
Copy link
Member

ghiscoding commented Nov 9, 2022

nice PR, I wonder if we should put this under a flag though? Perhaps an inverse flag in case some users might want to disable it.

# with inversed flag, we could disable it
lerna publish --no-override-publish-config

Also does npm support that? They probably don't right? So I wonder if we should run this function only when it's pnpm or yarn defined as npmClient

It also looks like all the code from the new function you added isn't tested, we'll need to make sure these are covered. I see that it does go in the return when no override are defined, so there is a unit test that covers this, we need to find similar test and add these overrides, I can take a look later to find that out if you can't

image

@ghiscoding ghiscoding changed the title feat: make npm-publish to override publishConfig feat(publish): make npm-publish apply publishConfig overrides Nov 9, 2022
@artechventure
Copy link
Contributor Author

Thanks for your comment. I think providing through options flag is a good idea. I will reflect you reviews this weekend. Thanks!

@ghiscoding ghiscoding changed the title feat(publish): make npm-publish apply publishConfig overrides feat(publish): make npm-publish apply publishConfig overrides, closes #404 Nov 10, 2022
@ghiscoding
Copy link
Member

ghiscoding commented Nov 18, 2022

@artechventure I had a chance to take a look at your PR today. After looking at the PR and trying to add unit tests, I discovered the code you added in pack-directory should actually be moved into the publish-command.ts and package.ts files, the main reason is because we do all temp publish changes into publish-command.ts that is just before publishing, this way it keeps the source files intact while using the modifies packed temps files when publishing (we do the same for replacing workspace: protocol, links: deps and add gitHead prop, so this override becomes just another step in that list of things to do before publishing as you can see below)

https://github.com/ghiscoding/lerna-lite/blob/67705c54e942d0873d081e755992e6bdeebf344a/packages/publish/src/publish-command.ts#L261-L282

I'll be closing this PR, but don't worry you will still be a contributor since I forked your PR 😉
Could you please review the new PR #415 that I just created to supersede yours.
Thanks for the contributions

@ghiscoding ghiscoding closed this Nov 18, 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.

None yet

2 participants