diff --git a/.changeset/stupid-planes-raise.md b/.changeset/stupid-planes-raise.md new file mode 100644 index 000000000..d48757eb2 --- /dev/null +++ b/.changeset/stupid-planes-raise.md @@ -0,0 +1,6 @@ +--- +'@vanilla-extract/integration': minor +'@vanilla-extract-private/tests': minor +--- + +Added debugId to custom identifiers diff --git a/packages/integration/src/transform.ts b/packages/integration/src/transform.ts index 2caf9dc27..f31c3b7c5 100644 --- a/packages/integration/src/transform.ts +++ b/packages/integration/src/transform.ts @@ -23,7 +23,7 @@ export const transformSync = ({ }: TransformParams): string => { let code = source; - if (identOption === 'debug') { + if (identOption !== 'short') { const result = babel.transformSync(source, { filename: filePath, cwd: rootPath, @@ -57,7 +57,7 @@ export const transform = async ({ }: TransformParams): Promise => { let code = source; - if (identOption === 'debug') { + if (identOption !== 'short') { const result = await babel.transformAsync(source, { filename: filePath, cwd: rootPath, diff --git a/tests/compiler/compiler.vitest.test.ts b/tests/compiler/compiler.vitest.test.ts index c614f9959..474452bfa 100644 --- a/tests/compiler/compiler.vitest.test.ts +++ b/tests/compiler/compiler.vitest.test.ts @@ -17,7 +17,7 @@ function getLocalFiles(files: Set) { describe('compiler', () => { let compilers: Record< - 'default' | 'cssImportSpecifier' | 'shortIdentifiers', + 'default' | 'cssImportSpecifier' | 'shortIdentifiers' | 'debugIdentifiers' | 'customIdentifiers', ReturnType >; @@ -36,6 +36,16 @@ describe('compiler', () => { root: __dirname, identifiers: 'short', }), + + debugIdentifiers: createCompiler({ + root: __dirname, + identifiers: 'debug', + }), + + customIdentifiers: createCompiler({ + root: __dirname, + identifiers: ({ debugId, hash }) => `${debugId}__${hash}`, + }), }; }); @@ -220,6 +230,48 @@ describe('compiler', () => { `); }); + test('debug identifiers', async () => { + const compiler = compilers.debugIdentifiers; + + const cssPath = path.join( + __dirname, + 'fixtures/class-composition/styles.css.ts', + ); + const output = await compiler.processVanillaFile(cssPath); + expect(output.source).toMatchInlineSnapshot(` + "import 'fixtures/class-composition/shared.css.ts.vanilla.css'; + import 'fixtures/class-composition/styles.css.ts.vanilla.css'; + export var className = 'styles_className__q7x3ow0 shared_shared__16bmd920';" + `); + const { css } = await compiler.getCssForFile(cssPath); + expect(css).toMatchInlineSnapshot(` + ".styles_className__q7x3ow0 { + color: red; + }" + `); + }); + + test('custom identifiers', async () => { + const compiler = compilers.customIdentifiers; + + const cssPath = path.join( + __dirname, + 'fixtures/class-composition/styles.css.ts', + ); + const output = await compiler.processVanillaFile(cssPath); + expect(output.source).toMatchInlineSnapshot(` + "import 'fixtures/class-composition/shared.css.ts.vanilla.css'; + import 'fixtures/class-composition/styles.css.ts.vanilla.css'; + export var className = 'className__q7x3ow0 shared__16bmd920';" + `); + const { css } = await compiler.getCssForFile(cssPath); + expect(css).toMatchInlineSnapshot(` + ".className__q7x3ow0 { + color: red; + }" + `); + }); + test('custom cssImportSpecifier', async () => { const compiler = compilers.cssImportSpecifier;