Skip to content

Commit a50de75

Browse files
authored
Improved Windows support (#133)
1 parent ed76e45 commit a50de75

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

.changeset/funny-candles-sin.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@vanilla-extract/babel-plugin': patch
3+
'@vanilla-extract/integration': patch
4+
---
5+
6+
Improve Windows support
7+
8+
Normalize all file paths to POSIX format. This fixes incorrect file paths on Windows and ensures consistent hashes across all operating systems.

packages/babel-plugin/src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { relative } from 'path';
1+
import { relative, posix, sep } from 'path';
22
import { types as t, PluginObj, PluginPass, NodePath } from '@babel/core';
33
import template from '@babel/template';
44
import { getPackageInfo } from '@vanilla-extract/integration';
@@ -158,7 +158,10 @@ export default function (): PluginObj<Context> {
158158
);
159159
}
160160
this.packageName = packageInfo.name;
161-
this.filePath = relative(packageInfo.dirname, opts.filename);
161+
// Encode windows file paths as posix
162+
this.filePath = posix.join(
163+
...relative(packageInfo.dirname, opts.filename).split(sep),
164+
);
162165
},
163166
visitor: {
164167
Program: {

packages/integration/src/compile.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dirname, relative, join } from 'path';
1+
import { dirname, relative, join, posix, sep } from 'path';
22
import { promises as fs } from 'fs';
33

44
import { build as esbuild, Plugin } from 'esbuild';
@@ -15,7 +15,10 @@ export const vanillaExtractFilescopePlugin = (): Plugin => ({
1515
const originalSource = await fs.readFile(path, 'utf-8');
1616

1717
if (originalSource.indexOf('@vanilla-extract/css/fileScope') === -1) {
18-
const filePath = relative(packageInfo.dirname, path);
18+
// Encode windows file paths as posix
19+
const filePath = posix.join(
20+
...relative(packageInfo.dirname, path).split(sep),
21+
);
1922

2023
const contents = `
2124
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";

packages/integration/src/processVanillaFile.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import path from 'path';
2-
31
import { FileScope, Adapter } from '@vanilla-extract/css';
42
import { setAdapter } from '@vanilla-extract/css/adapter';
53
import { transformCss } from '@vanilla-extract/css/transformCss';
@@ -91,13 +89,11 @@ export function processVanillaFile({
9189
}).join('\n');
9290

9391
const base64Source = Buffer.from(css, 'utf-8').toString('base64');
94-
const fileName = path.normalize(
95-
`${
96-
filescope.packageName
97-
? `${filescope.packageName}/${filescope.filePath}`
98-
: filescope.filePath
99-
}.vanilla.css`,
100-
);
92+
const fileName = `${
93+
filescope.packageName
94+
? `${filescope.packageName}/${filescope.filePath}`
95+
: filescope.filePath
96+
}.vanilla.css`;
10197

10298
const virtualCssFilePath = serializeVirtualCssPath
10399
? serializeVirtualCssPath({ fileName, base64Source })

0 commit comments

Comments
 (0)