-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix(add-caching): explicitly set targetDefaults for all scripts #3929
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
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 742ce93. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 8 targets
Sent with 💌 from NxCloud. |
const { targetDefaults } = await inquirer.prompt<{ targetDefaults: UserAnswers["targetDefaults"] }>([ | ||
{ | ||
type: "checkbox", | ||
name: "targetDefaults", | ||
message: | ||
"Which scripts need to be run in order? (e.g. before building a project, dependent projects must be built.)\n", | ||
choices: this.uniqueScriptNames, | ||
default: existingTargetDefaults, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -74,13 +90,13 @@ class AddCachingCommand extends Command { | |||
message: | |||
"Which scripts are cacheable? (Produce the same output given the same input, e.g. build, test and lint usually are, serve and start are not.)\n", | |||
choices: this.uniqueScriptNames, | |||
default: existingCacheableOperations, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above; this allows inquirer to pre-select all targets that have "cache": true
already configured
nxJson.tasksRunnerOptions = nxJson.tasksRunnerOptions || {}; | ||
nxJson.tasksRunnerOptions["default"] = nxJson.tasksRunnerOptions["default"] || {}; | ||
nxJson.tasksRunnerOptions["default"].runner = | ||
nxJson.tasksRunnerOptions["default"].runner || "nx/tasks-runners/default"; | ||
nxJson.tasksRunnerOptions["default"].options = nxJson.tasksRunnerOptions["default"].options || {}; | ||
|
||
if (nxJson.tasksRunnerOptions["default"].options.cacheableOperations) { | ||
this.logger.warn( | ||
"add-caching", | ||
"The `tasksRunnerOptions.default.cacheableOperations` property already exists in `nx.json` and will be overwritten by your answers" | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the default task runner seems like excess config. Nx should default this for us when this is missing.
The meaningful removal here is of cacheableOperations
, which moved to targetDefaults
.
"options": { | ||
"cacheableOperations": ["build", "test"] | ||
} | ||
"runner": "nx/tasks-runners/default" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn’t we remove this here too for simplicity?
@@ -199,7 +199,6 @@ option for the task runner in `nx.json`: | |||
"tasksRunnerOptions": { | |||
"default": { | |||
"options": { | |||
"cacheableOperations": ["build", "test"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole config is outdated too, cache directory is set at the top level, no needs for the object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed this whole section. We're pretty clear that it's Nx doing the caching in the docs and users can find the Nx docs if they need to do advanced things like changing the cache location.
I think we should minimize the amount Nx-specific docs on the Lerna site as they will get out of date quickly.
@@ -32,7 +32,6 @@ Note, you can also change the default in `nx.json`, like this: | |||
"default": { | |||
"runner": "nx/tasks-runners/default", | |||
"options": { | |||
"cacheableOperations": [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same again, outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. Same idea as the above comment; I removed the whole section to minimize the doc's coupling to Nx configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments
@JamesHenry I've updated the docs you've pointed out. I removed a couple of the outdated sections instead of just updating their config. To reduce the maintenance burden, I think we should keep the more advanced Nx configuration options to the Nx docs and link to the Nx site instead of duplicating them in the Lerna docs. |
Description
targetDefaults
for all scripts, not just those selected in the prompts.Motivation and Context
This allows
lerna run
to correctly identify when the user has configured Nx vialerna add-caching
, even if they didn't select any scripts to run in order. This also fixesadd-caching
for Nx 17.How Has This Been Tested?
This has been tested manually on a fresh workspace.
Types of changes
Checklist: