@@ -12,7 +12,7 @@ import { readFileSync, readdirSync } from 'node:fs';
12
12
import { basename , dirname , extname , join , relative } from 'node:path' ;
13
13
import { fileURLToPath , pathToFileURL } from 'node:url' ;
14
14
import type { CanonicalizeContext , Importer , ImporterResult , Syntax } from 'sass' ;
15
- import { findImports , findUrls } from './lexer' ;
15
+ import { findUrls } from './lexer' ;
16
16
17
17
/**
18
18
* A preprocessed cache entry for the files and directories within a previously searched
@@ -23,45 +23,6 @@ export interface DirectoryEntry {
23
23
directories : Set < string > ;
24
24
}
25
25
26
- /**
27
- * A prefix that is added to import and use directive specifiers that should be resolved
28
- * as modules and that will contain added resolve directory information.
29
- *
30
- * This functionality is used to workaround the Sass limitation that it does not provide the
31
- * importer file to custom resolution plugins.
32
- */
33
- const MODULE_RESOLUTION_PREFIX = '__NG_PACKAGE__' ;
34
-
35
- function packModuleSpecifier ( specifier : string , resolveDir : string ) : string {
36
- const packed =
37
- MODULE_RESOLUTION_PREFIX +
38
- ';' +
39
- // Encode the resolve directory to prevent unsupported characters from being present when
40
- // Sass processes the URL. This is important on Windows which can contain drive letters
41
- // and colons which would otherwise be interpreted as a URL scheme.
42
- encodeURIComponent ( resolveDir ) +
43
- ';' +
44
- // Escape characters instead of encoding to provide more friendly not found error messages.
45
- // Unescaping is automatically handled by Sass.
46
- // https://developer.mozilla.org/en-US/docs/Web/CSS/url#syntax
47
- specifier . replace ( / [ ( ) \s ' " ] / g, '\\$&' ) ;
48
-
49
- return packed ;
50
- }
51
-
52
- function unpackModuleSpecifier ( specifier : string ) : { specifier : string ; resolveDir ?: string } {
53
- if ( ! specifier . startsWith ( `${ MODULE_RESOLUTION_PREFIX } ;` ) ) {
54
- return { specifier } ;
55
- }
56
-
57
- const values = specifier . split ( ';' , 3 ) ;
58
-
59
- return {
60
- specifier : values [ 2 ] ,
61
- resolveDir : decodeURIComponent ( values [ 1 ] ) ,
62
- } ;
63
- }
64
-
65
26
/**
66
27
* A Sass Importer base class that provides the load logic to rebase all `url()` functions
67
28
* within a stylesheet. The rebasing will ensure that the URLs in the output of the Sass compiler
@@ -114,27 +75,6 @@ abstract class UrlRebasingImporter implements Importer<'sync'> {
114
75
updatedContents . update ( start , end , rebasedUrl ) ;
115
76
}
116
77
117
- // Add resolution directory information to module specifiers to facilitate resolution
118
- for ( const { start, end, specifier } of findImports ( contents ) ) {
119
- // Currently only provide directory information for known/common packages:
120
- // * `@material/`
121
- // * `@angular/`
122
- //
123
- // Comprehensive pre-resolution support may be added in the future. This is complicated by CSS/Sass not
124
- // requiring a `./` or `../` prefix to signify relative paths. A bare specifier could be either relative
125
- // or a module specifier. To differentiate, a relative resolution would need to be attempted first.
126
- if ( ! specifier . startsWith ( '@angular/' ) && ! specifier . startsWith ( '@material/' ) ) {
127
- continue ;
128
- }
129
-
130
- updatedContents ??= new MagicString ( contents ) ;
131
- updatedContents . update (
132
- start ,
133
- end ,
134
- `"${ packModuleSpecifier ( specifier , stylesheetDirectory ) } "` ,
135
- ) ;
136
- }
137
-
138
78
if ( updatedContents ) {
139
79
contents = updatedContents . toString ( ) ;
140
80
if ( this . rebaseSourceMaps ) {
@@ -348,10 +288,7 @@ export class ModuleUrlRebasingImporter extends RelativeUrlRebasingImporter {
348
288
entryDirectory : string ,
349
289
directoryCache : Map < string , DirectoryEntry > ,
350
290
rebaseSourceMaps : Map < string , RawSourceMap > | undefined ,
351
- private finder : (
352
- specifier : string ,
353
- options : CanonicalizeContext & { resolveDir ?: string } ,
354
- ) => URL | null ,
291
+ private finder : ( specifier : string , options : CanonicalizeContext ) => URL | null ,
355
292
) {
356
293
super ( entryDirectory , directoryCache , rebaseSourceMaps ) ;
357
294
}
@@ -361,9 +298,7 @@ export class ModuleUrlRebasingImporter extends RelativeUrlRebasingImporter {
361
298
return super . canonicalize ( url , options ) ;
362
299
}
363
300
364
- const { specifier, resolveDir } = unpackModuleSpecifier ( url ) ;
365
-
366
- let result = this . finder ( specifier , { ...options , resolveDir } ) ;
301
+ let result = this . finder ( url , options ) ;
367
302
result &&= super . canonicalize ( result . href , options ) ;
368
303
369
304
return result ;
0 commit comments