Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit 553e599

Browse files
lbovetblakeembrey
authored andcommitted
Enable configurable URL rewrite (#147)
1 parent 466670e commit 553e599

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"popsicle": "^8.0.2",
6161
"popsicle-proxy-agent": "^3.0.0",
6262
"popsicle-retry": "^3.2.0",
63+
"popsicle-rewrite": "^1.0.0",
6364
"popsicle-status": "^2.0.0",
6465
"promise-finally": "^2.0.1",
6566
"rc": "^1.1.5",

src/install.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ test('install', t => {
7474
updated: '2016-02-26T13:23:28.000Z'
7575
})
7676

77-
nock('http://raw.githubusercontent.com/')
77+
nock('https://raw.githubuserstuff.com/')
7878
.get('/DefinitelyTyped/DefinitelyTyped/48c1e3c1d6baefa4f1a126f188c27c4fefd36bff/node/node.d.ts')
7979
.reply(200, '// Type definitions for Node.js v4.x')
8080

81+
rc.urlRewrites = { '(.*)content(.*)': '$1stuff$2' }
82+
8183
return writeFile(CONFIG, '{}')
8284
.then(function () {
8385
return rimraf(join(FIXTURE_DIR, 'typings'))

src/interfaces/rc.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ export interface RcConfig {
5050
* Override the default installation source (E.g. when doing `typings install debug`) (default: `npm`).
5151
*/
5252
defaultSource?: string
53+
/**
54+
* Defines URL rewrites. May be useful when using corporate registries.
55+
*/
56+
urlRewrites?: { [pattern: string]: string }
5357
}

src/utils/fs.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import parse = require('parse-json')
77
import popsicle = require('popsicle')
88
import popsicleStatus = require('popsicle-status')
99
import popsicleRetry = require('popsicle-retry')
10+
import popsicleRewrite = require('popsicle-rewrite')
1011
import detectIndent = require('detect-indent')
1112
import sortKeys = require('sort-keys')
1213
import Mkdirp = require('mkdirp')
@@ -160,6 +161,8 @@ export const readHttp = throat(5, function readHttp (url: string): Promise<strin
160161
})
161162
// Check responses are "200 OK".
162163
.use(popsicleStatus(200))
164+
// Enable URL rewrite
165+
.use(popsicleRewrite(rc.urlRewrites || {}))
163166
// Enable tracking of repeat users on the registry.
164167
.use(function (request, next) {
165168
if (request.Url.host === registryURL.host) {

0 commit comments

Comments
 (0)