Skip to main content

Allow to add OS-specific scripts in your package.json!

This package works with Bun, Node.js, DenoIt is unknown whether this package works with Cloudflare Workers, Browsers
JSR Score
100%
Published
3 weeks ago (1.5.0)

cross-os

npm version npm downloads

OS Specific npm scripts! Ideal for tasks that differs across Operating System Platforms

Install

$ npm install cross-os --save-dev

Usage

Add scripts to your package.json like so:

  • it supports darwin, freebsd, linux, sunos or win32
{
    "scripts": {
        "foo": "cross-os bar",
        "bar": {
            "darwin": "echo 'i will only run on Mac'",
            "win32": "echo 'i will only run on Windows'",
            "linux": "echo 'i will only run on Linux'"
        }
    }
}

And call it like:

npm run foo

Alternatively you can also specify scripts on its own section in your package.json

{
    "scripts": {
        "foo": "cross-os bar"
    },
    "cross-os": {
        "bar": {
            "darwin": "echo 'i will only run on Mac'",
            "win32": "echo 'i will only run on Windows'",
            "linux": "echo 'i will only run on Linux'"
        }
    }
}

You also can pass args to the underlying script like this:

{
    "scripts": {
        "foo": "cross-os bar -- arg1 arg2"
    },
    "cross-os": {
        "bar": {
            "darwin": "echo received arg: ",
            "win32": "echo received arg: ",
            "linux": "echo received arg: "
        }
    }
}

or directly from the npm run script like this:

npm run foo -- arg1 arg2

License

MIT © Rafael Milewski

Add Package

deno add @milewski/cross-os

Import symbol

import * as mod from "@milewski/cross-os";

Add Package

npx jsr add @milewski/cross-os

Import symbol

import * as mod from "@milewski/cross-os";

Add Package

yarn dlx jsr add @milewski/cross-os

Import symbol

import * as mod from "@milewski/cross-os";

Add Package

pnpm dlx jsr add @milewski/cross-os

Import symbol

import * as mod from "@milewski/cross-os";

Add Package

bunx jsr add @milewski/cross-os

Import symbol

import * as mod from "@milewski/cross-os";