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

[Feature] Allow custom publish subdirectory #2113

Closed
aleclarson opened this issue May 29, 2019 · 15 comments
Closed

[Feature] Allow custom publish subdirectory #2113

aleclarson opened this issue May 29, 2019 · 15 comments

Comments

@aleclarson
Copy link

aleclarson commented May 29, 2019

Related: #91 #901 #1282 #1817

I'm setting up react-spring to use Lerna, and I want lerna publish to use npm publish ./dist instead of npm publish ./, but Lerna's maintainers have declined such a feature request in the past.

For each package in packages/ directory, there exists a stub package.json with only a little bit of metadata. The rest of the metadata is copied from the root package.json using a custom build script. I want the published contents to be excluded from source control (via .gitignore), so I don't want to mutate the stub package.json before publish. I could use the prepublish and postpublish scripts, but that can interfere with uncommitted changes and I need to keep the published contents around for local development.

One workaround is to put my package stubs in the .packages/ directory, but I'd like to avoid that, because some platform-specific code will exist in these package stubs, and I want that code to be easily discoverable by contributors. It's better to put the package stubs in packages/ since that's the "standard" for mono repos.

LMK if you have any questions. 👍

@aleclarson
Copy link
Author

aleclarson commented May 29, 2019

Especially nowadays with ES module exports and whatnot combined with tree-shaking module bundlers, there’s really no fundamental necessity for false-basedir publishing. #901 (comment)

@evocateur It's a useful feature for cross-platform libraries, I think. Tree-shaking can't solve the issue of platform differences in TypeScript definitions. For example, react-spring/web would conflict with react-spring/native if they shared an entry point. We'll have @react-spring/web and @react-spring/native, but we need the other style for back-compat.

@aleclarson
Copy link
Author

Ah, I just noticed the --contents flag for the publish command.

https://github.com/lerna/lerna/tree/master/commands/publish#--contents-dir

@aleclarson aleclarson reopened this Jun 2, 2019
@aleclarson
Copy link
Author

@evocateur It looks like Lerna doesn't use the package.json in the --contents directory. Should that be fixed?

@evocateur
Copy link
Member

Tree-shaking can't solve the issue of platform differences in TypeScript definitions

That sounds like a TypeScript problem, not a Lerna problem.

@evocateur
Copy link
Member

Also, I think I have a true fix for the underlying issue.

@aleclarson
Copy link
Author

Which issue exactly? I've had so many while setting up this monorepo (not all Lerna related). 😅

Anyway, the monorepo is up and running now. Note: It's still using patch-package for Lerna.
See here: https://github.com/react-spring/react-spring/tree/v9

@evocateur
Copy link
Member

Specifically, not using the subdirectory package.json when publishing. I'm also adding the ability to configure --contents per-leaf via pkg.publishConfig.directory (inspired by #2109).

@aleclarson
Copy link
Author

Specifically, not using the subdirectory package.json when publishing.

Perfect, thanks for the help!

I'm also adding the ability to configure --contents per-leaf via pkg.publishConfig.directory (inspired by #2109).

Nice I was just needing that!

@evocateur
Copy link
Member

Published v3.14.2 with these changes

@aleclarson
Copy link
Author

The getUnpublishedPackages function doesn't respect pkg.publishConfig.directory while filtering out private packages.

@evocateur
Copy link
Member

When getUnpublishedPackages is called, no package (or root) lifecycle has been called yet, so I wouldn't generally expect the --contents directory to even exist yet. I'm not inclined to accept the PR, or even fix it by other means?

Why can't you configure pkg.publishConfig.directory in the "real" leaf package.json? In the repo you linked to, all the leaves have "private": true set for no apparent reason?

@aleclarson
Copy link
Author

Why can't you configure pkg.publishConfig.directory in the "real" leaf package.json?

Huh? Lerna needs pkg.publishConfig.directory in packages/*/package.json to know where the published package.json is located. How else would it know to publish packages/*/dist/package.json instead?

In the repo you linked to, all the leaves have "private": true set for no apparent reason?

Making the leaves private prevents anyone from naïvely running npm publish in packages/* instead of packages/*/dist.

@evocateur
Copy link
Member

I guess I'm saying: remove the "private": true from your leaves, and it will work just fine. Document why your contributors shouldn't run npm publish in the leaf directories, and assume anyone that has publish access isn't a complete knob.

@aleclarson
Copy link
Author

Mistakes happen, but fair enough. ;)

@evocateur
Copy link
Member

Mistakes happen indeed, but package publishing is among the easier mistakes to rectify once discovered. :)

aleclarson added a commit to pmndrs/react-spring that referenced this issue Jul 18, 2019
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

No branches or pull requests

2 participants