Skip to content

Commit 89f0047

Browse files
CLI: Use the right base when loading files from stdin (#14522)
Fixes #14521 When using the CLI to read files from `stdin` like this: ```bash npx tailwindcss --input=- -o bar.css < foo.css ``` We need to set the `base` path to be the current working directory (`process.cwd()`). However, `cwd()` already _is_ a directory and calling `dirname()` on it did go to the parent directory _which might not have the `tailwindcss` dependency installed.
1 parent 8bbdb57 commit 89f0047

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Fixed
1515

16+
- Use the right import base path when using the CLI to reading files from stdin ([#14522](https://github.com/tailwindlabs/tailwindcss/pull/14522))
1617
- _Experimental_: Improve codemod output, keep CSS after last Tailwind directive unlayered ([#14512](https://github.com/tailwindlabs/tailwindcss/pull/14512))
1718
- _Experimental_: Fix incorrect empty `layer()` at the end of `@import` at-rules when running codemods ([#14513](https://github.com/tailwindlabs/tailwindcss/pull/14513))
1819
- _Experimental_: Migrate `@import "tailwindcss/tailwind.css"` to `@import "tailwindcss"` ([#14514](https://github.com/tailwindlabs/tailwindcss/pull/14514))

integrations/cli/index.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,29 @@ describe.each([
182182
])
183183
},
184184
)
185+
186+
test(
187+
'production build (stdin)',
188+
{
189+
fs: {
190+
'package.json': json`
191+
{
192+
"dependencies": {
193+
"tailwindcss": "workspace:^",
194+
"@tailwindcss/cli": "workspace:^"
195+
}
196+
}
197+
`,
198+
'index.html': html`
199+
<div class="underline"></div>
200+
`,
201+
'src/index.css': css`@import 'tailwindcss';`,
202+
},
203+
},
204+
async ({ fs, exec }) => {
205+
await exec(`${command} --input=- --output dist/out.css < src/index.css`)
206+
207+
await fs.expectFileToContain('dist/out.css', [candidate`underline`])
208+
},
209+
)
185210
})

packages/@tailwindcss-cli/src/commands/build/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ export async function handle(args: Result<ReturnType<typeof options>>) {
118118
}
119119
}
120120

121-
let inputFile = args['--input'] && args['--input'] !== '-' ? args['--input'] : process.cwd()
122-
let inputBasePath = path.dirname(path.resolve(inputFile))
121+
let inputBasePath =
122+
args['--input'] && args['--input'] !== '-'
123+
? path.dirname(path.resolve(args['--input']))
124+
: process.cwd()
123125
let fullRebuildPaths: string[] = []
124126

125127
function createCompiler(css: string) {

0 commit comments

Comments
 (0)