Enable per-leaf pack directory via "packageDir" key in package.json #2109
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.jsonand 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 adist
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 withoutpackageDir
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
Types of changes
Checklist: