Skip to content

Commit

Permalink
feat: clean ident option
Browse files Browse the repository at this point in the history
  • Loading branch information
mihkeleidast committed Sep 22, 2022
1 parent 58f3ca2 commit 5529a07
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 20 deletions.
8 changes: 8 additions & 0 deletions packages/css/src/identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ export function generateIdentifier(

let identifier = `${fileScopeHash}${refCount}`;

if (getIdentOption() === 'clean') {
const devPrefix = getDevPrefix({ debugId, debugFileName });

if (devPrefix) {
identifier = `${devPrefix}`;
}
}

if (getIdentOption() === 'debug') {
const devPrefix = getDevPrefix({ debugId, debugFileName });

Expand Down
2 changes: 1 addition & 1 deletion packages/css/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export interface Composition {
classList: string;
}

type IdentOption = 'short' | 'debug';
type IdentOption = 'short' | 'debug' | 'clean';
export interface Adapter {
appendCss: (css: CSS, fileScope: FileScope) => void;
registerClassName: (className: string) => void;
Expand Down
4 changes: 2 additions & 2 deletions packages/integration/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const transformSync = ({
}: TransformParams): string => {
let code = source;

if (identOption === 'debug') {
if (identOption === 'debug' || identOption === 'clean') {
const result = babel.transformSync(source, {
filename: filePath,
cwd: rootPath,
Expand Down Expand Up @@ -54,7 +54,7 @@ export const transform = async ({
}: TransformParams): Promise<string> => {
let code = source;

if (identOption === 'debug') {
if (identOption === 'debug' || identOption === 'clean') {
const result = await babel.transform(source, {
filename: filePath,
cwd: rootPath,
Expand Down
1 change: 1 addition & 0 deletions packages/jest-transform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"author": "SEEK",
"license": "MIT",
"dependencies": {
"@vanilla-extract/css": "^1.7.2",
"@vanilla-extract/integration": "^6.0.0",
"esbuild": "^0.11.16"
},
Expand Down
32 changes: 26 additions & 6 deletions packages/jest-transform/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
import type { Transformer } from '@jest/transform';
import { transformSync, getPackageInfo } from '@vanilla-extract/integration';
import { setAdapter } from '@vanilla-extract/css/adapter';
import {
transformSync,
getPackageInfo,
IdentifierOption,
} from '@vanilla-extract/integration';
import * as esbuild from 'esbuild';

const vanillaTransformer: Transformer = {
interface TransformerConfig {
identOption: IdentifierOption;
}

const vanillaTransformer: Transformer<TransformerConfig> = {
canInstrument: false,
process(source, filePath, options) {
const { name: packageName } = getPackageInfo(options.config.rootDir);
const { config, supportsStaticESM, transformerConfig } = options;
const { identOption = 'debug' } = transformerConfig;
const { name: packageName } = getPackageInfo(config.rootDir);

setAdapter({
appendCss: () => {},
registerClassName: () => {},
onEndFileScope: () => {},
registerComposition: () => {},
markCompositionUsed: () => {},
getIdentOption: () => identOption,
});

const code = transformSync({
source,
filePath,
rootPath: options.config.rootDir,
rootPath: config.rootDir,
packageName: packageName,
identOption: 'debug',
identOption: identOption,
});

const result = esbuild.transformSync(code, {
format: options.supportsStaticESM ? 'esm' : 'cjs',
format: supportsStaticESM ? 'esm' : 'cjs',
target: 'es2018',
loader: 'ts',
});
Expand Down
47 changes: 36 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5529a07

Please sign in to comment.