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

Commit

Permalink
Enable configurable URL rewrite (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbovet authored and blakeembrey committed Oct 3, 2016
1 parent 466670e commit 553e599
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"popsicle": "^8.0.2",
"popsicle-proxy-agent": "^3.0.0",
"popsicle-retry": "^3.2.0",
"popsicle-rewrite": "^1.0.0",
"popsicle-status": "^2.0.0",
"promise-finally": "^2.0.1",
"rc": "^1.1.5",
Expand Down
4 changes: 3 additions & 1 deletion src/install.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ test('install', t => {
updated: '2016-02-26T13:23:28.000Z'
})

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

rc.urlRewrites = { '(.*)content(.*)': '$1stuff$2' }

return writeFile(CONFIG, '{}')
.then(function () {
return rimraf(join(FIXTURE_DIR, 'typings'))
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/rc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ export interface RcConfig {
* Override the default installation source (E.g. when doing `typings install debug`) (default: `npm`).
*/
defaultSource?: string
/**
* Defines URL rewrites. May be useful when using corporate registries.
*/
urlRewrites?: { [pattern: string]: string }
}
3 changes: 3 additions & 0 deletions src/utils/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import parse = require('parse-json')
import popsicle = require('popsicle')
import popsicleStatus = require('popsicle-status')
import popsicleRetry = require('popsicle-retry')
import popsicleRewrite = require('popsicle-rewrite')
import detectIndent = require('detect-indent')
import sortKeys = require('sort-keys')
import Mkdirp = require('mkdirp')
Expand Down Expand Up @@ -160,6 +161,8 @@ export const readHttp = throat(5, function readHttp (url: string): Promise<strin
})
// Check responses are "200 OK".
.use(popsicleStatus(200))
// Enable URL rewrite
.use(popsicleRewrite(rc.urlRewrites || {}))
// Enable tracking of repeat users on the registry.
.use(function (request, next) {
if (request.Url.host === registryURL.host) {
Expand Down

0 comments on commit 553e599

Please sign in to comment.