Repository: netlify/zip-it-and-ship-it
Pull request #580 (2021-07-14 15:50:09)

fix: add basePath parameter to zipFunction
**- Summary**

The `basePath` parameter, which is required for dynamic import processing to work, is present in `zipFunctions` but missing in `zipFunction`. This PR fixes that.

**- Test plan**

New test added.

**- A picture of a cute animal (not mandatory but encouraged)**

🐞 

github-actions[bot]: ## ⏱ Benchmark results

*Comparing with 9c3d239efb5f53d53ada4c2d92db6f48b7401096*

### largeDepsEsbuild: 13s
 ⬇️ **6.61% decrease** vs. 9c3d239efb5f53d53ada4c2d92db6f48b7401096
```
^                                  14.1s                                                                  
│                                   ┌──┐                                   13.1s                          
│  12.5s                            |  |                                    ┌──┐   12.6s   12.9s    13s   
│   ┌──┐   12.2s           12.1s    |  |    12s                    12.2s    |  |    ┌──┐    ┌──┐    ┌──┐  
│ ──┼──┼────┌──┐────────────┌──┐────┼──┼────┌──┐───────────11.4s────┌──┐────┼──┼────┼──┼────┼──┼────|▒▒|──
│   |  |    |  |            |  |    |  |    |  |            ┌──┐    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    9.9s    |  |    |  |    |  |   10.1s    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    ┌──┐    |  |    |  |    |  |    ┌──┐    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
```
<details>
<summary>Legend</summary>

- T-30 (9c3d239efb5f53d53ada4c2d92db6f48b7401096): 13.9s
- T-29 (d790873c4cfb82de3f9d5cc64c2ecb45f4c4112f): 10.6s
- T-28 (c18abffd799ee05a0336a34fffd9a1d48e71c550): 10.9s
- T-27 (a0b35e4de9ee40eb9eed4fdd85a16796983fe154): 9.8s
- T-26 (f9084030bf84398023793983490c294b7b8ff483): 14s
- T-25 (b8eb5f8da62d48468c4aff35f2ed65b175bb14c7): 9.6s
- T-24 (cc6070c8f5a0b44163e3167be9b0beab9bf1c644): 12.5s
- T-23 (d1f77ee0caf96a19702d81abd85b8814ed62ab1c): 10.6s
- T-22 (2a11f56404dfdb6d92881751e9a21ed11f432ec8): 12.7s
- T-21 (30ec7f6a4e97007c2f5e0c40b85b196884acd10f): 12.2s
- T-20 (49c33d8209130930cdeed3b953ac874047cba15a): 10s
- T-19 (0bc0ff937f2bfc93d930c78ea4afb7ede53e30c1): 12.4s
- T-18 (69142468b5054449c51186dd64f79ec67ea7899b): 13.3s
- T-17 (d5392a0cb21fa9b712f5dd8c9d4703f6b080afbf): 12.6s
- T-16 (000ffff7ecbceeeb73e4b305859db4a1f8ff1e18): 12s
- T-15 (a36adf0bfcb253ec0271e974752f52a29796476e): 12.6s
- T-14 (01ae53482bc80186659d9a214394315f71135aa5): 13.3s
- T-13 (786deef392e4fa94987bd3667f5def20d1f34e5c): 12.4s
- T-12 (4bcecdda6622821f35844b7521b9f37fa1e69ff2): 12.5s
- T-11 (cfa7e98354411a4a0239e429a70bb620f7a8aa4d): 12.2s
- T-10 (1782d559b8179fd6e8785425f0d053470339df01): 9.9s
- T-9 (db05daa3366142f4dbb844397c25ace1af966123): 12.1s
- T-8 (f69dc7bb918004a5c4b06c826c2f7189be8e129e): 14.1s
- T-7 (11e3486bc4f2ecf0f7ea6dd72b40432cd5e48306): 12s
- T-6 (c7b62ca7080b6a1bbe77483fde32e9bcde326855): 10.1s
- T-5 (d7bbd41934ed22e31e1c56d64c1c98f8b1cac86f): 11.4s
- T-4 (c733b46dd3470999d2c2e51d5cfc1e38c087839a): 12.2s
- T-3 (f29156ef5395795ad40e9df9556908b58aec6ae9): 13.1s
- T-2 (459ae63da849a1e0d4a271276e0333936c058e4a): 12.6s
- T-1 (3b2bee45e41518ab4c5695de581c2e6202e533b6): 12.9s
- **T (current commit): 13s**</details>
### largeDepsZisi: 1m 6.8s
 ⬇️ **15.41% decrease** vs. 9c3d239efb5f53d53ada4c2d92db6f48b7401096
```
^                                 1m 16.4s                                                                
│                                   ┌──┐                                  1m 11.6s                        
│                                   |  |                                    ┌──┐                          
│ 1m 3.2s 1m 3.1s         1m 5.6s   |  |                          1m 3.5s   |  |  1m 4.5s 1m 6.6s 1m 6.8s 
│ ──┌──┐────┌──┐────────────┌──┐────┼──┼──1m 2.9s──────────59.9s────┌──┐────┼──┼────┌──┐────┌──┐────┌──┐──
│   |  |    |  |            |  |    |  |    ┌──┐            ┌──┐    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |   53.7s    |  |    |  |    |  |   53.4s    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    ┌──┐    |  |    |  |    |  |    ┌──┐    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
```
<details>
<summary>Legend</summary>

