From 63613b419913313c41f61a352febb0a51ae5368b Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Wed, 5 Jul 2017 10:45:58 +0200 Subject: [PATCH] Make original excludes and includes relative (#29) * Make original excludes and includes relative * Add test for exclamation mark prefixed path Fixes #21 --- src/lib/service.js | 15 +++++++++++++-- test/fns.js | 2 +- test/service.test.js | 14 +++++++------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/lib/service.js b/src/lib/service.js index 042fbde..02ededf 100644 --- a/src/lib/service.js +++ b/src/lib/service.js @@ -1,16 +1,27 @@ const path = require('path'); const R = require('ramda'); -const appendPath = (p, e) => R.over(R.lensPath(p), R.append(e)); +const makeRelative = R.replace(/[^!]+$/, R.concat('../')); +const makeAllRelative = p => R.when(R.has(p), R.over(R.lensProp(p), R.map(makeRelative))); +const makePackageRelative = R.compose(makeAllRelative('include'), makeAllRelative('exclude')); const setPackage = R.pipe( + makePackageRelative, R.over(R.lensProp('exclude'), R.append('**')), R.assoc('individually', true) ); const fnPath = R.compose(R.replace(/\.[^.]+$/, '.js'), R.prop('handler')); -const setFnsPackage = R.map(fn => appendPath(['package', 'include'], fnPath(fn))(fn)); +const setFnsPackage = R.map( + R.pipe( + R.over(R.lensProp('package'), makePackageRelative), + R.converge( + R.over(R.lensPath(['package', 'include'])), + [R.compose(R.append, fnPath), R.identity] + ) + ) +); const setFnsArtifacts = (serverlessPath, fns) => R.map( R.over( diff --git a/test/fns.js b/test/fns.js index 0501685..e3c6d22 100644 --- a/test/fns.js +++ b/test/fns.js @@ -15,7 +15,7 @@ const originalFns = { }, post: { handler: 'functions/post.handler', - package: { exclude: ['*.sql'] }, + package: { exclude: ['*.sql', '!test.sql'] }, }, }; diff --git a/test/service.test.js b/test/service.test.js index b36375c..ac0b139 100644 --- a/test/service.test.js +++ b/test/service.test.js @@ -29,8 +29,8 @@ test('service package with existing package and include/exclude', () => { }; const expectedPackage = { individually: true, - include: ['node_modules/**'], - exclude: ['*.txt', '**'], + include: ['../node_modules/**'], + exclude: ['../*.txt', '**'], }; expect(service.setPackage(existingPackage)).toEqual(expectedPackage); }); @@ -44,22 +44,22 @@ test('setFnsPackage', () => { firstGet: { handler: 'functions/first/get.handler', package: { - include: ['node_modules/**', 'functions/first/get.js'], - exclude: ['abc.js'], + include: ['../node_modules/**', 'functions/first/get.js'], + exclude: ['../abc.js'], }, }, secondGet: { handler: 'functions/second/get.handler', package: { - include: ['node_modules/**', 'functions/second/get.js'], - exclude: ['abc.js'], + include: ['../node_modules/**', 'functions/second/get.js'], + exclude: ['../abc.js'], }, }, post: { handler: 'functions/post.handler', package: { include: ['functions/post.js'], - exclude: ['*.sql'], + exclude: ['../*.sql', '!../test.sql'], }, }, };