Skip to content

Commit

Permalink
Fix format assumption when resolving module dependencies (#10878)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
RobinMalfait committed Mar 27, 2023
1 parent 8e85a86 commit 55aa403
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/lib/getModuleDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 55aa403

Please sign in to comment.