Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'];
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
})
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)
})
['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);
}
});
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]',