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

CLI regenerates ALL aar files on changes in node_modules #3710

Closed
sis0k0 opened this issue Jun 27, 2018 · 1 comment · Fixed by #3711
Closed

CLI regenerates ALL aar files on changes in node_modules #3710

sis0k0 opened this issue Jun 27, 2018 · 1 comment · Fixed by #3711

Comments

@sis0k0
Copy link
Contributor

sis0k0 commented Jun 27, 2018

Please, provide the details below:

Did you verify this is a real problem by searching the NativeScript Forum and the other open issues in this repo?

👍

Tell us about the problem

Setup:

Application with at least one plugin that requires the CLI to generate aar file. For example - the sdk samples that use the nativescript-camera plugin.

Command:

First case (webpack):
tns run android --bundle
Second case (no webpack):
tns run android

Behavior

First case (webpack)

When you change a file in the node_modules/ folder, for example node_modules/tns-core-modules/bundle-entry-points.js:

  1. The mtime (modified time) of the file is updated.
  2. Webpack detects the change and recompiles the JS bundles (for example, bundle.js or vendor.js). Then it starts the livesync process.
  3. The CLI detects that there was a change in node_modules.
  4. Because of the change in node_modules, the modulesChanged flag is raised and the CLI regenerates all aar files. see here
  5. The changed JS file is deployed on the device and the app is restarted/refreshed.
Second case (no webpack)

You have to make two file changes here, because the CLI keeps track of the mtimes of the files in node_modules, but the watcher detects changes only in the app/ folder.

  1. [User action] Modify a file in node_modules, for example - node_modules/tns-core-modules/bundle-entry-points.js.
  2. The mtime of the file is updated.
  3. [User action] Modify a file in the app/ folder, for example - app/app.css.
  4. The CLI watcher detects that there is a change in the app/ folder and starts the livesync process, which includes preparing the project.
  5. The CLI detects that there was a change in node_modules.
  6. Because of the change in node_modules, the modulesChanged flag is raised and the CLI regenerates all aar files. see here
  7. The changed JS bundles are deployed on the device and the app is restarted.

Expected behavior

The CLI should keep track of node_modules only when the sync-all-files flag is used. Checking for modified files in node_modules on every change can be quite slow.

Note: Rebuilding the aar files for every change in node_modules (even if that's done only when using the sync-all-files flag) is also slow and not necessary. This probably should be logged as separate issue. @rosen-vladimirov, what do you think?

Why does this happen?

Currently, the node_modules are traversed and checked for modified files explicitly. That's because of this change: 04f9737#diff-919912d52b0e0303e76febe7c84cacfdR67.
If we get the old code back, the CLI will only check node_modules when the --sync-all-files flag is provided.

Cons of the proposed change

If we stop keeping track of node_modules when using normal livesync or livesync with bundle, we will lose the following functionality:

  • Adding a new NativeScript plugin that doesn't have a prebuilt aar file will not work until you stop the CLI process and run a clean build.
  • Modifying the native files (platform/android) of a plugin in node_modules won't rebuild its aar file until you stop the CLI process and run a clean build.

Which platform(s) does your issue occur on?

Android

Please provide the following version numbers that your issue occurs with:

  • CLI: 4.2.0-2018-06-26-11829 (the same thing happens with the official version - 4.1.2)
@rosen-vladimirov
Copy link
Contributor

I'm adding some more use-cases here that describe the same behavior and that will be fixed in #3750 :
In case any file is modified in the <project dir>/node_modules/<nativescript plugin>/platforms/android , CLI rebuilds all .aar files of the plugins. This can be easily reproduced with this project (follow the README.md for detailed description):
https://github.com/rosen-vladimirov/project-local-plugins
In fact only the modified plugins should be rebuild.

NOTE: The changes introduce in #3711 caused additional issues - with them changes in node_modules are never prepared (i.e. they are not moved to <project dir>/platforms/... directory as CLI does not check node_modules unless --syncAllFiles is passed. As we do not want to pass --syncAllFiles to prepare, build, test, etc. commands, the #3750 fixes this behavior as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment