From 55aa4035f5ffd01021a5f94bb92685dc0170e7f1 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Mon, 27 Mar 2023 19:41:20 +0200 Subject: [PATCH] Fix format assumption when resolving module dependencies (#10878) * fix assumption when resolving dependencies When resolving dependencies given a path, we are only interested relative files from the current file. We are not interested in the dependencies that are listed in your `package.json` and thus in your `node_modules` folder. We made the assumption that your imports have at least 3 characters. This sort of makes sense because there will be a `.`, then the OS separator like `/` and than a file name. E.g.: `./a` is the minimal amount of characters. This makes sense for `import` statements, but in the case of `require`, it is totally valid to write `require('.')`. This will require the current `index.{js,ts,mjs,cjs,...}` in the current directory. Before this change, having a `require('.')` wouldn't crash, but the dependency would not be marked as a module dependencies and therefore we won't listen for file changes for that dependency. * update changelog --- CHANGELOG.md | 1 + src/lib/getModuleDependencies.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62e9d5265a09..0a00a241213c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Sort class lists deterministically for Prettier plugin ([#10672](https://github.com/tailwindlabs/tailwindcss/pull/10672)) - Ensure CLI builds have a non-zero exit code on failure ([#10703](https://github.com/tailwindlabs/tailwindcss/pull/10703)) - Ensure module dependencies for value `null`, is an empty `Set` ([#10877](https://github.com/tailwindlabs/tailwindcss/pull/10877)) +- Fix format assumption when resolving module dependencies ([#10878](https://github.com/tailwindlabs/tailwindcss/pull/10878)) ### Changed diff --git a/src/lib/getModuleDependencies.js b/src/lib/getModuleDependencies.js index bd27022f29c7..e6a38a89d21f 100644 --- a/src/lib/getModuleDependencies.js +++ b/src/lib/getModuleDependencies.js @@ -62,7 +62,7 @@ function* _getModuleDependencies(filename, base, seen, ext = path.extname(filena for (let match of [ ...contents.matchAll(/import[\s\S]*?['"](.{3,}?)['"]/gi), ...contents.matchAll(/import[\s\S]*from[\s\S]*?['"](.{3,}?)['"]/gi), - ...contents.matchAll(/require\(['"`](.{3,})['"`]\)/gi), + ...contents.matchAll(/require\(['"`](.+)['"`]\)/gi), ]) { // Bail out if it's not a relative file if (!match[1].startsWith('.')) continue