diff --git a/src/__tests__/codegen.test.ts b/src/__tests__/codegen.test.ts index fb18a5c..9f3544e 100644 --- a/src/__tests__/codegen.test.ts +++ b/src/__tests__/codegen.test.ts @@ -85,7 +85,7 @@ describe('codegen', () => { ], changed: [], }, - { ...context, config: { outExtension: 'js' } }, + context, ) as any[]; expect(result.at(0).files[0].file).toEqual('ct.js'); @@ -112,7 +112,7 @@ describe('codegen', () => { ], changed: [], }, - { ...context, config: { forceConsistentTypeExtension: true } }, + context, ) as any[]; expect(result.at(0).files[0].file).toEqual('ct.mjs'); @@ -121,36 +121,6 @@ describe('codegen', () => { expect(result.at(1).files[1].code).includes('./ct'); }); - it('generates ct runtime code with outExtension set to "js" and force type extension', () => { - const result = codegen( - { - artifacts: [ - { - id: 'css-fn', - files: [], - }, - { - id: 'css-index', - files: [ - { file: 'index.js', code: '' }, - { file: 'index.d.ts', code: '' }, - ], - }, - ], - changed: [], - }, - { - ...context, - config: { outExtension: 'js', forceConsistentTypeExtension: true }, - }, - ) as any[]; - - expect(result.at(0).files[0].file).toEqual('ct.js'); - expect(result.at(0).files[1].file).toEqual('ct.d.ts'); - expect(result.at(1).files[0].code).includes('./ct.js'); - expect(result.at(1).files[1].code).includes('./ct'); - }); - it('skips if artifacts dont exist', () => { const result = codegen( { diff --git a/src/codegen.ts b/src/codegen.ts index f880cf5..db87cb3 100644 --- a/src/codegen.ts +++ b/src/codegen.ts @@ -12,18 +12,21 @@ export const codegen = ( args: CodegenPrepareHookArgs, context: PluginContext, ): MaybeAsyncReturn => { - const { config, map } = context; - - // @see https://panda-css.com/docs/references/config#forceconsistenttypeextension - const ext = config?.outExtension ?? 'mjs'; - const dtsExt = !config?.forceConsistentTypeExtension - ? 'ts' - : ext === 'js' - ? 'ts' - : 'mts'; + const { map } = context; + let ext = 'mjs'; + let dtsExt = 'ts'; const cssFn = args.artifacts.find((a) => a.id === 'css-fn'); const index = args.artifacts.find((a) => a.id === 'css-index'); + + for (const artifact of index?.files || []) { + if (artifact.file.includes('.d.')) { + dtsExt = artifact.file.split('.').at(-1) || dtsExt; + } else { + ext = artifact.file.split('.').at(-1) || ext; + } + } + const indexFile = index?.files.find((f) => f.file.includes(`index.${ext}`)); const indexDtsFile = index?.files.find((f) => f.file.includes('index.d.')); diff --git a/src/index.ts b/src/index.ts index de60f6d..91c7afa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,6 @@ const pluginComponentTokens = (tokens: ComponentTokens): PandaPlugin => { hooks: { 'context:created': (args) => { context.debug = args.logger?.debug; - context.config = args.ctx.config; }, 'parser:before': (args) => { return parser(args, context); diff --git a/src/types.ts b/src/types.ts index c62fa62..e57053f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -import { Config, LoggerInterface, LogLevel } from '@pandacss/types'; +import type { LoggerInterface } from '@pandacss/types'; import { type Project } from 'ts-morph'; export type ComponentTokens = { [k: string]: string | ComponentTokens }; @@ -8,5 +8,4 @@ export type PluginContext = { tokens: ComponentTokens; map: Map; debug?: LoggerInterface['debug']; - config?: Config; };