Skip to content

Normalize CLI content globs - #5628

Merged
bradlc merged 3 commits into
masterfrom
cli-normalize-globs
Sep 29, 2021
Merged

Normalize CLI content globs#5628
bradlc merged 3 commits into
masterfrom
cli-normalize-globs

Conversation

@bradlc

@bradlc bradlc commented Sep 28, 2021

Copy link
Copy Markdown
Contributor

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.

@RobinMalfait RobinMalfait left a comment

Copy link
Copy Markdown
Member

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!

Comment thread src/cli.js
@@ -437,12 +438,14 @@ async function build() {
}

function extractFileGlobs(config) {

Copy link
Copy Markdown
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
Copy Markdown
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.

3 participants