diff --git a/index.js b/index.js index 5447643e04b66..570df352b9d4b 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,4 @@ -if (require.main === module) { +if (require.main === module) require('./lib/cli.js')(process) -} else { +else throw new Error('The programmatic API was removed in npm v8.0.0') -} diff --git a/package.json b/package.json index 1e07ffdbd6dc6..7735df88a7955 100644 --- a/package.json +++ b/package.json @@ -220,7 +220,7 @@ "sudotest:nocleanup": "sudo NO_TEST_CLEANUP=1 npm run test --", "posttest": "npm run lint", "eslint": "eslint", - "lint": "npm run eslint -- test/lib test/bin bin lib scripts docs smoke-tests", + "lint": "npm run eslint -- bin docs lib scripts smoke-tests test ./*.js", "lintfix": "npm run lint -- --fix", "prelint": "rimraf test/npm_cache*", "resetdeps": "bash scripts/resetdeps.sh", diff --git a/test/fixtures/mock-npm.js b/test/fixtures/mock-npm.js index b23b6e55b2554..0a7bc0e8ad8f0 100644 --- a/test/fixtures/mock-npm.js +++ b/test/fixtures/mock-npm.js @@ -26,7 +26,7 @@ const RealMockNpm = (t, otherMocks = {}) => { } const Npm = t.mock('../../lib/npm.js', otherMocks) class MockNpm extends Npm { - constructor() { + constructor () { super() for (const level in npmlog.levels) { npmlog[level] = (...msg) => { @@ -79,9 +79,8 @@ class MockNpm { const config = base.config || {} for (const attr in base) { - if (attr !== 'config') { + if (attr !== 'config') this[attr] = base[attr] - } } this.flatOptions = base.flatOptions || {} @@ -91,7 +90,7 @@ class MockNpm { find: (k) => ({...realConfig.defaults, ...config})[k], get: (k) => ({...realConfig.defaults, ...config})[k], set: (k, v) => config[k] = v, - list: [{ ...realConfig.defaults, ...config}] + list: [{ ...realConfig.defaults, ...config}], } if (!this.log) { this.log = { @@ -110,7 +109,7 @@ class MockNpm { } } - output(...msg) { + output (...msg) { if (this.base.output) return this.base.output(msg) this._mockOutputs.push(msg) @@ -118,10 +117,10 @@ class MockNpm { } const FakeMockNpm = (base = {}) => { - return new MockNpm(base) + return new MockNpm(base) } module.exports = { fake: FakeMockNpm, - real: RealMockNpm + real: RealMockNpm, } diff --git a/test/fixtures/sandbox.js b/test/fixtures/sandbox.js index 7c57e8d8bc88e..626e2ab5c509c 100644 --- a/test/fixtures/sandbox.js +++ b/test/fixtures/sandbox.js @@ -6,16 +6,17 @@ const { promisify } = require('util') const mkdirp = require('mkdirp-infer-owner') const npmlog = require('npmlog') const rimraf = promisify(require('rimraf')) -const t = require('tap') -let active = null const chain = new Map() const sandboxes = new Map() +// Disable lint errors for assigning to process global +/* global process:writable */ + // keep a reference to the real process const _process = process -const processHook = createHook({ +createHook({ init: (asyncId, type, triggerAsyncId, resource) => { // track parentage of asyncIds chain.set(asyncId, triggerAsyncId) @@ -23,9 +24,8 @@ const processHook = createHook({ before: (asyncId) => { // find the nearest parent id that has a sandbox let parent = asyncId - while (chain.has(parent) && !sandboxes.has(parent)) { + while (chain.has(parent) && !sandboxes.has(parent)) parent = chain.get(parent) - } process = sandboxes.has(parent) ? sandboxes.get(parent) @@ -173,7 +173,7 @@ class Sandbox extends EventEmitter { if (this[_npm]) { // replace default config values with placeholders for (const name of redactedDefaults) { - let value = this[_npm].config.defaults[name] + const value = this[_npm].config.defaults[name] clean = clean.split(value).join(`{${name.toUpperCase()}}`) } @@ -201,21 +201,19 @@ class Sandbox extends EventEmitter { // test.teardown hook teardown () { - if (this[_parent]) { + if (this[_parent]) sandboxes.delete(this[_parent]) - } + return rimraf(this[_dirs].temp).catch(() => null) } // proxy get handler [_get] (target, prop, receiver) { - if (this[_data].has(prop)) { + if (this[_data].has(prop)) return this[_data].get(prop) - } - if (this[prop] !== undefined) { + if (this[prop] !== undefined) return Reflect.get(this, prop, this) - } const actual = Reflect.get(target, prop, receiver) if (typeof actual === 'function') { diff --git a/test/index.js b/test/index.js index e23dc23136567..26db16e1f78ba 100644 --- a/test/index.js +++ b/test/index.js @@ -20,4 +20,3 @@ t.test('loading as main module will load the cli', t => { t.end() }) }) -