Skip to content

Commit 75bd106

Browse files
authored
Merge pull request #3866 from iclanton/heft-suppress-browserslist-warning-plugin
Introduce heft-suppress-browserslist-warning-plugin.
2 parents 6672b93 + b2ba3d8 commit 75bd106

File tree

15 files changed

+158
-28
lines changed

15 files changed

+158
-28
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,9 @@ jobs:
5151

5252
- name: Rush retest (install-run-rush)
5353
run: node common/scripts/install-run-rush.js retest --verbose --production
54-
env:
55-
# Prevent time-based browserslist update warning
56-
# See https://github.com/microsoft/rushstack/issues/2981
57-
BROWSERSLIST_IGNORE_OLD_DATA: 1
5854

5955
- name: Ensure repo README is up-to-date
6056
run: node repo-scripts/repo-toolbox/lib/start.js readme --verify
6157

6258
- name: Rush test (rush-lib)
6359
run: node apps/rush/lib/start-dev.js test --verbose --production --timeline
64-
env:
65-
# Prevent time-based browserslist update warning
66-
# See https://github.com/microsoft/rushstack/issues/2981
67-
BROWSERSLIST_IGNORE_OLD_DATA: 1

apps/heft/heft-plugin.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
"pluginName": "run-script-plugin",
3131
"entryPoint": "./lib/plugins/RunScriptPlugin",
3232
"optionsSchema": "./lib/schemas/run-script-options.schema.json"
33+
},
34+
{
35+
"entryPoint": "./lib/plugins/SetEnvironmentVariablesPlugin",
36+
"pluginName": "set-environment-variables-plugin",
37+
"optionsSchema": "./lib/schemas/set-environment-variables-plugin.schema.json"
3338
}
3439
]
3540
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 type { HeftConfiguration } from '../configuration/HeftConfiguration';
5+
import type { IHeftTaskSession } from '../pluginFramework/HeftTaskSession';
6+
import type { IHeftTaskPlugin } from '../pluginFramework/IHeftPlugin';
7+
8+
export const PLUGIN_NAME: string = 'set-environment-variables-plugin';
9+
10+
export interface ISetEnvironmentVariablesPluginOptions {
11+
environmentVariablesToSet: Record<string, string>;
12+
}
13+
14+
export default class SetEnvironmentVariablesPlugin
15+
implements IHeftTaskPlugin<ISetEnvironmentVariablesPluginOptions>
16+
{
17+
public apply(
18+
taskSession: IHeftTaskSession,
19+
heftConfiguration: HeftConfiguration,
20+
{ environmentVariablesToSet }: ISetEnvironmentVariablesPluginOptions
21+
): void {
22+
taskSession.hooks.run.tap(
23+
{
24+
name: PLUGIN_NAME,
25+
stage: Number.MIN_SAFE_INTEGER
26+
},
27+
() => {
28+
for (const [key, value] of Object.entries(environmentVariablesToSet)) {
29+
taskSession.logger.terminal.writeLine(`Setting environment variable ${key}=${value}`);
30+
process.env[key] = value;
31+
}
32+
}
33+
);
34+
}
35+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"title": "CopyFiles Heft Task Event Options",
4+
"description": "Defines configuration used by the \"copyFiles\" Heft task event.",
5+
"type": "object",
6+
7+
"additionalProperties": false,
8+
"required": ["environmentVariablesToSet"],
9+
10+
"properties": {
11+
"environmentVariablesToSet": {
12+
"type": "object",
13+
"pattern": ".+",
14+
"additionalProperties": {
15+
"type": "string"
16+
}
17+
}
18+
}
19+
}

apps/heft/src/startWithVersionSelector.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import type { IPackageJson } from '@rushstack/node-core-library';
1111
import { getToolParameterNamesFromArgs } from './utilities/CliUtilities';
1212
import { Constants } from './utilities/Constants';
1313

