-
Notifications
You must be signed in to change notification settings - Fork 587
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] Pass original cwd into custom commands #1247
Comments
Instead Rush should provide a well-defined set of environment variables that get passed to commands as a contract. I recall issue #1223 was proposing something similar for the event hooks. These environment variables are already supported when invoking Rush: export const enum EnvironmentVariableNames {
/**
* This variable overrides the temporary folder used by Rush.
* The default value is "common/temp" under the repository root.
*/
RUSH_TEMP_FOLDER = 'RUSH_TEMP_FOLDER',
/**
* This variable overrides the version of Rush that will be installed by
* the version selector. The default value is determined by the "rushVersion"
* field from rush.json.
*/
RUSH_PREVIEW_VERSION = 'RUSH_PREVIEW_VERSION',
/**
* This variable selects a specific installation variant for Rush to use when installing
* and linking package dependencies. For more information, see this article:
* https://rushjs.io/pages/advanced/installation_variants/
*/
RUSH_VARIANT = 'RUSH_VARIANT',
/**
* If this variable is set to "true", Rush will create symlinks with absolute paths instead
* of relative paths. This can be necessary when a repository is moved during a build or
* if parts of a repository are moved into a sandbox.
*/
RUSH_ABSOLUTE_SYMLINKS = 'RUSH_ABSOLUTE_SYMLINKS'
} I'm thinking there should be a different prefix for parameters passed when invoking a custom command. Perhaps something like And then for the hook parameter, maybe it would be That way we have separate namespaces to clearly indicate the scopes where the particular variable apply. |
Ah, cool, didn't know those other variables existed. My initial thought was to use the |
One of the things I really like about rush is that it's required to be installed globally, and whenever a command is run, it walks up the directory tree looking for rush configuration, allowing for a common cli throughout all directories of the monorepo. This breaks down, however, when trying to use custom scripts from an individual project directory.
Problem
I have a global
lint
script that, when executed from the monorepo root, will lint all projects in the repo, and when executed from an individual project, will only lint that project. The problem isn't the command getting invoked from the subdirectory, that works fine, the problem is that my script has no reference to the cwd it was invoked from (process.cwd()
at script runtime is just the monorepo root).The problem is illustrated by this repro repo.
Proposed Solution
I'm not proposing for the cwd to be changed; I'm instead proposing to invoke the script with an
INVOKED_CWD
environment variable. It's a backwards-compatible, opt-in change, and being an environment variable, automatically works with any type ofshellCommand
being used.I'm not very familiar with this repo, but from what I can tell, it looks like this change would require something like:
invokedCwd
property to ILifecycleCommandOptionsinvokedCwd
into environment in _executeLifecycleCommandInternalAlternate solution
I'm not entirely sure what purpose the
initCwd
env variable is currently serving, but it could possibly be repurposed to hold this new value in theINIT_CWD
variable instead. The change would be slightly simpler:initCwd
value toprocess.cwd()
in GlobalScriptAction.runWilling to send a PR if it'll speed up the implementation of this feature!
The text was updated successfully, but these errors were encountered: