Repository: netlify/zip-it-and-ship-it
Pull request #312 (2021-01-29 11:59:07)

fix: ignore critters if next version = latest
Fixes https://github.com/netlify/next-on-netlify/issues/157#issuecomment-769566359

Another ugly fix.

Moving forward we should allow customization of `zisi` by build plugins. This can happen as a part of https://github.com/netlify/zip-it-and-ship-it/issues/225 or before.

One approach could be to drop a `.netlify/bundle.js.config` file and have `zisi` read it - without doing https://github.com/netlify/zip-it-and-ship-it/issues/225 first that will create some tech debt.


Patch:
diff --git a/src/node_dependencies/nested.js b/src/node_dependencies/nested.js
index f0252c5..ba62f10 100644
--- a/src/node_dependencies/nested.js
+++ b/src/node_dependencies/nested.js
@@ -78,6 +78,10 @@ const isExternalCrittersModule = function (moduleName, { dependencies = {}, devD
   }
   const nextVersion = dependencies.next || devDependencies.next
 
+  if (nextVersion === 'latest') {
+    return true
+  }
+
   // can the declared Next.js version resolve to >=10.0.4 ?
   // test exact versions
   if (validVersion(nextVersion)) {


Test patch:
diff --git a/tests/fixtures/node-module-next10-critters-latest/function/function.js b/tests/fixtures/node-module-next10-critters-latest/function/function.js
new file mode 100644
index 0000000..41d8840
--- /dev/null
+++ b/tests/fixtures/node-module-next10-critters-latest/function/function.js
@@ -0,0 +1,4 @@
+// eslint-disable-next-line import/no-unassigned-import
+require('./renderNextPage')
+
+module.exports = true
diff --git a/tests/fixtures/node-module-next10-critters-latest/function/renderNextPage.js b/tests/fixtures/node-module-next10-critters-latest/function/renderNextPage.js
new file mode 100644
index 0000000..7fd8d6e
--- /dev/null
+++ b/tests/fixtures/node-module-next10-critters-latest/function/renderNextPage.js
@@ -0,0 +1,6 @@
+/* eslint-disable unicorn/filename-case */
+// eslint-disable-next-line import/no-unassigned-import
+require('next/dist/next-server/server/render.js')
+
+module.exports = true
+/* eslint-enable unicorn/filename-case */
diff --git a/tests/fixtures/node-module-next10-critters-latest/node_modules/next/dist/next-server/server/render.js b/tests/fixtures/node-module-next10-critters-latest/node_modules/next/dist/next-server/server/render.js
new file mode 100644
index 0000000..6480be1
--- /dev/null
+++ b/tests/fixtures/node-module-next10-critters-latest/node_modules/next/dist/next-server/server/render.js
@@ -0,0 +1,8 @@
+const render = () => {
+  if (renderOpts.optimizeCss) {
+    // eslint-disable-next-line node/no-extraneous-require
+    require('critters')
+  }
+}
+
+module.exports = render
diff --git a/tests/fixtures/node-module-next10-critters-latest/node_modules/next/index.js b/tests/fixtures/node-module-next10-critters-latest/node_modules/next/index.js
new file mode 100644
index 0000000..33c1891
--- /dev/null
+++ b/tests/fixtures/node-module-next10-critters-latest/node_modules/next/index.js
@@ -0,0 +1,1 @@
+module.exports = true
diff --git a/tests/fixtures/node-module-next10-critters-latest/node_modules/next/package.json b/tests/fixtures/node-module-next10-critters-latest/node_modules/next/package.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/tests/fixtures/node-module-next10-critters-latest/node_modules/next/package.json
@@ -0,0 +1,1 @@
+{}
diff --git a/tests/fixtures/node-module-next10-critters-latest/package.json b/tests/fixtures/node-module-next10-critters-latest/package.json
new file mode 100644
index 0000000..67432c9
--- /dev/null
+++ b/tests/fixtures/node-module-next10-critters-latest/package.json
@@ -0,0 +1,5 @@
+{
+  "dependencies": {
+    "next": "latest"
+  }
+}
diff --git a/tests/main.js b/tests/main.js
index 7da52a1..d4b471c 100644
--- a/tests/main.js
+++ b/tests/main.js
@@ -155,6 +155,10 @@ test('Ignore missing critters dependency for Next.js with range ^10.0.5', async
   await zipNode(t, 'node-module-next10-critters-10.0.5-range')
 })
 
+test(`Ignore missing critters dependency for Next.js with version='latest'`, async (t) => {
+  await zipNode(t, 'node-module-next10-critters-latest')
+})
+
 test('Resolves dependencies from .netlify/plugins/node_modules', async (t) => {
   await zipNode(t, 'node-module-next-image')
 })