@@ -220,15 +220,13 @@ function findSecondaryEntryPoints(
220220 * @param projectDir The directory containing the primary `ng-packagr` configuration file.
221221 * @param buildTarget The library's `build` target definition in `angular.json`.
222222 * @param ngPackageConfig The parsed `NgPackageConfig`, if available.
223- * @param secondaryEntryPoints The discovered secondary entry points of the library.
224223 * @param tree The virtual file system tree.
225224 */
226225function migrateTargetOptions (
227226 projectRoot : string ,
228227 projectDir : string ,
229228 buildTarget : TargetDefinition ,
230229 ngPackageConfig : NgPackageConfig | undefined ,
231- secondaryEntryPoints : SecondaryEntryPoint [ ] ,
232230 tree : Tree ,
233231) : void {
234232 buildTarget . builder = Builders . BuildLibrary ;
@@ -286,40 +284,31 @@ function migrateTargetOptions(
286284 buildTarget . options [ 'assets' ] = [ ...existingAssets , ...migratedAssets ] ;
287285 }
288286
289- // The library builder applies style options to all entry points, so the options of
290- // secondary entry points are merged with the primary ones.
291- const styleConfigs = [
292- { dir : projectDir , lib : ngPackageConfig ?. lib } ,
293- ...secondaryEntryPoints . map ( ( { configFile, config } ) => ( {
294- dir : dirname ( configFile ) ,
295- lib : config ?. lib ,
296- } ) ) ,
297- ] ;
298- const migratedIncludePaths = styleConfigs . flatMap ( ( { dir, lib } ) =>
299- ( lib ?. styleIncludePaths ?? [ ] ) . map ( ( p ) => join ( dir , p ) ) ,
300- ) ;
301- const migratedSassOptions = styleConfigs . flatMap ( ( { lib } ) => ( lib ?. sass ? [ lib . sass ] : [ ] ) ) ;
302-
303- if ( migratedIncludePaths . length || migratedSassOptions . length ) {
287+ if ( ngPackageConfig ?. lib ?. styleIncludePaths ?. length || ngPackageConfig ?. lib ?. sass ) {
304288 const stylePreprocessorOptions = buildTarget . options [ 'stylePreprocessorOptions' ] ;
305289 const existingPreprocessorOptions : JsonObject =
306290 stylePreprocessorOptions && isJsonObject ( stylePreprocessorOptions )
307291 ? { ...stylePreprocessorOptions }
308292 : { } ;
309293
310- if ( migratedIncludePaths . length ) {
294+ if ( ngPackageConfig . lib . styleIncludePaths ? .length ) {
311295 const existingIncludePaths = Array . isArray ( existingPreprocessorOptions [ 'includePaths' ] )
312296 ? ( existingPreprocessorOptions [ 'includePaths' ] as string [ ] )
313297 : [ ] ;
298+ const migratedIncludePaths = ngPackageConfig . lib . styleIncludePaths . map ( ( p ) =>
299+ join ( projectDir , p ) ,
300+ ) ;
314301 existingPreprocessorOptions [ 'includePaths' ] = [
315302 ...new Set ( [ ...existingIncludePaths , ...migratedIncludePaths ] ) ,
316303 ] ;
317304 }
318- if ( migratedSassOptions . length ) {
319- const sass : Record < string , string [ ] > = { } ;
320- for ( const options of migratedSassOptions ) {
321- for ( const [ key , value ] of Object . entries ( options ) ) {
322- sass [ key ] = [ ...new Set ( [ ...( sass [ key ] ?? [ ] ) , ...( value ?? [ ] ) ] ) ] ;
305+ if ( ngPackageConfig . lib . sass ) {
306+ const existingSass = existingPreprocessorOptions [ 'sass' ] ;
307+ const sass : JsonObject = isJsonObject ( existingSass ) ? { ...existingSass } : { } ;
308+ for ( const [ key , value ] of Object . entries ( ngPackageConfig . lib . sass ) ) {
309+ if ( Array . isArray ( value ) ) {
310+ const existing = Array . isArray ( sass [ key ] ) ? ( sass [ key ] as string [ ] ) : [ ] ;
311+ sass [ key ] = [ ...new Set ( [ ...existing , ...value ] ) ] ;
323312 }
324313 }
325314 existingPreprocessorOptions [ 'sass' ] = sass ;
@@ -421,7 +410,7 @@ function updateLibraryTarget(
421410 return false ;
422411 }
423412
424- const ngPackageConfig = primaryProjectFile
413+ let ngPackageConfig = primaryProjectFile
425414 ? parseNgPackageFile ( tree , primaryProjectFile )
426415 : undefined ;
427416
@@ -451,16 +440,34 @@ function updateLibraryTarget(
451440 ? secondary . subpath
452441 : `./${ secondary . subpath } ` ;
453442 entryPointExports [ exportKey ] = toRelativeExportPath ( secondary . entryPoint ) ;
443+
444+ if ( secondary . config ?. lib ) {
445+ ngPackageConfig ??= { } ;
446+ ngPackageConfig . lib ??= { } ;
447+
448+ if ( secondary . config . lib . styleIncludePaths ?. length ) {
449+ const secondaryDir = dirname ( secondary . configFile ) ;
450+ ngPackageConfig . lib . styleIncludePaths ??= [ ] ;
451+ for ( const includePath of secondary . config . lib . styleIncludePaths ) {
452+ ngPackageConfig . lib . styleIncludePaths . push (
453+ relative ( projectDir , join ( secondaryDir , includePath ) ) ,
454+ ) ;
455+ }
456+ }
457+
458+ if ( secondary . config . lib . sass ) {
459+ const sass : Record < string , unknown > = ( ngPackageConfig . lib . sass ??= { } ) ;
460+ for ( const [ key , value ] of Object . entries ( secondary . config . lib . sass ) ) {
461+ if ( Array . isArray ( value ) ) {
462+ const existing = Array . isArray ( sass [ key ] ) ? ( sass [ key ] as string [ ] ) : [ ] ;
463+ sass [ key ] = [ ...new Set ( [ ...existing , ...value ] ) ] ;
464+ }
465+ }
466+ }
467+ }
454468 }
455469
456- migrateTargetOptions (
457- normalizedProjectRoot ,
458- projectDir ,
459- buildTarget ,
460- ngPackageConfig ,
461- secondaryEntryPoints ,
462- tree ,
463- ) ;
470+ migrateTargetOptions ( normalizedProjectRoot , projectDir , buildTarget , ngPackageConfig , tree ) ;
464471
465472 const packageJsonPath = join ( normalizedProjectRoot , 'package.json' ) ;
466473
0 commit comments