diff --git a/integrations/utils.ts b/integrations/utils.ts index 9b06d8dc1a18..0a881ba367f6 100644 --- a/integrations/utils.ts +++ b/integrations/utils.ts @@ -21,6 +21,7 @@ interface SpawnedProcess { interface ChildProcessOptions { cwd?: string + env?: Record } 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() { diff --git a/integrations/vite/nuxt.test.ts b/integrations/vite/nuxt.test.ts index 8c7eedc386d7..cfd521e48300 100644 --- a/integrations/vite/nuxt.test.ts +++ b/integrations/vite/nuxt.test.ts @@ -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) diff --git a/packages/@tailwindcss-upgrade/src/migrate-js-config.ts b/packages/@tailwindcss-upgrade/src/migrate-js-config.ts index 63fc094db8fb..84a062b461b8 100644 --- a/packages/@tailwindcss-upgrade/src/migrate-js-config.ts +++ b/packages/@tailwindcss-upgrade/src/migrate-js-config.ts @@ -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 diff --git a/packages/@tailwindcss-upgrade/src/template/migrate.ts b/packages/@tailwindcss-upgrade/src/template/migrate.ts index d70ca20f9dec..f95344fa0bc8 100644 --- a/packages/@tailwindcss-upgrade/src/template/migrate.ts +++ b/packages/@tailwindcss-upgrade/src/template/migrate.ts @@ -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( diff --git a/packages/@tailwindcss-upgrade/src/utils/hoist-static-glob-parts.ts b/packages/@tailwindcss-upgrade/src/utils/hoist-static-glob-parts.ts index 0c8ab4629fd6..18d58799857b 100644 --- a/packages/@tailwindcss-upgrade/src/utils/hoist-static-glob-parts.ts +++ b/packages/@tailwindcss-upgrade/src/utils/hoist-static-glob-parts.ts @@ -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 }