Repository: netlify/zip-it-and-ship-it
Pull request #91 (2020-04-01 18:27:50)

Fix `skipGo` and `zipGo` options
We currently have two options that do the same thing:
  - `skipGo` is only in Node.js and defaults to `true`
  - `zipGo` is only in the CLI and defaults to `false`. Its behavior is inverse to `skipGo`

To make it more consistent, #89 tried to enforce using `skipGo` only. However @mraerino pointed out that boolean option should ideally default to `false`. Therefore this PR switches to enforcing using `zipGo` only. `skipGo` is still kept for backward compatibility until the next major release.


Patch:
diff --git a/README.md b/README.md
index 1e7132a..9957e03 100644
--- a/README.md
+++ b/README.md
@@ -86,7 +86,7 @@ const zipped = [
 ```js
 {
   parallelLimit: 5, // Limit the number of concurrent zipping operations at a time
-  skipGo: false // Don't zip go functions, just move them to the destination path
+  zipGo: false // Don't zip go functions, just move them to the destination path
 }
 ```
 
@@ -101,7 +101,7 @@ $ zip-it-and-ship-it --help
 @netlify/zip-it-and-ship-it: Zip lambda functions and their dependencies for deployment
 
 Usage: zip-it-and-ship-it [source] [destination] {options}
-    --skip-go             do not zip go binaries (default: true)
+    --zip-go              zip go binaries (default: false)
     --help, -h            show help
     --version, -v         print the version of the program
 ```
diff --git a/src/bin.js b/src/bin.js
index 5b82ab1..609a383 100755
--- a/src/bin.js
+++ b/src/bin.js
@@ -7,10 +7,10 @@ const zipIt = require('..')
 
 // CLI entry point
 const runCli = async function() {
-  const { srcFolder, destFolder, zipGo = false, skipGo = !zipGo } = parseArgs()
+  const { srcFolder, destFolder, zipGo } = parseArgs()
 
   try {
-    const zipped = await zipIt.zipFunctions(srcFolder, destFolder, { skipGo })
+    const zipped = await zipIt.zipFunctions(srcFolder, destFolder, { zipGo })
     console.log(JSON.stringify(zipped, null, 2))
   } catch (error) {
     console.error(error.toString())
@@ -28,13 +28,9 @@ const parseArgs = function() {
 }
 
 const OPTIONS = {
-  'skip-go': {
-    boolean: true,
-    describe: 'Whether Go binaries should be copied as is or zipped'
-  },
-  // TODO: deprecated. Remove on the next major release
   'zip-go': {
     boolean: true,
+    default: false,
     describe: 'Whether Go binaries should be zipped or copied as is'
   }
 }
diff --git a/src/main.js b/src/main.js
index ef9c389..40c00fd 100644
--- a/src/main.js
+++ b/src/main.js
@@ -15,11 +15,12 @@ const pLstat = promisify(lstat)
 
 // Zip `srcFolder/*` (Node.js or Go files) to `destFolder/*.zip` so it can be
 // used by AWS Lambda
-const zipFunctions = async function(srcFolder, destFolder, { parallelLimit = 5, skipGo = true } = {}) {
+// TODO: remove `skipGo` option in next major release
+const zipFunctions = async function(srcFolder, destFolder, { parallelLimit = 5, skipGo, zipGo } = {}) {
   const filenames = await listFilenames(srcFolder)
   const srcPaths = filenames.map(filename => resolve(srcFolder, filename))
 
-  const zipped = await pMap(srcPaths, srcPath => zipFunction(srcPath, destFolder, { skipGo }), {
+  const zipped = await pMap(srcPaths, srcPath => zipFunction(srcPath, destFolder, { skipGo, zipGo }), {
     concurrency: parallelLimit
   })
   return zipped.filter(Boolean)
@@ -33,7 +34,7 @@ const listFilenames = async function(srcFolder) {
   }
 }
 
-const zipFunction = async function(srcPath, destFolder, { skipGo } = {}) {
+const zipFunction = async function(srcPath, destFolder, { skipGo = true, zipGo = !skipGo } = {}) {
   const { filename, extension, srcDir, stat, handler, destPath, destCopyPath } = await statFile(srcPath, destFolder)
 
   if (filename === 'node_modules' || (stat.isDirectory() && handler === undefined)) {
@@ -52,7 +53,7 @@ const zipFunction = async function(srcPath, destFolder, { skipGo } = {}) {
 
   const isGoExecutable = await isGoExe(srcPath)
 
-  if (isGoExecutable && skipGo) {
+  if (isGoExecutable && !zipGo) {
     await cpFile(srcPath, destCopyPath)
     return { path: destCopyPath, runtime: 'go' }
   }


Test patch:
diff --git a/src/main.test.js b/src/main.test.js
index a99839d..8101fa9 100644
--- a/src/main.test.js
+++ b/src/main.test.js
@@ -181,7 +181,7 @@ test('Copies already zipped files', async t => {
 })
 
 test('Zips Go function files', async t => {
-  const { files, tmpDir } = await zipFixture(t, 'go-simple', 1, { skipGo: false })
+  const { files, tmpDir } = await zipFixture(t, 'go-simple', 1, { zipGo: true })
 
   t.true(files.every(({ runtime }) => runtime === 'go'))