From 3f85676edd88d244d31db9741c07cd811f662077 Mon Sep 17 00:00:00 2001 From: Christian Georgi Date: Fri, 1 Apr 2022 11:43:41 +0200 Subject: [PATCH] Registry to handle packages with dashes Like `@capire/data-viewer`, resulting in requests like `GET /capire-data-viewer-0.1.0.tgz` --- .registry/server.js | 5 +++-- test/registry.test.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.registry/server.js b/.registry/server.js index cca773de..d3489325 100644 --- a/.registry/server.js +++ b/.registry/server.js @@ -16,7 +16,8 @@ app.use('/-/:tarball', (req,res,next) => { console.debug ('GET', req.params) try { const { tarball } = req.params - const [, pkg ] = /^\w+-(\w+)/.exec(tarball) + const pkgFull = tarball.substring(0, tarball.lastIndexOf('-')) + const [, pkg ] = /^\w+-(.+)/.exec(pkgFull) fs.lstat(tarball,(err => { if (err) console.debug (`npm pack ../${pkg}`) if (err) exec(`npm pack ../${pkg}`,{cwd},next) @@ -31,7 +32,7 @@ app.use('/-/:tarball', (req,res,next) => { app.use('/-', express.static(__dirname)) app.get('/*', (req,res)=>{ - const urlRegex = /^\/(@\w+)\/(\w+)/ + const urlRegex = /^\/(@[\w-]+)\/(.+)/ const url = decodeURIComponent(req.url) console.debug ('GET',url) try { diff --git a/test/registry.test.js b/test/registry.test.js index c8a02c87..fce83b25 100644 --- a/test/registry.test.js +++ b/test/registry.test.js @@ -20,7 +20,7 @@ describe('Local NPM registry', () => { after(() => { registry.kill() }) - for (const mod of ['bookshop','fiori','orders','reviews']) { + for (const mod of ['bookshop', 'data-viewer', 'fiori','orders','reviews']) { it(`should serve ${mod}`, async () => { const resp = await axios.get(`/@capire/${mod}`) expect(resp.data).to.containSubset({name: `@capire/${mod}`, versions:{}})