From 368495e38ac989f444b82867c753a7402de51b59 Mon Sep 17 00:00:00 2001 From: Ger Hobbelt Date: Tue, 3 Oct 2017 16:51:05 +0200 Subject: [PATCH 1/2] fix: npm.org now has a different way to request info about scoped packages: via the `Npm-Scope` header. See also https://docs.npmjs.com/misc/registry --- lib/datasrc/npm.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/datasrc/npm.js b/lib/datasrc/npm.js index f772a1d..88d2a07 100644 --- a/lib/datasrc/npm.js +++ b/lib/datasrc/npm.js @@ -32,10 +32,21 @@ var repo = ''; function packageHistory(moduleName) { var deferred = q.defer(); // Escape / in moduleName to support scoped repositories - var url = 'http://registry.npmjs.org/' + moduleName.replace('/', '%2F'); + var url = 'http://registry.npmjs.org/' + moduleName.replace(/^@[^/]+\//, ''); log.debug('requesting: ' + url); - request({ uri: url, json: true }, function (err, res, data) { + var query = { + uri: url, + json: true + }; + var packageScope = moduleName.replace(/^@([^/]+)\/[^/]+$/, '$1'); + log.debug('scoped package? scope = ' + (packageScope ? packageScope : '(none)')); + if (packageScope) { + query.headers = { + "Npm-Scope": packageScope + }; + } + request(query, function (err, res, data) { log.debug('complete: ' + url); if (err) { From 5c6dcddfa88dceba3d4240ef9a24ba2c4f536545 Mon Sep 17 00:00:00 2001 From: Ger Hobbelt Date: Mon, 30 Oct 2017 23:56:48 +0100 Subject: [PATCH 2/2] turns out today, npm registry requests for scoped packages has apparently reverted to old behaviour. See also commit SHA-1: 368495e38ac989f444b82867c753a7402de51b59 :: fix: npm.org now has a different way to request info about scoped packages: via the `Npm-Scope` header. See also https://docs.npmjs.com/misc/registry --- lib/datasrc/npm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datasrc/npm.js b/lib/datasrc/npm.js index 88d2a07..d9a70fb 100644 --- a/lib/datasrc/npm.js +++ b/lib/datasrc/npm.js @@ -32,7 +32,7 @@ var repo = ''; function packageHistory(moduleName) { var deferred = q.defer(); // Escape / in moduleName to support scoped repositories - var url = 'http://registry.npmjs.org/' + moduleName.replace(/^@[^/]+\//, ''); + var url = 'http://registry.npmjs.org/' + moduleName.replace(/\//g, '%2F'); log.debug('requesting: ' + url); var query = {