@@ -3,23 +3,46 @@ import hash from '@emotion/hash';
33import { getIdentOption } from './adapter' ;
44import { getAndIncrementRefCounter , getFileScope } from './fileScope' ;
55
6- function getDevPrefix ( debugId : string | undefined ) {
6+ function getDevPrefix ( {
7+ debugId,
8+ debugFileName,
9+ } : {
10+ debugId ?: string ;
11+ debugFileName : boolean ;
12+ } ) {
713 const parts = debugId ? [ debugId . replace ( / \s / g, '_' ) ] : [ ] ;
8- const { filePath } = getFileScope ( ) ;
914
10- const matches = filePath . match (
11- / (?< dir > [ ^ \/ \\ ] * ) ? [ \/ \\ ] ? (?< file > [ ^ \/ \\ ] * ) \. c s s \. ( t s | j s | t s x | j s x ) $ / ,
12- ) ;
15+ if ( debugFileName ) {
16+ const { filePath } = getFileScope ( ) ;
17+
18+ const matches = filePath . match (
19+ / (?< dir > [ ^ \/ \\ ] * ) ? [ \/ \\ ] ? (?< file > [ ^ \/ \\ ] * ) \. c s s \. ( t s | j s | t s x | j s x | c j s | m j s ) $ / ,
20+ ) ;
1321
14- if ( matches && matches . groups ) {
15- const { dir, file } = matches . groups ;
16- parts . unshift ( file && file !== 'index' ? file : dir ) ;
22+ if ( matches && matches . groups ) {
23+ const { dir, file } = matches . groups ;
24+ parts . unshift ( file && file !== 'index' ? file : dir ) ;
25+ }
1726 }
1827
1928 return parts . join ( '_' ) ;
2029}
2130
22- export function generateIdentifier ( debugId : string | undefined ) {
31+ interface GenerateIdentifierOptions {
32+ debugId ?: string ;
33+ debugFileName ?: boolean ;
34+ }
35+
36+ export function generateIdentifier ( debugId ?: string ) : string ;
37+ export function generateIdentifier ( options ?: GenerateIdentifierOptions ) : string ;
38+ export function generateIdentifier (
39+ arg ?: string | GenerateIdentifierOptions ,
40+ ) : string {
41+ const { debugId, debugFileName = true } = {
42+ ...( typeof arg === 'string' ? { debugId : arg } : null ) ,
43+ ...( typeof arg === 'object' ? arg : null ) ,
44+ } ;
45+
2346 // Convert ref count to base 36 for optimal hash lengths
2447 const refCount = getAndIncrementRefCounter ( ) . toString ( 36 ) ;
2548 const { filePath, packageName } = getFileScope ( ) ;
@@ -31,7 +54,7 @@ export function generateIdentifier(debugId: string | undefined) {
3154 let identifier = `${ fileScopeHash } ${ refCount } ` ;
3255
3356 if ( getIdentOption ( ) === 'debug' ) {
34- const devPrefix = getDevPrefix ( debugId ) ;
57+ const devPrefix = getDevPrefix ( { debugId, debugFileName } ) ;
3558
3659 if ( devPrefix ) {
3760 identifier = `${ devPrefix } __${ identifier } ` ;
0 commit comments