@@ -3,23 +3,46 @@ import hash from '@emotion/hash';
3
3
import { getIdentOption } from './adapter' ;
4
4
import { getAndIncrementRefCounter , getFileScope } from './fileScope' ;
5
5
6
- function getDevPrefix ( debugId : string | undefined ) {
6
+ function getDevPrefix ( {
7
+ debugId,
8
+ debugFileName,
9
+ } : {
10
+ debugId ?: string ;
11
+ debugFileName : boolean ;
12
+ } ) {
7
13
const parts = debugId ? [ debugId . replace ( / \s / g, '_' ) ] : [ ] ;
8
- const { filePath } = getFileScope ( ) ;
9
14
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
+ ) ;
13
21
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
+ }
17
26
}
18
27
19
28
return parts . join ( '_' ) ;
20
29
}
21
30
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
+
23
46
// Convert ref count to base 36 for optimal hash lengths
24
47
const refCount = getAndIncrementRefCounter ( ) . toString ( 36 ) ;
25
48
const { filePath, packageName } = getFileScope ( ) ;
@@ -31,7 +54,7 @@ export function generateIdentifier(debugId: string | undefined) {
31
54
let identifier = `${ fileScopeHash } ${ refCount } ` ;
32
55
33
56
if ( getIdentOption ( ) === 'debug' ) {
34
- const devPrefix = getDevPrefix ( debugId ) ;
57
+ const devPrefix = getDevPrefix ( { debugId, debugFileName } ) ;
35
58
36
59
if ( devPrefix ) {
37
60
identifier = `${ devPrefix } __${ identifier } ` ;
0 commit comments