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(link): Use publishConfig.directory as symlink source if it exists to allow linking sub-directories #2274

Merged
merged 16 commits into from Oct 10, 2019

Conversation

kamranayub
Copy link
Contributor

@kamranayub kamranayub commented Sep 17, 2019

Description

This is a fork of #2081 but uses the suggestions from #2209 (comment)

  • Use pkg.contents to resolve symlink source path, allowing usage of publishConfig.directory to link to a sub-directory
  • Add support for --contents to bootstrap and link with docs

TODO

  • Update documentation to mention semantics of directory with regards to link command

Open Questions

  • ❓I believe this may be a breaking change, as anyone using publishConfig.directory and who've run lerna link before will experience a change in behavior. I could enhance this PR to include a flag for link, suggestions welcome.
  • ❓ I'm unclear what the comment "And probably need to make the pkg.bin field resolvable from contents, as well (it's currently hard-code)" refers to. In the Jest snapshots, it looks correct for bin files (I think) but wondering if @evocateur had some more context for that comment that I should add to the PR.

Motivation and Context

Closes #2209

There was an existing PR already #2081 but it needed tests and I believe the idea was to use pkg.contents instead of introducing a new config property.

I explained my motivation/need in my comment (#2081 (comment)):


The publishConfig.directory works well for publishing. In our monorepo we have two packages, core and baked. baked uses components from core. Since we use Rollup + Babel + TypeScript (these are libraries), we have a dist directory that we publish as the package. While we can publish new versions of the core components, for local development we're looking at using lerna link to make that easier to have a nicer workflow.

In a file within baked you may have:

import { MyComponent } from '@org/core-components'

This works for a published package but since lerna link symlinks the root directory and not the dist directory, for local development you must change the path:

import { MyComponent } from '@org/core-components/dist'

How Has This Been Tested?

  • Added Jest tests with snapshots that test the generated src/dest paths
  • Linked lerna with npm link and tested within our own monorepo for our use case
    • Specifically I tested depending from package baked -> core and successfully consumed TypeScript-based components from the symlinked core package.

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.

@kamranayub kamranayub changed the title feat(link): Use contents as symlink source if it exists to allow linking sub-directories feat(link): Use publishConfig.directory as symlink source if it exists to allow linking sub-directories Sep 18, 2019
@kamranayub kamranayub marked this pull request as ready for review September 19, 2019 17:07
Copy link
Member

@evocateur evocateur left a comment

Choose a reason for hiding this comment

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

Thanks for adding tests, they look good. A few more additions to make this "fully formed" and we're good to go.

commands/publish/README.md Outdated Show resolved Hide resolved
commands/link/README.md Outdated Show resolved Hide resolved
@evocateur
Copy link
Member

I don't see this as a breaking change, really. If one is already using --contents or publishConfig.directory, then this is somewhat of a "return" to expected behavior.

Copy link
Member

@evocateur evocateur left a comment

Choose a reason for hiding this comment

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

Thanks so much! Just remove the unused with-contents fixture under bootstrap, and we're good to go!

Copy link
Member

@evocateur evocateur left a comment

Choose a reason for hiding this comment

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

Thanks!

@evocateur evocateur merged commit d04ce8e into lerna:master Oct 10, 2019
@evocateur
Copy link
Member

Published in v3.17.0

@kamranayub kamranayub deleted the feat/gh-2209/symlink-subdir branch October 10, 2019 14:58
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.

Publish and link package subdirectory (like lib/dist/build)
2 participants