Skip to content

Commit aba62a3

Browse files
committed
[heft-json-schema-typings-plugin] Make formatWithPrettier configurable
- Add formatWithPrettier option to JsonSchemaTypingsGenerator constructor - Expose formatWithPrettier in the Heft plugin options and JSON schema - Defaults to false (skip prettier formatting)
1 parent 55f7188 commit aba62a3

4 files changed

Lines changed: 31 additions & 7 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/heft-json-schema-typings-plugin",
5+
"comment": "Add a `formatWithPrettier` option (defaults to `false`) to skip prettier formatting of generated typings.",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@rushstack/heft-json-schema-typings-plugin"
10+
}

heft-plugins/heft-json-schema-typings-plugin/src/JsonSchemaTypingsGenerator.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ import { type ITypingsGeneratorBaseOptions, TypingsGenerator } from '@rushstack/
99

1010
import { _addTsDocTagToExports } from './TsDocTagHelpers';
1111

12-
interface IJsonSchemaTypingsGeneratorBaseOptions extends ITypingsGeneratorBaseOptions {}
12+
interface IJsonSchemaTypingsGeneratorBaseOptions extends ITypingsGeneratorBaseOptions {
13+
/**
14+
* If true, format generated typings with prettier. Defaults to false.
15+
*
16+
* @remarks
17+
* Enabling this requires the `prettier` package to be installed as a dependency.
18+
*/
19+
formatWithPrettier?: boolean;
20+
}
1321

1422
const SCHEMA_FILE_EXTENSION: '.schema.json' = '.schema.json';
1523
const X_TSDOC_TAG_KEY: 'x-tsdoc-tag' = 'x-tsdoc-tag';
@@ -21,8 +29,9 @@ interface IExtendedJson4Schema extends Json4Schema {
2129

2230
export class JsonSchemaTypingsGenerator extends TypingsGenerator {
2331
public constructor(options: IJsonSchemaTypingsGeneratorBaseOptions) {
32+
const { formatWithPrettier = false, ...otherOptions } = options;
2433
super({
25-
...options,
34+
...otherOptions,
2635
fileExtensions: [SCHEMA_FILE_EXTENSION],
2736
// eslint-disable-next-line @typescript-eslint/naming-convention
2837
parseAndGenerateTypings: async (
@@ -44,9 +53,7 @@ export class JsonSchemaTypingsGenerator extends TypingsGenerator {
4453
// The typings generator adds its own banner comment
4554
bannerComment: '',
4655
cwd: dirname,
47-
// The generated typings are machine-produced .d.ts files that do not need
48-
// prettier formatting.
49-
format: false
56+
format: formatWithPrettier
5057
});
5158

5259
// Check for an "x-tsdoc-tag" property in the schema (e.g. "@public" or "@beta").

heft-plugins/heft-json-schema-typings-plugin/src/JsonSchemaTypingsPlugin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const PLUGIN_NAME: 'json-schema-typings-plugin' = 'json-schema-typings-plugin';
1818
export interface IJsonSchemaTypingsPluginOptions {
1919
srcFolder?: string;
2020
generatedTsFolders?: string[];
21+
formatWithPrettier?: boolean;
2122
}
2223

2324
export default class JsonSchemaTypingsPlugin implements IHeftTaskPlugin<IJsonSchemaTypingsPluginOptions> {
@@ -34,7 +35,7 @@ export default class JsonSchemaTypingsPlugin implements IHeftTaskPlugin<IJsonSch
3435
hooks: { run, runIncremental }
3536
} = taskSession;
3637
const { buildFolderPath } = heftConfiguration;
37-
const { srcFolder = 'src', generatedTsFolders = ['temp/schemas-ts'] } = options;
38+
const { srcFolder = 'src', generatedTsFolders = ['temp/schemas-ts'], formatWithPrettier } = options;
3839

3940
const resolvedTsFolders: string[] = [];
4041
for (const generatedTsFolder of generatedTsFolders) {
@@ -47,7 +48,8 @@ export default class JsonSchemaTypingsPlugin implements IHeftTaskPlugin<IJsonSch
4748
srcFolder: `${buildFolderPath}/${srcFolder}`,
4849
generatedTsFolder,
4950
secondaryGeneratedTsFolders,
50-
terminal
51+
terminal,
52+
formatWithPrettier
5153
});
5254

5355
run.tapPromise(PLUGIN_NAME, async () => {

heft-plugins/heft-json-schema-typings-plugin/src/schemas/heft-json-schema-typings-plugin.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
"items": {
1919
"type": "string"
2020
}
21+
},
22+
23+
"formatWithPrettier": {
24+
"type": "boolean",
25+
"description": "If true, format generated typings with prettier. Defaults to false."
2126
}
2227
}
2328
}

0 commit comments

Comments
 (0)