nxrocks icon indicating copy to clipboard operation
nxrocks copied to clipboard

[Bug] nx-flutter: inferred tasks aren't working

Open danielesegato opened this issue 1 year ago • 13 comments

Plugin Name

create-nx-flutter

Nx Report

Node : 20.2.0 OS : darwin-arm64 npm : 9.6.6

nx (global) : 19.2.0 nx : 19.2.0 @nx/js : 19.2.0 @nx/workspace : 19.2.0 @nx/devkit : 19.2.0 @nrwl/tao : 19.2.0 typescript : 5.4.5

Registered Plugins: @nxrocks/nx-flutter

Community plugins: @nxrocks/nx-flutter : 9.0.2

Expected Behaviour

running

nx run-many -t test

should run tests on all flutter modules

  • dependencies between flutter modules should show up in the graph

Actual Behaviour

this is what happens

 NX   Successfully ran target test for 0 projects (20ms)

despite having projects in the workspace.

Steps to reproduce the behaviour

# create the workspace
npx create-nx-workspace@latest

# enter the workspace
cd the-workspace

# install nx-flutter plugin
npm install @nxrocks/nx-flutter --save-dev

# create a flutter project
npx nx g @nxrocks/nx-flutter:project 

# try running tests or any other command supported by nx-flutter
nx run-many -t test

danielesegato avatar Jun 06 '24 11:06 danielesegato

Hi @danielesegato

Thanks for using the plugin and for reporting this.

Can you please share me the content of your .env file (if present at root) and your nx.json + project.json files please?

tinesoft avatar Jun 06 '24 14:06 tinesoft

Sure.

there's no .env file at the moment, it's a new project - mostly empty.

The nx.json in the root of the workspace:

{
  "extends": "nx/presets/npm.json",
  "$schema": "./node_modules/nx/schemas/nx-schema.json",
  "plugins": [
    {
      "plugin": "@nxrocks/nx-flutter",
      "options": {
        "analyzeTargetName": "analyze",
        "cleanTargetName": "clean",
        "formatTargetName": "format",
        "testTargetName": "test",
        "doctorTargetName": "doctor",
        "assembleTargetName": "assemble",
        "attachTargetName": "attach",
        "driveTargetName": "drive",
        "genL10nTargetName": "gen-l10n",
        "installTargetName": "install",
        "runTargetName": "run",
        "buildAarTargetName": "build-aar",
        "buildApkTargetName": "build-apk",
        "buildAppbundleTargetName": "build-appbundle",
        "buildBundleTargetName": "build-bundle",
        "buildIosTargetName": "build-ios",
        "buildIosFrameworkTargetName": "build-ios-framework",
        "buildIpaTargetName": "build-ipa"
      }
    }
  ],
  "targetDefaults": {}
}

And a project.info file in a module at apps/poc relative directory

{
  "name": "apps/poc",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/poc/src",
  "tags": []
}

this is what was generated by the plugin, I just changed the name of the project to match the folder

danielesegato avatar Jun 06 '24 16:06 danielesegato

Hi,

can you try changing the name to simply poc in project.json ?

I'm not sure "apps/poc" is valid. What matters to find the files is the "sourceRoot".

tinesoft avatar Jun 06 '24 18:06 tinesoft

I've created a new project to test this out.

Run this command from the route:

npx nx g @nxrocks/nx-flutter:project

and chose these options:

✔ What name would you like to use? · foo
✔ What package name would you like to use? · foo
✔ What is the project about? · Testing NX-Flutter
✔ Which type of Flutter project would you like to create? · app
✔ Are you using Flutter Version Manager (fvm)? (y/N) · true
✔ What should be the project name and where should it be generated? · foo @ foo
✔ Which platforms would you like to use? · android, ios
✔ Which Android language would you like to use? · kotlin
✔ Which iOS language would you like to use? · swift
⚙️ Generating project configuration...
Generating Flutter project with following options : --project-name=foo --org=foo --description="Testing NX-Flutter" --android-language=kotlin --ios-language=swift --template=app --platforms="android,ios" ...
Executing command: fvm flutter create --project-name=foo --org=foo --description="Testing NX-Flutter" --android-language=kotlin --ios-language=swift --template=app --platforms="android,ios"  foo
Creating project foo...
Resolving dependencies in `foo`... 
Downloading packages... 
Got dependencies in `foo`.
Wrote 74 files.

