NativeScript / plugin-seed

Build NativeScript Plugins Fast ⚡
https://docs.nativescript.org/plugins/plugin-workspace-guide
Apache License 2.0
45 stars 11 forks source link

[Question] build plugins in dependency order #23

Closed alexander-mai closed 10 months ago

alexander-mai commented 2 years ago

I have a plugin repository with 12 plugins, where multiple plugins depends on other plugins inside this repository.

Calling nps --> build all or directly nx run-many --target=build.all --all throws errors shows multiple errors that dependencies have not been built. Calling nx graph is showing a correct dependency graph of all packages. Is it possible to build the all packages at once considering the dependencies? If nx correctly detects the dependencies between the packages, then why doesn't it automatically build the packages in the required order? Is there a way to do that?

NathanWalker commented 2 years ago

@alexander-mai when possible could you try migrating:

yarn nx migrate @nativescript/plugin-tools

Then follow the printed instructions to run the migrations. Can also reference this section: https://docs.nativescript.org/plugins/plugin-workspace-guide.html#migrating-your-plugin-workspace

After migrating it should auto build dependencies in correct order.

alexander-mai commented 2 years ago

Thank you for your help @NathanWalker . I have already upgraded my plugin repo. When I run build-allI get the following result:

 nx run-many --target=build.all --all

    ✖  nx run entity:build
       Some of the project plugin6's dependencies have not been built yet. Please build these libraries before:
       - plugin12
       - plugin2

       Try: nx run plugin6:build --with-deps
       Some dependencies of 'plugin6' have not been built. This probably due to the build target being misconfigured.

    ✔  nx run plugin12:build (11s)
    ✔  nx run plugin7:build (10s)
    ✔  nx run plugin2:build (12s)

    ✖  nx run plugin8:build
       Some of the project plugin8's dependencies have not been built yet. Please build these libraries before:
       - plugin6
       - plugin5

       Try: nx run plugin8:build --with-deps
       Some dependencies of 'plugin8' have not been built. This probably due to the build target being misconfigured.

    ✖  nx run plugin1:build
       Some of the project plugin1's dependencies have not been built yet. Please build these libraries before:
       - plugin4
       - plugin8
       - plugin6
       - plugin5

       Try: nx run plugin1:build --with-deps
       Some dependencies of 'plugin1' have not been built. This probably due to the build target being misconfigured.

    ✖  nx run plugin10:build
       Some of the project plugin10's dependencies have not been built yet. Please build these libraries before:
       - plugin6
       - plugin1
       - plugin4
       - plugin8
       - plugin5

       Try: nx run plugin10:build --with-deps
       Some dependencies of 'plugin10' have not been built. This probably due to the build target being misconfigured.

    ✔  nx run plugin4:build (11s)
    ✔  nx run plugin5:build (11s)
    ✔  nx run plugin11:build (10s)
    ✔  nx run plugin12:build.all (3s)
    ✔  nx run plugin7:build.all (2s)
    ✔  nx run plugin3:build (10s)
    ✔  nx run plugin9:build (10s)
    ✔  nx run plugin2:build.all (10s)
    ✔  nx run plugin4:build.all (8s)
    ✔  nx run plugin11:build.all (10s)
    ✔  nx run plugin9:build.all (2s)
    ✔  nx run plugin4:build.all (2s)
    ✔  nx run plugin3:build.all (7s)

 —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 >  NX   Ran target build.all for 12 projects and 12 task(s) they depend on (46s)

    ✖    4/20 failed
    ✔    16/20 succeeded [0 read from cache]

This is my dependency graph generated by nx graph grafik

agonper commented 2 years ago

I'm facing the same issue. I'll be able to share a repo to reproduce the issue soon (it is a near-future open source workspace).

Meanwhile, in case it helps. I've been able to fix the issue with the following:

For convenience, just update the workspace-scripts.js inside the tools/folder following the above where needed (i.e., build-all, demo builds, etc.).

My guess is that something is being notified as finished before really finishing its execution, or that nx does not handle well creating a safe execution sequence for tasks to be run in parallel when the build.all task is involved.

agonper commented 2 years ago

Hello,

I've just remembered that I had pending to share a repo to reproduce this issue. Here it is: https://github.com/GeoTecINIT/awarns-framework

Try to update the workspace-scripts.js file, for example, removing the --parallel=1 flag in the build-all script and see how the build fails.

I also have to manually set this flag in the publish executor inside node_modules/@nativescript/plugin-tools when publishing multiple packages, which depend on one another, at once.

Hope this helps