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

Enable per-leaf pack directory via "packageDir" key in package.json #2109

Closed
wants to merge 3 commits into from

Conversation

heavypennies
Copy link

@heavypennies heavypennies commented May 27, 2019

Description

Some packages produce a build directory and contents that are different than the root/source folder structure in the project. This addition to lerna enables those packages to specify a different base directory for the Pack function. This is akin to enabling e.g. npm publish <dir> on a per-leaf basis.

To use this feature, add "packageDir", "dist" to package.json

and you'll get this:
lerna notice packed @your-org/your-package packages/your-package/dist

If you do not add packageDir to your package.json, you'll continue to get this:
lerna notice packed @your-org/your-package packages/your-package

Motivation and Context

When we have lerna managed modules that transpile and otherwise construct a package structure outside the root of the source tree, it's ideal to be able to run e.g. npm publish dist. The "files" directive in package.json DOES enable targeting only the dist contents, and for flat packages where index.js only includes relative files, this works. However when publishing a library exposing multiple folders e.g. import * from "@your-org/your-package/feature" having to include a dist dereference e.g. import * from "@your-org/your-package/dist/feature" is not ideal.

I also noticed --contents dist would have a similar effect, but I was in need of a per-leaf solution to this issue.

This will fix #1282

How Has This Been Tested?

First, I added a test to publish-command to ensure the pack-directory command would include the proper folder name if the package.json key was included.

npm run test -- publish-command

Then I tried it out in a local project:
First I ran lerna publish --force-publish on my package without packageDir included in package.json. Result:

lerna notice packed @your-org/your-package packages/your-package

Next I ran lerna publish --force-publish on my package with "packageDir" : "dist" included in package.json. Result:

lerna notice packed @your-org/your-package packages/your-package/dist

$ node --version
v10.15.2
$ npm --version
6.4.1
$ lerna --version
3.14.1

Types of changes

  • 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 read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@evocateur
Copy link
Member

I really appreciate the PR, my sincere apologies for the delay in review.

Inspired by your review, I implemented ea861d9 to fix this. Published in v3.14.2.

@ithinkihaveacat
Copy link

Also fixes #901 (which is locked—trying to add a reference from that to this feature for people who come across the issue via search).

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.

Link and publish not the package directory but it's child dist folder instead
3 participants