File tree Expand file tree Collapse file tree 2 files changed +53
-4
lines changed
packages/angular_devkit/build_angular/src/webpack/configs
tests/legacy-cli/e2e/tests/build/styles Expand file tree Collapse file tree 2 files changed +53
-4
lines changed Original file line number Diff line number Diff line change @@ -423,12 +423,30 @@ function getSassResolutionImporter(
423
423
} ) ;
424
424
425
425
return {
426
- findFileUrl : ( url , { fromImport } ) : Promise < URL | null > => {
426
+ findFileUrl : async ( url , { fromImport } ) : Promise < URL | null > => {
427
+ if ( url . charAt ( 0 ) === '.' ) {
428
+ // Let Sass handle relative imports.
429
+ return null ;
430
+ }
431
+
432
+ let file : string | undefined ;
427
433
const resolve = fromImport ? resolveImport : resolveModule ;
428
434
429
- return resolve ( root , url )
430
- . then ( ( file ) => pathToFileURL ( file ) )
431
- . catch ( ( ) => null ) ;
435
+ try {
436
+ file = await resolve ( root , url ) ;
437
+ } catch {
438
+ // Try to resolve a partial file
439
+ // @use '@material/button/button' as mdc-button;
440
+ // `@material/button/button` -> `@material/button/_button`
441
+ const lastSlashIndex = url . lastIndexOf ( '/' ) ;
442
+ const underscoreIndex = lastSlashIndex + 1 ;
443
+ if ( underscoreIndex > 0 && url . charAt ( underscoreIndex ) !== '_' ) {
444
+ const partialFileUrl = `${ url . slice ( 0 , underscoreIndex ) } _${ url . slice ( underscoreIndex ) } ` ;
445
+ file = await resolve ( root , partialFileUrl ) . catch ( ( ) => undefined ) ;
446
+ }
447
+ }
448
+
449
+ return file ? pathToFileURL ( file ) : null ;
432
450
} ,
433
451
} ;
434
452
}
Original file line number Diff line number Diff line change
1
+ import { installPackage } from '../../../utils/packages' ;
2
+ import { writeMultipleFiles , deleteFile , replaceInFile } from '../../../utils/fs' ;
3
+ import { ng } from '../../../utils/process' ;
4
+ import { updateJsonFile } from '../../../utils/project' ;
5
+
6
+ export default async function ( ) {
7
+ // Supports resolving node_modules with are pointing to partial files partial files.
8
+ // @material /button/button below points to @material /button/_button.scss
9
+ // https://unpkg.com/browse/@material /button@14.0.0/_button.scss
10
+
11
+ await installPackage ( '@material/button@14.0.0' ) ;
12
+
13
+ await writeMultipleFiles ( {
14
+ 'src/styles.scss' : `
15
+ @use '@material/button/button' as mat;
16
+ ` ,
17
+ 'src/app/app.component.scss' : `
18
+ @use '@material/button/button' as mat;
19
+ ` ,
20
+ } ) ;
21
+
22
+ await updateJsonFile ( 'angular.json' , ( workspaceJson ) => {
23
+ const appArchitect = workspaceJson . projects [ 'test-project' ] . architect ;
24
+ appArchitect . build . options . styles = [ 'src/styles.scss' ] ;
25
+ } ) ;
26
+
27
+ await deleteFile ( 'src/app/app.component.css' ) ;
28
+ await replaceInFile ( 'src/app/app.component.ts' , './app.component.css' , './app.component.scss' ) ;
29
+
30
+ await ng ( 'build' , '--source-map' , '--configuration=development' ) ;
31
+ }
You can’t perform that action at this time.
0 commit comments