Skip to content

Commit cf97433

Browse files
committed
Make the plugin a task plugin.
1 parent 15f4a4c commit cf97433

File tree

9 files changed

+71
-115
lines changed

9 files changed

+71
-115
lines changed

apps/heft/heft-plugin.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
{
22
"$schema": "https://developer.microsoft.com/json-schemas/heft/v0/heft-plugin.schema.json",
33

4-
"lifecyclePlugins": [
5-
{
6-
"entryPoint": "./lib/plugins/SetEnvironmentVariablesPlugin",
7-
"pluginName": "set-environment-variables-plugin",
8-
"optionsSchema": "./lib/schemas/set-environment-variables-plugin.schema.json"
9-
}
10-
],
4+
"lifecyclePlugins": [],
115

126
"taskPlugins": [
137
{
@@ -36,6 +30,11 @@
3630
"pluginName": "run-script-plugin",
3731
"entryPoint": "./lib/plugins/RunScriptPlugin",
3832
"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"
3938
}
4039
]
4140
}

apps/heft/src/plugins/SetEnvironmentVariablesPlugin.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// See LICENSE in the project root for license information.
33

44
import type { HeftConfiguration } from '../configuration/HeftConfiguration';
5-
import type { IHeftLifecycleSession } from '../pluginFramework/HeftLifecycleSession';
6-
import type { IHeftLifecyclePlugin } from '../pluginFramework/IHeftPlugin';
5+
import type { IHeftTaskSession } from '../pluginFramework/HeftTaskSession';
6+
import type { IHeftTaskPlugin } from '../pluginFramework/IHeftPlugin';
77

88
export const PLUGIN_NAME: string = 'set-environment-variables-plugin';
99

@@ -12,21 +12,21 @@ export interface ISetEnvironmentVariablesPluginOptions {
1212
}
1313

