Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.run = function (basedir) {
// TODO: change the name to "gagarin" when the meta package is ready
var packageName = 'gagarin-core';
utils.stopOnFirstSuccess([
resolve.bind({}, packageName, { basedir: basedir }),
resolve.bind({}, packageName, { basedir: path.join(basedir, 'tests') }),
resolve.bind({}, packageName, { basedir: path.join(basedir, 'test') }),
utils.promiseAsThunk(findUp.bind({}, 'lib/gagarin.js')),
], function (err, pathToGagarin) {
if (err || !pathToGagarin) {
console.log(chalk.red('gagarin-cli:'), 'Unable to find local gagarin.');
if (err) {
console.log(chalk.red('gagarin-cli:'), err.stack);
}
return;
}
console.log(chalk.green('gagarin-cli:'),
'Found local gagarin at: ' + chalk.magenta(pathToGagarin));
require(pathToGagarin).cli(basedir).catch(function (err) {
console.log(chalk.red('gagarin-cli:'), err.stack);
const npath = rootPath || '*'
if (pkgs[npath]) return pkgs[npath]
const findUp = require('find-up')
let obj = {}
try {
let startDir = rootPath || require('require-main-filename')(parentRequire || require)
// When called in an environment that lacks require.main.filename, such as a jest test runner,
// startDir is already process.cwd(), and should not be shortened.
// Whether or not it is _actually_ a directory (e.g., extensionless bin) is irrelevant, find-up handles it.
if (!rootPath && path.extname(startDir)) {
startDir = path.dirname(startDir)
}
const pkgJsonPath = findUp.sync('package.json', {
cwd: startDir
})
obj = JSON.parse(fs.readFileSync(pkgJsonPath))
} catch (noop) {}
pkgs[npath] = obj || {}
return pkgs[npath]
}
/* global process require */
// there seems to be a bug in yarn whereby forwarding arguments with -- like so:
// $ yarn monorun [...] -- --foo
// results in [...] being stripped away; can workaround with:
// $ yarn monorun -- [...] -- --foo
// but note that yarn warns about a future behavioral change re: yarn and --
const {dirname} = require('path');
const {spawn} = require('child_process');
const {sync: findUp} = require('find-up');
const minimist = require('minimist');
const monorepoRootPath = dirname(findUp('lerna.json'));
let cliArgs = process.argv.slice(2);
const options = minimist(
cliArgs,
{boolean: [
'include-filtered-dependents',
'include-filtered-dependencies',
'no-bail',
'no-prefix',
'no-private',
'no-progress',
'no-sort',
'parallel',
'reject-cycles',
'stream'
import { readFileSync } from 'fs';
import findUp from 'find-up';
let options;
const pkgPath = findUp.sync('package.json');
// Read compiler options from `package.json`.
if (pkgPath) {
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
options = pkg['svelte:compiler'];
}
Plugin.registerCompiler({
extensions: (options && options.extensions) || [
'html',
'svelte'
]
}, () => new SvelteCompiler(options));
export async function eventNextPlugins(
dir: string
): Promise> {
try {
const packageJsonPath = await findUp('package.json', { cwd: dir })
if (!packageJsonPath) {
return []
}
const { dependencies = {}, devDependencies = {} } = require(packageJsonPath)
const deps = { ...devDependencies, ...dependencies }
return Object.keys(deps).reduce(
(events: NextPluginsEvent[], plugin: string): NextPluginsEvent[] => {
const version = deps[plugin]
// Don't add deps without a version set
if (!version) {
return events
}
export async function compileWithTruffle(): Promise {
Loggy.spin(
__filename,
'compileWithTruffle',
`compile-contracts`,
'Compiling contracts with Truffle, using settings from truffle.js file',
);
// Attempt to load global truffle if local was not found
const truffleBin: string = (await findUp('node_modules/.bin/truffle')) || 'truffle';
let stdout: string, stderr: string;
try {
const args: object = { shell: true };
({ stdout, stderr } = await execFile(truffleBin, ['compile', '--all'], args));
} catch (error) {
if (error.code === 127) {
Loggy.fail(
'compile-contracts',
'Could not find truffle executable. Please install it by running: npm install truffle',
);
({ stdout, stderr } = error);
throw error;
}
} finally {
Loggy.succeed(`compile-contracts`);
test('init without an existing package.json will fail', () => {
mockFindUp.mock.syncFail = true
mockFindUp.mock.syncReturn = undefined
const result = parse('init')
expect(result).toBe(undefined)
expect(mockReadLine.keyInYN).toHaveBeenCalledTimes(0)
expect(mockGetLogger.mock.error).toHaveBeenCalledWith(
expect.stringMatching(/Unable/),
)
delete mockFindUp.mock.syncFail
delete mockReadLine.mock.keyInYNReturn
delete mockFindUp.mock.syncReturn
})
test('init without an existing package.json will fail', () => {
mockFindUp.mock.syncFail = true
mockFindUp.mock.syncReturn = undefined
const result = parse('init')
expect(result).toBe(undefined)
expect(mockReadLine.keyInYN).toHaveBeenCalledTimes(0)
expect(mockGetLogger.mock.error).toHaveBeenCalledWith(
expect.stringMatching(/Unable/),
)
delete mockFindUp.mock.syncFail
delete mockReadLine.mock.keyInYNReturn
delete mockFindUp.mock.syncReturn
})
test('with CLI config', () => {
mockFindUp.mock.cliReturn = '/path/to/.npsrc'
mockBinUtils.mock.cliConfig = {
require: 'ts-node/register',
config: 'package-scripts.ts',
}
const {argv, psConfig} = parse('"build --fast"')
expect(mockBinUtils.loadConfig).toHaveBeenCalledTimes(1)
expect(mockBinUtils.loadCLIConfig).toHaveBeenCalledTimes(1)
expect(psConfig.isMock).toBe(true)
expect(argv).toEqual(
expect.objectContaining({
_: [`\"build --fast\"`],
require: 'ts-node/register',
config: 'package-scripts.ts',
}),
)
initialize: jest.fn(() => {
if (mockFindUp.mock.syncFail) {
return undefined
}
return {
packageScriptsPath: '/path/to/package-scripts.js',
packageJsonPath: '/path/to/package.json',
}
}),
help: jest.fn(),