Description
Environment
Provide version numbers for the following components (information can be retrieved by running tns info
in your project folder or by inspecting the package.json
of the project):
- CLI: 5.2.0
- Cross-platform modules: Not applicable
- Android Runtime: Not applicable
- iOS Runtime: Not applicable
- Plugin(s):
{
"nativescript": {
"id": "org.nativescript.app1",
"tns-android": {
"version": "5.2.0"
},
"tns-ios": {
"version": "5.2.0"
}
},
"description": "NativeScript Application",
"license": "SEE LICENSE IN <your-license-filename>",
"repository": "<fill-your-repository-here>",
"dependencies": {
"nativescript-theme-core": "~1.0.4",
"tns-core-modules": "~5.2.0"
},
"devDependencies": {
"nativescript-dev-webpack": "~0.20.0"
},
"gitHead": "59b6da006346fedb5bb201fcc9cd7d204a69a82f",
"readme": "NativeScript Application"
}
Describe the bug
Every run after the first tns run <platform> --bundle
produces App_Resources directory inside <project dir>/platforms/<platform>/.../app/
directory. App_Resources
directory must not exist in platforms dir - content of the App_Resources should be placed on specific locations in the platforms dir, but the directory itself should not be copied anywhere. In fact the resources are prepared on the correct place and duplicated in <project dir>/platforms/<platform>/.../app/
.
To Reproduce
tns create myApp --js
cd myApp
tns run android --bundle --justlaunch
ls -l platforms/android/app/src/main/assets/app
- App_Resources will not be in the listed files/dirs.- Now run
tns run android --bundle --justlaunch
again. ls -l platforms/android/app/src/main/assets/app
- App_Resources will be in the listed files/dirs.
NOTE: Same is valid for iOS.
Expected behavior
App_Resources must not be in the platforms dir.
Additional context
The issue is caused by the way CLI prepares App_Resources and the way nativescript-dev-webpack plugs in CLI's lifecycle.
Currently, during project preparation CLI copies the project's app directory to platforms dir. By default, the App_Resources are inside project's app directory, so CLI actually copies them as well. After that CLI executes some actions over the files in platforms/<platform>.../app/App_Resources
(i.e. deletes some of them) and moves them to correct places in platforms dir. At the end of these operations, CLI deletes the platforms/<platform>.../app/App_Resources
dir, as it has already prepared the files.
What happens when --bundle
is used - nativescript-dev-webpack
replaces the method in which CLI copies project's app directory to platforms
dir. However, other methods after the replaced one (particularly the prepareAppResources method), expect to find App_Resources in platforms/.../app/App_Resources
. So nativescript-dev-webpack
has a logic to copy project's App_Resources dir to the location where prepareAppResources method will expect. This whole thing works correctly when building application. However, when tns run <platform> --bundle
is executed, there's additional magic. First operation that is run in such case is starting the webpack process with watcher enabled. Webpack produces files and reports them to CLI to be LiveSynced. Whenever webpack compiler is started, our logic in nativescript-dev-webpack copies App_Resources to platforms/.../app/App_Resources
. NOTE: The start of webpack process and producing the App_Resources comes from the before-watch hook, not from the replacement of the method where CLI copies app dir to platforms. After watcher is started CLI checks the application state and decides that it should skip the project preparation as nothing has changed since last time. However, it uploads the files reported by webpack to device (i.e. the new bundle.js, vendor,js, etc.). The App_Resources remain in platforms/.../app/App_Resources
as CLI skips its preparation phase. However, these files will never be uploaded on device. In case some change in the app requires build, CLI will reprepare the native files, including App_Resources and they will not be included in the build .apk/.ipa file.
Related to: #4239