A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/npm/cli/commit/885accdc750dd45fc9e4b5faf11bcc81292e17ad below:

only replace hostname for resolved URL (#8185) · npm/cli@885accd · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+64

-17

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+64

-17

lines changed Original file line number Diff line number Diff line change

@@ -8,7 +8,6 @@ const semver = require('semver')

8 8

const debug = require('../debug.js')

9 9

const { walkUp } = require('walk-up-path')

10 10

const { log, time } = require('proc-log')

11 -

const hgi = require('hosted-git-info')

12 11

const rpj = require('read-package-json-fast')

13 12 14 13

const { dirname, resolve, relative, join } = require('node:path')

@@ -833,21 +832,23 @@ module.exports = cls => class Reifier extends cls {

833 832

// ${REGISTRY} or something. This has to be threaded through the

834 833

// Shrinkwrap and Node classes carefully, so for now, just treat

835 834

// the default reg as the magical animal that it has been.

836 -

const resolvedURL = hgi.parseUrl(resolved)

837 - 838 -

if (!resolvedURL) {

835 +

try {

836 +

const resolvedURL = new URL(resolved)

837 + 838 +

if ((this.options.replaceRegistryHost === resolvedURL.hostname) ||

839 +

this.options.replaceRegistryHost === 'always') {

840 +

const registryURL = new URL(this.registry)

841 +

// Replace the host with the registry host while keeping the path intact

842 +

resolvedURL.hostname = registryURL.hostname

843 +

resolvedURL.port = registryURL.port

844 +

return resolvedURL.toString()

845 +

}

846 +

return resolved

847 +

} catch (e) {

839 848

// if we could not parse the url at all then returning nothing

840 849

// here means it will get removed from the tree in the next step

841 -

return

850 +

return undefined

842 851

}

843 - 844 -

if ((this.options.replaceRegistryHost === resolvedURL.hostname)

845 -

|| this.options.replaceRegistryHost === 'always') {

846 -

// this.registry always has a trailing slash

847 -

return `${this.registry.slice(0, -1)}${resolvedURL.pathname}${resolvedURL.searchParams}`

848 -

}

849 - 850 -

return resolved

851 852

}

852 853 853 854

// bundles are *sort of* like shrinkwraps, in that the branch is defined

Original file line number Diff line number Diff line change

@@ -3171,7 +3171,7 @@ t.test('installLinks', (t) => {

3171 3171

t.end()

3172 3172

})

3173 3173 3174 -

t.only('should preserve exact ranges, missing actual tree', async (t) => {

3174 +

t.test('should preserve exact ranges, missing actual tree', async (t) => {

3175 3175

const Pacote = require('pacote')

3176 3176

const Arborist = t.mock('../../lib/arborist', {

3177 3177

pacote: {

@@ -3256,7 +3256,7 @@ t.only('should preserve exact ranges, missing actual tree', async (t) => {

3256 3256

},

3257 3257

})

3258 3258 3259 -

t.only('host should not be replaced replaceRegistryHost=never', async (t) => {

3259 +

t.test('host should not be replaced replaceRegistryHost=never', async (t) => {

3260 3260

const testdir = t.testdir({

3261 3261

project: {

3262 3262

'package.json': JSON.stringify({

@@ -3296,7 +3296,7 @@ t.only('should preserve exact ranges, missing actual tree', async (t) => {

3296 3296

await arb.reify()

3297 3297

})

3298 3298 3299 -

t.only('host should be replaced replaceRegistryHost=npmjs', async (t) => {

3299 +

t.test('host should be replaced replaceRegistryHost=npmjs', async (t) => {

3300 3300

const testdir = t.testdir({

3301 3301

project: {

3302 3302

'package.json': JSON.stringify({

@@ -3336,7 +3336,7 @@ t.only('should preserve exact ranges, missing actual tree', async (t) => {

3336 3336

await arb.reify()

3337 3337

})

3338 3338 3339 -

t.only('host should be always replaceRegistryHost=always', async (t) => {

3339 +

t.test('host should be always replaceRegistryHost=always', async (t) => {

3340 3340

const testdir = t.testdir({

3341 3341

project: {

3342 3342

'package.json': JSON.stringify({

@@ -3375,6 +3375,52 @@ t.only('should preserve exact ranges, missing actual tree', async (t) => {

3375 3375

})

3376 3376

await arb.reify()

3377 3377

})

3378 + 3379 +

t.test('registry with path should only swap hostname', async (t) => {

3380 +

const abbrevPackument3 = JSON.stringify({

3381 +

_id: 'abbrev',

3382 +

_rev: 'lkjadflkjasdf',

3383 +

name: 'abbrev',

3384 +

'dist-tags': { latest: '1.1.1' },

3385 +

versions: {

3386 +

'1.1.1': {

3387 +

name: 'abbrev',

3388 +

version: '1.1.1',

3389 +

dist: {

3390 +

tarball: 'https://artifactory.example.com/api/npm/npm-all/abbrev/-/abbrev-1.1.1.tgz',

3391 +

},

3392 +

},

3393 +

},

3394 +

})

3395 + 3396 +

const testdir = t.testdir({

3397 +

project: {

3398 +

'package.json': JSON.stringify({

3399 +

name: 'myproject',

3400 +

version: '1.0.0',

3401 +

dependencies: {

3402 +

abbrev: '1.1.1',

3403 +

},

3404 +

}),

3405 +

},

3406 +

})

3407 + 3408 +

tnock(t, 'https://new-host.artifactory.example.com')

3409 +

.get('/api/npm/npm-all/abbrev')

3410 +

.reply(200, abbrevPackument3)

3411 + 3412 +

tnock(t, 'https://new-host.artifactory.example.com')

3413 +

.get('/api/npm/npm-all/abbrev/-/abbrev-1.1.1.tgz')

3414 +

.reply(200, abbrevTGZ)

3415 + 3416 +

const arb = new Arborist({

3417 +

path: resolve(testdir, 'project'),

3418 +

registry: 'https://new-host.artifactory.example.com/api/npm/npm-all',

3419 +

cache: resolve(testdir, 'cache'),

3420 +

replaceRegistryHost: 'always',

3421 +

})

3422 +

await arb.reify()

3423 +

})

3378 3424

})

3379 3425 3380 3426

t.test('install stategy linked', async (t) => {

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4