Skip to content

Commit 33de175

Browse files
authored
Replace endsWith with includes to check adapter path (#214)
1 parent fbd8df5 commit 33de175

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

packages/pigment-css-react/src/utils/preprocessor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ export function preprocessor(
6565

6666
return css;
6767
}
68+
69+
export function matchAdapterPath(path: string) {
70+
return path.includes('zero-styled');
71+
}

packages/pigment-css-react/tests/testUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
transform as wywTransform,
99
createFileReporter,
1010
} from '@wyw-in-js/transform';
11-
import { PluginCustomOptions, preprocessor } from '@pigment-css/react/utils';
11+
import { matchAdapterPath, PluginCustomOptions, preprocessor } from '@pigment-css/react/utils';
1212
import * as prettier from 'prettier';
1313

1414
import sxTransformPlugin from '../exports/sx-plugin';
@@ -70,7 +70,7 @@ export async function runTransformation(absolutePath: string, options?: Transfor
7070
return require.resolve(`../exports/styled`);
7171
}
7272

73-
if (source !== '@pigment-css/react' && !source.endsWith('/zero-styled')) {
73+
if (source !== '@pigment-css/react' && !matchAdapterPath(source)) {
7474
return null;
7575
}
7676
return require.resolve(`../${pkgJson['wyw-in-js'].tags[tag]}`.replace('.js', ''));
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { expect } from 'chai';
2+
import { matchAdapterPath } from '@pigment-css/react/utils';
3+
4+
describe('matchAdapterPath', () => {
5+
it('should match adapter path', () => {
6+
expect(matchAdapterPath('../zero-styled')).to.equal(true);
7+
expect(matchAdapterPath('../zero-styled/index.js')).to.equal(true);
8+
});
9+
});

packages/pigment-css-unplugin/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
generateTokenCss,
2121
generateThemeSource,
2222
extendTheme,
23+
matchAdapterPath,
2324
type Theme as BaseTheme,
2425
type PluginCustomOptions,
2526
} from '@pigment-css/react/utils';
@@ -256,7 +257,7 @@ export const plugin = createUnplugin<PigmentOptions, true>((options) => {
256257
if (tagResult) {
257258
return tagResult;
258259
}
259-
if (source.endsWith('/zero-styled')) {
260+
if (matchAdapterPath(source)) {
260261
return require.resolve(`${process.env.RUNTIME_PACKAGE_NAME}/exports/${tag}`);
261262
}
262263
return null;

packages/pigment-css-vite-plugin/src/vite-plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
type PluginOptions,
2121
type IFileReporterOptions,
2222
} from '@wyw-in-js/transform';
23-
import { type PluginCustomOptions } from '@pigment-css/react/utils';
23+
import { matchAdapterPath, type PluginCustomOptions } from '@pigment-css/react/utils';
2424

2525
export type VitePluginOptions = {
2626
debug?: IFileReporterOptions | false | null | undefined;
@@ -238,7 +238,7 @@ export default function wywVitePlugin({
238238
if (tagResult) {
239239
return tagResult;
240240
}
241-
if (source.endsWith('/zero-styled')) {
241+
if (matchAdapterPath(source)) {
242242
return `${process.env.RUNTIME_PACKAGE_NAME}/exports/${tag}`;
243243
}
244244
return null;

0 commit comments

Comments
 (0)