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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions __fixtures__/package-dir/lerna.json
@@ -0,0 +1,3 @@
{
"version": "1.0.0"
}
3 changes: 3 additions & 0 deletions __fixtures__/package-dir/package.json
@@ -0,0 +1,3 @@
{
"name": "package-dir"
}
5 changes: 5 additions & 0 deletions __fixtures__/package-dir/packages/package-1/dist/package.json
@@ -0,0 +1,5 @@
{
"name": "package-1",
"version": "1.0.0",
"packageDir": "dist"
}
1 change: 1 addition & 0 deletions __fixtures__/package-dir/packages/package-1/dist/tmp.txt
@@ -0,0 +1 @@
I am included
5 changes: 5 additions & 0 deletions __fixtures__/package-dir/packages/package-1/package.json
@@ -0,0 +1,5 @@
{
"name": "package-1",
"version": "1.0.0",
"packageDir": "dist"
}
4 changes: 4 additions & 0 deletions __fixtures__/package-dir/packages/package-2/package.json
@@ -0,0 +1,4 @@
{
"name": "package-2",
"version": "2.0.0"
}
20 changes: 20 additions & 0 deletions commands/publish/README.md
Expand Up @@ -275,6 +275,26 @@ You can customize the dist-tag on a per-package basis by setting [`tag`](https:/
- Passing [`--dist-tag`](#--dist-tag-tag) will _overwrite_ this value.
- This value is _always_ ignored when [`--canary`](#--canary) is passed.


### `packageDir` key in `package.json`

You can specify a relative folder where `lerna` should run `pack`. This will enable publishing the contents of e.g. a `dist` folder
vs. the root of the package.

Here's an example snippet of package.json that takes advantage:
```javascript
{
"name": "@your-org/your-project",
"main": "index.js",
"packageDir": "dist",
"scripts" : {
"build": "babel source --presets env,react-app --out-dir dist --copy-files && cp package.json dist && cp README.md dist",
"prepare": "npm run build"
},
...
}
```

## LifeCycle Events

Lerna will run [npm lifecycle scripts](https://docs.npmjs.com/misc/scripts#description) during `lerna publish` in the following order:
Expand Down
23 changes: 23 additions & 0 deletions commands/publish/__tests__/publish-command.test.js
Expand Up @@ -262,6 +262,29 @@ Map {
});
});

describe("packageDir property", () => {
it("allows you to do even more fancy crap", async () => {
const cwd = await initFixture("package-dir");

await lernaPublish(cwd)();

for (const name of ["package-1"]) {
expect(packDirectory).toHaveBeenCalledWith(
expect.objectContaining({ name }),
expect.stringContaining(`packages/${name}/dist`),
expect.any(Object)
);
}
for (const name of ["package-2"]) {
expect(packDirectory).toHaveBeenCalledWith(
expect.objectContaining({ name }),
expect.stringContaining(`packages/${name}`),
expect.any(Object)
);
}
});
});

describe("in a cyclical repo", () => {
it("should throw an error with --reject-cycles", async () => {
expect.assertions(1);
Expand Down
7 changes: 6 additions & 1 deletion commands/publish/index.js
Expand Up @@ -595,7 +595,12 @@ class PublishCommand extends Command {
}

const { contents } = this.options;
const getLocation = contents ? pkg => path.resolve(pkg.location, contents) : pkg => pkg.location;
const getLocation = contents
? pkg => path.resolve(pkg.location, contents)
: pkg => {
const packageDir = pkg.get("packageDir");
return packageDir ? path.resolve(pkg.location, packageDir) : pkg.location;
};

const opts = this.conf.snapshot;
const mapper = pPipe(
Expand Down