Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize CLI content globs #5628

Merged
merged 3 commits into from
Sep 29, 2021
Merged

Normalize CLI content globs #5628

merged 3 commits into from
Sep 29, 2021

Conversation

bradlc
Copy link
Contributor

@bradlc bradlc commented Sep 28, 2021

This PR ensures that the content globs are normalized when using the CLI, like they are when not using the CLI.

fast-glob expects patterns to always use forward-slashes, but when using something like path.resolve on Windows your pattern might end up with back-slashes and not working, e.g.

module.exports = {
  content: [require('path').resolve(__dirname, 'index.html')], // C:\Users\Me\Project\index.html
}

This doesn't currently work when using the CLI on Windows, but this PR fixes that.

Copy link
Contributor

@RobinMalfait RobinMalfait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, looks like it fixes 2 issues at once!

@@ -437,12 +438,14 @@ async function build() {
}

function extractFileGlobs(config) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use this function in both the `getChangedContent.

tailwindcss/src/cli.js

Lines 461 to 462 in 2ab6e6e

let globs = extractFileGlobs(config)
let files = fastGlob.sync(globs)

But we also use this function when setting up the chokidar watcher:

watcher = chokidar.watch([...contextDependencies, ...extractFileGlobs(config)], {

And I wonder if this causes issues, because now we are passing normalized paths to chokidar. Do you know if chokidar can handle C:/../ instead of C:\..\? 🤔

Ah nvm, it fixes chokidar as well: https://github.com/paulmillr/chokidar#api

Note: globs must not contain windows separators (), because that's how they work by the standard — you'll need to replace them with forward slashes (/).

Nice!

@adamwathan
Copy link
Member

Should we backport this to v2 as well?

@bradlc bradlc merged commit 484acb3 into master Sep 29, 2021
@bradlc bradlc deleted the cli-normalize-globs branch September 29, 2021 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants