@@ -4,12 +4,13 @@ import { glob } from 'tinyglobby';
4
4
import { AssetPattern } from '../../../ng-package.schema' ;
5
5
import { BuildGraph } from '../../graph/build-graph' ;
6
6
import { Node } from '../../graph/node' ;
7
+ import { isInProgress } from '../../graph/select' ;
7
8
import { transformFromPromise } from '../../graph/transform' ;
8
9
import { colors } from '../../utils/color' ;
9
10
import { copyFile , exists , readFile , rmdir , stat , writeFile } from '../../utils/fs' ;
10
11
import * as log from '../../utils/log' ;
11
12
import { ensureUnixPath } from '../../utils/path' ;
12
- import { EntryPointNode , PackageNode , fileUrl , isEntryPoint , isEntryPointInProgress , isPackage } from '../nodes' ;
13
+ import { EntryPointNode , PackageNode , fileUrl , isEntryPoint , isPackage } from '../nodes' ;
13
14
import { NgPackagrOptions } from '../options.di' ;
14
15
import { NgPackage } from '../package' ;
15
16
import { NgEntryPoint } from './entry-point' ;
@@ -19,7 +20,8 @@ type CompilationMode = 'partial' | 'full' | undefined;
19
20
export const writePackageTransform = ( options : NgPackagrOptions ) =>
20
21
transformFromPromise ( async graph => {
21
22
const spinner = ora ( { hideCursor : false , discardStdin : false } ) ;
22
- const entryPoint : EntryPointNode = graph . find ( isEntryPointInProgress ( ) ) ;
23
+ const entryPoints = graph . filter ( isEntryPoint ) ;
24
+ const entryPoint = entryPoints . find ( isInProgress ) ;
23
25
const ngEntryPoint : NgEntryPoint = entryPoint . data . entryPoint ;
24
26
const ngPackageNode : PackageNode = graph . find ( isPackage ) ;
25
27
const ngPackage = ngPackageNode . data ;
@@ -28,7 +30,7 @@ export const writePackageTransform = (options: NgPackagrOptions) =>
28
30
if ( ! ngEntryPoint . isSecondaryEntryPoint ) {
29
31
spinner . start ( 'Copying assets' ) ;
30
32
try {
31
- await copyAssets ( graph , entryPoint , ngPackageNode ) ;
33
+ await copyAssets ( graph , entryPoint , ngPackageNode , entryPoints ) ;
32
34
} catch ( error ) {
33
35
spinner . fail ( ) ;
34
36
throw error ;
@@ -59,7 +61,7 @@ export const writePackageTransform = (options: NgPackagrOptions) =>
59
61
{
60
62
module : relativeUnixFromDestPath ( destinationFiles . fesm2022 ) ,
61
63
typings : relativeUnixFromDestPath ( destinationFiles . declarationsBundled ) ,
62
- exports : generatePackageExports ( ngEntryPoint , graph ) ,
64
+ exports : generatePackageExports ( ngEntryPoint , entryPoints ) ,
63
65
// webpack v4+ specific flag to enable advanced optimizations and code splitting
64
66
sideEffects : ngEntryPoint . packageJson . sideEffects ?? false ,
65
67
} ,
@@ -107,21 +109,20 @@ async function copyAssets(
107
109
graph : BuildGraph ,
108
110
entryPointNode : EntryPointNode ,
109
111
ngPackageNode : PackageNode ,
112
+ entryPoints : EntryPointNode [ ] ,
110
113
) : Promise < void > {
111
114
const ngPackage = ngPackageNode . data ;
112
-
113
115
const globsForceIgnored : string [ ] = [ '.gitkeep' , '**/.DS_Store' , '**/Thumbs.db' , `${ ngPackage . dest } /**` ] ;
114
116
const defaultAssets : AssetEntry [ ] = [
115
117
{ glob : 'LICENSE' , input : '/' , output : '/' } ,
116
- ...graph . filter ( isEntryPoint ) . map ( ( { data } ) => {
118
+ ...entryPoints . map ( ( { data } ) => {
117
119
const subpath = data . entryPoint . destinationFiles . directory || '/' ;
118
120
119
121
return { glob : 'README.md' , input : subpath , output : subpath } ;
120
122
} ) ,
121
123
] ;
122
124
123
125
const assets : AssetEntry [ ] = [ ] ;
124
-
125
126
for ( const assetPath of [ ...ngPackage . assets , ...defaultAssets ] ) {
126
127
let asset : AssetEntry ;
127
128
if ( typeof assetPath === 'object' ) {
@@ -332,7 +333,10 @@ type ConditionalExport = { types?: string; default?: string };
332
333
* Generates the `package.json` package exports following APF v13.
333
334
* This is supposed to match with: https://github.com/angular/angular/blob/e0667efa6eada64d1fb8b143840689090fc82e52/packages/bazel/src/ng_package/packager.ts#L415.
334
335
*/
335
- function generatePackageExports ( { destinationPath, packageJson } : NgEntryPoint , graph : BuildGraph ) : PackageExports {
336
+ function generatePackageExports (
337
+ { destinationPath, packageJson } : NgEntryPoint ,
338
+ entryPoints : EntryPointNode [ ] ,
339
+ ) : PackageExports {
336
340
const exports : PackageExports = packageJson . exports ? JSON . parse ( JSON . stringify ( packageJson . exports ) ) : { } ;
337
341
338
342
const insertMappingOrError = ( subpath : string , mapping : ConditionalExport ) => {
@@ -361,7 +365,6 @@ function generatePackageExports({ destinationPath, packageJson }: NgEntryPoint,
361
365
362
366
insertMappingOrError ( './package.json' , { default : './package.json' } ) ;
363
367
364
- const entryPoints = graph . filter ( isEntryPoint ) ;
365
368
for ( const entryPoint of entryPoints ) {
366
369
const { destinationFiles, isSecondaryEntryPoint } = entryPoint . data . entryPoint ;
367
370
const subpath = isSecondaryEntryPoint ? `./${ destinationFiles . directory } ` : '.' ;
0 commit comments