From 5f4040aa0e30a3b74caab64958770c682e4d0031 Mon Sep 17 00:00:00 2001 From: Yucel Okcu Date: Fri, 19 Nov 2021 11:43:07 +0300 Subject: [PATCH] chore: remove get-project-scope utils --- lib/npm.js | 5 --- lib/utils/get-project-scope.js | 19 ------------ test/lib/utils/get-project-scope.js | 48 ----------------------------- 3 files changed, 72 deletions(-) delete mode 100644 lib/utils/get-project-scope.js delete mode 100644 test/lib/utils/get-project-scope.js diff --git a/lib/npm.js b/lib/npm.js index ecc7f0a7de206..0096e0ac59e06 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -38,7 +38,6 @@ const which = require('which') const deref = require('./utils/deref-command.js') const setupLog = require('./utils/setup-log.js') const cleanUpLogFiles = require('./utils/cleanup-log-files.js') -const getProjectScope = require('./utils/get-project-scope.js') let warnedNonDashArg = false const _load = Symbol('_load') @@ -249,10 +248,6 @@ class Npm extends EventEmitter { this.config.set('scope', `@${configScope}`, this.config.find('scope')) } process.emit('timeEnd', 'npm:load:configScope') - - process.emit('time', 'npm:load:projectScope') - this.projectScope = this.config.get('scope') || getProjectScope(this.prefix) - process.emit('timeEnd', 'npm:load:projectScope') } get flatOptions () { diff --git a/lib/utils/get-project-scope.js b/lib/utils/get-project-scope.js deleted file mode 100644 index dc1b4deba3dc2..0000000000000 --- a/lib/utils/get-project-scope.js +++ /dev/null @@ -1,19 +0,0 @@ -const { resolve } = require('path') -module.exports = prefix => { - try { - const { name } = require(resolve(prefix, 'package.json')) - if (!name || typeof name !== 'string') { - return '' - } - - const split = name.split('/') - if (split.length < 2) { - return '' - } - - const scope = split[0] - return /^@/.test(scope) ? scope : '' - } catch (er) { - return '' - } -} diff --git a/test/lib/utils/get-project-scope.js b/test/lib/utils/get-project-scope.js deleted file mode 100644 index 9737b06433c22..0000000000000 --- a/test/lib/utils/get-project-scope.js +++ /dev/null @@ -1,48 +0,0 @@ -const getProjectScope = require('../../../lib/utils/get-project-scope.js') -const t = require('tap') - -t.test('package.json with scope', t => { - const dir = t.testdir({ - 'package.json': JSON.stringify({ name: '@foo/bar' }), - }) - t.equal(getProjectScope(dir), '@foo') - t.end() -}) - -t.test('package.json with slash, but no @', t => { - const dir = t.testdir({ - 'package.json': JSON.stringify({ name: 'foo/bar' }), - }) - t.equal(getProjectScope(dir), '') - t.end() -}) - -t.test('package.json without scope', t => { - const dir = t.testdir({ - 'package.json': JSON.stringify({ name: 'foo' }), - }) - t.equal(getProjectScope(dir), '') - t.end() -}) - -t.test('package.json without name', t => { - const dir = t.testdir({ - 'package.json': JSON.stringify({}), - }) - t.equal(getProjectScope(dir), '') - t.end() -}) - -t.test('package.json not JSON', t => { - const dir = t.testdir({ - 'package.json': 'hello', - }) - t.equal(getProjectScope(dir), '') - t.end() -}) - -t.test('no package.json', t => { - const dir = t.testdir({}) - t.equal(getProjectScope(dir), '') - t.end() -})