From 770857963e484b4d23c125e6da5d63a92cc9c0d7 Mon Sep 17 00:00:00 2001 From: "Matt A. Atasoy" <145038728+matt-ahmet-bbc@users.noreply.github.com> Date: Tue, 12 Mar 2024 09:55:30 +0000 Subject: [PATCH] Fix: Creating a service file with a custom name falls back to the package.name when package.json has "files" (#108) * Refactor service file name to accept a name rather than package obj * fix: Creating custom service when file defined falls back to package.name --- lib/files.js | 6 +++--- lib/generate.js | 6 +++--- test/generate.js | 20 +++++++++++++++++++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/files.js b/lib/files.js index 8642c8f..b108bc0 100644 --- a/lib/files.js +++ b/lib/files.js @@ -3,11 +3,11 @@ const path = require('path'); module.exports = { - serviceFileName: function (pkg) { - return `${pkg.name}.service`; + serviceFileName: function (name) { + return `${name}.service`; }, serviceFile: function (root, pkg) { - return path.resolve(root, this.serviceFileName(pkg)); + return path.resolve(root, this.serviceFileName(pkg.name)); }, specsDirectory: function (root) { return path.resolve(root, 'SPECS'); diff --git a/lib/generate.js b/lib/generate.js index 72f0939..1bd2cba 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -40,9 +40,9 @@ function relativeToRoot(root, files) { }); } -function getArchiveWhitelist(pkg) { +function getArchiveWhitelist(pkg, customName) { return { - service: files.serviceFileName(pkg), + service: files.serviceFileName(customName || pkg.name), main: pkg.main, files: pkg.files }; @@ -59,7 +59,7 @@ module.exports = async (root, pkg, release, customName) => { const serviceFile = generateServiceFile(root, customPackage); const specFile = generateSpecFile(specsDirectory, customPackage, release); - const archiveWhitelist = getArchiveWhitelist(pkg); + const archiveWhitelist = getArchiveWhitelist(pkg, customName); await archiver.compress(root, sourcesArchive, archiveWhitelist); diff --git a/test/generate.js b/test/generate.js index 3d3f5d3..6f1b205 100644 --- a/test/generate.js +++ b/test/generate.js @@ -112,7 +112,7 @@ describe('generate', () => { { files: undefined, main: 'index.js', - service: 'my-cool-api.service' + service: 'penguin.service' } ); }); @@ -135,6 +135,24 @@ describe('generate', () => { ); }); + it('creates the service file with a custom name if specified and "files" defined', async () => { + await generate('/path/to/project', pkgWithWhitelist, null, 'penguin'); + sandbox.assert.calledWith( + archiver.compress, + '/path/to/project', + '/path/to/project/SOURCES/penguin.tar.gz', + { + main: 'server.js', + files: [ + 'lib', + 'routes', + 'index.js' + ], + service: 'penguin.service' + } + ); + }); + it('creates the service file with a custom name if specified', async () => { await generate('/path/to/project', pkg, 1, 'penguin'); sandbox.assert.calledWith(