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

Debug id for custom identifiers #1229

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .changeset/stupid-planes-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@vanilla-extract/integration': minor
'@vanilla-extract-private/tests': minor
---

Added debugId to custom identifiers
4 changes: 2 additions & 2 deletions packages/integration/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -57,7 +57,7 @@ export const transform = async ({
}: TransformParams): Promise<string> => {
let code = source;

if (identOption === 'debug') {
if (identOption !== 'short') {
const result = await babel.transformAsync(source, {
filename: filePath,
cwd: rootPath,
Expand Down
54 changes: 53 additions & 1 deletion tests/compiler/compiler.vitest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function getLocalFiles(files: Set<string>) {

describe('compiler', () => {
let compilers: Record<
'default' | 'cssImportSpecifier' | 'shortIdentifiers',
'default' | 'cssImportSpecifier' | 'shortIdentifiers' | 'debugIdentifiers' | 'customIdentifiers',
ReturnType<typeof createCompiler>
>;

Expand All @@ -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}`,
}),
};
});

Expand Down Expand Up @@ -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;

Expand Down