@@ -16,16 +16,10 @@ import {analyzeFileAndEnsureNoCrossImports} from './cross_entry_points_imports';
1616 * List of known `package.json` fields which provide information about
1717 * supported package formats and their associated entry paths.
1818 */
19- const knownFormatPackageJsonFormatFields = [
20- 'main' ,
21- 'esm2022' ,
22- 'esm' ,
23- 'typings' ,
24- 'module' ,
25- ] as const ;
19+ const knownFormatPackageJsonFormatFields = [ 'main' , 'esm2022' , 'esm' , 'typings' , 'module' ] as const ;
2620
2721/** Union type matching known `package.json` format fields. */
28- type KnownPackageJsonFormatFields = typeof knownFormatPackageJsonFormatFields [ number ] ;
22+ type KnownPackageJsonFormatFields = ( typeof knownFormatPackageJsonFormatFields ) [ number ] ;
2923
3024/**
3125 * Type describing the conditional exports descriptor for an entry-point.
@@ -41,7 +35,7 @@ type ConditionalExport = {
4135/** Type describing a `package.json` the packager deals with. */
4236type PackageJson = {
4337 [ key in KnownPackageJsonFormatFields ] ?: string ;
44- } & {
38+ } & {
4539 name : string ;
4640 type ?: string ;
4741 exports ?: Record < string , ConditionalExport > ;
@@ -64,29 +58,29 @@ function main(args: string[]): void {
6458 const params = fs . readFileSync ( paramFilePath , 'utf-8' ) . split ( '\n' ) . map ( unquoteParameter ) ;
6559
6660 const [
67- // Output directory for the npm package.
68- outputDirExecPath ,
61+ // Output directory for the npm package.
62+ outputDirExecPath ,
6963
70- // The package segment of the ng_package rule's label (e.g. 'package/common').
71- owningPackageName ,
64+ // The package segment of the ng_package rule's label (e.g. 'package/common').
65+ owningPackageName ,
7266
73- // JSON data capturing metadata of the package being built. See `PackageMetadata`.
74- metadataArg ,
67+ // JSON data capturing metadata of the package being built. See `PackageMetadata`.
68+ metadataArg ,
7569
76- // Path to the package's README.md.
77- readmeMd ,
70+ // Path to the package's README.md.
71+ readmeMd ,
7872
79- // List of rolled-up flat ES2022 modules
80- fesm2022Arg ,
73+ // List of rolled-up flat ES2022 modules
74+ fesm2022Arg ,
8175
82- // List of individual ES2022 modules
83- esm2022Arg ,
76+ // List of individual ES2022 modules
77+ esm2022Arg ,
8478
85- // List of static files that should be copied into the package.
86- staticFilesArg ,
79+ // List of static files that should be copied into the package.
80+ staticFilesArg ,
8781
88- // List of all type definitions that need to packaged into the ng_package.
89- typeDefinitionsArg ,
82+ // List of all type definitions that need to packaged into the ng_package.
83+ typeDefinitionsArg ,
9084 ] = params ;
9185
9286 const fesm2022 = JSON . parse ( fesm2022Arg ) as BazelFileInfo [ ] ;
@@ -105,7 +99,7 @@ function main(args: string[]): void {
10599 * file is written to.
106100 * @param fileContent Content of the file.
107101 */
108- function writeFile ( outputRelativePath : string , fileContent : string | Buffer ) {
102+ function writeFile ( outputRelativePath : string , fileContent : string | Buffer ) {
109103 const outputPath = path . join ( outputDirExecPath , outputRelativePath ) ;
110104
111105 // Always ensure that the target directory exists.
@@ -192,7 +186,7 @@ function main(args: string[]): void {
192186
193187 const crossEntryPointFailures : string [ ] = [ ] ;
194188
195- esm2022 . forEach ( file => {
189+ esm2022 . forEach ( ( file ) => {
196190 crossEntryPointFailures . push ( ...analyzeFileAndEnsureNoCrossImports ( file , metadata ) ) ;
197191 writeEsm2022File ( file ) ;
198192 } ) ;
@@ -203,12 +197,12 @@ function main(args: string[]): void {
203197 }
204198
205199 // Copy all FESM files into the package output.
206- fesm2022 . forEach ( f => copyFile ( f . path , getFlatEsmOutputRelativePath ( f ) ) ) ;
200+ fesm2022 . forEach ( ( f ) => copyFile ( f . path , getFlatEsmOutputRelativePath ( f ) ) ) ;
207201
208202 // Copy all type definitions into the package, preserving the sub-path from the
209203 // owning package. e.g. a file like `packages/animations/browser/__index.d.ts` will
210204 // end up in `browser/index.d.ts`
211- typeDefinitions . forEach ( f => copyFile ( f . path , getTypingOutputRelativePath ( f ) ) ) ;
205+ typeDefinitions . forEach ( ( f ) => copyFile ( f . path , getTypingOutputRelativePath ( f ) ) ) ;
212206
213207 for ( const file of staticFiles ) {
214208 // We copy all files into the package output while preserving the sub-path from
@@ -226,20 +220,25 @@ function main(args: string[]): void {
226220 // Resolution in the package should only be based on the top-level `package.json`.
227221 if ( ! isPrimaryPackageJson ) {
228222 throw Error (
229- `Found a nested "package.json" file in the package output: ${ file . shortPath } .\n` +
230- `All information of the package should reside in the primary package file.` ) ;
223+ `Found a nested "package.json" file in the package output: ${ file . shortPath } .\n` +
224+ `All information of the package should reside in the primary package file.` ,
225+ ) ;
231226 }
232227
233228 // Check if the `name` field of the `package.json` files are matching with
234229 // name of the NPM package. This is an additional safety check.
235230 if ( packageName !== metadata . npmPackageName ) {
236231 throw Error (
237- `Primary "package.json" has mismatching package name. Expected the ` +
238- `package to be named "${ metadata . npmPackageName } ", but is set to: ${ packageName } .` ) ;
232+ `Primary "package.json" has mismatching package name. Expected the ` +
233+ `package to be named "${ metadata . npmPackageName } ", but is set to: ${ packageName } .` ,
234+ ) ;
239235 }
240236
241- let newPackageJson =
242- insertFormatFieldsIntoPackageJson ( outputRelativePath , packageJson , false ) ;
237+ let newPackageJson = insertFormatFieldsIntoPackageJson (
238+ outputRelativePath ,
239+ packageJson ,
240+ false ,
241+ ) ;
243242
244243 newPackageJson = updatePrimaryPackageJson ( newPackageJson ) ;
245244
@@ -260,8 +259,10 @@ function main(args: string[]): void {
260259 * @param isGeneratedPackageJson Whether the passed package.json has been generated.
261260 */
262261 function insertFormatFieldsIntoPackageJson (
263- packageJsonOutRelativePath : string , parsedPackage : Readonly < PackageJson > ,
264- isGeneratedPackageJson : boolean ) : PackageJson {
262+ packageJsonOutRelativePath : string ,
263+ parsedPackage : Readonly < PackageJson > ,
264+ isGeneratedPackageJson : boolean ,
265+ ) : PackageJson {
265266 const packageJson : PackageJson = { ...parsedPackage } ;
266267 const packageName = packageJson [ 'name' ] ;
267268 const entryPointInfo = metadata . entryPoints [ packageName ] ;
@@ -280,30 +281,37 @@ function main(args: string[]): void {
280281 console . error ( 'WARNING: no module metadata for package' , packageName ) ;
281282 console . error ( ' Not updating the package.json file to point to it' ) ;
282283 console . error (
283- ' The ng_module for this package is possibly missing the module_name attribute ' ) ;
284+ ' The ng_module for this package is possibly missing the module_name attribute ' ,
285+ ) ;
284286 return packageJson ;
285287 }
286288
287289 // If we guessed the index paths for a module, and it contains an explicit `package.json`
288290 // file that already sets format properties, we skip automatic insertion of format
289291 // properties but report a warning in case properties have been set by accident.
290- if ( entryPointInfo . guessedPaths && ! isGeneratedPackageJson &&
291- hasExplicitFormatProperties ( packageJson ) ) {
292+ if (
293+ entryPointInfo . guessedPaths &&
294+ ! isGeneratedPackageJson &&
295+ hasExplicitFormatProperties ( packageJson )
296+ ) {
292297 console . error ( 'WARNING: `package.json` explicitly sets format properties (like `main`).' ) ;
293298 console . error (
294- ' Skipping automatic insertion of format properties as explicit ' +
295- 'format properties are set.' ) ;
299+ ' Skipping automatic insertion of format properties as explicit ' +
300+ 'format properties are set.' ,
301+ ) ;
296302 console . error ( ' Ignore this warning if explicit properties are set intentionally.' ) ;
297303 return packageJson ;
298304 }
299305
300306 const fesm2022RelativeOutPath = getFlatEsmOutputRelativePath ( entryPointInfo . fesm2022Bundle ) ;
301307 const typingsRelativeOutPath = getTypingOutputRelativePath ( entryPointInfo . typings ) ;
302308
303- packageJson . module =
304- normalizePath ( path . relative ( packageJsonContainingDir , fesm2022RelativeOutPath ) ) ;
305- packageJson . typings =
306- normalizePath ( path . relative ( packageJsonContainingDir , typingsRelativeOutPath ) ) ;
309+ packageJson . module = normalizePath (
310+ path . relative ( packageJsonContainingDir , fesm2022RelativeOutPath ) ,
311+ ) ;
312+ packageJson . typings = normalizePath (
313+ path . relative ( packageJsonContainingDir , typingsRelativeOutPath ) ,
314+ ) ;
307315
308316 return packageJson ;
309317 }
@@ -315,8 +323,9 @@ function main(args: string[]): void {
315323 function updatePrimaryPackageJson ( packageJson : Readonly < PackageJson > ) : PackageJson {
316324 if ( packageJson . type !== undefined ) {
317325 throw Error (
318- 'The primary "package.json" file of the package sets the "type" field ' +
319- 'that is controlled by the packager. Please unset it.' ) ;
326+ 'The primary "package.json" file of the package sets the "type" field ' +
327+ 'that is controlled by the packager. Please unset it.' ,
328+ ) ;
320329 }
321330
322331 const newPackageJson : PackageJson = { ...packageJson } ;
@@ -330,8 +339,9 @@ function main(args: string[]): void {
330339 // Capture all entry-points in the `exports` field using the subpath export declarations:
331340 // https://nodejs.org/api/packages.html#packages_subpath_exports.
332341 for ( const [ moduleName , entryPoint ] of Object . entries ( metadata . entryPoints ) ) {
333- const subpath =
334- isSecondaryEntryPoint ( moduleName ) ? `./${ getEntryPointSubpath ( moduleName ) } ` : '.' ;
342+ const subpath = isSecondaryEntryPoint ( moduleName )
343+ ? `./${ getEntryPointSubpath ( moduleName ) } `
344+ : '.' ;
335345 const esmIndexOutRelativePath = getEsm2022OutputRelativePath ( entryPoint . index ) ;
336346 const fesm2022OutRelativePath = getFlatEsmOutputRelativePath ( entryPoint . fesm2022Bundle ) ;
337347 const typesOutRelativePath = getTypingOutputRelativePath ( entryPoint . typings ) ;
@@ -356,7 +366,10 @@ function main(args: string[]): void {
356366 * @throws An error if the mapping is already defined and would conflict.
357367 */
358368 function insertExportMappingOrError (
359- packageJson : PackageJson , subpath : string , mapping : ConditionalExport ) {
369+ packageJson : PackageJson ,
370+ subpath : string ,
371+ mapping : ConditionalExport ,
372+ ) {
360373 if ( packageJson . exports === undefined ) {
361374 packageJson . exports = { } ;
362375 }
@@ -372,8 +385,9 @@ function main(args: string[]): void {
372385 for ( const conditionName of Object . keys ( mapping ) as [ keyof ConditionalExport ] ) {
373386 if ( subpathExport [ conditionName ] !== undefined ) {
374387 throw Error (
375- `Found a conflicting export condition for "${ subpath } ". The "${ conditionName } " ` +
376- `condition would be overridden by the packager. Please unset it.` ) ;
388+ `Found a conflicting export condition for "${ subpath } ". The "${ conditionName } " ` +
389+ `condition would be overridden by the packager. Please unset it.` ,
390+ ) ;
377391 }
378392
379393 // **Note**: The order of the conditions is preserved even though we are setting
@@ -384,10 +398,9 @@ function main(args: string[]): void {
384398
385399 /** Whether the package explicitly sets any of the format properties (like `main`). */
386400 function hasExplicitFormatProperties ( parsedPackage : Readonly < PackageJson > ) : boolean {
387- return Object . keys ( parsedPackage )
388- . some (
389- ( fieldName : string ) => knownFormatPackageJsonFormatFields . includes (
390- fieldName as KnownPackageJsonFormatFields ) ) ;
401+ return Object . keys ( parsedPackage ) . some ( ( fieldName : string ) =>
402+ knownFormatPackageJsonFormatFields . includes ( fieldName as KnownPackageJsonFormatFields ) ,
403+ ) ;
391404 }
392405
393406 /**
0 commit comments