Local REPOs as Dependencies

I am developing in two repos, one depends on the other. I'm on npm v5. I define the dependence package.json

of main-repo

both ../dependent-repo

. When I do npm install

, this creates a symbolic link for dependent-repo

in main-repo/node_modules

, pointing to ../../dependent-repo

.

The problem is that the pod dependent-repo

has its own node_modules

under it, so when I reference (require or import) something in one of its dependencies, the default resolution routine resolves the dependency in dependent-repo/node_modules

, not the dependency on main-repo/node_modules

.

This turns out to be a problem with TypeScript, as it apparently believes it main-repo/node_modules/@angular/core

is different from dependent-repo/node_modules/@angular/core

even if they are the same version and bytes for bytes are identical. This leads to TS form errors

An argument of type "ViewContainerRef" is not assigned to a parameter of type "ViewContainerRef".

I am familiar with this problem because it also happened with npm v3 when I used npm link

. This issue has been discussed extensively on the TS question list, but without permission as far as I can tell. I was hoping that npm v5 would somehow magically solve this problem, but no luck so far.

I tried to point the dependency as file://../dependent-repo

, but this also just creates the same symlink (at least in npm5, I seem to remember that in earlier versions I copied the directory lock, stock, and barrel if possible).

At the moment, the only workaround I can see is leaving the dependency pointing to the github server and then committing and pushing every change I make and rerunning the npm install

main repo for the latest changes.This was exactly what I was trying to avoid.

I was thinking about a temporary rename dependent-repo/node_modules

before testing main-repo

, so it is not considered in the resolution process. However, this obviously requires all dependencies dependent-repo

on main-repo

.

I played paths

around with the on tsconfig.json

(c main-repo

) option a bit and had some luck with things like paths: {"*": ["node_modules"]}

, but couldn't get it to work completely.

I realize that I angular-cli

may have made some changes to my internal webpack config to make this work better, but unfortunately mine is main-repo

using the old webpack build process and I could not make some of the suggested changes like resolve: {fallback: [path.join(__dirname, 'node_modules')]}

or resolve: { modules: [ path.join(__dirname, "node_modules") ] }

work for me ...

+3


source to share


1 answer


You can add a new remote to git in the repository dependent

, but the new "remote" will be somewhere in your local field. This way you can make git push <remote-name> <branch>

and point the repo url in the repository main

to pull from your remote. [ git how to add a local repo and treat it as remote is a hacky solution, but should ease some pain when used with multiple makefiles.



0


source







All Articles