From 4b1b0d0905694d8d0ec7aad1e3381d4b537adb56 Mon Sep 17 00:00:00 2001 From: Ben Gourley Date: Wed, 1 Aug 2018 11:47:58 +0100 Subject: [PATCH 1/2] fix: Ensure all boolean CLI opts are parsed correctly --- cli.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cli.js b/cli.js index e4afd65..710a77e 100755 --- a/cli.js +++ b/cli.js @@ -59,6 +59,12 @@ const cli = meow(` string: [ 'app-version', ], + boolean: [ + 'overwrite', + 'upload-node-modules', + 'upload-sources', + 'add-wildcard-prefix', + ], }); const conf = { From 4d11f1a1f90e7fa5fb174882b8c6ddd8a721dc45 Mon Sep 17 00:00:00 2001 From: Ben Gourley Date: Wed, 1 Aug 2018 11:55:45 +0100 Subject: [PATCH 2/2] fix: Remove overwrite from payload when false Fixes #23 --- index.js | 8 ++++++++ index.test.js | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/index.js b/index.js index 247a32f..2b29ac8 100644 --- a/index.js +++ b/index.js @@ -297,6 +297,14 @@ function prepareRequest(options) { case 'tempDir': { break; } + case 'overwrite': { + // the presence of any value for this flag causes the API to interpret it as + // true, so only add it to the payload if it is truthy + if (options.overwrite) { + formData[name] = String(value); + } + break; + } // Basic fields (strings/booleans) & future fields default: { formData[name] = String(value); diff --git a/index.test.js b/index.test.js index 02beae2..e508209 100644 --- a/index.test.js +++ b/index.test.js @@ -3,6 +3,7 @@ const stripProjectRoot = require('./index').stripProjectRoot const upload = require('./index').upload const validateOptions = require('./index').validateOptions +const prepareRequest = require('./index').prepareRequest test('upload function exists', () => { expect(typeof upload).toBe('function'); @@ -71,3 +72,12 @@ describe('validateOptions', () => { }).toThrow('You must provide a path to the source map you want to upload.'); }); }); + +describe('prepareRequest', () => { + test('removes options.overwrite when false', () => { + expect(prepareRequest({ overwrite: false }).formData).toEqual({}); + }); + test('does not remove options.overwrite when true', () => { + expect(prepareRequest({ overwrite: true }).formData).toEqual({ overwrite: 'true' }); + }); +});