1
1
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2
2
// See LICENSE in the project root for license information.
3
3
4
+ import { Buffer } from 'node:buffer' ;
4
5
import { TSDocConfiguration } from '@microsoft/tsdoc' ;
5
6
import { DeclarationReference } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference.js' ;
6
7
import { TSDocConfigFile } from '@microsoft/tsdoc-config' ;
@@ -10,6 +11,7 @@ import {
10
11
PackageJsonLookup ,
11
12
type IPackageJson ,
12
13
type JsonObject ,
14
+ FileSystem ,
13
15
} from '@rushstack/node-core-library' ;
14
16
import { ApiDocumentedItem , type IApiDocumentedItemOptions } from '../items/ApiDocumentedItem.js' ;
15
17
import { ApiItem , ApiItemKind , type IApiItemJson } from '../items/ApiItem.js' ;
@@ -98,6 +100,11 @@ export interface IApiPackageJson extends IApiItemJson {
98
100
* @public
99
101
*/
100
102
export interface IApiPackageSaveOptions extends IJsonFileSaveOptions {
103
+ /**
104
+ * Set to true to not have indentation or newlines in resulting JSON.
105
+ */
106
+ minify ?: boolean ;
107
+
101
108
/**
102
109
* Set to true only when invoking API Extractor's test harness.
103
110
*
@@ -300,7 +307,13 @@ export class ApiPackage extends ApiItemContainerMixin(ApiNameMixin(ApiDocumented
300
307
}
301
308
302
309
this . serializeInto ( jsonObject ) ;
303
- JsonFile . save ( jsonObject , apiJsonFilename , ioptions ) ;
310
+ if ( ioptions . minify ) {
311
+ FileSystem . writeFile ( apiJsonFilename , Buffer . from ( JSON . stringify ( jsonObject ) , 'utf8' ) , {
312
+ ensureFolderExists : ioptions . ensureFolderExists ?? true ,
313
+ } ) ;
314
+ } else {
315
+ JsonFile . save ( jsonObject , apiJsonFilename , ioptions ) ;
316
+ }
304
317
}
305
318
306
319
/**
0 commit comments