diff --git a/packages/cli/src/commands/setup/tailwind/tailwind.js b/packages/cli/src/commands/setup/tailwind/tailwind.js index 956f4414aaef..742093bbf102 100644 --- a/packages/cli/src/commands/setup/tailwind/tailwind.js +++ b/packages/cli/src/commands/setup/tailwind/tailwind.js @@ -143,30 +143,28 @@ export const handler = async ({ force }) => { 'Tailwindcss config already exists.\nUse --force to override existing config.' ) } else { + // A gotcha here is that `yarn tailwindcss init` can generate + // tailwind.config.js in either BASE_DIR or BASE_DIR/web, depending + // on what cwd is await execa('yarn', ['tailwindcss', 'init']) - // When the `yarn tailwindcss init` command is issued a - // tailwind.config.js file will be generated in cwd(). (cwd() will - // be either BASE_DIR or BASE_DIR/web depending on where the user - // runns the command from.) By only passing the filename (and not a - // fully qualified path) to the fs.* commands below node will look - // in cwd() for the file. + const tailwindConfigPathCwd = path.join(process.cwd(), 'tailwind.config.js') // opt-in to upcoming changes - const config = fs.readFileSync('tailwind.config.js', 'utf-8') + const config = fs.readFileSync(tailwindConfigPathCwd, 'utf-8') const uncommentFlags = (str) => str.replace(/\/{2} ([\w-]+: true)/g, '$1') const newConfig = config.replace(/future.*purge/s, uncommentFlags) - fs.writeFileSync('tailwind.config.js', newConfig) + fs.writeFileSync(tailwindConfigPathCwd, newConfig) /** * Later, when we can tell the vscode extension where to look for the config, * we can put it in web/config/ */ - fs.renameSync('tailwind.config.js', tailwindConfigPathWeb) + fs.renameSync(tailwindConfigPathCwd, tailwindConfigPathWeb) } }, },