Skip to content

Commit 99c4c04

Browse files
Fix glob pattern hoisting on Windows (#14904)
This ensures our glob hoisting mechanism (see #14896) works on Windows when performing an upgrade. --------- Co-authored-by: Jordan Pittman <[email protected]>
1 parent 95c4877 commit 99c4c04

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

integrations/utils.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface SpawnedProcess {
2121

2222
interface ChildProcessOptions {
2323
cwd?: string
24+
env?: Record<string, string>
2425
}
2526

2627
interface ExecOptions {
@@ -109,6 +110,7 @@ export function test(
109110
{
110111
cwd,
111112
...childProcessOptions,
113+
env: childProcessOptions.env,
112114
},
113115
(error, stdout, stderr) => {
114116
if (error) {
@@ -145,10 +147,11 @@ export function test(
145147
let child = spawn(command, {
146148
cwd,
147149
shell: true,
150+
...childProcessOptions,
148151
env: {
149152
...process.env,
153+
...childProcessOptions.env,
150154
},
151-
...childProcessOptions,
152155
})
153156

154157
function dispose() {

integrations/vite/nuxt.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ test('dev mode', SETUP, async ({ fs, spawn, getFreePort }) => {
6565
test('build', SETUP, async ({ spawn, getFreePort, exec }) => {
6666
let port = await getFreePort()
6767
await exec(`pnpm nuxt build`)
68-
await spawn(`PORT=${port} pnpm nuxt preview`)
68+
await spawn(`pnpm nuxt preview`, {
69+
env: {
70+
PORT: `${port}`,
71+
},
72+
})
6973

7074
await retryAssertion(async () => {
7175
let css = await fetchStyles(port)

packages/@tailwindcss-upgrade/src/migrate-js-config.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Scanner } from '@tailwindcss/oxide'
22
import fs from 'node:fs/promises'
3-
import { dirname, resolve } from 'node:path'
3+
import path from 'node:path'
44
import { fileURLToPath } from 'node:url'
55
import { type Config } from 'tailwindcss'
66
import defaultTheme from 'tailwindcss/defaultTheme'
@@ -21,7 +21,7 @@ import { findStaticPlugins, type StaticPluginOptions } from './utils/extract-sta
2121
import { info } from './utils/renderer'
2222

2323
const __filename = fileURLToPath(import.meta.url)
24-
const __dirname = dirname(__filename)
24+
const __dirname = path.dirname(__filename)
2525

2626
export type JSConfigMigration =
2727
// Could not convert the config file, need to inject it as-is in a @config directive
@@ -195,21 +195,21 @@ async function migrateContent(
195195
return unresolvedConfig.future?.relativeContentPathsByDefault ?? false
196196
})()
197197

198-
let contentFiles = Array.isArray(unresolvedConfig.content)
199-
? unresolvedConfig.content
200-
: (unresolvedConfig.content?.files ?? []).map((content) => {
201-
if (typeof content === 'string' && contentIsRelative) {
202-
return resolve(dirname(configPath), content)
198+
let sourceGlobs = Array.isArray(unresolvedConfig.content)
199+
? unresolvedConfig.content.map((pattern) => ({ base, pattern }))
200+
: (unresolvedConfig.content?.files ?? []).map((pattern) => {
201+
if (typeof pattern === 'string' && contentIsRelative) {
202+
return { base: path.dirname(configPath), pattern: pattern }
203203
}
204-
return content
204+
return { base, pattern }
205205
})
206206

207-
for (let content of contentFiles) {
208-
if (typeof content !== 'string') {
209-
throw new Error('Unsupported content value: ' + content)
207+
for (let { base, pattern } of sourceGlobs) {
208+
if (typeof pattern !== 'string') {
209+
throw new Error('Unsupported content value: ' + pattern)
210210
}
211211

212-
let sourceFiles = patternSourceFiles({ base, pattern: content })
212+
let sourceFiles = patternSourceFiles({ base, pattern })
213213

214214
let autoContentContainsAllSourceFiles = true
215215
for (let sourceFile of sourceFiles) {
@@ -220,7 +220,7 @@ async function migrateContent(
220220
}
221221

222222
if (!autoContentContainsAllSourceFiles) {
223-
sources.push({ base, pattern: content })
223+
sources.push({ base, pattern })
224224
}
225225
}
226226
return sources

packages/@tailwindcss-upgrade/src/template/migrate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default async function migrateContents(
8686
}
8787

8888
export async function migrate(designSystem: DesignSystem, userConfig: Config, file: string) {
89-
let fullPath = path.resolve(process.cwd(), file)
89+
let fullPath = path.isAbsolute(file) ? file : path.resolve(process.cwd(), file)
9090
let contents = await fs.readFile(fullPath, 'utf-8')
9191

9292
await fs.writeFile(

packages/@tailwindcss-upgrade/src/utils/hoist-static-glob-parts.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { normalizePath } from '@tailwindcss/node'
12
import braces from 'braces'
23
import path from 'node:path'
34

@@ -12,10 +13,12 @@ export function hoistStaticGlobParts(entry: GlobEntry): GlobEntry[] {
1213
let [staticPart, dynamicPart] = splitPattern(pattern)
1314

1415
// Move static part into the `base`.
16+
let absolutePosixPath = normalizePath(entry.base)
17+
1518
if (staticPart !== null) {
16-
clone.base = path.resolve(entry.base, staticPart)
19+
clone.base = path.posix.join(absolutePosixPath, staticPart)
1720
} else {
18-
clone.base = path.resolve(entry.base)
21+
clone.base = absolutePosixPath
1922
}
2023

2124
// Move dynamic part into the `pattern`.
@@ -56,7 +59,7 @@ function splitPattern(pattern: string): [staticPart: string | null, dynamicPart:
5659
let lastSlashPosition: number | null = null
5760

5861
for (let i = 0; i < pattern.length; i++) {
59-
let c = pattern[i];
62+
let c = pattern[i]
6063
if (c === '/') {
6164
lastSlashPosition = i
6265
}

0 commit comments

Comments
 (0)