Repository: netlify/zip-it-and-ship-it
Pull request #603 (2021-08-04 10:32:45)

feat: change default value of `processDynamicNodeImports`
**- Summary**

The `processDynamicNodeImports` configuration property controls whether esbuild should add a runtime shim to any imports using dynamic expressions. The [feature flag](https://github.com/netlify/build/blob/main/packages/build/src/core/feature_flags.js#L20) in Netlify Build that controls this value has been fully rolled out to production, so we can begin its removal.

This PR changes the default value of `processDynamicNodeImports` to `true`, but still allows the functionality to be switched off if the value of the property is `false`. 

**- Test plan**

Tests updated.

**- A picture of a cute animal (not mandatory but encouraged)**

![f8cc66794661850608a39e78cc693558](https://user-images.githubusercontent.com/4162329/128166672-72039a07-bf87-4bd7-a0a0-0c325b9c39a3.jpg)


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

*Comparing with f41a7a28b9b049ade7b656b0dc79deb4f45c829e*

### largeDepsEsbuild: 11.9s
 ⬆️ **2.05% increase** vs. f41a7a28b9b049ade7b656b0dc79deb4f45c829e
```
^                           14s                                                                           
│                           ┌──┐                                                           13.3s          
│                           |  |           12.5s           12.7s                   12.4s    ┌──┐          
│                           |  |            ┌──┐            ┌──┐   12.2s            ┌──┐    |  |   11.9s  
│ ─────────10.9s────────────┼──┼────────────┼──┼────────────┼──┼────┌──┐────────────┼──┼────┼──┼────┌──┐──
│  10.6s    ┌──┐            |  |            |  |   10.6s    |  |    |  |            |  |    |  |    |▒▒|  
│   ┌──┐    |  |    9.8s    |  |    9.6s    |  |    ┌──┐    |  |    |  |    10s     |  |    |  |    |▒▒|  
│   |  |    |  |    ┌──┐    |  |    ┌──┐    |  |    |  |    |  |    |  |    ┌──┐    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    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 (f41a7a28b9b049ade7b656b0dc79deb4f45c829e): 11.6s
- T-29 (65c4b941e2866aab49c77cb55504ddad4bdb50a2): 12.9s
- T-28 (e6490d61a256a27c70f3b602ec37e648d415b442): 10.9s
- T-27 (15787efd3bfac84e0036e96082d071afa67c42c5): 11.3s
- T-26 (1ce8157a7351adbc6c6c751ddc8499e9080536b8): 12.9s
- T-25 (96c833514c1b10081dee2a1c236e05186c2ebe01): 13.2s
- T-24 (5d48d64bea0d963efa9dbe64925baef24002a9a4): 12.4s
- T-23 (bd7206ea53810a73ea9938f4e34e2826a142ae2d): 14.3s
- T-22 (69fdb7b0f312a6e007e6cedd6a40494772756eef): 11.4s
- T-21 (57a644f24c7bfd2c0ab1e19360465a3301157162): 13.8s
- T-20 (a9a9e610e1324bbcbee604561605dd12c8a7c4c8): 13.2s
- T-19 (8e299a25c7449b440f7a07849d73b8f184a3245c): 12.6s
- T-18 (cebf521a0a5e42ee0244108aa86367f74524f1be): 10.5s
- T-17 (b789589e534a4cc26c6a56636039b9a22f07a2e3): 12.9s
- T-16 (2e25a52b4d23522c64a01c78f7dba16291a085cf): 12.3s
- T-15 (fec9333941c4b8d0a6a648fd755ddecca07fc892): 12.1s
- T-14 (bd61ad00330f73d247dac787734abc9efeaba4b1): 12.7s
- T-13 (9c3d239efb5f53d53ada4c2d92db6f48b7401096): 13.9s
- T-12 (d790873c4cfb82de3f9d5cc64c2ecb45f4c4112f): 10.6s
- T-11 (c18abffd799ee05a0336a34fffd9a1d48e71c550): 10.9s
- T-10 (a0b35e4de9ee40eb9eed4fdd85a16796983fe154): 9.8s
- T-9 (f9084030bf84398023793983490c294b7b8ff483): 14s
- T-8 (b8eb5f8da62d48468c4aff35f2ed65b175bb14c7): 9.6s
- T-7 (cc6070c8f5a0b44163e3167be9b0beab9bf1c644): 12.5s
- T-6 (d1f77ee0caf96a19702d81abd85b8814ed62ab1c): 10.6s
- T-5 (2a11f56404dfdb6d92881751e9a21ed11f432ec8): 12.7s
- T-4 (30ec7f6a4e97007c2f5e0c40b85b196884acd10f): 12.2s
- T-3 (49c33d8209130930cdeed3b953ac874047cba15a): 10s
- T-2 (0bc0ff937f2bfc93d930c78ea4afb7ede53e30c1): 12.4s
- T-1 (69142468b5054449c51186dd64f79ec67ea7899b): 13.3s
- **T (current commit): 11.9s**</details>
### largeDepsZisi: 1m 7.7s
 ⬆️ **3.48% increase** vs. f41a7a28b9b049ade7b656b0dc79deb4f45c829e
```
^                         1m 15.1s                                                        1m 14.3s        
│                           ┌──┐                                                            ┌──┐          
│                           |  |                          1m 8.7s                           |  |  1m 7.7s 
│                           |  |          1m 4.1s           ┌──┐                   1m 4s    |  |    ┌──┐  
│          58.4s            |  |            ┌──┐            |  |  1m 1.5s           ┌──┐    |  |    |▒▒|  
│ ──────────┌──┐────────────┼──┼────────────┼──┼───54.9s────┼──┼────┌──┐────────────┼──┼────┼──┼────|▒▒|──
│  54.3s    |  |   51.8s    |  |    51s     |  |    ┌──┐    |  |    |  |   52.8s    |  |    |  |    |▒▒|  
│   ┌──┐    |  |    ┌──┐    |  |    ┌──┐    |  |    |  |    |  |    |  |    ┌──┐    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    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 (f41a7a28b9b049ade7b656b0dc79deb4f45c829e): 1m 5.4s
- T-29 (65c4b941e2866aab49c77cb55504ddad4bdb50a2): 1m 15s
- T-28 (e6490d61a256a27c70f3b602ec37e648d415b442): 59s
- T-27 (15787efd3bfac84e0036e96082d071afa67c42c5): 55.9s
- T-26 (1ce8157a7351adbc6c6c751ddc8499e9080536b8): 1m 2.9s
- T-25 (96c833514c1b10081dee2a1c236e05186c2ebe01): 1m 3.6s
- T-24 (5d48d64bea0d963efa9dbe64925baef24002a9a4): 1m 2.1s
- T-23 (bd7206ea53810a73ea9938f4e34e2826a142ae2d): 1m 11.7s
- T-22 (69fdb7b0f312a6e007e6cedd6a40494772756eef): 54.7s
- T-21 (57a644f24c7bfd2c0ab1e19360465a3301157162): 1m 6.5s
- T-20 (a9a9e610e1324bbcbee604561605dd12c8a7c4c8): 1m 9.5s
- T-19 (8e299a25c7449b440f7a07849d73b8f184a3245c): 1m 3.8s
- T-18 (cebf521a0a5e42ee0244108aa86367f74524f1be): 51.2s
- T-17 (b789589e534a4cc26c6a56636039b9a22f07a2e3): 1m 8.3s
- T-16 (2e25a52b4d23522c64a01c78f7dba16291a085cf): 1m 3.4s
- T-15 (fec9333941c4b8d0a6a648fd755ddecca07fc892): 1m 4.1s
- T-14 (bd61ad00330f73d247dac787734abc9efeaba4b1): 1m 7.9s
- T-13 (9c3d239efb5f53d53ada4c2d92db6f48b7401096): 1m 17.1s
- T-12 (d790873c4cfb82de3f9d5cc64c2ecb45f4c4112f): 54.3s
- T-11 (c18abffd799ee05a0336a34fffd9a1d48e71c550): 58.4s
- T-10 (a0b35e4de9ee40eb9eed4fdd85a16796983fe154): 51.8s
- T-9 (f9084030bf84398023793983490c294b7b8ff483): 1m 15.1s
- T-8 (b8eb5f8da62d48468c4aff35f2ed65b175bb14c7): 51s
- T-7 (cc6070c8f5a0b44163e3167be9b0beab9bf1c644): 1m 4.1s
- T-6 (d1f77ee0caf96a19702d81abd85b8814ed62ab1c): 54.9s
- T-5 (2a11f56404dfdb6d92881751e9a21ed11f432ec8): 1m 8.7s
- T-4 (30ec7f6a4e97007c2f5e0c40b85b196884acd10f): 1m 1.5s
- T-3 (49c33d8209130930cdeed3b953ac874047cba15a): 52.8s
- T-2 (0bc0ff937f2bfc93d930c78ea4afb7ede53e30c1): 1m 4s
- T-1 (69142468b5054449c51186dd64f79ec67ea7899b): 1m 14.3s
- **T (current commit): 1m 7.7s**</details>
<!--delta:benchmark@{}-->

Patch:
diff --git a/src/runtimes/node/bundler.js b/src/runtimes/node/bundler.js
index a686f82..0c1d625 100644
--- a/src/runtimes/node/bundler.js
+++ b/src/runtimes/node/bundler.js
@@ -57,7 +57,7 @@ const bundleJsFile = async function ({
       basePath,
       includedPaths: dynamicImportsIncludedPaths,
       moduleNames: nodeModulesWithDynamicImports,
-      processImports: config.processDynamicNodeImports === true,
+      processImports: config.processDynamicNodeImports !== false,
       srcDir,
     }),
   ]


Test patch:
diff --git a/tests/main.js b/tests/main.js
index 4b4167f..7026b88 100644
--- a/tests/main.js
+++ b/tests/main.js
@@ -1424,10 +1424,13 @@ test('Returns an empty list of modules with dynamic imports if the modules are m
   t.is(files[0].nodeModulesWithDynamicImports.length, 0)
 })
 
