Skip to content

Commit 7d90301

Browse files
committed
Add "Experiments" configuration file.
1 parent 758ca4d commit 7d90301

7 files changed

Lines changed: 122 additions & 4 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* This configuration file allows repo maintainers to enable and disable experimental
3+
* Rush features. For full documentation, please see https://rushjs.io
4+
*/
5+
{
6+
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/experiments.schema.json",
7+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
import * as path from 'path';
5+
import {
6+
JsonFile,
7+
JsonSchema,
8+
FileSystem
9+
} from '@microsoft/node-core-library';
10+
11+
/**
12+
* @beta
13+
*/
14+
export interface IExperimentsJson {
15+
}
16+
17+
/**
18+
* Use this class to load the "common/config/rush/experiments.json" config file.
19+
* This file allows repo maintainers to enable and disable experimental Rush features.
20+
* @beta
21+
*/
22+
export class ExperimentsConfiguration {
23+
private static _jsonSchema: JsonSchema = JsonSchema.fromFile(
24+
path.join(__dirname, '..', 'schemas', 'experiments.schema.json')
25+
);
26+
27+
private _experimentConfiguration: IExperimentsJson;
28+
private _jsonFileName: string;
29+
30+
/**
31+
* @internal
32+
*/
33+
public constructor(jsonFileName: string) {
34+
this._jsonFileName = jsonFileName;
35+
this._experimentConfiguration = {};
36+
37+
if (!FileSystem.exists(this._jsonFileName)) {
38+
this._experimentConfiguration = {};
39+
} else {
40+
this._experimentConfiguration = JsonFile.loadAndValidate(
41+
this._jsonFileName,
42+
ExperimentsConfiguration._jsonSchema
43+
);
44+
}
45+
}
46+
47+
/**
48+
* Get the experiments configuration.
49+
*/
50+
public get experimentConfiguration(): Readonly<IExperimentsJson> {
51+
return this._experimentConfiguration;
52+
}
53+
}

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { PackageManagerName, PackageManager } from './packageManager/PackageMana
2626
import { NpmPackageManager } from './packageManager/NpmPackageManager';
2727
import { YarnPackageManager } from './packageManager/YarnPackageManager';
2828
import { PnpmPackageManager } from './packageManager/PnpmPackageManager';
29+
import { ExperimentsConfiguration } from './ExperimentsConfiguration';
2930

3031
const MINIMUM_SUPPORTED_RUSH_JSON_VERSION: string = '0.0.0';
3132

@@ -40,7 +41,8 @@ const knownRushConfigFilenames: string[] = [
4041
RushConstants.browserApprovedPackagesFilename,
4142
RushConstants.nonbrowserApprovedPackagesFilename,
4243
RushConstants.versionPoliciesFilename,
43-
RushConstants.commandLineFilename
44+
RushConstants.commandLineFilename,
45+
RushConstants.experimentsFilename
4446
];
4547

4648
/**
@@ -327,6 +329,7 @@ export class RushConfiguration {
327329
private _projectsByName: Map<string, RushConfigurationProject>;
328330

329331
private _versionPolicyConfiguration: VersionPolicyConfiguration;
332+
private _experimentsConfiguration: ExperimentsConfiguration;
330333

331334
/**
332335
* Loads the configuration data from an Rush.json configuration file and returns
@@ -1013,6 +1016,16 @@ export class RushConfiguration {
10131016
return this._versionPolicyConfiguration;
10141017
}
10151018

1019+
/**
1020+
* This configuration object contains settings repo maintainers have specified to enable
1021+
* and disable experimental Rush features.
1022+
*
1023+
* @beta
1024+
*/
1025+
public get experimentsConfiguration(): ExperimentsConfiguration {
1026+
return this._experimentsConfiguration;
1027+
}
1028+
10161029
/**
10171030
* Returns the project for which the specified path is underneath that project's folder.
10181031
* If the path is not under any project's folder, returns undefined.
@@ -1077,8 +1090,14 @@ export class RushConfiguration {
10771090

10781091
this._ensureConsistentVersions = !!rushConfigurationJson.ensureConsistentVersions;
10791092

1093+
const experimentsConfigFile: string = path.join(
1094+
this._commonRushConfigFolder,
1095+
RushConstants.experimentsFilename
1096+
);
1097+
this._experimentsConfiguration = new ExperimentsConfiguration(experimentsConfigFile);
1098+
10801099
this._pnpmOptions = new PnpmOptionsConfiguration(rushConfigurationJson.pnpmOptions || {});
1081-
this._yarnOptions = new YarnOptionsConfiguration(rushConfigurationJson.yarnOptions || { });
1100+
this._yarnOptions = new YarnOptionsConfiguration(rushConfigurationJson.yarnOptions || {});
10821101

10831102
// TODO: Add an actual "packageManager" field in rush.json
10841103
const packageManagerFields: string[] = [];
@@ -1185,8 +1204,10 @@ export class RushConfiguration {
11851204
this._eventHooks = new EventHooks(rushConfigurationJson.eventHooks);
11861205
}
11871206

1188-
const versionPolicyConfigFile: string =
1189-
path.join(this._commonRushConfigFolder, RushConstants.versionPoliciesFilename);
1207+
const versionPolicyConfigFile: string = path.join(
1208+
this._commonRushConfigFolder,
1209+
RushConstants.versionPoliciesFilename
1210+
);
11901211
this._versionPolicyConfiguration = new VersionPolicyConfiguration(versionPolicyConfigFile);
11911212

11921213
this._projects = [];

‎apps/rush-lib/src/index.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,8 @@ export {
8080
ILaunchOptions,
8181
Rush
8282
} from './api/Rush';
83+
84+
export {
85+
ExperimentsConfiguration,
86+
IExperimentsJson
87+
} from './api/ExperimentsConfiguration';

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ export namespace RushConstants {
128128

129129
export const versionPoliciesFilename: string = 'version-policies.json';
130130

131+
/**
132+
* Experiments configuration file, which
133+
*/
134+
export const experimentsFilename: string = 'experiments.json';
135+
131136
/**
132137
* The URL ("http://rushjs.io") for the Rush web site.
133138
*/
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"title": "Rush experiments.json config file",
4+
"description": "For use with the Rush tool, this file allows repo maintainers to enable and disable experimental Rush features.",
5+
6+
"type": "object",
7+
"properties": {
8+
"$schema": {
9+
"description": "Part of the JSON Schema standard, this optional keyword declares the URL of the schema that the file conforms to. Editors may download the schema and use it to perform syntax highlighting.",
10+
"type": "string"
11+
}
12+
},
13+
"additionalProperties": false
14+
}

‎common/reviews/api/rush-lib.api.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ export class EventHooks {
110110
get(event: Event): string[];
111111
}
112112

113+
// @beta
114+
export class ExperimentsConfiguration {
115+
// @internal
116+
constructor(jsonFileName: string);
117+
readonly experimentConfiguration: Readonly<IExperimentsJson>;
118+
}
119+
120+
// @beta (undocumented)
121+
export interface IExperimentsJson {
122+
}
123+
113124
// @public
114125
export interface ILaunchOptions {
115126
alreadyReportedNodeTooNewError?: boolean;
@@ -255,6 +266,8 @@ export class RushConfiguration {
255266
readonly ensureConsistentVersions: boolean;
256267
// @beta
257268
readonly eventHooks: EventHooks;
269+
// @beta
270+
readonly experimentsConfiguration: ExperimentsConfiguration;
258271
findProjectByShorthandName(shorthandProjectName: string): RushConfigurationProject | undefined;
259272
findProjectByTempName(tempProjectName: string): RushConfigurationProject | undefined;
260273
getCommittedShrinkwrapFilename(variant?: string | undefined): string;

0 commit comments

Comments
 (0)