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(type): add support for new link: dependency type #3359

Merged
merged 1 commit into from
May 30, 2017

Conversation

mgcrea
Copy link
Contributor

@mgcrea mgcrea commented May 9, 2017

Summary

Following the accepted 0000-link-dependency-type.md RFC, and as discussed in yarnpkg/rfcs#34, here is a rebase of my previous work implementing both:

  • Support for a new link: specifier
  • CLI flag --linkFileDependencies to override file: specifier handling.

Test plan

Did not port previous unit test back for now as the idea is to first discuss the implementation with @arcanis and @bestander. Code is very likely to change. Will happily add unit tests once the implementation looks OK.

After rebasing the PR, tests are currently failing (master is failing too so probably ok).

@bestander
Copy link
Member

Awesome!
Thanks

@arcanis
Copy link
Member

arcanis commented May 9, 2017

Great PR! Seems good to merge, except for the way you're accessing the command line parameter -
you should use the config object to store it, and retrieve it from there later (unless there's a reason why you can't?). Otherwise, it won't work properly with the .yarnrc command line arguments :)

@bestander bestander mentioned this pull request May 9, 2017
22 tasks
@bestander
Copy link
Member

ping @mgcrea, we'd love to have it in 0.25 that we plan to cut tomorrow

@benlangfeld
Copy link

@arcanis / @bestander Is there precedent for that storage in config that we could follow?

@arcanis
Copy link
Member

arcanis commented May 11, 2017

Sure, you can take a look at this commit, for example. You just have to use getOption in the Config's init() method to set the variable to the right value, and after that you can access it from the config object (usually available via this.config).

@benlangfeld
Copy link

@arcanis Is this what you had in mind?

@arcanis
Copy link
Member

arcanis commented May 11, 2017

@benlangfeld Not exactly, but not far! Look at the commit I just pushed if you're interested; basically, instead of adding a linkFileDependencies argument to the resolver, we just use the config object as source of truth.

@mgcrea I've added a test to make sure that everything works, and unfortunately it seems there's still a few issues (I quickly checked, and I think one of them is because the install command is trying to read the manifest from the location. The other one is inside the check command, which fails because it is trying to make sure that the package path exists, which might not be true if the link is a broken link, or if the link target has no package.json). Can you take a look at this?

Don't bother about the rebase, I'll fix them directly on Github before merging.

@bbrzoska
Copy link

I've tested this branch and the package name is not inferred from the path:

$ yarn add link:../i18n-import-webpack-plugin --dev
yarn add v0.25.0-0
[1/4] 🔍  Resolving packages...
error Package "@0.0.0" doesn't have a "name".

I have to run the following instead:

yarn add i18n-import-webpack-plugin@link:../i18n-import-webpack-plugin --dev

The first command works with file: specifier.

@arcanis
Copy link
Member

arcanis commented May 22, 2017

Ping @mgcrea ? 🙂

@mgcrea
Copy link
Contributor Author

mgcrea commented May 23, 2017

@arcanis I'll have a look today. Thanks for the patches.

@mgcrea mgcrea force-pushed the feat-884 branch 4 times, most recently from 7f3946f to 9210f9d Compare May 23, 2017 10:34
@mgcrea
Copy link
Contributor Author

mgcrea commented May 23, 2017

Did finish a first squash+rebase+update, had to add code since the functionality was broken by a few recent commits on master (mostly from the cli/commands/check.js related checks), I've kept the commit separated for now to ease the review of these new patches since initial commit. Some tests seems a bit hacky, but tried to keep the refactoring to a minimum.

Looks like my existing workflow is still broken on master, so I'll have to dig a bit deeper to make sure I have the relevant unit tests.

@bestander
Copy link
Member

Thanks, @mgcrea