-test('Leaves dynamic imports untouched when the `processDynamicNodeImports` configuration property is not `true`', async (t) => {
+test('Leaves dynamic imports untouched when the `processDynamicNodeImports` configuration property is `false`', async (t) => {
   const fixtureName = 'node-module-dynamic-import-template-literal'
   const { tmpDir } = await zipNode(t, fixtureName, {
-    opts: { basePath: join(FIXTURES_DIR, fixtureName), config: { '*': { nodeBundler: ESBUILD } } },
+    opts: {
+      basePath: join(FIXTURES_DIR, fixtureName),
+      config: { '*': { nodeBundler: ESBUILD, processDynamicNodeImports: false } },
+    },
   })
   const functionSource = await pReadFile(`${tmpDir}/function.js`, 'utf8')
 
@@ -1445,7 +1448,7 @@ test('Adds a runtime shim and includes the files needed for dynamic imports usin
   const { files, tmpDir } = await zipNode(t, fixtureName, {
     opts: {
       basePath: join(FIXTURES_DIR, fixtureName),
-      config: { '*': { nodeBundler: ESBUILD, processDynamicNodeImports: true } },
+      config: { '*': { nodeBundler: ESBUILD } },
     },
   })
 
@@ -1466,7 +1469,7 @@ test('Leaves dynamic imports untouched when the files required to resolve the ex
   const { tmpDir } = await zipNode(t, fixtureName, {
     opts: {
       basePath: join(FIXTURES_DIR, fixtureName),
-      config: { '*': { nodeBundler: ESBUILD, processDynamicNodeImports: true } },
+      config: { '*': { nodeBundler: ESBUILD } },
     },
   })
   const functionSource = await pReadFile(`${tmpDir}/function.js`, 'utf8')
@@ -1482,7 +1485,7 @@ test('Adds a runtime shim and includes the files needed for dynamic imports usin
   const { tmpDir } = await zipNode(t, fixtureName, {
     opts: {
       basePath: join(FIXTURES_DIR, fixtureName),
-      config: { '*': { nodeBundler: ESBUILD, processDynamicNodeImports: true } },
+      config: { '*': { nodeBundler: ESBUILD } },
     },
   })
 
@@ -1501,7 +1504,7 @@ test('The dynamic import runtime shim handles files in nested directories', asyn
   const { tmpDir } = await zipNode(t, fixtureName, {
     opts: {
       basePath: join(FIXTURES_DIR, fixtureName),
-      config: { '*': { nodeBundler: ESBUILD, processDynamicNodeImports: true } },
+      config: { '*': { nodeBundler: ESBUILD } },
     },
   })
 
@@ -1523,7 +1526,7 @@ test('The dynamic import runtime shim handles files in nested directories when u
     opts: {
       archiveFormat: 'none',
       basePath: join(FIXTURES_DIR, fixtureName),
-      config: { '*': { nodeBundler: ESBUILD, processDynamicNodeImports: true } },
+      config: { '*': { nodeBundler: ESBUILD } },
     },
   })
 
@@ -1544,7 +1547,7 @@ test('Negated files in `included_files` are excluded from the bundle even if the
   const { tmpDir } = await zipNode(t, fixtureName, {
     opts: {
       basePath: join(FIXTURES_DIR, fixtureName),
-      config: { '*': { includedFiles: ['!lang/en.*'], nodeBundler: ESBUILD, processDynamicNodeImports: true } },
+      config: { '*': { includedFiles: ['!lang/en.*'], nodeBundler: ESBUILD } },
     },
   })
 
@@ -1564,7 +1567,7 @@ test('Creates dynamic import shims for functions with the same name and same shi
     length: FUNCTION_COUNT,
     opts: {
       basePath: join(FIXTURES_DIR, fixtureName),
-      config: { '*': { nodeBundler: ESBUILD, processDynamicNodeImports: true } },
+      config: { '*': { nodeBundler: ESBUILD } },
     },
   })
 
@@ -1585,7 +1588,7 @@ test('Creates dynamic import shims for functions using `zipFunction`', async (t)
   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 } },
+    config: { '*': { nodeBundler: 'esbuild' } },
   })
 
   await unzipFiles([result])