Skip to content

CLI regenerates ALL aar files on changes in node_modules #3710

Closed
@sis0k0

Description

@sis0k0

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)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions