Skip to content

Commit cfa56fe

Browse files
authored
Merge pull request microsoft#778 from Microsoft/pgonzal/json-schema-update
[rush] Add missing "$schema" directives for Rush config files
2 parents 5383df6 + 5128064 commit cfa56fe

17 files changed

Lines changed: 221 additions & 52 deletions

‎apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as os from 'os';
66
import { JsonFile, JsonSchema, FileSystem, NewlineKind } from '@microsoft/node-core-library';
77

88
import { Utilities } from '../utilities/Utilities';
9+
import { JsonSchemaUrls } from '../logic/JsonSchemaUrls';
910

1011
/**
1112
* Part of IApprovedPackagesJson.
@@ -67,6 +68,8 @@ export class ApprovedPackagesConfiguration {
6768
public clear(): void {
6869
this._itemsByName.clear();
6970
this._loadedJson = {
71+
// Ensure this comes first in the key ordering
72+
$schema: '',
7073
packages: []
7174
};
7275
}
@@ -127,6 +130,8 @@ export class ApprovedPackagesConfiguration {
127130
// Update the JSON structure that we already loaded, preserving any existing state
128131
// (which passed schema validation).
129132

133+
this._loadedJson.$schema = JsonSchemaUrls.approvedPackages,
134+
130135
this._loadedJson.packages = [];
131136

132137
this.items.sort((a: ApprovedPackagesItem, b: ApprovedPackagesItem) => {
@@ -147,7 +152,7 @@ export class ApprovedPackagesConfiguration {
147152
}
148153

149154
// Save the file
150-
let body: string = JSON.stringify(this._loadedJson, undefined, 2) + '\n';
155+
let body: string = JsonFile.stringify(this._loadedJson);
151156

152157
// Unindent the allowedCategories array to improve readability
153158
body = body.replace(

‎apps/rush-lib/src/api/CommonVersionsConfiguration.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ProtectableMap,
1111
FileSystem
1212
} from '@microsoft/node-core-library';
13+
import { JsonSchemaUrls } from '../logic/JsonSchemaUrls';
1314

1415
/**
1516
* Part of the ICommonVersionsJson structure.
@@ -37,6 +38,8 @@ export declare interface ICommonVersionsJsonVersionsMap {
3738
* Describes the file structure for the "common/config/rush/common-versions.json" config file.
3839
*/
3940
interface ICommonVersionsJson {
41+
$schema?: string;
42+
4043
preferredVersions?: ICommonVersionsJsonVersionMap;
4144

4245
xstitchPreferredVersions?: ICommonVersionsJsonVersionMap;
@@ -104,7 +107,7 @@ export class CommonVersionsConfiguration {
104107
* Writes the "common-versions.json" file to disk, using the filename that was passed to loadFromFile().
105108
*/
106109
public save(): void {
107-
JsonFile.save(this._serialize(), this._filename);
110+
JsonFile.save(this._serialize(), this._filename, { updateExistingFile: true });
108111
}
109112

110113
/**
@@ -218,7 +221,9 @@ export class CommonVersionsConfiguration {
218221
}
219222

220223
private _serialize(): ICommonVersionsJson {
221-
const result: ICommonVersionsJson = { };
224+
const result: ICommonVersionsJson = {
225+
$schema: JsonSchemaUrls.commonVersions
226+
};
222227

223228
if (this._preferredVersions.size) {
224229
result.preferredVersions = CommonVersionsConfiguration._serializeTable(this.preferredVersions);

‎apps/rush-lib/src/api/VersionPolicyConfiguration.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class VersionPolicyConfiguration {
156156
versionPolicyJson.push(versionPolicy._json);
157157
});
158158
if (shouldCommit) {
159-
JsonFile.save(versionPolicyJson, this._jsonFileName);
159+
JsonFile.save(versionPolicyJson, this._jsonFileName, { updateExistingFile: true });
160160
}
161161
}
162162
}

‎apps/rush-lib/src/logic/ChangelogGenerator.ts‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ export class ChangelogGenerator {
5555
project.isMainProject
5656
);
5757

58-
if (changeLog) {
59-
updatedChangeLogs.push(changeLog);
60-
}
58+
if (changeLog) {
59+
updatedChangeLogs.push(changeLog);
60+
}
6161
}
6262
}
6363
}
@@ -129,11 +129,16 @@ export class ChangelogGenerator {
129129
changelogEntry.comments[changeTypeString] =
130130
changelogEntry.comments[changeTypeString] || [];
131131

132-
comments.push({
133-
author: individualChange.author,
134-
commit: individualChange.commit,
132+
const changeLogComment: IChangeLogComment = {
135133
comment: individualChange.comment
136-
});
134+
};
135+
if (individualChange.author) {
136+
changeLogComment.author = individualChange.author;
137+
}
138+
if (individualChange.commit) {
139+
changeLogComment.commit = individualChange.commit;
140+
}
141+
comments.push(changeLogComment);
137142
}
138143
});
139144

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+
// See LICENSE in the project root for license information.
3+
4+
/**
5+
* JSON schema URLs that Rush writes into config files.
6+
*/
7+
export namespace JsonSchemaUrls {
8+
export const approvedPackages: string
9+
= 'https://developer.microsoft.com/json-schemas/rush/v5/approved-packages.schema.json';
10+
11+
export const commonVersions: string
12+
= 'https://developer.microsoft.com/json-schemas/rush/v5/common-versions.schema.json';
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/node-core-library",
5+
"comment": "Add features to JsonFile API to update an existing JSON file while preserving comments and whitespace",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@microsoft/node-core-library",
10+
"email": "pgonzal@users.noreply.github.com"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "When saving config files, Rush should include the \"$schema\" directive",
5+
"packageName": "@microsoft/rush",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "pgonzal@users.noreply.github.com"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Fix a regression where \"rush version\" sometimes failed with \"The value for entries[0].comments.dependency[0].author is undefined\"",
5+
"packageName": "@microsoft/rush",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "pgonzal@users.noreply.github.com"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "When updating common-versions.json and version-policies.json, preserve the existing comments and whitespace",
5+
"packageName": "@microsoft/rush",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "pgonzal@users.noreply.github.com"
11+
}

‎common/config/rush/command-line.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json",
3+
24
"parameters": [
35
{
46
"longName": "--no-color",

0 commit comments

Comments
 (0)