14-
const HEFT_PACKAGE_NAME: string = '@rushstack/heft';
15-
1614
// Excerpted from PackageJsonLookup.tryGetPackageFolderFor()
1715
function tryGetPackageFolderFor(resolvedFileOrFolderPath: string): string | undefined {
1816
// Two lookups are required, because get() cannot distinguish the undefined value
@@ -82,16 +80,16 @@ function tryStartLocalHeft(): boolean {
8280

8381
// Does package.json have a dependency on Heft?
8482
if (
85-
!(packageJson.dependencies && packageJson.dependencies[HEFT_PACKAGE_NAME]) &&
86-
!(packageJson.devDependencies && packageJson.devDependencies[HEFT_PACKAGE_NAME])
83+
!(packageJson.dependencies && packageJson.dependencies[Constants.heftPackageName]) &&
84+
!(packageJson.devDependencies && packageJson.devDependencies[Constants.heftPackageName])
8785
) {
8886
// No explicit dependency on Heft
8987
return false;
9088
}
9189

9290
// To avoid a loading the "resolve" NPM package, let's assume that the Heft dependency must be
9391
// installed as "<projectFolder>/node_modules/@rushstack/heft".
94-
const heftFolder: string = path.join(projectFolder, 'node_modules', HEFT_PACKAGE_NAME);
92+
const heftFolder: string = path.join(projectFolder, 'node_modules', Constants.heftPackageName);
9593

9694
heftEntryPoint = path.join(heftFolder, 'lib', 'start.js');
9795
if (!fs.existsSync(heftEntryPoint)) {

apps/heft/src/utilities/Constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ export class Constants {
3333
public static verboseParameterShortName: string = '-v';
3434

3535
public static maxParallelism: number = 100;
36+
37+
public static heftPackageName: string = '@rushstack/heft';
3638
}

apps/heft/src/utilities/CoreConfigFiles.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,28 @@ export class CoreConfigFiles {
7777
rigConfig?: IRigConfig | undefined
7878
): Promise<IHeftConfigurationJson> {
7979
if (!CoreConfigFiles._heftConfigFileLoader) {
80+
let heftPluginPackageFolder: string | undefined;
81+
8082
const pluginPackageResolver: (
8183
options: IJsonPathMetadataResolverOptions<IHeftConfigurationJson>
8284
) => string = (options: IJsonPathMetadataResolverOptions<IHeftConfigurationJson>) => {
8385
const { propertyValue, configurationFilePath } = options;
84-
if (propertyValue === '@rushstack/heft') {
86+
if (propertyValue === Constants.heftPackageName) {
8587
// If the value is "@rushstack/heft", then resolve to the Heft package that is
8688
// installed in the project folder. This avoids issues with mismatched versions
8789
// between the project and the globally installed Heft. Use the PackageJsonLookup
8890
// class to find the package folder to avoid hardcoding the path for compatibility
8991
// with bundling.
90-
const pluginPackageFolder: string | undefined =
91-
PackageJsonLookup.instance.tryGetPackageFolderFor(__dirname);
92-
if (!pluginPackageFolder) {
92+
if (!heftPluginPackageFolder) {
93+
heftPluginPackageFolder = PackageJsonLookup.instance.tryGetPackageFolderFor(__dirname);
94+
}
95+
96+
if (!heftPluginPackageFolder) {
9397
// This should never happen
9498
throw new InternalError('Unable to find the @rushstack/heft package folder');
9599
}
96-
return pluginPackageFolder;
100+
101+
return heftPluginPackageFolder;
97102
} else {
98103
const configurationFileDirectory: string = path.dirname(configurationFilePath);
99104
return Import.resolvePackage({

build-tests/heft-sass-test/config/heft.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,23 @@
1010
"cleanFiles": [{ "includeGlobs": ["dist", "lib", "lib-commonjs", "temp"] }],
1111

1212
"tasksByName": {
13+
"set-browserslist-ignore-old-data-env-var": {
14+
"taskPlugin": {
15+
"pluginPackage": "@rushstack/heft",
16+
"pluginName": "set-environment-variables-plugin",
17+
"options": {
18+
"environmentVariablesToSet": {
19+
// Suppress the "Browserslist: caniuse-lite is outdated" warning. Although the warning is
20+
// potentially useful, the check is performed in a way that is nondeterministic and can cause
21+
// Rush pipelines to fail. Moreover, the outdated version is often irrelevant and/or nontrivial
22+
// to upgrade. See this thread for details: https://github.com/microsoft/rushstack/issues/2981
23+
"BROWSERSLIST_IGNORE_OLD_DATA": "1"
24+
}
25+
}
26+
}
27+
},
1328
"sass": {
29+
"taskDependencies": ["set-browserslist-ignore-old-data-env-var"],
1430
"taskPlugin": {
1531
"pluginPackage": "@rushstack/heft-sass-plugin"
1632
}

build-tests/install-test-workspace/workspace/common/pnpm-lock.yaml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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-web-rig",
5+
"comment": "Include the `set-environment-variables-plugin` plugin from the `@rushstack/heft` package to set the `BROWSERSLIST_IGNORE_OLD_DATA` environment variable to `1` to suppress the warning printed when the `browserslist` package decides it's out of date.",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@rushstack/heft-web-rig"
10+
}

0 commit comments

Comments
 (0)