Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Is there a way in my package.json to tell JSPM not to install a specific dependency? #1070

Open
onlywei opened this issue Feb 1, 2018 · 14 comments

Comments

@onlywei
Copy link

onlywei commented Feb 1, 2018

For example, can I do something like this in my package.json?

{
  "name": "my-package",
  "dependencies": {
    "a": "^0.1.0",
    "b": "^2.3.5"
  },
  "jspm": {
    "dependencies": {
      "b": null
    }
  }
}

Such that when I do jspm install npm:my-package, I also want JSPM to install "a", but not "b"?

@aluanhaddad
Copy link
Collaborator

aluanhaddad commented Feb 3, 2018

Hi @onlywei

Yes indeed, using "@empty"

{
  "name": "my-package",
  "dependencies": {
    "a": "^0.1.0",
    "b": "^2.3.5"
  },
  "map": {
    "b": "@empty"
  }
}

A working example from the registry

@josephschmitt
Copy link

@aluanhaddad any idea if this is jspm 0.17.x only? We're on 0.16.47 and it's not working.

@onlywei
Copy link
Author

onlywei commented Feb 5, 2018

@aluanhaddad the working example you have provided and the written example you gave are inconsistent. One is using "map" an the other is using "dependencies". Which one is correct?

@aluanhaddad
Copy link
Collaborator

@onlywei I figured that out trying to answer @josephschmitt's question.

Total fail on my part.

"map": {
  "dep": "@empty"
}

works correctly and in both 0.17 and master.

@josephschmitt
Copy link

@aluanhaddad ok sorry, just to confirm, in the package with the dependency, I add this "map" key in the root of the package.json? Not inside "jspm"? So it would be:

{
  "name": "my-package",
  "dependencies": {
    "my-unwanted-dep": "1.0.0"
  },
  "map": {
    "my-unwanted-dep": "@empty"
  }
}

@aluanhaddad
Copy link
Collaborator

aluanhaddad commented Feb 5, 2018

Yes, just like you have it there. Note I tested with the master branch, not with 0.16.47.
It feels like a bug that it doesn't work in the nested "jspm" section.

Sorry for the confusion.

I'm going to leave this issue open to track that bug.

@josephschmitt
Copy link

@aluanhaddad ok. Doesn't seem to work with 0.16.47 at all, either in the root or nested in "jspm". Hopefully we can figure out why at some point. Thanks

@aluanhaddad
Copy link
Collaborator

looking into it now

@onlywei
Copy link
Author

onlywei commented Feb 14, 2018

@aluanhaddad I'm also experiencing that it does not work in the root nor nested in "jspm". Maybe I can try upgrading.

@onlywei
Copy link
Author

onlywei commented Feb 15, 2018

I just upgraded to 0.16.53 and I am not seeing a difference. Using "@empty" does not seem to have any effect at all.

@aluanhaddad
Copy link
Collaborator

@onlywei, @josephschmitt sorry for not replying sooner.

I have created a package, to demonstrate that this works. You can find it at https://github.com/aluanhaddad/jspm-registry-1070

The package has two dependencies, jsdom, and jquery.

I have used "map" to specify that JSPM users should not install the dependency on jsdom.

To test, run

$ jspm install github:aluanhaddad/jspm-registry-1070

Observe that jsdom is not installed, but jquery is.

Then run

$ npm install aluanhaddad/jspm-registry-1070

Observe that jsdom and jquery are both installed.

Let me know if this helps

@josephschmitt
Copy link

@aluanhaddad thanks, we were finally able to get this working for the most part, closing out this issue.

However, I do want to bring attention to a new issue I'm going to create soon related to this. It seems that if we use this technique of setting @empty, but do so on a dependency which we're not installing in our target app but instead use the sytemjs config's "paths" option, then it'll actually re-write the dependency as import * from '@empty', which then throws errors.

Not sure if this project is the right place to file this issue, but I'll work on creating a stand-alone reproducible example in the mean time I can link you to.

Thanks again for your help.

@josephschmitt
Copy link

@aluanhaddad here's the new issue I've filed #1072
Additionally, I've set up this repo as a way to easily reproduce the bug we're seeing https://github.com/josephschmitt/jspm-empty-demo

Let me know if someone is able to help out.

@guybedford
Copy link
Member

Yup this is definitely a bug. I'm not sure what the best fix would be though.

Note that jspm 0.17 fixed up a lot of these sorts of mapping cases, it may be worth trying that version if you can.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants