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

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

Open
danielesegato opened this issue Jun 6, 2024 · 13 comments
Open

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

danielesegato opened this issue Jun 6, 2024 · 13 comments

Comments

@danielesegato
Copy link

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
@tinesoft
Copy link
Owner

tinesoft commented Jun 6, 2024

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?

@danielesegato
Copy link
Author

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

@tinesoft
Copy link
Owner

tinesoft commented Jun 6, 2024

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

@danielesegato
Copy link
Author

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.

@tinesoft
Copy link
Owner

tinesoft commented Jun 7, 2024

Hi @danielesegato

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

Stay tuned

@tinesoft
Copy link
Owner

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!

@danielesegato
Copy link
Author

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)

@tinesoft
Copy link
Owner

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

@danielesegato
Copy link
Author

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.

@tinesoft
Copy link
Owner

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

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 tinesoft reopened this Jun 18, 2024
@danielesegato
Copy link
Author

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.

@tinesoft
Copy link
Owner

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 ?

@danielesegato
Copy link
Author

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.

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

No branches or pull requests

2 participants