From b63bf5b56edd4e2eb6307fd793bf558e1c2cdb36 Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Mon, 24 Feb 2025 17:30:18 +0100 Subject: [PATCH 1/4] Vite: Handle missing mtime --- packages/@tailwindcss-vite/src/index.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/@tailwindcss-vite/src/index.ts b/packages/@tailwindcss-vite/src/index.ts index 8e3d2348ea16..2a7c933e6340 100644 --- a/packages/@tailwindcss-vite/src/index.ts +++ b/packages/@tailwindcss-vite/src/index.ts @@ -202,8 +202,9 @@ class Root { private candidates: Set = new Set() // List of all build dependencies (e.g. imported stylesheets or plugins) and - // their last modification timestamp - private buildDependencies = new Map() + // their last modification timestamp. If no mtime can be found, we need to + // assume the file has always changed. + private buildDependencies = new Map() constructor( private id: string, @@ -334,14 +335,22 @@ class Root { } private async addBuildDependency(path: string) { - let stat = await fs.stat(path) - this.buildDependencies.set(path, stat.mtimeMs) + let mtime: number | null = null + try { + mtime = (await fs.stat(path)).mtimeMs + } catch {} + this.buildDependencies.set(path, mtime) } private async requiresBuild(): Promise { for (let [path, mtime] of this.buildDependencies) { - let stat = await fs.stat(path) - if (stat.mtimeMs > mtime) { + if (mtime === null) return true + try { + let stat = await fs.stat(path) + if (stat.mtimeMs > mtime) { + return true + } + } catch { return true } } From 5beab27d37af5c7644bdfbe626506de7b6718b04 Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Mon, 24 Feb 2025 17:30:47 +0100 Subject: [PATCH 2/4] Add change log --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b75932023c29..7eb9e3397a7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - _Experimental_: Add `user-valid` and `user-invalid` variants ([#12370](https://github.com/tailwindlabs/tailwindcss/pull/12370)) - _Experimental_: Add `wrap-anywhere`, `wrap-break-word`, and `wrap-normal` utilities ([#12128](https://github.com/tailwindlabs/tailwindcss/pull/12128)) +### Fixed + +- Vite: Don't crash when importing virtual modules + ## [4.0.8] - 2025-02-21 ### Added From a8add9e43a5b1290bc6fc3b737ed391c73886f31 Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Mon, 24 Feb 2025 17:42:30 +0100 Subject: [PATCH 3/4] Add regression test --- integrations/vite/virtual-modules.test.ts | Bin 0 -> 2339 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 integrations/vite/virtual-modules.test.ts diff --git a/integrations/vite/virtual-modules.test.ts b/integrations/vite/virtual-modules.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..12eadb6c715b903259d0e2840a7ee9435d82caf2 GIT binary patch literal 2339 zcmaJ@O>^5e5bfE&V#5n5S0$V2ZVDCpa&_sq8tGx>*Ln&K`eysaIc&VL zW(ppir!%elM-Mxw8oP!x&x_V8?b4Hz(i-RC-@iZpb@}1V+dp6dPbUCrEy{bb#Qe@# zlg`-rhFZNUYIFG^IjE7JDCnd&e}#()wlro z7-T^)MXUWm?5rpJwpCgZ|E!ny%BX5PgGy+JFmP7ucBzb;!PRI#*<=bE)%aHE_o2Ai zt`aeC*t+kK*UU1xVq z`iwk}y;!m{?y8&Dz2m5T(qGAbcXGnhHzVd!Y0-hP9?C|z6+EoaK=e~)38EJo#D)Nx zo%~)I;NIYC-B26Gh6_FIf|Q@2qQ>11?@(Ofwx)!P*QPWiu;g=%C5`_HEY3QuiwB{6 zSkBVg)N4w?BZSy#*WwyI@Fa57wb8tC`BK~4ES1Xn;`FpQ4ZS-F;)ozw@R;P@z7rd~ zK(q9#>}9mzfLFZEeR)k$gYDJN*Rg>Ij2P)pGW=v|SQ4=&gk`rWTn(SWo1ySG*Ni~h zr_=-KDR-AU;x#ZSal*e?(CH+Q&nPtMd0cWEM`oUj6Nf#!tOflLkW+DC zOQC09+-bJ*zRpi4Uy34UEf91l77w{#J?U`5!_~{{u-XmM->lUrOh%amdP8b4m&5;z stfOtDFHR>;h=Hcj?+S;ULfXxWFmz&Gort0*tEjL4{}sJUiatsI0i~D8_W%F@ literal 0 HcmV?d00001 From 545ae0116de39dd0b1ebc4ba76323c2495266563 Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Mon, 24 Feb 2025 17:45:22 +0100 Subject: [PATCH 4/4] Add change log --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eb9e3397a7b..5a5742b7eb40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Vite: Don't crash when importing virtual modules +- Vite: Don't crash when importing a virtual module in JavaScript that ends in `.css` ([#16780](https://github.com/tailwindlabs/tailwindcss/pull/16780)) ## [4.0.8] - 2025-02-21