How to use npm-which - 5 common examples

To help you get started, we’ve selected a few npm-which examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spockjs / spockjs / integration-tests / utils.ts View on Github external
thing, it runs in ts-node as well.

  Either way, runners needs to be started with cache disabled,
  because the transform cache is only invalidated when the
  test files that use assertion blocks etc. change,
  but not when the babel plugin that transforms them changes.
*/

// paths

export const modulePath = (packageName: string) =>
  getInstalledPathSync(packageName, { local: true });

const tsconfigPath = resolve(__dirname, '..', 'tsconfig.json');

const tsNodePath = which(__dirname).sync('ts-node');

// babel / typescript helpers

/**
 * Preferred way to use JIT TypeScript compilation,
 * available when @babel/register is not required.
 * No further arguments or environment overrides required.
 * If JIT Babel compilation is also required,
 * fall back to the JitArgs/JitEnv this file exports as well.
 */
export const runWithTypescriptJit = (
  args: string[],
  options?: SpawnSyncOptions,
) => run(tsNodePath, ['--project', tsconfigPath, ...args], options);

export const requireBabelJitArgs = ['--require', '@babel/register'];
github okonet / lint-staged / test / findBin.spec.js View on Github external
it('should throw a helpful error if the cmd is present in pkg scripts', () => {
    const originalConsole = global.console
    global.console = makeConsoleMock()
    npmWhichMock.mockFn.mockImplementationOnce(() => {
      throw new Error()
    })

    expect(() => {
      findBin('lint')
    }).toThrow('Could not resolve binary for `lint`')
    expect(console.printHistory()).toMatchSnapshot()

    global.console = originalConsole
  })
github okonet / lint-staged / test / findBin.spec.js View on Github external
it('should resolve path to bin from cache for subsequent invocations', () => {
    npmWhichMock.mockFn.mockClear()
    findBin('my-cmd')
    expect(npmWhichMock.mockFn).toHaveBeenCalledTimes(1)
    findBin('my-cmd --arg')
    expect(npmWhichMock.mockFn).toHaveBeenCalledTimes(1)
  })
github boennemann / grunt-semantic-release / util / setup.js View on Github external
['git', 'grunt', 'travis'].forEach(function(module) {
  try {
    which(module);
  } catch (e) {
    console.log('ERROR: You need ' + module + ' installed and available in your PATH.');
    process.exit(0);
  }
});
github timoxley / npm-run / bin / npm-run.js View on Github external
if (program.version) {
    console.log(pkg.version)
    process.exit()
  }

  if (program.help) {
    displayHelp(pkg.name)
    process.exit()
  } else {
    displayHelp(pkg.name)
    process.exit(1)
  }
}

try {
  npmWhich.sync(process.argv[2], {cwd: process.cwd()})
} catch (err) {
  console.log(err.message)
  process.exit(1)
}

npmExec.spawn(process.argv[2], process.argv.slice(3), {stdio: 'inherit'})
  .on('error', function (err) {
    console.error(err.stack)
  })
  .on('close', function (code) {
    process.exit(code)
  })

function displayHelp (name) {
  console.log([
    'Usage: ' + name + ' command [...args]',

npm-which

Locate a program or locally installed node module's executable

MIT
Latest version published 8 years ago

Package Health Score

65 / 100
Full package analysis

Popular npm-which functions