Phillip9587 / nx-stylelint

Nx plugin to use Stylelint in your Nx workspace.
MIT License
84 stars 15 forks source link

Nx 18 Inferred Tasks support #635

Closed Phillip9587 closed 3 weeks ago

Phillip9587 commented 9 months ago

Support Nx Project Crystal / Inferred Tasks

Phillip9587 commented 7 months ago

v18.0.0-beta.3 provides support for Nx 18 Inferred Tasks

Please test it out and provide feedback.

To add the plugin add the following to your nx.json:

{
    "plugins": [
        {
            "plugin": "nx-stylelint/plugin",
            "options": {
                "targetName": "stylelint",
                "extensions": ["css"]
            }
        }
    ]
}

targetDefaults can be configured e.g. --allow-empty-input:

"targetDefaults": {
    "stylelint": {
        "options": {
            "args": ["--allow-empty-input"]
        }
    }
}
mateusgpereira commented 5 months ago

I add the plugin to the nx.json file:

{
   "plugin": "nx-stylelint/plugin",
    "options": {
        "targetName": "stylelint",
        "extensions": ["scss"]
    }
 }

I'm also using this on targetDefaults:

"targetDefaults": {
  "stylelint": {
    "inputs": [
      "default",
      "{workspaceRoot}/.stylelintrc(.(json|yml|yaml|js))?"
    ],
    "cache": true,
    "options": {
      "args": [
        "--allow-empty-input"
      ]
    }
  }
}

With this setup I can see the task being inferred in nx console with this description:
Created by nx/core/target-defaults from nx.json
but only for the libraries that have their own .stylelintrc file.
It would be nice to have this task inferred independently of the lib having or not its own configuration file and using the rules defined at the workspaceRoot level.

Great job with this plugin guys ^^

Phillip9587 commented 5 months ago

@mateusgpereira Thanks for trying out the plugin.

I'm also using this on targetDefaults:

"targetDefaults": {
  "stylelint": {
    "inputs": [
      "default",
      "{workspaceRoot}/.stylelintrc(.(json|yml|yaml|js))?"
    ],
    "cache": true,
    "options": {
      "args": [
        "--allow-empty-input"
      ]
    }
  }
}

You can remove the inputs here. The Inputs are infered by the plugin.

With this setup I can see the task being inferred in nx console with this description: Created by nx/core/target-defaults from nx.json but only for the libraries that have their own .stylelintrc file. It would be nice to have this task inferred independently of the lib having or not its own configuration file and using the rules defined at the workspaceRoot level.

First, remove the stylelint targets from your project.json files. It looks like there is a stylelint target with the nx-stylelint:lint executor left. The stylelint target has to be infered from nx-stylelint/plugin.

The libraries need a .stylelintrc file to identify them as projects that need Stylelint setup. However, you can add a simple .stylelintrc.json to your project root that extends the workspace root .stylelintrc file:

{
    "extends": "../path/to/workspaceroot/.stylelintrc.json"
}
Phillip9587 commented 3 weeks ago

nx-stylelint v18 includes the experimental plugin. The generators do not support adding the plugin yet but it is planned once Nx exports the needed helpers from @nx/devkit. Please test it out and provide feedback.