isaacs/npm — Issue #2006: Feature: Support for OS-specific "scripts" properties in package.json
Author: clintharris
Created: 2012-01-07 20:17:02+00:00
State: open

It's hard to find a cross-OS way to run commands like install, start, test, etc., without using an intermediary Node script to do conditional platform-checking and spawning, etc. For example, many people have "install" reference a make file; it would be nice to offer a .bat file version for win32 support.

There was a [discussion](https://groups.google.com/forum/#!searchin/npm-/overlay/npm-/N0WspLh5pII/O3S5v9UIrl0J) about this in November--not sure if anything happened with it... [Isaac suggested](https://groups.google.com/d/msg/npm-/N0WspLh5pII/tEG2geYeu1MJ) the following:

> Here's a proposal, just a straw man to get it started. If there's no objection, we can go with this, and see how it works:

```javascript
{ ...
, "overlay":
{ "win32": { "dependencies": { ... }, "scripts": { ... } }
}
```
> So, it would only be allowed for hash-type fields (not description, name, version, and other "string" things), and would fold in rather than overwrite. Setting something to "null" should delete it from the hash.
>
> So, if you had this:

```javascript
{ "name": "foo"
, "version": "1.2.3"
, "bin": { "foo": "./bin/foo.js", "foo-bar": "./bin/bar.js" }
, "scripts": { "install": "make install }
, "dependencies": { "baz": "1.2.7", "blerg": "1.5.3" }
, "overlay":
{ "win32":
{ "bin": { "foo-bar": null }
, "scripts": { "preinstall": "win-configure.bat", "install":
"win-make.bat" }
, "dependencies": { "blerg": "1.4.7" }
}
}
}
```
> this would result on windows as:

```javascript
{ "name": "foo"
, "version": "1.2.3"
, "bin": { "foo": "./bin/foo.js" } // foo-bar removed
, "scripts":
{ "preinstall": "win-configure.bat" // added
, "install": "win-make.bat" // changed
}
, "dependencies": { "baz": "1.2.7", "blerg": "1.4.7" } // blerg modified
}
```