Skip to content

[Feature] Support relative dependencies within the repo - #204

Closed
gigabo wants to merge 2 commits into
lerna:masterfrom
gigabo:relative-deps
Closed

gigabo wants to merge 2 commits into
lerna:masterfrom
gigabo:relative-deps

Conversation

@gigabo

@gigabo gigabo commented Jun 9, 2016

Copy link
Copy Markdown
Contributor

We use relative dependencies in private packages as a crude workaround for #11.

This generates warnings during bootstrap, and prevents us from receiving the full benefit of #199.

This patch causes bootstrap to treat relative dependencies as satisfactory.

@jamiebuilds

Copy link
Copy Markdown
Contributor

How do the relative dependencies work when publishing that module?

@gigabo

gigabo commented Jun 10, 2016

Copy link
Copy Markdown
Contributor Author

We only do it on private modules, so they don't get published.

@gigabo

gigabo commented Jun 10, 2016 •

Copy link
Copy Markdown
Contributor Author

Should probably actually be an error to do it on a public module...

@patrickheeney

patrickheeney commented Jul 24, 2016 •

Copy link
Copy Markdown

I tried to add support for this in #10 but it was closed (also is outdated now). This may also work for my use case but it would need to support the other ways to declare relative dependencies:

"dependencies": {
    "some-local-dependency": "file:../some-local-dependency"
},

It may be worthwhile to use the same logic npm uses internally to determine if this is a local dependency or not (https://github.com/npm/npm-package-arg).

@gigabo

gigabo commented Jul 25, 2016

Copy link
Copy Markdown
Contributor Author

the other ways to declare relative dependencies

Oh yeah, good point. Thanks for the link to npm-package-arg.

I've actually realized since opening this that local dependencies are a little trickier than I originally thought. Specifically, running npm install ../some-local-dependency isn't actually correct if some-local-dependency itself has non-local dependencies on packages that live in the repo.

For example with deps that look like:

package-a => "../package-b"
package-b => "package-c@^1.0.0"

If package-c lives in the repo it should be linked for package-b.

Not sure what to do about that case.

@patrickheeney

Copy link
Copy Markdown

I think the first step is something like you have done, which is to make sure the local file based packages can be bootstrapped at all. I haven't looked into it since #10, but back then private / local packages were excluded from lerna.

Then likely the bootstrap process needs to be modified to detect that package-c needs to be linked from package-b. That is likely related to my other issue #11 since I currently solved it by symlinking all package dependencies as a last step after npm install (see Global Cache / Symlink approach in that issue).

@gigabo

gigabo commented Jul 25, 2016

Copy link
Copy Markdown
Contributor Author

back then private / local packages were excluded from lerna.

They're npm installed now. It actually works fine on the surface. It's just with transitive dependencies that it starts to fall apart.

the bootstrap process needs to be modified to detect that package-c needs to be linked from package-b.

Right, but when is it linked? It can't happen before npm install, because the target in node_modules gets fresh copies of dependencies. It can't happen after npm install, because the dependency may be used during install (in a prepublish script). So, it would need to be linked during install. I don't know that npm provides the hooks we would need to do this without reimplementing npm install at a high level.

@patrickheeney

Copy link
Copy Markdown

Right, but when is it linked?

At the root level this is how I am doing it at the moment:

  • Get a list of all project packages
  • Symlink them in node_modules project node_modules so they can be resolved
  • Diff local packages against package.json and pass non-local ones to npm install
  • Do the same for each package

If each package is installed separately then all the other non-local dependencies, then in theory by the time the dependency packages are installed you already have the right local one.

I am also using pnpm because of global cache, faster, and easier to pass it CLI arguments. I don't think this easily supports multiple versions of the same local dependency (but could maybe?). I haven't had an issue with scripts but I imagine there is some scenario where this might not work?

@jamiebuilds jamiebuilds changed the title Support relative dependencies within the repo [Feature] Support relative dependencies within the repo Nov 16, 2016
@evocateur

Copy link
Copy Markdown
Member

@gigabo Can we close this PR now?

@gigabo

gigabo commented Feb 28, 2017

Copy link
Copy Markdown
Contributor Author

Yes!

@gigabo gigabo closed this Feb 28, 2017
@lock

lock Bot commented Dec 27, 2018

Copy link
Copy Markdown

This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked as resolved and limited conversation to collaborators Dec 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants