Repository: netlify/zip-it-and-ship-it (js)

Issue:
Expose additional data in return value
**- Do you want to request a _feature_ or report a _bug_?**

Feature! 🚀 

**- What is the current behavior?**

Currently, the following properties are returned for each bundled function:

- `runtime`: The name of the runtime (e.g. `"js"`)
- `path`: The full path to the generated zip file
- `bundler`: The name of the JavaScript bundler used to create the function (applicable only when `runtime` is `js`)

**- If the current behavior is a bug, please provide the steps to reproduce.**

N/A

**- What is the expected behavior?**

We could introduce a `name` property that contains the name of the function. This would be useful for https://github.com/netlify/build/issues/2025.

Additionally, we could expose a `config` property that exposes the configuration object, if any, that was applied to the function. This would allow users to debug problems where some configuration parameter was overridden by a block with a higher priority in the cascade. Related to #376.

- [ ] `name`
- [x] `config`

**- Please mention your node.js, and operating system version.**

N/A

Pull request:
feat: add function name to output of zipFunction and zipFunctions
**- Summary**

This PR adds the name of each bundled function to the output of `zipFunction` and `zipFunctions`, under the `name` property.

Closes #383.

**- Test plan**

Adjusted existing tests.

**- Description for the changelog**

feat: add function name to output of zipFunction and zipFunctions

**- A picture of a cute animal (not mandatory but encouraged)**

![How-do-you-call-a-Baby-Gorillaa](https://user-images.githubusercontent.com/4162329/114877338-17665f00-9df7-11eb-9d3c-866b126ce039.jpg)


Patch:
diff --git a/src/zip.js b/src/zip.js
index bb42c09..713f496 100644
--- a/src/zip.js
+++ b/src/zip.js
@@ -19,9 +19,17 @@ const validateArchiveFormat = (archiveFormat) => {
 
 // Takes the result of zipping a function and formats it for output.
 const formatZipResult = (result) => {
-  const { bundler, bundlerErrors, bundlerWarnings, config = {}, path, runtime } = result
+  const { bundler, bundlerErrors, bundlerWarnings, config = {}, name, path, runtime } = result
 
-  return removeFalsy({ bundler, bundlerErrors, bundlerWarnings, config, path, runtime: runtime.name })
+  return removeFalsy({
+    bundler,
+    bundlerErrors,
+    bundlerWarnings,
+    config,
+    name,
+    path,
+    runtime: runtime.name,
+  })
 }
 
 // Zip `srcFolder/*` (Node.js or Go files) to `destFolder/*.zip` so it can be
@@ -57,7 +65,7 @@ const zipFunctions = async function (
         stat: func.stat,
       })
 
-      return { ...zipResult, runtime: func.runtime }
+      return { ...zipResult, name: func.name, runtime: func.runtime }
     },
     {
       concurrency: parallelLimit,
@@ -80,7 +88,7 @@ const zipFunction = async function (
     return
   }
 
-  const { config, extension, filename, mainFile, runtime, srcDir, stat } = functions.values().next().value
+  const { config, extension, filename, mainFile, name, runtime, srcDir, stat } = functions.values().next().value
   const pluginsModulesPath =
     defaultModulesPath === undefined ? await getPluginsModulesPath(srcPath) : defaultModulesPath
 
@@ -100,7 +108,7 @@ const zipFunction = async function (
     pluginsModulesPath,
   })
 
-  return formatZipResult({ ...zipResult, runtime })
+  return formatZipResult({ ...zipResult, name, runtime })
 }
 
 module.exports = { zipFunction, zipFunctions }


Test patch:
diff --git a/tests/main.js b/tests/main.js
index c501042..ab7d91f 100644
--- a/tests/main.js
+++ b/tests/main.js
@@ -383,10 +383,15 @@ testBundlers('Works with many dependencies', [ESBUILD, ESBUILD_ZISI, DEFAULT], a
 })
 
 testBundlers('Works with many function files', [ESBUILD, ESBUILD_ZISI, DEFAULT], async (bundler, t) => {
-  await zipNode(t, 'many-functions', {
+  const names = new Set(['one', 'two', 'three', 'four', 'five', 'six'])
+  const { files } = await zipNode(t, 'many-functions', {
     opts: { config: { '*': { nodeBundler: bundler } } },
     length: TEST_FUNCTIONS_LENGTH,
   })
+
+  files.forEach(({ name }) => {
+    t.true(names.has(name))
+  })
 })
 
 const TEST_FUNCTIONS_LENGTH = 6
@@ -466,6 +471,7 @@ testBundlers('Can use zipFunction()', [ESBUILD, ESBUILD_ZISI, DEFAULT], async (b
   const outBundlers = { [ESBUILD_ZISI]: ESBUILD, [DEFAULT]: JS_BUNDLER_ZISI }
   const outBundler = outBundlers[bundler] || bundler
 
+  t.is(result.name, 'function')
   t.is(result.runtime, 'js')
   t.is(result.bundler, outBundler)
   t.deepEqual(result.config, bundler === DEFAULT ? {} : { nodeBundler: outBundler })