Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace endsWith with includes to check adapter path #214

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/pigment-css-react/src/utils/preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ export function preprocessor(

return css;
}

export function matchAdapterPath(path: string) {
return path.includes('zero-styled');
}
4 changes: 2 additions & 2 deletions packages/pigment-css-react/tests/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
transform as wywTransform,
createFileReporter,
} from '@wyw-in-js/transform';
import { PluginCustomOptions, preprocessor } from '@pigment-css/react/utils';
import { matchAdapterPath, PluginCustomOptions, preprocessor } from '@pigment-css/react/utils';
import * as prettier from 'prettier';

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

if (source !== '@pigment-css/react' && !source.endsWith('/zero-styled')) {
if (source !== '@pigment-css/react' && !matchAdapterPath(source)) {
return null;
}
return require.resolve(`../${pkgJson['wyw-in-js'].tags[tag]}`.replace('.js', ''));
Expand Down
9 changes: 9 additions & 0 deletions packages/pigment-css-react/tests/utils/adapter-path.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { expect } from 'chai';
import { matchAdapterPath } from '@pigment-css/react/utils';

describe('matchAdapterPath', () => {
it('should match adapter path', () => {
expect(matchAdapterPath('../zero-styled')).to.equal(true);
expect(matchAdapterPath('../zero-styled/index.js')).to.equal(true);
});
});
3 changes: 2 additions & 1 deletion packages/pigment-css-unplugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
generateTokenCss,
generateThemeSource,
extendTheme,
matchAdapterPath,
type Theme as BaseTheme,
type PluginCustomOptions,
} from '@pigment-css/react/utils';
Expand Down Expand Up @@ -256,7 +257,7 @@ export const plugin = createUnplugin<PigmentOptions, true>((options) => {
if (tagResult) {
return tagResult;
}
if (source.endsWith('/zero-styled')) {
if (matchAdapterPath(source)) {
return require.resolve(`${process.env.RUNTIME_PACKAGE_NAME}/exports/${tag}`);
}
return null;
Expand Down
4 changes: 2 additions & 2 deletions packages/pigment-css-vite-plugin/src/vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
type PluginOptions,
type IFileReporterOptions,
} from '@wyw-in-js/transform';
import { type PluginCustomOptions } from '@pigment-css/react/utils';
import { matchAdapterPath, type PluginCustomOptions } from '@pigment-css/react/utils';

export type VitePluginOptions = {
debug?: IFileReporterOptions | false | null | undefined;
Expand Down Expand Up @@ -238,7 +238,7 @@ export default function wywVitePlugin({
if (tagResult) {
return tagResult;
}
if (source.endsWith('/zero-styled')) {
if (matchAdapterPath(source)) {
return `${process.env.RUNTIME_PACKAGE_NAME}/exports/${tag}`;
}
return null;
Expand Down
Loading