Skip to content

Commit

Permalink
fix: minify mainlib docs json (#9963)
Browse files Browse the repository at this point in the history
* fix: minify mainlib docs json

* fix: minify them all
  • Loading branch information
Qjuh authored Nov 14, 2023
1 parent f9177be commit 4b88306
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 14 deletions.
15 changes: 14 additions & 1 deletion packages/api-extractor-model/src/model/ApiPackage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.

import { Buffer } from 'node:buffer';
import { TSDocConfiguration } from '@microsoft/tsdoc';
import { DeclarationReference } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference.js';
import { TSDocConfigFile } from '@microsoft/tsdoc-config';
Expand All @@ -10,6 +11,7 @@ import {
PackageJsonLookup,
type IPackageJson,
type JsonObject,
FileSystem,
} from '@rushstack/node-core-library';
import { ApiDocumentedItem, type IApiDocumentedItemOptions } from '../items/ApiDocumentedItem.js';
import { ApiItem, ApiItemKind, type IApiItemJson } from '../items/ApiItem.js';
Expand Down Expand Up @@ -98,6 +100,11 @@ export interface IApiPackageJson extends IApiItemJson {
* @public
*/
export interface IApiPackageSaveOptions extends IJsonFileSaveOptions {
/**
* Set to true to not have indentation or newlines in resulting JSON.
*/
minify?: boolean;

/**
* Set to true only when invoking API Extractor's test harness.
*
Expand Down Expand Up @@ -300,7 +307,13 @@ export class ApiPackage extends ApiItemContainerMixin(ApiNameMixin(ApiDocumented
}

this.serializeInto(jsonObject);
JsonFile.save(jsonObject, apiJsonFilename, ioptions);
if (ioptions.minify) {
FileSystem.writeFile(apiJsonFilename, Buffer.from(JSON.stringify(jsonObject), 'utf8'), {
ensureFolderExists: ioptions.ensureFolderExists ?? true,
});
} else {
JsonFile.save(jsonObject, apiJsonFilename, ioptions);
}
}

/**
Expand Down
7 changes: 6 additions & 1 deletion packages/api-extractor/src/api/Extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export interface IExtractorInvokeOptions {
*/
compilerState?: CompilerState;

/**
* Whether to minify the resulting doc model JSON, i.e. without any indentation or newlines.
*/
docModelMinify?: boolean;

/**
* Indicates that API Extractor is running as part of a local build, e.g. on developer's
* machine.
Expand Down Expand Up @@ -270,7 +275,7 @@ export class Extractor {
apiPackage.saveToJsonFile(extractorConfig.apiJsonFilePath, {
toolPackage: Extractor.packageName,
toolVersion: Extractor.version,

minify: options?.docModelMinify ?? false,
newlineConversion: extractorConfig.newlineKind,
ensureFolderExists: true,
testMode: extractorConfig.testMode,
Expand Down
9 changes: 9 additions & 0 deletions packages/api-extractor/src/cli/RunAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export class RunAction extends CommandLineAction {

private readonly _typescriptCompilerFolder: CommandLineStringParameter;

private readonly _minify: CommandLineFlagParameter;

public constructor(_parser: ApiExtractorCommandLine) {
super({
actionName: 'run',
Expand Down Expand Up @@ -57,6 +59,12 @@ export class RunAction extends CommandLineAction {
description: 'Show additional informational messages in the output.',
});

this._minify = this.defineFlagParameter({
parameterLongName: '--minify',
parameterShortName: '-m',
description: 'Minify the resulting doc model JSON, i.e. without any indentation or newlines.',
});

this._diagnosticsParameter = this.defineFlagParameter({
parameterLongName: '--diagnostics',
description:
Expand Down Expand Up @@ -136,6 +144,7 @@ export class RunAction extends CommandLineAction {

const extractorResult: ExtractorResult = Extractor.invoke(extractorConfig, {
localBuild: this._localParameter.value,
docModelMinify: this._minify.value,
showVerboseMessages: this._verboseParameter.value,
showDiagnostics: this._diagnosticsParameter.value,
typescriptCompilerFolder,
Expand Down
2 changes: 1 addition & 1 deletion packages/brokers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"prepack": "pnpm run lint && pnpm run test && pnpm run build",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/brokers/*'",
"release": "cliff-jumper"
Expand Down
2 changes: 1 addition & 1 deletion packages/builders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"prepack": "pnpm run lint && pnpm run test && pnpm run build",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/builders/*'",
"release": "cliff-jumper"
Expand Down
2 changes: 1 addition & 1 deletion packages/collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"prepack": "pnpm run lint && pnpm run test && pnpm run build",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/collection/*'",
"release": "cliff-jumper"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src",
"docs": "pnpm run build:docs && api-extractor run --local",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"prepack": "pnpm run build && pnpm run lint",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/core/*'",
"release": "cliff-jumper"
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"fmt": "pnpm run format",
"docs": "docgen -i './src/*.js' './src/**/*.js' -c ./docs/index.json -r ../../ -o ./docs/docs.json && pnpm run docs:new",
"docs:test": "docgen -i './src/*.js' './src/**/*.js' -c ./docs/index.json -r ../../",
"docs:new": "api-extractor -d run --local",
"docs:new": "api-extractor run --local --minify",
"prepack": "pnpm run lint && pnpm run test",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/discord.js/*'",
"release": "cliff-jumper"
Expand Down
2 changes: 1 addition & 1 deletion packages/formatters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"docs": "pnpm run build:docs && api-extractor run --local",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"prepack": "pnpm run build && pnpm run lint",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/formatters/*'",
"release": "cliff-jumper"
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"docs": "pnpm run build:docs && api-extractor run --local",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"prepack": "pnpm run build && pnpm run lint",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/next/*'",
"release": "cliff-jumper"
Expand Down
2 changes: 1 addition & 1 deletion packages/proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"prepack": "pnpm run lint && pnpm run test && pnpm run build",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/proxy/*'",
"release": "cliff-jumper"
Expand Down
2 changes: 1 addition & 1 deletion packages/rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"prepack": "pnpm run lint && pnpm run test && pnpm run build",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/rest/*'",
"release": "cliff-jumper"
Expand Down
2 changes: 1 addition & 1 deletion packages/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"prepack": "pnpm run lint && pnpm run test && pnpm run build",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/util/*'",
"release": "cliff-jumper"
Expand Down
2 changes: 1 addition & 1 deletion packages/voice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"prepack": "pnpm run lint && pnpm run test && pnpm run build",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/voice/*'",
"release": "cliff-jumper"
Expand Down
2 changes: 1 addition & 1 deletion packages/ws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"docs": "pnpm run build:docs && api-extractor run --local",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"prepack": "pnpm run build && pnpm run lint",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/ws/*'",
"release": "cliff-jumper"
Expand Down

0 comments on commit 4b88306

Please sign in to comment.