@@ -37,6 +37,13 @@ export default class PackageFetcher {
const dest = this.config.generateHardModulePath(ref);

const remote = ref.remote;

// Mock metedata for linked dependencies
if (remote.type === 'link') {
Copy link
Member

Choose a reason for hiding this comment

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

Would it be a bit cleaner if LinkFetcher existed instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bestander iirc at the time I started to work on the feature, I had to diverge earlier in the stack so there were no use for a LinkFetcher. Might be worth revisiting though.

@mgcrea mgcrea force-pushed the feat-884 branch 5 times, most recently from 6a52f8b to ae00d87 Compare May 26, 2017 15:41
@mgcrea
Copy link
Contributor Author

mgcrea commented May 26, 2017

I think we're getting close to something "ready". I've fixed and added a unit-test for the issue encountered by @bazyli-brzoska. Test are OK, rebase done.

@bestander, regarding the package-fetcher.js patch, I tried again to use a LinkFetcher but it would have still required a lot of branching in PackageFetcher as we need to opt out cache entirely. So I decided against it (would lead to more LOCs & increased complexity).

Let me know if there is something else I can do.

@mgcrea mgcrea force-pushed the feat-884 branch 3 times, most recently from 50d81bc to 7ad1bec Compare May 27, 2017 15:13
@bestander
Copy link
Member

@mgcrea, I agree about the fetcher, makes sense to have an if block rather than more complexity.

@bestander
Copy link
Member

Amazing work, @mgcrea!
You've lead the whole feature from design to implementation.
I am sure quite a lot of people would want to use it if they know about it, do you want to post in the blog about it?

@bestander
Copy link
Member

It is ready to merge although windows tests fail:

__tests__\commands\install\integration.js (120.573s)
  ● creates a symlink to a non-existing directory when using the link: protocol
    Error: expect(received).toEqual(expected)
    
    Expected value to equal:
      "../baz"
    Received:
      "C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\yarn-install-link-1495898245160-0.05036491088610817\\baz\\"

@mgcrea
Copy link
Contributor Author

mgcrea commented May 30, 2017

@bestander can fix the tests (add a platform ternary) if you want.

Blogpost is a great idea, I'll try to come up with something.

@bestander
Copy link
Member

bestander commented May 30, 2017 via email

@@ -49,21 +49,33 @@ export async function verifyTreeCheck(
const dependenciesToCheckVersion: PackageToVerify[] = [];
if (rootManifest.dependencies) {
for (const name in rootManifest.dependencies) {
const version = rootManifest.dependencies[name];
// skip linked dependencies
const isLinkedDepencency = /^link:/i.test(version) || (/^file:/i.test(version) && config.linkFileDependencies);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bestander This is the last thing I don't really like, as regex testing feels a bit hackish, but I would need to change the parent method API to pass the proper type. So was unsure if it was worth it.

@mgcrea mgcrea force-pushed the feat-884 branch 3 times, most recently from 7370f51 to 38fb1b3 Compare May 30, 2017 12:16
@mgcrea
Copy link
Contributor Author

mgcrea commented May 30, 2017

I've fixed the tests for windows, (looks like the test are still failing there but for unrelated reasons).

@bestander bestander merged commit db5edea into yarnpkg:master May 30, 2017
@bestander
Copy link
Member

Thanks, yeah one test got broken earlier, investigating

@zertosh
Copy link
Member

zertosh commented May 30, 2017

https://github.com/zertosh/yarn-link-test is an example of how link breaks down due to Node's realpath module resolution (nodejs/node#3402)

@benlangfeld
Copy link

Much ❤️ to everyone involved here, particularly @mgcrea. You guys are awesome and this will make my team very happy. We owe you at least some drinks!

@benlangfeld
Copy link

@bestander I guess this will now go in 0.26.0? By the recent cadence of minor releases, that would likely be cut within the next two weeks. Is that a fair estimate?

@bestander
Copy link
Member

We plan to cut on Monday.
There are a couple of hi pri issues we want to fix before cutting 0.26.

@felixrabe
Copy link

So ... is this documented somewhere and/or example usage available?

Is

"my-package": "link:../some/path",  // package.depencencies entry

equivalent to

cd ../some/path
yarn link
cd -
yarn link my-package

?

@felixrabe
Copy link

felixrabe commented May 6, 2018

(Equivalent meaning: will both approaches result in the same symlink being present in ./node_modules?)

@jRichardeau
Copy link

Why is this feature not documented ? Can we use it safely ?

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.

8 participants