Skip to content

Commit

Permalink
fix(transform): fix types (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonambas authored Apr 9, 2024
1 parent 98ee26a commit b9bf0e2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ const nextConfig = {
config.plugins.push(
unplugin.webpack({
transform: transform(tokens),
optimizeJs: true, // Optional, this will replace other Panda runtime functions (css, cva, etc)
}),
);
return config;
Expand Down
4 changes: 0 additions & 4 deletions src/__tests__/transformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ describe('transform', () => {
it('replaces ct', () => {
expect(
transform(tokens)({
configure: () => {},
filePath: 'test.tsx',
content: `
import { css, ct, cva } from '@/styled-system/css';
Expand Down Expand Up @@ -56,23 +55,20 @@ describe('transform', () => {
it('skips without imports, expressions, content', () => {
expect(
transform(tokens)({
configure: () => {},
filePath: 'test.tsx',
content: `<div className={css({ bg: ct("foo.200") })/>`,
}),
).toBeUndefined();

expect(
transform(tokens)({
configure: () => {},
filePath: 'test.tsx',
content: `import { ct } from '@/styled-system/css`,
}),
).toBeUndefined();

expect(
transform(tokens)({
configure: () => {},
filePath: 'test.tsx',
content: ``,
}),
Expand Down
9 changes: 7 additions & 2 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { createContext } from './context';
import type { ComponentTokens } from './types';
import { parser } from './parser';

// TODO: This is what unplugin expects, but avoiding installing @pandacss/node bc of a type conflict
// Omit<ParserResultBeforeHookArgs, 'configure'> & Pick<SourceFileHookArgs, 'context'>

type TransformArgs = Omit<ParserResultBeforeHookArgs, 'configure'>;

/**
* Transformer for @pandabox/unplugin.
* Replaces JS runtime calls to `ct` with their resulting class names.
Expand All @@ -12,10 +17,10 @@ import { parser } from './parser';
*/
export const transform = (tokens: ComponentTokens) => {
const context = createContext(tokens);
return (args: ParserResultBeforeHookArgs) => {
return (args: TransformArgs) => {
// This doesn't have `args.configure`

if (!args.content) return;
return parser(args, context);
return parser(args as ParserResultBeforeHookArgs, context);
};
};

0 comments on commit b9bf0e2

Please sign in to comment.