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

fix(add-caching): explicitly set targetDefaults for all scripts #3929

Merged
merged 9 commits into from
Jan 4, 2024

Conversation

fahslaj
Copy link
Contributor

@fahslaj fahslaj commented Jan 3, 2024

Description

  • Explicitly sets targetDefaults for all scripts, not just those selected in the prompts.
  • Updates how cacheable targets are configured to align with Nx 17 expectations.

Motivation and Context

This allows lerna run to correctly identify when the user has configured Nx via lerna add-caching, even if they didn't select any scripts to run in order. This also fixes add-caching for Nx 17.

How Has This Been Tested?

This has been tested manually on a fresh workspace.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (change that has absolutely no effect on users)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows inquirer to pre-select all targets that already have dependsOn configured

image

@@ -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,
Copy link
Contributor Author

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

Comment on lines -119 to -130
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"
);
}
Copy link
Contributor Author

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.

@fahslaj fahslaj marked this pull request as ready for review January 3, 2024 22:16
"options": {
"cacheableOperations": ["build", "test"]
}
"runner": "nx/tasks-runners/default"
Copy link
Member

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"],
Copy link
Member

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

Copy link
Contributor Author

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": [],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same again, outdated

Copy link
Contributor Author

@fahslaj fahslaj Jan 4, 2024

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.

Copy link
Member

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

@fahslaj
Copy link
Contributor Author

fahslaj commented Jan 4, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants