Package Exports
- @nx-dart/nx-dart
- @nx-dart/nx-dart/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@nx-dart/nx-dart) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
nx-dart is a Nx plugin, that adds support for developing Dart and Flutter
packages in a Nx workspace.
This plugin is at an early stage of development. Please open an issue if you find a bug or have a feature request. Feel free to open a discussion, if you have a question.
Features
- Surface dependencies between packages to the Nx project graph.
- Executors:
- format
- analyze
- test
- Generators:
- add-package
- change-lints
Getting started
Create a new Nx workspace with the nx-dart preset
Run the following command to create a new Nx workspace including nx-dart:
npx create-nx-workspace <workspace-name> --preset=@nx-dart/nx-dartAdd Nx and nx-dart to an existing monorepo
In an existing monorepo, run the following command to add Nx and nx-dart:
npx add-nx-dart-to-monorepoNx projects and Dart packages
Every package that should be part of the Nx workspace needs to have a
project.json file in the package root and needs to be registered in the
workspace.json file at the root of the workspace.
The add-package generator takes care of creating an initial project.json
file and registering the project in workspace.json, under the package's name.
If package B depends on package A and both live in the same workspace, the Nx project graph will reflect this dependency. Dependencies on local packages are not automatically overridden with path dependency for development, though. If this is something you need, implement your own mechanism for overriding dependencies or check out Melos.
Melos is a Dart/Flutter specific monorepo tool with support for conventional commit based versioning and publishing, among other features. Melos and Nx complement each other, and can be used together.
Generators
add-package
Adds an existing Dart package to the workspace.
This generator is usually used to integrate a package into the Nx workspace
after creating it with dart create or flutter create:
flutter create -t app apps/counter
npx nx generate @nx-dart/nx-dart:add-package apps/counterOptions
--project-type: The Nx project type of the package. This is optional. If not specified, the project type is inferred.
change-lints
Changes the lint rules in the workspace analysis options.
Lint rules are defined in the analysis_options.yaml file at the project root.
These options apply to all packages in the workspace, that don't have a
analysis_options.yaml file of their own.
This generator changes the lint rules to one of the following:
core: Core rules from thelintspackage.recommended: Recommended rules from thelintspackage.flutter: Rules from theflutter_lintspackage.all: All available lint rules. Requires resolving conflicting rules.
npx nx generator @nx-dart/nx-dart:change-lints flutterExecutors
format
Formats Dart files in a package.
// libs/foo/project.json
{
"targets": {
"format": {
"executor": "@nx-dart/nx-dart:format",
"outputs": []
}
}
}Options
check: Whether to validate the current formatting instead of fixing it. Default isfalse.
analyze
Analyzes a Dart package.
// libs/foo/project.json
{
"targets": {
"analyze": {
"executor": "@nx-dart/nx-dart:analyze",
"outputs": []
}
}
}Options
fatalInfos: Treat info level issues as fatal. Default istrue.fatalWarnings: Treat warning level issues as fatal. Default istrue.
test
Runs Dart or Flutter tests in a package.
// libs/foo/project.json
{
"targets": {
"test": {
"executor": "@nx-dart/nx-dart:test",
"outputs": ["libs/foo/coverage"]
},
"e2e": {
"executor": "@nx-dart/nx-dart:test",
"outputs": ["libs/foo/coverage"],
"options": {
"targets": ["integration_test"]
}
}
}
}Options
targets: The files or directories which contain the tests to run. When not specified, all tests in thetestdirectory are run.coverage: Whether to collect coverage information. Thedarttool does not outputlcov.infofiles by default. The executor converts the Dart coverage data into alcov.infofile automatically. Thefluttertool outputs alcov.infofile by default.
All additional options are passed to the Dart or Flutter test tool. Abbreviations are not supported.