I would like to create a package.json build script that executes slightly different set of commands when run from Windows, Linux, Mac.

The problem is that I cannot find a way to put it in package.json file that will run without problems at every system.

Here is an example that I would like to have:

"scripts" : {
    "build.windows" : "echo do windows specific stuff",
    "build.linux" : "echo do linux specific stuff",
    "build.mac" : "echo do mac specific stuff",
    "build" : "??????????????" <- what to put here to execute script designed for OS
                                  on which npm is running
}

It depends on exactly what you're trying to do in the scripts, but it's likely that you can use npm cli packages to effectively add cross-platform commands to any shell.

For example, if you wanted to delete a directory, you could use separate syntaxes for windows and linux:

rm -rf _site     # bash
rd /s /q _site   # cmd

Or instead, you could use the npm package rimraf which works cross platform:

npx rimraf _site

To take Dave P's example above, you could set environment variables with cross-env like this:

"scripts": {
    "test": "npx cross-env NODE_ENV=test mocha",
}

And if you don't want to use npx to install scripts live, you can install them globally ahead of time like this:

npm i cross-env -g

Here's a post I wrote on making NPM scripts work cross platform which explores some of these options