Skip to content

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
Member

@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!

return config.content.content.concat(config.content.safelist)
}

function extractFileGlobs(config) {
Copy link
Member

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.

4 participants