All done!

still getting 0 projects run when trying to run a target.

I've also tried renaming the project just "poc" but that didn't help either.

danielesegato avatar Jun 07 '24 05:06 danielesegato

Hi @danielesegato

Thanks for your response. I will have a closer look this weekend and let you know.

Stay tuned

tinesoft avatar Jun 07 '24 08:06 tinesoft

Hi @danielesegato

Sorry for the delay.

This should be fixed now in the latest version of the create-nx-flutter.

If you've already generated your workspace, you can simply update the version of @nxrocks/nx-flutter package in the nx.json to latest version (i.e 9.0.3) and run any nx command ( for example ./nx reset && ./nx graph)

If the version of package, in the nx.json is set to latest (default setting), simply delete the node_modules folder within the .nx/installation folder. Then run any nx command ( for example ./nx reset && ./nx graph).

Either action should force the download of the right version of underlying @nxrocks/nx-flutter plugin, that contains the fix.

Enjoy!

tinesoft avatar Jun 16 '24 20:06 tinesoft

Thanks @tinesoft yes I can confirm some of the tasks are now running.

I did npm upgrade to update to the latest version.

Is it expected for build-aar to not run in flutter modules? (it only tried to run on the app module which doesn't have android libraries)

(is there a way to specify if I want to use FVM or not via environmental flag? it would be useful to disable FVM on CI)

danielesegato avatar Jun 17 '24 09:06 danielesegato

Thanks for the updates.

Is it expected for build-aar to not run in flutter modules? (it only tried to run on the app module which doesn't have android libraries)

build-aar is only available when building for android platform.

(is there a way to specify if I want to use FVM or not via environmental flag? it would be useful to disable FVM on CI)

Right now, no. fvm is automatically used (instead of regular flutter) when it is found on the path. This is not configurable at the moment, but I agree, this can/should be configurable.

In the meantime, if you don't have fvm on your CI/CD, but just regular flutter binary, it should be good already

tinesoft avatar Jun 17 '24 14:06 tinesoft

Hi @tinesoft I'm sorry, there's still some target not working:

npx nx run-many -t gen-l10n

produces:

 NX   Successfully ran target gen-l10n for 0 projects (15ms)

the same happen with, for example, the assemble target.

danielesegato avatar Jun 18 '24 09:06 danielesegato

Hi @danielesegato

Inferred tasks depends on the type of project (template) your have generated, the target platforms you've chosen , etc...

The related code can be found here https://github.com/tinesoft/nxrocks/blob/0e2ae881800f72b450b5a1d5fb4e4491fcee50f8/packages/nx-flutter/src/utils/plugin-utils.ts#L68

Some of the values, are read at runtime from the .metadata file that is present at the root of each flutter project.

Can you show me the content of those files ?

tinesoft avatar Jun 18 '24 09:06 tinesoft

core/auth .metadata

# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
  revision: "a14f74ff3a1cbd521163c5f03d68113d50af93d3"
  channel: "stable"

project_type: package

and apps/poc .metadata:

# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
  revision: "a14f74ff3a1cbd521163c5f03d68113d50af93d3"
  channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
  platforms:
    - platform: root
      create_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
      base_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
    - platform: android
      create_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
      base_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
    - platform: ios
      create_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
      base_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
    - platform: linux
      create_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
      base_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
    - platform: macos
      create_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
      base_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
    - platform: web
      create_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
      base_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
    - platform: windows
      create_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
      base_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3

  # User provided section

  # List of Local paths (relative to this file) that should be
  # ignored by the migrate tool.
  #
  # Files that are not part of the templates will be ignored by default.
  unmanaged_files:
    - 'lib/main.dart'
    - 'ios/Runner.xcodeproj/project.pbxproj'

both of them contains localizations and should be able to run the gen-l10n task.

and I'd expect all projects to be able to run the assemble task.

I see the code checks for this app template, not sure what's the logic behind that.

danielesegato avatar Jun 18 '24 09:06 danielesegato

Hi,

You might be right about the gen-l10n and assemble tasks. I 'll review the conditions for all tasks.

As for the poc project (which is of template app), I'm surprised it was not picked when you run npx nx run-many -t gen-l10n... Can you try running npx nx gen-l10n poc directly ?

tinesoft avatar Jun 18 '24 11:06 tinesoft

Here it is @tinesoft

$ npx nx gen-l10n apps/poc --verbose

 NX   Cannot find configuration for task apps/poc:gen-l10n


Error: Cannot find configuration for task apps/poc:gen-l10n
    at ProcessTasks.createTask (/Volumes/sourcecode/[redacted]/node_modules/nx/src/tasks-runner/create-task-graph.js:156:19)
    at ProcessTasks.processTasks (/Volumes/sourcecode/[redacted]/node_modules/nx/src/tasks-runner/create-task-graph.js:23:39)
    at createTaskGraph (/Volumes/sourcecode/[redacted]/node_modules/nx/src/tasks-runner/create-task-graph.js:194:21)
    at createTaskGraphAndValidateCycles (/Volumes/sourcecode/[redacted]/node_modules/nx/src/tasks-runner/run-command.js:62:63)
    at /Volumes/sourcecode/[redacted]/node_modules/nx/src/tasks-runner/run-command.js:85:27
    at handleErrors (/Volumes/sourcecode/[redacted]/node_modules/nx/src/utils/params.js:9:30)
    at runCommand (/Volumes/sourcecode/[redacted]/node_modules/nx/src/tasks-runner/run-command.js:83:52)
    at Object.runOne (/Volumes/sourcecode/[redacted]/node_modules/nx/src/command-line/run/run-one.js:53:59)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async handleErrors (/Volumes/sourcecode/[redacted]/node_modules/nx/src/utils/params.js:9:24)

regarding the gen-l10n command it should only be available on projects and modules that have generation anabled and the l10n.yaml file I believe.

for the assemble one I'm not sure.

danielesegato avatar Jun 18 '24 16:06 danielesegato

Hm. For me it is still not working. I've tried several commands, but it always states: Cannot find configuration.

I'm using the latest 9.1.1 version of this plugin.

I did the same as the author, as i had an existing workspace and just wanted to add the flutter subproject.

# install nx-flutter plugin
npm install @nxrocks/nx-flutter --save-dev

# create a flutter project
npx nx g @nxrocks/nx-flutter:project 

Funny side note:

I've just named the project flutter-app. This caused a lot of trouble with flutter as the name included a -. So i had to recreate it with an underscore (flutter_app)

denny99 avatar Jul 26 '24 13:07 denny99

Hi @denny99 ,

Can you make sure that you're using at least version v9.1.2: https://github.com/tinesoft/nxrocks/releases/tag/nx-flutter%2Fv9.1.2?

Try removing node_modules, then reinstalling them.

As for this:

I've just named the project flutter-app. This caused a lot of trouble with flutter as the name included a -. So i had to recreate it with an underscore (flutter_app)

can you open another ticket, with reproduction steps?

tinesoft avatar Aug 01 '24 03:08 tinesoft

image

Nope sorry. Still the same issue.

Edit:

The naming issue seems to be fixed. I used an older version that caused the issue

denny99 avatar Aug 01 '24 06:08 denny99

Hum,

the issue seems specific to your setup....

can you provide more information about your workspace? how you created it? the files/folders structure?

better yet, if you can share a minimum reproductible project, that would be great

tinesoft avatar Aug 01 '24 07:08 tinesoft

npx [email protected]

 NX   Let's create a new workspace [https://nx.dev/getting-started/intro]

✔ Where would you like to create your workspace? · flutter-repro
✔ Which stack do you want to use? · none
✔ Package-based monorepo, integrated monorepo, or standalone project? · integrated
✔ Set up CI with caching, distribution and test deflaking · skip
✔ Would you like remote caching to make your build faster? · skip

cd flutter-repro/

npm i -D @nxrocks/nx-flutter

nx g @nxrocks/nx-flutter:project flutter-app

 NX  Generating @nxrocks/nx-flutter:project

✔ What package name would you like to use? · com.example
✔ What is the project about? ·
✔ Which type of Flutter project would you like to create? · app
✔ Are you using Flutter Version Manager (fvm)? (y/N) · false
✔ Which platforms would you like to use? · android, ios
✔ Which Android language would you like to use? · kotlin
✔ Which iOS language would you like to use? · swift

nx clean flutter-app

 NX   Cannot find configuration for task flutter-app:clean

Pass --verbose to see the stacktrace.

It is basically the same as the author described it. It does not matter if i use nx 18 oder 19

denny99 avatar Aug 01 '24 07:08 denny99

Ok thanks for the complementary information. I'll try to have another look at today.

Stay tuned!

tinesoft avatar Aug 01 '24 14:08 tinesoft

I just tried your exact steps, and could not reproduce the issue... image

Can you show me the content of your nx.json, project.json and .env(if present). ?

Also, regarding your previous response image This error is normal, because the flutter project name is "flutter_app" (note the underscore, so that the name matches Dart naming convention), whereas the nx project name is the one you provided ("flutter-app"). So you must use the later to run nx commands on it.

tinesoft avatar Aug 03 '24 04:08 tinesoft

Then i'm kinda confused. I've tried pnpm as well but it does not make any difference. My Flutter Version is: Flutter 3.22.3

And here are my nx and project json files nx.json

{
  "$schema": "./node_modules/nx/schemas/nx-schema.json",
  "namedInputs": {
    "default": [
      "{projectRoot}/**/*",
      "sharedGlobals"
    ],
    "production": [
      "default"
    ],
    "sharedGlobals": []
  },
  "plugins": [
    {
      "plugin": "@nxrocks/nx-flutter",
      "options": {
        "analyzeTargetName": "analyze",
        "cleanTargetName": "clean",
        "formatTargetName": "format",
        "testTargetName": "test",
        "assembleTargetName": "assemble",
        "attachTargetName": "attach",
        "driveTargetName": "drive",
        "genL10nTargetName": "gen-l10n",
        "installTargetName": "install",
        "runTargetName": "run",
        "buildAarTargetName": "build-aar",
        "buildApkTargetName": "build-apk",
        "buildAppbundleTargetName": "build-appbundle",
        "buildBundleTargetName": "build-bundle",
        "buildIosTargetName": "build-ios",
        "buildIosFrameworkTargetName": "build-ios-framework",
        "buildIpaTargetName": "build-ipa"
      }
    }
  ],
  "targetDefaults": {}
}

project.json

{
  "name": "flutter-app",
  "$schema": "../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "flutter-app/src",
  "tags": []
}

The flutter_app was my renamed project. So nx and flutter package names are identical. Just for testing purposes i've used flutter-app for nx (which will result in a flutter_app in the pubspec file)

denny99 avatar Aug 04 '24 08:08 denny99

Can you try clearing Nx cache with nx reset and retry the command?

If it still doesn"t work, I'm afraid I cannot assist you more without accessing your code, or at least a minimal repro project showing the issue...

tinesoft avatar Aug 06 '24 04:08 tinesoft

Here you go

https://github.com/denny99/nxrocks

pnpm i or npm i. Does not matter.

nx clean flutter-app will result in no target found.

The NX UI in Webstorm does not show any targets either

image

denny99 avatar Aug 07 '24 07:08 denny99

Thanks for the repro project, it will help a lot finding and fixing the issue. I'll have a look tonight, stay tuned!

tinesoft avatar Aug 07 '24 07:08 tinesoft

OK, the problem is now fixed.

Simply update the plugin to latest version (v9.2.0) and you should be good. Tested on your repro project above.

tinesoft avatar Aug 07 '24 21:08 tinesoft

Thanks awesome!

denny99 avatar Aug 08 '24 06:08 denny99