Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Conversation

andrewbranch
Copy link
Contributor

What

The npm postinstall script runs both on local npm install as well as after being installed as a dependency of someone else’s project. The prepare script only runs on local npm install (and before publishing). [npm-scripts]

Why

vscode is a devDependency, not a dependency, so if someone tries to install this package as a dependency of their own, the installation fails because ./node_modules/vscode does not exist.

Wait, what?

I’m the maintainer of gatsby-remark-vscode, a plugin for the Gatsby static site system that lets blog authors harness VS Code’s syntax highlighting engine to style their code blocks. In the plugin’s v2, currently under development and released in alpha, I’m encouraging users to npm install any language and theme packages they need directly from GitHub, provided the source is licensed appropriately. One user (@janosh) tried this method on this package (yarn add styled-components/vscode-styled-components), only to find that it can’t be installed since it tries unsuccessfully to set itself up for development/testing (andrewbranch/gatsby-remark-vscode#69).

@julienp
Copy link
Collaborator

julienp commented Jan 14, 2020

Thank you for the clear explanation and the fix!

@julienp julienp merged commit 9a24df8 into styled-components:master Jan 14, 2020
@andrewbranch andrewbranch deleted the patch-1 branch January 14, 2020 17:54
@janosh
Copy link
Contributor

janosh commented Jan 14, 2020

@julienp Thanks for the quick merge!

tmr08c added a commit to tmr08c/vscode-elixir that referenced this pull request Nov 21, 2020
The npm `postinstall` script runs both on local npm install as well as
after being installed as a dependency of someone else’s project. The
`prepare` script only runs on local npm install (and before publishing).
[npm-scripts](https://docs.npmjs.com/cli/v6/using-npm/scripts)

`vscode` is a `devDependency`, not a `dependency`, so if someone tries to
install this package as a dependency of their own, the installation
fails because `./node_modules/vscode` does not exist.

One example of where it may be useful to install the package directly
would be when using something like
[andrewbranch/gatsby-remark-vscode](https://github.com/andrewbranch/gatsby-remark-vscode)
which uses VS Code syntax highlighting and themes to generate the syntax
highlighting in Gatsby sites.

The `postinstall` to `prepare` change is
[suggested](andrewbranch/gatsby-remark-vscode#129)
by the author of the Gatsby plugin as a way to work with languates that
aren't supported by VS Code out-of-the-box.

This change seems to have works successfully in the past for other VS
Code extensions as well:

* juanfranblanco/vscode-solidity#186
* styled-components/vscode-styled-components#203
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.

3 participants