How to use the sync function from cross-spawn

Find comprehensive JavaScript cross-spawn.sync code examples handpicked from public code repositorys.

71
72
73
74
75
76
77
78
79
80
const checkThatNpmCanReadCwd = function ()
{
    const cwd = process.cwd();
    let childOutput = null;
    try {
        childOutput = spawn.sync("npm", ["config", "list"]).output.join("");
    } catch (err) {
        return true;
    }

fork icon1
star icon1
watch icon1

89
90
91
92
93
94
95
96
97
98
getAvailablePackageManagers() {
    const { sync } = require("cross-spawn");
    const installers = ["npm", "yarn", "pnpm"];
    const hasPackageManagerInstalled = (packageManager) => {
        try {
            sync(packageManager, ["--version"]);
            return packageManager;
        }
        catch (err) {
            return false;
fork icon0
star icon0
watch icon1

+ 7 other calls in file

996
997
998
999
1000
1001
1002
1003
1004
1005
  // Note: intentionally using spawn over exec since
  // the problem doesn't reproduce otherwise.
  // `npm config list` is the only reliable way I could find
  // to reproduce the wrong path. Just printing process.cwd()
  // in a Node process was not enough.
  childOutput = spawn.sync('npm', ['config', 'list']).output.join('');
} catch (err) {
  // Something went wrong spawning node.
  // Not great, but it means we can't do this check.
  // We might fail later on, but let's continue.
fork icon0
star icon0
watch icon1

+ 4 other calls in file