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 <jordan@cryptica.me>
This commit is contained in:
Robin Malfait 2024-11-07 21:31:06 +01:00 committed by GitHub
parent 95c4877200
commit 99c4c04c54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 19 deletions

View File

@ -21,6 +21,7 @@ interface SpawnedProcess {
interface ChildProcessOptions {
cwd?: string
env?: Record<string, string>
}
interface ExecOptions {
@ -109,6 +110,7 @@ export function test(
{
cwd,
...childProcessOptions,
env: childProcessOptions.env,
},
(error, stdout, stderr) => {
if (error) {
@ -145,10 +147,11 @@ export function test(
let child = spawn(command, {
cwd,
shell: true,
...childProcessOptions,
env: {
...process.env,
...childProcessOptions.env,
},
...childProcessOptions,
})
function dispose() {

View File

@ -65,7 +65,11 @@ test('dev mode', SETUP, async ({ fs, spawn, getFreePort }) => {
test('build', SETUP, async ({ spawn, getFreePort, exec }) => {
let port = await getFreePort()
await exec(`pnpm nuxt build`)
await spawn(`PORT=${port} pnpm nuxt preview`)
await spawn(`pnpm nuxt preview`, {
env: {
PORT: `${port}`,
},
})
await retryAssertion(async () => {
let css = await fetchStyles(port)

View File

@ -1,6 +1,6 @@
import { Scanner } from '@tailwindcss/oxide'
import fs from 'node:fs/promises'
import { dirname, resolve } from 'node:path'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { type Config } from 'tailwindcss'
import defaultTheme from 'tailwindcss/defaultTheme'
@ -21,7 +21,7 @@ import { findStaticPlugins, type StaticPluginOptions } from './utils/extract-sta
import { info } from './utils/renderer'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const __dirname = path.dirname(__filename)
export type JSConfigMigration =
// Could not convert the config file, need to inject it as-is in a @config directive
@ -195,21 +195,21 @@ async function migrateContent(
return unresolvedConfig.future?.relativeContentPathsByDefault ?? false
})()
let contentFiles = Array.isArray(unresolvedConfig.content)
? unresolvedConfig.content
: (unresolvedConfig.content?.files ?? []).map((content) => {
if (typeof content === 'string' && contentIsRelative) {
return resolve(dirname(configPath), content)
let sourceGlobs = Array.isArray(unresolvedConfig.content)
? unresolvedConfig.content.map((pattern) => ({ base, pattern }))
: (unresolvedConfig.content?.files ?? []).map((pattern) => {
if (typeof pattern === 'string' && contentIsRelative) {
return { base: path.dirname(configPath), pattern: pattern }
}
return content
return { base, pattern }
})
for (let content of contentFiles) {
if (typeof content !== 'string') {
throw new Error('Unsupported content value: ' + content)
for (let { base, pattern } of sourceGlobs) {
if (typeof pattern !== 'string') {
throw new Error('Unsupported content value: ' + pattern)
}
let sourceFiles = patternSourceFiles({ base, pattern: content })
let sourceFiles = patternSourceFiles({ base, pattern })
let autoContentContainsAllSourceFiles = true
for (let sourceFile of sourceFiles) {
@ -220,7 +220,7 @@ async function migrateContent(
}
if (!autoContentContainsAllSourceFiles) {
sources.push({ base, pattern: content })
sources.push({ base, pattern })
}
}
return sources

View File

@ -86,7 +86,7 @@ export default async function migrateContents(
}
export async function migrate(designSystem: DesignSystem, userConfig: Config, file: string) {
let fullPath = path.resolve(process.cwd(), file)
let fullPath = path.isAbsolute(file) ? file : path.resolve(process.cwd(), file)
let contents = await fs.readFile(fullPath, 'utf-8')
await fs.writeFile(

View File

@ -1,3 +1,4 @@
import { normalizePath } from '@tailwindcss/node'
import braces from 'braces'
import path from 'node:path'
@ -12,10 +13,12 @@ export function hoistStaticGlobParts(entry: GlobEntry): GlobEntry[] {
let [staticPart, dynamicPart] = splitPattern(pattern)
// Move static part into the `base`.
let absolutePosixPath = normalizePath(entry.base)
if (staticPart !== null) {
clone.base = path.resolve(entry.base, staticPart)
clone.base = path.posix.join(absolutePosixPath, staticPart)
} else {
clone.base = path.resolve(entry.base)
clone.base = absolutePosixPath
}
// Move dynamic part into the `pattern`.
@ -56,7 +59,7 @@ function splitPattern(pattern: string): [staticPart: string | null, dynamicPart:
let lastSlashPosition: number | null = null
for (let i = 0; i < pattern.length; i++) {
let c = pattern[i];
let c = pattern[i]
if (c === '/') {
lastSlashPosition = i
}