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

bin/package-unlink unlinks all packages instead of the one that was specified #6248

Closed
3 tasks done
loan-laux opened this issue May 19, 2020 · 9 comments · Fixed by #6266
Closed
3 tasks done

bin/package-unlink unlinks all packages instead of the one that was specified #6248

loan-laux opened this issue May 19, 2020 · 9 comments · Fixed by #6266
Labels
bug For issues that describe a defect or regression in the released software priority medium severity low verified reproducible For issues that describe bugs that the core team was able to confirm

Comments

@loan-laux
Copy link
Collaborator

Prerequisites

  • Are you running the latest version?
  • Are you able to consistently reproduce the issue?
  • Did you search the issue queue for existing issue? Search issues

Issue Description

Running bin/package-unlink some-plugin (works for all plugins) seems to unlink all plugins and not just some-plugin. This is the case regardless of whether the plugin was linked with bin/package-link beforehand or not.

Steps to Reproduce

  1. Link a plugin with bin/package-link some-plugin, then link another plugin with bin/package-link other-plugin.
  2. Open a shell on your API container with docker exec -it reaction_api_1 bash.
  3. In your container's shell, go to /usr/local/src/app/node_modules/@reactioncommerce.
  4. Still in your container's shell, run ls -la. Notice you have two symlinks in place: one for some-plugin and another for other-plugin.
  5. On your host machine, run bin/package-unlink some-plugin to unlink some-plugin.
  6. Back into your container's shell, run ls-ls. Notice that both some-plugin and other-plugin were unlinked.

Possible Solution

No idea. Is this even on Reaction's side or is it an NPM issue?

@loan-laux loan-laux added bug For issues that describe a defect or regression in the released software needs triage For issues that are awaiting triage by the core development team priority medium severity low verified reproducible For issues that describe bugs that the core team was able to confirm and removed needs triage For issues that are awaiting triage by the core development team labels May 19, 2020
@aldeed
Copy link
Contributor

aldeed commented May 20, 2020

This is yucky. This is indeed an npm unlink issue, and there's an accepted RFC to make it work correctly here: https://github.com/npm/rfcs/blob/latest/accepted/0011-npm-link-changes.md

But it seems that won't be until at least npm@7.

I've experimented a bunch and there appear to be a few different bugs. Some I can fix. I have a draft PR here: #6251

I'd like to also figure out a way to maintain the other links when unlinking one, but I think we'd have to create a file to track the links and re-create them all in the unlink script after unlinking. In other words, essentially write our own version of the NPM RFC proposal.

A bigger concern is that I am seeing that often, after I link a second package, the code from the first package is no longer executing, even though the symlink is still there and the symlinked files have the changes. It's like there's a different version of the package also installed somewhere in the node_modules tree, and the import() is finding that one instead. So far I haven't figured out what's going on.

@loan-laux
Copy link
Collaborator Author

@aldeed The implementation of this RFC can't come soon enough! Things will be a lot better when this will be available for us to use.

As for your last paragraph, do your symptoms match by any chance what I've noted at #6250?

@aldeed
Copy link
Contributor

aldeed commented May 20, 2020

@loan-laux Yes! I hadn't thought about the cache. I don't know why that would override what's actually there but it's an idea to explore.

@mikemurray
Copy link
Member

I'm also seeing issues where package-unlink things a package isn't symlinked, even though it most definitely is.

npm link and docker are very problematic together that I'd rather see us use something else like yalc (https://github.com/whitecolor/yalc). I've tested with the new admin at the start and it was far less buggy.

@loan-laux
Copy link
Collaborator Author

@mikemurray Since @aldeed's latest changes, I've found that I needed to use bin/package-unlink @reactioncommerce/package-name instead of just bin/package-unlink package-name. Did this occur in both cases?

However, I do agree that Yalc looks like a much better solution. This looks like what we should implement!

@mikemurray
Copy link
Member

@loan-laux your suggestion worked for me. I think there was a disconnect for me between the plugin name used during the link is different than the unlink.

I think a quick fix to the current script could be, either an error message suggesting Did you mean @reactioncommerce/plugin_name or trying @reactioncommerce/$plugin_name first if there's no prefix, then fallback to previous logic.

@loan-laux
Copy link
Collaborator Author

@mikemurray 100% agreed.

@aldeed
Copy link
Contributor

aldeed commented Jun 2, 2020

Definitely should be using the full pkg name for both link and unlink now. It's done that way so that non-Reaction pkgs can be linked, too. But I agree there could be ways to add sanity checks.

I think it would also be easy to add a flag or something telling it to use yalc instead of link. Most of the script other than the link command would be the same (if I'm understanding yalc). Only problem is I think you'd need to update the node-dev Docker images to have yalc preinstalled.

@mikemurray
Copy link
Member

This past week, I've been running the yalc commands locally and have it do it's thing. Everything seems to work fine, but this does mean that you have to globally install yalc. Since we run package-link and package-unlink out side of docker it should be fine, but I can't be sure until we try.

The steps I've used for linking packages and running tests.

# Install yalc globally
npm i -g yalc

# Go you the plugin, or package you want to publish
cd api-plugin-<name>/

# Publish package
yalc publish

# Go to reaction
cd reaction/

# Publish (use one of the following, preferably link)
yalc link @reactioncommerce/api-plugin-<name> # Safer, doesn't add to package.json
yalc add @reactioncommerce/api-plugin-<name> # Adds to package.json so be careful

# Make changes in the package and republish
cd api-plugin-<name>/
yalc push # Publishes and auto updates reaction (or any project that contains this as yalc dependency)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For issues that describe a defect or regression in the released software priority medium severity low verified reproducible For issues that describe bugs that the core team was able to confirm
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants