5448c234d6
### What? - [x] fixes a bug in the CLI with the combination of `--tailwind` and `--src-dir` flags. - [x] fixes Tailwind CSS config when `--src-dir` is set - [x] respect `NEXT_TEST_SKIP_CLEANUP` in test utils ### Why? `pnpm create next-app@canary --tailwind --src-dir` should not fail. ### How? We introduced the `app-tw` and `default-tw` templates, so we need to respect them when working with files (in this case, the CLI was erroneously assuming that if `template !== "app"` it must be a pages template.) I also noticed that the `tailwind.config.js` file need to also respect `--src-dir` by prefixing the paths in `content` Fixes #47236 fix NEXT-838 ([link](https://linear.app/vercel/issue/NEXT-838)) Related: #46927, #47276 --------- Co-authored-by: JJ Kasper <jj@jjsweb.site>
30 lines
666 B
TypeScript
30 lines
666 B
TypeScript
import fs from 'fs-extra'
|
|
import os from 'os'
|
|
import path from 'path'
|
|
|
|
/**
|
|
* Create a randomly-named directory in `os.tmpdir()`, await a function call,
|
|
* and delete the directory when finished, unless `NEXT_TEST_SKIP_CLEANUP` is set.
|
|
*/
|
|
export async function useTempDir(
|
|
fn: (folder: string) => void | Promise<void>,
|
|
mode?: string | number
|
|
) {
|
|
const folder = path.join(
|
|
os.tmpdir(),
|
|
'next-test-' + Math.random().toString(36).slice(2)
|
|
)
|
|
await fs.mkdirp(folder)
|
|
|
|
if (mode) {
|
|
await fs.chmod(folder, mode)
|
|
}
|
|
|
|
try {
|
|
await fn(folder)
|
|
} finally {
|
|
if (!process.env.NEXT_TEST_SKIP_CLEANUP) {
|
|
await fs.remove(folder)
|
|
}
|
|
}
|
|
}
|