Skip to content

Commit f68bea6

Browse files
committed
fix: support windows
1 parent 8e7ea8e commit f68bea6

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

.changeset/small-clouds-speak.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'phosphor-icons-tailwindcss': patch
3+
---
4+
5+
switch to `path/posix` implementation to support Windows

src/plugin.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFileSync, existsSync } from 'fs';
1+
import fs from 'fs';
22

33
import { icons } from '@phosphor-icons/core';
44
import { resolve } from 'import-meta-resolve';
@@ -51,16 +51,15 @@ export default createPlugin.withOptions(
5151

5252
let url = 'icon-not-found';
5353
if (ICON_SET.has(name) && VARIANTS.includes(weight)) {
54-
const fileUrl = new URL(
54+
let fileUrl = new URL(
5555
resolve(
5656
`@phosphor-icons/core/assets/${weight}/${name}${weight === 'regular' ? '' : `-${weight}`}.svg`,
5757
import.meta.url,
5858
),
5959
);
60-
const path = fileUrl.pathname;
6160

62-
if (existsSync(path)) {
63-
const svgStr = readFileSync(path, { encoding: 'base64' });
61+
if (fs.existsSync(fileUrl)) {
62+
const svgStr = fs.readFileSync(fileUrl, { encoding: 'base64' });
6463
url = `url(data:image/svg+xml;base64,${svgStr})`;
6564
}
6665
}

tests/plugin.test.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function tests(run: Run, version: number) {
1919
test('default', async function ({ expect }) {
2020
const result = await run([...COMMON_CANDIDATES, 'ph', 'ph-[info]']);
2121
await expect(result).toMatchFileSnapshot(
22-
path.resolve(__dirname, '__snapshots__', `v${version}/default.css`),
22+
path.resolve(import.meta.dirname, '__snapshots__', `v${version}/default.css`),
2323
);
2424
});
2525

@@ -28,7 +28,7 @@ function tests(run: Run, version: number) {
2828
prefix: 'i',
2929
});
3030
await expect(result).toMatchFileSnapshot(
31-
path.resolve(__dirname, '__snapshots__', `v${version}/custom-prefix.css`),
31+
path.resolve(import.meta.dirname, '__snapshots__', `v${version}/custom-prefix.css`),
3232
);
3333
});
3434

@@ -37,7 +37,7 @@ function tests(run: Run, version: number) {
3737
layer: null,
3838
});
3939
await expect(result).toMatchFileSnapshot(
40-
path.resolve(__dirname, '__snapshots__', `v${version}/no-layer.css`),
40+
path.resolve(import.meta.dirname, '__snapshots__', `v${version}/no-layer.css`),
4141
);
4242
});
4343

@@ -46,7 +46,7 @@ function tests(run: Run, version: number) {
4646
layer: 'custom',
4747
});
4848
await expect(result).toMatchFileSnapshot(
49-
path.resolve(__dirname, '__snapshots__', `v${version}/custom-layer.css`),
49+
path.resolve(import.meta.dirname, '__snapshots__', `v${version}/custom-layer.css`),
5050
);
5151
});
5252

@@ -55,7 +55,7 @@ function tests(run: Run, version: number) {
5555
'custom-property': '--icon-url',
5656
});
5757
await expect(result).toMatchFileSnapshot(
58-
path.resolve(__dirname, '__snapshots__', `v${version}/custom-property.css`),
58+
path.resolve(import.meta.dirname, '__snapshots__', `v${version}/custom-property.css`),
5959
);
6060
});
6161

@@ -64,21 +64,21 @@ function tests(run: Run, version: number) {
6464
customProperty: '--icon-url',
6565
});
6666
await expect(result).toMatchFileSnapshot(
67-
path.resolve(__dirname, '__snapshots__', `v${version}/custom-property.css`),
67+
path.resolve(import.meta.dirname, '__snapshots__', `v${version}/custom-property.css`),
6868
);
6969
});
7070

7171
test('no icon found', async function () {
7272
const result = await run([...COMMON_CANDIDATES, 'ph', 'ph-[404]']);
7373
await expect(result).toMatchFileSnapshot(
74-
path.resolve(__dirname, '__snapshots__', `v${version}/no-icon-found.css`),
74+
path.resolve(import.meta.dirname, '__snapshots__', `v${version}/no-icon-found.css`),
7575
);
7676
});
7777

7878
test('no icon name', async function () {
7979
const result = await run([...COMMON_CANDIDATES, 'ph', 'ph-[]']);
8080
await expect(result).toMatchFileSnapshot(
81-
path.resolve(__dirname, '__snapshots__', `v${version}/no-icon-name.css`),
81+
path.resolve(import.meta.dirname, '__snapshots__', `v${version}/no-icon-name.css`),
8282
);
8383
});
8484

@@ -87,7 +87,7 @@ function tests(run: Run, version: number) {
8787
test(`weight:${weight}`, async function () {
8888
const result = await run([...COMMON_CANDIDATES, 'ph', `ph-[info--${weight}]`]);
8989
await expect(result).toMatchFileSnapshot(
90-
path.resolve(__dirname, `__snapshots__`, `v${version}/weight-${weight}.css`),
90+
path.resolve(import.meta.dirname, `__snapshots__`, `v${version}/weight-${weight}.css`),
9191
);
9292
});
9393
}
@@ -107,8 +107,6 @@ describe('v4', function () {
107107
@tailwind utilities;
108108
}
109109
`;
110-
const { currentTestName } = expect.getState();
111-
112110
let cssPlugin = css`
113111
@plugin 'phosphor-icons-tailwindcss';
114112
`;
@@ -123,9 +121,8 @@ describe('v4', function () {
123121
};
124122
`;
125123
}
126-
127124
const { build } = await compile(cssEntry + cssPlugin, {
128-
base: `${path.resolve(__filename)}?test=${currentTestName}`,
125+
base: `${path.resolve(import.meta.url, '..')}`,
129126
onDependency: () => {},
130127
shouldRewriteUrls: true,
131128
...({
@@ -156,7 +153,7 @@ describe('v3', async function () {
156153
} satisfies import('tailwindcssv3').Config;
157154

158155
const { css } = await postcss(tailwindcss(config)).process(cssEntry, {
159-
from: `${path.resolve(__filename)}?test=${currentTestName}`,
156+
from: `${path.resolve(import.meta.url)}?test=${currentTestName}`,
160157
});
161158
return css;
162159
};

0 commit comments

Comments
 (0)