Skip to content

Commit a069813

Browse files
committed
wip
1 parent 7ad17cc commit a069813

File tree

10 files changed

+88
-31
lines changed

10 files changed

+88
-31
lines changed

integrations/content-resolution/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"version": "0.0.0",
55
"scripts": {
66
"build": "NODE_ENV=production postcss ./src/index.css -o ./dist/main.css --verbose",
7-
"test": "jest --runInBand --forceExit"
7+
"test": "jest --runInBand --forceExit",
8+
"prewip": "npm run --prefix=../../ build",
9+
"wip": "npx postcss ./src/index.css -o ./dist/main.css"
810
},
911
"jest": {
1012
"testTimeout": 10000,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="mr-2"></div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="mr-3"></div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="mr-1"></div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="mr-5"></div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="mr-4"></div>

integrations/content-resolution/tests/content.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,30 @@ it('it can resolve symlinks for files when relative to the config', async () =>
285285
}
286286
`)
287287
})
288+
289+
it('handles some special glob characters in paths', async () => {
290+
await writeConfigs({
291+
both: {
292+
content: {
293+
relative: true,
294+
files: [
295+
'./src/escapes/1.html',
296+
'./src/escapes/(test)/2.html',
297+
'./src/escapes/(test)/[test]/3.html',
298+
'./src/escapes/[test]/4.html',
299+
'./src/escapes/[test]/(test)/5.html',
300+
],
301+
},
302+
},
303+
})
304+
305+
let result = await build({ cwd: path.resolve(__dirname, '..') })
306+
307+
expect(result.css).toMatchFormattedCss(css`
308+
.mr-1 { margin-right: 0.25rem; }
309+
.mr-2 { margin-right: 0.5rem; }
310+
.mr-3 { margin-right: 0.75rem; }
311+
.mr-4 { margin-right: 1rem; }
312+
.mr-5 { margin-right: 1.25rem; }
313+
`)
314+
})

integrations/execute.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,29 @@ function debounce(fn, ms) {
2020
}
2121
}
2222

23+
function resolveCommandPath(root, command) {
24+
let paths = [
25+
path.resolve(root, 'node_modules', '.bin', command),
26+
path.resolve(root, '..', '..', 'node_modules', '.bin', command),
27+
]
28+
29+
if (path.sep === '\\') {
30+
paths = [
31+
path.resolve(root, 'node_modules', '.bin', `${command}.cmd`),
32+
path.resolve(root, '..', '..', 'node_modules', '.bin', `${command}.cmd`),
33+
...paths,
34+
]
35+
}
36+
37+
for (let filepath of paths) {
38+
if (fs.existsSync(filepath)) {
39+
return filepath
40+
}
41+
}
42+
43+
return `npx ${command}`
44+
}
45+
2346
module.exports = function $(command, options = {}) {
2447
let abortController = new AbortController()
2548
let root = resolveToolRoot()
@@ -33,19 +56,7 @@ module.exports = function $(command, options = {}) {
3356
command =
3457
command === 'node'
3558
? command
36-
: (function () {
37-
let local = path.resolve(root, 'node_modules', '.bin', command)
38-
if (fs.existsSync(local)) {
39-
return local
40-
}
41-
42-
let hoisted = path.resolve(root, '..', '..', 'node_modules', '.bin', command)
43-
if (fs.existsSync(hoisted)) {
44-
return hoisted
45-
}
46-
47-
return `npx ${command}`
48-
})()
59+
: resolveCommandPath(root, command)
4960
return [command, args]
5061
})()
5162

integrations/resolve-tool-root.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ let path = require('path')
22

33
module.exports = function resolveToolRoot() {
44
let { testPath } = expect.getState()
5-
let separator = '/' // TODO: Does this resolve correctly on windows, or should we use `path.sep` instead.
65

76
return path.resolve(
87
__dirname,
98
testPath
10-
.replace(__dirname + separator, '')
11-
.split(separator)
9+
.replace(__dirname + path.sep, '')
10+
.split(path.sep)
1211
.shift()
1312
)
1413
}

src/lib/content.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ function normalizePath(path) {
5050
// `/` and `\\` that is _not_ followed by any of the following characters: ()[]
5151
// This is to ensure that we keep the escaping of brackets and parentheses
5252
let segs = path.split(/[/\\]+(?![\(\)\[\]])/)
53+
5354
return prefix + segs.join('/')
5455
}
5556

@@ -110,6 +111,8 @@ export function parseCandidateFiles(context, tailwindConfig) {
110111
skip: [context.userConfigPath],
111112
})
112113

114+
console.log({ files })
115+
113116
// Normalize the file globs
114117
files = files.filter((filePath) => typeof filePath === 'string')
115118

@@ -129,15 +132,23 @@ export function parseCandidateFiles(context, tailwindConfig) {
129132

130133
let paths = [...included, ...excluded]
131134

135+
console.log("parseCandidateFiles 0", { paths })
136+
132137
// Resolve paths relative to the config file or cwd
133138
paths = resolveRelativePaths(context, paths)
134139

140+
console.log("parseCandidateFiles 1", { paths })
141+
135142
// Resolve symlinks if possible
136143
paths = paths.flatMap(resolvePathSymlinks)
137144

145+
console.log("parseCandidateFiles 2", { paths })
146+
138147
// Update cached patterns
139148
paths = paths.map(resolveGlobPattern)
140149

150+
console.log("parseCandidateFiles 3", { paths })
151+
141152
return paths
142153
}
143154

@@ -186,18 +197,13 @@ function parseFilePath(filePath, ignore) {
186197
* @returns {ContentPath}
187198
*/
188199
function resolveGlobPattern(contentPath) {
189-
// This is required for Windows support to properly pick up Glob paths.
190-
// Afaik, this technically shouldn't be needed but there's probably
191-
// some internal, direct path matching with a normalized path in
192-
// a package which can't handle mixed directory separators
193-
let base = normalizePath(contentPath.base)
200+
contentPath.pattern = contentPath.glob
201+
? `${contentPath.base}/${contentPath.glob}`
202+
: contentPath.base
194203

195-
// If the user's file path contains any special characters (like parens) for instance fast-glob
196-
// is like "OOOH SHINY" and treats them as such. So we have to escape the base path to fix this
197-
base = fastGlob.escapePath(base)
198-
199-
contentPath.pattern = contentPath.glob ? `${base}/${contentPath.glob}` : base
200-
contentPath.pattern = contentPath.ignore ? `!${contentPath.pattern}` : contentPath.pattern
204+
contentPath.pattern = contentPath.ignore
205+
? `!${contentPath.pattern}`
206+
: contentPath.pattern
201207

202208
return contentPath
203209
}
@@ -215,11 +221,15 @@ function resolveRelativePaths(context, contentPaths) {
215221

216222
// Resolve base paths relative to the config file (when possible) if the experimental flag is enabled
217223
if (context.userConfigPath && context.tailwindConfig.content.relative) {
218-
resolveFrom = [path.dirname(context.userConfigPath)]
224+
resolveFrom = [path.posix.dirname(context.userConfigPath)]
219225
}
220226

221227
return contentPaths.map((contentPath) => {
222-
contentPath.base = path.resolve(...resolveFrom, contentPath.base)
228+
contentPath.base = path.posix.resolve(...resolveFrom, contentPath.base)
229+
230+
if (path.sep === '\\' && contentPath.base.startsWith('/') && !contentPath.base.startsWith('//?/')) {
231+
contentPath.base = `C:${contentPath.base}`
232+
}
223233

224234
return contentPath
225235
})
@@ -238,7 +248,7 @@ function resolvePathSymlinks(contentPath) {
238248
let paths = [contentPath]
239249

240250
try {
241-
let resolvedPath = fs.realpathSync(contentPath.base)
251+
let resolvedPath = normalizePath(fs.realpathSync(contentPath.base))
242252
if (resolvedPath !== contentPath.base) {
243253
paths.push({
244254
...contentPath,
@@ -286,6 +296,9 @@ function resolveChangedFiles(candidateFiles, fileModifiedMap) {
286296
let changedFiles = new Set()
287297
env.DEBUG && console.time('Finding changed files')
288298
let files = fastGlob.sync(paths, { absolute: true })
299+
300+
console.log({ paths, files })
301+
289302
for (let file of files) {
290303
let prevModified = fileModifiedMap.get(file) || -Infinity
291304
let modified = fs.statSync(file).mtimeMs

0 commit comments

Comments
 (0)