Skip to content

Commit 55aa403

Browse files
authored
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
1 parent 8e85a86 commit 55aa403

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3030
- Sort class lists deterministically for Prettier plugin ([#10672](https://github.com/tailwindlabs/tailwindcss/pull/10672))
3131
- Ensure CLI builds have a non-zero exit code on failure ([#10703](https://github.com/tailwindlabs/tailwindcss/pull/10703))
3232
- Ensure module dependencies for value `null`, is an empty `Set` ([#10877](https://github.com/tailwindlabs/tailwindcss/pull/10877))
33+
- Fix format assumption when resolving module dependencies ([#10878](https://github.com/tailwindlabs/tailwindcss/pull/10878))
3334

3435
### Changed
3536

src/lib/getModuleDependencies.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function* _getModuleDependencies(filename, base, seen, ext = path.extname(filena
6262
for (let match of [
6363
...contents.matchAll(/import[\s\S]*?['"](.{3,}?)['"]/gi),
6464
...contents.matchAll(/import[\s\S]*from[\s\S]*?['"](.{3,}?)['"]/gi),
65-
...contents.matchAll(/require\(['"`](.{3,})['"`]\)/gi),
65+
...contents.matchAll(/require\(['"`](.+)['"`]\)/gi),
6666
]) {
6767
// Bail out if it's not a relative file
6868
if (!match[1].startsWith('.')) continue

0 commit comments

Comments
 (0)