Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rush] Add hooks for pre and post rushx events #4286

Merged
merged 32 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bbba972
adding pre and post rushx events
nebosite Aug 18, 2023
bfff506
Adding Pro and Post event hooks to rushx
nebosite Aug 23, 2023
6d29a0e
Move exitcode handling out of _lauchRushXInternal
nebosite Sep 7, 2023
406fb69
Whoops accidentally checked in test code
nebosite Sep 7, 2023
d936b16
Special handling for process errors
nebosite Sep 7, 2023
8050af6
Quote unknown arguments
nebosite Sep 7, 2023
454e113
Rename INSIDERUSH to _RUSH_SUPPRESS_HOOKS
nebosite Sep 7, 2023
9517be9
Add debug parameter to rushx so it can be passed to hooks
nebosite Sep 7, 2023
39d1011
Don't print hook suppressed messages on recursive calls
nebosite Sep 8, 2023
f8a0be2
Add --ignorehooks and fix bug in hook runner
nebosite Sep 8, 2023
657eb84
Don't try to run hooks on --help
nebosite Sep 8, 2023
3ba9901
responding to code reviews
nebosite Oct 3, 2023
738b55f
Rush change
nebosite Oct 3, 2023
327fbe4
Merge remote-tracking branch 'remotes/origin/main' into neboste/rushx…
octogonz Oct 4, 2023
3815b1a
Fix some build warnings
octogonz Oct 4, 2023
c89d1dc
Fix a test failure (but I have some questions about this variable, se…
octogonz Oct 4, 2023
a93c500
Add more detail to change file
octogonz Oct 4, 2023
3d406c6
Document event hooks in rush.json template
octogonz Oct 4, 2023
ff5d1b9
Rename RUSH_SUPPRESS_HOOKS to _RUSH_SUPPRESS_RUSHX_HOOKS (because it …
octogonz Oct 4, 2023
914ab21
Rename EnvironmentVariableNames.RUSH_LIB_PATH to _RUSH_LIB_PATH to ma…
octogonz Oct 5, 2023
aaee1f2
Remove "-i" parameter per PR discussion
octogonz Oct 5, 2023
3065543
Refactor arguments to _launchRushXInternal
nebosite Oct 5, 2023
b7f94fd
Refactor environment variable name for hook suppression
nebosite Oct 5, 2023
ee01b51
Handle rushx hook errors as benign
nebosite Oct 5, 2023
710af8a
rolling back accidental change to rush and rushx scripts
nebosite Oct 5, 2023
2bd1390
Add environment var _RUSH_ORIGINAL_ARGS
nebosite Oct 5, 2023
5618ca8
Rename _RUSH_ORIGINAL_ARGS to a public environment variable RUSH_INVO…
octogonz Oct 5, 2023
6da0cf6
RUSH_INVOKED_ARGS should only be assigned when invoking hook scripts …
octogonz Oct 6, 2023
125f25c
putting back alreadyReportedNodeTooNewError
nebosite Oct 6, 2023
04c723d
rolling back accidental change to rush and rushx scripts
nebosite Oct 6, 2023
9236fac
Merge branch 'neboste/rushx_hooks' of github.com:nebosite/rushstack i…
nebosite Oct 6, 2023
00d2c19
make _launchRushXInternal private
nebosite Oct 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/rush/CHANGELOG.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@
"comments": {
"none": [
{
"comment": "Add code path to @rushstack/rush-sdk for inheriting @microsoft/rush-lib location from a parent process via the RUSH_LIB_PATH environment variable."
"comment": "Add code path to @rushstack/rush-sdk for inheriting @microsoft/rush-lib location from a parent process via the _RUSH_LIB_PATH environment variable."
}
]
}
Expand Down
14 changes: 7 additions & 7 deletions apps/rush/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ Fri, 17 Feb 2023 02:14:43 GMT

### Updates

- Add code path to @rushstack/rush-sdk for inheriting @microsoft/rush-lib location from a parent process via the RUSH_LIB_PATH environment variable.
- Add code path to @rushstack/rush-sdk for inheriting @microsoft/rush-lib location from a parent process via the _RUSH_LIB_PATH environment variable.

## 5.92.0
Sun, 12 Feb 2023 02:50:42 GMT
Expand Down Expand Up @@ -553,7 +553,7 @@ Sat, 06 Aug 2022 05:35:19 GMT
### Updates

- Validate that if shouldPublish is set, private is not set
- "rush install/update" should always set "ignore-compatibility-db=true" and print warning if the rush.json pnpmVersion specifies a version affected by this problem.
- "rush install/update" should always set "ignore-compatibility-db=true" and print warning if the rush.json pnpmVersion specifies a version affected by this problem.
- Reorder some initialization logic so that Rush's change analysis is not counted as part of the build time for the first project
- (BREAKING API CHANGE) Rename cyclicDependencyProjects to decoupledLocalDependencies

Expand Down Expand Up @@ -1878,7 +1878,7 @@ Thu, 11 Jul 2019 22:00:50 GMT

### Updates

- Fix for issue https://github.com/microsoft/web-build-tools/issues/1349 rush install fails when there is a preferred version with a peer dependency. This was caused by file format changes in pnpm 3.x
- Fix for issue https://github.com/microsoft/web-build-tools/issues/1349 rush install fails when there is a preferred version with a peer dependency. This was caused by file format changes in pnpm 3.x
- Fix an issue where "rush add" erroneously believes ensureConsistentVersions is unset.
- Fix an issue that arises when "rush add" is run and the package manager isn't installed.
- Fix an issue where rush add -m doesn't corretly update the common-versions.json file.
Expand Down Expand Up @@ -2360,9 +2360,9 @@ Fri, 06 Oct 2017 22:44:31 GMT
### Patches

- Enable strickNullChecks
- Fix a bug in "rush version" that devdependency does not get bumped if there is no dependency.
- Fix a bug in "rush change" so it handles rename properly.
- Add npm tag support in "rush publish".
- Fix a bug in "rush version" that devdependency does not get bumped if there is no dependency.
- Fix a bug in "rush change" so it handles rename properly.
- Add npm tag support in "rush publish".

## 3.0.18
Tue, 26 Sep 2017 13:51:05 GMT
Expand Down Expand Up @@ -2617,7 +2617,7 @@ Sun, 22 Jan 2017 02:04:57 GMT

### Patches

- Update temp_modules when versions are bumped.
- Update temp_modules when versions are bumped.

## 1.4.1
Tue, 03 Jan 2017 21:52:49 GMT
Expand Down
2 changes: 1 addition & 1 deletion apps/rush/bin/rush
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require('../lib/start.js')
require('../lib/start.js');
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Add start `preRushx` and `postRushx` event hooks for monitoring the `rushx` command",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
8 changes: 6 additions & 2 deletions common/reviews/api/rush-lib.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,20 @@ export const EnvironmentVariableNames: {
readonly RUSH_COBUILD_LEAF_PROJECT_LOG_ONLY_ALLOWED: "RUSH_COBUILD_LEAF_PROJECT_LOG_ONLY_ALLOWED";
readonly RUSH_GIT_BINARY_PATH: "RUSH_GIT_BINARY_PATH";
readonly RUSH_TAR_BINARY_PATH: "RUSH_TAR_BINARY_PATH";
readonly RUSH_LIB_PATH: "_RUSH_LIB_PATH";
readonly _RUSH_RECURSIVE_RUSHX_CALL: "_RUSH_RECURSIVE_RUSHX_CALL";
readonly _RUSH_LIB_PATH: "_RUSH_LIB_PATH";
readonly RUSH_INVOKED_FOLDER: "RUSH_INVOKED_FOLDER";
readonly RUSH_INVOKED_ARGS: "RUSH_INVOKED_ARGS";
};

// @beta
enum Event_2 {
postRushBuild = 4,
postRushInstall = 2,
postRushx = 6,
preRushBuild = 3,
preRushInstall = 1
preRushInstall = 1,
preRushx = 5
}
export { Event_2 as Event }

Expand Down
20 changes: 15 additions & 5 deletions libraries/rush-lib/assets/rush-init/rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,26 +247,36 @@
*/
"eventHooks": {
/**
* The list of shell commands to run before the Rush installation starts
* A list of shell commands to run before "rush install" or "rush update" starts installation
*/
"preRushInstall": [
/*[LINE "HYPOTHETICAL"]*/ "common/scripts/pre-rush-install.js"
],

/**
* The list of shell commands to run after the Rush installation finishes
* A list of shell commands to run after "rush install" or "rush update" finishes installation
*/
"postRushInstall": [],

/**
* The list of shell commands to run before the Rush build command starts
* A list of shell commands to run before "rush build" or "rush rebuild" starts building
*/
"preRushBuild": [],

/**
* The list of shell commands to run after the Rush build command finishes
* A list of shell commands to run after "rush build" or "rush rebuild" finishes building
*/
"postRushBuild": []
"postRushBuild": [],

/**
* A list of shell commands to run before the "rushx" command starts
*/
"preRushX": [],

/**
* A list of shell commands to run after the "rushx" command finishes
*/
"postRushX": []
},

/**
Expand Down
28 changes: 25 additions & 3 deletions libraries/rush-lib/src/api/EnvironmentConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,17 @@ export const EnvironmentVariableNames = {
*/
RUSH_TAR_BINARY_PATH: 'RUSH_TAR_BINARY_PATH',

/**
* Internal variable used by `rushx` when recursively invoking another `rushx` process, to avoid
* nesting event hooks.
*/
_RUSH_RECURSIVE_RUSHX_CALL: '_RUSH_RECURSIVE_RUSHX_CALL',

/**
* Internal variable that explicitly specifies the path for the version of `@microsoft/rush-lib` being executed.
* Will be set upon loading Rush.
*/
RUSH_LIB_PATH: '_RUSH_LIB_PATH',
_RUSH_LIB_PATH: '_RUSH_LIB_PATH',

/**
* When Rush executes shell scripts, it sometimes changes the working directory to be a project folder or
Expand All @@ -199,7 +205,18 @@ export const EnvironmentVariableNames = {
* The `RUSH_INVOKED_FOLDER` variable is the same idea as the `INIT_CWD` variable that package managers
* assign when they execute lifecycle scripts.
*/
RUSH_INVOKED_FOLDER: 'RUSH_INVOKED_FOLDER'
RUSH_INVOKED_FOLDER: 'RUSH_INVOKED_FOLDER',

/**
* When running a hook script, this environment variable communicates the original arguments
* passed to the `rush` or `rushx` command.
*
* @remarks
* Unlike `RUSH_INVOKED_FOLDER`, the `RUSH_INVOKED_ARGS` variable is only available for hook scripts.
* Other lifecycle scripts should not make assumptions about Rush's command line syntax
* if Rush did not explicitly pass along command-line parameters to their process.
*/
RUSH_INVOKED_ARGS: 'RUSH_INVOKED_ARGS'
} as const;

/**
Expand Down Expand Up @@ -530,10 +547,15 @@ export class EnvironmentConfiguration {
break;

case EnvironmentVariableNames.RUSH_INVOKED_FOLDER:
case EnvironmentVariableNames.RUSH_LIB_PATH:
case EnvironmentVariableNames.RUSH_INVOKED_ARGS:
case EnvironmentVariableNames._RUSH_LIB_PATH:
// Assigned by Rush itself
break;

case EnvironmentVariableNames._RUSH_RECURSIVE_RUSHX_CALL:
// Assigned/read internally by RushXCommandLine
break;

default:
unknownEnvVariables.push(envVarName);
break;
Expand Down
10 changes: 9 additions & 1 deletion libraries/rush-lib/src/api/EventHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ export enum Event {
/**
* Post Rush build event
*/
postRushBuild = 4
postRushBuild = 4,
/**
* Start of rushx execution event
*/
preRushx = 5,
/**
* End of rushx execution event
*/
postRushx = 6
}

/**
Expand Down
2 changes: 1 addition & 1 deletion libraries/rush-lib/src/api/Rush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class Rush {
options = Rush._normalizeLaunchOptions(options);

Rush._assignRushInvokedFolder();
RushXCommandLine._launchRushXInternal(launcherVersion, { ...options });
RushXCommandLine.launchRushX(options.isManaged, options.alreadyReportedNodeTooNewError);
}

/**
Expand Down
Loading
Loading