1414
export default class SetEnvironmentVariablesPlugin
15-
implements IHeftLifecyclePlugin<ISetEnvironmentVariablesPluginOptions>
15+
implements IHeftTaskPlugin<ISetEnvironmentVariablesPluginOptions>
1616
{
1717
public apply(
18-
lifecycleSession: IHeftLifecycleSession,
18+
taskSession: IHeftTaskSession,
1919
heftConfiguration: HeftConfiguration,
2020
{ environmentVariablesToSet }: ISetEnvironmentVariablesPluginOptions
2121
): void {
22-
lifecycleSession.hooks.toolStart.tap(
22+
taskSession.hooks.run.tap(
2323
{
2424
name: PLUGIN_NAME,
2525
stage: Number.MIN_SAFE_INTEGER
2626
},
2727
() => {
2828
for (const [key, value] of Object.entries(environmentVariablesToSet)) {
29-
lifecycleSession.logger.terminal.writeLine(`Setting environment variable ${key}=${value}`);
29+
taskSession.logger.terminal.writeLine(`Setting environment variable ${key}=${value}`);
3030
process.env[key] = value;
3131
}
3232
}

apps/heft/src/utilities/CoreConfigFiles.ts

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ import type { IRigConfig } from '@rushstack/rig-package';
1515
import type { IDeleteOperation } from '../plugins/DeleteFilesPlugin';
1616
import type { INodeServicePluginConfiguration } from '../plugins/NodeServicePlugin';
1717
import { Constants } from './Constants';
18-
import {
19-
type ISetEnvironmentVariablesPluginOptions,
20-
PLUGIN_NAME as setEnvVarsPluginName
21-
} from '../plugins/SetEnvironmentVariablesPlugin';
2218

2319
export interface IHeftConfigurationJsonActionReference {
2420
actionName: string;
@@ -81,12 +77,7 @@ export class CoreConfigFiles {
8177
rigConfig?: IRigConfig | undefined
8278
): Promise<IHeftConfigurationJson> {
8379
if (!CoreConfigFiles._heftConfigFileLoader) {
84-
const heftPluginPackageFolder: string | undefined =
85-
PackageJsonLookup.instance.tryGetPackageFolderFor(__dirname);
86-
if (!heftPluginPackageFolder) {
87-
// This should never happen
88-
throw new InternalError('Unable to find the @rushstack/heft package folder');
89-
}
80+
let heftPluginPackageFolder: string | undefined;
9081

9182
const pluginPackageResolver: (
9283
options: IJsonPathMetadataResolverOptions<IHeftConfigurationJson>
@@ -98,6 +89,15 @@ export class CoreConfigFiles {
9889
// between the project and the globally installed Heft. Use the PackageJsonLookup
9990
// class to find the package folder to avoid hardcoding the path for compatibility
10091
// with bundling.
92+
if (!heftPluginPackageFolder) {
93+
heftPluginPackageFolder = PackageJsonLookup.instance.tryGetPackageFolderFor(__dirname);
94+
}
95+
96+
if (!heftPluginPackageFolder) {
97+
// This should never happen
98+
throw new InternalError('Unable to find the @rushstack/heft package folder');
99+
}
100+
101101
return heftPluginPackageFolder;
102102
} else {
103103
const configurationFileDirectory: string = path.dirname(configurationFilePath);
@@ -117,42 +117,6 @@ export class CoreConfigFiles {
117117
array: { inheritanceType: InheritanceType.append },
118118
object: { inheritanceType: InheritanceType.merge }
119119
},
120-
propertyInheritance: {
121-
heftPlugins: {
122-
inheritanceType: InheritanceType.custom,
123-
inheritanceFunction: (current, parent) => {
124-
if (!current) {
125-
return parent;
126-
} else if (!parent) {
127-
return current;
128-
} else {
129-
// Special-case the "set-environment-variables-plugin" to merge the environment variables
130-
// that are being set instead of including two copies of the plugin when there are multiple
131-
// config files in the extends chain that reference the plugin.
132-
let mergedEnvironmentVariablesToSet: Record<string, string> | undefined;
133-
function processLifecyclePlugins(pluginList: IHeftConfigurationJsonPluginSpecifier[]): void {
134-
for (let i: number = 0; i < pluginList.length; i++) {
135-
const lifecyclePlugin: IHeftConfigurationJsonPluginSpecifier = pluginList[i];
136-
const { pluginName, pluginPackage, options } = lifecyclePlugin;
137-
if (pluginName === setEnvVarsPluginName && pluginPackage === heftPluginPackageFolder) {
138-
const { environmentVariablesToSet } = options as ISetEnvironmentVariablesPluginOptions;
139-
if (!mergedEnvironmentVariablesToSet) {
140-
mergedEnvironmentVariablesToSet = environmentVariablesToSet;
141-
} else {
142-
Object.assign(mergedEnvironmentVariablesToSet, environmentVariablesToSet);
143-
pluginList.splice(i, 1);
144-
i--;
145-
}
146-
}
147-
}
148-
}
149-
processLifecyclePlugins(parent);
150-
processLifecyclePlugins(current);
151-
return [...parent, ...current];
152-
}
153-
}
154-
}
155-
},
156120
jsonPathMetadata: {
157121
// Use a custom resolver for the plugin packages, since the NodeResolve algorithm will resolve to the
158122
// package.json exports/module property, which may or may not exist.

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
{
55
"$schema": "https://developer.microsoft.com/json-schemas/heft/v0/heft.schema.json",
66

7-
"heftPlugins": [
8-
{
9-
"pluginPackage": "@rushstack/heft",
10-
"pluginName": "set-environment-variables-plugin",
11-
"options": {
12-
"environmentVariablesToSet": {
13-
"BROWSERSLIST_IGNORE_OLD_DATA": "1"
14-
}
15-
}
16-
}
17-
],
18-
197
// TODO: Add comments
208
"phasesByName": {
219
"build": {
2210
"cleanFiles": [{ "includeGlobs": ["dist", "lib", "lib-commonjs", "temp"] }],
2311

2412
"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+
"BROWSERSLIST_IGNORE_OLD_DATA": "1"
20+
}
21+
}
22+
}
23+
},
2524
"sass": {
25+
"taskDependencies": ["set-browserslist-ignore-old-data-env-var"],
2626
"taskPlugin": {
2727
"pluginPackage": "@rushstack/heft-sass-plugin"
2828
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"_phase:test": "heft run --only test -- --clean"
1111
},
1212
"devDependencies": {
13+
"local-eslint-config": "workspace:*",
1314
"@rushstack/heft-jest-plugin": "workspace:*",
1415
"@rushstack/heft-lint-plugin": "workspace:*",
1516
"@rushstack/heft-sass-plugin": "workspace:*",
@@ -25,7 +26,6 @@
2526
"css-loader": "~5.2.7",
2627
"eslint": "~8.7.0",
2728
"html-webpack-plugin": "~4.5.2",
28-
"local-eslint-config": "workspace:*",
2929
"postcss-loader": "~4.1.0",
3030
"postcss": "~8.4.6",
3131
"react-dom": "~17.0.2",

build-tests/heft-web-rig-library-test/config/heft.json

Lines changed: 0 additions & 17 deletions
This file was deleted.
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",
5+
"comment": "Add a built-in `set-environment-variables-plugin` task plugin to set environment variables.",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@rushstack/heft"
10+
}

rigs/heft-web-rig/profiles/app/config/heft.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@
1717
}
1818
},
1919

20-
"heftPlugins": [
21-
{
22-
"pluginPackage": "@rushstack/heft",
23-
"pluginName": "set-environment-variables-plugin",
24-
"options": {
25-
"environmentVariablesToSet": {
26-
"BROWSERSLIST_IGNORE_OLD_DATA": "1"
27-
}
28-
}
29-
}
30-
],
31-
3220
"phasesByName": {
3321
"build": {
3422
"cleanFiles": [{ "includeGlobs": ["dist", "lib", "lib-amd", "lib-commonjs", "lib-es6"] }],
3523

3624
"tasksByName": {
25+
"set-browserslist-ignore-old-data-env-var": {
26+
"taskPlugin": {
27+
"pluginPackage": "@rushstack/heft",
28+
"pluginName": "set-environment-variables-plugin",
29+
"options": {
30+
"environmentVariablesToSet": {
31+
"BROWSERSLIST_IGNORE_OLD_DATA": "1"
32+
}
33+
}
34+
}
35+
},
3736
"sass": {
37+
"taskDependencies": ["set-browserslist-ignore-old-data-env-var"],
3838
"taskPlugin": {
3939
"pluginPackage": "@rushstack/heft-sass-plugin"
4040
}

rigs/heft-web-rig/profiles/library/config/heft.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,30 @@
1717
}
1818
},
1919

20-
"heftPlugins": [
21-
{
22-
"pluginPackage": "@rushstack/heft",
23-
"pluginName": "set-environment-variables-plugin",
24-
"options": {
25-
"environmentVariablesToSet": {
26-
"BROWSERSLIST_IGNORE_OLD_DATA": "1"
27-
}
28-
}
29-
}
30-
],
31-
3220
"phasesByName": {
3321
"build": {
3422
"cleanFiles": [{ "includeGlobs": ["dist", "lib", "lib-amd", "lib-commonjs", "lib-es6"] }],
3523

3624
"tasksByName": {
37-
"sass-typings": {
25+
"set-browserslist-ignore-old-data-env-var": {
26+
"taskPlugin": {
27+
"pluginPackage": "@rushstack/heft",
28+
"pluginName": "set-environment-variables-plugin",
29+
"options": {
30+
"environmentVariablesToSet": {
31+
"BROWSERSLIST_IGNORE_OLD_DATA": "1"
32+
}
33+
}
34+
}
35+
},
36+
"sass": {
37+
"taskDependencies": ["set-browserslist-ignore-old-data-env-var"],
3838
"taskPlugin": {
3939
"pluginPackage": "@rushstack/heft-sass-plugin"
4040
}
4141
},
4242
"typescript": {
43-
"taskDependencies": ["sass-typings"],
43+
"taskDependencies": ["sass"],
4444
"taskPlugin": {
4545
"pluginPackage": "@rushstack/heft-typescript-plugin"
4646
}

0 commit comments

Comments
 (0)