@@ -45,7 +45,9 @@ export class ComponentStylesheetBundler {
45
45
constructor (
46
46
private readonly options : BundleStylesheetOptions ,
47
47
private readonly incremental : boolean ,
48
- ) { }
48
+ ) {
49
+ this . options . sourcemap = this . options . sourcemap ? 'linked' : false ;
50
+ }
49
51
50
52
async bundleFile ( entry : string ) {
51
53
const bundlerContext = this . #fileContexts. getOrCreate ( entry , ( ) => {
@@ -57,7 +59,7 @@ export class ComponentStylesheetBundler {
57
59
} ) ;
58
60
} ) ;
59
61
60
- return extractResult ( await bundlerContext . bundle ( ) , bundlerContext . watchFiles ) ;
62
+ return this . extractResult ( await bundlerContext . bundle ( ) , bundlerContext . watchFiles ) ;
61
63
}
62
64
63
65
async bundleInline ( data : string , filename : string , language : string ) {
@@ -103,7 +105,7 @@ export class ComponentStylesheetBundler {
103
105
} ) ;
104
106
105
107
// Extract the result of the bundling from the output files
106
- return extractResult ( await bundlerContext . bundle ( ) , bundlerContext . watchFiles ) ;
108
+ return this . extractResult ( await bundlerContext . bundle ( ) , bundlerContext . watchFiles ) ;
107
109
}
108
110
109
111
invalidate ( files : Iterable < string > ) {
@@ -128,52 +130,51 @@ export class ComponentStylesheetBundler {
128
130
129
131
await Promise . allSettled ( contexts . map ( ( context ) => context . dispose ( ) ) ) ;
130
132
}
131
- }
132
133
133
- function extractResult ( result : BundleContextResult , referencedFiles ?: Set < string > ) {
134
- let contents = '' ;
135
- let map ;
136
- let outputPath ;
137
- const resourceFiles : OutputFile [ ] = [ ] ;
138
- if ( ! result . errors ) {
139
- for ( const outputFile of result . outputFiles ) {
140
- const filename = path . basename ( outputFile . path ) ;
141
- if ( outputFile . type === BuildOutputFileType . Media ) {
142
- // The output files could also contain resources (images/fonts/etc.) that were referenced
143
- resourceFiles . push ( outputFile ) ;
144
- } else if ( filename . endsWith ( '.css' ) ) {
145
- outputPath = outputFile . path ;
146
- contents = outputFile . text ;
147
- } else if ( filename . endsWith ( '.css.map' ) ) {
148
- map = outputFile . text ;
149
- } else {
150
- throw new Error (
151
- `Unexpected non CSS/Media file "${ filename } " outputted during component stylesheet processing.` ,
152
- ) ;
134
+ private extractResult ( result : BundleContextResult , referencedFiles ?: Set < string > ) {
135
+ let contents = '' ;
136
+ const outputFiles : OutputFile [ ] = [ ] ;
137
+ if ( ! result . errors ) {
138
+ for ( const outputFile of result . outputFiles ) {
139
+ const filename = path . basename ( outputFile . path ) ;
140
+
141
+ // Needed for Bazel as otherwise the files will not be written in the correct place.
142
+ outputFile . path = path . join ( this . options . workspaceRoot , outputFile . path ) ;
143
+
144
+ if ( outputFile . type === BuildOutputFileType . Media ) {
145
+ // The output files could also contain resources (images/fonts/etc.) that were referenced
146
+ outputFiles . push ( outputFile ) ;
147
+ } else if ( filename . endsWith ( '.css' ) ) {
148
+ contents = outputFile . text ;
149
+ } else if ( filename . endsWith ( '.css.map' ) ) {
150
+ outputFiles . push ( outputFile ) ;
151
+ } else {
152
+ throw new Error (
153
+ `Unexpected non CSS/Media file "${ filename } " outputted during component stylesheet processing.` ,
154
+ ) ;
155
+ }
153
156
}
154
157
}
155
- }
156
158
157
- let metafile ;
158
- if ( ! result . errors ) {
159
- metafile = result . metafile ;
160
- // Remove entryPoint fields from outputs to prevent the internal component styles from being
161
- // treated as initial files. Also mark the entry as a component resource for stat reporting.
162
- Object . values ( metafile . outputs ) . forEach ( ( output ) => {
163
- delete output . entryPoint ;
164
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
165
- ( output as any ) [ 'ng-component' ] = true ;
166
- } ) ;
167
- }
159
+ let metafile ;
160
+ if ( ! result . errors ) {
161
+ metafile = result . metafile ;
162
+ // Remove entryPoint fields from outputs to prevent the internal component styles from being
163
+ // treated as initial files. Also mark the entry as a component resource for stat reporting.
164
+ Object . values ( metafile . outputs ) . forEach ( ( output ) => {
165
+ delete output . entryPoint ;
166
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
167
+ ( output as any ) [ 'ng-component' ] = true ;
168
+ } ) ;
169
+ }
168
170
169
- return {
170
- errors : result . errors ,
171
- warnings : result . warnings ,
172
- contents,
173
- map,
174
- path : outputPath ,
175
- resourceFiles,
176
- metafile,
177
- referencedFiles,
178
- } ;
171
+ return {
172
+ errors : result . errors ,
173
+ warnings : result . warnings ,
174
+ contents,
175
+ outputFiles,
176
+ metafile,
177
+ referencedFiles,
178
+ } ;
179
+ }
179
180
}
0 commit comments