From e19c978b60762e7acce2cd1b94ca8a5f8d64a40d Mon Sep 17 00:00:00 2001 From: Urban Faubion Date: Mon, 13 Nov 2023 10:48:01 -0800 Subject: [PATCH 1/3] updated compiler vitests --- tests/compiler/compiler.vitest.test.ts | 54 +++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) 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; From 3f4f06c8a40b3b54c9d99cb6c28e1a765d395783 Mon Sep 17 00:00:00 2001 From: Urban Faubion Date: Mon, 13 Nov 2023 14:15:05 -0800 Subject: [PATCH 2/3] Added debugId to custom identifiers --- packages/integration/src/transform.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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, From 3d04b52801ea6174ef924bbea94cf6121f703227 Mon Sep 17 00:00:00 2001 From: Urban Faubion Date: Mon, 13 Nov 2023 15:42:01 -0800 Subject: [PATCH 3/3] added changeset --- .changeset/stupid-planes-raise.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/stupid-planes-raise.md 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