- T-30 (9c3d239efb5f53d53ada4c2d92db6f48b7401096): 1m 17.1s
- T-29 (d790873c4cfb82de3f9d5cc64c2ecb45f4c4112f): 54.3s
- T-28 (c18abffd799ee05a0336a34fffd9a1d48e71c550): 58.4s
- T-27 (a0b35e4de9ee40eb9eed4fdd85a16796983fe154): 51.8s
- T-26 (f9084030bf84398023793983490c294b7b8ff483): 1m 15.1s
- T-25 (b8eb5f8da62d48468c4aff35f2ed65b175bb14c7): 51s
- T-24 (cc6070c8f5a0b44163e3167be9b0beab9bf1c644): 1m 4.1s
- T-23 (d1f77ee0caf96a19702d81abd85b8814ed62ab1c): 54.9s
- T-22 (2a11f56404dfdb6d92881751e9a21ed11f432ec8): 1m 8.7s
- T-21 (30ec7f6a4e97007c2f5e0c40b85b196884acd10f): 1m 1.5s
- T-20 (49c33d8209130930cdeed3b953ac874047cba15a): 52.8s
- T-19 (0bc0ff937f2bfc93d930c78ea4afb7ede53e30c1): 1m 4s
- T-18 (69142468b5054449c51186dd64f79ec67ea7899b): 1m 14.3s
- T-17 (d5392a0cb21fa9b712f5dd8c9d4703f6b080afbf): 1m 5.3s
- T-16 (000ffff7ecbceeeb73e4b305859db4a1f8ff1e18): 1m 3.6s
- T-15 (a36adf0bfcb253ec0271e974752f52a29796476e): 1m 7.1s
- T-14 (01ae53482bc80186659d9a214394315f71135aa5): 1m 8.3s
- T-13 (786deef392e4fa94987bd3667f5def20d1f34e5c): 1m 7.1s
- T-12 (4bcecdda6622821f35844b7521b9f37fa1e69ff2): 1m 3.2s
- T-11 (cfa7e98354411a4a0239e429a70bb620f7a8aa4d): 1m 3.1s
- T-10 (1782d559b8179fd6e8785425f0d053470339df01): 53.7s
- T-9 (db05daa3366142f4dbb844397c25ace1af966123): 1m 5.6s
- T-8 (f69dc7bb918004a5c4b06c826c2f7189be8e129e): 1m 16.4s
- T-7 (11e3486bc4f2ecf0f7ea6dd72b40432cd5e48306): 1m 2.9s
- T-6 (c7b62ca7080b6a1bbe77483fde32e9bcde326855): 53.4s
- T-5 (d7bbd41934ed22e31e1c56d64c1c98f8b1cac86f): 59.9s
- T-4 (c733b46dd3470999d2c2e51d5cfc1e38c087839a): 1m 3.5s
- T-3 (f29156ef5395795ad40e9df9556908b58aec6ae9): 1m 11.6s
- T-2 (459ae63da849a1e0d4a271276e0333936c058e4a): 1m 4.5s
- T-1 (3b2bee45e41518ab4c5695de581c2e6202e533b6): 1m 6.6s
- **T (current commit): 1m 6.8s**</details>
<!--delta:benchmark@{}-->

Patch:
diff --git a/src/zip.js b/src/zip.js
index c6af48f..4b9a522 100644
--- a/src/zip.js
+++ b/src/zip.js
@@ -108,6 +108,7 @@ const zipFunction = async function (
   destFolder,
   {
     archiveFormat = ARCHIVE_FORMAT_ZIP,
+    basePath,
     config: inputConfig = {},
     featureFlags: inputFeatureFlags,
     pluginsModulesPath: defaultModulesPath,
@@ -131,6 +132,7 @@ const zipFunction = async function (
 
   const zipResult = await runtime.zipFunction({
     archiveFormat,
+    basePath,
     config,
     srcPath,
     destFolder,


Test patch:
diff --git a/tests/main.js b/tests/main.js
index cc5eb0d..d8d7453 100644
--- a/tests/main.js
+++ b/tests/main.js
@@ -1487,6 +1487,26 @@ test('Creates dynamic import shims for functions with the same name and same shi
   }
 })
 
+test('Creates dynamic import shims for functions using `zipFunction`', async (t) => {
+  const { path: tmpDir } = await getTmpDir({ prefix: 'zip-it-test' })
+  const fixtureDir = join(FIXTURES_DIR, 'node-module-dynamic-import-2')
+  const result = await zipFunction(join(fixtureDir, 'function.js'), tmpDir, {
+    basePath: fixtureDir,
+    config: { '*': { nodeBundler: 'esbuild', processDynamicNodeImports: true } },
+  })
+
+  await unzipFiles([result])
+
+  // eslint-disable-next-line import/no-dynamic-require, node/global-require
+  const func = require(`${tmpDir}/function.js`)
+
+  t.deepEqual(func('en')[0], ['yes', 'no'])
+  t.deepEqual(func('en')[1], ['yes', 'no'])
+  t.deepEqual(func('pt')[0], ['sim', 'não'])
+  t.deepEqual(func('pt')[1], ['sim', 'não'])
+  t.throws(() => func('fr'))
+})
+
 test('Uses the default Node bundler if no configuration object is supplied', async (t) => {
   const { files, tmpDir } = await zipNode(t, 'local-node-module')
   const requires = await getRequires({ filePath: resolve(tmpDir, 'function.js') })