Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// helpers
import callsBack from "./helpers/callsBack";
import initFixture from "./helpers/initFixture";
import normalizeRelativeDir from "./helpers/normalizeRelativeDir";
import yargsRunner from "./helpers/yargsRunner";
// file under test
import * as commandModule from "../src/commands/RunCommand";
const run = yargsRunner(commandModule);
jest.mock("../src/NpmUtilities");
jest.mock("../src/utils/output");
// silence logs
log.level = "silent";
const ranInPackages = testDir =>
NpmUtilities.runScriptInDir.mock.calls.reduce((arr, [script, cfg]) => {
const { args, directory } = cfg;
const dir = normalizeRelativeDir(testDir, directory);
arr.push([dir, script].concat(args).join(" "));
return arr;
}, []);
const ranInPackagesStreaming = testDir =>
NpmUtilities.runScriptInPackageStreaming.mock.calls.reduce((arr, [script, cfg]) => {
const { args, pkg } = cfg;
const dir = normalizeRelativeDir(testDir, pkg.location);
arr.push([dir, script].concat(args).join(" "));
return arr;
}, []);
if (!cbCalled) {
log.error('', 'cb() never called!')
console.error('')
log.error('', 'This is an error with npm itself. Please report this error at:')
log.error('', ' ')
writeLogFile()
}
if (code) {
log.verbose('code', code)
}
}
if (npm.config.loaded && npm.config.get('timing') && !wroteLogFile) writeLogFile()
if (wroteLogFile) {
// just a line break
if (log.levels[log.level] <= log.levels.error) console.error('')
log.error(
'',
[
'A complete log of this run can be found in:',
' ' + getLogFile()
].join('\n')
)
wroteLogFile = false
}
var doExit = npm.config.loaded && npm.config.get('_exit')
if (doExit) {
// actually exit.
if (exitCode === 0 && !itWorked) {
exitCode = 1
function exit (code, noLog) {
exitCode = exitCode || process.exitCode || code
var doExit = npm.config.get("_exit")
log.verbose("exit", [code, doExit])
if (log.level === "silent") noLog = true
if (code && !noLog) writeLogFile(reallyExit)
else rm("npm-debug.log", function () { rm(npm.tmp, reallyExit) })
function reallyExit() {
// truncate once it's been written.
log.record.length = 0
itWorked = !code
// just emit a fake exit event.
// if we're really exiting, then let it exit on its own, so that
// in-process stuff can finish or clean up first.
if (!doExit) process.emit("exit", code)
npm.spinner.stop()
}
Object.keys(process.env).forEach(function (name) {
if (name.indexOf(npm_config_prefix) !== 0) return
var val = process.env[name]
if (name === npm_config_prefix + 'loglevel') {
log.level = val
} else {
// add the user-defined options to the config
name = name.substring(npm_config_prefix.length)
this.opts[name] = val
}
}, this)
name: 'foo',
version: '1.2.1'
},
'1.2.3': BASE,
'1.2.4': {
name: 'foo',
version: '1.2.4'
},
'3.4.5': {
name: 'foo',
version: '3.4.5'
}
}
}
npmlog.level = process.env.LOGLEVEL || 'silent'
const OPTS = {
registry: 'https://mock.reg',
log: npmlog,
retry: {
retries: 1,
factor: 1,
minTimeout: 1,
maxTimeout: 10
}
}
test('fetches packument from registry', t => {
const srv = tnock(t, OPTS.registry)
srv.get('/foo').reply(200, META)
return packument('foo', OPTS).then(meta => {
'use strict'
const getBuff = require('get-stream').buffer
const mockTar = require('./util/mock-tarball')
const npa = require('npm-package-arg')
const npmlog = require('npmlog')
const test = require('tap').test
const tnock = require('./util/tnock')
require('./util/test-dir')(__filename)
const fetch = require('../lib/fetch')
npmlog.level = process.env.LOGLEVEL || 'silent'
const OPTS = {
log: npmlog,
registry: 'https://my.mock.registry/',
retry: {
retries: 1,
factor: 1,
minTimeout: 1,
maxTimeout: 10
}
}
test('basic tarball streaming', function (t) {
const pkg = {
'package.json': JSON.stringify({
name: 'foo',
version: '1.2.3'
function runCmd (note, cmd, pkg, env, stage, wd, unsafe, cb) {
if (running) {
queue.push([note, cmd, pkg, env, stage, wd, unsafe, cb])
return
}
running = true
log.pause()
var user = unsafe ? null : npm.config.get("user")
, group = unsafe ? null : npm.config.get("group")
if (log.level !== 'silent') {
if (npm.spinner.int) {
npm.config.get("logstream").write("\r \r")
}
console.log(note)
}
log.verbose("unsafe-perm in lifecycle", unsafe)
if (process.platform === "win32") {
unsafe = true
}
if (unsafe) {
runCmd_(cmd, pkg, env, wd, stage, unsafe, 0, 0, cb)
} else {
uidNumber(user, group, function (er, uid, gid) {
runCmd_(cmd, pkg, env, wd, stage, unsafe, uid, gid, cb)
function npmUsage (cb) {
npm.config.set("loglevel", "silent")
log.level = "silent"
console.log
( ["\nUsage: npm "
, ""
, "where is one of:"
, npm.config.get("long") ? usages()
: " " + wrap(Object.keys(npm.commands))
, ""
, "npm -h quick help on "
, "npm -l display full usage info"
, "npm faq commonly asked questions"
, "npm help search for help on "
, "npm help npm involved overview"
, ""
, "Specify configs in the ini-formatted file:"
, " " + npm.config.get("userconfig")
, "or on the command line via: npm --key value"
'use strict';
let dbcheck = require('../../lib/dbcheck');
let log = require('npmlog');
let path = require('path');
let fs = require('fs');
log.level = 'verbose';
if (process.env.NODE_ENV === 'production') {
log.error('sqlinit', 'This script does not run in production');
process.exit(1);
}
if (process.env.NODE_ENV === 'test' && !fs.existsSync(path.join(__dirname, '..', '..', 'config', 'test.toml'))) {
log.error('sqlinit', 'This script only runs in test if config/test.toml (i.e. a dedicated test database) is present');
process.exit(1);
}
dbcheck(err => {
if (err) {
log.error('DB', err);
return process.exit(1);
}
coerce: (level) => {
log.level = level
return level
},
})