Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Scoped packages #272

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"request": "~2.42.0",
"parse-json-response": "~1.0.1",
"rimraf": "~2.2.6",
"tap": "*",
"tap": "^10.7.3",
"which": "~1.0.5"
},
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions registry/shows.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ shows.package = function (doc, req) {

var t = doc.versions[v].dist.tarball
t = t.replace(/^https?:\/\/[^\/:]+(:[0-9]+)?/, '')
var f = t.match(/[^\/]+$/)[0]
var f = t.match(/(@[^\/]+\/)?[^\/]+$/)[0]
var requestedPath = req.requested_path
if (doc._attachments && doc._attachments[f]) {
// workaround for old couch versions that didn't
Expand Down Expand Up @@ -115,7 +115,7 @@ shows.package = function (doc, req) {
// .../_rewrite/pkg/-/pkg-version.tgz
// or: /pkg/-/pkg-version.tgz
// depending on what requested path is.
var tf = [doc.name, '-', t.split('/').pop()]
var tf = [doc.name.replace('/','%2f'), '-', f.replace('/','%2f')]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine, but can we just use encodeURIComponent instead of regex?

Copy link
Author

@jbeard4 jbeard4 Jan 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also uri-encode the "@" as "%40". So, for example, the saved tarball for package name "@scoped/package@0.2.3-alpha" will be available at path "%40scoped%2Fpackage/-/%40scoped%2Fpackage-0.2.3-alpha.tgz", rather than "@Scoped%2Fpackage/-/@Scoped%2Fpackage-0.2.3-alpha.tgz"

I need to check if this maintains compatibility with the npm client.

var i = requestedPath.indexOf('_rewrite')
if (i !== -1) {
tf = requestedPath.slice(0, i + 1).concat(tf)
Expand Down
6 changes: 5 additions & 1 deletion test/01-adduser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ var path = require('path')
var conf = path.resolve(__dirname, 'fixtures', 'npmrc')
var conf2 = path.resolve(__dirname, 'fixtures', 'npmrc2')
var conf3 = path.resolve(__dirname, 'fixtures', 'npmrc3')
var conf4 = path.resolve(__dirname, 'fixtures', 'npmrc4')

var fs = require('fs')

try { fs.unlinkSync(conf) } catch (er) {}
try { fs.unlinkSync(conf2) } catch (er) {}
try { fs.unlinkSync(conf3) } catch (er) {}
try { fs.unlinkSync(conf4) } catch (er) {}

var u = { u: 'user', p: 'pass@:!%\'', e: 'email@example.com' }
var o = { u: 'other', p: 'pass@:!%\'', e: 'other@example.com' }
var t = { u: 'third', p: 'pass@:!%\'', e: '3@example.com' }
var v = { u: 'admin', p: 'admin', e: 'x@x.com' }

test('adduser', fn.bind(null, conf, u))
test('adduser again', fn.bind(null, conf, u))
Expand All @@ -26,6 +29,8 @@ test('adduser 2 again', fn.bind(null, conf2, o))
test('adduser 3', fn.bind(null, conf3, t))
test('adduser 3 again', fn.bind(null, conf3, t))

test('adduser admin', fn.bind(null, conf4, v))

function fn(conf, u, t) {
var c = common.npm([
'--registry=' + reg,
Expand All @@ -38,7 +43,6 @@ function fn(conf, u, t) {
c.stdout.on('data', function(d) {
buf += d
if (buf.match(/: /)) {
console.log(buf)
switch (buf.split(':')[0]) {
case 'Username':
c.stdin.write(u.u + '\r\n')
Expand Down
7 changes: 7 additions & 0 deletions test/01b-user-views.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ var expect = {
"other"
],
"value": 1
},
{
"key": [
"x@x.com",
"admin"
],
"value": 1
}
]
},
Expand Down
Loading