From 6f48b4bef3ecce6927f9c8cfd9fdc4c404a5b09d Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Sat, 9 Jul 2022 11:01:14 -0700 Subject: [PATCH] chore: remove legacy webpack4 as no longer used Still accessible on a branch though here: https://github.com/NativeScript/NativeScript/tree/feat/webpack4 --- packages/webpack/.gitignore | 47 - packages/webpack/.npmignore | 17 - packages/webpack/.nycrc | 5 - packages/webpack/CHANGELOG.md | 1177 ----------------- packages/webpack/LICENSE | 201 --- packages/webpack/README.md | 49 - .../webpack/bin/generate-android-snapshot | 6 - .../webpack/bin/generate-android-snapshot.cmd | 1 - packages/webpack/bin/install-ns-webpack | 3 - packages/webpack/bin/install-ns-webpack.cmd | 1 - packages/webpack/bin/ns-bundle | 4 - packages/webpack/bin/ns-bundle.cmd | 1 - packages/webpack/bin/ns-verify-bundle | 104 -- packages/webpack/bin/ns-verify-bundle.cmd | 1 - packages/webpack/bin/ns-webpack-update.cmd | 1 - packages/webpack/bin/remove-ns-webpack | 3 - packages/webpack/bin/remove-ns-webpack.cmd | 1 - packages/webpack/bin/update-ns-webpack | 20 - packages/webpack/build/prepublish.js | 30 - packages/webpack/bundle-config-loader.d.ts | 3 - .../webpack/bundle-config-loader.spec.d.ts | 1 - packages/webpack/bundle-config-loader.spec.ts | 114 -- packages/webpack/bundle-config-loader.ts | 88 -- .../helpers/android-app-components-loader.js | 18 - .../webpack/helpers/androidProjectHelpers.js | 77 -- .../webpack/helpers/angular-config-parser.js | 114 -- packages/webpack/helpers/apply-css-loader.js | 43 - packages/webpack/helpers/css2json-loader.d.ts | 3 - .../webpack/helpers/css2json-loader.spec.d.ts | 1 - .../webpack/helpers/css2json-loader.spec.ts | 66 - packages/webpack/helpers/css2json-loader.ts | 59 - packages/webpack/helpers/dependencyManager.js | 110 -- packages/webpack/helpers/hot-loader-helper.js | 9 - packages/webpack/helpers/hot.js | 172 --- .../helpers/lazy-ngmodule-hot-loader.js | 30 - .../helpers/load-application-css-angular.js | 8 - .../helpers/load-application-css-regular.js | 8 - .../webpack/helpers/load-application-css.js | 8 - packages/webpack/helpers/markup-hot-loader.js | 10 - .../webpack/helpers/moduleid-compat-loader.js | 16 - .../webpack/helpers/projectFilesManager.js | 152 --- packages/webpack/helpers/projectHelpers.js | 162 --- .../webpack/helpers/projectHelpers.spec.js | 132 -- packages/webpack/helpers/script-hot-loader.js | 9 - packages/webpack/helpers/style-hot-loader.js | 10 - .../webpack/helpers/xml-namespace-loader.d.ts | 3 - .../helpers/xml-namespace-loader.spec.d.ts | 1 - .../helpers/xml-namespace-loader.spec.ts | 296 ----- .../webpack/helpers/xml-namespace-loader.ts | 141 -- packages/webpack/hmr/hmr-update.d.ts | 1 - packages/webpack/hmr/hmr-update.ts | 13 - packages/webpack/hmr/hot-loader.d.ts | 3 - packages/webpack/hmr/hot-loader.ts | 41 - packages/webpack/hmr/index.d.ts | 1 - packages/webpack/hmr/index.ts | 1 - packages/webpack/host/resolver.d.ts | 1 - packages/webpack/host/resolver.ts | 41 - packages/webpack/index.js | 264 ---- packages/webpack/index.spec.d.ts | 1 - packages/webpack/index.spec.ts | 44 - packages/webpack/installer.js | 29 - packages/webpack/jasmine-config/jasmine.json | 13 - packages/webpack/jasmine-config/reporter.d.ts | 1 - packages/webpack/jasmine-config/reporter.ts | 6 - packages/webpack/lib/after-prepare.js | 23 - .../webpack/lib/before-checkForChanges.js | 33 - packages/webpack/lib/utils.js | 41 - .../NsJsonpChunkTemplatePlugin.js | 48 - .../NsJsonpMainTemplate.runtime.js | 32 - .../NsJsonpMainTemplatePlugin.js | 324 ----- .../NsJsonpTemplatePlugin.js | 17 - packages/webpack/nativescript-target/index.js | 16 - packages/webpack/package.json | 103 -- .../plugins/GenerateBundleStarterPlugin.js | 14 - .../GenerateNativeScriptEntryPointsPlugin.js | 111 -- .../NativeScriptAngularCompilerPlugin.d.ts | 1 - .../NativeScriptAngularCompilerPlugin.ts | 32 - .../NativeScriptSnapshotPlugin/index.js | 173 --- .../NativeScriptSnapshotPlugin/options.json | 66 - .../webpack/plugins/PlatformFSPlugin.d.ts | 33 - packages/webpack/plugins/PlatformFSPlugin.ts | 241 ---- .../webpack/plugins/PlatformSuffixPlugin.js | 35 - .../plugins/WatchStateLoggerPlugin.d.ts | 13 - .../webpack/plugins/WatchStateLoggerPlugin.ts | 57 - packages/webpack/plugins/index.js | 8 - packages/webpack/postinstall.js | 55 - packages/webpack/preuninstall.js | 11 - packages/webpack/project.json | 31 - ...oject-snapshot-generator-cli-ags-parser.js | 74 -- .../android/project-snapshot-generator.js | 197 --- .../snapshot-generator-tools/bundle-ending.js | 12 - .../bundle-preamble.js | 34 - .../snapshot-generator-tools/include.gradle | 13 - .../ndk-build/.gitignore | 4 - .../ndk-build/jni/Android.mk | 7 - .../snapshot/android/snapshot-generator.js | 464 ------- packages/webpack/snapshot/android/utils.js | 128 -- packages/webpack/templates/webpack.angular.js | 375 ------ .../templates/webpack.config.spec.d.ts | 1 - .../webpack/templates/webpack.config.spec.ts | 306 ----- .../webpack/templates/webpack.javascript.js | 293 ---- packages/webpack/templates/webpack.react.js | 87 -- packages/webpack/templates/webpack.svelte.js | 356 ----- .../webpack/templates/webpack.typescript.js | 332 ----- packages/webpack/templates/webpack.vue.js | 357 ----- .../transformers/ns-support-hmr-ng.d.ts | 8 - .../transformers/ns-support-hmr-ng.spec.d.ts | 1 - .../transformers/ns-support-hmr-ng.spec.ts | 81 -- .../webpack/transformers/ns-support-hmr-ng.ts | 103 -- .../ns-transform-native-classes-ng.d.ts | 2 - .../ns-transform-native-classes-ng.ts | 7 - .../ns-transform-native-classes.d.ts | 2 - .../ns-transform-native-classes.ts | 30 - packages/webpack/tsconfig.json | 20 - .../webpack/unit-testing-config-loader.js | 46 - packages/webpack/utils/ast-utils.d.ts | 17 - packages/webpack/utils/ast-utils.ts | 298 ----- .../webpack/utils/transformers-utils.d.ts | 5 - packages/webpack/utils/transformers-utils.ts | 16 - packages/webpack/utils/tsconfig-utils.d.ts | 3 - packages/webpack/utils/tsconfig-utils.ts | 25 - packages/webpack/verify/update.js | 91 -- workspace.json | 1 - 123 files changed, 9310 deletions(-) delete mode 100644 packages/webpack/.gitignore delete mode 100644 packages/webpack/.npmignore delete mode 100644 packages/webpack/.nycrc delete mode 100644 packages/webpack/CHANGELOG.md delete mode 100755 packages/webpack/LICENSE delete mode 100644 packages/webpack/README.md delete mode 100755 packages/webpack/bin/generate-android-snapshot delete mode 100644 packages/webpack/bin/generate-android-snapshot.cmd delete mode 100755 packages/webpack/bin/install-ns-webpack delete mode 100644 packages/webpack/bin/install-ns-webpack.cmd delete mode 100755 packages/webpack/bin/ns-bundle delete mode 100644 packages/webpack/bin/ns-bundle.cmd delete mode 100755 packages/webpack/bin/ns-verify-bundle delete mode 100644 packages/webpack/bin/ns-verify-bundle.cmd delete mode 100644 packages/webpack/bin/ns-webpack-update.cmd delete mode 100755 packages/webpack/bin/remove-ns-webpack delete mode 100644 packages/webpack/bin/remove-ns-webpack.cmd delete mode 100755 packages/webpack/bin/update-ns-webpack delete mode 100644 packages/webpack/build/prepublish.js delete mode 100644 packages/webpack/bundle-config-loader.d.ts delete mode 100644 packages/webpack/bundle-config-loader.spec.d.ts delete mode 100644 packages/webpack/bundle-config-loader.spec.ts delete mode 100644 packages/webpack/bundle-config-loader.ts delete mode 100644 packages/webpack/helpers/android-app-components-loader.js delete mode 100644 packages/webpack/helpers/androidProjectHelpers.js delete mode 100644 packages/webpack/helpers/angular-config-parser.js delete mode 100644 packages/webpack/helpers/apply-css-loader.js delete mode 100644 packages/webpack/helpers/css2json-loader.d.ts delete mode 100644 packages/webpack/helpers/css2json-loader.spec.d.ts delete mode 100644 packages/webpack/helpers/css2json-loader.spec.ts delete mode 100644 packages/webpack/helpers/css2json-loader.ts delete mode 100644 packages/webpack/helpers/dependencyManager.js delete mode 100644 packages/webpack/helpers/hot-loader-helper.js delete mode 100644 packages/webpack/helpers/hot.js delete mode 100644 packages/webpack/helpers/lazy-ngmodule-hot-loader.js delete mode 100644 packages/webpack/helpers/load-application-css-angular.js delete mode 100644 packages/webpack/helpers/load-application-css-regular.js delete mode 100644 packages/webpack/helpers/load-application-css.js delete mode 100644 packages/webpack/helpers/markup-hot-loader.js delete mode 100644 packages/webpack/helpers/moduleid-compat-loader.js delete mode 100644 packages/webpack/helpers/projectFilesManager.js delete mode 100644 packages/webpack/helpers/projectHelpers.js delete mode 100644 packages/webpack/helpers/projectHelpers.spec.js delete mode 100644 packages/webpack/helpers/script-hot-loader.js delete mode 100644 packages/webpack/helpers/style-hot-loader.js delete mode 100644 packages/webpack/helpers/xml-namespace-loader.d.ts delete mode 100644 packages/webpack/helpers/xml-namespace-loader.spec.d.ts delete mode 100644 packages/webpack/helpers/xml-namespace-loader.spec.ts delete mode 100644 packages/webpack/helpers/xml-namespace-loader.ts delete mode 100644 packages/webpack/hmr/hmr-update.d.ts delete mode 100644 packages/webpack/hmr/hmr-update.ts delete mode 100644 packages/webpack/hmr/hot-loader.d.ts delete mode 100644 packages/webpack/hmr/hot-loader.ts delete mode 100644 packages/webpack/hmr/index.d.ts delete mode 100644 packages/webpack/hmr/index.ts delete mode 100644 packages/webpack/host/resolver.d.ts delete mode 100644 packages/webpack/host/resolver.ts delete mode 100644 packages/webpack/index.js delete mode 100644 packages/webpack/index.spec.d.ts delete mode 100644 packages/webpack/index.spec.ts delete mode 100644 packages/webpack/installer.js delete mode 100644 packages/webpack/jasmine-config/jasmine.json delete mode 100644 packages/webpack/jasmine-config/reporter.d.ts delete mode 100644 packages/webpack/jasmine-config/reporter.ts delete mode 100644 packages/webpack/lib/after-prepare.js delete mode 100644 packages/webpack/lib/before-checkForChanges.js delete mode 100644 packages/webpack/lib/utils.js delete mode 100644 packages/webpack/nativescript-target/NsJsonpChunkTemplatePlugin.js delete mode 100644 packages/webpack/nativescript-target/NsJsonpMainTemplate.runtime.js delete mode 100644 packages/webpack/nativescript-target/NsJsonpMainTemplatePlugin.js delete mode 100644 packages/webpack/nativescript-target/NsJsonpTemplatePlugin.js delete mode 100644 packages/webpack/nativescript-target/index.js delete mode 100644 packages/webpack/package.json delete mode 100644 packages/webpack/plugins/GenerateBundleStarterPlugin.js delete mode 100644 packages/webpack/plugins/GenerateNativeScriptEntryPointsPlugin.js delete mode 100644 packages/webpack/plugins/NativeScriptAngularCompilerPlugin.d.ts delete mode 100644 packages/webpack/plugins/NativeScriptAngularCompilerPlugin.ts delete mode 100644 packages/webpack/plugins/NativeScriptSnapshotPlugin/index.js delete mode 100644 packages/webpack/plugins/NativeScriptSnapshotPlugin/options.json delete mode 100644 packages/webpack/plugins/PlatformFSPlugin.d.ts delete mode 100644 packages/webpack/plugins/PlatformFSPlugin.ts delete mode 100644 packages/webpack/plugins/PlatformSuffixPlugin.js delete mode 100644 packages/webpack/plugins/WatchStateLoggerPlugin.d.ts delete mode 100644 packages/webpack/plugins/WatchStateLoggerPlugin.ts delete mode 100644 packages/webpack/plugins/index.js delete mode 100644 packages/webpack/postinstall.js delete mode 100644 packages/webpack/preuninstall.js delete mode 100644 packages/webpack/project.json delete mode 100644 packages/webpack/snapshot/android/project-snapshot-generator-cli-ags-parser.js delete mode 100644 packages/webpack/snapshot/android/project-snapshot-generator.js delete mode 100644 packages/webpack/snapshot/android/snapshot-generator-tools/bundle-ending.js delete mode 100644 packages/webpack/snapshot/android/snapshot-generator-tools/bundle-preamble.js delete mode 100644 packages/webpack/snapshot/android/snapshot-generator-tools/include.gradle delete mode 100644 packages/webpack/snapshot/android/snapshot-generator-tools/ndk-build/.gitignore delete mode 100644 packages/webpack/snapshot/android/snapshot-generator-tools/ndk-build/jni/Android.mk delete mode 100644 packages/webpack/snapshot/android/snapshot-generator.js delete mode 100644 packages/webpack/snapshot/android/utils.js delete mode 100644 packages/webpack/templates/webpack.angular.js delete mode 100644 packages/webpack/templates/webpack.config.spec.d.ts delete mode 100644 packages/webpack/templates/webpack.config.spec.ts delete mode 100644 packages/webpack/templates/webpack.javascript.js delete mode 100644 packages/webpack/templates/webpack.react.js delete mode 100644 packages/webpack/templates/webpack.svelte.js delete mode 100644 packages/webpack/templates/webpack.typescript.js delete mode 100644 packages/webpack/templates/webpack.vue.js delete mode 100644 packages/webpack/transformers/ns-support-hmr-ng.d.ts delete mode 100644 packages/webpack/transformers/ns-support-hmr-ng.spec.d.ts delete mode 100644 packages/webpack/transformers/ns-support-hmr-ng.spec.ts delete mode 100644 packages/webpack/transformers/ns-support-hmr-ng.ts delete mode 100644 packages/webpack/transformers/ns-transform-native-classes-ng.d.ts delete mode 100644 packages/webpack/transformers/ns-transform-native-classes-ng.ts delete mode 100644 packages/webpack/transformers/ns-transform-native-classes.d.ts delete mode 100644 packages/webpack/transformers/ns-transform-native-classes.ts delete mode 100644 packages/webpack/tsconfig.json delete mode 100644 packages/webpack/unit-testing-config-loader.js delete mode 100644 packages/webpack/utils/ast-utils.d.ts delete mode 100644 packages/webpack/utils/ast-utils.ts delete mode 100644 packages/webpack/utils/transformers-utils.d.ts delete mode 100644 packages/webpack/utils/transformers-utils.ts delete mode 100644 packages/webpack/utils/tsconfig-utils.d.ts delete mode 100644 packages/webpack/utils/tsconfig-utils.ts delete mode 100644 packages/webpack/verify/update.js diff --git a/packages/webpack/.gitignore b/packages/webpack/.gitignore deleted file mode 100644 index fca848e3e..000000000 --- a/packages/webpack/.gitignore +++ /dev/null @@ -1,47 +0,0 @@ - -node_modules -*.tgz -package-lock.json -*.js.map - -plugins/NativeScriptAngularCompilerPlugin.d.ts -plugins/NativeScriptAngularCompilerPlugin.js - -transformers/*.d.ts -transformers/*.js - -utils/*.d.ts -utils/*.js - -hmr/*.d.ts -hmr/*.js - -plugins/PlatformFSPlugin.d.ts -plugins/PlatformFSPlugin.js - -plugins/WatchStateLoggerPlugin.d.ts -plugins/WatchStateLoggerPlugin.js - -host/resolver.d.ts -host/resolver.js - -jasmine-config/reporter.d.ts -jasmine-config/reporter.js - -bundle-config-loader.d.ts -bundle-config-loader.js - -xml-namespace-loader.d.ts -xml-namespace-loader.js - -css2json-loader.d.ts -css2json-loader.js - -**/*.spec.js* -**/*.spec.d.ts* - -hooks -.DS_Store -.nyc_output -coverage -!projectHelpers.spec.js diff --git a/packages/webpack/.npmignore b/packages/webpack/.npmignore deleted file mode 100644 index 58343b363..000000000 --- a/packages/webpack/.npmignore +++ /dev/null @@ -1,17 +0,0 @@ -build -demo - -*.ts -!*.d.ts - -*.spec.* -.vscode/ -.github/ -.nyc_output -coverage/ -jasmine-config/ -CONTRIBUTING.md -CODE_OF_CONDUCT.md -PULL_REQUEST_TESTS.md - -*.tgz diff --git a/packages/webpack/.nycrc b/packages/webpack/.nycrc deleted file mode 100644 index 3294892ac..000000000 --- a/packages/webpack/.nycrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "@istanbuljs/nyc-config-typescript", - "exclude": ["/demo/**"], - "reporter": ["text", "lcov"] -} \ No newline at end of file diff --git a/packages/webpack/CHANGELOG.md b/packages/webpack/CHANGELOG.md deleted file mode 100644 index d86d1d1df..000000000 --- a/packages/webpack/CHANGELOG.md +++ /dev/null @@ -1,1177 +0,0 @@ - -## [1.4.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/1.4.0...1.4.1) (2020-01-07) - - -### Bug Fixes - -* add missing tsconfig paths when the app is using only scoped modules and angular ([87ec157](https://github.com/NativeScript/nativescript-dev-webpack/commit/87ec157)) -* handle missing paths obj in tsconfig ([867a9f1](https://github.com/NativeScript/nativescript-dev-webpack/commit/867a9f1)) - - - -# [1.4.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/1.3.1...1.4.0) (2019-12-08) - -### Bug Fixes - -* add import of `.css` file into another `.css` file ([c5e4552](https://github.com/NativeScript/nativescript-dev-webpack/commit/c5e4552)) -* avoid duplicate modules from tns-core-modules and [@nativescript](https://github.com/nativescript)/core causing app crashes on Android ([b74b231](https://github.com/NativeScript/nativescript-dev-webpack/commit/b74b231)) -* bundle emitted on save without changes ([2d01df9](https://github.com/NativeScript/nativescript-dev-webpack/commit/2d01df9)), closes [/github.com/webpack/webpack/blob/4056506488c1e071dfc9a0127daa61bf531170bf/lib/Compiler.js#L326](https://github.com//github.com/webpack/webpack/blob/4056506488c1e071dfc9a0127daa61bf531170bf/lib/Compiler.js/issues/L326) -* fix module import of local css files ([2c0a36e](https://github.com/NativeScript/nativescript-dev-webpack/commit/2c0a36e)), closes [/github.com/webpack-contrib/css-loader/blob/967fb66da2545f04055eb0900a69f86e484dd842/src/utils.js#L220](https://github.com//github.com/webpack-contrib/css-loader/blob/967fb66da2545f04055eb0900a69f86e484dd842/src/utils.js/issues/L220) -* remove the tns-core-modules dependency in order to allow [@nativescrip](https://github.com/nativescrip)/core migration ([7d60958](https://github.com/NativeScript/nativescript-dev-webpack/commit/7d60958)) -* stop ignoring the initial hot updates ([d032e4c](https://github.com/NativeScript/nativescript-dev-webpack/commit/d032e4c)) -* stop on compilation error in typescript applications ([df7d122](https://github.com/NativeScript/nativescript-dev-webpack/commit/df7d122)) -* update worker loader in order to fix HMR ([5ad141e](https://github.com/NativeScript/nativescript-dev-webpack/commit/5ad141e)) - -### Features - -* snapshot in Docker on macOS with Android runtime 6.3.0 or higher as it will not contain snapshot tools for macOS anymore ([9e99683](https://github.com/NativeScript/nativescript-dev-webpack/commit/9e99683)) -* stop using the proxy `tns-core-modules` package when the `[@nativescript](https://github.com/nativescript)/core` is available ([061b270](https://github.com/NativeScript/nativescript-dev-webpack/commit/061b270)) - - - - -# [1.3.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/1.2.1...1.3.0) (2019-10-31) - - -### Bug Fixes - -* exclude files from tests folder from built application ([c61f10e](https://github.com/NativeScript/nativescript-dev-webpack/commit/c61f10e)) -* fix dependencies in package.json ([eefd042](https://github.com/NativeScript/nativescript-dev-webpack/commit/eefd042)), closes [/github.com/NativeScript/nativescript-dev-webpack/blob/master/bundle-config-loader.ts#L4](https://github.com//github.com/NativeScript/nativescript-dev-webpack/blob/master/bundle-config-loader.ts/issues/L4) [/github.com/NativeScript/nativescript-dev-webpack/blob/2978b81b5a8100774b2bb4a331ac8637205927b8/package.json#L54](https://github.com//github.com/NativeScript/nativescript-dev-webpack/blob/2978b81b5a8100774b2bb4a331ac8637205927b8/package.json/issues/L54) -* fix xxd path for local snapshots generation ([f63d493](https://github.com/NativeScript/nativescript-dev-webpack/commit/f63d493)) -* handle correctly webpack compilation errors ([363c4da](https://github.com/NativeScript/nativescript-dev-webpack/commit/363c4da)) -* handle imports like [@import](https://github.com/import) url("./xxx.css") ([8921120](https://github.com/NativeScript/nativescript-dev-webpack/commit/8921120)) -* search for the proper NDK executable on Windows ([f93bb6c](https://github.com/NativeScript/nativescript-dev-webpack/commit/f93bb6c)) -* Unbound namespace error with ios and android ([#1053](https://github.com/NativeScript/nativescript-dev-webpack/issues/1053)) ([6cd6efe](https://github.com/NativeScript/nativescript-dev-webpack/commit/6cd6efe)) - - -### Features - -* add useForImports option ([632af4f](https://github.com/NativeScript/nativescript-dev-webpack/commit/632af4f)) -* ensure valid CLI version when Windows snapshot is requested ([3a687c0](https://github.com/NativeScript/nativescript-dev-webpack/commit/3a687c0)) -* support [@nativescript](https://github.com/nativescript) scope in host resolver ([efda509](https://github.com/NativeScript/nativescript-dev-webpack/commit/efda509)) -* support useLibs though env.compileSnapshot and calculate the NDK path internally ([5431bd7](https://github.com/NativeScript/nativescript-dev-webpack/commit/5431bd7)) -* support V8 snapshots on Windows ([2e9b753](https://github.com/NativeScript/nativescript-dev-webpack/commit/2e9b753)) -* use css2json loader by default ([6b0c9ae](https://github.com/NativeScript/nativescript-dev-webpack/commit/6b0c9ae)) - - - - -## [1.2.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/1.2.0...1.2.1) (2019-10-03) - - -### Features - -* snapshot in docker container when the local tools are not available ([6861d22](https://github.com/NativeScript/nativescript-dev-webpack/commit/6861d22)) - - - - -# [1.2.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/1.1.1...1.2.0) (2019-09-03) - - -### Bug Fixes - -* register non-relative app.css module ([710acd7](https://github.com/NativeScript/nativescript-dev-webpack/commit/710acd7)) - - -### Features - -* support dynamic ES6 import ([4a07932](https://github.com/NativeScript/nativescript-dev-webpack/commit/4a07932)) - - - -## [1.1.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/1.1.0...1.1.1) (2019-08-22) - - -### Bug Fixes - -* add ia64 as supported architecture ([65d5d3f](https://github.com/NativeScript/nativescript-dev-webpack/commit/65d5d3f)) - - - - -# [1.1.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/1.0.2...1.1.0) (2019-08-19) - - -### Bug Fixes - -* **hmr:** check for hot update should not create new file ([c9656a9](https://github.com/NativeScript/nativescript-dev-webpack/commit/c9656a9)) - - -### Features - -* update to angular 8.2 ([d13441a](https://github.com/NativeScript/nativescript-dev-webpack/commit/d13441a)) - - - - -## [1.0.3](https://github.com/NativeScript/nativescript-dev-webpack/compare/1.0.2...1.0.3) (2019-08-05) - - -### Bug Fixes - -* crash with source-map instead of inline-source-map (https://github.com/NativeScript/nativescript-dev-webpack/issues/968) ([ff07d6c](https://github.com/NativeScript/nativescript-dev-webpack/commit/ff07d6c)) -* **update-ns-webpack:** skip the update of tsconfig.tns.json in… ([#1001](https://github.com/NativeScript/nativescript-dev-webpack/issues/1001)) ([2ed9850](https://github.com/NativeScript/nativescript-dev-webpack/commit/2ed9850)) - - - - -## [1.0.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/1.0.1...1.0.2) (2019-07-26) - - -### Bug Fixes - -* do not require `.js.map` files in the entry points when someone is using devtool: "source-map" ([#968](https://github.com/NativeScript/nativescript-dev-webpack/issues/968)) ([4bb6124](https://github.com/NativeScript/nativescript-dev-webpack/commit/4bb6124)) -* avoid getting invalid require calls when building from Windows ([#989](https://github.com/NativeScript/nativescript-dev-webpack/issues/989)) ([4799271](https://github.com/NativeScript/nativescript-dev-webpack/commit/4799271)) -* escape the regex for the path to the entry module of application ([#998](https://github.com/NativeScript/nativescript-dev-webpack/issues/998)) ([571c7f2](https://github.com/NativeScript/nativescript-dev-webpack/commit/571c7f2)) - - - -## [1.0.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/1.0.0...1.0.1) (2019-07-16) - - -### Bug Fixes - -* don't include partial scss files in bundle ([#988](https://github.com/NativeScript/nativescript-dev-webpack/issues/988)) ([786bd6c](https://github.com/NativeScript/nativescript-dev-webpack/commit/786bd6c)) -* **js:** try to resolve node_modules from the project root before resolving in a linked location ([#987](https://github.com/NativeScript/nativescript-dev-webpack/issues/987)) ([a3df142](https://github.com/NativeScript/nativescript-dev-webpack/commit/a3df142)) - - - -# [1.0.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.24.1...1.0.0) (2019-07-10) - - -### Bug Fixes - -* allow overriding the `global.process` object from both the app and the plugins ([8c4292e](https://github.com/NativeScript/nativescript-dev-webpack/commit/8c4292e)) -* auto accept new or deleted files ([#972](https://github.com/NativeScript/nativescript-dev-webpack/issues/972)) ([bd893ce](https://github.com/NativeScript/nativescript-dev-webpack/commit/bd893ce)) -* avoid generating invalid JavaScript when merging IIFE files ([7586d4c](https://github.com/NativeScript/nativescript-dev-webpack/commit/7586d4c)) -* create PropertyAssignment instead of string literal (Identifier) when modifying the NgModule - in some cases (e.g. when there is a decomposition in another NgModule property), the TypeScipt program is trying to read `node.name.kind` on each property causing an exception for Identifiers) ([a70fb3b](https://github.com/NativeScript/nativescript-dev-webpack/commit/a70fb3b)) -* do not add inspector_modules entry when core modules are an external module ([e0cd8c1](https://github.com/NativeScript/nativescript-dev-webpack/commit/e0cd8c1)) -* do not show warning for format differences in templates ([#947](https://github.com/NativeScript/nativescript-dev-webpack/issues/947)) ([a352064](https://github.com/NativeScript/nativescript-dev-webpack/commit/a352064)) -* don't restart application when lazy loaded code is changed in angular app with uglify option ([121c3b2](https://github.com/NativeScript/nativescript-dev-webpack/commit/121c3b2)) -* emit inspector_modules as a module ([be2a5a6](https://github.com/NativeScript/nativescript-dev-webpack/commit/be2a5a6)) -* fix app.css file path on windows machines ([7d734d8](https://github.com/NativeScript/nativescript-dev-webpack/commit/7d734d8)) -* fix hmr for platform specific files in linked plugins ([#946](https://github.com/NativeScript/nativescript-dev-webpack/issues/946)) ([9e8c921](https://github.com/NativeScript/nativescript-dev-webpack/commit/9e8c921)) -* follow the symlinks in JavaScript apps ([#941](https://github.com/NativeScript/nativescript-dev-webpack/issues/941)) ([f0c62fb](https://github.com/NativeScript/nativescript-dev-webpack/commit/f0c62fb)) -* hmr should work with uglify ([#953](https://github.com/NativeScript/nativescript-dev-webpack/issues/953)) ([874e4f8](https://github.com/NativeScript/nativescript-dev-webpack/commit/874e4f8)) -* **xml-ns-loader:** remove wrong register of xml ([#940](https://github.com/NativeScript/nativescript-dev-webpack/issues/940)) ([bc2f6f1](https://github.com/NativeScript/nativescript-dev-webpack/commit/bc2f6f1)) -* inject app.css file from unit-test-runner on test command ([#949](https://github.com/NativeScript/nativescript-dev-webpack/issues/949)) ([a216ed3](https://github.com/NativeScript/nativescript-dev-webpack/commit/a216ed3)) -* log the real snapshot tool error by trying to evaluate the input file script ([1a9c4b2](https://github.com/NativeScript/nativescript-dev-webpack/commit/1a9c4b2)) -* migrate demo apps to android x ([c2d6684](https://github.com/NativeScript/nativescript-dev-webpack/commit/c2d6684)) -* unify the entry points handling and enable custom applications in android ([de10041](https://github.com/NativeScript/nativescript-dev-webpack/commit/de10041)) -* **hooks:** improve hooks handling ([#961](https://github.com/NativeScript/nativescript-dev-webpack/issues/961)) ([f558607](https://github.com/NativeScript/nativescript-dev-webpack/commit/f558607)) - -### Features - -* introduce webpack only workflow ([#882](https://github.com/NativeScript/nativescript-dev-webpack/issues/882)) ([2de4c68](https://github.com/NativeScript/nativescript-dev-webpack/commit/2de4c68)) -* no need of "page" suffix ([#966](https://github.com/NativeScript/nativescript-dev-webpack/pull/966)) ([d4a8dec](https://github.com/NativeScript/nativescript-dev-webpack/commit/d4a8dec803acf39b7cdeb4f3bc8c23284046fe67)) -* support for file qualifiers ([#966](https://github.com/NativeScript/nativescript-dev-webpack/pull/966)) ([d4a8dec](https://github.com/NativeScript/nativescript-dev-webpack/commit/d4a8dec803acf39b7cdeb4f3bc8c23284046fe67)) -* universal hmr loader ([#966](https://github.com/NativeScript/nativescript-dev-webpack/pull/966)) ([d4a8dec](https://github.com/NativeScript/nativescript-dev-webpack/commit/d4a8dec803acf39b7cdeb4f3bc8c23284046fe67)) - -### BREAKING CHANGES: - -* the file names of the NativeScript pages are not required to end with `-page` or `-root`. All `xml`, `css`, `js`, `ts` and `scss` files are not included in the bundle. - -* the plugin is not working with NativeScript CLI older than 6.0.0 (`nativescript@6.0.0`). - -* the Webpack mode it set to `production` based on the `--release` flag of the NativeScript CLI, instead of the `--env.uglify` one. - - -## [0.24.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.24.0...0.24.1) (2019-06-06) - - -### Bug Fixes - -* move the type check to a child process in order to make it faster in bigger apps and unify the hmr and no-hmr experience. ([#926](https://github.com/NativeScript/nativescript-dev-webpack/issues/926)) ([1398179](https://github.com/NativeScript/nativescript-dev-webpack/commit/1398179)) -* stop generating .d.ts on TS compilation ([#919](https://github.com/NativeScript/nativescript-dev-webpack/issues/919)) ([ccbf8de](https://github.com/NativeScript/nativescript-dev-webpack/commit/ccbf8de)) - - - - -# [0.24.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.22.0...0.24.0) (2019-05-30) - - -### Bug Fixes - -* import the workaroundResolve funciton based on the Angular version (it was moved from compiler_host to utils in Angular 8) ([#904](https://github.com/NativeScript/nativescript-dev-webpack/pull/904)) ([56224a8](https://github.com/NativeScript/nativescript-dev-webpack/commit/56224a898b46fc8542f8b5928c52e9e4cb6022e2)) - - -### Features - -* update deps to Angular 8.0.0 deps ([#904](https://github.com/NativeScript/nativescript-dev-webpack/pull/904)) ([d6afb74](https://github.com/NativeScript/nativescript-dev-webpack/commit/d6afb7436585d41c4188a2373d376f2b51bc541e)) - - - - -# [0.22.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.21.0...0.22.0) (2019-05-15) - - -### Bug Fixes - -* ignore the Webpack runtime chunks when sending HMR updates ([be82ab7](https://github.com/NativeScript/nativescript-dev-webpack/commit/be82ab7)) -* show proper stack traces from uglified code (split by new line instead of semicolon) ([0ae6030](https://github.com/NativeScript/nativescript-dev-webpack/commit/0ae6030)) -* sourceMap not generated with Uglify ([#819](https://github.com/NativeScript/nativescript-dev-webpack/issues/819)) ([b5fd066](https://github.com/NativeScript/nativescript-dev-webpack/commit/b5fd066)) -* support platform specific files that are not directly imported anywhere in the app ([#843](https://github.com/NativeScript/nativescript-dev-webpack/issues/843)) ([e1e9463](https://github.com/NativeScript/nativescript-dev-webpack/commit/e1e9463)) -* update the css loader in order to fix a bug with leading dashes of css classes ([#847](https://github.com/NativeScript/nativescript-dev-webpack/issues/847)) ([7670e33](https://github.com/NativeScript/nativescript-dev-webpack/commit/7670e33)) -* **hmr:** run ts-loader in transpileOnly mode ([#878](https://github.com/NativeScript/nativescript-dev-webpack/issues/878)) ([0317729](https://github.com/NativeScript/nativescript-dev-webpack/commit/0317729)) - - -### Features - -* replace UglifyJs with Terser ([621090a](https://github.com/NativeScript/nativescript-dev-webpack/commit/621090a)) -* support hidden source maps to map error stack traces from crash reports ([#854](https://github.com/NativeScript/nativescript-dev-webpack/issues/854)) ([dbcfbc2](https://github.com/NativeScript/nativescript-dev-webpack/commit/dbcfbc2)) - - - -## [0.21.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.21.0...0.21.2) (2019-04-22) - - -### Bug Fixes - -* add support for executing unit tests for vue projects ([#870](https://github.com/NativeScript/nativescript-dev-webpack/issues/870)) ([c8afe9f](https://github.com/NativeScript/nativescript-dev-webpack/commit/c8afe9f)) - - - - -## [0.21.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.21.0...0.21.1) (2019-04-18) - - -### Bug Fixes - -* add support for ts files on test command when `--bundle` is provided ([#848](https://github.com/NativeScript/nativescript-dev-webpack/issues/848)) ([bd4fa9c](https://github.com/NativeScript/nativescript-dev-webpack/commit/bd4fa9c)) -* fix "ERROR in Must have a source file to refactor." error from ngCompilerPlugin on `test` command ([#859](https://github.com/NativeScript/nativescript-dev-webpack/issues/859)) ([196d977](https://github.com/NativeScript/nativescript-dev-webpack/commit/196d977)) -* typescript source maps are containing javascript code ([#857](https://github.com/NativeScript/nativescript-dev-webpack/issues/857)) ([384bee2](https://github.com/NativeScript/nativescript-dev-webpack/commit/384bee2)) -* use correct slashes on windows ([#851](https://github.com/NativeScript/nativescript-dev-webpack/issues/851)) ([9020c47](https://github.com/NativeScript/nativescript-dev-webpack/commit/9020c47)) - - - - -# [0.21.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.20.3...0.21.0) (2019-03-21) - - -### Bug Fixes - -* Emit inspector_modules.js as a separate entry point for iOS ([00ecaa0](https://github.com/NativeScript/nativescript-dev-webpack/commit/00ecaa0)) -* execute bundle-config-loader only for the entry point of the application ([#829](https://github.com/NativeScript/nativescript-dev-webpack/issues/829)) ([36824b1](https://github.com/NativeScript/nativescript-dev-webpack/commit/36824b1)) -* fix "Cannot read property 'kill' of undefined" error ([#822](https://github.com/NativeScript/nativescript-dev-webpack/issues/822)) ([8d18853](https://github.com/NativeScript/nativescript-dev-webpack/commit/8d18853)) -* stop deleting chunks with compilation errors in order to avoid outdated app state when deleting files or throwing errors ([#836](https://github.com/NativeScript/nativescript-dev-webpack/issues/836)) ([69cb061](https://github.com/NativeScript/nativescript-dev-webpack/commit/69cb061)) -* **HMR:** modulePath on Windows to apply changes in app styles at runtime ([#807](https://github.com/NativeScript/nativescript-dev-webpack/issues/807)) ([c4b4fee](https://github.com/NativeScript/nativescript-dev-webpack/commit/c4b4fee)) -* **inspector_modules:** Switch to `single` runtime chunk ([6e780af](https://github.com/NativeScript/nativescript-dev-webpack/commit/6e780af)) - - -### Features - -* Implement unit testing with bundle ([#835](https://github.com/NativeScript/nativescript-dev-webpack/issues/835)) ([7944611](https://github.com/NativeScript/nativescript-dev-webpack/commit/7944611)) -* Support Angular Ivy modules with AOT ([#828](https://github.com/NativeScript/nativescript-dev-webpack/issues/828)) ([f476c56](https://github.com/NativeScript/nativescript-dev-webpack/commit/f476c56)) - - - - -## [0.20.3](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.20.2...0.20.3) (2019-03-14) - - -### Bug Fixes - -* initial compilation always generates same compilation hash ([#815](https://github.com/NativeScript/nativescript-dev-webpack/issues/815)) ([ba6d896](https://github.com/NativeScript/nativescript-dev-webpack/commit/ba6d896)) -* show message for stopping webpack only when it has been started ([#821](https://github.com/NativeScript/nativescript-dev-webpack/issues/821)) ([1bd18e5](https://github.com/NativeScript/nativescript-dev-webpack/commit/1bd18e5)) -* **HMR:** modulePath on Windows to apply changes in app styles at runtime ([#807](https://github.com/NativeScript/nativescript-dev-webpack/issues/807)) ([cc55d4f](https://github.com/NativeScript/nativescript-dev-webpack/commit/cc55d4f)) - - -### Features - -* **Vue:** option to enable sourcemaps ([#774](https://github.com/NativeScript/nativescript-dev-webpack/issues/774)) ([70cd58a](https://github.com/NativeScript/nativescript-dev-webpack/commit/70cd58a)) - - - - -## [0.20.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.20.0...0.20.1) (2019-02-18) - - -### Bug Fixes - -* add a typescript module resolution when searching for the main Angular module location ([#800](https://github.com/NativeScript/nativescript-dev-webpack/issues/800)) ([e2714f2](https://github.com/NativeScript/nativescript-dev-webpack/commit/e2714f2)) - - -### Features - -* allow angular resolver configuration via webpack.config ([4f3e8a6](https://github.com/NativeScript/nativescript-dev-webpack/commit/4f3e8a6)) -* backwards compatible angular resolver options ([c9fc731](https://github.com/NativeScript/nativescript-dev-webpack/commit/c9fc731)) - - - - -# [0.20.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.19.2...0.20.0) (2019-02-08) - - -### Bug Fixes - -* some packages are treated as externals when they shouldn't ([#771](https://github.com/NativeScript/nativescript-dev-webpack/issues/771)) ([3362cd6](https://github.com/NativeScript/nativescript-dev-webpack/commit/3362cd6)) - - -### Features - -* support HMR in Angular apps ([#788](https://github.com/NativeScript/nativescript-dev-webpack/issues/788)) ([6a9ce33](https://github.com/NativeScript/nativescript-dev-webpack/commit/6a9ce33)) -* **Angular:** apply changes in application styles at runtime with HMR ([#748](https://github.com/NativeScript/nativescript-dev-webpack/issues/748)) ([fe4abfb](https://github.com/NativeScript/nativescript-dev-webpack/commit/fe4abfb)) -* **snapshot:** the parameters passed to mksnapshot are now retrieved… ([#789](https://github.com/NativeScript/nativescript-dev-webpack/issues/789)) ([cb68dac](https://github.com/NativeScript/nativescript-dev-webpack/commit/cb68dac)) - -### BREAKING CHANGES - -* Hot Module Replacement in NativeScript Angular Project - -This version enables the *Hot Module Replacement* feature in NativeScript Angular projects by default. - -So far it was required to add a snippet to enable HMR. With this release, you have to __remove__ any previous `module["hot"]` related code so HMR can work out of the box. - -However, if you want to continue handling *hot* changes manually, follow [these](https://github.com/NativeScript/nativescript-angular/wiki/NativeScript-5.2-HMR-with-Angular#how-to-manually-enable-hmr-in-nativescript-angular-projects-with-n-52) instructions. - -### Migration - -Please, refer to [this](https://github.com/NativeScript/nativescript-angular/wiki/NativeScript-5.2-HMR-with-Angular) wiki page for detailed information. - - -## [0.19.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.19.1...0.19.2) (2019-02-01) - - -### Bug Fixes - -* optimize platform specific files resolver ([#782](https://github.com/NativeScript/nativescript-dev-webpack/issues/782)) ([fb52c53](https://github.com/NativeScript/nativescript-dev-webpack/commit/fb52c53)) - - - - -## [0.19.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.19.0...0.19.1) (2019-01-28) - - -### Bug Fixes - -* **Vue:** apply style changes with HMR ([#763](https://github.com/NativeScript/nativescript-dev-webpack/issues/763)) ([#777](https://github.com/NativeScript/nativescript-dev-webpack/issues/777)) ([8ee1880](https://github.com/NativeScript/nativescript-dev-webpack/commit/8ee1880)), closes [#744](https://github.com/NativeScript/nativescript-dev-webpack/issues/744) [#742](https://github.com/NativeScript/nativescript-dev-webpack/issues/742) [#762](https://github.com/NativeScript/nativescript-dev-webpack/issues/762) -* **debugging:** lazy-ngmodule-hot-loader breaks the sourceMaps ([#770](https://github.com/NativeScript/nativescript-dev-webpack/issues/770)) ([aca851c](https://github.com/NativeScript/nativescript-dev-webpack/commit/aca851c)) - - - - -# [0.19.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.18.5...0.19.0) (2019-01-03) - - -### Bug Fixes - -* **angular:** support angular lazy routes in preview ([#753](https://github.com/NativeScript/nativescript-dev-webpack/issues/753)) ([a6c23da](https://github.com/NativeScript/nativescript-dev-webpack/commit/a6c23da)) -* **Angular:** add hot loader for lazy loaded NgModules ([#747](https://github.com/NativeScript/nativescript-dev-webpack/issues/747)) ([6a9db32](https://github.com/NativeScript/nativescript-dev-webpack/commit/6a9db32)) -* **Vue:** disable mangling of function names when building in production mode ([#743](https://github.com/NativeScript/nativescript-dev-webpack/issues/743)) ([fffcf66](https://github.com/NativeScript/nativescript-dev-webpack/commit/fffcf66)), closes [/github.com/NativeScript/nativescript-dev-webpack/blob/master/CONTRIBUTING.md#testing-locally-by-running-e2](https://github.com//github.com/NativeScript/nativescript-dev-webpack/blob/master/CONTRIBUTING.md/issues/testing-locally-by-running-e2) - - -### Features - -* **TypeScript:** use `ts-loader` instead of `awesome-typescript-loader` ([#738](https://github.com/NativeScript/nativescript-dev-webpack/issues/738)) ([7f67198](https://github.com/NativeScript/nativescript-dev-webpack/commit/7f67198)) - - -### BREAKING CHANGES - -* **Angular:** The `lazy-ngmodule-hot-loader` should be added to the webpack configuration. - -**BEFORE** -``` js -// webpack.config.js - { - test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/, - use: [ - "nativescript-dev-webpack/moduleid-compat-loader", - "@ngtools/webpack", - ] - }, -// ... -``` - -**AFTER** -``` js -// webpack.config.js - { - test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/, - use: [ - "nativescript-dev-webpack/moduleid-compat-loader", - "nativescript-dev-webpack/lazy-ngmodule-hot-loader", - "@ngtools/webpack", - ] - }, -// ... -``` - - - - -## [0.18.5](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.18.3...0.18.5) (2018-12-17) - - -### Bug Fixes - -* **JS/TS:** use webpack resolver instead of Node.js resolver ([#681](https://github.com/NativeScript/nativescript-dev-webpack/issues/681)) ([9adc7e7](https://github.com/NativeScript/nativescript-dev-webpack/commit/9adc7e7)) -* **Vue:** resolve full path for entry module ([#744](https://github.com/NativeScript/nativescript-dev-webpack/issues/744)) ([4d31ea0](https://github.com/NativeScript/nativescript-dev-webpack/commit/4d31ea0)), closes [#742](https://github.com/NativeScript/nativescript-dev-webpack/issues/742) - - -### Features - -* **Vue:** add support for TypeScript ([#734](https://github.com/NativeScript/nativescript-dev-webpack/issues/734)) ([d290515](https://github.com/NativeScript/nativescript-dev-webpack/commit/d290515)) - - - - -## [0.18.3](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.18.2...0.18.3) (2018-12-10) - - -### Bug Fixes - -* project's package.json indentation is not persisted ([#727](https://github.com/NativeScript/nativescript-dev-webpack/issues/727)) ([a45a45c](https://github.com/NativeScript/nativescript-dev-webpack/commit/a45a45c)) - - - - -## [0.18.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.18.1...0.18.2) (2018-12-06) - - -### Bug Fixes - -* avoid getting `js` template in a `ts` project ([#717](https://github.com/NativeScript/nativescript-dev-webpack/issues/717)) ([c121c24](https://github.com/NativeScript/nativescript-dev-webpack/commit/c121c24)) - - -### Features - -* **HMR:** expose context ([#724](https://github.com/NativeScript/nativescript-dev-webpack/issues/724)) ([c14110c](https://github.com/NativeScript/nativescript-dev-webpack/commit/c14110c)) - - - - -## [0.18.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.18.0...0.18.1) (2018-12-03) - - -### Bug Fixes - -* avoid getting `js` template in a `ts` project ([#717](https://github.com/NativeScript/nativescript-dev-webpack/issues/717)) ([c121c24](https://github.com/NativeScript/nativescript-dev-webpack/commit/c121c24)) - - - - -# [0.18.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.17.0...0.18.0) (2018-11-13) - - -### Bug Fixes - -* globs usage in CopyWebpackPlugin ([#700](https://github.com/NativeScript/nativescript-dev-webpack/issues/700)) ([4782bf6](https://github.com/NativeScript/nativescript-dev-webpack/commit/4782bf6)) - - -### Features -* Angular 7 support - - - -# [0.17.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.17.0-rc.1...0.17.0) (2018-10-31) - -Version 0.17.0 introduces initial **Hot Module Replacement** support for plain JavaScript, TypeScript and Vue applications. - -> Note: find out [here](https://github.com/NativeScript/nativescript-angular/wiki/HMR) how to enable HMR for Angular projects. - -For more details, refer to [0.17.0-rc.1](https://github.com/NativeScript/nativescript-dev-webpack/blob/master/CHANGELOG.md#0170-rc1-2018-10-25) and [0.17.0-rc.0](https://github.com/NativeScript/nativescript-dev-webpack/blob/master/CHANGELOG.md#0170-rc0-2018-10-17) changelogs below. - - -# [0.17.0-rc.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.17.0-rc.0...0.17.0-rc.1) (2018-10-25) - - -### Bug Fixes - -* update the version of `request` ([#694](https://github.com/NativeScript/nativescript-dev-webpack/issues/694)) ([39b858b](https://github.com/NativeScript/nativescript-dev-webpack/commit/39b858b)) - - -# [0.16.3](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.16.2...0.16.3) (2018-10-25) - - -### Bug Fixes - -* update the version of `request` ([#694](https://github.com/NativeScript/nativescript-dev-webpack/issues/694)) ([39b858b](https://github.com/NativeScript/nativescript-dev-webpack/commit/39b858b)) - - -# [0.17.0-rc.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.16.2...0.17.0-rc.0) (2018-10-17) - - -### Bug Fixes - -* add a check for undefined environment values ([#673](https://github.com/NativeScript/nativescript-dev-webpack/issues/673)) ([c81484f](https://github.com/NativeScript/nativescript-dev-webpack/commit/c81484f)) -* **uglify:** cache/parallel should be outside uglifyOptions ([#670](https://github.com/NativeScript/nativescript-dev-webpack/issues/670)) ([e15fec7](https://github.com/NativeScript/nativescript-dev-webpack/commit/e15fec7)) -* attach to process's exit event on correct place ([#671](https://github.com/NativeScript/nativescript-dev-webpack/issues/671)) ([f4b40bf](https://github.com/NativeScript/nativescript-dev-webpack/commit/f4b40bf)) - - -### Features - -* add initial HMR support for plain JS/TS apps ([#645](https://github.com/NativeScript/nativescript-dev-webpack/issues/645)) ([a4ac32b](https://github.com/NativeScript/nativescript-dev-webpack/commit/a4ac32b)) -* add hook for the preview command ([#649](https://github.com/NativeScript/nativescript-dev-webpack/issues/649)) ([b47da3c](https://github.com/NativeScript/nativescript-dev-webpack/commit/b47da3c)) -* add Vue bundling support ([#676](https://github.com/NativeScript/nativescript-dev-webpack/issues/676)) ([8da8ccf](https://github.com/NativeScript/nativescript-dev-webpack/commit/8da8ccf)) - - - -## [0.16.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.16.0...0.16.2) (2018-09-28) - - -### Bug Fixes - -* update webpack dependencies ([#675](https://github.com/NativeScript/nativescript-dev-webpack/issues/675)) ([71cb30c](https://github.com/NativeScript/nativescript-dev-webpack/commit/71cb30c)), closes [#674](https://github.com/NativeScript/nativescript-dev-webpack/issues/674) - - - -## [0.16.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.16.0...0.16.1) (2018-09-17) - - -### Bug Fixes - -* **angular:** AoT rebuild on template and style changes ([#659](https://github.com/NativeScript/nativescript-dev-webpack/issues/659)) ([d812d5d](https://github.com/NativeScript/nativescript-dev-webpack/commit/d812d5d)), closes [#641](https://github.com/NativeScript/nativescript-dev-webpack/issues/641) - - - - -# [0.16.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.15.1...0.16.0) (2018-09-10) - - -### Features - -* NativeScript bootstrap transformer ([#634](https://github.com/NativeScript/nativescript-dev-webpack/issues/634)) ([c016418](https://github.com/NativeScript/nativescript-dev-webpack/commit/c016418)) - - - - -# [0.15.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.15.0...0.15.1) (2018-08-07) - - -### Bug Fixes - -* define process as undefined ([#619](https://github.com/NativeScript/nativescript-dev-webpack/issues/619)) ([845f426](https://github.com/NativeScript/nativescript-dev-webpack/commit/845f426)) - - - -# [0.15.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.14.4...0.15.0) (2018-07-24) - - -### Bug Fixes - -* **angular:** fix livesync for platform-specific files ([#615](https://github.com/NativeScript/nativescript-dev-webpack/issues/615)) ([93c5f77](https://github.com/NativeScript/nativescript-dev-webpack/commit/93c5f77)), closes [#611](https://github.com/NativeScript/nativescript-dev-webpack/issues/611) [#601](https://github.com/NativeScript/nativescript-dev-webpack/issues/601) -* array env args are serialized when sent to webpack ([#614](https://github.com/NativeScript/nativescript-dev-webpack/issues/614)) ([bfecb8c](https://github.com/NativeScript/nativescript-dev-webpack/commit/bfecb8c)) - - -### Features - -* **xml-namespace-loader:** add ignore option ([#605](https://github.com/NativeScript/nativescript-dev-webpack/issues/605)) ([b509bb3](https://github.com/NativeScript/nativescript-dev-webpack/commit/b509bb3)), closes [#558](https://github.com/NativeScript/nativescript-dev-webpack/issues/558) -* **debug**: generate source maps when running `tns debug --bundle` ([#617](https://github.com/NativeScript/nativescript-dev-webpack/pull/617)) - - - -## [0.14.3](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.14.2...0.14.3) (2018-07-05) - - -### Bug Fixes - -* Angular projects: the plugin will add `@ngtools/webpack` to the project deps only if `@angular-devkit/build-angular` is not a dependency. ([#594](https://github.com/NativeScript/nativescript-dev-webpack/issues/594)) ([7b15418](https://github.com/NativeScript/nativescript-dev-webpack/commit/7b15418)), closes [#595](https://github.com/NativeScript/nativescript-dev-webpack/issues/595) - - -### Migration - -It's a good idea to remove `@angular-devkit/build-angular` from the -package.json and add `@ngtools/webpack` instead. This will speed up -the build. - - - -## [0.14.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.14.1...0.14.2) (2018-06-27) - - -### Bug Fixes - -* resolve appComponents and xml namespaces absolute paths on Windows ([#578](https://github.com/NativeScript/nativescript-dev-webpack/issues/578)) ([14de7e1](https://github.com/NativeScript/nativescript-dev-webpack/commit/14de7e1)) -* tell the {N} CLI to ignore the source dir when watching for changes ([#586](https://github.com/NativeScript/nativescript-dev-webpack/issues/586)) ([6b0f56b](https://github.com/NativeScript/nativescript-dev-webpack/commit/6b0f56b)), closes [#584](https://github.com/NativeScript/nativescript-dev-webpack/issues/584) - - -### Features - -* add setting for plain modules regex ([#582](https://github.com/NativeScript/nativescript-dev-webpack/issues/582)) ([404abbb](https://github.com/NativeScript/nativescript-dev-webpack/commit/404abbb)), closes [#556](https://github.com/NativeScript/nativescript-dev-webpack/issues/556) - - - - -## [0.14.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.14.0...0.14.1) (2018-06-22) - - -### Bug Fixes - -* schema-utils peer dep warning for webpack 2/3 ([#577](https://github.com/NativeScript/nativescript-dev-webpack/issues/577)) ([afe569d](https://github.com/NativeScript/nativescript-dev-webpack/commit/afe569d)) -* **AoT:** stop using require.context in Angular apps ([#574](https://github.com/NativeScript/nativescript-dev-webpack/issues/574)) ([23aaee9](https://github.com/NativeScript/nativescript-dev-webpack/commit/23aaee9)), closes [/github.com/angular/angular-cli/blob/master/packages/ngtools/webpack/src/compiler_host.ts#L235](https://github.com//github.com/angular/angular-cli/blob/master/packages/ngtools/webpack/src/compiler_host.ts/issues/L235) [#566](https://github.com/NativeScript/nativescript-dev-webpack/issues/566) - - -### Features - -* add platform matching host for AngularCompilerPlugin ([#539](https://github.com/NativeScript/nativescript-dev-webpack/issues/539)) ([979f732](https://github.com/NativeScript/nativescript-dev-webpack/commit/979f732)), closes [#547](https://github.com/NativeScript/nativescript-dev-webpack/issues/547) -* make webpack deps production deps of the plugin ([#571](https://github.com/NativeScript/nativescript-dev-webpack/issues/571)) ([ba68a1b](https://github.com/NativeScript/nativescript-dev-webpack/commit/ba68a1b)), closes [#569](https://github.com/NativeScript/nativescript-dev-webpack/issues/569) - - -### BREAKING CHANGES - -* The dependencies that were previously added by the nativescript-dev-webpack plugin to the project's package.json are now dependencies of the plugin itself. - -MIGRATION: -1. Remove all obsolete dependencies from your project. You can do that by invoking the script: -``` -./node_modules/.bin/update-ns-webpack --deps -``` -2. [Angular] Add the following packages as devDependencies: -``` -//package.json - -"devDependencies": { - "@angular-devkit/build-angular": "~0.7.0-rc.0", - "@angular/compiler-cli": "~6.1.0-beta.1", - //... -} -``` - - - - -# [0.14.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.13.0...0.14.0) (2018-06-22) - - -### Bug Fixes - -* register UI modules in NG apps ([#570](https://github.com/NativeScript/nativescript-dev-webpack/issues/570)) ([c27e0db](https://github.com/NativeScript/nativescript-dev-webpack/commit/c27e0db)) - - -### Features - -* make webpack deps production deps of the plugin ([#571](https://github.com/NativeScript/nativescript-dev-webpack/issues/571)) ([ba68a1b](https://github.com/NativeScript/nativescript-dev-webpack/commit/ba68a1b)), closes [#569](https://github.com/NativeScript/nativescript-dev-webpack/issues/569) - - -### BREAKING CHANGES - -* The dependencies that were previously added by the nativescript-dev-webpack plugin to the project's package.json are now dependencies of the plugin itself. - -MIGRATION: -1. Remove all obsolete dependencies from your project. You can do that by invoking the script: -``` -./node_modules/.bin/update-ns-webpack --deps -``` -2. [Angular] Add the following packages as devDependencies: -``` -//package.json - -"devDependencies": { - "@angular-devkit/build-angular": "~0.7.0-rc.0", - "@angular/compiler-cli": "~6.1.0-beta.1", - //... -} -``` - -If you see one of the following errors: -``` -Error: Cannot find module '@ngtools/webpack' -Error: No module factory available for dependency type: ContextElementDependency -Error: Cannot find module '/Users/nsbuilduser/workspace/master-nativescript-sdk-examples-js-android/nativescript-sdk-examples-js/node_modules/webpack/bin/webpack.js -``` - -try running a clean npm install: -``` -rm -rf node_modules package-lock.json -npm i -``` - - - - -# [0.13.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.12.0...0.13.0) (2018-06-13) - - -### Features - -* add platform matching host for AngularCompilerPlugin ([#539](https://github.com/NativeScript/nativescript-dev-webpack/issues/539)) ([979f732](https://github.com/NativeScript/nativescript-dev-webpack/commit/979f732)), closes [#547](https://github.com/NativeScript/nativescript-dev-webpack/issues/547) - - -### Bug Fixes - -* Webpack recompile fails when using AoT with watch mode ([#547](https://github.com/NativeScript/nativescript-dev-webpack/issues/547)) ([979f732](https://github.com/NativeScript/nativescript-dev-webpack/commit/979f732)), closes [#547](https://github.com/NativeScript/nativescript-dev-webpack/issues/547) - - - - -# [0.12.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.11.0...0.12.0) (2018-05-30) - -> You can follow the [Migration guide](https://www.nativescript.org/blog/upgrading-to-nativescript-webpack-0.12.0) for upgrading to this version. - - -### Bug Fixes - -* allow using the plugin via symlink ([#501](https://github.com/NativeScript/nativescript-dev-webpack/issues/501)) ([a7acb4d](https://github.com/NativeScript/nativescript-dev-webpack/commit/a7acb4d)) -* bundling of Angular apps using linked TS plugins ([#505](https://github.com/NativeScript/nativescript-dev-webpack/issues/505)) ([41779ad](https://github.com/NativeScript/nativescript-dev-webpack/commit/41779ad)) -* bundling of ts apps using linked plugins ([#530](https://github.com/NativeScript/nativescript-dev-webpack/issues/530)) ([c7117d7](https://github.com/NativeScript/nativescript-dev-webpack/commit/c7117d7)) -* register XML-only custom components ([#537](https://github.com/NativeScript/nativescript-dev-webpack/issues/537)) ([aaf4e88](https://github.com/NativeScript/nativescript-dev-webpack/commit/aaf4e88)) - - -### Features - -* add webpack 4 and Angular 6 support ([#495](https://github.com/NativeScript/nativescript-dev-webpack/issues/495)) ([eefce39](https://github.com/NativeScript/nativescript-dev-webpack/commit/eefce39)) -* add xml loader for elements from external namespaces ([#525](https://github.com/NativeScript/nativescript-dev-webpack/issues/525)) ([19bbc7e](https://github.com/NativeScript/nativescript-dev-webpack/commit/19bbc7e)) -* configure v8Version for snapshot tools ([#503](https://github.com/NativeScript/nativescript-dev-webpack/issues/503)) ([cf0d76b](https://github.com/NativeScript/nativescript-dev-webpack/commit/cf0d76b)) -* generate the snapshot entry module at build time ([2ec8083](https://github.com/NativeScript/nativescript-dev-webpack/commit/2ec8083)), closes [#511](https://github.com/NativeScript/nativescript-dev-webpack/issues/511) -* load bundle config and app css at build time ([f9bbea9](https://github.com/NativeScript/nativescript-dev-webpack/commit/f9bbea9)) -* move all node modules to the common chunk ([#507](https://github.com/NativeScript/nativescript-dev-webpack/issues/507)) ([2ff43bf](https://github.com/NativeScript/nativescript-dev-webpack/commit/2ff43bf)) -* tweak the uglify configuration to enable compression for android ([7a125ee](https://github.com/NativeScript/nativescript-dev-webpack/commit/7a125ee)) -* target es2015 modules when bundling using tsconfig.esm.json file. ([8922c96])(https://github.com/NativeScript/nativescript-dev-webpack/commit/8922c9611e756d165ec6ca454c237b6bcb56b8ef) - - - -# [0.11.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.10.2...0.11.0) (2018-04-25) - - -### Bug Fixes - -* allow using the plugin via symlink ([#501](https://github.com/NativeScript/nativescript-dev-webpack/issues/501)) ([a7acb4d](https://github.com/NativeScript/nativescript-dev-webpack/commit/a7acb4d)) -* bundling of Angular apps using linked TS plugins ([#505](https://github.com/NativeScript/nativescript-dev-webpack/issues/505)) ([41779ad](https://github.com/NativeScript/nativescript-dev-webpack/commit/41779ad)) - - -### Features - -* configure v8Version for snapshot tools ([#503](https://github.com/NativeScript/nativescript-dev-webpack/issues/503)) ([cf0d76b](https://github.com/NativeScript/nativescript-dev-webpack/commit/cf0d76b)) - -### BREAKING CHANGES - -> The command below will overwrite the existing project's webpack configuration files with the most recent ones, so you don't have to manually apply the required changes: -> ``` -> ./node_modules/.bin/update-ns-webpack --configs -> ``` - -* The NativeScriptAngularCompilerPlugin is loaded in a different way now. The existing projects using the plugin should add the following line to their `webpack.config.js` file: -``` js -// webpack.config.js - -module.exports = env => { - const platform = env && (env.android && "android" || env.ios && "ios"); - if (!platform) { - throw new Error("You need to provide a target platform!"); - } - - const platforms = ["ios", "android"]; - const projectRoot = __dirname; - nsWebpack.loadAdditionalPlugins({ projectDir: projectRoot }); // <----- Add this line - - // ... -``` - -* The `getAppPath` method expects two arguments now - `platform` and `projectRoot`. The usage inside the project's `webpack.config.js` should be changed in the following way: - -Before: -``` js -// webpack.config.js - -// Default destination inside platforms//... -const dist = resolve(projectRoot, nsWebpack.getAppPath(platform)); - -// ... -``` - -After: -``` js -// webpack.config.js - -// Default destination inside platforms//... -const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - -// ... -``` - - - - -## [0.10.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.10.1...0.10.2) (2018-04-18) - - -### Bug Fixes - -* **hooks:** do not set INIT_CWD on any hook ([#494](https://github.com/NativeScript/nativescript-dev-webpack/issues/494)) ([afe6208](https://github.com/NativeScript/nativescript-dev-webpack/commit/afe6208)) - - - -## [0.10.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.10.0...0.10.1) (2018-04-11) - - -### Bug Fixes - -* **configs/angular:** use path relative to the appDir for the root ([8e7aa0c](https://github.com/NativeScript/nativescript-dev-webpack/commit/8e7aa0c)) - - -# [0.10.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.9.1...0.10.0) (2018-04-05) - -> You need NativeScript 4.0 for using the new features from this version. - -### Bug Fixes - -* **hooks:** `after-watch` hook is not executed ([#483](https://github.com/NativeScript/nativescript-dev-webpack/issues/483)) ([a61cff4](https://github.com/NativeScript/nativescript-dev-webpack/commit/a61cff4)) -* allow snapshot only in release ([#448](https://github.com/NativeScript/nativescript-dev-webpack/issues/448)) ([2dd9adc](https://github.com/NativeScript/nativescript-dev-webpack/commit/2dd9adc)) -* clean snapshot artifacts on cleanApp hook ([#423](https://github.com/NativeScript/nativescript-dev-webpack/issues/423)) ([50c3ab9](https://github.com/NativeScript/nativescript-dev-webpack/commit/50c3ab9)) -* remove progress indication ([#468](https://github.com/NativeScript/nativescript-dev-webpack/issues/468)) ([8961a93](https://github.com/NativeScript/nativescript-dev-webpack/commit/8961a93)), closes [/github.com/webpack/webpack/blob/4428efe48e1c5ff4cadb79e13f0fa48c12bdac35/lib/ProgressPlugin.js#L50](https://github.com//github.com/webpack/webpack/blob/4428efe48e1c5ff4cadb79e13f0fa48c12bdac35/lib/ProgressPlugin.js/issues/L50) -* remove unnecessary comma ([#472](https://github.com/NativeScript/nativescript-dev-webpack/issues/472)) ([ce60606](https://github.com/NativeScript/nativescript-dev-webpack/commit/ce60606)) -* send arguments in watchPatterns hook ([#449](https://github.com/NativeScript/nativescript-dev-webpack/issues/449)) ([aa255bb](https://github.com/NativeScript/nativescript-dev-webpack/commit/aa255bb)) -* Set INIT_CWD env in all before-* hooks ([#480](https://github.com/NativeScript/nativescript-dev-webpack/issues/480)) ([b7ef84f](https://github.com/NativeScript/nativescript-dev-webpack/commit/b7ef84f)) -* **hooks:** Hooks not executed correctly when CLI is used as a library ([#479](https://github.com/NativeScript/nativescript-dev-webpack/issues/479)) ([87dd53d](https://github.com/NativeScript/nativescript-dev-webpack/commit/87dd53d)) -* **prepare:** clean platforms/.../app/ when running webpack ([#465](https://github.com/NativeScript/nativescript-dev-webpack/issues/465)) ([cb2f51b](https://github.com/NativeScript/nativescript-dev-webpack/commit/cb2f51b)) -* **snapshot:** use request module for http requests ([#428](https://github.com/NativeScript/nativescript-dev-webpack/issues/428)) ([01933e0](https://github.com/NativeScript/nativescript-dev-webpack/commit/01933e0)), closes [#389](https://github.com/NativeScript/nativescript-dev-webpack/issues/389) -* **uglify:** prevent SideDrawer transition class names from being renamed ([#426](https://github.com/NativeScript/nativescript-dev-webpack/issues/426)) ([0120329](https://github.com/NativeScript/nativescript-dev-webpack/commit/0120329)), closes [/github.com/telerik/nativescript-ui-feedback/issues/477#issuecomment-360772046](https://github.com//github.com/telerik/nativescript-ui-feedback/issues/477/issues/issuecomment-360772046) [#258](https://github.com/NativeScript/nativescript-dev-webpack/issues/258) - - -### Features - -* **livesync:** enable webpack with watch ([#433](https://github.com/NativeScript/nativescript-dev-webpack/issues/433)) ([847a56f](https://github.com/NativeScript/nativescript-dev-webpack/commit/847a56f)) -* consume shouldprepare hook ([#447](https://github.com/NativeScript/nativescript-dev-webpack/issues/447)) ([adb896c](https://github.com/NativeScript/nativescript-dev-webpack/commit/adb896c)) - - -### BREAKING CHANGES - -* The snapshot plugin is applied only when building for release. - -Before: -``` -tns run android --bundle --env.snapshot -``` - -After: -``` -tns run android --bundle --env.snapshot --release --keyStorePath ~/path/to/keystore/my.keystore --keyStorePassword password --keyStoreAlias alias --keyStoreAliasPassword aliasPassword -``` - - -## [0.9.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.9.1...0.9.2) (2018-02-15) - - -### Bug Fixes - -* clean snapshot artifacts on cleanApp hook ([#423](https://github.com/NativeScript/nativescript-dev-webpack/issues/423)) ([50c3ab9](https://github.com/NativeScript/nativescript-dev-webpack/commit/50c3ab9)) -* **snapshot:** use request module for http requests ([#428](https://github.com/NativeScript/nativescript-dev-webpack/issues/428)) ([01933e0](https://github.com/NativeScript/nativescript-dev-webpack/commit/01933e0)), closes [#389](https://github.com/NativeScript/nativescript-dev-webpack/issues/389) -* **uglify:** prevent SideDrawer transition class names from being renamed ([#426](https://github.com/NativeScript/nativescript-dev-webpack/issues/426)) ([0120329](https://github.com/NativeScript/nativescript-dev-webpack/commit/0120329)), closes [#258](https://github.com/NativeScript/nativescript-dev-webpack/issues/258) - - - - -## [0.9.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.9.0...0.9.1) (2018-01-10) - - -### Bug Fixes - -* respect windows paths in /app.css regex ([#385](https://github.com/NativeScript/nativescript-dev-webpack/issues/385)) ([a37cca0](https://github.com/NativeScript/nativescript-dev-webpack/commit/a37cca0)) -* support aot on windows ([#392](https://github.com/NativeScript/nativescript-dev-webpack/issues/392)) ([8a20502](https://github.com/NativeScript/nativescript-dev-webpack/commit/8a20502)) -* **css:** disable minification when using uglify ([#383](https://github.com/NativeScript/nativescript-dev-webpack/issues/383)) ([8e1a5a6](https://github.com/NativeScript/nativescript-dev-webpack/commit/8e1a5a6)), closes [#377](https://github.com/NativeScript/nativescript-dev-webpack/issues/377) - - -### Features - -* support for Angular 5.1 ([#374](https://github.com/NativeScript/nativescript-dev-webpack/issues/374)) ([5a40330](https://github.com/NativeScript/nativescript-dev-webpack/commit/5a40330)) -* use UglifyJsPlugin which support es6 code ([#401](https://github.com/NativeScript/nativescript-dev-webpack/issues/401)) ([34b1b9d](https://github.com/NativeScript/nativescript-dev-webpack/commit/34b1b9d)) - - - - -# [0.9.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.8.0...v0.9.0) (2017-12-20) - -> You can follow the [Migration guide](https://www.nativescript.org/blog/nativescript-webpack-0.9.0-what-changed-and-how-to-upgrade) for upgrading to this version. - - -### Bug Fixes - -* **compiler:** reject promise with real error ([#350](https://github.com/NativeScript/nativescript-dev-webpack/issues/350)) ([0b9febe](https://github.com/NativeScript/nativescript-dev-webpack/commit/0b9febe)) -* **configs:** don't follow symlinks for loaders ([#287](https://github.com/NativeScript/nativescript-dev-webpack/issues/287)) ([7deb117](https://github.com/NativeScript/nativescript-dev-webpack/commit/7deb117)) -* **ns-bundle:** support for Node.js 9 ([#321](https://github.com/NativeScript/nativescript-dev-webpack/issues/321)) ([b4800c8](https://github.com/NativeScript/nativescript-dev-webpack/commit/b4800c8)) -* **postinstall:** stop removing "start/run-platform-bundle" scripts ([#301](https://github.com/NativeScript/nativescript-dev-webpack/issues/301)) ([ddecb56](https://github.com/NativeScript/nativescript-dev-webpack/commit/ddecb56)) -* **snapshot:** interrupt the webpack build on error ([#369](https://github.com/NativeScript/nativescript-dev-webpack/issues/369)) ([0a6d1b9](https://github.com/NativeScript/nativescript-dev-webpack/commit/0a6d1b9)) -* **snapshot:** use autoclose option on writestream ([#345](https://github.com/NativeScript/nativescript-dev-webpack/issues/345)) ([3967d79](https://github.com/NativeScript/nativescript-dev-webpack/commit/3967d79)) -* **update-ns-webpack:** make it possible to call as executable ([#347](https://github.com/NativeScript/nativescript-dev-webpack/issues/347)) ([9fa7656](https://github.com/NativeScript/nativescript-dev-webpack/commit/9fa7656)) - - -### Features - -* Angular 5 support ([#328](https://github.com/NativeScript/nativescript-dev-webpack/issues/328)) ([5539ddb](https://github.com/NativeScript/nativescript-dev-webpack/commit/5539ddb)) -* add FS, PlatformSuffixPlugin and css2json-loader ([#290](https://github.com/NativeScript/nativescript-dev-webpack/issues/290)) ([ea29bb6](https://github.com/NativeScript/nativescript-dev-webpack/commit/ea29bb6)) -* Configure the vendor scripts to also use less, sass, scss for app.css ([#343](https://github.com/NativeScript/nativescript-dev-webpack/issues/343)) ([273dbd5](https://github.com/NativeScript/nativescript-dev-webpack/commit/273dbd5)) -* enable plugin to run through {N} CLI hooks ([#299](https://github.com/NativeScript/nativescript-dev-webpack/issues/299)) ([9a57a53](https://github.com/NativeScript/nativescript-dev-webpack/commit/9a57a53)) -* **sass:** add conditional sass deps for webpack ([#355](https://github.com/NativeScript/nativescript-dev-webpack/issues/355)) ([f51241c](https://github.com/NativeScript/nativescript-dev-webpack/commit/f51241c)) - - - - -# [0.8.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.7.3...0.8.0) (2017-09-08) - -### Features - -* add support for web workers to default template ([#269](https://github.com/NativeScript/nativescript-dev-webpack/issues/269)) ([494ccbb](https://github.com/NativeScript/nativescript-dev-webpack/commit/494ccbb)) - - - -## [0.7.3](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.7.2...0.7.3) (2017-07-12) - - -### Bug Fixes - -* **ns-bundle:** remove command escaping when spawning child process ([#218](https://github.com/NativeScript/nativescript-dev-webpack/issues/218)) ([28e3aad](https://github.com/NativeScript/nativescript-dev-webpack/commit/28e3aad)), closes [#214](https://github.com/NativeScript/nativescript-dev-webpack/issues/214) - - - -## [0.7.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.7.1...0.7.2) (2017-07-05) - - -### Bug Fixes - -* **mangle-excludes:** add Compat Query and Close listener classes ([#190](https://github.com/NativeScript/nativescript-dev-webpack/issues/190)) ([5791cfc](https://github.com/NativeScript/nativescript-dev-webpack/commit/5791cfc)) -* **ns-bundle:** escape command and args when spawning child process ([c3e7376](https://github.com/NativeScript/nativescript-dev-webpack/commit/c3e7376)), closes [#209](https://github.com/NativeScript/nativescript-dev-webpack/issues/209) -* run gradlew clean only for tns <=3.0.1 ([efea463](https://github.com/NativeScript/nativescript-dev-webpack/commit/efea463)) - - -### Features - -* add support for passing params via --env to webpack ([#204](https://github.com/NativeScript/nativescript-dev-webpack/issues/204)) ([4921321](https://github.com/NativeScript/nativescript-dev-webpack/commit/4921321)) -* alias tilde to point to the app root ([#201](https://github.com/NativeScript/nativescript-dev-webpack/issues/201)) ([3fb865d](https://github.com/NativeScript/nativescript-dev-webpack/commit/3fb865d)) -* add BundleAnalyzerPlugin to webpack config ([ac32b14](https://github.com/NativeScript/nativescript-dev-webpack/commit/ac32b14)) - - - - -## [0.7.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.6.3...0.7.1) (2017-06-22) - - -### Bug Fixes - -* **mangle-excludes:** add Compat Query and Close listener classes ([#190](https://github.com/NativeScript/nativescript-dev-webpack/issues/190)) ([5791cfc](https://github.com/NativeScript/nativescript-dev-webpack/commit/5791cfc)) - - -### Features - -* introduce support for v8 heap snapshot generation ([1b5dcdc](https://github.com/NativeScript/nativescript-dev-webpack/commit/1b5dcdc)) -* add BundleAnalyzerPlugin to webpack config ([ac32b14](https://github.com/NativeScript/nativescript-dev-webpack/commit/ac32b14)) - - - - -## [0.6.3](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.6.2...0.6.3) (2017-06-09) - - -### Bug Fixes - -* **npm scripts:** replace deprecated build-app script on postinstall ([#184](https://github.com/NativeScript/nativescript-dev-webpack/issues/184)) ([a4e7f1c](https://github.com/NativeScript/nativescript-dev-webpack/commit/a4e7f1c)), closes [#183](https://github.com/NativeScript/nativescript-dev-webpack/issues/183) - - - - -## [0.6.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.6.1...0.6.2) (2017-06-06) - - -### Bug Fixes - -* **ns-bundle:** properly get tns command ([#170](https://github.com/NativeScript/nativescript-dev-webpack/issues/170)) ([43eeaf4](https://github.com/NativeScript/nativescript-dev-webpack/commit/43eeaf4)), closes [#169](https://github.com/NativeScript/nativescript-dev-webpack/issues/169) -* bundle scripts should invoke tns run instead of tns start ([#174](https://github.com/NativeScript/nativescript-dev-webpack/issues/174)) ([f3d8a3a](https://github.com/NativeScript/nativescript-dev-webpack/commit/f3d8a3a)), closes [#172](https://github.com/NativeScript/nativescript-dev-webpack/issues/172) -* clean android build artifacts when using with uglify ([#175](https://github.com/NativeScript/nativescript-dev-webpack/issues/175)) ([278244b](https://github.com/NativeScript/nativescript-dev-webpack/commit/278244b)) -* exclude impl core modules classes from mangling ([#173](https://github.com/NativeScript/nativescript-dev-webpack/issues/173)) ([53d7538](https://github.com/NativeScript/nativescript-dev-webpack/commit/53d7538)) - - - - -## [0.6.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.6.0...0.6.1) (2017-05-31) - - -### Bug Fixes - -* **ns-bundle:** add missing return ([#167](https://github.com/NativeScript/nativescript-dev-webpack/issues/167)) ([cd7ea25](https://github.com/NativeScript/nativescript-dev-webpack/commit/cd7ea25)) -* **ns-bundle:** parse all '*-app' flags as tns commands ([#166](https://github.com/NativeScript/nativescript-dev-webpack/issues/166)) ([8e7a1b3](https://github.com/NativeScript/nativescript-dev-webpack/commit/8e7a1b3)) - - -### Features - -* add publish-ios-bundle npm script ([c424a8a](https://github.com/NativeScript/nativescript-dev-webpack/commit/c424a8a)) - - - - -# [0.6.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.5.0...0.6.0) (2017-05-29) - - -### Bug Fixes - -* **ns-bundle:** clean android build for NativeScript CLI 3.0.1<= ([#163](https://github.com/NativeScript/nativescript-dev-webpack/issues/163)) ([35ce787](https://github.com/NativeScript/nativescript-dev-webpack/commit/35ce787)) -* **template:** disable minification of css by css-loader ([#154](https://github.com/NativeScript/nativescript-dev-webpack/issues/154)) ([30e9c97](https://github.com/NativeScript/nativescript-dev-webpack/commit/30e9c97)), closes [#135](https://github.com/NativeScript/nativescript-dev-webpack/issues/135) - - -### Features - -* add UrlResolvePlugin for platform-specific template/style urls ([#155](https://github.com/NativeScript/nativescript-dev-webpack/issues/155)) ([2ccf55b](https://github.com/NativeScript/nativescript-dev-webpack/commit/2ccf55b)), closes [#75](https://github.com/NativeScript/nativescript-dev-webpack/issues/75) - -### BREAKING CHANGES: -The StyleUrlResolvePlugin is now replaced by the UrlResolvePlugin. The latter replaces both style and template platform-specific urls from Angular components. On postinstall nativescript-dev-webpack will automatically replaces all occurencies of the old plugin in the project's webpack config. - - - -# [0.5.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.4.2...0.5.0) (2017-05-11) - - -### Bug Fixes - -* **ns-bundle:** don't re-add scripts from nativescript-dev-webpack ([3d690cb](https://github.com/NativeScript/nativescript-dev-webpack/commit/3d690cb)) -* **ns-bundle:** pass platform and uglify as env properties ([dcf21f8](https://github.com/NativeScript/nativescript-dev-webpack/commit/dcf21f8)) -* **ns-bundle:** use webpack.config.js instead of webpack.common.js ([3df5d9b](https://github.com/NativeScript/nativescript-dev-webpack/commit/3df5d9b)) -* **template:** create empty `tns-java-classes.js` internally ([#148](https://github.com/NativeScript/nativescript-dev-webpack/issues/148)) ([0fd9159](https://github.com/NativeScript/nativescript-dev-webpack/commit/0fd9159)) -* **templates:** prefer css templates over platform.css templates ([6fc4747](https://github.com/NativeScript/nativescript-dev-webpack/commit/6fc4747)) - -### BREAKING CHANGES: -The plugin now adds `webpack.config.js` file instead of `webpack.common.js`, `webpack.android.js` and `webpack.ios.js` files. -The ns-bundle script targets the `webpack.config.js` file in -your repository instead of the `webpack.common.js` one. If you modified -your configuration, you need to apply the changes to `webpack.config.js`. -The following files are no longer needed and can be safely removed from -the project: `webpack.common.js`, `webpack.android.js`, -`webpack.ios.js`. - - - -## [0.4.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.4.1...0.4.2) (2017-05-04) - - -### Bug Fixes - -* **ns-bundle:** respect platform version from app package.json ([#138](https://github.com/NativeScript/nativescript-dev-webpack/issues/138)) ([839ce93](https://github.com/NativeScript/nativescript-dev-webpack/commit/839ce93)) -* **tsconfig:** add missing paths and skipLibCheck option ([#140](https://github.com/NativeScript/nativescript-dev-webpack/issues/140)) ([c453944](https://github.com/NativeScript/nativescript-dev-webpack/commit/c453944)) - - - - -## [0.4.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/v0.4.0...0.4.1) (2017-05-01) - - -### Bug Fixes - -* **ns-bundle:** escape arguments passed to `tns` command ([#125](https://github.com/NativeScript/nativescript-dev-webpack/issues/125)) ([b9430e3](https://github.com/NativeScript/nativescript-dev-webpack/commit/b9430e3)), closes [#123](https://github.com/NativeScript/nativescript-dev-webpack/issues/123) -* **template:** include platform specific files in bundle first ([#133](https://github.com/NativeScript/nativescript-dev-webpack/issues/133)) ([c399e1e](https://github.com/NativeScript/nativescript-dev-webpack/commit/c399e1e)), closes [#31](https://github.com/NativeScript/nativescript-dev-webpack/issues/31) -* **template:** ship android bundle with empty `tns-java-classes.js` chunk ([#128](https://github.com/NativeScript/nativescript-dev-webpack/issues/128)) ([b65a80c](https://github.com/NativeScript/nativescript-dev-webpack/commit/b65a80c)) - - -### Features - -* **ns-bundle:** app can be just prepared and bundled now ([#126](https://github.com/NativeScript/nativescript-dev-webpack/issues/126)) ([b0688b4](https://github.com/NativeScript/nativescript-dev-webpack/commit/b0688b4)) - - - - -# [0.4.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/v0.3.7...v0.4.0) (2017-04-20) - - -### Bug Fixes - -* add webpack.common template for JS projects ([7451545](https://github.com/NativeScript/nativescript-dev-webpack/commit/7451545)), closes [#113](https://github.com/NativeScript/nativescript-dev-webpack/issues/113) -* **installer:** show helper message for new dependencies ([#122](https://github.com/NativeScript/nativescript-dev-webpack/issues/122)) ([5c7ebeb](https://github.com/NativeScript/nativescript-dev-webpack/commit/5c7ebeb)) -* **ns-bundle:** use remove/add platform instead of clean-app ([#116](https://github.com/NativeScript/nativescript-dev-webpack/issues/116)) ([6609370](https://github.com/NativeScript/nativescript-dev-webpack/commit/6609370)) -* **tsconfig:** add "exclude" property to aot config ([#120](https://github.com/NativeScript/nativescript-dev-webpack/issues/120)) ([d28dba1](https://github.com/NativeScript/nativescript-dev-webpack/commit/d28dba1)), closes [#101](https://github.com/NativeScript/nativescript-dev-webpack/issues/101) - - -### Features - -* detect required devDeps versions ([9b102c3](https://github.com/NativeScript/nativescript-dev-webpack/commit/9b102c3)) - - - - -## [0.3.7](https://github.com/NativeScript/nativescript-dev-webpack/compare/v0.3.6...v0.3.7) (2017-03-31) - - -### Bug Fixes - -* **uglify:** exclude tns 3.0 listener impls from mangling ([#102](https://github.com/NativeScript/nativescript-dev-webpack/issues/102)) ([6666191](https://github.com/NativeScript/nativescript-dev-webpack/commit/6666191)) - - -### Features - -* update to Angular 4.0 and pin @ngtools/webpack version ([#107](https://github.com/NativeScript/nativescript-dev-webpack/issues/107)) ([247e507](https://github.com/NativeScript/nativescript-dev-webpack/commit/247e507)) - - - - -## [0.3.6](https://github.com/NativeScript/nativescript-dev-webpack/compare/v0.3.5...v0.3.6) (2017-03-08) - - -### Bug Fixes - -* **plugins:** add additional check for node.text in StyleUrlResolvePlugin ([#95](https://github.com/NativeScript/nativescript-dev-webpack/issues/95)) ([4a1b625](https://github.com/NativeScript/nativescript-dev-webpack/commit/4a1b625)), closes [#92](https://github.com/NativeScript/nativescript-dev-webpack/issues/92) - - - - -## [0.3.5](https://github.com/NativeScript/nativescript-dev-webpack/compare/v0.3.4...v0.3.5) (2017-02-28) - - -### Bug Fixes - -* **plugins:** check for argument properties before traversing ([#83](https://github.com/NativeScript/nativescript-dev-webpack/issues/83)) ([bc2c6ec](https://github.com/NativeScript/nativescript-dev-webpack/commit/bc2c6ec)) -* **scripts:** correctly execute ns-bundle for windows ([#89](https://github.com/NativeScript/nativescript-dev-webpack/issues/89)) ([ad965ed](https://github.com/NativeScript/nativescript-dev-webpack/commit/ad965ed)) -* **templates:** Disable node "fs" shim ([#82](https://github.com/NativeScript/nativescript-dev-webpack/issues/82)) ([b86e1ae](https://github.com/NativeScript/nativescript-dev-webpack/commit/b86e1ae)), closes [#80](https://github.com/NativeScript/nativescript-dev-webpack/issues/80) - - -### Features - -* **deps:** update to @ngtools/webpack v1.2.10 ([#84](https://github.com/NativeScript/nativescript-dev-webpack/issues/84)) ([70e60a6](https://github.com/NativeScript/nativescript-dev-webpack/commit/70e60a6)) - - - - -## [0.3.4](https://github.com/NativeScript/nativescript-dev-webpack/compare/v0.3.3...v0.3.4) (2017-02-16) - - -### Bug Fixes - -* run `tns-xml-loader` before `@ngtools` loader ([#66](https://github.com/NativeScript/nativescript-dev-webpack/issues/66)) ([325cb90](https://github.com/NativeScript/nativescript-dev-webpack/commit/325cb90)), closes [#64](https://github.com/NativeScript/nativescript-dev-webpack/issues/64) -* **scripts:** respect tns build/run args passed to ns-bundle ([#71](https://github.com/NativeScript/nativescript-dev-webpack/issues/71)) ([17b9d82](https://github.com/NativeScript/nativescript-dev-webpack/commit/17b9d82)) -* **uglify:** exclude tns 3.0 listeners from mangling ([#72](https://github.com/NativeScript/nativescript-dev-webpack/issues/72)) ([b9d6a3f](https://github.com/NativeScript/nativescript-dev-webpack/commit/b9d6a3f)) - - -### Features - -* **scripts:** add ns-bundle and verify-bundle ([#69](https://github.com/NativeScript/nativescript-dev-webpack/issues/69)) ([e80cbdc](https://github.com/NativeScript/nativescript-dev-webpack/commit/e80cbdc)) - - - - -## [0.3.3](https://github.com/NativeScript/nativescript-dev-webpack/compare/v0.3.2...v0.3.3) (2017-02-01) - - -### Bug Fixes - -* exclude from mangling EditableTextBase ([#60](https://github.com/NativeScript/nativescript-dev-webpack/issues/60)) ([226f354](https://github.com/NativeScript/nativescript-dev-webpack/commit/226f354)) -* register elements from embedded templates ([#56](https://github.com/NativeScript/nativescript-dev-webpack/issues/56)) ([05f33ed](https://github.com/NativeScript/nativescript-dev-webpack/commit/05f33ed)), closes [#55](https://github.com/NativeScript/nativescript-dev-webpack/issues/55) -* **uglify:** Exclude layout classes from mangling. ([75bdeb1](https://github.com/NativeScript/nativescript-dev-webpack/commit/75bdeb1)) - - -### Features - -* **deps:** add support for webpack 2.2+ ([5c00f2d](https://github.com/NativeScript/nativescript-dev-webpack/commit/5c00f2d)) - - - - -## [0.3.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/v0.3.1...v0.3.2) (2017-01-16) - - -### Features - -* add support for tsc[@2](https://github.com/2).1 and ng[@2](https://github.com/2).4.2 ([e320b8b](https://github.com/NativeScript/nativescript-dev-webpack/commit/e320b8b)) - - - - -## [0.3.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/71d7823...v0.3.1) (2017-01-11) - - -### Bug Fixes - -* add typescript@~2.0.10 to ng projects ([#48](https://github.com/NativeScript/nativescript-dev-webpack/issues/48)) ([87741a1](https://github.com/NativeScript/nativescript-dev-webpack/commit/87741a1)) -* use AoT entry module if it exists ([b8c4f1c](https://github.com/NativeScript/nativescript-dev-webpack/commit/b8c4f1c)) - - -### Features - -* add plugin to support android/ios styleUrls ([#47](https://github.com/NativeScript/nativescript-dev-webpack/issues/47)) ([be12c23](https://github.com/NativeScript/nativescript-dev-webpack/commit/be12c23)), closes [#36](https://github.com/NativeScript/nativescript-dev-webpack/issues/36) -* support @ngtools/webpack-1.2.1 ([71d7823](https://github.com/NativeScript/nativescript-dev-webpack/commit/71d7823)) -* use the nativescript fork of css-loader ([3b6a1c8](https://github.com/NativeScript/nativescript-dev-webpack/commit/3b6a1c8)) - - diff --git a/packages/webpack/LICENSE b/packages/webpack/LICENSE deleted file mode 100755 index 061c44028..000000000 --- a/packages/webpack/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright (c) 2015-2019 Progress Software Corporation - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file diff --git a/packages/webpack/README.md b/packages/webpack/README.md deleted file mode 100644 index f10eef29a..000000000 --- a/packages/webpack/README.md +++ /dev/null @@ -1,49 +0,0 @@ -# NativeScript Webpack - -This repository contains the code for the @nativescript/webpack plugin which helps in webpacking [NativeScript](https://www.nativescript.org/) apps. - -JavaScript code and general asset bundling have been a member of the web developer toolbox for a long time. Tools like Webpack have been providing support for an enjoyable development experience that lets you assemble client-side code from various module sources and formats and then package it together. Most importantly, they allow for page load time optimizations that reduce or parallelize the number of requests a browser makes to the server. - -Why bundle scripts in a mobile app though? - -- Fewer filesystem operations on app startup -- Smaller code size -- Tree-shaking -- Preprocessing and interoperability hooks. Webpack provides a way to resolve modules and expressions differently according to its configuration. It also contains a lot of plugins and loaders that let you embed different content in your application or use code written in different programming languages - -For more details, see the [NativeScript docs for building with webpack](http://docs.nativescript.org/angular/best-practices/bundling-with-webpack.html). - - - -- [Ingredients](#ingredients) -- [Usage](#usage) -- [Contribute](#contribute) -- [Get Help](#get-help) - - - -## Ingredients - -* webpack config templates. -* helper functions that place files at the correct locations before packaging apps. -* loaders and plugins for vanilla NativeScript and Angular apps. - -## Usage - -```sh -$ npm install --save-dev @nativescript/webpack - -$ tns run android -or -$ tns run ios -``` - -## Contribute -We love PRs! Check out the [contributing guidelines](CONTRIBUTING.md) and [instructions for local setup](https://github.com/NativeScript/nativescript-dev-webpack/blob/master/CONTRIBUTING.md#setup). If you want to contribute, but you are not sure where to start - look for [issues labeled `help wanted`](https://github.com/NativeScript/nativescript-dev-webpack/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22). - -## Get Help -Please, use [github issues](https://github.com/NativeScript/nativescript-dev-webpack/issues) strictly for [reporting bugs](CONTRIBUTING.md#reporting-bugs) or [requesting features](CONTRIBUTING.md#requesting-features). For general questions and support, check out [Stack Overflow](https://stackoverflow.com/questions/tagged/nativescript) or ask our experts in [NativeScript community Slack channel](http://developer.telerik.com/wp-login.php?action=slack-invitation). - -![](https://ga-beacon.appspot.com/UA-111455-24/nativescript/nativescript-dev-webpack?pixel) - - diff --git a/packages/webpack/bin/generate-android-snapshot b/packages/webpack/bin/generate-android-snapshot deleted file mode 100755 index 2aed1dde7..000000000 --- a/packages/webpack/bin/generate-android-snapshot +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env node -const ProjectSnapshotGenerator = require("../snapshot/android/project-snapshot-generator"); -const args = require("../snapshot/android/project-snapshot-generator-cli-ags-parser")(); - -const generator = new ProjectSnapshotGenerator(args); -generator.generate(args); diff --git a/packages/webpack/bin/generate-android-snapshot.cmd b/packages/webpack/bin/generate-android-snapshot.cmd deleted file mode 100644 index 4f28f8e31..000000000 --- a/packages/webpack/bin/generate-android-snapshot.cmd +++ /dev/null @@ -1 +0,0 @@ -@node %~dp0\generate-android-snapshot %* diff --git a/packages/webpack/bin/install-ns-webpack b/packages/webpack/bin/install-ns-webpack deleted file mode 100755 index e8445188b..000000000 --- a/packages/webpack/bin/install-ns-webpack +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env node -const installer = require("../installer"); -installer.install(); diff --git a/packages/webpack/bin/install-ns-webpack.cmd b/packages/webpack/bin/install-ns-webpack.cmd deleted file mode 100644 index 5de779b80..000000000 --- a/packages/webpack/bin/install-ns-webpack.cmd +++ /dev/null @@ -1 +0,0 @@ -@node %~dp0\install-ns-webpack %* diff --git a/packages/webpack/bin/ns-bundle b/packages/webpack/bin/ns-bundle deleted file mode 100755 index ffbd1a9a1..000000000 --- a/packages/webpack/bin/ns-bundle +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env node - -console.error("Using npm run scripts is no longer supported. Use CLI commands instead.\nExample:\ntns build android") -process.exit(1); \ No newline at end of file diff --git a/packages/webpack/bin/ns-bundle.cmd b/packages/webpack/bin/ns-bundle.cmd deleted file mode 100644 index 780766846..000000000 --- a/packages/webpack/bin/ns-bundle.cmd +++ /dev/null @@ -1 +0,0 @@ -@node %~dp0\ns-bundle %* diff --git a/packages/webpack/bin/ns-verify-bundle b/packages/webpack/bin/ns-verify-bundle deleted file mode 100755 index d7de29e2d..000000000 --- a/packages/webpack/bin/ns-verify-bundle +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env node - -console.error("The ns-verify-bundle script is deprecated!") - -const path = require("path"); -const fs = require("fs"); - -const { getProjectDir } = require("../projectHelpers"); - -const PROJECT_DIR = getProjectDir(); -const APP_ID = require(path.resolve(PROJECT_DIR, "./package.json")).nativescript.id; -const APP_NAME = APP_ID.substring(APP_ID.lastIndexOf(".") + 1); -const PROJECT_PATHS = { - android: path.resolve(PROJECT_DIR, "platforms/android/src/main/assets/app"), - ios: path.resolve(PROJECT_DIR, `platforms/ios/build/emulator/${APP_NAME}.app/app`), -}; - -const npmArgs = JSON.parse(process.env.npm_config_argv).original; -const flags = npmArgs.filter(a => a.startsWith("--")).map(a => a.substring(2)); -const file = getTargetFile(flags); -const platform = getPlatform(flags); - -const filePath = path.resolve(PROJECT_PATHS[platform], file); - -console.log(`Checking ${filePath} exists`); -if (!fs.existsSync(filePath)) { - throwError({message: `${filePath} doesn not exist!`}); -} - -const maxSize = getMaxSize(flags); -if (maxSize) { - checkFileSizeIsUnder(filePath, maxSize).then().catch(throwError); -} - -function getTargetFile(flags) { - let fileFlags = flags.filter(f => f.startsWith("file=")); - - if (fileFlags.length != 1) { - throwError({message: "You must provide a target file!"}); - } - - fileFlags = fileFlags[0]; - return fileFlags.substring(fileFlags.indexOf("=") + 1); -} - -function getMaxSize(flags) { - let sizeFlags = flags.filter(f => f.startsWith("maxSize=")); - - if (sizeFlags.length == 0) { - return; - } else if (sizeFlags.length > 1) { - throwError({message: "You must provide 0 or 1 maxSize flags!"}); - } - - sizeFlags = sizeFlags[0]; - return sizeFlags.substring(sizeFlags.indexOf("=") + 1); -} - -function getPlatform(flags) { - if (flags.includes("android") && flags.includes("ios")) { - throwError({message: "You cannot use both --android and --ios flags!"}); - } - - if (flags.includes("android")) { - return "android"; - } else if (flags.includes("ios")) { - return "ios"; - } else { - throwError({message: "You must provide a target platform! Use either --android, or --ios flag."}); - } -} - -function checkFileSizeIsUnder(fileName, sizeInBytes) { - console.log(`Checking ${fileName} size is under ${sizeInBytes}`); - - return new Promise((resolve, reject) => { - readFile(fileName) - .then(content => { - if (content.length <= sizeInBytes) { - resolve(); - } else { - reject({message: `File "${fileName}" exceeded file size of "${sizeInBytes}".`}); - } - }); - }); -} - -function readFile(fileName) { - return new Promise((resolve, reject) => { - fs.readFile(fileName, "utf-8", (err, data) => { - if (err) { - reject(err); - } else { - resolve(data); - } - }); - }); -} - -function throwError(error) { - console.error(error.message); - process.exit(error.code || 1); -} - diff --git a/packages/webpack/bin/ns-verify-bundle.cmd b/packages/webpack/bin/ns-verify-bundle.cmd deleted file mode 100644 index 0a479f43c..000000000 --- a/packages/webpack/bin/ns-verify-bundle.cmd +++ /dev/null @@ -1 +0,0 @@ -@node %~dp0\ns-verify-bundle %* diff --git a/packages/webpack/bin/ns-webpack-update.cmd b/packages/webpack/bin/ns-webpack-update.cmd deleted file mode 100644 index 135558e71..000000000 --- a/packages/webpack/bin/ns-webpack-update.cmd +++ /dev/null @@ -1 +0,0 @@ -@node %~dp0\ns-webpack-update %* diff --git a/packages/webpack/bin/remove-ns-webpack b/packages/webpack/bin/remove-ns-webpack deleted file mode 100755 index 88ea2bfa9..000000000 --- a/packages/webpack/bin/remove-ns-webpack +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env node -const installer = require("../installer"); -installer.uninstall(); diff --git a/packages/webpack/bin/remove-ns-webpack.cmd b/packages/webpack/bin/remove-ns-webpack.cmd deleted file mode 100644 index 311f4ecfe..000000000 --- a/packages/webpack/bin/remove-ns-webpack.cmd +++ /dev/null @@ -1 +0,0 @@ -@node %~dp0\remove-ns-webpack %* diff --git a/packages/webpack/bin/update-ns-webpack b/packages/webpack/bin/update-ns-webpack deleted file mode 100755 index 286cec969..000000000 --- a/packages/webpack/bin/update-ns-webpack +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env node - -const update = require("../verify/update"); - -const { original: npmArgs = [] } = JSON.parse(process.env.npm_config_argv || "{}"); -const [, , ...processArgs ] = process.argv; - -const flags = [ ...npmArgs, ...processArgs ] - .filter(f => f.startsWith("--")) - .map(f => f.substring(2)); - -function addOption(all, current) { - all[current] = true; - return all; -} - -const options = flags.reduce(addOption, {}); - -update(options); - diff --git a/packages/webpack/build/prepublish.js b/packages/webpack/build/prepublish.js deleted file mode 100644 index 41b76817d..000000000 --- a/packages/webpack/build/prepublish.js +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env node - -const { dirname: pathDirname } = require("path"); -const { getPackageJson, writePackageJson } = require("../projectHelpers"); - -let processArgs = process.argv; -const distTag = processArgs.includes("--distTag") ? processArgs[processArgs.indexOf("--distTag") + 1] : undefined; - -const tag = distTag || process.env["distTag"] || "next"; - -const projectDir = pathDirname(__dirname); -const packageJson = getPackageJson(projectDir); - -if (distTag) { - processArgs = processArgs.splice(processArgs.indexOf("--distTag"), 2); -} -const [, , packageVersion = new Date()] = processArgs; - -packageJson.publishConfig = Object.assign( - packageJson.publishConfig || {}, - { tag } -); - -delete packageJson.private; - -const currentVersion = packageJson.version; -const nextVersion = `${currentVersion}-${packageVersion}`; -const newPackageJson = Object.assign(packageJson, { version: nextVersion }); - -writePackageJson(newPackageJson, projectDir); diff --git a/packages/webpack/bundle-config-loader.d.ts b/packages/webpack/bundle-config-loader.d.ts deleted file mode 100644 index 55fd343ba..000000000 --- a/packages/webpack/bundle-config-loader.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { loader } from 'webpack'; -declare const loader: loader.Loader; -export default loader; diff --git a/packages/webpack/bundle-config-loader.spec.d.ts b/packages/webpack/bundle-config-loader.spec.d.ts deleted file mode 100644 index cb0ff5c3b..000000000 --- a/packages/webpack/bundle-config-loader.spec.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/packages/webpack/bundle-config-loader.spec.ts b/packages/webpack/bundle-config-loader.spec.ts deleted file mode 100644 index dd50f8e80..000000000 --- a/packages/webpack/bundle-config-loader.spec.ts +++ /dev/null @@ -1,114 +0,0 @@ -import bundleConfigLoader from './bundle-config-loader'; - -const defaultLoaderOptions = { - angular: false, - loadCss: true, - unitTesting: false, -}; - -const defaultTestFiles = { - './app-root.xml': true, - './app-root.land.xml': true, - './app.ts': true, - './app.css': true, - './app.android.scss': true, - './app.ios.scss': true, - './app.land.css': true, - './components/my-component.css': true, - './components/my-component.land.ts': true, - './components/my-component.ts': true, - './components/my-component.land.xml': true, - './components/my-component.xml': true, - './components/my-component.land.css': true, - './main/main-page.land.css': true, - './main/main-page.css': true, - './main/main-page.ts': true, - './main/main-page.land.xml': true, - './main/main-page.xml': true, - './main/main-page.land.ts': true, - './main/main-page-vm.ts': true, - - './app_component.scss': true, - './App_Resources123/some-file.xml': true, - './MyApp_Resources/some-file.xml': true, - './App_Resources_Nobody_Names_Folders_Like_That_Roska/some-file.xml': true, - - './package.json': false, // do not include package.json files - './app.d.ts': false, // do not include ts definitions - './_app-common.scss': false, // do not include scss partial files - './_app-variables.scss': false, // do not include scss partial files - './App_Resources/Android/src/main/res/values/colors.xml': false, // do not include App_Resources - './App_Resources/Android/src/main/AndroidManifest.xml': false, // do not include App_Resources - './tests/example.js': false, // do not include files from tests folder - './tests/component1/model1/file1.js': false, // do not include files from tests folder - './components/tests/example.js': true, -}; - -const loaderOptionsWithIgnore = { - angular: false, - loadCss: true, - unitTesting: false, - ignoredFiles: ['./application', './activity'], -}; - -const ignoredTestFiles = { - './application.ts': false, - './activity.ts': false, -}; - -function getRequireContextRegex(source: string): RegExp { - const requireContextStr = `require.context("~/", true, `; - - expect(source).toContain(requireContextStr); - - const start = source.indexOf(requireContextStr) + requireContextStr.length; - const end = source.indexOf(');\n', start); - const regexStr = source.substring(start, end); - const regex: RegExp = eval(regexStr); - - expect(regex instanceof RegExp).toBeTruthy(); - return regex; -} - -function assertTestFilesAreMatched(testFiles: { [key: string]: boolean }, regex: RegExp) { - for (let fileName in testFiles) { - if (defaultTestFiles[fileName]) { - expect(fileName).toMatch(regex); - } else { - expect(fileName).not.toMatch(regex); - } - } -} - -describe('BundleConfigLoader should create require.context', () => { - it('default case', (done) => { - const loaderContext = { - callback: (error, source: string, map) => { - const regex = getRequireContextRegex(source); - - assertTestFilesAreMatched(defaultTestFiles, regex); - - done(); - }, - query: defaultLoaderOptions, - }; - - bundleConfigLoader.call(loaderContext, ' ___CODE___'); - }); - - it('with ignored files', (done) => { - const loaderContext = { - callback: (error, source: string, map) => { - const regex = getRequireContextRegex(source); - const testFiles = { ...defaultTestFiles, ...ignoredTestFiles }; - - assertTestFilesAreMatched(testFiles, regex); - - done(); - }, - query: loaderOptionsWithIgnore, - }; - - bundleConfigLoader.call(loaderContext, ' ___CODE___'); - }); -}); diff --git a/packages/webpack/bundle-config-loader.ts b/packages/webpack/bundle-config-loader.ts deleted file mode 100644 index 8e5412a8c..000000000 --- a/packages/webpack/bundle-config-loader.ts +++ /dev/null @@ -1,88 +0,0 @@ -import * as unitTestingConfigLoader from './unit-testing-config-loader'; -import { loader } from 'webpack'; -import { getOptions } from 'loader-utils'; -import * as escapeRegExp from 'escape-string-regexp'; - -// Matches all source, markup and style files that are not in App_Resources and in tests folder -const defaultMatch = '(?ignoredFiles) { - registerModules = `(?new RegExp(registerModules); - } - - if (unitTesting) { - source = unitTestingConfigLoader({ appFullPath, projectRoot, angular, rootPagesRegExp: registerModules }); - this.callback(null, source); - return; - } - - const hmr = ` - if (module.hot) { - const hmrUpdate = require("@nativescript/webpack/hmr").hmrUpdate; - global.__coreModulesLiveSync = global.__onLiveSync; - - global.__onLiveSync = function () { - // handle hot updated on LiveSync - hmrUpdate(); - }; - - global.hmrRefresh = function({ type, path } = {}) { - // the hot updates are applied, ask the modules to apply the changes - setTimeout(() => { - global.__coreModulesLiveSync({ type, path }); - }); - }; - - // handle hot updated on initial app start - hmrUpdate(); - } - `; - - let sourceModule = '@nativescript/core'; - - if (platform && platform !== 'ios' && platform !== 'android') { - sourceModule = `nativescript-platform-${platform}`; - } - - source = ` - import "${sourceModule}/bundle-entry-points"; - ${source} - `; - - if (angular) { - source = ` - ${hmr} - ${source} - `; - } else if (registerModules) { - source = ` - ${hmr} - const context = require.context("~/", true, ${registerModules}); - global.registerWebpackModules(context); - if (module.hot) { - module.hot.accept(context.id, () => { - console.log("HMR: Accept module '" + context.id + "' from '" + module.id + "'"); - }); - } - ${source} - `; - } - - if (loadCss) { - source = ` - require("${angular ? '@nativescript/webpack/helpers/load-application-css-angular' : '@nativescript/webpack/helpers/load-application-css-regular'}")(); - ${source} - `; - } - - this.callback(null, source, map); -}; - -export default loader; diff --git a/packages/webpack/helpers/android-app-components-loader.js b/packages/webpack/helpers/android-app-components-loader.js deleted file mode 100644 index 3a80e72a1..000000000 --- a/packages/webpack/helpers/android-app-components-loader.js +++ /dev/null @@ -1,18 +0,0 @@ -const { convertSlashesInPath } = require("./projectHelpers"); - -module.exports = function (source, map) { - this.cacheable(); - const { modules } = this.query; - const imports = modules.map(convertSlashesInPath) - .map(m => `require("${m}");`).join("\n"); - const augmentedSource = ` - const isAndroid = require("@nativescript/core").isAndroid; - if (isAndroid && !global["__snapshot"]) { - ${imports} - } - - ${source} - `; - - this.callback(null, augmentedSource, map); -}; diff --git a/packages/webpack/helpers/androidProjectHelpers.js b/packages/webpack/helpers/androidProjectHelpers.js deleted file mode 100644 index 58ce9fa4e..000000000 --- a/packages/webpack/helpers/androidProjectHelpers.js +++ /dev/null @@ -1,77 +0,0 @@ -const { join, resolve } = require("path"); -const { existsSync, readFileSync } = require("fs"); - -const { getPackageJson } = require("./projectHelpers"); - -const PLATFORMS_ANDROID = "platforms/android"; -const ANDROID_PROJECT_DIR = join(PLATFORMS_ANDROID, "app"); -const ANDROID_APP_PATH = join(ANDROID_PROJECT_DIR, "src/main/assets/app"); -const ANDROID_CONFIGURATIONS_PATH = join(ANDROID_PROJECT_DIR, "build/configurations"); - -const getAndroidRuntimeVersion = (projectDir) => { - try { - const projectPackageJSON = getPackageJson(projectDir); - - const version = projectPackageJSON["nativescript"]["tns-android"]["version"]; - return version && toReleaseVersion(version); - } catch (e) { - return null; - } -} - -const toReleaseVersion = version => version.replace(/-.*/, ""); - -const getAndroidV8Version = (projectDir) => { - try { - const androidSettingsJSON = getAndroidSettingsJson(projectDir); - if (androidSettingsJSON !== null) { - return androidSettingsJSON.v8Version; - } else { - return null; - } - } catch (e) { - return null; - } -} - -const getMksnapshotParams = (projectDir) => { - try { - const androidSettingsJSON = getAndroidSettingsJson(projectDir); - if (androidSettingsJSON !== null) { - return androidSettingsJSON.mksnapshotParams; - } else { - return null; - } - } catch (e) { - return null; - } -}; - -const getRuntimeNdkRevision = (projectDir) => { - try { - const androidSettingsJSON = getAndroidSettingsJson(projectDir); - const result = androidSettingsJSON && androidSettingsJSON.ndkRevision; - return result; - } catch (e) { - return null; - } -}; - -const getAndroidSettingsJson = projectDir => { - const androidSettingsJsonPath = resolve(projectDir, PLATFORMS_ANDROID, "settings.json"); - if (existsSync(androidSettingsJsonPath)) { - return JSON.parse(readFileSync(androidSettingsJsonPath, "utf8")); - } else { - return null; - } -}; - -module.exports = { - ANDROID_PROJECT_DIR, - ANDROID_APP_PATH, - ANDROID_CONFIGURATIONS_PATH, - getAndroidRuntimeVersion, - getAndroidV8Version, - getMksnapshotParams, - getRuntimeNdkRevision -}; diff --git a/packages/webpack/helpers/angular-config-parser.js b/packages/webpack/helpers/angular-config-parser.js deleted file mode 100644 index 95d4398f6..000000000 --- a/packages/webpack/helpers/angular-config-parser.js +++ /dev/null @@ -1,114 +0,0 @@ -const { resolve } = require('path'); -const fs = require('fs'); - -const parseWorkspaceConfig = function(platform, envConfigs, projectName, debug) { - if (debug) { - console.log('-- config DEBUG ---'); - console.log('platform:', platform); - console.log('configuration:', envConfigs); - } - // configuration file replacements - const fileReplacements = {}; - // anything other than .ts files should be added as part of copy plugin - const copyReplacements = []; - if (hasConfigurations(envConfigs)) { - envConfigs = envConfigs.split(',').map(e => e.trim()); - - const configData = findConfig(__dirname); - const rootPath = configData.rootPath; - const workspaceConfig = configData.workspaceConfig; - - if (workspaceConfig && projectName) { - const projectSettings = workspaceConfig.projects[projectName]; - if (projectSettings) { - var targetProp = 'architect'; - if (!projectSettings.architect) { - targetProp = 'targets'; // Nx - } - // default project configurations - for (const envConfig of envConfigs) { - if (projectSettings[targetProp]) { - if (projectSettings[targetProp].default && projectSettings[targetProp].default.configurations) { - const defaultConfigurations = projectSettings[targetProp].default.configurations; - if (defaultConfigurations && defaultConfigurations[envConfig]) { - if (defaultConfigurations[envConfig].fileReplacements) { - for (const fileReplace of defaultConfigurations[envConfig].fileReplacements) { - if (debug) { - console.log('project fileReplacement:', fileReplace); - } - if (fileReplace.replace.indexOf('.ts') > -1) { - fileReplacements[resolve(__dirname, `${rootPath}${fileReplace.replace}`)] = resolve(__dirname, `${rootPath}${fileReplace.with}`); - } else { - copyReplacements.push({ from: resolve(__dirname, `${rootPath}${fileReplace.with}`), to: resolve(__dirname, `${rootPath}${fileReplace.replace}`), force: true }); - } - } - } - } - } - } - } - // platform specific configurations (always override top level project configurations) - for (const envConfig of envConfigs) { - if (projectSettings[targetProp]) { - if (projectSettings[targetProp] && projectSettings[targetProp][platform]) { - const platformConfig = projectSettings[targetProp][platform].configurations; - if (platformConfig && platformConfig[envConfig] && platformConfig[envConfig].fileReplacements) { - for (const fileReplace of platformConfig[envConfig].fileReplacements) { - if (debug) { - console.log(`"${platform}" specific fileReplacement:`, fileReplace); - } - if (fileReplace.replace.indexOf('.ts') > -1) { - fileReplacements[resolve(__dirname, `${rootPath}${fileReplace.replace}`)] = resolve(__dirname, `${rootPath}${fileReplace.with}`); - } else { - copyReplacements.push({ from: resolve(__dirname, `${rootPath}${fileReplace.with}`), to: resolve(__dirname, `${rootPath}${fileReplace.replace}`), force: true }); - } - } - } - } - } - } - } - } - } - - if (debug && copyReplacements.length) { - console.log('Adding to CopyWebpackPlugin:', copyReplacements); - } - - return { - fileReplacements, - copyReplacements - }; -} - -const findConfig = function(projectDir, rootPath = '') { - // support workspace.json and angular.json configurations - const angularConfigName = 'angular.json'; - const angularConfig = resolve(projectDir, angularConfigName); - const workspaceConfigName = 'workspace.json'; - const workspaceConfig = resolve(projectDir, workspaceConfigName); - if (fs.existsSync(workspaceConfig)) { - return { - rootPath, - workspaceConfig: require(workspaceConfig) - }; - } else if (fs.existsSync(angularConfig)) { - return { - rootPath, - workspaceConfig: require(angularConfig) - }; - } else { - rootPath += '../'; - return findConfig(resolve(projectDir, '..'), rootPath); - } -} - -const hasConfigurations = function(envConfigs) { - return envConfigs && envConfigs !== 'undefined'; -} - -module.exports = { - parseWorkspaceConfig, - findConfig, - hasConfigurations -}; \ No newline at end of file diff --git a/packages/webpack/helpers/apply-css-loader.js b/packages/webpack/helpers/apply-css-loader.js deleted file mode 100644 index ea1c286b7..000000000 --- a/packages/webpack/helpers/apply-css-loader.js +++ /dev/null @@ -1,43 +0,0 @@ -const cssLoaderWarning = "The apply-css-loader expects the file to be pre-processed by css-loader. It might not work properly. Please check your webpack configuration"; - -function checkForCssLoader(loaders, loaderIndex) { - if (!loaders) { - return false; - } - - for (var i = loaderIndex + 1; i < loaders.length; i++) { - const loader = loaders[i]; - if (loader.path && loader.path.indexOf("css-loader") > 0) { - return true; - } - } - - return false; -} - -module.exports = function (content, map) { - if (this.request.match(/\/app\.(css|scss|less|sass)$/)) { - return content; - } - - // Emit a warning if the file was not processed by the css-loader. - if (!checkForCssLoader(this.loaders, this.loaderIndex)) { - this.emitWarning(new Error(cssLoaderWarning)); - } - - content += ` - const { Application } = require("@nativescript/core"); - require("@nativescript/core/ui/styling/style-scope"); - - if (___CSS_LOADER_EXPORT___ && typeof ___CSS_LOADER_EXPORT___.forEach === "function") { - ___CSS_LOADER_EXPORT___.forEach(cssExport => { - if (cssExport.length > 1 && cssExport[1]) { - // applying the second item of the export as it contains the css contents - Application.addCss(cssExport[1]); - } - }); - } -`; - - this.callback(null, content, map); -} diff --git a/packages/webpack/helpers/css2json-loader.d.ts b/packages/webpack/helpers/css2json-loader.d.ts deleted file mode 100644 index 55fd343ba..000000000 --- a/packages/webpack/helpers/css2json-loader.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { loader } from 'webpack'; -declare const loader: loader.Loader; -export default loader; diff --git a/packages/webpack/helpers/css2json-loader.spec.d.ts b/packages/webpack/helpers/css2json-loader.spec.d.ts deleted file mode 100644 index cb0ff5c3b..000000000 --- a/packages/webpack/helpers/css2json-loader.spec.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/packages/webpack/helpers/css2json-loader.spec.ts b/packages/webpack/helpers/css2json-loader.spec.ts deleted file mode 100644 index 6553b4586..000000000 --- a/packages/webpack/helpers/css2json-loader.spec.ts +++ /dev/null @@ -1,66 +0,0 @@ -import css2jsonLoader from './css2json-loader'; - -const importTestCases = [`@import url("custom.css");`, `@import url('custom.css');`, `@import url('custom.css') print;`, `@import url("custom.css") print;`, `@import url('custom.css') screen and (orientation:landscape);`, `@import url("custom.css") screen and (orientation:landscape);`, `@import 'custom.css';`, `@import "custom.css";`, `@import 'custom.css' screen;`, `@import "custom.css" screen;`, `@import url(custom.css);`]; - -const someCSS = ` -.btn { - background-color: #7f9 -} -`; - -describe('css2jsonLoader', () => { - it('converts CSS to JSON', (done) => { - const loaderContext = { - callback: (error, source: string, map) => { - expect(source).toContain(`{"type":"declaration","property":"background-color","value":"#7f9"}`); - - done(); - }, - }; - - css2jsonLoader.call(loaderContext, someCSS); - }); - - importTestCases.forEach((importTestCase) => { - it(`handles: ${importTestCase}`, (done) => { - const loaderContext = { - callback: (error, source: string, map) => { - expect(source).toContain(`global.registerModule("./custom.css", () => require("./custom.css"))`); - expect(source).toContain(`{"type":"declaration","property":"background-color","value":"#7f9"}`); - - done(); - }, - }; - - css2jsonLoader.call(loaderContext, importTestCase + someCSS); - }); - }); - - it('inlines css2json loader in imports if option is provided', (done) => { - const loaderContext = { - callback: (error, source: string, map) => { - expect(source).toContain(`global.registerModule("./custom.css", () => require("!@nativescript/webpack/helpers/css2json-loader?useForImports!./custom.css"))`); - expect(source).toContain(`{"type":"declaration","property":"background-color","value":"#7f9"}`); - - done(); - }, - query: { useForImports: true }, - }; - - css2jsonLoader.call(loaderContext, `@import url("custom.css");` + someCSS); - }); - - it('registers modules for paths starting with ~', (done) => { - const loaderContext = { - callback: (error, source: string, map) => { - expect(source).toContain(`global.registerModule("~custom.css", () => require("custom.css"))`); - expect(source).toContain(`global.registerModule("custom.css", () => require("custom.css"))`); - expect(source).toContain(`{"type":"declaration","property":"background-color","value":"#7f9"}`); - - done(); - }, - }; - - css2jsonLoader.call(loaderContext, `@import url("~custom.css");` + someCSS); - }); -}); diff --git a/packages/webpack/helpers/css2json-loader.ts b/packages/webpack/helpers/css2json-loader.ts deleted file mode 100644 index 9a1676207..000000000 --- a/packages/webpack/helpers/css2json-loader.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { parse, Import, Stylesheet } from 'css'; -import { loader } from 'webpack'; -import { getOptions, urlToRequest } from 'loader-utils'; - -const betweenQuotesPattern = /('|")(.*?)\1/; -const unpackUrlPattern = /url\(([^\)]+)\)/; -const inlineLoader = '!@nativescript/webpack/helpers/css2json-loader?useForImports!'; - -const loader: loader.Loader = function (content: string, map) { - const options = getOptions(this) || {}; - const inline = !!options.useForImports; - const requirePrefix = inline ? inlineLoader : ''; - - const ast = parse(content, undefined); - - let dependencies = []; - getImportRules(ast) - .map(extractUrlFromRule) - .map(createRequireUri) - .forEach(({ uri, requireURI }) => { - dependencies.push(`global.registerModule("${uri}", () => require("${requirePrefix}${requireURI}"));`); - - // Call registerModule with requireURI to handle cases like @import "~@nativescript/theme/css/blue.css"; - if (uri !== requireURI) { - dependencies.push(`global.registerModule("${requireURI}", () => require("${requirePrefix}${requireURI}"));`); - } - }); - const str = JSON.stringify(ast, (k, v) => (k === 'position' ? undefined : v)); - this.callback(null, `${dependencies.join('\n')}module.exports = ${str};`); -}; - -function getImportRules(ast: Stylesheet): Import[] { - if (!ast || (ast).type !== 'stylesheet' || !ast.stylesheet) { - return []; - } - return ast.stylesheet.rules.filter((rule) => rule.type === 'import' && (rule).import); -} - -/** - * Extracts the url from import rule (ex. `url("./platform.css")`) - */ -function extractUrlFromRule(importRule: Import): string { - const urlValue = importRule.import; - - const unpackedUrlMatch = urlValue.match(unpackUrlPattern); - const unpackedValue = unpackedUrlMatch ? unpackedUrlMatch[1] : urlValue; - - const quotesMatch = unpackedValue.match(betweenQuotesPattern); - return quotesMatch ? quotesMatch[2] : unpackedValue; -} - -function createRequireUri(uri): { uri: string; requireURI: string } { - return { - uri: uri, - requireURI: urlToRequest(uri), - }; -} - -export default loader; diff --git a/packages/webpack/helpers/dependencyManager.js b/packages/webpack/helpers/dependencyManager.js deleted file mode 100644 index 66f010e78..000000000 --- a/packages/webpack/helpers/dependencyManager.js +++ /dev/null @@ -1,110 +0,0 @@ -const { isAngular } = require("./projectHelpers"); - -const NEW_DEPS_MESSAGE = `\ -A few new dependencies were added. \ -Run "npm install" before building your project. -`; - -const ALREADY_ADDED_MESSAGE = `\ -Some dependencies have already been added. \ -If you want to force update them, please run "node_modules/.bin/update-ns-webpack". -`; - -function addProjectDeps(packageJson, force = false) { - packageJson.devDependencies = packageJson.devDependencies || {}; - const postinstallOptions = { - deps: Object.assign({}, packageJson.devDependencies), - }; - - const depsToAdd = getRequiredDeps(packageJson); - Object.keys(depsToAdd).forEach(function (name) { - const version = depsToAdd[name]; - Object.assign(postinstallOptions, - addDependency(postinstallOptions.deps, name, version, force)); - }); - - return postinstallOptions; -} - -function forceUpdateProjectDeps(packageJson) { - removeObsoleteDeps(packageJson); - - return addProjectDeps(packageJson, true); -} - -function removeObsoleteDeps(packageJson) { - const depsToRemove = [ - "webpack", - "webpack-cli", - "webpack-bundle-analyzer", - "webpack-sources", - "clean-webpack-plugin", - "copy-webpack-plugin", - "raw-loader", - "css-loader", - "nativescript-worker-loader", - "terser-webpack-plugin", - "@angular-devkit/core", - "resolve-url-loader", - "sass-loader", - ]; - - depsToRemove.forEach(dep => delete packageJson.devDependencies[dep]); -} - -function addDependency(deps, name, version, force) { - const options = { deps }; - - if (!deps[name] || force) { - deps[name] = version; - options.newDepsAdded = true; - console.info(`Adding dev dependency: ${name}@${version}`); - } else if (deps[name] !== version) { - options.hasOldDeps = true; - console.info(`Dev dependency: ${name} already added. Leaving version: ${deps[name]}`); - } - - return options; -} - -function getRequiredDeps(packageJson) { - if (!isAngular({ packageJson })) { - return false; - } - - const deps = { - "@angular/compiler-cli": "~10.0.0", - }; - - if (!dependsOn(packageJson, "@angular-devkit/build-angular")) { - deps["@ngtools/webpack"] = "~10.0.0"; - } - - return deps; -} - - -function dependsOn(packageJson, package) { - if (!packageJson) { - return false; - } - - return packageJson.dependencies.hasOwnProperty(package) || - packageJson.devDependencies.hasOwnProperty(package); -} - -function showHelperMessages({ newDepsAdded, hasOldDeps }) { - if (hasOldDeps) { - console.info(ALREADY_ADDED_MESSAGE); - } - - if (newDepsAdded) { - console.info(NEW_DEPS_MESSAGE); - } -} - -module.exports = { - addProjectDeps, - forceUpdateProjectDeps, - showHelperMessages, -}; diff --git a/packages/webpack/helpers/hot-loader-helper.js b/packages/webpack/helpers/hot-loader-helper.js deleted file mode 100644 index 5a81cb9fe..000000000 --- a/packages/webpack/helpers/hot-loader-helper.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports.reload = function ({ type, path }) { - return ` - if (module.hot) { - module.hot.accept(); - module.hot.dispose(() => { - global.hmrRefresh({ type: '${type}', path: '${path}' }); - }) - } -`}; diff --git a/packages/webpack/helpers/hot.js b/packages/webpack/helpers/hot.js deleted file mode 100644 index 4d9f5c770..000000000 --- a/packages/webpack/helpers/hot.js +++ /dev/null @@ -1,172 +0,0 @@ -const hmrPrefix = 'HMR:'; -const log = { - info: (message) => console.info(`${hmrPrefix} ${message}`), - warn: (message) => console.warn(`${hmrPrefix} ${message}`), - error: (message) => console.error(`${hmrPrefix} ${message}`), -}; -const refresh = 'Application needs to be restarted in order to apply the changes.'; -const hotOptions = { - ignoreUnaccepted: false, - ignoreDeclined: false, - ignoreErrored: false, - onUnaccepted(data) { - const chain = [].concat(data.chain); - const last = chain[chain.length - 1]; - - if (last === 0) { - chain.pop(); - } - - log.warn(`Ignored an update to unaccepted module: `); - chain.forEach(mod => log.warn(` ➭ ${mod}`)); - }, - onDeclined(data) { - log.warn(`Ignored an update to declined module:`); - data.chain.forEach(mod => log.warn(` ➭ ${mod}`)); - }, - onErrored(data) { - log.warn( - `Ignored an error while updating module ${data.moduleId} <${data.type}>` - ); - log.warn(data.error); - }, -}; - -let nextHash; -let currentHash; - -function upToDate() { - return nextHash.indexOf(__webpack_hash__) >= 0; -} - -function result(modules, appliedModules) { - const unaccepted = modules.filter( - (moduleId) => appliedModules && appliedModules.indexOf(moduleId) < 0 - ); - - if (unaccepted.length > 0) { - log.warn('The following modules could not be updated:'); - - for (const moduleId of unaccepted) { - log.warn(` ⦻ ${moduleId}`); - } - } - - if (!(appliedModules || []).length) { - log.info('No Modules Updated.'); - } else { - log.info('The following modules were updated:'); - - for (const moduleId of appliedModules) { - log.info(` ↻ ${moduleId}`); - } - - const numberIds = appliedModules.every( - (moduleId) => typeof moduleId === 'number' - ); - if (numberIds) { - log.info( - 'Please consider using the NamedModulesPlugin for module names.' - ); - } - } -} - -function check(options) { - return module.hot - .check() - .then((modules) => { - if (!modules) { - log.warn( - `Cannot find update. ${refresh}` - ); - return null; - } - - return module.hot - .apply(hotOptions) - .then((appliedModules) => { - let nextCheck; - if (!upToDate()) { - nextCheck = check(options); - } - - result(modules, appliedModules); - - if (upToDate()) { - // Do not modify message - CLI depends on this exact content to determine hmr operation status. - log.info(`Successfully applied update with hmr hash ${currentHash}. App is up to date.`); - } - - return nextCheck || null; - }) - .catch((err) => { - const status = module.hot.status(); - if (['abort', 'fail'].indexOf(status) >= 0) { - // Do not modify message - CLI depends on this exact content to determine hmr operation status. - log.error(`Cannot apply update with hmr hash ${currentHash}.`); - log.error(err.message || err.stack); - } else { - log.error(`Update failed: ${err.message || err.stack}`); - } - }); - }) - .catch((err) => { - const status = module.hot.status(); - if (['abort', 'fail'].indexOf(status) >= 0) { - log.error(`Cannot check for update. ${refresh}`); - log.error(err.message || err.stack); - } else { - log.error(`Update check failed: ${err.message || err.stack}`); - } - }); -} - -if (module.hot) { - log.info('Hot Module Replacement Enabled. Waiting for signal.'); -} else { - log.error('Hot Module Replacement is disabled.'); -} - -function update(latestHash, options) { - nextHash = latestHash; - if (!upToDate()) { - const status = module.hot.status(); - - if (status === 'idle') { - //Do not modify message - CLI depends on this exact content to determine hmr operation status. - log.info(`Checking for updates to the bundle with hmr hash ${currentHash}.`); - return check(options); - } else if (['abort', 'fail'].indexOf(status) >= 0) { - log.warn( - `Cannot apply update. A previous update ${status}ed. ${refresh}` - ); - } - } -}; - -function getNextHash(hash, getFileContent) { - const file = getFileContent(`${hash}.hot-update.json`); - if (!file) { - return Promise.resolve(hash); - } - - return file.readText().then(hotUpdateContent => { - if (hotUpdateContent) { - const manifest = JSON.parse(hotUpdateContent); - const newHash = manifest.h; - return getNextHash(newHash, getFileContent); - } else { - return Promise.resolve(hash); - } - }).catch(error => Promise.reject(error)); -} - -module.exports = function checkState(initialHash, getFileContent) { - currentHash = initialHash; - return getNextHash(initialHash, getFileContent).then(nextHash => { - if (nextHash != initialHash) { - return update(nextHash, {}); - } - }) -} diff --git a/packages/webpack/helpers/lazy-ngmodule-hot-loader.js b/packages/webpack/helpers/lazy-ngmodule-hot-loader.js deleted file mode 100644 index d38f20b89..000000000 --- a/packages/webpack/helpers/lazy-ngmodule-hot-loader.js +++ /dev/null @@ -1,30 +0,0 @@ -const { safeGet } = require("./projectHelpers"); - -const LAZY_RESOURCE_CONTEXT = "$$_lazy_route_resource"; -const HOT_SELF_ACCEPT = "module.hot.accept();"; -const HOT_DISPOSE = ` - module.hot.dispose(() => { - // Currently the context is needed only for application style modules. - const moduleContext = {}; - global.hmrRefresh(moduleContext); - });`; -const HMR_HANDLER = ` - if (module.hot) { - ${HOT_SELF_ACCEPT}${HOT_DISPOSE} - } -`; - -const isLazyLoadedNgModule = resource => { - const issuer = safeGet(resource, "issuer"); - const issuerContext = safeGet(issuer, "context"); - - return issuerContext && issuerContext.endsWith(LAZY_RESOURCE_CONTEXT); -}; - -module.exports = function (source, map) { - const modifiedSource = isLazyLoadedNgModule(this._module) ? - `${source};${HMR_HANDLER}`: - source; - - this.callback(null, modifiedSource, map); -}; diff --git a/packages/webpack/helpers/load-application-css-angular.js b/packages/webpack/helpers/load-application-css-angular.js deleted file mode 100644 index 42e721670..000000000 --- a/packages/webpack/helpers/load-application-css-angular.js +++ /dev/null @@ -1,8 +0,0 @@ -const loadCss = require("./load-application-css"); - -module.exports = function() { - loadCss(function() { - global.registerModule("./app.css", () => require("~/app")); - global.registerModule("app.css", () => require("~/app")); - }); -} diff --git a/packages/webpack/helpers/load-application-css-regular.js b/packages/webpack/helpers/load-application-css-regular.js deleted file mode 100644 index eaa99d3de..000000000 --- a/packages/webpack/helpers/load-application-css-regular.js +++ /dev/null @@ -1,8 +0,0 @@ -const loadCss = require("./load-application-css"); - -module.exports = function() { - loadCss(function() { - const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sass)$/); - global.registerWebpackModules(appCssContext); - }); -} diff --git a/packages/webpack/helpers/load-application-css.js b/packages/webpack/helpers/load-application-css.js deleted file mode 100644 index 70fb4ed6a..000000000 --- a/packages/webpack/helpers/load-application-css.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = function (loadModuleFn) { - const nsCore = require("@nativescript/core"); - require("@nativescript/core/ui/styling/style-scope"); - - loadModuleFn(); - - nsCore.Application.loadAppCss(); -} diff --git a/packages/webpack/helpers/markup-hot-loader.js b/packages/webpack/helpers/markup-hot-loader.js deleted file mode 100644 index 2f8576af6..000000000 --- a/packages/webpack/helpers/markup-hot-loader.js +++ /dev/null @@ -1,10 +0,0 @@ -const { reload } = require("./hot-loader-helper"); -const { convertToUnixPath } = require("../lib/utils"); - -module.exports = function (source, map) { - const typeMarkup = "markup"; - const moduleRelativePath = this.resourcePath.replace(this.rootContext, "."); - const modulePath = convertToUnixPath(moduleRelativePath); - - this.callback(null, `${source};${reload({ type: typeMarkup, path: modulePath })}`, map); -}; diff --git a/packages/webpack/helpers/moduleid-compat-loader.js b/packages/webpack/helpers/moduleid-compat-loader.js deleted file mode 100644 index 6ade9e7f7..000000000 --- a/packages/webpack/helpers/moduleid-compat-loader.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * When building NativeScript angular apps without webpack (`tns run android`) the moduleId: module.id is necessary. - * When building with webpack the angular compiler and webpack handle relative paths in the modules and no longer need moduleId - * to be set, however webpack emits numbers for module.id and angular has typecheck for moduleId to be a string. - */ -module.exports = function (source, map) { - this.cacheable(); - - // Strips occurrences of `moduleId: module.id,`, since it is no longer needed for webpack builds - const noModuleIdsSource = source.replace(/moduleId\:\s*module\.id\s*(\,)?/g, result => - // Try to preserve char count so sourcemaps may remain intact - "/*" + result.substring(2, result.length - 2) + "*/" - ); - - this.callback(null, noModuleIdsSource, map); -}; diff --git a/packages/webpack/helpers/projectFilesManager.js b/packages/webpack/helpers/projectFilesManager.js deleted file mode 100644 index 856c80b1e..000000000 --- a/packages/webpack/helpers/projectFilesManager.js +++ /dev/null @@ -1,152 +0,0 @@ -const path = require("path"); -const fs = require("fs"); - -const { isTypeScript, isAngular, isVue, isReact, isSvelte, isShared, isPlugin } = require("./projectHelpers"); - -function addProjectFiles(projectDir) { - const projectTemplates = getProjectTemplates(projectDir); - Object.keys(projectTemplates).forEach(function (templateName) { - const templateDestination = projectTemplates[templateName]; - templateName = path.resolve(templateName); - copyTemplate(templateName, templateDestination); - }); -} - -function removeProjectFiles(projectDir) { - const projectTemplates = getProjectTemplates(projectDir); - Object.keys(projectTemplates).forEach(function (templateName) { - const templateDestination = projectTemplates[templateName]; - deleteFile(templateDestination); - }); -} - -function forceUpdateProjectFiles(projectDir) { - removeProjectFiles(projectDir); - addProjectFiles(projectDir); -} - -function compareProjectFiles(projectDir) { - const projectTemplates = getProjectTemplates(projectDir); - Object.keys(projectTemplates).forEach(newTemplatePath => { - const currentTemplatePath = projectTemplates[newTemplatePath]; - if (fs.existsSync(currentTemplatePath)) { - const currentTemplate = fs.readFileSync(currentTemplatePath).toString(); - const newTemplate = fs.readFileSync(newTemplatePath).toString(); - if (newTemplate.replace(/\s/g, '') !== currentTemplate.replace(/\s/g, '')) { - const message = `Note: ${path.basename(currentTemplatePath)} is different than the suggested @nativescript/webpack config at ${newTemplatePath}.\nIf you have build trouble you can update to latest config using "./node_modules/.bin/update-ns-webpack --configs" command.`; - console.info(`\x1B[33;1m${message}\x1B[0m`); - } - } - }); -} - -function deleteFile(destinationPath) { - if (fs.existsSync(destinationPath)) { - console.info(`Deleting file: ${destinationPath}`); - fs.unlinkSync(destinationPath); - } -} - -function copyTemplate(templateName, destinationPath) { - // Create destination file, only if not present. - if (!fs.existsSync(destinationPath)) { - console.info(`Creating file: ${destinationPath}`); - const content = fs.readFileSync(templateName, "utf8"); - fs.writeFileSync(destinationPath, content); - } -} - -function getProjectTemplates(projectDir) { - const WEBPACK_CONFIG_NAME = "webpack.config.js"; - - let templates; - if (isPlugin({ projectDir })) { - // TODO: create config for plugin builds - templates = []; - } else if (isAngular({ projectDir })) { - if (isShared({ projectDir })) { - templates = getSharedAngularTemplates(WEBPACK_CONFIG_NAME); - } else { - templates = getAngularTemplates(WEBPACK_CONFIG_NAME); - } - } else if (isVue({ projectDir })) { - templates = getVueTemplates(WEBPACK_CONFIG_NAME); - } else if (isReact({ projectDir })) { - templates = getReactTemplates(WEBPACK_CONFIG_NAME); - } else if (isSvelte({ projectDir })) { - templates = getSvelteTemplates(WEBPACK_CONFIG_NAME); - } else if (isTypeScript({ projectDir })) { - templates = getTypeScriptTemplates(WEBPACK_CONFIG_NAME); - } else { - templates = getJavaScriptTemplates(WEBPACK_CONFIG_NAME); - } - - return getFullTemplatesPath(projectDir, templates); -} - -function getSharedAngularTemplates(webpackConfigName) { - return { - "webpack.angular.js": webpackConfigName, - }; -} - -function getAngularTemplates(webpackConfigName) { - return { - "webpack.angular.js": webpackConfigName - }; -} - -function getTypeScriptTemplates(webpackConfigName) { - return { - "webpack.typescript.js": webpackConfigName - }; -} - -function getVueTemplates(webpackConfigName) { - return { - "webpack.vue.js": webpackConfigName - }; -} - -function getReactTemplates(webpackConfigName) { - return { - "webpack.typescript.js": "webpack.typescript.js", - "webpack.react.js": webpackConfigName - }; -} - -function getSvelteTemplates(webpackConfigName) { - return { - "webpack.svelte.js": webpackConfigName - }; -} - -function getJavaScriptTemplates(webpackConfigName) { - return { - "webpack.javascript.js": webpackConfigName, - }; -} - -function getFullTemplatesPath(projectDir, templates) { - let updatedTemplates = {}; - - Object.keys(templates).forEach(key => { - const updatedKey = getFullPath(path.join(__dirname, "..", "templates"), key); - const updatedValue = getFullPath(projectDir, templates[key]) - - updatedTemplates[updatedKey] = updatedValue; - }); - - return updatedTemplates; -} - -function getFullPath(projectDir, filePath) { - return path.resolve(projectDir, filePath); -} - -module.exports = { - addProjectFiles, - removeProjectFiles, - forceUpdateProjectFiles, - compareProjectFiles, -}; diff --git a/packages/webpack/helpers/projectHelpers.js b/packages/webpack/helpers/projectHelpers.js deleted file mode 100644 index 77bd60804..000000000 --- a/packages/webpack/helpers/projectHelpers.js +++ /dev/null @@ -1,162 +0,0 @@ -const { resolve } = require("path"); -const fs = require("fs"); - -const hook = require("@nativescript/hook")(__dirname); - -const isTypeScript = ({ projectDir, packageJson } = {}) => { - packageJson = packageJson || getPackageJson(projectDir); - - return ( - packageJson.dependencies && - packageJson.dependencies.hasOwnProperty("typescript")) - || (packageJson.devDependencies && - packageJson.devDependencies.hasOwnProperty("typescript")) - || isAngular({ packageJson }); -}; - -const isShared = ({ projectDir }) => { - const nsConfig = getNsConfig(projectDir); - return nsConfig && !!nsConfig.shared; -} - -const isPlugin = ({ projectDir, packageJson } = {}) => { - packageJson = packageJson || getPackageJson(projectDir); - return packageJson && packageJson.bootstrapper && (['nativescript-plugin-seed', '@nativescript/plugin-seed'].includes(packageJson.bootstrapper)); -} - -const isAngular = ({ projectDir, packageJson } = {}) => { - packageJson = packageJson || getPackageJson(projectDir); - - return packageJson.dependencies && Object.keys(packageJson.dependencies) - .some(dependency => /^@angular\b/.test(dependency)); -}; - -const getAngularVersion = ({ projectDir, packageJson } = {}) => { - packageJson = packageJson || getPackageJson(projectDir); - - return packageJson.dependencies && packageJson.dependencies["@angular/core"]; -} - -const isVue = ({ projectDir, packageJson } = {}) => { - packageJson = packageJson || getPackageJson(projectDir); - - return packageJson.dependencies && Object.keys(packageJson.dependencies) - .some(dependency => dependency === "nativescript-vue"); -}; - -const isReact = ({ projectDir, packageJson } = {}) => { - packageJson = packageJson || getPackageJson(projectDir); - - return packageJson.dependencies && Object.keys(packageJson.dependencies) - .some(dependency => dependency === "react-nativescript"); -}; - -const isSvelte = ({ projectDir, packageJson } = {}) => { - packageJson = packageJson || getPackageJson(projectDir); - - return packageJson.dependencies && Object.keys(packageJson.dependencies) - .some(dependency => dependency === "svelte-native"); -}; - -const getPackageJson = projectDir => { - const packageJsonPath = getPackageJsonPath(projectDir); - const result = readJsonFile(packageJsonPath); - - return result; -}; - -const getNsConfig = projectDir => { - const nsConfigPath = getNsConfigPath(projectDir); - const result = readJsonFile(nsConfigPath); - - return result; -}; - -const readJsonFile = filePath => { - let result; - try { - result = JSON.parse(fs.readFileSync(filePath, "utf8")); - } catch (e) { - result = {}; - } - - return result; -}; - -const writePackageJson = (content, projectDir) => { - const packageJsonPath = getPackageJsonPath(projectDir); - const currentJsonContent = fs.readFileSync(packageJsonPath); - const indentation = getIndentationCharacter(currentJsonContent); - const stringifiedContent = JSON.stringify(content, null, indentation); - const currentPackageJsonContent = JSON.parse(currentJsonContent); - - if (JSON.stringify(currentPackageJsonContent, null, indentation) !== stringifiedContent) { - fs.writeFileSync(packageJsonPath, stringifiedContent) - } -} - -const getIndentationCharacter = (jsonContent) => { - const matches = jsonContent && jsonContent.toString().match(/{\r*\n*(\W*)"/m); - return matches && matches[1]; -} - -const getProjectDir = hook.findProjectDir; - -const getPackageJsonPath = projectDir => { - const packagePath = resolve(projectDir, "package.json"); - if (fs.existsSync(packagePath)) { - return packagePath; - } else { - return getPackageJsonPath(resolve(projectDir, '..')); - } - -} -const getNsConfigPath = projectDir => resolve(projectDir, "nsconfig.json"); - -const isAndroid = platform => /android/i.test(platform); -const isIos = platform => /ios/i.test(platform); - -function safeGet(object, property, ...args) { - if (!object) { - return; - } - - const value = object[property]; - if (!value) { - return; - } - - return typeof value === "function" ? - value.bind(object)(...args) : - value; -} - -// Convert paths from C:\some\path to C:/some/path in order to be required -function convertSlashesInPath(modulePath) { - if (isWindows) { - modulePath = modulePath.replace(/\\/g, "/"); - } - return modulePath; -} - -const isWindows = process.platform.startsWith("win32"); - -module.exports = { - getPackageJson, - getProjectDir, - isAndroid, - isIos, - isAngular, - isShared, - isPlugin, - getAngularVersion, - isVue, - isReact, - isSvelte, - isTypeScript, - writePackageJson, - convertSlashesInPath, - getIndentationCharacter, - safeGet, -}; - diff --git a/packages/webpack/helpers/projectHelpers.spec.js b/packages/webpack/helpers/projectHelpers.spec.js deleted file mode 100644 index 364259250..000000000 --- a/packages/webpack/helpers/projectHelpers.spec.js +++ /dev/null @@ -1,132 +0,0 @@ -const { getIndentationCharacter, writePackageJson, safeGet } = require("./projectHelpers"); -const fs = require("fs"); - -describe('projectHelpers', () => { - const originalReadFileSync = fs.readFileSync; - const originalWriteFileSync = fs.writeFileSync; - const tab = "\t"; - const multipleSpaces = " "; - const twoSpaces = " "; - - afterEach(() => { - fs.readFileSync = originalReadFileSync; - fs.writeFileSync = originalWriteFileSync; - }); - - describe('getIndentationCharacter', () => { - [ - { - testName: 'returns two spaces when file starts with two spaces', - input: `{${twoSpaces}"abc": "1"${twoSpaces}}`, - expectedResult: twoSpaces - }, - { - testName: 'returns two spaces when file starts with two spaces and binary content is passed', - input: Buffer.from(`{${twoSpaces}"abc": "1"${twoSpaces}}`), - expectedResult: twoSpaces - }, - { - testName: 'returns empty string when file starts without any indentation', - input: `{"abc": "1"}`, - expectedResult: '' - }, - { - testName: 'returns tab when file starts with tab', - input: `{${tab}"abc": "1"${tab}}`, - expectedResult: tab - }, - { - testName: 'returns two spaces when file starts with two spaces and new line before them', - input: `{\n${twoSpaces}"abc": "1"\n}`, - expectedResult: twoSpaces - }, - { - testName: 'returns tab when file starts with tab and new line before them', - input: `{\n${tab}"abc": "1"\n}`, - expectedResult: tab - }, - { - testName: 'returns multiple spaces when file starts with multiple spaces and new line before them', - input: `{\n${multipleSpaces}"abc": "1"\n}`, - expectedResult: multipleSpaces - } - ].forEach(({ testName, input, expectedResult }) => { - it(testName, () => { - expect(getIndentationCharacter(input)).toEqual(expectedResult); - }); - }); - }); - - describe('safeGet', () => { - it('should return the correct value of existing properties', () => { - const obj = { a: 15 }; - expect(safeGet(obj, 'a')).toBe(15); - }); - - it('should return undefined for unexisting properties', () => { - const obj = { a: 15 }; - expect(safeGet(obj, 'random')).toBeUndefined(); - }); - - it('should return undefined when the first argument is undefined', () => { - let obj; - expect(safeGet(obj, 'random')).toBeUndefined(); - }); - - it('should return undefined when the first argument is not an object and does not have inherited property with the queried name', () => { - const num = 15; - expect(safeGet(num, 'random')).toBeUndefined(); - }); - }); - - describe('writePackageJson', () => { - const mockFileSystemApi = () => { - const data = { - isWriteFileSyncCalled: false - }; - - fs.readFileSync = (p) => { - return JSON.stringify({ a: 1 }); - }; - - fs.writeFileSync = (p, c) => { - data.isWriteFileSyncCalled = true; - }; - - return data; - }; - - it('does not write package.json when content has not changed', () => { - const data = mockFileSystemApi(); - writePackageJson({ a: 1 }, "projDir"); - expect(data.isWriteFileSyncCalled).toBe(false); - }); - - it('writes content, when the new one is different from the current one', () => { - const data = mockFileSystemApi(); - writePackageJson({ b: 2 }, "projDir"); - expect(data.isWriteFileSyncCalled).toBe(true); - }); - - it('keeps indentation of the package.json when rewriting it', () => { - let currentIndentSymbol = tab; - fs.readFileSync = (p) => { - return JSON.stringify({ a: 1 }, null, currentIndentSymbol); - }; - - let writtenContent = null; - fs.writeFileSync = (p, c) => { - writtenContent = c; - }; - - // Ensure tab indentation is persisted - writePackageJson({ b: 2 }, "projDir"); - expect(writtenContent).toBe(`{\n${tab}"b": 2\n}`); - - // Ensure spaces indentation is persisted - currentIndentSymbol = multipleSpaces; - writePackageJson({ b: 2 }, "projDir"); - expect(writtenContent).toBe(`{\n${multipleSpaces}"b": 2\n}`); - }); - }); -}); diff --git a/packages/webpack/helpers/script-hot-loader.js b/packages/webpack/helpers/script-hot-loader.js deleted file mode 100644 index 31c147bce..000000000 --- a/packages/webpack/helpers/script-hot-loader.js +++ /dev/null @@ -1,9 +0,0 @@ -const { reload } = require("./hot-loader-helper"); -const { convertToUnixPath } = require("../lib/utils"); - -module.exports = function (source, map) { - const typeScript = "script"; - const moduleRelativePath = this.resourcePath.replace(this.rootContext, "."); - const modulePath = convertToUnixPath(moduleRelativePath); - this.callback(null, `${source};${reload({ type: typeScript, path: modulePath })}`, map); -}; diff --git a/packages/webpack/helpers/style-hot-loader.js b/packages/webpack/helpers/style-hot-loader.js deleted file mode 100644 index de1e75638..000000000 --- a/packages/webpack/helpers/style-hot-loader.js +++ /dev/null @@ -1,10 +0,0 @@ -const { reload } = require("./hot-loader-helper"); -const { convertToUnixPath } = require("../lib/utils"); - -module.exports = function (source, map) { - const typeStyle = "style"; - const moduleRelativePath = this.resourcePath.replace(this.rootContext, "."); - const modulePath = convertToUnixPath(moduleRelativePath); - - this.callback(null, `${source};${reload({ type: typeStyle, path: modulePath })}`, map); -}; diff --git a/packages/webpack/helpers/xml-namespace-loader.d.ts b/packages/webpack/helpers/xml-namespace-loader.d.ts deleted file mode 100644 index 55fd343ba..000000000 --- a/packages/webpack/helpers/xml-namespace-loader.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { loader } from 'webpack'; -declare const loader: loader.Loader; -export default loader; diff --git a/packages/webpack/helpers/xml-namespace-loader.spec.d.ts b/packages/webpack/helpers/xml-namespace-loader.spec.d.ts deleted file mode 100644 index cb0ff5c3b..000000000 --- a/packages/webpack/helpers/xml-namespace-loader.spec.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/packages/webpack/helpers/xml-namespace-loader.spec.ts b/packages/webpack/helpers/xml-namespace-loader.spec.ts deleted file mode 100644 index 8f3927f78..000000000 --- a/packages/webpack/helpers/xml-namespace-loader.spec.ts +++ /dev/null @@ -1,296 +0,0 @@ -import xmlNsLoader from './xml-namespace-loader'; -import { convertSlashesInPath } from './projectHelpers'; - -const CODE_FILE = ` - - - - - - - - - - -`; - -interface TestSetup { - resolveMap: { [path: string]: string }; - expectedDeps: string[]; - expectedRegs: { name: string; path: string }[]; - ignore?: RegExp; - assureNoDeps?: boolean; - expectError?: boolean; - expectWarnings?: number; -} - -function getContext(done: DoneFn, { resolveMap, expectedDeps, expectedRegs, assureNoDeps, ignore, expectError, expectWarnings }: TestSetup) { - const actualDeps: string[] = []; - const actualWarnings: Error[] = []; - let callbackCalled = false; - - const loaderContext = { - rootContext: 'app', - context: 'app/component', - async: () => (error, source: string) => { - if (callbackCalled) { - done.fail('Callback called more than once!'); - } - callbackCalled = true; - - expectedDeps.forEach((expectedDep) => expect(actualDeps).toContain(expectedDep)); - - expectedRegs.forEach(({ name, path }) => { - const regCode = `global.registerModule("${name}", function() { return require("${path}"); });`; - expect(source).toContain(regCode); - }); - - if (assureNoDeps) { - expect(actualDeps.length).toBe(0); - expect(source).not.toContain('global.registerModule'); - } - - if (expectWarnings) { - expect(actualWarnings.length).toEqual(expectWarnings); - } - - if (error && !expectError) { - done.fail(error); - } else if (!error && expectError) { - done.fail('Error expected here'); - } else { - done(); - } - }, - resolve: (context: string, request: string, callback: (err: Error, result: string) => void) => { - request = convertSlashesInPath(request); - if (resolveMap[request]) { - callback(undefined, resolveMap[request]); - } else { - callback(new Error(`Module ${request} not found`), undefined); - } - }, - addDependency: (dep: string) => { - actualDeps.push(dep); - }, - emitWarning: (err: Error) => { - actualWarnings.push(err); - }, - query: { ignore }, - }; - - return loaderContext; -} - -describe('XmlNamespaceLoader', () => { - it('with namespace pointing to files', (done) => { - const resolveMap = { - 'app/nativescript-ui-chart': 'app/nativescript-ui-chart.js', - 'app/nativescript-ui-chart.xml': 'app/nativescript-ui-chart.xml', - 'app/nativescript-ui-chart.css': 'app/nativescript-ui-chart.css', - }; - - const expectedDeps = ['app/nativescript-ui-chart.js', 'app/nativescript-ui-chart.xml', 'app/nativescript-ui-chart.css']; - - const expectedRegs = [ - { name: 'nativescript-ui-chart', path: 'app/nativescript-ui-chart.js' }, - { name: 'nativescript-ui-chart/RadCartesianChart', path: 'app/nativescript-ui-chart.js' }, - { name: 'nativescript-ui-chart/RadCartesianChart.xml', path: 'app/nativescript-ui-chart.xml' }, - { name: 'nativescript-ui-chart/RadCartesianChart.css', path: 'app/nativescript-ui-chart.css' }, - ]; - - const loaderContext = getContext(done, { resolveMap, expectedDeps, expectedRegs }); - - xmlNsLoader.call(loaderContext, CODE_FILE); - }); - - it('with namespace/elementName pointing to files (with package.json)', (done) => { - const resolveMap = { - 'app/nativescript-ui-chart': 'app/nativescript-ui-chart/RadCartesianChart.js', //simulate package.json - 'app/nativescript-ui-chart/RadCartesianChart': 'app/nativescript-ui-chart/RadCartesianChart.js', - 'app/nativescript-ui-chart/RadCartesianChart.xml': 'app/nativescript-ui-chart/RadCartesianChart.xml', - 'app/nativescript-ui-chart/RadCartesianChart.css': 'app/nativescript-ui-chart/RadCartesianChart.css', - }; - - const expectedDeps = ['app/nativescript-ui-chart/RadCartesianChart.js', 'app/nativescript-ui-chart/RadCartesianChart.xml', 'app/nativescript-ui-chart/RadCartesianChart.css']; - - const expectedRegs = [ - { name: 'nativescript-ui-chart', path: 'app/nativescript-ui-chart/RadCartesianChart.js' }, - { name: 'nativescript-ui-chart/RadCartesianChart', path: 'app/nativescript-ui-chart/RadCartesianChart.js' }, - { name: 'nativescript-ui-chart/RadCartesianChart.xml', path: 'app/nativescript-ui-chart/RadCartesianChart.xml' }, - { name: 'nativescript-ui-chart/RadCartesianChart.css', path: 'app/nativescript-ui-chart/RadCartesianChart.css' }, - ]; - - const loaderContext = getContext(done, { resolveMap, expectedDeps, expectedRegs }); - xmlNsLoader.call(loaderContext, CODE_FILE); - }); - - it('with namespace/elementName pointing to files', (done) => { - const resolveMap = { - 'app/nativescript-ui-chart/RadCartesianChart': 'app/nativescript-ui-chart/RadCartesianChart.js', - 'app/nativescript-ui-chart/RadCartesianChart.xml': 'app/nativescript-ui-chart/RadCartesianChart.xml', - 'app/nativescript-ui-chart/RadCartesianChart.css': 'app/nativescript-ui-chart/RadCartesianChart.css', - }; - - const expectedDeps = ['app/nativescript-ui-chart/RadCartesianChart.js', 'app/nativescript-ui-chart/RadCartesianChart.xml', 'app/nativescript-ui-chart/RadCartesianChart.css']; - - const expectedRegs = [ - { name: 'nativescript-ui-chart', path: 'app/nativescript-ui-chart/RadCartesianChart.js' }, - { name: 'nativescript-ui-chart/RadCartesianChart', path: 'app/nativescript-ui-chart/RadCartesianChart.js' }, - { name: 'nativescript-ui-chart/RadCartesianChart.xml', path: 'app/nativescript-ui-chart/RadCartesianChart.xml' }, - { name: 'nativescript-ui-chart/RadCartesianChart.css', path: 'app/nativescript-ui-chart/RadCartesianChart.css' }, - ]; - - const loaderContext = getContext(done, { resolveMap, expectedDeps, expectedRegs }); - xmlNsLoader.call(loaderContext, CODE_FILE); - }); - - it('with namespace/elementName pointing to files - only XML and CSS', (done) => { - const resolveMap = { - 'app/nativescript-ui-chart/RadCartesianChart.xml': 'app/nativescript-ui-chart/RadCartesianChart.xml', - 'app/nativescript-ui-chart/RadCartesianChart.css': 'app/nativescript-ui-chart/RadCartesianChart.css', - }; - - const expectedDeps = ['app/nativescript-ui-chart/RadCartesianChart.xml', 'app/nativescript-ui-chart/RadCartesianChart.css']; - - const expectedRegs = [ - { name: 'nativescript-ui-chart/RadCartesianChart.xml', path: 'app/nativescript-ui-chart/RadCartesianChart.xml' }, - { name: 'nativescript-ui-chart/RadCartesianChart.css', path: 'app/nativescript-ui-chart/RadCartesianChart.css' }, - ]; - - const loaderContext = getContext(done, { resolveMap, expectedDeps, expectedRegs }); - xmlNsLoader.call(loaderContext, CODE_FILE); - }); - - it('with plugin path', (done) => { - const resolveMap = { - 'nativescript-ui-chart': 'node_module/nativescript-ui-chart/ui-chart.js', - }; - - const expectedDeps = []; - - const expectedRegs = [ - { name: 'nativescript-ui-chart', path: 'nativescript-ui-chart' }, - { name: 'nativescript-ui-chart/RadCartesianChart', path: 'nativescript-ui-chart' }, - ]; - - const loaderContext = getContext(done, { resolveMap, expectedDeps, expectedRegs }); - xmlNsLoader.call(loaderContext, CODE_FILE); - }); - - it('with ignored namespace should not add deps or register calls', (done) => { - const resolveMap = { - 'app/nativescript-ui-chart': 'app/nativescript-ui-chart.js', - 'app/nativescript-ui-chart.xml': 'app/nativescript-ui-chart.xml', - 'app/nativescript-ui-chart.css': 'app/nativescript-ui-chart.css', - }; - const expectedDeps = []; - const expectedRegs = []; - - const loaderContext = getContext(done, { resolveMap, expectedDeps, expectedRegs, ignore: /nativescript\-ui\-chart/, assureNoDeps: true }); - - xmlNsLoader.call(loaderContext, CODE_FILE); - }); - - it('with XML declaration and Doctype does not fail', (done) => { - const resolveMap = {}; - const expectedDeps = []; - const expectedRegs = []; - - const testXml = ` - - - - `; - - const loaderContext = getContext(done, { resolveMap, expectedDeps, expectedRegs, assureNoDeps: true }); - - xmlNsLoader.call(loaderContext, testXml); - }); - it('with invalid XML fails', (done) => { - const resolveMap = {}; - const expectedDeps = []; - const expectedRegs = []; - - const testXml = ``; - - const loaderContext = getContext(done, { resolveMap, expectedDeps, expectedRegs, expectError: true }); - - xmlNsLoader.call(loaderContext, testXml); - }); - - it("doesn't throw with ios and android platform namespaces", (done) => { - const resolveMap = {}; - const expectedDeps = []; - const expectedRegs = []; - - const testXml = ` - - - - `; - - const loaderContext = getContext(done, { resolveMap, expectedDeps, expectedRegs, assureNoDeps: true }); - - xmlNsLoader.call(loaderContext, testXml); - }); - - it("doesn't throw with ios and android platform namespaces", (done) => { - const resolveMap = {}; - const expectedDeps = []; - const expectedRegs = []; - - const testXml = ` - - - - - - `; - - const loaderContext = getContext(done, { resolveMap, expectedDeps, expectedRegs, assureNoDeps: true }); - - xmlNsLoader.call(loaderContext, testXml); - }); - - it('throws with unbound namespace namespaces', (done) => { - const resolveMap = {}; - const expectedDeps = []; - const expectedRegs = []; - - const testXml = ` - - - - `; - - const loaderContext = getContext(done, { resolveMap, expectedDeps, expectedRegs, expectError: true }); - - xmlNsLoader.call(loaderContext, testXml); - }); - - it("with '&&', '||', '<=' and '>=' in binding expression, emits warnings, but does not fail", (done) => { - const resolveMap = { - 'nativescript-ui-chart': 'node_module/nativescript-ui-chart/ui-chart.js', - }; - - const expectedDeps = []; - - const expectedRegs = [ - { name: 'nativescript-ui-chart', path: 'nativescript-ui-chart' }, - { name: 'nativescript-ui-chart/RadCartesianChart', path: 'nativescript-ui-chart' }, - ]; - - const testXml = ` - - - - - - `; - - const loaderContext = getContext(done, { resolveMap, expectedDeps, expectedRegs, expectWarnings: 1 }); - - xmlNsLoader.call(loaderContext, testXml); - }); -}); diff --git a/packages/webpack/helpers/xml-namespace-loader.ts b/packages/webpack/helpers/xml-namespace-loader.ts deleted file mode 100644 index 27f7b34be..000000000 --- a/packages/webpack/helpers/xml-namespace-loader.ts +++ /dev/null @@ -1,141 +0,0 @@ -import { parse, join } from 'path'; -import { promisify } from 'util'; -import { loader } from 'webpack'; -import { parser, QualifiedTag } from 'sax'; - -import { convertSlashesInPath } from './projectHelpers'; - -interface NamespaceEntry { - name: string; - path: string; -} - -const loader: loader.Loader = function (source: string, map) { - const { ignore } = this.query; - - let callbackCalled = false; - const callback = this.async(); - const callbackWrapper = (error?: Error, content?: string, map?: any) => { - if (!callbackCalled) { - callbackCalled = true; - callback(error, content, map); - } - }; - - const resolvePromise = promisify(this.resolve); - const promises: Promise[] = []; - const namespaces: NamespaceEntry[] = []; - - const handleOpenTag = (namespace: string, elementName: string) => { - const moduleName = `${namespace}/${elementName}`; - if (namespace && !namespace.startsWith('http') && !namespaces.some((n) => n.name === moduleName) && (!ignore || !moduleName.match(ignore))) { - const localNamespacePath = join(this.rootContext, namespace); - const localModulePath = join(localNamespacePath, elementName); - - const pathResolved = (resolvedPath) => { - this.addDependency(resolvedPath); - - namespaces.push({ name: namespace, path: resolvedPath }); - namespaces.push({ name: moduleName, path: resolvedPath }); - - const { dir, name } = parse(resolvedPath); - const noExtFilename = join(dir, name); - - return Promise.all([ - resolvePromise(this.context, `${noExtFilename}.xml`) - .then((xml) => { - this.addDependency(xml); - namespaces.push({ name: `${moduleName}.xml`, path: xml }); - }) - .catch((err) => {}), - - resolvePromise(this.context, `${noExtFilename}.css`) - .then((css) => { - this.addDependency(css); - namespaces.push({ name: `${moduleName}.css`, path: css }); - }) - .catch((err) => {}), - ]); - }; - - promises.push( - resolvePromise(this.context, localNamespacePath) - .then((path) => pathResolved(path)) - .catch(() => { - return resolvePromise(this.context, localModulePath) - .then((path) => pathResolved(path)) - .catch(() => { - return Promise.all([ - resolvePromise(this.context, `${localModulePath}.xml`) - .then((xml) => { - namespaces.push({ name: `${moduleName}.xml`, path: xml }); - this.addDependency(xml); - }) - .catch(() => { - namespaces.push({ name: namespace, path: namespace }); - namespaces.push({ name: moduleName, path: namespace }); - }), - - resolvePromise(this.context, `${localModulePath}.css`) - .then((css) => { - namespaces.push({ name: `${moduleName}.css`, path: css }); - this.addDependency(css); - }) - .catch(() => {}), - ]); - }); - }) - ); - } - }; - - const saxParser = parser(true, { xmlns: true }); - - // Register ios and android prefixes as namespaces to avoid "unbound xml namespace" errors - (saxParser).ns['ios'] = 'http://schemas.nativescript.org/tns.xsd'; - (saxParser).ns['android'] = 'http://schemas.nativescript.org/tns.xsd'; - (saxParser).ns['desktop'] = 'http://schemas.nativescript.org/tns.xsd'; - (saxParser).ns['web'] = 'http://schemas.nativescript.org/tns.xsd'; - - saxParser.onopentag = (node: QualifiedTag) => { - handleOpenTag(node.uri, node.local); - }; - saxParser.onerror = (err) => { - // Do only warning about invalid character "&"" for back-compatibility - // as it is common to use it in a binding expression - if (err && err.message.indexOf('Invalid character') >= 0 && err.message.indexOf('Char: &') >= 0) { - this.emitWarning(err); - } else { - callbackWrapper(err); - } - - saxParser.error = null; - }; - saxParser.write(source).close(); - - Promise.all(promises) - .then(() => { - const distinctNamespaces = new Map(); - namespaces.forEach(({ name, path }) => distinctNamespaces.set(name, convertSlashesInPath(path))); - - const moduleRegisters: string[] = []; - distinctNamespaces.forEach((path, name) => { - moduleRegisters.push(`global.registerModule("${name}", function() { return require("${path}"); });\n`); - }); - - // escape special whitespace characters - // see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Issue_with_plain_JSON.stringify_for_use_as_JavaScript - const json = JSON.stringify(source) - .replace(/\u2028/g, '\\u2028') - .replace(/\u2029/g, '\\u2029'); - - const wrapped = `${moduleRegisters.join('')}\nmodule.exports = ${json}`; - - callbackWrapper(null, wrapped, map); - }) - .catch((err) => { - callbackWrapper(err); - }); -}; - -export default loader; diff --git a/packages/webpack/hmr/hmr-update.d.ts b/packages/webpack/hmr/hmr-update.d.ts deleted file mode 100644 index c8c4d9ab0..000000000 --- a/packages/webpack/hmr/hmr-update.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function hmrUpdate(): any; diff --git a/packages/webpack/hmr/hmr-update.ts b/packages/webpack/hmr/hmr-update.ts deleted file mode 100644 index 85f3db565..000000000 --- a/packages/webpack/hmr/hmr-update.ts +++ /dev/null @@ -1,13 +0,0 @@ -import * as hot from '../helpers/hot'; - -declare const __webpack_require__: any; - -export function hmrUpdate() { - const coreFile = require('@nativescript/core'); - const currentAppFolder = coreFile.knownFolders.currentApp(); - const latestHash = __webpack_require__['h'](); - return hot(latestHash, (filename) => { - const fullFilePath = coreFile.path.join(currentAppFolder.path, filename); - return coreFile.File.exists(fullFilePath) ? currentAppFolder.getFile(filename) : null; - }); -} diff --git a/packages/webpack/hmr/hot-loader.d.ts b/packages/webpack/hmr/hot-loader.d.ts deleted file mode 100644 index 55fd343ba..000000000 --- a/packages/webpack/hmr/hot-loader.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { loader } from 'webpack'; -declare const loader: loader.Loader; -export default loader; diff --git a/packages/webpack/hmr/hot-loader.ts b/packages/webpack/hmr/hot-loader.ts deleted file mode 100644 index 7330316ea..000000000 --- a/packages/webpack/hmr/hot-loader.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { loader } from 'webpack'; -import { convertToUnixPath } from '../lib/utils'; -import { extname } from 'path'; -import { getOptions } from 'loader-utils'; - -const extMap = { - '.css': 'style', - '.scss': 'style', - '.less': 'style', - '.js': 'script', - '.ts': 'script', - '.xml': 'markup', - '.html': 'markup', -}; - -const loader: loader.Loader = function (source, map) { - const moduleRelativePath = this.resourcePath.replace(this.rootContext, '.'); - const modulePath = convertToUnixPath(moduleRelativePath); - const ext = extname(modulePath).toLowerCase(); - const moduleType = extMap[ext] || 'unknown'; - - const options = getOptions(this) || {}; - const alwaysSelfAccept = options.alwaysSelfAccept; - const trace = options.trace; - - const shouldAutoAcceptCheck = `&& global._isModuleLoadedForUI && global._isModuleLoadedForUI("${modulePath}")`; - const traceCode = `console.log("[hot-loader]: Self-accept module: ${modulePath}");`; - - const hotCode = ` -if (module.hot ${alwaysSelfAccept ? '' : shouldAutoAcceptCheck} ) { - ${trace ? traceCode : ''} - module.hot.accept(); - module.hot.dispose(() => { - global.hmrRefresh({ type: "${moduleType}", path: "${modulePath}" }); - }); -}`; - - this.callback(null, `${source}; ${hotCode} `, map); -}; - -export default loader; diff --git a/packages/webpack/hmr/index.d.ts b/packages/webpack/hmr/index.d.ts deleted file mode 100644 index c58c01beb..000000000 --- a/packages/webpack/hmr/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export { hmrUpdate } from './hmr-update'; diff --git a/packages/webpack/hmr/index.ts b/packages/webpack/hmr/index.ts deleted file mode 100644 index c58c01beb..000000000 --- a/packages/webpack/hmr/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { hmrUpdate } from './hmr-update'; diff --git a/packages/webpack/host/resolver.d.ts b/packages/webpack/host/resolver.d.ts deleted file mode 100644 index 5127e2086..000000000 --- a/packages/webpack/host/resolver.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function getResolver(platforms: string[], explicitResolve?: string[], nsPackageFilters?: string[], platformSpecificExt?: string[]): (path: string) => string; diff --git a/packages/webpack/host/resolver.ts b/packages/webpack/host/resolver.ts deleted file mode 100644 index c861a3ec1..000000000 --- a/packages/webpack/host/resolver.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { parse, join } from 'path'; -import { statSync } from 'fs'; - -export function getResolver(platforms: string[], explicitResolve?: string[], nsPackageFilters?: string[], platformSpecificExt?: string[]) { - explicitResolve = explicitResolve || []; - nsPackageFilters = nsPackageFilters || ['nativescript', 'tns', 'ns', '@nativescript']; - platformSpecificExt = platformSpecificExt || ['.ts', '.js', '.scss', '.less', '.css', '.html', '.xml', '.vue', '.json']; - - return function (path: string) { - const { dir, name, ext } = parse(path); - - if (platformSpecificExt.indexOf(ext) === -1) { - return path; - } - - for (const platform of platforms) { - const platformFileName = `${name}.${platform}${ext}`; - const platformPath = toSystemPath(join(dir, platformFileName)); - - try { - if (statSync(platformPath)) { - return platformPath; - } - } catch (_e) { - // continue checking the other platforms - } - } - - return path; - }; -} - -// Convert paths from \c\some\path to c:\some\path -function toSystemPath(path: string) { - if (!process.platform.startsWith('win32')) { - return path; - } - - const drive = path.match(/^\\(\w)\\(.*)$/); - return drive ? `${drive[1]}:\\${drive[2]}` : path; -} diff --git a/packages/webpack/index.js b/packages/webpack/index.js deleted file mode 100644 index 7a909990c..000000000 --- a/packages/webpack/index.js +++ /dev/null @@ -1,264 +0,0 @@ -const path = require("path"); -const { existsSync } = require("fs"); -const { ANDROID_APP_PATH } = require("./helpers/androidProjectHelpers"); -const { - getPackageJson, - isAndroid, - isIos, -} = require("./helpers/projectHelpers"); - -Object.assign(exports, require("./plugins")); -Object.assign(exports, require("./host/resolver")); - -exports.processTsPathsForScopedModules = function ({ compilerOptions }) { - const tnsModulesOldPackage = "tns-core-modules"; - const tnsModulesNewPackage = "@nativescript/core"; - replacePathInCompilerOptions({ - compilerOptions, - targetPath: tnsModulesOldPackage, - replacementPath: tnsModulesNewPackage - }); - ensurePathInCompilerOptions({ - compilerOptions, - sourcePath: tnsModulesOldPackage, - destinationPath: `./node_modules/${tnsModulesNewPackage}` - }); - ensurePathInCompilerOptions({ - compilerOptions, - sourcePath: `${tnsModulesOldPackage}/*`, - destinationPath: `./node_modules/${tnsModulesNewPackage}/*` - }); -} - -exports.processTsPathsForScopedAngular = function ({ compilerOptions }) { - const nsAngularOldPackage = "nativescript-angular"; - const nsAngularNewPackage = "@nativescript/angular"; - replacePathInCompilerOptions({ - compilerOptions, - targetPath: nsAngularOldPackage, - replacementPath: nsAngularNewPackage - }); - ensurePathInCompilerOptions({ - compilerOptions, - sourcePath: nsAngularOldPackage, - destinationPath: `./node_modules/${nsAngularNewPackage}` - }); - ensurePathInCompilerOptions({ - compilerOptions, - sourcePath: `${nsAngularOldPackage}/*`, - destinationPath: `./node_modules/${nsAngularNewPackage}/*` - }); -} - -exports.hasRootLevelScopedModules = function ({ projectDir }) { - return hasRootLevelPackage({ projectDir, packageName: "@nativescript/core" }); -} - -exports.hasRootLevelScopedAngular = function ({ projectDir }) { - return hasRootLevelPackage({ projectDir, packageName: "@nativescript/angular" }); -} - -exports.getAotEntryModule = function (appDirectory) { - verifyEntryModuleDirectory(appDirectory); - - const entry = getPackageJsonEntry(appDirectory); - const aotEntry = `${entry}.aot.ts`; - - const aotEntryPath = path.resolve(appDirectory, aotEntry); - if (!existsSync(aotEntryPath)) { - throw new Error(`For ahead-of-time compilation you need to have an entry module ` + - `at ${aotEntryPath} that bootstraps the app with a static platform instead of dynamic one!`) - } - - return aotEntry; -} - -exports.getEntryModule = function (appDirectory, platform) { - verifyEntryModuleDirectory(appDirectory); - - const entry = getPackageJsonEntry(appDirectory); - - const tsEntryPath = path.resolve(appDirectory, `${entry}.ts`); - const jsEntryPath = path.resolve(appDirectory, `${entry}.js`); - let entryExists = existsSync(tsEntryPath) || existsSync(jsEntryPath); - if (!entryExists && platform) { - const platformTsEntryPath = path.resolve(appDirectory, `${entry}.${platform}.ts`); - const platformJsEntryPath = path.resolve(appDirectory, `${entry}.${platform}.js`); - entryExists = existsSync(platformTsEntryPath) || existsSync(platformJsEntryPath); - } - - if (!entryExists) { - throw new Error(`The entry module ${entry} specified in ` + - `${appDirectory}/package.json doesn't exist!`) - } - - return entry; -}; - -exports.getAppPath = (platform, projectDir) => { - if (isIos(platform)) { - const appName = path.basename(projectDir); - const sanitizedName = sanitize(appName); - - return `platforms/ios/${sanitizedName}/app`; - } else if (isAndroid(platform)) { - return ANDROID_APP_PATH; - } else if (hasPlatformPlugin(projectDir, platform)) { - return `platforms/${platform}/app`; - } else { - throw new Error(`Invalid platform: ${platform}`); - } -}; - -/** - * For backward compatibility. This method is deprecated. Do not use it anymore. - * This method also has a bug of not escaping valid regex symbols in entry path. - * For module rules use: "include" instead of "test". - */ -exports.getEntryPathRegExp = (appFullPath, entryModule) => { - const entryModuleFullPath = path.join(appFullPath, entryModule); - // Windows paths contain `\`, so we need to convert each of the `\` to `\\`, so it will be correct inside RegExp - const escapedPath = entryModuleFullPath.replace(/\\/g, "\\\\"); - return new RegExp(escapedPath); -} - -exports.getSourceMapFilename = (hiddenSourceMap, appFolderPath, outputPath) => { - const appFolderRelativePath = path.join(path.relative(outputPath, appFolderPath)); - let sourceMapFilename = "[file].map"; - if (typeof hiddenSourceMap === "string") { - sourceMapFilename = path.join(appFolderRelativePath, hiddenSourceMap, "[file].map"); - } else if (typeof hiddenSourceMap === "boolean" && !!hiddenSourceMap) { - sourceMapFilename = path.join(appFolderRelativePath, "sourceMap", "[file].map"); - } - - return sourceMapFilename; -} - -/** - * Converts an array of strings externals to an array of regular expressions. - * Input is an array of string, which we need to convert to regular expressions, so all imports for this module will be treated as externals. - - * For example, in case we want nativescript-vue to be external, we will pass `["nativescript-vue"]`. - * If we pass it to webpack in this way, it will treat all `require("nativescript-vue")` as externals. - * However, you may import some file/subdir of the module, for example `require("nativescript-vue/somedir/file1")`. - * To treat this as external, we convert the strings to regular expressions, which makes webpack exclude all imports of the module. - * @param {string[]} externals Array of strings. - * @returns {RegExp[]} Array of regular expressions constructed from the input strings. In case the input is nullable, an empty array is returned. - */ -exports.getConvertedExternals = (externals) => { - const modifiedExternals = (externals || []).map((e) => { - return new RegExp(`^${e}((/.*)|$)`); - }); - - return modifiedExternals; -}; - - -/** - * The `require.context` call in `bundle-config-loader` will ask the FS for files and - * the PlatformFSPlugin will return files without `.${platform}`. The SplitChunksPlugin will - * compare the `appComponents` with the files returned from the `PlatformFSPlugin` and when they - * do not match because of the platform extension, it will duplicate the custom components - * in `bundle` (activity.js - included by the `require.context` call in `bundle-config-loader`) - * and `vendor` (activity.android.js - included by `android-app-components-loader` and `SplitChunksPlugin`). - * We are post-processing the `appComponents` in order to unify the file names and avoid getting - * a build-time SBG exception for duplicate native class definition. - */ -exports.processAppComponents = (appComponents, platform) => { - for (const key in appComponents) { - appComponents[key] = appComponents[key].replace(`.${platform}`, ""); - } -}; - -/** - * The `bundle-config-loader` needs this in order to skip the custom entries in its `require.context` call. - * If we don't skip them, custom entries like custom Android application will be included in both `application.js` - * (because its defined as an entry) and `bundle.js` (included by the `require.context` call in `bundle-config-loader`) - * causing a build-time SBG exception for duplicate native class definition. - * We are removing the extension in order to unify the file names with the `PlatformFSPlugin`. - */ -exports.getUserDefinedEntries = (entries, platform) => { - const userDefinedEntries = []; - for (const entry in entries) { - if (entry !== "bundle" && entry !== "tns_modules/@nativescript/core/inspector_modules") { - userDefinedEntries.push(entries[entry].replace(`.${platform}`, "")); - } - } - - return userDefinedEntries; -}; - -const sanitize = name => name - .split("") - .filter(char => /[a-zA-Z0-9]/.test(char)) - .join(""); - -function hasPlatformPlugin(appDirectory, platform) { - const packageJsonSource = getPackageJson(appDirectory); - const { dependencies } = packageJsonSource; - - return !!dependencies[`nativescript-platform-${platform}`]; -} - -function getPackageJsonEntry(appDirectory) { - const packageJsonSource = getPackageJson(appDirectory); - const entry = packageJsonSource.main; - - if (!entry) { - throw new Error(`${appDirectory}/package.json must contain a 'main' attribute!`); - } - - return entry.replace(/\.js$/i, ""); -} - -function verifyEntryModuleDirectory(appDirectory) { - if (!appDirectory) { - throw new Error("Path to app directory is not specified. Unable to find entry module."); - } - - if (!existsSync(appDirectory)) { - throw new Error(`The specified path to app directory ${appDirectory} does not exist. Unable to find entry module.`); - } -} - - -function hasRootLevelPackage({ projectDir, packageName }) { - let hasRootLevelPackage; - try { - require.resolve(packageName, { paths: [projectDir] }); - hasRootLevelPackage = true; - } catch (e) { - hasRootLevelPackage = false; - } - - return hasRootLevelPackage; -} - -function replacePathInCompilerOptions({ compilerOptions, targetPath, replacementPath }) { - const paths = (compilerOptions && compilerOptions.paths) || {}; - for (const key in paths) { - if (paths.hasOwnProperty(key)) { - const pathsForPattern = paths[key]; - if (Array.isArray(pathsForPattern)) { - for (let i = 0; i < pathsForPattern.length; ++i) { - if (typeof pathsForPattern[i] === "string") { - pathsForPattern[i] = pathsForPattern[i].replace(targetPath, replacementPath); - } - } - } - } - } -} - -function ensurePathInCompilerOptions({ compilerOptions, sourcePath, destinationPath }) { - compilerOptions = compilerOptions || {}; - compilerOptions.paths = compilerOptions.paths || {}; - const paths = compilerOptions.paths; - if (paths[sourcePath]) { - if (Array.isArray(paths[sourcePath]) && paths[sourcePath].indexOf(destinationPath) === -1) { - paths[sourcePath].push(destinationPath); - } - } else { - paths[sourcePath] = [destinationPath]; - } -} diff --git a/packages/webpack/index.spec.d.ts b/packages/webpack/index.spec.d.ts deleted file mode 100644 index cb0ff5c3b..000000000 --- a/packages/webpack/index.spec.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/packages/webpack/index.spec.ts b/packages/webpack/index.spec.ts deleted file mode 100644 index 0eccda570..000000000 --- a/packages/webpack/index.spec.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { getConvertedExternals } from './index'; - -describe('index', () => { - describe('getConvertedExternals', () => { - it('returns empty array when nullable is passed', () => { - const actualResult = getConvertedExternals(null); - expect(actualResult).toEqual([]); - }); - - const testCases = [ - { - input: ['nativescript-vue'], - expectedOutput: [/^nativescript-vue((\/.*)|$)/], - }, - { - input: ['nativescript-vue', 'nativescript-angular'], - expectedOutput: [/^nativescript-vue((\/.*)|$)/, /^nativescript-angular((\/.*)|$)/], - }, - ]; - - testCases.forEach((testCase) => { - it('converts passed strings to regular expressions', () => { - const actualResult = getConvertedExternals(testCase.input); - expect(actualResult).toEqual(testCase.expectedOutput); - }); - - it(`returns regular expressions which match expected modules and their subdirs, for input ${testCase.input}`, () => { - ['nativescript-vue', 'nativescript-vue/subdir', 'nativescript-vue/subdir/subdir-2'].forEach((testString) => { - const regExpsExternals = getConvertedExternals(testCase.input); - const result = regExpsExternals.some((regExp: RegExp) => !!regExp.exec(testString)); - expect(result).toBe(true, `String ${testString} does not match any of the regular expressions: ${regExpsExternals.join(', ')}`); - }); - }); - - it(`returns regular expressions which does not match expected modules and their subdirs, for input ${testCase.input}`, () => { - ['nativescript-facebook', 'nativescript-facebook/nativescript-vue', 'main-plugin/subdir/nativescript-vue', 'nativescript-vue-template-compiler', 'nativescript-vue-template-compiler/subdir'].forEach((testString) => { - const regExpsExternals = getConvertedExternals(testCase.input); - const result = regExpsExternals.some((regExp: RegExp) => !!regExp.exec(testString)); - expect(result).toBe(false, `String ${testString} matches some of the regular expressions: ${regExpsExternals.join(', ')}`); - }); - }); - }); - }); -}); diff --git a/packages/webpack/installer.js b/packages/webpack/installer.js deleted file mode 100644 index 32e4eab73..000000000 --- a/packages/webpack/installer.js +++ /dev/null @@ -1,29 +0,0 @@ -const helpers = require("./helpers/projectHelpers"); -const projectFilesManager = require("./helpers/projectFilesManager"); -const dependencyManager = require("./helpers/dependencyManager"); - -function install() { - const projectDir = helpers.getProjectDir(); - const packageJson = helpers.getPackageJson(projectDir); - - projectFilesManager.addProjectFiles(projectDir); - - const postinstallOptions = dependencyManager.addProjectDeps(packageJson); - packageJson.devDependencies = postinstallOptions.deps; - - helpers.writePackageJson(packageJson, projectDir); - - dependencyManager.showHelperMessages(postinstallOptions); -} - -function uninstall() { - const projectDir = helpers.getProjectDir(); - projectFilesManager.removeProjectFiles(projectDir); - - console.log("NativeScript Webpack removed!"); -} - -module.exports = { - install, - uninstall, -}; diff --git a/packages/webpack/jasmine-config/jasmine.json b/packages/webpack/jasmine-config/jasmine.json deleted file mode 100644 index 3d06fa01c..000000000 --- a/packages/webpack/jasmine-config/jasmine.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "spec_dir": ".", - "spec_files": [ - "!node_modules/**/*.spec.js", - "!demo/**/*.spec.js", - "./**/*.spec.js" - ], - "helpers": [ - "jasmine-config/**/*.js" - ], - "stopSpecOnExpectationFailure": false, - "random": false -} diff --git a/packages/webpack/jasmine-config/reporter.d.ts b/packages/webpack/jasmine-config/reporter.d.ts deleted file mode 100644 index cb0ff5c3b..000000000 --- a/packages/webpack/jasmine-config/reporter.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/packages/webpack/jasmine-config/reporter.ts b/packages/webpack/jasmine-config/reporter.ts deleted file mode 100644 index 5de7c4375..000000000 --- a/packages/webpack/jasmine-config/reporter.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { SpecReporter } from 'jasmine-spec-reporter'; - -jasmine.getEnv().clearReporters(); - -// @ts-ignore https://github.com/bcaudan/jasmine-spec-reporter/issues/588 -jasmine.getEnv().addReporter(new SpecReporter()); diff --git a/packages/webpack/lib/after-prepare.js b/packages/webpack/lib/after-prepare.js deleted file mode 100644 index 333e60f76..000000000 --- a/packages/webpack/lib/after-prepare.js +++ /dev/null @@ -1,23 +0,0 @@ -const { installSnapshotArtefacts } = require("../snapshot/android/project-snapshot-generator"); -const { shouldSnapshot } = require("./utils"); - -module.exports = function (hookArgs) { - if (hookArgs && hookArgs.appFilesUpdaterOptions && !hookArgs.appFilesUpdaterOptions.bundle) { - return; - } - - const env = hookArgs.prepareData.env || {}; - const shouldSnapshotOptions = { - platform: hookArgs.prepareData.platform, - release: hookArgs.prepareData.release - }; - - if (env.snapshot && - shouldSnapshot(shouldSnapshotOptions) && - (!hookArgs.prepareData || - !hookArgs.prepareData.nativePrepare || - !hookArgs.prepareData.nativePrepare.skipNativePrepare)) { - - installSnapshotArtefacts(hookArgs.prepareData.projectDir); - } -} diff --git a/packages/webpack/lib/before-checkForChanges.js b/packages/webpack/lib/before-checkForChanges.js deleted file mode 100644 index fd81fd445..000000000 --- a/packages/webpack/lib/before-checkForChanges.js +++ /dev/null @@ -1,33 +0,0 @@ -const { shouldSnapshot, isWinOS } = require("./utils"); -const semver = require("semver"); - -module.exports = function ($staticConfig, hookArgs) { - const cliVersion = semver.parse($staticConfig.version); - const majorVersion = cliVersion && cliVersion.major; - const minorVersion = cliVersion && cliVersion.minor; - - if (majorVersion && majorVersion < 6) { - // check if we are using the bundle workflow or the legacy one. - const isUsingBundleWorkflow = hookArgs && - hookArgs.checkForChangesOpts && - hookArgs.checkForChangesOpts.projectChangesOptions && - hookArgs.checkForChangesOpts.projectChangesOptions.bundle; - - if (isUsingBundleWorkflow) { - const packageJsonData = require("../package.json") - throw new Error(`The current version of ${packageJsonData.name} (${packageJsonData.version}) is not compatible with the used CLI: ${$staticConfig.version}. Please upgrade your NativeScript CLI version (npm i -g nativescript).`); - } - } else { - const env = hookArgs.prepareData.env || {}; - const shouldSnapshotOptions = { - platform: hookArgs.prepareData.platform, - release: hookArgs.prepareData.release - }; - - const shouldSnapshotOnWin = env.snapshot && shouldSnapshot(shouldSnapshotOptions) && isWinOS(); - const isCLIWithoutWinSnapshotsSupport = majorVersion && majorVersion == 6 && minorVersion && minorVersion < 2; - if (shouldSnapshotOnWin && isCLIWithoutWinSnapshotsSupport) { - throw new Error(`In order to generate Snapshots on Windows, please upgrade your NativeScript CLI version (npm i -g nativescript).`); - } - } -} \ No newline at end of file diff --git a/packages/webpack/lib/utils.js b/packages/webpack/lib/utils.js deleted file mode 100644 index 45486e9e2..000000000 --- a/packages/webpack/lib/utils.js +++ /dev/null @@ -1,41 +0,0 @@ -const os = require("os"); -const { dirname } = require("path"); -const { existsSync, mkdirSync } = require("fs"); -const { isAndroid } = require("../helpers/projectHelpers"); - -function shouldSnapshot(config) { - const platformSupportsSnapshot = isAndroid(config.platform); - - return config.release && platformSupportsSnapshot; -} - -function convertToUnixPath(relativePath) { - return relativePath.replace(/\\/g, "/"); -} - -function isWinOS() { - return os.type() === "Windows_NT"; -} - -function warn(message) { - if (message) { - console.log(`\x1B[33;1m${message}\x1B[0m`); - } -} - -function ensureDirectoryExistence(filePath) { - var dir = dirname(filePath); - if (existsSync(dir)) { - return true; - } - ensureDirectoryExistence(dir); - mkdirSync(dir); -} - -module.exports = { - shouldSnapshot, - convertToUnixPath, - isWinOS, - warn, - ensureDirectoryExistence -}; diff --git a/packages/webpack/nativescript-target/NsJsonpChunkTemplatePlugin.js b/packages/webpack/nativescript-target/NsJsonpChunkTemplatePlugin.js deleted file mode 100644 index 98c6a5561..000000000 --- a/packages/webpack/nativescript-target/NsJsonpChunkTemplatePlugin.js +++ /dev/null @@ -1,48 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -"use strict"; - -const ConcatSource = require("webpack-sources").ConcatSource; - -class JsonpChunkTemplatePlugin { - apply(chunkTemplate) { - chunkTemplate.hooks.render.tap( - "JsonpChunkTemplatePlugin", - (modules, chunk) => { - const jsonpFunction = chunkTemplate.outputOptions.jsonpFunction; - const globalObject = chunkTemplate.outputOptions.globalObject; - const source = new ConcatSource(); - source.add( - `(${globalObject}[${JSON.stringify(jsonpFunction)}] = ${ - globalObject - }[${JSON.stringify(jsonpFunction)}] || []).push([${JSON.stringify( - chunk.ids - )},` - ); - source.add(modules); - const entries = [chunk.entryModule].filter(Boolean).map(m => - [m.id].concat( - Array.from(chunk.groupsIterable)[0] - .chunks.filter(c => c !== chunk) - .map(c => c.id) - ) - ); - if (entries.length > 0) { - source.add(`,${JSON.stringify(entries)}`); - } - source.add("])"); - return source; - } - ); - chunkTemplate.hooks.hash.tap("JsonpChunkTemplatePlugin", hash => { - hash.update("JsonpChunkTemplatePlugin"); - hash.update("4"); - hash.update(`${chunkTemplate.outputOptions.jsonpFunction}`); - hash.update(`${chunkTemplate.outputOptions.globalObject}`); - }); - } -} -module.exports = JsonpChunkTemplatePlugin; - diff --git a/packages/webpack/nativescript-target/NsJsonpMainTemplate.runtime.js b/packages/webpack/nativescript-target/NsJsonpMainTemplate.runtime.js deleted file mode 100644 index f99f404a2..000000000 --- a/packages/webpack/nativescript-target/NsJsonpMainTemplate.runtime.js +++ /dev/null @@ -1,32 +0,0 @@ -module.exports = function () { - function webpackHotUpdateCallback(chunkId, moreModules) { - hotAddUpdateChunk(chunkId, moreModules); - if (parentHotUpdateCallback) { - parentHotUpdateCallback(chunkId, moreModules); - } - } - - function hotDownloadUpdateChunk(chunkId) { - const requestPath = './' + $hotChunkFilename$; - try { - require(requestPath); - } catch (e) { - console.log("Hot download for update chunk failed."); - console.error(e); - } - } - - function hotDownloadManifest() { - return new Promise(function (resolve, reject) { - const requestPath = './' + $hotMainFilename$; - try { - const update = require(requestPath); - resolve(update); - } catch (e) { - console.log("Hot download for manifest failed."); - console.error(e); - reject(e); - } - }); - } -}; diff --git a/packages/webpack/nativescript-target/NsJsonpMainTemplatePlugin.js b/packages/webpack/nativescript-target/NsJsonpMainTemplatePlugin.js deleted file mode 100644 index 4f7f965e7..000000000 --- a/packages/webpack/nativescript-target/NsJsonpMainTemplatePlugin.js +++ /dev/null @@ -1,324 +0,0 @@ -const Template = require("webpack/lib/Template"); -const SyncWaterfallHook = require("tapable").SyncWaterfallHook; - -class NsJsonpMainTemplatePlugin { - apply(mainTemplate) { - const needChunkOnDemandLoadingCode = chunk => { - for (const chunkGroup of chunk.groupsIterable) { - if (chunkGroup.getNumberOfChildren() > 0) return true; - } - return false; - }; - const needChunkLoadingCode = chunk => { - for (const chunkGroup of chunk.groupsIterable) { - if (chunkGroup.chunks.length > 1) return true; - if (chunkGroup.getNumberOfChildren() > 0) return true; - } - return false; - }; - const needEntryDeferringCode = chunk => { - for (const chunkGroup of chunk.groupsIterable) { - if (chunkGroup.chunks.length > 1) return true; - } - return false; - }; - if (!mainTemplate.hooks.jsonpScript) { - mainTemplate.hooks.jsonpScript = new SyncWaterfallHook([ - "source", - "chunk", - "hash" - ]); - } - - mainTemplate.hooks.localVars.tap( - "JsonpMainTemplatePlugin", - (source, chunk) => { - if (needChunkLoadingCode(chunk)) { - return Template.asString([ - source, - "", - "// object to store loaded and loading chunks", - "var installedChunks = {", - Template.indent( - chunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(",\n") - ), - "};", - "", - needEntryDeferringCode(chunk) ? "var deferredModules = [];" : "" - ]); - } - return source; - } - ); - mainTemplate.hooks.requireEnsure.tap( - "JsonpMainTemplatePlugin", - (source, chunk, hash) => { - - const chunkFilename = mainTemplate.outputOptions.chunkFilename; - const chunkMaps = chunk.getChunkMaps(); - - const request = mainTemplate.getAssetPath( - JSON.stringify(`./${chunkFilename}`), - { - hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`, - hashWithLength: length => - `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`, - chunk: { - id: '" + chunkId + "', - hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`, - hashWithLength(length) { - const shortChunkHashMap = Object.create(null); - for (const chunkId of Object.keys(chunkMaps.hash)) { - if (typeof chunkMaps.hash[chunkId] === "string") - shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr( - 0, - length - ); - } - return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`; - }, - name: `" + (${JSON.stringify( - chunkMaps.name - )}[chunkId]||chunkId) + "` - } - } - ); - - return Template.asString([ - source, - "", - "// JSONP chunk loading for javascript", - "", - "var installedChunkData = installedChunks[chunkId];", - 'if(installedChunkData !== 0) { // 0 means "already installed".', - Template.indent([`var chunk = require(${request})`]), - "}" - ]); - } - ); - mainTemplate.hooks.requireExtensions.tap( - "JsonpMainTemplatePlugin", - (source, chunk) => { - if (!needChunkOnDemandLoadingCode(chunk)) return source; - - return Template.asString([ - source, - "", - "// on error function for async loading", - `${ - mainTemplate.requireFn - }.oe = function(err) { console.error(err); throw err; };` - ]); - } - ); - mainTemplate.hooks.bootstrap.tap( - "JsonpMainTemplatePlugin", - (source, chunk, hash) => { - if (needChunkLoadingCode(chunk)) { - const withDefer = needEntryDeferringCode(chunk); - return Template.asString([ - source, - "", - "// install a JSONP callback for chunk loading", - "function webpackJsonpCallback(data) {", - Template.indent([ - "var chunkIds = data[0];", - "var moreModules = data[1];", - withDefer ? "var executeModules = data[2];" : "", - '// add "moreModules" to the modules object,', - '// then flag all "chunkIds" as loaded and fire callback', - "var moduleId, chunkId, i = 0, resolves = [];", - "for(;i < chunkIds.length; i++) {", - Template.indent([ - "chunkId = chunkIds[i];", - "if(installedChunks[chunkId]) {", - Template.indent("resolves.push(installedChunks[chunkId][0]);"), - "}", - "installedChunks[chunkId] = 0;" - ]), - "}", - "for(moduleId in moreModules) {", - Template.indent([ - "if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {", - Template.indent( - mainTemplate.renderAddModule( - hash, - chunk, - "moduleId", - "moreModules[moduleId]" - ) - ), - "}" - ]), - "}", - "if(parentJsonpFunction) parentJsonpFunction(data);", - "while(resolves.length) {", - Template.indent("resolves.shift()();"), - "}", - withDefer - ? Template.asString([ - "", - "// add entry modules from loaded chunk to deferred list", - "deferredModules.push.apply(deferredModules, executeModules || []);", - "", - "// run deferred modules when all chunks ready", - "return checkDeferredModules();" - ]) - : "" - ]), - "};", - withDefer - ? Template.asString([ - "function checkDeferredModules() {", - Template.indent([ - "var result;", - "for(var i = 0; i < deferredModules.length; i++) {", - Template.indent([ - "var deferredModule = deferredModules[i];", - "var fulfilled = true;", - "for(var j = 1; j < deferredModule.length; j++) {", - Template.indent([ - "var depId = deferredModule[j];", - "if(installedChunks[depId] !== 0) fulfilled = false;" - ]), - "}", - "if(fulfilled) {", - Template.indent([ - "deferredModules.splice(i--, 1);", - "result = " + - mainTemplate.requireFn + - "(" + - mainTemplate.requireFn + - ".s = deferredModule[0]);" - ]), - "}" - ]), - "}", - "return result;" - ]), - "}" - ]) - : "" - ]); - } - return source; - } - ); - mainTemplate.hooks.beforeStartup.tap( - "JsonpMainTemplatePlugin", - (source, chunk, hash) => { - if (needChunkLoadingCode(chunk)) { - var jsonpFunction = mainTemplate.outputOptions.jsonpFunction; - var globalObject = mainTemplate.outputOptions.globalObject; - return Template.asString([ - `var jsonpArray = ${globalObject}[${JSON.stringify( - jsonpFunction - )}] = ${globalObject}[${JSON.stringify(jsonpFunction)}] || [];`, - "var oldJsonpFunction = jsonpArray.push.bind(jsonpArray);", - "jsonpArray.push = webpackJsonpCallback;", - "jsonpArray = jsonpArray.slice();", - "for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]);", - "var parentJsonpFunction = oldJsonpFunction;", - "", - source - ]); - } - return source; - } - ); - mainTemplate.hooks.startup.tap( - "JsonpMainTemplatePlugin", - (source, chunk, hash) => { - if (needEntryDeferringCode(chunk)) { - if (chunk.hasEntryModule()) { - const entries = [chunk.entryModule].filter(Boolean).map(m => - [m.id].concat( - Array.from(chunk.groupsIterable)[0] - .chunks.filter(c => c !== chunk) - .map(c => c.id) - ) - ); - return Template.asString([ - "// add entry module to deferred list", - `deferredModules.push(${entries - .map(e => JSON.stringify(e)) - .join(", ")});`, - "// run deferred modules when ready", - "return checkDeferredModules();" - ]); - } else { - return Template.asString([ - "// run deferred modules from other chunks", - "checkDeferredModules();" - ]); - } - } - return source; - } - ); - mainTemplate.hooks.hotBootstrap.tap( - "JsonpMainTemplatePlugin", - (source, chunk, hash) => { - const globalObject = mainTemplate.outputOptions.globalObject; - const hotUpdateChunkFilename = - mainTemplate.outputOptions.hotUpdateChunkFilename; - const hotUpdateMainFilename = - mainTemplate.outputOptions.hotUpdateMainFilename; - const crossOriginLoading = - mainTemplate.outputOptions.crossOriginLoading; - const hotUpdateFunction = mainTemplate.outputOptions.hotUpdateFunction; - const currentHotUpdateChunkFilename = mainTemplate.getAssetPath( - JSON.stringify(hotUpdateChunkFilename), - { - hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`, - hashWithLength: length => - `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`, - chunk: { - id: '" + chunkId + "' - } - } - ); - const currentHotUpdateMainFilename = mainTemplate.getAssetPath( - JSON.stringify(hotUpdateMainFilename), - { - hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`, - hashWithLength: length => - `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "` - } - ); - const runtimeSource = Template.getFunctionContent( - require("./NsJsonpMainTemplate.runtime.js") - ) - .replace(/\/\/\$semicolon/g, ";") - .replace(/\$require\$/g, mainTemplate.requireFn) - .replace( - /\$crossOriginLoading\$/g, - crossOriginLoading - ? `script.crossOrigin = ${JSON.stringify(crossOriginLoading)}` - : "" - ) - .replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename) - .replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename) - .replace(/\$hash\$/g, JSON.stringify(hash)); - return `${source} -function hotDisposeChunk(chunkId) { - delete installedChunks[chunkId]; -} -var parentHotUpdateCallback = ${globalObject}[${JSON.stringify( - hotUpdateFunction - )}]; -${globalObject}[${JSON.stringify(hotUpdateFunction)}] = ${runtimeSource}`; - } - ); - mainTemplate.hooks.hash.tap("JsonpMainTemplatePlugin", hash => { - hash.update("jsonp"); - hash.update("5"); - hash.update(`${mainTemplate.outputOptions.globalObject}`); - hash.update(`${mainTemplate.outputOptions.chunkFilename}`); - hash.update(`${mainTemplate.outputOptions.jsonpFunction}`); - hash.update(`${mainTemplate.outputOptions.hotUpdateFunction}`); - }); - } -} -module.exports = NsJsonpMainTemplatePlugin; - diff --git a/packages/webpack/nativescript-target/NsJsonpTemplatePlugin.js b/packages/webpack/nativescript-target/NsJsonpTemplatePlugin.js deleted file mode 100644 index 18ee9cd7a..000000000 --- a/packages/webpack/nativescript-target/NsJsonpTemplatePlugin.js +++ /dev/null @@ -1,17 +0,0 @@ -const NsJsonpMainTemplatePlugin = require("./NsJsonpMainTemplatePlugin"); -const JsonpChunkTemplatePlugin = require("webpack/lib/web/JsonpChunkTemplatePlugin"); -const JsonpHotUpdateChunkTemplatePlugin = require("webpack/lib/web/JsonpHotUpdateChunkTemplatePlugin"); - -class NsJsonpTemplatePlugin { - apply(compiler) { - compiler.hooks.thisCompilation.tap("NsJsonpTemplatePlugin", compilation => { - new NsJsonpMainTemplatePlugin().apply(compilation.mainTemplate); - new JsonpChunkTemplatePlugin().apply(compilation.chunkTemplate); - new JsonpHotUpdateChunkTemplatePlugin().apply( - compilation.hotUpdateChunkTemplate - ); - }) - } -} - -module.exports = NsJsonpTemplatePlugin; diff --git a/packages/webpack/nativescript-target/index.js b/packages/webpack/nativescript-target/index.js deleted file mode 100644 index b0f974a16..000000000 --- a/packages/webpack/nativescript-target/index.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = function nativescriptTarget(compiler) { - const options = this; - const webpackLib = "webpack/lib"; - - // Custom template plugin - const NsJsonpTemplatePlugin = require("./NsJsonpTemplatePlugin"); - - const FunctionModulePlugin = require(webpackLib + "/FunctionModulePlugin"); - const NodeSourcePlugin = require(webpackLib + "/node/NodeSourcePlugin"); - const LoaderTargetPlugin = require(webpackLib + "/LoaderTargetPlugin"); - - new NsJsonpTemplatePlugin(options.output).apply(compiler); - new FunctionModulePlugin(options.output).apply(compiler); - new NodeSourcePlugin(options.node).apply(compiler); - new LoaderTargetPlugin("web").apply(compiler); -} diff --git a/packages/webpack/package.json b/packages/webpack/package.json deleted file mode 100644 index 95bcd0dd5..000000000 --- a/packages/webpack/package.json +++ /dev/null @@ -1,103 +0,0 @@ -{ - "name": "@nativescript/webpack", - "version": "4.1.0", - "main": "index", - "description": "Webpack plugin for NativeScript", - "homepage": "https://nativescript.org", - "bugs": "https://github.com/NativeScript/NativeScript/issues", - "contributors": [ - "Hristo Deshev ", - "NativeScript " - ], - "nativescript": { - "hooks": [ - { - "type": "after-prepare", - "script": "lib/after-prepare.js", - "inject": true - }, - { - "type": "before-checkForChanges", - "script": "lib/before-checkForChanges.js", - "inject": true - } - ] - }, - "license": "Apache-2.0", - "repository": { - "type": "git", - "url": "https://github.com/NativeScript/nativescript-dev-webpack.git" - }, - "scripts": { - "tsc": "tsc", - "postinstall": "node postinstall.js", - "preuninstall": "node preuninstall.js", - "postpack": "rm -rf node_modules", - "setup": "npm run clean && npm run build", - "build": "npm run tsc && npm run jasmine", - "test": "npm run build", - "jasmine": "jasmine --config=jasmine-config/jasmine.json", - "coverage": "nyc npm run test", - "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s" - }, - "bin": { - "install-ns-webpack": "./bin/install-ns-webpack", - "remove-ns-webpack": "./bin/remove-ns-webpack", - "update-ns-webpack": "./bin/update-ns-webpack", - "ns-bundle": "./bin/ns-bundle", - "ns-verify-bundle": "./bin/ns-verify-bundle", - "generate-android-snapshot": "./bin/generate-android-snapshot" - }, - "dependencies": { - "@angular-devkit/core": "~10.0.0", - "@nativescript/hook": "~2.0.0", - "clean-webpack-plugin": "~3.0.0", - "copy-webpack-plugin": "4.6.0", - "css": "~3.0.0", - "css-loader": "~4.2.0", - "escape-string-regexp": "~4.0.0", - "fork-ts-checker-webpack-plugin": "~5.0.0", - "global-modules-path": "~2.3.0", - "loader-utils": "~2.0.0", - "minimatch": "~3.0.4", - "nativescript-worker-loader": "~0.12.0", - "properties-reader": "~2.0.0", - "proxy-lib": "0.4.0", - "raw-loader": "~4.0.0", - "resolve-url-loader": "~3.1.0", - "sass-loader": "~9.0.0", - "sax": "^1.2.4", - "schema-utils": "~2.7.0", - "semver": "^7.3.0", - "shelljs": "~0.8.4", - "tapable": "~1.1.3", - "terser": "~5.0.0", - "terser-webpack-plugin": "~3.0.6", - "ts-loader": "^8.0.2", - "webpack": "~4.44.1", - "webpack-bundle-analyzer": "~3.8.0", - "webpack-cli": "~3.3.12", - "webpack-sources": "~1.4.3" - }, - "devDependencies": { - "@angular/compiler": "~10.0.0", - "@angular/compiler-cli": "~10.0.0", - "@istanbuljs/nyc-config-typescript": "^1.0.0", - "@ngtools/webpack": "~10.0.0", - "@types/css": "~0.0.31", - "@types/jasmine": "3.6.6", - "@types/loader-utils": "^2.0.0", - "@types/node": "~14.0.0", - "@types/proxyquire": "~1.3.28", - "@types/sax": "^1.2.0", - "@types/semver": "^7.3.0", - "@types/webpack": "^4.41.21", - "conventional-changelog-cli": "~2.0.34", - "jasmine": "3.6.4", - "jasmine-spec-reporter": "6.0.0", - "nyc": "^15.1.0", - "proxyquire": "~2.1.0", - "source-map-support": "^0.5.13", - "typescript": "4.5.4" - } -} diff --git a/packages/webpack/plugins/GenerateBundleStarterPlugin.js b/packages/webpack/plugins/GenerateBundleStarterPlugin.js deleted file mode 100644 index 1c1059119..000000000 --- a/packages/webpack/plugins/GenerateBundleStarterPlugin.js +++ /dev/null @@ -1,14 +0,0 @@ -const { GenerateNativeScriptEntryPointsPlugin } = require("./GenerateNativeScriptEntryPointsPlugin"); - -// backwards compatibility for <= 0.22 configs -exports.GenerateBundleStarterPlugin = (function () { - function GenerateBundleStarterPlugin() { - this.entryPointsPlugin = new GenerateNativeScriptEntryPointsPlugin("bundle"); - }; - - GenerateBundleStarterPlugin.prototype.apply = function (compiler) { - this.entryPointsPlugin.apply(compiler); - } - - return GenerateBundleStarterPlugin; -})(); diff --git a/packages/webpack/plugins/GenerateNativeScriptEntryPointsPlugin.js b/packages/webpack/plugins/GenerateNativeScriptEntryPointsPlugin.js deleted file mode 100644 index 3ca265920..000000000 --- a/packages/webpack/plugins/GenerateNativeScriptEntryPointsPlugin.js +++ /dev/null @@ -1,111 +0,0 @@ -const { convertToUnixPath } = require("../lib/utils"); -const { RawSource, ConcatSource } = require("webpack-sources"); -const { getPackageJson } = require("../helpers/projectHelpers"); -const { SNAPSHOT_ENTRY_NAME } = require("./NativeScriptSnapshotPlugin"); -const path = require("path"); - -exports.GenerateNativeScriptEntryPointsPlugin = (function () { - const GenerationFailedError = "Unable to generate entry files."; - - function GenerateNativeScriptEntryPointsPlugin(appEntryName) { - this.appEntryName = appEntryName; - this.files = {}; - }; - - GenerateNativeScriptEntryPointsPlugin.prototype.apply = function (compiler) { - this.webpackContext = compiler.options.context; - - compiler.hooks.emit.tapAsync("GenerateNativeScriptEntryPointsPlugin", (compilation, cb) => { - compilation.entrypoints.forEach(entryPoint => { - this.generateEntryFile(compilation, entryPoint); - }); - this.addAsset(compilation, "package.json", this.generatePackageJson()); - this.generateTnsJavaClasses(compilation); - - cb(); - }); - } - - GenerateNativeScriptEntryPointsPlugin.prototype.generateTnsJavaClasses = function (compilation) { - const path = compilation.compiler.outputPath; - const isAndroid = path.indexOf("android") > -1; - - if (isAndroid && !compilation.assets["tns-java-classes.js"]) { - this.addAsset(compilation, "tns-java-classes.js", ""); 0 - } - } - - GenerateNativeScriptEntryPointsPlugin.prototype.generatePackageJson = function () { - const packageJson = getPackageJson(this.webpackContext); - packageJson.main = this.appEntryName; - - return JSON.stringify(packageJson, null, 4); - } - - GenerateNativeScriptEntryPointsPlugin.prototype.generateEntryFile = function (compilation, entryPoint) { - const entryPointName = entryPoint.options.name; - let entryChunk; - if (entryPointName === SNAPSHOT_ENTRY_NAME) { - // Do not require the snapshot entry dependencies as the snapshot will fail. - return; - } - - const requiredFiles = []; - entryPoint.chunks.forEach(chunk => { - if (chunk.name === entryPointName) { - entryChunk = chunk; - } else { - chunk.files.forEach(fileName => { - if (!this.isHMRFile(fileName) && this.isSourceFile(fileName)) { - requiredFiles.push(fileName); - } - }); - } - }); - - if (!entryChunk) { - throw new Error(`${GenerationFailedError} Entry chunk not found for entry "${entryPointName}".`); - } - - entryChunk.files.forEach(filePath => { - if (!compilation.assets[filePath]) { - throw new Error(`${GenerationFailedError} File "${filePath}" not found for entry "${entryPointName}".`); - } - - if (!this.isHMRFile(filePath) && this.isSourceFile(filePath)) { - const currFileDirRelativePath = path.dirname(filePath); - const pathToRootFromCurrFile = path.relative(currFileDirRelativePath, "."); - - const requireDeps = requiredFiles.map(depPath => { - const depRelativePath = path.join(pathToRootFromCurrFile, depPath); - const depRelativePathUnix = convertToUnixPath(depRelativePath); - - return `require("./${depRelativePathUnix}");`; - }).join(""); - const currentEntryFileContent = compilation.assets[filePath].source(); - - if(compilation.assets[filePath] instanceof ConcatSource) { - compilation.assets[filePath].children.unshift(`${requireDeps}`); - } else { - compilation.assets[filePath] = new RawSource(`${requireDeps}${currentEntryFileContent}`); - } - } - }); - } - GenerateNativeScriptEntryPointsPlugin.prototype.addAsset = function (compilation, name, content) { - if (this.files[name] !== content) { - this.files[name] = content; - compilation.assets[name] = new RawSource(content); - } - } - - GenerateNativeScriptEntryPointsPlugin.prototype.isHMRFile = function (fileName) { - return fileName.indexOf("hot-update") > -1; - } - - GenerateNativeScriptEntryPointsPlugin.prototype.isSourceFile = function (fileName) { - return fileName.endsWith(".js"); - } - - return GenerateNativeScriptEntryPointsPlugin; -})(); diff --git a/packages/webpack/plugins/NativeScriptAngularCompilerPlugin.d.ts b/packages/webpack/plugins/NativeScriptAngularCompilerPlugin.d.ts deleted file mode 100644 index 212dee621..000000000 --- a/packages/webpack/plugins/NativeScriptAngularCompilerPlugin.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function getAngularCompilerPlugin(platform: string): any; diff --git a/packages/webpack/plugins/NativeScriptAngularCompilerPlugin.ts b/packages/webpack/plugins/NativeScriptAngularCompilerPlugin.ts deleted file mode 100644 index db12e5636..000000000 --- a/packages/webpack/plugins/NativeScriptAngularCompilerPlugin.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { parse, join } from 'path'; -import { AngularCompilerPlugin } from '@ngtools/webpack'; - -export function getAngularCompilerPlugin(platform: string): any { - class NativeScriptAngularCompilerPlugin extends AngularCompilerPlugin { - // This is the bridge between the @ngtols/webpack loader and the AngularCompilerPlugin plugin itself: - // https://github.com/angular/angular-cli/blob/bf52b26219ffc16bed2dd55716e21773b415fd2a/packages/ngtools/webpack/src/loader.ts#L49 - // The problem is that the loader does not call the `hostReplacementPaths` method when asking for the compiledFile. - // By overriding this method, we work around this issue and support platform specific files from the loader - // that are not compiled by the AngularCompilerPlugin plugin. e.g. main.ts is the webpack entry point and - // it's loaded by the @ngtools/webpack loader but its not compiled by the plugin because the TypeScript Compiler - // knowns only about main.android.ts and main.ios.ts (main.ts is not imported/required anywhere in the app). - getCompiledFile(file) { - try { - if (platform) { - const parsed = parse(file); - const platformFile = join(parsed.dir, `${parsed.name}.${platform}${parsed.ext}`); - const result = super.getCompiledFile(platformFile); - // In case there's some issue with the generation, getCompilePath may fail or - // produce a result with empty outputText and errorDependencies array populated with files. - if (result && result.outputText) { - return result; - } - } - } catch (e) {} - - return super.getCompiledFile(file); - } - } - - return NativeScriptAngularCompilerPlugin; -} diff --git a/packages/webpack/plugins/NativeScriptSnapshotPlugin/index.js b/packages/webpack/plugins/NativeScriptSnapshotPlugin/index.js deleted file mode 100644 index 26ed338f3..000000000 --- a/packages/webpack/plugins/NativeScriptSnapshotPlugin/index.js +++ /dev/null @@ -1,173 +0,0 @@ -const { relative, resolve, join } = require("path"); -const { closeSync, openSync, writeFileSync } = require("fs"); -const validateOptions = require("schema-utils"); - -const ProjectSnapshotGenerator = require("../../snapshot/android/project-snapshot-generator"); -const { getPackageJson } = require("../../helpers/projectHelpers"); -const { - ANDROID_PROJECT_DIR, - ANDROID_APP_PATH, -} = require("../../helpers/androidProjectHelpers"); -const { ensureDirectoryExistence } = require("../../lib/utils"); -const schema = require("./options.json"); - -const SNAPSHOT_ENTRY_NAME = "snapshot-entry"; -const SNAPSHOT_ENTRY_MODULE = `${SNAPSHOT_ENTRY_NAME}.js`; -exports.SNAPSHOT_ENTRY_NAME = SNAPSHOT_ENTRY_NAME; - -exports.NativeScriptSnapshotPlugin = (function () { - function NativeScriptSnapshotPlugin(options) { - NativeScriptSnapshotPlugin.validateSchema(options); - - ProjectSnapshotGenerator.call(this, options); - - const { webpackConfig } = this.options; - NativeScriptSnapshotPlugin.removeLibraryTarget(webpackConfig); - - const { entry } = webpackConfig; - if (typeof entry === "string" || Array.isArray(entry)) { - webpackConfig.entry = { bundle: entry }; - } - - NativeScriptSnapshotPlugin.ensureSnapshotModuleEntry(this.options); - } - - NativeScriptSnapshotPlugin.removeLibraryTarget = function (webpackConfig) { - const { output } = webpackConfig; - if (output) { - output.libraryTarget = undefined; - } - } - - NativeScriptSnapshotPlugin.ensureSnapshotModuleEntry = function (options) { - const { webpackConfig, requireModules, chunks, includeApplicationCss } = options; - const internalRequireModules = this.getInternalRequireModules(webpackConfig.context); - - const snapshotEntryPath = join(ANDROID_PROJECT_DIR, SNAPSHOT_ENTRY_MODULE); - - let snapshotEntryContent = ""; - if (includeApplicationCss) { - snapshotEntryContent += ` - require("${ - options.angular ? - '@nativescript/webpack/helpers/load-application-css-angular' : - '@nativescript/webpack/helpers/load-application-css-regular' - }")(); - `; - } - snapshotEntryContent += [...requireModules, ...internalRequireModules] - .map(mod => `require('${mod}')`).join(";"); - - ensureDirectoryExistence(snapshotEntryPath); - writeFileSync(snapshotEntryPath, snapshotEntryContent, { encoding: "utf8" }); - - // add the module to the entry points to make sure it's content is evaluated - webpackConfig.entry[SNAPSHOT_ENTRY_NAME] = relative(webpackConfig.context, snapshotEntryPath); - - // prepend the module to the script that will be snapshotted - chunks.unshift(SNAPSHOT_ENTRY_NAME); - - // ensure that the runtime is installed only in the snapshotted chunk - webpackConfig.optimization.runtimeChunk = { name: SNAPSHOT_ENTRY_NAME }; - } - NativeScriptSnapshotPlugin.getInternalRequireModules = function (webpackContext) { - const packageJson = getPackageJson(webpackContext); - return (packageJson && packageJson["android"] && packageJson["android"]["requireModules"]) || []; - } - - NativeScriptSnapshotPlugin.validateSchema = function (options) { - if (!options.chunk && !options.chunks) { - const error = NativeScriptSnapshotPlugin.extendError({ message: `No chunks specified!` }); - throw error; - } - - try { - validateOptions(schema, options, "NativeScriptSnapshotPlugin"); - - if (options.chunk) { - options.chunks = options.chunks || []; - options.chunks.push(options.chunk); - } - } catch (error) { - throw new Error(error.message); - } - } - - NativeScriptSnapshotPlugin.prototype = Object.create(ProjectSnapshotGenerator.prototype); - NativeScriptSnapshotPlugin.prototype.constructor = NativeScriptSnapshotPlugin; - - NativeScriptSnapshotPlugin.prototype.generate = function (webpackChunks) { - const options = this.options; - if (options.skipSnapshotTools) { - console.log(`Skipping snapshot tools.`); - return Promise.resolve(); - } - - const inputFiles = webpackChunks.map(chunk => join(options.webpackConfig.output.path, chunk.files[0])); - const preprocessedInputFile = join( - this.options.projectRoot, - ANDROID_APP_PATH, - "_embedded_script_.js" - ); - - console.log(`\n Snapshotting bundle from ${inputFiles}`); - - return ProjectSnapshotGenerator.prototype.generate.call(this, { - inputFiles, - preprocessedInputFile, - targetArchs: options.targetArchs, - useLibs: options.useLibs, - androidNdkPath: options.androidNdkPath, - v8Version: options.v8Version, - snapshotInDocker: options.snapshotInDocker, - skipSnapshotTools: options.skipSnapshotTools - }).then(() => { - // Make the original files empty - inputFiles.forEach(inputFile => - closeSync(openSync(inputFile, "w")) // truncates the input file content - ); - }); - } - - NativeScriptSnapshotPlugin.prototype.apply = function (compiler) { - const options = this.options; - - compiler.hooks.afterEmit.tapAsync("NativeScriptSnapshotPlugin", function (compilation, callback) { - const chunksToSnapshot = options.chunks - .map(name => ({ name, chunk: compilation.chunks.find(chunk => chunk.name === name) })); - const unexistingChunks = chunksToSnapshot.filter(pair => !pair.chunk); - - if (unexistingChunks.length) { - const message = `The following chunks does not exist: ` + unexistingChunks.map(pair => pair.name).join(", "); - const error = NativeScriptSnapshotPlugin.extendError({ message }); - compilation.errors.push(error); - return callback(); - } - - this.generate(chunksToSnapshot.map(pair => pair.chunk)) - .then(() => { - console.log("Successfully generated snapshots!"); - return callback(); - }) - .catch((error) => { - const extendedError = NativeScriptSnapshotPlugin.extendError({ originalError: error }); - compilation.errors.push(extendedError); - return callback(); - }); - }.bind(this)); - } - - NativeScriptSnapshotPlugin.extendError = function ({ originalError, message } = {}) { - const header = `NativeScriptSnapshot. Snapshot generation failed!\n`; - if (originalError) { - originalError.message = `${header}${originalError.message}`; - return originalError; - } - - const newMessage = message ? `${header}${message}` : header; - return new Error(newMessage); - }; - - return NativeScriptSnapshotPlugin; -})(); - diff --git a/packages/webpack/plugins/NativeScriptSnapshotPlugin/options.json b/packages/webpack/plugins/NativeScriptSnapshotPlugin/options.json deleted file mode 100644 index 22e08d609..000000000 --- a/packages/webpack/plugins/NativeScriptSnapshotPlugin/options.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "type": "object", - "properties": { - "androidNdkPath": { - "type": "string" - }, - "angular": { - "type": "boolean", - "default": false - }, - "chunk": { - "type": "string" - }, - "chunks": { - "type": "array", - "items": { - "type": "string" - } - }, - "projectRoot": { - "type": "string" - }, - "webpackConfig": { - "type": "object" - }, - "targetArchs": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "arm", - "arm64", - "ia32", - "ia64" - ] - } - }, - "useLibs": { - "type": "boolean", - "default": false - }, - "snapshotInDocker": { - "type": "boolean" - }, - "skipSnapshotTools": { - "type": "boolean", - "default": false - }, - "v8Version": { - "type": "string" - }, - "requireModules": { - "type": "array", - "default": [] - }, - "includeApplicationCss": { - "type": "boolean", - "default": true - } - }, - "required": [ - "projectRoot", - "webpackConfig" - ], - "additionalProperties": false -} \ No newline at end of file diff --git a/packages/webpack/plugins/PlatformFSPlugin.d.ts b/packages/webpack/plugins/PlatformFSPlugin.d.ts deleted file mode 100644 index 3f20af06b..000000000 --- a/packages/webpack/plugins/PlatformFSPlugin.d.ts +++ /dev/null @@ -1,33 +0,0 @@ -export interface PlatformFSPluginOptions { - /** - * The target platform. - */ - platform?: string; - /** - * A list of all platforms. By default it is `["ios", "android", "desktop"]`. - */ - platforms?: string[]; - /** - * An array of minimatch expressions used to filter nodes from the file system. - */ - ignore?: string[]; -} -export declare class PlatformFSPlugin { - protected readonly platform: string; - protected readonly platforms: ReadonlyArray; - protected readonly ignore: ReadonlyArray; - protected context: string; - constructor({ platform, platforms, ignore }: PlatformFSPluginOptions); - apply(compiler: any): void; -} -export interface MapFileSystemArgs { - /** - * This is the underlying webpack compiler.inputFileSystem, its interface is similar to Node's fs. - */ - readonly context: string; - readonly platform: string; - readonly platforms: ReadonlyArray; - readonly ignore: ReadonlyArray; - readonly compiler: any; -} -export declare function mapFileSystem(args: MapFileSystemArgs): any; diff --git a/packages/webpack/plugins/PlatformFSPlugin.ts b/packages/webpack/plugins/PlatformFSPlugin.ts deleted file mode 100644 index d98e423f3..000000000 --- a/packages/webpack/plugins/PlatformFSPlugin.ts +++ /dev/null @@ -1,241 +0,0 @@ -import { parse as parseFile, join, basename, relative } from 'path'; -import * as minimatch from 'minimatch'; - -export interface PlatformFSPluginOptions { - /** - * The target platform. - */ - platform?: string; - - /** - * A list of all platforms. By default it is `["ios", "android", "desktop"]`. - */ - platforms?: string[]; - - /** - * An array of minimatch expressions used to filter nodes from the file system. - */ - ignore?: string[]; -} - -const internalPlatforms = ['ios', 'android']; - -export class PlatformFSPlugin { - protected readonly platform: string; - protected readonly platforms: ReadonlyArray; - protected readonly ignore: ReadonlyArray; - protected context: string; - - constructor({ platform, platforms, ignore }: PlatformFSPluginOptions) { - this.platform = platform || ''; - this.platforms = platforms || internalPlatforms; - this.ignore = ignore || []; - } - - public apply(compiler) { - this.context = compiler.context; - compiler.inputFileSystem = mapFileSystem({ - platform: this.platform, - platforms: this.platforms, - ignore: this.ignore, - context: this.context, - compiler, - }); - } -} - -export interface MapFileSystemArgs { - /** - * This is the underlying webpack compiler.inputFileSystem, its interface is similar to Node's fs. - */ - readonly context: string; - readonly platform: string; - readonly platforms: ReadonlyArray; - readonly ignore: ReadonlyArray; - readonly compiler: any; -} - -export function mapFileSystem(args: MapFileSystemArgs): any { - let { platform, platforms, ignore, context, compiler } = args; - const fs = compiler.inputFileSystem; - ignore = args.ignore || []; - - const isExternal = internalPlatforms.indexOf(platform) === -1; - - const minimatchFileFilters = ignore.map((pattern) => { - const minimatchFilter = minimatch.filter(pattern); - return (file) => minimatchFilter(relative(context, file), 0, []); - }); - - const isIgnored = (file) => minimatchFileFilters.some((filter) => filter(file)); - - const alienPlatforms = platforms.filter((p) => p !== platform); - const alienPlatformFilters = alienPlatforms.map((platform) => `.${platform}.`).map((contains) => (baseFileName) => baseFileName.indexOf(contains) !== -1); - - const isNotAlienPlatformFile = (file) => !alienPlatformFilters.some((filter) => filter(basename(file))); - - const currentPlatformExt = `.${platform}`; - - const trimPlatformSuffix = (file) => { - const { dir, name, ext } = parseFile(file); - if (name.endsWith(currentPlatformExt)) { - return join(dir, name.substr(0, name.length - currentPlatformExt.length) + ext); - } - return file; - }; - - const isNotIgnored = (file) => !isIgnored(file); - - const mappedFS: any = { - get _statStorage() { - return fs._statStorage; - }, - get _readFileStorage() { - return fs._readFileStorage; - }, - get _readdirStorage() { - return fs._readdirStorage; - }, - }; - - ['readFile', 'provide', 'stat', 'readJson', 'readlink'].forEach(mapPath); - ['readdir'].forEach(filterResultingFiles); - - function platformSpecificFile(file: string): string { - const { dir, name, ext } = parseFile(file); - let platformFilePath = join(dir, `${name}.${platform}${ext}`); - - if (isExternal && dir.indexOf('/@nativescript/core/') !== -1) { - let replacedPath; - try { - replacedPath = dir.replace(/node_modules(\/[^/]+)?\/@nativescript\/core/, `node_modules/nativescript-platform-${platform}`); - - platformFilePath = require.resolve(join(replacedPath, `${name}.${platform}${ext}`)); - } catch (e) { - if (replacedPath) { - if (ext === '.d') { - platformFilePath = undefined; - } else { - platformFilePath = join(replacedPath, `${name}${ext}`); - } - } - } - } - - return platformFilePath; - } - - function listWithPlatformSpecificFiles(files: string[]): string[] { - const mappedFiles = []; - files.forEach((file) => { - mappedFiles.push(file); - mappedFiles.push(platformSpecificFile(file)); - }); - return mappedFiles; - } - - /** - * Maps and filters the input files. - * Expects array with absolute paths. - * Returns array with absolute paths. - */ - function filterIgnoredFilesAlienFilesAndMap(files: string[]): string[] { - const mappedFiles = files.filter(isNotIgnored).filter(isNotAlienPlatformFile).map(trimPlatformSuffix); - const uniqueMappedFiles = Array.from(new Set(mappedFiles)); - return uniqueMappedFiles; - } - - const platformSuffix = '.' + platform + '.'; - const baseWatch = compiler.watchFileSystem.watch; - compiler.watchFileSystem.watch = function (files, dirs, missing, startTime, watchOptions, callback: (err, filesModified, contextModified, missingModified, fileTimestamps, contextTimestamps) => void, callbackUndelayed: (filename, timestamp) => void) { - const mappedFiles = listWithPlatformSpecificFiles(files); - - const newCallback = function (err, filesModified, contextModified, missingModified, fileTimestamps, contextTimestamps) { - const mappedFilesModified = filterIgnoredFilesAlienFilesAndMap(filesModified); - const mappedTimestamps = new Map(); - const fileTimestampsAsArray = Array.from(fileTimestamps); - - for (const entry of fileTimestampsAsArray) { - const file = entry[0]; - const timestamp = entry[1]; - mappedTimestamps.set(file, timestamp); - - const platformSuffixIndex = file.lastIndexOf(platformSuffix); - if (platformSuffixIndex != -1) { - // file name without platform suffix - const mappedFile = file.substr(0, platformSuffixIndex) + file.substr(platformSuffixIndex + platformSuffix.length - 1); - if (!(mappedFile in fileTimestamps)) { - mappedTimestamps.set(mappedFile, timestamp); - } - } - } - - callback.call(this, err, mappedFilesModified, contextModified, missingModified, mappedTimestamps, contextTimestamps); - }; - - const newCallbackUndelayed = function (filename, timestamp) { - compiler.watchFileSystem.inputFileSystem.purge(filename); - callbackUndelayed(filename, timestamp); - }; - - baseWatch.apply(compiler.watchFileSystem.watch, [mappedFiles, dirs, missing, startTime, watchOptions, newCallback, newCallbackUndelayed]); - }; - - /** - * For FS functions that get as first argument a file path, - * this will map it to a platform specific file if such file exists or fallback to the default. - * Also the last argument must be a function that handles results such as (err, files[]), - * it will invoke err for files that are ignored. - */ - function mapPath(fName) { - const base = fs[fName]; - mappedFS[fName] = function () { - const args = arguments; - const originalFilePath = args[0]; - const callback = args[args.length - 1]; - if (isIgnored(originalFilePath)) { - callback(new Error('File ' + originalFilePath + ' is ignored!')); - return; - } - const platformFilePath = platformSpecificFile(originalFilePath); - fs.stat(platformFilePath, (err, stat) => { - if (!err && stat && stat.isFile()) { - args[0] = platformFilePath; - } - base.apply(fs, args); - }); - }; - } - - /** - * For FS functions that get as a last argument a function, - * that handles results such as (err, files[]), - * will filter and map the returned files[]. - */ - function filterResultingFiles(name) { - const base = fs[name]; - mappedFS[name] = function () { - const dir = arguments[0]; - const callback = arguments[arguments.length - 1]; - if (isIgnored(dir)) { - // Return empty file list for filtered directories. - callback(null, []); - return; - } - arguments[arguments.length - 1] = function (err, files: string[]) { - if (err) { - callback(err); - } else { - // Create absolute paths for "ignored" testing, map platforms, and return back the base name. - const absoluteFilePaths = files.map((file) => join(dir, file)); - const resultAbsolute = filterIgnoredFilesAlienFilesAndMap(absoluteFilePaths); - const resultFileNames = resultAbsolute.map((f) => basename(f)); - callback(null, resultFileNames); - } - }; - base.apply(fs, arguments); - }; - } - - return mappedFS; -} diff --git a/packages/webpack/plugins/PlatformSuffixPlugin.js b/packages/webpack/plugins/PlatformSuffixPlugin.js deleted file mode 100644 index e5ef78000..000000000 --- a/packages/webpack/plugins/PlatformSuffixPlugin.js +++ /dev/null @@ -1,35 +0,0 @@ -const parseFile = require("path").parse; - -function PlatformSuffixPlugin(platform) { - this.platform = platform; -} -exports.PlatformSuffixPlugin = PlatformSuffixPlugin; - -PlatformSuffixPlugin.prototype.apply = function(resolver) { - var platform = this.platform; - - resolver.plugin("file", function(request, callback) { - const fs = this.fileSystem; - const file = this.join(request.path, request.request); - const query = request.query; - const pFile = parseFile(file); - const platformFile = this.join(pFile.dir, pFile.name + ("." + platform) + pFile.ext); - fs.stat(platformFile, (err, stat) => { - if (!err && stat && stat.isFile()) { - const err = undefined; - const path = platformFile; - callback(err, { file: true, path, query }); - } else { - fs.stat(file, (err, stat) => { - if (!err && stat && stat.isFile()) { - const err = undefined; - const path = file; - callback(err, { file: true, path, query }); - } else { - callback(); - } - }); - } - }); - }); -} diff --git a/packages/webpack/plugins/WatchStateLoggerPlugin.d.ts b/packages/webpack/plugins/WatchStateLoggerPlugin.d.ts deleted file mode 100644 index 23342c148..000000000 --- a/packages/webpack/plugins/WatchStateLoggerPlugin.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -export declare enum messages { - compilationComplete = "Webpack compilation complete.", - startWatching = "Webpack compilation complete. Watching for file changes.", - changeDetected = "File change detected. Starting incremental webpack compilation..." -} -/** - * This little plugin will report the webpack state through the console. - * So the {N} CLI can get some idea when compilation completes. - */ -export declare class WatchStateLoggerPlugin { - isRunningWatching: boolean; - apply(compiler: any): void; -} diff --git a/packages/webpack/plugins/WatchStateLoggerPlugin.ts b/packages/webpack/plugins/WatchStateLoggerPlugin.ts deleted file mode 100644 index e42c187a4..000000000 --- a/packages/webpack/plugins/WatchStateLoggerPlugin.ts +++ /dev/null @@ -1,57 +0,0 @@ -export enum messages { - compilationComplete = 'Webpack compilation complete.', - startWatching = 'Webpack compilation complete. Watching for file changes.', - changeDetected = 'File change detected. Starting incremental webpack compilation...', -} - -/** - * This little plugin will report the webpack state through the console. - * So the {N} CLI can get some idea when compilation completes. - */ -export class WatchStateLoggerPlugin { - isRunningWatching: boolean; - apply(compiler) { - const plugin = this; - compiler.hooks.watchRun.tapAsync('WatchStateLoggerPlugin', function (compiler, callback) { - plugin.isRunningWatching = true; - if (plugin.isRunningWatching) { - console.log(messages.changeDetected); - } - process.send && process.send(messages.changeDetected, (error) => null); - callback(); - }); - compiler.hooks.afterEmit.tapAsync('WatchStateLoggerPlugin', function (compilation, callback) { - callback(); - - if (plugin.isRunningWatching) { - console.log(messages.startWatching); - } else { - console.log(messages.compilationComplete); - } - - const emittedFiles = Object.keys(compilation.assets).filter((assetKey) => compilation.assets[assetKey].emitted); - - const chunkFiles = getChunkFiles(compilation); - process.send && process.send(messages.compilationComplete, (error) => null); - // Send emitted files so they can be LiveSynced if need be - process.send && process.send({ emittedFiles, chunkFiles, hash: compilation.hash }, (error) => null); - }); - } -} - -function getChunkFiles(compilation) { - const chunkFiles = []; - try { - compilation.chunks.forEach((chunk) => { - chunk.files.forEach((file) => { - if (file.indexOf('hot-update') === -1) { - chunkFiles.push(file); - } - }); - }); - } catch (e) { - console.log('Warning: Unable to find chunk files.'); - } - - return chunkFiles; -} diff --git a/packages/webpack/plugins/index.js b/packages/webpack/plugins/index.js deleted file mode 100644 index 132bcdde5..000000000 --- a/packages/webpack/plugins/index.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = Object.assign({}, - require("./GenerateBundleStarterPlugin"), - require("./GenerateNativeScriptEntryPointsPlugin"), - require("./NativeScriptSnapshotPlugin"), - require("./PlatformSuffixPlugin"), - require("./PlatformFSPlugin"), - require("./WatchStateLoggerPlugin") -); diff --git a/packages/webpack/postinstall.js b/packages/webpack/postinstall.js deleted file mode 100644 index 67cf1f270..000000000 --- a/packages/webpack/postinstall.js +++ /dev/null @@ -1,55 +0,0 @@ -"use strict"; - -const hook = require("@nativescript/hook")(__dirname); - -const { compareProjectFiles } = require("./helpers/projectFilesManager"); -const { getProjectDir } = require("./helpers/projectHelpers"); -const path = require("path"); -const fs = require("fs"); - -const projectDir = getProjectDir(); - -// This method is introduced as in version 1.0.0 of @nativescript/webpack (compatible and required for NativeScript 6.0.0) -// we have changed a lot of hooks and old ones are incompatible. This should be automatically handled with preuninstall script of the old version. -// However, old versions of nativescript-dev-webpack do not have such logic, so remove them manually on postinstall of the current version. -// This logic can be removed later, once most of the projects are migrated to 1.0.0 of the package or later. -// These new versions have preuninstall script that will automatically handle this case. -function removeOldHooks() { - const oldHooks = [ - "before-prepareJSApp", - "before-cleanApp", - "before-watch", - "after-watch", - "before-watchPatterns", - "before-shouldPrepare", - "after-prepare", - "before-preview-sync" - ]; - - const hooksDir = path.join(projectDir, "hooks"); - const pkgName = require("./package.json").name; - const filename = `${pkgName}.js`; - oldHooks.forEach(hookName => { - const hookPath = path.join(hooksDir, hookName, filename); - - try { - if (fs.existsSync(hookPath)) { - fs.unlinkSync(hookPath); - } - } catch (err) { - console.warn(`${pkgName} postinstall task: unable to delete hook ${hookPath}. Error is: ${err}`); - } - }); -} - -if (projectDir) { - compareProjectFiles(projectDir); - removeOldHooks(); - hook.postinstall(); - const installer = require("./installer"); - installer.install(); -} else { - // We are installing dev dependencies for the @nativescript/webpack plugin. - console.log("Skipping postinstall artifacts! We assumed the @nativescript/webpack is installing devDependencies"); -} - diff --git a/packages/webpack/preuninstall.js b/packages/webpack/preuninstall.js deleted file mode 100644 index d21bfa859..000000000 --- a/packages/webpack/preuninstall.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict"; - -const hook = require("@nativescript/hook")(__dirname); - -const { getProjectDir } = require("./helpers/projectHelpers"); - -const projectDir = getProjectDir(); - -if (projectDir) { - hook.preuninstall(); -} diff --git a/packages/webpack/project.json b/packages/webpack/project.json deleted file mode 100644 index 7b8ca6b51..000000000 --- a/packages/webpack/project.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "$schema": "../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "packages/webpack", - "projectType": "library", - "generators": {}, - "targets": { - "lint": { - "executor": "@nrwl/linter:eslint", - "options": { - "lintFilePatterns": [] - } - }, - "test": { - "executor": "@nrwl/workspace:run-commands", - "options": { - "commands": ["npm run tsc", "npm run jasmine"], - "cwd": "packages/webpack", - "parallel": false - } - }, - "build": { - "executor": "@nrwl/workspace:run-commands", - "outputs": ["dist/packages"], - "options": { - "commands": ["npm run setup", "mkdir -p ../../dist/packages", "mv \"$(npm pack | tail -n 1)\" ../../dist/packages/nativescript-webpack.tgz"], - "cwd": "packages/webpack", - "parallel": false - } - } - } -} diff --git a/packages/webpack/snapshot/android/project-snapshot-generator-cli-ags-parser.js b/packages/webpack/snapshot/android/project-snapshot-generator-cli-ags-parser.js deleted file mode 100644 index 6d3b9b612..000000000 --- a/packages/webpack/snapshot/android/project-snapshot-generator-cli-ags-parser.js +++ /dev/null @@ -1,74 +0,0 @@ -module.exports = function parseProjectSnapshotGeneratorArgs() { - var result = parseJsonFromProcessArgs(); - - if (result.targetArchs) { - result.targetArchs = parseStringArray(result.targetArchs); - } - - if (result.useLibs !== undefined) { - result.useLibs = parseBool(result.useLibs); - } - - if (result.snapshotInDocker !== undefined) { - result.snapshotInDocker = parseBool(result.snapshotInDocker); - } - - if (result.skipSnapshotTools !== undefined) { - result.skipSnapshotTools = parseBool(result.skipSnapshotTools); - } - - if (result.install !== undefined) { - result.install = parseBool(result.install); - } - - return result; -} - -function parseJsonFromProcessArgs() { - var args = process.argv.slice(2); - var result = {}; - - var currentKey = ""; - var currentValue = ""; - args.forEach(function (value, index, array) { - if (value.startsWith("--")) { // if is key - addKeyAndValueToResult(currentKey, currentValue, result); - currentKey = value.slice(2); - currentValue = null; - } - else { // if is first value - currentValue = (currentValue === null) ? value : currentValue + " " + value; - } - - if (index == array.length - 1) { // if is the last one - addKeyAndValueToResult(currentKey, currentValue, result); - } - }); - - return result; -} - -function addKeyAndValueToResult(key, value, result) { - if (!key) - return; - var jsValue = (value === null) ? null : value.toString(); - var keyPath = key.split("."); - var parentObject = result; - for (var i = 0; i < keyPath.length; i++) { - if (i == keyPath.length - 1) { - parentObject[keyPath[i]] = jsValue; - } - else { - parentObject[keyPath[i]] = parentObject[keyPath[i]] || {}; - parentObject = parentObject[keyPath[i]]; - } - } -} - -function parseBool(value) { - return (value === null || value === "true") ? true : false; -} - -function parseStringArray(str) { - return str.toString().split(",").map(value => value.trim()); -} diff --git a/packages/webpack/snapshot/android/project-snapshot-generator.js b/packages/webpack/snapshot/android/project-snapshot-generator.js deleted file mode 100644 index 307b5587b..000000000 --- a/packages/webpack/snapshot/android/project-snapshot-generator.js +++ /dev/null @@ -1,197 +0,0 @@ -const { isAbsolute, join, resolve, sep } = require("path"); -const { readFileSync, writeFileSync } = require("fs"); - -const shelljs = require("shelljs"); -const semver = require("semver"); - -const SnapshotGenerator = require("./snapshot-generator"); -const { - CONSTANTS -} = require("./utils"); -const { - ANDROID_PROJECT_DIR, - ANDROID_APP_PATH, - ANDROID_CONFIGURATIONS_PATH, - getAndroidRuntimeVersion, - getAndroidV8Version, - getRuntimeNdkRevision, - getMksnapshotParams -} = require("../../helpers/androidProjectHelpers"); - -// min version with settings.json file specifying the V8 version -const MIN_ANDROID_RUNTIME_VERSION = "5.2.1"; -const VALID_ANDROID_RUNTIME_TAGS = Object.freeze(["next", "rc"]); - -const resolveRelativePath = (path) => { - if (path) - return isAbsolute(path) ? path : resolve(process.cwd(), path); - return null; -}; - -function ProjectSnapshotGenerator(options) { - this.options = options = options || {}; - options.projectRoot = resolveRelativePath(options.projectRoot) || process.cwd(); - - console.log("Project root: " + options.projectRoot); - console.log("Snapshots build directory: " + this.getBuildPath()); - - this.validateAndroidRuntimeVersion(); -} -module.exports = ProjectSnapshotGenerator; - -ProjectSnapshotGenerator.calculateBuildPath = function (projectRoot) { - return join( - ProjectSnapshotGenerator.calculateProjectPath(projectRoot), - "snapshot-build", - "build" - ); -} - -ProjectSnapshotGenerator.prototype.getBuildPath = function () { - return ProjectSnapshotGenerator.calculateBuildPath(this.options.projectRoot); -} - -ProjectSnapshotGenerator.calculateProjectPath = function (projectRoot) { - return join(projectRoot, ANDROID_PROJECT_DIR); -} - -ProjectSnapshotGenerator.calculateConfigurationsPath = function (projectRoot) { - return join(projectRoot, ANDROID_CONFIGURATIONS_PATH); -} - -ProjectSnapshotGenerator.calculateAppPath = function (projectRoot) { - return join(projectRoot, ANDROID_APP_PATH); -} - -ProjectSnapshotGenerator.prototype.getProjectPath = function () { - return ProjectSnapshotGenerator.calculateProjectPath(this.options.projectRoot); -} - -ProjectSnapshotGenerator.cleanSnapshotArtefacts = function (projectRoot) { - const platformPath = ProjectSnapshotGenerator.calculateProjectPath(projectRoot); - - // Remove blob files from prepared folder - shelljs.rm("-rf", join(platformPath, "src/main/assets/snapshots")); - - // Remove prepared include.gradle configurations - const configurationsPath = ProjectSnapshotGenerator.calculateConfigurationsPath(projectRoot); - shelljs.rm("-rf", join(configurationsPath, SnapshotGenerator.SNAPSHOT_PACKAGE_NANE)); -} - -ProjectSnapshotGenerator.installSnapshotArtefacts = function (projectRoot) { - const buildPath = ProjectSnapshotGenerator.calculateBuildPath(projectRoot); - const platformPath = ProjectSnapshotGenerator.calculateProjectPath(projectRoot); - - const appPath = ProjectSnapshotGenerator.calculateAppPath(projectRoot); - const configurationsPath = ProjectSnapshotGenerator.calculateConfigurationsPath(projectRoot); - const configDestinationPath = join(configurationsPath, SnapshotGenerator.SNAPSHOT_PACKAGE_NANE); - - // Remove build folder to make sure that the apk will be fully rebuild - shelljs.rm("-rf", join(platformPath, "build")); - - // Copy include.gradle to the specified destination in the platforms folder - shelljs.mkdir("-p", configDestinationPath); - shelljs.cp(join(buildPath, "include.gradle"), join(configDestinationPath, "include.gradle")); - - if (shelljs.test("-e", join(buildPath, "ndk-build/libs"))) { - // useLibs = true - const libsDestinationPath = join(platformPath, "src", SnapshotGenerator.SNAPSHOT_PACKAGE_NANE, "jniLibs"); - - // Copy the libs to the specified destination in the platforms folder - shelljs.mkdir("-p", libsDestinationPath); - shelljs.cp("-R", join(buildPath, "ndk-build/libs") + sep, libsDestinationPath); - } else { - // useLibs = false - const blobsSrcPath = join(buildPath, "snapshots/blobs"); - const blobsDestinationPath = resolve(appPath, "../snapshots"); - const appPackageJsonPath = join(appPath, "package.json"); - - // Copy the blobs in the prepared app folder - shelljs.cp("-R", blobsSrcPath + sep, resolve(appPath, "../snapshots")); - - // Update the package.json file - const appPackageJson = shelljs.test("-e", appPackageJsonPath) ? JSON.parse(readFileSync(appPackageJsonPath, 'utf8')) : {}; - appPackageJson["android"] = appPackageJson["android"] || {}; - appPackageJson["android"]["heapSnapshotBlob"] = "../snapshots"; - writeFileSync(appPackageJsonPath, JSON.stringify(appPackageJson, null, 2)); - } -} - -ProjectSnapshotGenerator.prototype.validateAndroidRuntimeVersion = function () { - const currentRuntimeVersion = getAndroidRuntimeVersion(this.options.projectRoot); - - if (!currentRuntimeVersion || !this.getProjectPath()) { - throw new Error("In order to generate a V8 snapshot you must have the \"android\" platform installed - to do so please run \"tns platform add android\"."); - } - - if (!VALID_ANDROID_RUNTIME_TAGS.includes(currentRuntimeVersion) && - !semver.gte(currentRuntimeVersion, MIN_ANDROID_RUNTIME_VERSION)) { - - throw new Error("In order to support heap snapshots, you must have at least tns-android@" + MIN_ANDROID_RUNTIME_VERSION + - " installed. Current Android Runtime version is: " + currentRuntimeVersion + "."); - } -} - -ProjectSnapshotGenerator.prototype.generate = function (generationOptions) { - if (generationOptions.skipSnapshotTools) { - console.log("Skipping snapshot tools."); - return Promise.resolve(); - } - - generationOptions = generationOptions || {}; - - console.log("Running snapshot generation with the following arguments: "); - console.log(JSON.stringify(generationOptions, null, '\t')); - - // Clean build folder - shelljs.rm("-rf", this.getBuildPath()); - shelljs.mkdir("-p", this.getBuildPath()); - - const snapshotToolsPath = resolveRelativePath(generationOptions.snapshotToolsPath) || CONSTANTS.SNAPSHOT_TMP_DIR; - console.log("Snapshot tools path: " + snapshotToolsPath); - - // Generate snapshots - const generator = new SnapshotGenerator({ buildPath: this.getBuildPath() }); - const noV8VersionFoundMessage = `Cannot find suitable v8 version!`; - const mksnapshotParams = getMksnapshotParams(this.options.projectRoot); - const recommendedAndroidNdkRevision = getRuntimeNdkRevision(this.options.projectRoot); - const v8Version = generationOptions.v8Version || getAndroidV8Version(this.options.projectRoot); - if (!v8Version) { - throw new Error(noV8VersionFoundMessage); - } - - // NOTE: Order is important! Add new archs at the end of the array - const defaultTargetArchs = ["arm", "arm64", "ia32", "ia64"]; - const runtimeVersion = getAndroidRuntimeVersion(this.options.projectRoot); - if (runtimeVersion && semver.lt(semver.coerce(runtimeVersion), "6.0.2")) { - const indexOfIa64 = defaultTargetArchs.indexOf("ia64"); - // Before 6.0.2 version of Android runtime we supported only arm, arm64 and ia32. - defaultTargetArchs.splice(indexOfIa64, defaultTargetArchs.length - indexOfIa64); - } - - const options = { - snapshotToolsPath, - targetArchs: generationOptions.targetArchs || defaultTargetArchs, - v8Version: generationOptions.v8Version || v8Version, - preprocessedInputFile: generationOptions.preprocessedInputFile, - useLibs: generationOptions.useLibs || false, - inputFiles: generationOptions.inputFiles || [join(this.options.projectRoot, "__snapshot.js")], - androidNdkPath: generationOptions.androidNdkPath, - mksnapshotParams: mksnapshotParams, - snapshotInDocker: generationOptions.snapshotInDocker, - recommendedAndroidNdkRevision, - runtimeVersion - }; - - return generator.generate(options).then(() => { - console.log("Snapshots build finished succesfully!"); - - if (generationOptions.install) { - ProjectSnapshotGenerator.cleanSnapshotArtefacts(this.options.projectRoot); - ProjectSnapshotGenerator.installSnapshotArtefacts(this.options.projectRoot); - console.log(generationOptions.useLibs ? - "Snapshot is included in the app as dynamically linked library (.so file)." : - "Snapshot is included in the app as binary .blob file. The more space-efficient option is to embed it in a dynamically linked library (.so file)."); - } - });; -} diff --git a/packages/webpack/snapshot/android/snapshot-generator-tools/bundle-ending.js b/packages/webpack/snapshot/android/snapshot-generator-tools/bundle-ending.js deleted file mode 100644 index 1b19817a7..000000000 --- a/packages/webpack/snapshot/android/snapshot-generator-tools/bundle-ending.js +++ /dev/null @@ -1,12 +0,0 @@ - - -/*!**********************************************************!*\ - !*** ../android-snapshot-bundle-ending.js ***! - \**********************************************************/ -// Set the __snapshot flag to false -Object.defineProperty(global, "__snapshot", { - value: false, - writable: false, - configurable: false, - enumerable: false -}); diff --git a/packages/webpack/snapshot/android/snapshot-generator-tools/bundle-preamble.js b/packages/webpack/snapshot/android/snapshot-generator-tools/bundle-preamble.js deleted file mode 100644 index 46e171f5b..000000000 --- a/packages/webpack/snapshot/android/snapshot-generator-tools/bundle-preamble.js +++ /dev/null @@ -1,34 +0,0 @@ -/*!**********************************************************!*\ - !*** ../android-snapshot-bundle-preamble.js ***! - \**********************************************************/ -var global = Function('return this')(); global.global = global; // Mock global object -// Set the __snapshotEnabled flag to true -Object.defineProperty(global, "__snapshotEnabled", { - value: true, - writable: false, - configurable: false, - enumerable: false -}); -// Set the __snapshot flag to true -Object.defineProperty(global, "__snapshot", { - value: true, - writable: false, - configurable: true, - enumerable: false -}); - -global.__requireOverride = (function() { - return function(moduleId, dirname) { - /* - The android runtime loads in advance all JS modules that contain a native class successor generated statically at build time. - In case of snapshot this file always is the bundled one. Since it is snapshoted it is already loaded in the heap and is not meant - to be required. The main entry file (bundle.js) is responsible for actually executing the modules containing native java classes. - */ - var resolvedModuleId = moduleId.replace(/^\.\/tns_modules\//, ""); - if (resolvedModuleId === './_embedded_script_.js') { - return {}; - } - }; -}()); - - diff --git a/packages/webpack/snapshot/android/snapshot-generator-tools/include.gradle b/packages/webpack/snapshot/android/snapshot-generator-tools/include.gradle deleted file mode 100644 index 739ac63a4..000000000 --- a/packages/webpack/snapshot/android/snapshot-generator-tools/include.gradle +++ /dev/null @@ -1,13 +0,0 @@ -android { - productFlavors { - "nativescript-android-snapshot" { - dimension "nativescript-android-snapshot" - } - } -} - -android { - aaptOptions { - ignoreAssetsPattern "_embedded_script_.js" - } -} diff --git a/packages/webpack/snapshot/android/snapshot-generator-tools/ndk-build/.gitignore b/packages/webpack/snapshot/android/snapshot-generator-tools/ndk-build/.gitignore deleted file mode 100644 index 3012f1592..000000000 --- a/packages/webpack/snapshot/android/snapshot-generator-tools/ndk-build/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/libs -/obj -/jni/*/TNSSnapshot.c - diff --git a/packages/webpack/snapshot/android/snapshot-generator-tools/ndk-build/jni/Android.mk b/packages/webpack/snapshot/android/snapshot-generator-tools/ndk-build/jni/Android.mk deleted file mode 100644 index caee92608..000000000 --- a/packages/webpack/snapshot/android/snapshot-generator-tools/ndk-build/jni/Android.mk +++ /dev/null @@ -1,7 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) -LOCAL_MODULE := snapshot -LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/TNSSnapshot.c -include $(BUILD_SHARED_LIBRARY) - diff --git a/packages/webpack/snapshot/android/snapshot-generator.js b/packages/webpack/snapshot/android/snapshot-generator.js deleted file mode 100644 index d3b54d223..000000000 --- a/packages/webpack/snapshot/android/snapshot-generator.js +++ /dev/null @@ -1,464 +0,0 @@ -const fs = require("fs"); -const { dirname, relative, join, EOL } = require("path"); -const child_process = require("child_process"); -const { convertToUnixPath, warn } = require("../../lib/utils"); -const { isWindows } = require("./utils"); -const PropertiesReader = require('properties-reader'); -const semver = require("semver"); -const shelljs = require("shelljs"); - -const { createDirectory, downloadFile, getHostOS, getHostOSArch, CONSTANTS, has32BitArch, isMacOSCatalinaOrHigher, isSubPath } = require("./utils"); - -const SNAPSHOTS_DOCKER_IMAGE = "nativescript/v8-snapshot:latest"; -const SNAPSHOT_TOOLS_DIR_NAME = "mksnapshot-tools"; -const NDK_BUILD_SEED_PATH = join(__dirname, "snapshot-generator-tools/ndk-build"); -const BUNDLE_PREAMBLE_PATH = join(__dirname, "snapshot-generator-tools/bundle-preamble.js"); -const BUNDLE_ENDING_PATH = join(__dirname, "snapshot-generator-tools/bundle-ending.js"); -const INCLUDE_GRADLE_PATH = join(__dirname, "snapshot-generator-tools/include.gradle"); -const MKSNAPSHOT_TOOLS_DOWNLOAD_ROOT_URL = "https://raw.githubusercontent.com/NativeScript/mksnapshot-tools/production/"; -const MKSNAPSHOT_TOOLS_DOWNLOAD_TIMEOUT = 60000; -const SNAPSHOT_BLOB_NAME = "TNSSnapshot"; -const DOCKER_IMAGE_OS = "linux"; -const DOCKER_IMAGE_ARCH = "x64"; - -function shellJsExecuteInDir(dir, action) { - const currentDir = shelljs.pwd(); - shelljs.cd(dir); - try { - action(); - } finally { - shelljs.cd(currentDir); - } -} - -function SnapshotGenerator(options) { - this.buildPath = options.buildPath || join(__dirname, "build"); -} -module.exports = SnapshotGenerator; - -SnapshotGenerator.SNAPSHOT_PACKAGE_NANE = "nativescript-android-snapshot"; - -SnapshotGenerator.prototype.shouldSnapshotInDocker = function (hostOS, targetArchs, currentRuntimeVersion) { - let shouldSnapshotInDocker = false; - const minRuntimeWithoutMacOSSnapshotTools = "6.3.0"; - const generateInDockerMessage = "The snapshots will be generated in a docker container."; - if (hostOS === CONSTANTS.WIN_OS_NAME) { - console.log(`The V8 snapshot tools are not supported on Windows. ${generateInDockerMessage}`); - shouldSnapshotInDocker = true; - } else if (hostOS === CONSTANTS.MAC_OS_NAME && semver.gte(currentRuntimeVersion, minRuntimeWithoutMacOSSnapshotTools)) { - console.log(`Starting from Android Runtime 6.3.0, the Snapshot tools are no longer supported on macOS. ${generateInDockerMessage}`); - shouldSnapshotInDocker = true; - } else if (isMacOSCatalinaOrHigher() && has32BitArch(targetArchs)) { - console.log(`Starting from macOS Catalina, the 32-bit processes are no longer supported. ${generateInDockerMessage}`); - shouldSnapshotInDocker = true; - } - - return shouldSnapshotInDocker; -} - -SnapshotGenerator.prototype.preprocessInputFiles = function (inputFiles, outputFile) { - // Make some modifcations on the original bundle and save it on the specified path - const bundlePreambleContent = fs.readFileSync(BUNDLE_PREAMBLE_PATH, "utf8"); - const bundleEndingContent = fs.readFileSync(BUNDLE_ENDING_PATH, "utf8"); - - // IMPORTANT: join by "\n;" as we are joining IIFE functions and if the snapshot tool is used - // along with Uglify configuration for replacing `;` with `/n`, we will generate invalid JavaScript - // Example: - // (function() { - // some code here - // })() - // // sourceMapUrl...... - // ** when we join without `;` here, the next IIFE is assumed as a function call to the result of the first IIFE - // (function() { - // some code here - // })() - // // sourceMapUrl...... - const inputFilesContent = inputFiles.map(file => fs.readFileSync(file, "utf8")).join("\n;"); - const snapshotFileContent = bundlePreambleContent + "\n" + inputFilesContent + "\n" + bundleEndingContent; - fs.writeFileSync(outputFile, snapshotFileContent, { encoding: "utf8" }); -} - -const snapshotToolsDownloads = {}; - -SnapshotGenerator.prototype.downloadMksnapshotTools = function (snapshotToolsPath, v8Version, targetArchs, snapshotInDocker) { - var toolsOS = ""; - var toolsArch = ""; - if (snapshotInDocker) { - toolsOS = DOCKER_IMAGE_OS; - toolsArch = DOCKER_IMAGE_ARCH; - } else { - toolsOS = getHostOS(); - toolsArch = getHostOSArch(); - } - - return Promise.all(targetArchs.map((arch) => { - return this.downloadMksnapshotTool(snapshotToolsPath, v8Version, arch, toolsOS, toolsArch).then(path => { - return { path, arch }; - }); - })); -} - -SnapshotGenerator.prototype.downloadMksnapshotTool = function (snapshotToolsPath, v8Version, targetArch, hostOS, hostArch) { - const mksnapshotToolRelativePath = join(SNAPSHOT_TOOLS_DIR_NAME, "v8-v" + v8Version, hostOS + "-" + hostArch, "mksnapshot-" + targetArch); - const mksnapshotToolPath = join(snapshotToolsPath, mksnapshotToolRelativePath); - if (fs.existsSync(mksnapshotToolPath)) - return Promise.resolve(mksnapshotToolPath); - - if (snapshotToolsDownloads[mksnapshotToolPath]) - return snapshotToolsDownloads[mksnapshotToolPath]; - - const downloadUrl = MKSNAPSHOT_TOOLS_DOWNLOAD_ROOT_URL + mksnapshotToolRelativePath; - createDirectory(dirname(mksnapshotToolPath)); - snapshotToolsDownloads[mksnapshotToolPath] = downloadFile(downloadUrl, mksnapshotToolPath, MKSNAPSHOT_TOOLS_DOWNLOAD_TIMEOUT); - snapshotToolsDownloads[mksnapshotToolPath].catch(err => { - const errorMessage = err && err.message ? err.message : ""; - let cleanupError = ""; - try { - fs.unlinkSync(mksnapshotToolPath); - } catch (unlinkErr) { - if (unlinkErr && unlinkErr.code !== "ENOENT") { - cleanupError = `${EOL}Failed to cleanup mksnapshot tool.`; - } - } - - throw new Error(`Failed to download mksnapshot tool. Error: ${errorMessage}.${cleanupError}`); - }); - return snapshotToolsDownloads[mksnapshotToolPath]; -} - -SnapshotGenerator.prototype.convertToAndroidArchName = function (archName) { - switch (archName) { - case "arm": return "armeabi-v7a"; - case "arm64": return "arm64-v8a"; - case "ia32": return "x86"; - case "ia64": return "x86_64"; - default: return archName; - } -} - -SnapshotGenerator.prototype.generateSnapshots = function (snapshotToolsPath, inputFile, v8Version, targetArchs, buildCSource, mksnapshotParams, snapshotInDocker) { - // Cleans the snapshot build folder - shelljs.rm("-rf", join(this.buildPath, "snapshots")); - return this.downloadMksnapshotTools(snapshotToolsPath, v8Version, targetArchs, snapshotInDocker).then((localTools) => { - var shouldDownloadDockerTools = false; - if (!snapshotInDocker) { - snapshotInDocker = localTools.some(tool => !this.canUseSnapshotTool(tool.path)); - shouldDownloadDockerTools = snapshotInDocker; - } - - if (shouldDownloadDockerTools) { - return this.downloadMksnapshotTools(snapshotToolsPath, v8Version, targetArchs, snapshotInDocker).then((dockerTools) => { - console.log(`Generating snapshots in a docker container.`); - return this.runMksnapshotTools(snapshotToolsPath, dockerTools, inputFile, mksnapshotParams, buildCSource, snapshotInDocker); - }); - } - - return this.runMksnapshotTools(snapshotToolsPath, localTools, inputFile, mksnapshotParams, buildCSource, snapshotInDocker); - }); -} - - -SnapshotGenerator.prototype.runMksnapshotTools = function (snapshotToolsBasePath, snapshotTools, inputFile, mksnapshotParams, buildCSource, snapshotInDocker) { - let currentSnapshotOperation = Promise.resolve(); - const canRunInParallel = !snapshotInDocker; - return Promise.all(snapshotTools.map((tool) => { - if (canRunInParallel) { - return this.runMksnapshotTool(tool, mksnapshotParams, inputFile, snapshotInDocker, snapshotToolsBasePath, buildCSource); - } else { - currentSnapshotOperation = currentSnapshotOperation.then(() => { - return this.runMksnapshotTool(tool, mksnapshotParams, inputFile, snapshotInDocker, snapshotToolsBasePath, buildCSource); - }); - - return currentSnapshotOperation; - } - })).then(() => { - console.log("***** Finished generating snapshots. *****"); - }); -} - -SnapshotGenerator.prototype.canUseSnapshotTool = function (snapshotToolPath) { - try { - child_process.execSync(`${snapshotToolPath} --help`); - return true; - } - catch (error) { - console.log(`Unable to execute '${snapshotToolPath}' locally.Error message: '${error.message}'`); - return false; - } -} - -SnapshotGenerator.prototype.setupDocker = function () { - try { - child_process.execSync(`docker --version`); - } - catch (error) { - throw new Error(`Docker installation cannot be found. Install Docker and add it to your PATH in order to build snapshots.`); - } - - child_process.execSync(`docker pull ${SNAPSHOTS_DOCKER_IMAGE}`); -} - -SnapshotGenerator.prototype.buildSnapshotLibs = function (androidNdkPath, recommendedAndroidNdkRevision, targetArchs) { - // Compile *.c files to produce *.so libraries with ndk-build tool - const androidNdkBuildPath = this.getAndroidNdkBuildPath(androidNdkPath, recommendedAndroidNdkRevision); - const ndkBuildPath = join(this.buildPath, "ndk-build"); - const androidArchs = targetArchs.map(arch => this.convertToAndroidArchName(arch)); - console.log("Building native libraries for " + androidArchs.join()); - shelljs.rm("-rf", ndkBuildPath); - shelljs.cp("-r", NDK_BUILD_SEED_PATH, ndkBuildPath); - fs.writeFileSync(join(ndkBuildPath, "jni/Application.mk"), "APP_ABI := " + androidArchs.join(" ")); // create Application.mk file - shelljs.mv(join(this.buildPath, "snapshots/src/*"), join(ndkBuildPath, "jni")); - shellJsExecuteInDir(ndkBuildPath, function () { - shelljs.exec(androidNdkBuildPath); - }); - return join(ndkBuildPath, "libs"); -} - -SnapshotGenerator.prototype.getAndroidNdkBuildPath = function (androidNdkPath, recommendedAndroidNdkRevision) { - const ndkBuildExecutableName = isWindows() ? "ndk-build.cmd" : "ndk-build"; - let hasNdk = false; - // fallback for Android Runtime < 6.2.0 with the 6.1.0 value - recommendedAndroidNdkRevision = recommendedAndroidNdkRevision || "20.0.5594570"; - let androidNdkBuildPath = ""; - if (androidNdkPath) { - // specified by the user - const localNdkRevision = this.getAndroidNdkRevision(androidNdkPath); - androidNdkBuildPath = join(androidNdkPath, ndkBuildExecutableName); - if (!fs.existsSync(androidNdkBuildPath)) { - throw new Error(`The provided Android NDK path does not contain ${ndkBuildExecutableName} executable.`); - } else if (localNdkRevision !== recommendedAndroidNdkRevision) { - warn(this.getRecommendedNdkWarning(localNdkRevision, recommendedAndroidNdkRevision)); - } - - hasNdk = true; - console.log("Using Android NDK from webpack.config."); - } else { - if (process.env.ANDROID_NDK_HOME) { - // check ANDROID_NDK_HOME - const localNdkRevision = this.getAndroidNdkRevision(process.env.ANDROID_NDK_HOME); - androidNdkBuildPath = join(process.env.ANDROID_NDK_HOME, ndkBuildExecutableName); - if (fs.existsSync(androidNdkBuildPath)) { - hasNdk = true; - console.log("Using Android NDK from ANDROID_NDK_HOME."); - } - - if (localNdkRevision !== recommendedAndroidNdkRevision) { - warn(this.getRecommendedNdkWarning(localNdkRevision, recommendedAndroidNdkRevision)); - } - } - - if (!hasNdk) { - // available globally - androidNdkBuildPath = ndkBuildExecutableName; - try { - child_process.execSync(`${androidNdkBuildPath} --version`, { stdio: "ignore" }); - hasNdk = true; - console.log("Using Android NDK from PATH."); - console.log(`Cannot determine the version of the global Android NDK. The recommended versions is v${recommendedAndroidNdkRevision}`); - } catch (_) { - } - } - - if (!hasNdk) { - // installed in ANDROID_HOME - androidNdkBuildPath = join(process.env.ANDROID_HOME, "ndk", recommendedAndroidNdkRevision, ndkBuildExecutableName); - if (fs.existsSync(androidNdkBuildPath)) { - hasNdk = true; - console.log("Using Android NDK from ANDROID_HOME."); - } - } - } - - if (!hasNdk) { - throw new Error(`Android NDK v${recommendedAndroidNdkRevision} is not installed. Install it from Android Studio or download it and set ANDROID_NDK_HOME or add it to your PATH. You can find installation instructions in this article: https://developer.android.com/studio/projects/install-ndk#specific-version`); - } - - return androidNdkBuildPath; -} - -SnapshotGenerator.prototype.getAndroidNdkRevision = function (androidNdkPath) { - const ndkPropertiesFile = join(androidNdkPath, "source.properties"); - if (fs.existsSync(ndkPropertiesFile)) { - const properties = PropertiesReader(ndkPropertiesFile); - return properties.get("Pkg.Revision"); - } else { - return null; - } -} - -SnapshotGenerator.prototype.buildIncludeGradle = function () { - shelljs.cp(INCLUDE_GRADLE_PATH, join(this.buildPath, "include.gradle")); -} - -SnapshotGenerator.prototype.generate = function (options) { - // Arguments validation - options = options || {}; - if (!options.v8Version) { throw new Error("No v8 version specified."); } - if (!options.snapshotToolsPath) { throw new Error("snapshotToolsPath option is not specified."); } - const preprocessedInputFile = options.preprocessedInputFile || join(this.buildPath, "inputFile.preprocessed"); - - console.log("***** Starting snapshot generation using V8 version: ", options.v8Version); - - this.preprocessInputFiles(options.inputFiles, preprocessedInputFile); - const hostOS = getHostOS(); - const snapshotInDocker = options.snapshotInDocker || this.shouldSnapshotInDocker(hostOS, options.targetArchs, options.runtimeVersion); - - // generates the actual .blob and .c files - return this.generateSnapshots( - options.snapshotToolsPath, - preprocessedInputFile, - options.v8Version, - options.targetArchs, - options.useLibs, - options.mksnapshotParams, - snapshotInDocker - ).then(() => { - this.buildIncludeGradle(); - if (options.useLibs) { - this.buildSnapshotLibs(options.androidNdkPath, options.recommendedAndroidNdkRevision, options.targetArchs); - } - return this.buildPath; - }); -} - -SnapshotGenerator.prototype.getSnapshotToolCommand = function (snapshotToolPath, inputFilePath, outputPath, toolParams) { - return `${snapshotToolPath} ${inputFilePath} --startup_blob ${outputPath} ${toolParams}`; -} - -SnapshotGenerator.prototype.getXxdCommand = function (srcOutputDir, xxdLocation) { - // https://github.com/NativeScript/docker-images/tree/master/v8-snapshot/bin - return `${xxdLocation || ""}xxd -i ${SNAPSHOT_BLOB_NAME}.blob > ${srcOutputDir}`; -} - -SnapshotGenerator.prototype.getPathInDocker = function (mappedLocalDir, mappedDockerDir, targetPath) { - if (!isSubPath(mappedLocalDir, targetPath)) { - throw new Error(`Cannot determine a docker path. '${targetPath}' should be inside '${mappedLocalDir}'`) - } - - const pathInDocker = join(mappedDockerDir, relative(mappedLocalDir, targetPath)); - - return convertToUnixPath(pathInDocker); -} - -SnapshotGenerator.prototype.handleSnapshotToolResult = function (error, stdout, stderr, inputFile, androidArch) { - let toolError = null; - const errorHeader = `Target architecture: ${androidArch}\n`; - let errorFooter = ``; - if ((stderr && stderr.length) || error) { - try { - require(inputFile); - } - catch (e) { - errorFooter = `\nJavaScript execution error: ${e.stack}$`; - } - } - - if (stderr && stderr.length) { - const message = `${errorHeader}${stderr}${errorFooter}`; - toolError = new Error(message); - } - else if (error) { - error.message = `${errorHeader}${error.message}${errorFooter}`; - toolError = error; - } else { - console.log(stdout); - } - - return toolError; -} - -SnapshotGenerator.prototype.copySnapshotTool = function (allToolsDir, targetTool, destinationDir) { - // we cannot mount the source tools folder as its not shared by default: - // docker: Error response from daemon: Mounts denied: - // The path /var/folders/h2/1yck52fx2mg7c790vhcw90s8087sk8/T/snapshot-tools/mksnapshot-tools - // is not shared from OS X and is not known to Docker. - const toolPathRelativeToAllToolsDir = relative(allToolsDir, targetTool); - const toolDestinationPath = join(destinationDir, toolPathRelativeToAllToolsDir) - createDirectory(dirname(toolDestinationPath)); - shelljs.cp(targetTool, toolDestinationPath); - - return toolDestinationPath; -} - -SnapshotGenerator.prototype.buildCSource = function (androidArch, blobInputDir, snapshotInDocker) { - const srcOutputDir = join(this.buildPath, "snapshots/src", androidArch); - createDirectory(srcOutputDir); - let command = ""; - if (snapshotInDocker) { - const blobsInputInDocker = `/blobs/${androidArch}` - const srcOutputDirInDocker = `/dist/src/${androidArch}`; - const outputPathInDocker = this.getPathInDocker(srcOutputDir, srcOutputDirInDocker, join(srcOutputDir, `${SNAPSHOT_BLOB_NAME}.c`)); - const buildCSourceCommand = this.getXxdCommand(outputPathInDocker, "/bin/"); - command = `docker run --rm -v "${blobInputDir}:${blobsInputInDocker}" -v "${srcOutputDir}:${srcOutputDirInDocker}" ${SNAPSHOTS_DOCKER_IMAGE} /bin/sh -c "cd ${blobsInputInDocker} && ${buildCSourceCommand}"`; - } - else { - command = this.getXxdCommand(join(srcOutputDir, `${SNAPSHOT_BLOB_NAME}.c`)); - } - shellJsExecuteInDir(blobInputDir, function () { - shelljs.exec(command); - }); -} - -SnapshotGenerator.prototype.getRecommendedNdkWarning = function (localNdkRevision, recommendedAndroidNdkRevision) { - return `The provided Android NDK is v${localNdkRevision} while the recommended one is v${recommendedAndroidNdkRevision}`; -} - -SnapshotGenerator.prototype.runMksnapshotTool = function (tool, mksnapshotParams, inputFile, snapshotInDocker, snapshotToolsPath, buildCSource) { - const toolPath = tool.path; - const androidArch = this.convertToAndroidArchName(tool.arch); - if (!fs.existsSync(toolPath)) { - throw new Error(`Can't find mksnapshot tool for ${androidArch} at path ${toolPath}`); - } - - const tempFolders = []; - return new Promise((resolve, reject) => { - console.log("***** Generating snapshot for " + androidArch + " *****"); - const inputFileDir = dirname(inputFile); - const blobOutputDir = join(this.buildPath, "snapshots/blobs", androidArch); - createDirectory(blobOutputDir); - const toolParams = mksnapshotParams || "--profile_deserialization"; - - let command = ""; - if (snapshotInDocker) { - this.setupDocker(); - const appDirInDocker = "/app"; - const blobOutputDirInDocker = `/dist/blobs/${androidArch}`; - const toolsTempFolder = join(inputFileDir, "tmp"); - tempFolders.push(toolsTempFolder); - const toolPathInAppDir = this.copySnapshotTool(snapshotToolsPath, toolPath, toolsTempFolder); - const toolPathInDocker = this.getPathInDocker(inputFileDir, appDirInDocker, toolPathInAppDir); - const inputFilePathInDocker = this.getPathInDocker(inputFileDir, appDirInDocker, inputFile); - const outputPathInDocker = this.getPathInDocker(blobOutputDir, blobOutputDirInDocker, join(blobOutputDir, `${SNAPSHOT_BLOB_NAME}.blob`)); - const toolCommandInDocker = this.getSnapshotToolCommand(toolPathInDocker, inputFilePathInDocker, outputPathInDocker, toolParams); - command = `docker run --rm -v "${inputFileDir}:${appDirInDocker}" -v "${blobOutputDir}:${blobOutputDirInDocker}" ${SNAPSHOTS_DOCKER_IMAGE} /bin/sh -c "${toolCommandInDocker}"`; - } else { - command = this.getSnapshotToolCommand(toolPath, inputFile, join(blobOutputDir, `${SNAPSHOT_BLOB_NAME}.blob`), toolParams); - } - - // Generate .blob file - child_process.exec(command, { encoding: "utf8" }, (error, stdout, stderr) => { - tempFolders.forEach(tempFolder => { - shelljs.rm("-rf", tempFolder); - }); - - const snapshotError = this.handleSnapshotToolResult(error, stdout, stderr, inputFile, androidArch); - if (snapshotError) { - return reject(snapshotError); - } - - return resolve(blobOutputDir); - }); - }).then((blobOutputDir) => { - // Generate .c file - if (buildCSource) { - this.buildCSource(androidArch, blobOutputDir, snapshotInDocker) - } - - /* - Rename TNSSnapshot.blob files to snapshot.blob files. The xxd tool uses the file name for the name of the static array. - This is why the *.blob files are initially named TNSSnapshot.blob. - After the xxd step, they must be renamed to snapshot.blob, because this is the filename that the Android runtime is looking for. - */ - shelljs.mv(join(blobOutputDir, `${SNAPSHOT_BLOB_NAME}.blob`), join(blobOutputDir, `snapshot.blob`)); - }); -} diff --git a/packages/webpack/snapshot/android/utils.js b/packages/webpack/snapshot/android/utils.js deleted file mode 100644 index 193d3352a..000000000 --- a/packages/webpack/snapshot/android/utils.js +++ /dev/null @@ -1,128 +0,0 @@ -const { chmodSync, createWriteStream } = require("fs"); -const { tmpdir, EOL } = require("os"); -const { join, relative, isAbsolute } = require("path"); -const os = require("os"); - -const { mkdir } = require("shelljs"); -// const { get } = require("request"); -const { getProxySettings } = require("proxy-lib"); -const semver = require("semver"); - -const CONSTANTS = { - SNAPSHOT_TMP_DIR: join(tmpdir(), "snapshot-tools"), - MAC_OS_NAME: "darwin", - WIN_OS_NAME: "win", - LINUX_OS_NAME: "linux" -}; - -const createDirectory = dir => mkdir('-p', dir); - -function getHostOS() { - const hostOS = os.type().toLowerCase(); - if (hostOS.startsWith(CONSTANTS.MAC_OS_NAME)) - return CONSTANTS.MAC_OS_NAME; - if (hostOS.startsWith(CONSTANTS.LINUX_OS_NAME)) - return CONSTANTS.LINUX_OS_NAME; - if (hostOS.startsWith(CONSTANTS.WIN_OS_NAME)) - return CONSTANTS.WIN_OS_NAME; - return hostOS; -} - -function getHostOSVersion() { - return os.release(); -} - -function getHostOSArch() { - return os.arch(); -} - -function has32BitArch(targetArchs) { - return (Array.isArray(targetArchs) && targetArchs.some(arch => arch === "arm" || arch === "ia32")) || - (targetArchs === "arm" || targetArchs === "ia32"); -} - -function isSubPath(parentPath, childPath) { - const relativePath = relative(parentPath, childPath); - - return relativePath === "" || - (relativePath && !relativePath.startsWith('..') && !isAbsolute(relativePath)); -} - -function isMacOSCatalinaOrHigher() { - let isCatalinaOrHigher = false; - const catalinaVersion = "19.0.0"; - const hostOS = getHostOS(); - if (hostOS === CONSTANTS.MAC_OS_NAME) { - const hostOSVersion = getHostOSVersion(); - isCatalinaOrHigher = semver.gte(hostOSVersion, catalinaVersion); - } - - return isCatalinaOrHigher; -} - -function isWindows() { - return getHostOS() === CONSTANTS.WIN_OS_NAME; -} - -const downloadFile = (url, destinationFilePath, timeout) => - new Promise((resolve, reject) => { - // getRequestOptions(url, timeout) - // .then(options => - // get(options) - // .on("error", reject) - // .pipe(createWriteStream(destinationFilePath, { autoClose: true })) - // .on("finish", _ => { - // chmodSync(destinationFilePath, 0755); - // return resolve(destinationFilePath); - // }) - // ).catch(reject); - }); - -const getJsonFile = url => - new Promise((resolve, reject) => { - // getRequestOptions(url) - // .then(options => - // get(options, (error, response, body) => { - // if (error) { - // return reject(error); - // } - - // if (!response || response.statusCode !== 200) { - // return reject(`Couldn't fetch ${url}! Response:${EOL}${response}`); - // } - - // try { - // const data = JSON.parse(body); - // resolve(data); - // } catch (error) { - // reject(`Couldn't parse json data! Original error:${EOL}${error}`); - // } - // }) - // ).catch(reject); - }); - -const getRequestOptions = (url, timeout) => - new Promise((resolve, reject) => { - const options = { url, timeout }; - getProxySettings() - .then(proxySettings => { - const allOptions = Object.assign(options, proxySettings); - resolve(allOptions); - }) - .catch(error => - reject(`Couldn't get proxy settings! Original error:${EOL}${error}`)); - }); - -module.exports = { - CONSTANTS, - createDirectory, - has32BitArch, - getHostOS, - getHostOSVersion, - getHostOSArch, - isMacOSCatalinaOrHigher, - downloadFile, - getJsonFile, - isSubPath, - isWindows -}; diff --git a/packages/webpack/templates/webpack.angular.js b/packages/webpack/templates/webpack.angular.js deleted file mode 100644 index d9ba22b4e..000000000 --- a/packages/webpack/templates/webpack.angular.js +++ /dev/null @@ -1,375 +0,0 @@ -const { join, relative, resolve, sep, dirname } = require('path'); -const fs = require('fs'); - -const webpack = require('webpack'); -const nsWebpack = require('@nativescript/webpack'); -const nativescriptTarget = require('@nativescript/webpack/nativescript-target'); -const { nsSupportHmrNg } = require('@nativescript/webpack/transformers/ns-support-hmr-ng'); -const { nsTransformNativeClassesNg } = require('@nativescript/webpack/transformers/ns-transform-native-classes-ng'); -const { parseWorkspaceConfig, hasConfigurations } = require('@nativescript/webpack/helpers/angular-config-parser'); -const { getMainModulePath } = require('@nativescript/webpack/utils/ast-utils'); -const { getNoEmitOnErrorFromTSConfig, getCompilerOptionsFromTSConfig } = require('@nativescript/webpack/utils/tsconfig-utils'); -const { CleanWebpackPlugin } = require('clean-webpack-plugin'); -const CopyWebpackPlugin = require('copy-webpack-plugin'); -const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); -const { NativeScriptWorkerPlugin } = require('nativescript-worker-loader/NativeScriptWorkerPlugin'); -const TerserPlugin = require('terser-webpack-plugin'); -const { getAngularCompilerPlugin } = require('@nativescript/webpack/plugins/NativeScriptAngularCompilerPlugin'); -const hashSalt = Date.now().toString(); - -module.exports = (env) => { - const platform = env && ((env.android && 'android') || (env.ios && 'ios')); - if (!platform) { - throw new Error('You need to provide a target platform!'); - } - - const AngularCompilerPlugin = getAngularCompilerPlugin(platform); - const projectRoot = __dirname; - - // Default destination inside platforms//... - const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - - const { - // The 'appPath' and 'appResourcesPath' values are fetched from - // the nsconfig.json configuration file - // when bundling with `tns run android|ios --bundle`. - appPath = 'src', - appResourcesPath = 'App_Resources', - - // You can provide the following flags when running 'tns run android|ios' - snapshot, // --env.snapshot, - production, // --env.production - configuration, // --env.configuration (consistent with angular cli usage) - projectName, // --env.projectName (drive configuration through angular projects) - uglify, // --env.uglify - report, // --env.report - sourceMap, // --env.sourceMap - hiddenSourceMap, // --env.hiddenSourceMap - hmr, // --env.hmr, - unitTesting, // --env.unitTesting - testing, // --env.testing - verbose, // --env.verbose - ci, // --env.ci - snapshotInDocker, // --env.snapshotInDocker - skipSnapshotTools, // --env.skipSnapshotTools - compileSnapshot, // --env.compileSnapshot - appComponents = [], - entries = {}, - } = env; - - const { fileReplacements, copyReplacements } = parseWorkspaceConfig(platform, configuration, projectName); - - const useLibs = compileSnapshot; - const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap; - const externals = nsWebpack.getConvertedExternals(env.externals); - const appFullPath = resolve(projectRoot, appPath); - const appResourcesFullPath = resolve(projectRoot, appResourcesPath); - let tsConfigName = 'tsconfig.json'; - let tsConfigPath = resolve(projectRoot, tsConfigName); - const tsConfigTnsName = 'tsconfig.tns.json'; - const tsConfigTnsPath = resolve(projectRoot, tsConfigTnsName); - if (fs.existsSync(tsConfigTnsPath)) { - // support shared angular app configurations - tsConfigName = tsConfigTnsName; - tsConfigPath = tsConfigTnsPath; - } - const tsConfigEnvName = 'tsconfig.env.json'; - const tsConfigEnvPath = resolve(projectRoot, tsConfigEnvName); - if (hasConfigurations(configuration) && fs.existsSync(tsConfigEnvPath)) { - // when configurations are used, switch to environments supported config - tsConfigName = tsConfigEnvName; - tsConfigPath = tsConfigEnvPath; - } - const entryModule = `${nsWebpack.getEntryModule(appFullPath, platform)}.ts`; - const entryPath = `.${sep}${entryModule}`; - Object.assign(entries, { bundle: entryPath }, entries); - const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some((e) => e.indexOf('@nativescript') > -1); - if (platform === 'ios' && !areCoreModulesExternal && !testing) { - entries['tns_modules/inspector_modules'] = '@nativescript/core/inspector_modules'; - } - - const compilerOptions = getCompilerOptionsFromTSConfig(tsConfigPath); - nsWebpack.processTsPathsForScopedModules({ compilerOptions }); - nsWebpack.processTsPathsForScopedAngular({ compilerOptions }); - - const ngCompilerTransformers = [nsTransformNativeClassesNg]; - const additionalLazyModuleResources = []; - - const copyIgnore = { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }; - const copyTargets = [{ from: { glob: 'assets/**', dot: false } }, { from: { glob: 'fonts/**', dot: false } }, ...copyReplacements]; - - if (!production) { - // for development purposes only - // for example, include mock json folder - // copyTargets.push({ from: 'tools/mockdata', to: 'assets/mockdata' }); - - if (hmr) { - ngCompilerTransformers.push(nsSupportHmrNg); - } - } - - // when "@angular/core" is external, it's not included in the bundles. In this way, it will be used - // directly from node_modules and the Angular modules loader won't be able to resolve the lazy routes - // fixes https://github.com/NativeScript/nativescript-cli/issues/4024 - if (env.externals && env.externals.indexOf('@angular/core') > -1) { - const appModuleRelativePath = getMainModulePath(resolve(appFullPath, entryModule), tsConfigName); - if (appModuleRelativePath) { - const appModuleFolderPath = dirname(resolve(appFullPath, appModuleRelativePath)); - // include the new lazy loader path in the allowed ones - additionalLazyModuleResources.push(appModuleFolderPath); - } - } - - const ngCompilerPlugin = new AngularCompilerPlugin({ - hostReplacementPaths: nsWebpack.getResolver([platform, 'tns']), - platformTransformers: ngCompilerTransformers.map((t) => t(() => ngCompilerPlugin, resolve(appFullPath, entryModule), projectRoot)), - mainPath: join(appFullPath, entryModule), - tsConfigPath, - skipCodeGeneration: false, - sourceMap: !!isAnySourceMapEnabled, - additionalLazyModuleResources: additionalLazyModuleResources, - compilerOptions: { paths: compilerOptions.paths }, - }); - - let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist); - - const itemsToClean = [`${dist}/**/*`]; - if (platform === 'android') { - itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'assets', 'snapshots')}`); - itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'build', 'configurations', 'nativescript-android-snapshot')}`); - } - - const noEmitOnErrorFromTSConfig = getNoEmitOnErrorFromTSConfig(tsConfigName); - - // Add your custom Activities, Services and other android app components here. - appComponents.push('@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity'); - - nsWebpack.processAppComponents(appComponents, platform); - const config = { - mode: production ? 'production' : 'development', - context: appFullPath, - externals, - watchOptions: { - ignored: [ - appResourcesFullPath, - // Don't watch hidden files - '**/.*', - ], - }, - target: nativescriptTarget, - entry: entries, - output: { - pathinfo: false, - path: dist, - sourceMapFilename, - libraryTarget: 'commonjs2', - filename: '[name].js', - globalObject: 'global', - hashSalt, - }, - resolve: { - extensions: ['.ts', '.js', '.scss', '.css'], - // Resolve {N} system modules from @nativescript/core - modules: [resolve(__dirname, 'node_modules/@nativescript/core'), resolve(__dirname, 'node_modules'), 'node_modules/@nativescript/core', 'node_modules'], - alias: { - '~/package.json': resolve(projectRoot, 'package.json'), - '~': appFullPath, - 'tns-core-modules': '@nativescript/core', - 'nativescript-angular': '@nativescript/angular', - ...fileReplacements, - }, - symlinks: true, - }, - resolveLoader: { - symlinks: false, - }, - node: { - // Disable node shims that conflict with NativeScript - http: false, - timers: false, - setImmediate: false, - fs: 'empty', - __dirname: false, - }, - devtool: hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none', - optimization: { - runtimeChunk: 'single', - noEmitOnErrors: noEmitOnErrorFromTSConfig, - splitChunks: { - cacheGroups: { - vendor: { - name: 'vendor', - chunks: 'all', - test: (module, chunks) => { - const moduleName = module.nameForCondition ? module.nameForCondition() : ''; - return /[\\/]node_modules[\\/]/.test(moduleName) || appComponents.some((comp) => comp === moduleName); - }, - enforce: true, - }, - }, - }, - minimize: !!uglify, - minimizer: [ - new TerserPlugin({ - parallel: true, - cache: !ci, - sourceMap: isAnySourceMapEnabled, - terserOptions: { - output: { - comments: false, - semicolons: !isAnySourceMapEnabled, - }, - compress: { - // The Android SBG has problems parsing the output - // when these options are enabled - collapse_vars: platform !== 'android', - sequences: platform !== 'android', - // For v8 Compatibility - keep_infinity: true, // for V8 - reduce_funcs: false, // for V8 - // custom - drop_console: production, - drop_debugger: true, - ecma: 6, - global_defs: { - __UGLIFIED__: true, - }, - }, - // Required for Element Level CSS, Observable Events, & Android Frame - keep_classnames: true, - // custom - ecma: 6, - safari10: platform !== 'android', - }, - }), - ], - }, - module: { - rules: [ - { - include: join(appFullPath, entryPath), - use: [ - // Require all Android app components - platform === 'android' && { - loader: '@nativescript/webpack/helpers/android-app-components-loader', - options: { modules: appComponents }, - }, - - { - loader: '@nativescript/webpack/bundle-config-loader', - options: { - angular: true, - loadCss: !snapshot, // load the application css if in debug mode - unitTesting, - appFullPath, - projectRoot, - ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform), - }, - }, - ].filter((loader) => !!loader), - }, - - { test: /\.html$|\.xml$/, use: 'raw-loader' }, - - { - test: /[\/|\\]app\.css$/, - use: [ - '@nativescript/webpack/helpers/style-hot-loader', - { - loader: '@nativescript/webpack/helpers/css2json-loader', - options: { useForImports: true }, - }, - ], - }, - { - test: /[\/|\\]app\.scss$/, - use: [ - '@nativescript/webpack/helpers/style-hot-loader', - { - loader: '@nativescript/webpack/helpers/css2json-loader', - options: { useForImports: true }, - }, - 'sass-loader', - ], - }, - - // Angular components reference css files and their imports using raw-loader - { test: /\.css$/, exclude: /[\/|\\]app\.css$/, use: 'raw-loader' }, - { - test: /\.scss$/, - exclude: /[\/|\\]app\.scss$/, - use: ['raw-loader', 'resolve-url-loader', 'sass-loader'], - }, - - { - test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/, - use: ['@nativescript/webpack/helpers/moduleid-compat-loader', '@nativescript/webpack/helpers/lazy-ngmodule-hot-loader', '@ngtools/webpack'], - }, - - // Mark files inside `@angular/core` as using SystemJS style dynamic imports. - // Removing this will cause deprecation warnings to appear. - { - test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/, - parser: { system: true }, - }, - ], - }, - plugins: [ - // Define useful constants like TNS_WEBPACK - new webpack.DefinePlugin({ - 'global.TNS_WEBPACK': 'true', - 'global.isAndroid': platform === 'android', - 'global.isIOS': platform === 'ios', - process: 'global.process', - }), - // Remove all files from the out dir. - new CleanWebpackPlugin({ - cleanOnceBeforeBuildPatterns: itemsToClean, - verbose: !!verbose, - }), - // Copy assets - new CopyWebpackPlugin([...copyTargets, { from: { glob: '**/*.jpg', dot: false } }, { from: { glob: '**/*.png', dot: false } }], copyIgnore), - new nsWebpack.GenerateNativeScriptEntryPointsPlugin('bundle'), - // For instructions on how to set up workers with webpack - // check out https://github.com/nativescript/worker-loader - new NativeScriptWorkerPlugin(), - ngCompilerPlugin, - // Does IPC communication with the {N} CLI to notify events when running in watch mode. - new nsWebpack.WatchStateLoggerPlugin(), - ], - }; - - if (report) { - // Generate report files for bundles content - config.plugins.push( - new BundleAnalyzerPlugin({ - analyzerMode: 'static', - openAnalyzer: false, - generateStatsFile: true, - reportFilename: resolve(projectRoot, 'report', `report.html`), - statsFilename: resolve(projectRoot, 'report', `stats.json`), - }) - ); - } - - if (snapshot) { - config.plugins.push( - new nsWebpack.NativeScriptSnapshotPlugin({ - chunk: 'vendor', - angular: true, - requireModules: ['reflect-metadata', '@angular/platform-browser', '@angular/core', '@angular/common', '@angular/router', '@nativescript/angular'], - projectRoot, - webpackConfig: config, - snapshotInDocker, - skipSnapshotTools, - useLibs, - }) - ); - } - - if (!production && hmr) { - config.plugins.push(new webpack.HotModuleReplacementPlugin()); - } - - return config; -}; diff --git a/packages/webpack/templates/webpack.config.spec.d.ts b/packages/webpack/templates/webpack.config.spec.d.ts deleted file mode 100644 index cb0ff5c3b..000000000 --- a/packages/webpack/templates/webpack.config.spec.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/packages/webpack/templates/webpack.config.spec.ts b/packages/webpack/templates/webpack.config.spec.ts deleted file mode 100644 index 84de508a4..000000000 --- a/packages/webpack/templates/webpack.config.spec.ts +++ /dev/null @@ -1,306 +0,0 @@ -import * as proxyquire from 'proxyquire'; -import * as nsWebpackIndex from '../index'; -import { join } from 'path'; -// With noCallThru enabled, `proxyquire` will not fall back to requiring the real module to populate properties that are not mocked. -// This allows us to mock packages that are not available in node_modules. -// In case you want to enable fallback for a specific object, just add `'@noCallThru': false`. -proxyquire.noCallThru(); - -class EmptyClass {} - -let angularCompilerOptions: any; -class AngularCompilerStub { - constructor(options) { - angularCompilerOptions = options; - } -} - -let terserOptions: any; -class TerserJsStub { - constructor(options) { - terserOptions = options; - } -} - -const nativeScriptDevWebpack = { - GenerateBundleStarterPlugin: EmptyClass, - GenerateNativeScriptEntryPointsPlugin: EmptyClass, - WatchStateLoggerPlugin: EmptyClass, - PlatformFSPlugin: EmptyClass, - getAppPath: () => 'app', - getEntryModule: () => 'EntryModule', - hasRootLevelScopedModules: () => false, - hasRootLevelScopedAngular: () => false, - processTsPathsForScopedModules: () => false, - processTsPathsForScopedAngular: () => false, - getResolver: () => null, - getConvertedExternals: nsWebpackIndex.getConvertedExternals, - getSourceMapFilename: nsWebpackIndex.getSourceMapFilename, - processAppComponents: nsWebpackIndex.processAppComponents, - getUserDefinedEntries: nsWebpackIndex.getUserDefinedEntries, -}; - -const emptyObject = {}; -const FakeHmrTransformerFlag = 'hmr'; -const FakeNativeClassTransformerFlag = 'NativeClass'; -const FakeLazyTransformerFlag = 'lazy'; -const webpackConfigAngular = proxyquire('./webpack.angular', { - '@nativescript/webpack': nativeScriptDevWebpack, - '@nativescript/webpack/nativescript-target': emptyObject, - '@nativescript/webpack/transformers/ns-support-hmr-ng': { - nsSupportHmrNg: () => { - return FakeHmrTransformerFlag; - }, - }, - '@nativescript/webpack/transformers/ns-transform-native-classes-ng': { - nsTransformNativeClassesNg: () => { - return FakeNativeClassTransformerFlag; - }, - }, - '@nativescript/webpack/helpers/angular-config-parser': { - parseWorkspaceConfig: (platform, envConfigs, rootPath = '') => { - return { - fileReplacements: {}, - copyReplacements: [], - }; - }, - hasConfigurations: (envConfigs) => { - return false; - }, - }, - '@nativescript/webpack/utils/ast-utils': { - getMainModulePath: () => { - return 'fakePath'; - }, - }, - '@nativescript/webpack/utils/tsconfig-utils': { - getNoEmitOnErrorFromTSConfig: () => { - return false; - }, - getCompilerOptionsFromTSConfig: () => { - return false; - }, - }, - '@nativescript/webpack/plugins/NativeScriptAngularCompilerPlugin': { - getAngularCompilerPlugin: () => { - return AngularCompilerStub; - }, - }, - '@ngtools/webpack': { - AngularCompilerPlugin: AngularCompilerStub, - }, - 'terser-webpack-plugin': TerserJsStub, -}); - -const webpackConfigTypeScript = proxyquire('./webpack.typescript', { - '@nativescript/webpack': nativeScriptDevWebpack, - '@nativescript/webpack/nativescript-target': emptyObject, - '@nativescript/webpack/transformers/ns-transform-native-classes': emptyObject, - '@nativescript/webpack/utils/tsconfig-utils': { - getNoEmitOnErrorFromTSConfig: () => { - return false; - }, - getCompilerOptionsFromTSConfig: () => { - return false; - }, - }, - 'terser-webpack-plugin': TerserJsStub, -}); - -const webpackConfigJavaScript = proxyquire('./webpack.javascript', { - '@nativescript/webpack': nativeScriptDevWebpack, - '@nativescript/webpack/nativescript-target': emptyObject, - 'terser-webpack-plugin': TerserJsStub, -}); - -const webpackConfigVue = proxyquire('./webpack.vue', { - '@nativescript/webpack': nativeScriptDevWebpack, - '@nativescript/webpack/nativescript-target': emptyObject, - '@nativescript/webpack/transformers/ns-transform-native-classes': emptyObject, - 'vue-loader/lib/plugin': EmptyClass, - 'nativescript-vue-template-compiler': emptyObject, - 'terser-webpack-plugin': TerserJsStub, -}); - -describe('webpack.config.js', () => { - const getInput = (options: { platform: string; hmr?: boolean; externals?: string[]; sourceMap?: boolean; hiddenSourceMap?: boolean | string }) => { - const input: any = Object.assign({}, options); - input[options.platform] = true; - return input; - }; - - [ - { type: 'javascript', webpackConfig: webpackConfigJavaScript }, - { type: 'typescript', webpackConfig: webpackConfigTypeScript }, - { type: 'angular', webpackConfig: webpackConfigAngular }, - { type: 'vue', webpackConfig: webpackConfigVue }, - ].forEach((element) => { - const { type, webpackConfig } = element; - ['android', 'ios'].forEach((platform) => { - describe(`verify externals for webpack.${type}.js (${platform})`, () => { - afterEach(() => { - nativeScriptDevWebpack.getConvertedExternals = nsWebpackIndex.getConvertedExternals; - }); - - it('returns empty array when externals are not passed', () => { - const input = getInput({ platform }); - const config = webpackConfig(input); - expect(config.externals).toEqual([]); - }); - - it('calls getConvertedExternals to convert externals', () => { - let isCalled = false; - nativeScriptDevWebpack.getConvertedExternals = () => { - isCalled = true; - return []; - }; - - const input = getInput({ platform, externals: ['nativescript-vue'] }); - webpackConfig(input); - expect(isCalled).toBe(true, 'Webpack.config.js must use the getConvertedExternals method'); - }); - - // if (platform === "ios") { - // it('has inspector_modules entry when tns-core-modules are not externals', () => { - // const input = getInput({ platform, externals: ['nativescript-vue'] }); - // const config = webpackConfig(input); - // expect(config.entry["tns_modules/@nativescript/core/inspector_modules"]).toEqual("inspector_modules"); - // }); - - // it('does not have inspector_modules entry when @nativescript/core are externals', () => { - // const input = getInput({ platform, externals: ['@nativescript'] }); - // const config = webpackConfig(input); - // expect(config.entry["tns_modules/@nativescript/core/inspector_modules"]).toBeUndefined(); - // }); - // } - - [ - { - input: ['nativescript-vue'], - expectedOutput: [/^nativescript-vue((\/.*)|$)/], - }, - { - input: ['nativescript-vue', 'nativescript-angular'], - expectedOutput: [/^nativescript-vue((\/.*)|$)/, /^nativescript-angular((\/.*)|$)/], - }, - ].forEach((testCase) => { - const input = getInput({ platform, externals: testCase.input }); - - it(`are correct regular expressions, for input ${testCase.input}`, () => { - const config = webpackConfig(input); - expect(config.externals).toEqual(testCase.expectedOutput); - }); - }); - }); - - if (type === 'angular') { - describe(`angular transformers for webpack.${type}.js (${platform})`, () => { - beforeEach(() => { - angularCompilerOptions = null; - }); - - it('should contain only NativeClass transformer by default', () => { - const input = getInput({ platform }); - - webpackConfig(input); - - expect(angularCompilerOptions).toBeDefined(); - expect(angularCompilerOptions.platformTransformers).toBeDefined(); - expect(angularCompilerOptions.platformTransformers.length).toEqual(1); - expect(angularCompilerOptions.platformTransformers[0]).toEqual(FakeNativeClassTransformerFlag); - }); - - it('should contain the HMR transformer when the HMR flag is passed', () => { - const input = getInput({ platform, hmr: true }); - - webpackConfig(input); - - expect(angularCompilerOptions).toBeDefined(); - expect(angularCompilerOptions.platformTransformers).toBeDefined(); - expect(angularCompilerOptions.platformTransformers.length).toEqual(2); - expect(angularCompilerOptions.platformTransformers[1]).toEqual(FakeHmrTransformerFlag); - }); - }); - } - - describe(`source map for webpack.${type}.js (${platform})`, () => { - beforeEach(() => { - terserOptions = null; - }); - - it('should not set source maps without the flag', () => { - const input = getInput({ platform, sourceMap: false }); - - const config = webpackConfig(input); - - expect(config.devtool).toEqual('none'); - expect(terserOptions.sourceMap).toBeFalsy(); - expect(terserOptions.terserOptions.output.semicolons).toBeTruthy(); - expect(config.output.sourceMapFilename).toEqual('[file].map'); - }); - - it('should set inline-source-map devtool', () => { - const input = getInput({ platform, sourceMap: true }); - - const config = webpackConfig(input); - - expect(config.devtool).toEqual('inline-source-map'); - expect(terserOptions.sourceMap).toBeTruthy(); - expect(terserOptions.terserOptions.output.semicolons).toBeFalsy(); - expect(config.output.sourceMapFilename).toEqual('[file].map'); - }); - }); - - describe(`hidden source map for webpack.${type}.js (${platform})`, () => { - beforeEach(() => { - terserOptions = null; - }); - - it('should not set source maps without the flag', () => { - const input = getInput({ platform, hiddenSourceMap: false }); - - const config = webpackConfig(input); - - expect(config.devtool).toEqual('none'); - expect(terserOptions.sourceMap).toBeFalsy(); - expect(terserOptions.terserOptions.output.semicolons).toBeTruthy(); - expect(config.output.sourceMapFilename).toEqual('[file].map'); - }); - - it('should set hidden-source-map devtool and the default sourceMap folder', () => { - const input = getInput({ platform, hiddenSourceMap: true }); - - const config = webpackConfig(input); - - expect(config.devtool).toEqual('hidden-source-map'); - expect(terserOptions.sourceMap).toBeTruthy(); - expect(terserOptions.terserOptions.output.semicolons).toBeFalsy(); - expect(config.output.sourceMapFilename).toEqual(join('..', 'sourceMap', '[file].map')); - }); - - it('should override the sourceMap property and the default sourceMap folder', () => { - const input = getInput({ platform, sourceMap: true, hiddenSourceMap: true }); - - const config = webpackConfig(input); - - expect(config.devtool).toEqual('hidden-source-map'); - expect(terserOptions.sourceMap).toBeTruthy(); - expect(terserOptions.terserOptions.output.semicolons).toBeFalsy(); - expect(config.output.sourceMapFilename).toEqual(join('..', 'sourceMap', '[file].map')); - }); - - it('should set hidden-source-map devtool and override the sourceMapFilename', () => { - const newSourceMapFolder = 'myCoolSourceMapFolder'; - const input = getInput({ platform, sourceMap: true, hiddenSourceMap: newSourceMapFolder }); - - const config = webpackConfig(input); - - expect(config.devtool).toEqual('hidden-source-map'); - expect(terserOptions.sourceMap).toBeTruthy(); - expect(terserOptions.terserOptions.output.semicolons).toBeFalsy(); - expect(config.output.sourceMapFilename).toEqual(join('..', newSourceMapFolder, '[file].map')); - }); - }); - }); - }); -}); diff --git a/packages/webpack/templates/webpack.javascript.js b/packages/webpack/templates/webpack.javascript.js deleted file mode 100644 index df1a3caf5..000000000 --- a/packages/webpack/templates/webpack.javascript.js +++ /dev/null @@ -1,293 +0,0 @@ -const { join, relative, resolve, sep } = require('path'); -const fs = require('fs'); - -const webpack = require('webpack'); -const nsWebpack = require('@nativescript/webpack'); -const nativescriptTarget = require('@nativescript/webpack/nativescript-target'); -const { CleanWebpackPlugin } = require('clean-webpack-plugin'); -const CopyWebpackPlugin = require('copy-webpack-plugin'); -const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); -const { NativeScriptWorkerPlugin } = require('nativescript-worker-loader/NativeScriptWorkerPlugin'); -const TerserPlugin = require('terser-webpack-plugin'); -const hashSalt = Date.now().toString(); - -module.exports = (env) => { - const platform = env && ((env.android && 'android') || (env.ios && 'ios') || env.platform); - if (!platform) { - throw new Error('You need to provide a target platform!'); - } - - const platforms = ['ios', 'android']; - const projectRoot = __dirname; - - if (env.platform) { - platforms.push(env.platform); - } - - // Default destination inside platforms//... - const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - - const { - // The 'appPath' and 'appResourcesPath' values are fetched from - // the nsconfig.json configuration file. - appPath = 'src', - appResourcesPath = 'App_Resources', - - // You can provide the following flags when running 'tns run android|ios' - snapshot, // --env.snapshot - production, // --env.production - uglify, // --env.uglify - report, // --env.report - sourceMap, // --env.sourceMap - hiddenSourceMap, // --env.hiddenSourceMap - hmr, // --env.hmr, - unitTesting, // --env.unitTesting, - testing, // --env.testing - verbose, // --env.verbose - snapshotInDocker, // --env.snapshotInDocker - skipSnapshotTools, // --env.skipSnapshotTools - ci, // --env.ci - compileSnapshot, // --env.compileSnapshot - appComponents = [], - entries = {}, - } = env; - - const useLibs = compileSnapshot; - const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap; - const externals = nsWebpack.getConvertedExternals(env.externals); - - let appFullPath = resolve(projectRoot, appPath); - if (!fs.existsSync(appFullPath)) { - // some apps use 'app' directory - appFullPath = resolve(projectRoot, 'app'); - } - const hasRootLevelScopedModules = nsWebpack.hasRootLevelScopedModules({ projectDir: projectRoot }); - let coreModulesPackageName = 'tns-core-modules'; - const alias = env.alias || {}; - alias['~/package.json'] = resolve(projectRoot, 'package.json'); - alias['~'] = appFullPath; - - if (hasRootLevelScopedModules) { - coreModulesPackageName = '@nativescript/core'; - alias['tns-core-modules'] = coreModulesPackageName; - } - const appResourcesFullPath = resolve(projectRoot, appResourcesPath); - - const copyIgnore = { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }; - - const entryModule = nsWebpack.getEntryModule(appFullPath, platform); - const entryPath = `.${sep}${entryModule}.js`; - Object.assign(entries, { bundle: entryPath }, entries); - - const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some((e) => e.indexOf('@nativescript') > -1); - if (platform === 'ios' && !areCoreModulesExternal && !testing) { - entries['tns_modules/inspector_modules'] = '@nativescript/core/inspector_modules'; - } - - let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist); - - const itemsToClean = [`${dist}/**/*`]; - if (platform === 'android') { - itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'assets', 'snapshots')}`); - itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'build', 'configurations', 'nativescript-android-snapshot')}`); - } - - // Add your custom Activities, Services and other android app components here. - appComponents.push('@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity'); - - nsWebpack.processAppComponents(appComponents, platform); - const config = { - mode: production ? 'production' : 'development', - context: appFullPath, - externals, - watchOptions: { - ignored: [ - appResourcesFullPath, - // Don't watch hidden files - '**/.*', - ], - }, - target: nativescriptTarget, - entry: entries, - output: { - pathinfo: false, - path: dist, - sourceMapFilename, - libraryTarget: 'commonjs2', - filename: '[name].js', - globalObject: 'global', - hashSalt, - }, - resolve: { - extensions: ['.js', '.scss', '.css'], - // Resolve {N} system modules from @nativescript/core - modules: [resolve(__dirname, `node_modules/${coreModulesPackageName}`), resolve(__dirname, 'node_modules'), `node_modules/${coreModulesPackageName}`, 'node_modules'], - alias, - // resolve symlinks to symlinked modules - symlinks: true, - }, - resolveLoader: { - // don't resolve symlinks to symlinked loaders - symlinks: false, - }, - node: { - // Disable node shims that conflict with NativeScript - http: false, - timers: false, - setImmediate: false, - fs: 'empty', - __dirname: false, - }, - devtool: hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none', - optimization: { - runtimeChunk: 'single', - noEmitOnErrors: true, - splitChunks: { - cacheGroups: { - vendor: { - name: 'vendor', - chunks: 'all', - test: (module, chunks) => { - const moduleName = module.nameForCondition ? module.nameForCondition() : ''; - return /[\\/]node_modules[\\/]/.test(moduleName) || appComponents.some((comp) => comp === moduleName); - }, - enforce: true, - }, - }, - }, - minimize: !!uglify, - minimizer: [ - new TerserPlugin({ - parallel: true, - cache: !ci, - sourceMap: isAnySourceMapEnabled, - terserOptions: { - output: { - comments: false, - semicolons: !isAnySourceMapEnabled, - }, - compress: { - // The Android SBG has problems parsing the output - // when these options are enabled - collapse_vars: platform !== 'android', - sequences: platform !== 'android', - // For v8 Compatibility - keep_infinity: true, // for V8 - reduce_funcs: false, // for V8 - // custom - drop_console: production, - drop_debugger: true, - global_defs: { - __UGLIFIED__: true, - }, - }, - // Required for Element Level CSS, Observable Events, & Android Frame - keep_classnames: true, - }, - }), - ], - }, - module: { - rules: [ - { - include: join(appFullPath, entryPath), - use: [ - // Require all Android app components - platform === 'android' && { - loader: '@nativescript/webpack/helpers/android-app-components-loader', - options: { modules: appComponents }, - }, - - { - loader: '@nativescript/webpack/bundle-config-loader', - options: { - loadCss: !snapshot, // load the application css if in debug mode - unitTesting, - appFullPath, - projectRoot, - ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform), - }, - }, - ].filter((loader) => !!loader), - }, - - { - test: /\.(js|css|scss|html|xml)$/, - use: '@nativescript/webpack/hmr/hot-loader', - }, - - { test: /\.(html|xml)$/, use: '@nativescript/webpack/helpers/xml-namespace-loader' }, - - { - test: /\.css$/, - use: '@nativescript/webpack/helpers/css2json-loader', - }, - - { - test: /\.scss$/, - use: ['@nativescript/webpack/helpers/css2json-loader', 'sass-loader'], - }, - ], - }, - plugins: [ - // Define useful constants like TNS_WEBPACK - new webpack.DefinePlugin({ - 'global.TNS_WEBPACK': 'true', - 'global.isAndroid': platform === 'android', - 'global.isIOS': platform === 'ios', - process: 'global.process', - }), - // Remove all files from the out dir. - new CleanWebpackPlugin({ - cleanOnceBeforeBuildPatterns: itemsToClean, - verbose: !!verbose, - }), - // Copy assets - new CopyWebpackPlugin([{ from: { glob: 'assets/**', dot: false } }, { from: { glob: 'fonts/**', dot: false } }, { from: { glob: '**/*.jpg', dot: false } }, { from: { glob: '**/*.png', dot: false } }], copyIgnore), - new nsWebpack.GenerateNativeScriptEntryPointsPlugin('bundle'), - - // For instructions on how to set up workers with webpack - // check out https://github.com/nativescript/worker-loader - new NativeScriptWorkerPlugin(), - new nsWebpack.PlatformFSPlugin({ - platform, - platforms, - }), - // Does IPC communication with the {N} CLI to notify events when running in watch mode. - new nsWebpack.WatchStateLoggerPlugin(), - ], - }; - - if (report) { - // Generate report files for bundles content - config.plugins.push( - new BundleAnalyzerPlugin({ - analyzerMode: 'static', - openAnalyzer: false, - generateStatsFile: true, - reportFilename: resolve(projectRoot, 'report', `report.html`), - statsFilename: resolve(projectRoot, 'report', `stats.json`), - }) - ); - } - - if (snapshot) { - config.plugins.push( - new nsWebpack.NativeScriptSnapshotPlugin({ - chunk: 'vendor', - requireModules: ['@nativescript/core/bundle-entry-points'], - projectRoot, - webpackConfig: config, - snapshotInDocker, - skipSnapshotTools, - useLibs, - }) - ); - } - - if (hmr) { - config.plugins.push(new webpack.HotModuleReplacementPlugin()); - } - - return config; -}; diff --git a/packages/webpack/templates/webpack.react.js b/packages/webpack/templates/webpack.react.js deleted file mode 100644 index ebd0f4d52..000000000 --- a/packages/webpack/templates/webpack.react.js +++ /dev/null @@ -1,87 +0,0 @@ -/** - * @see https://github.com/NativeScript/NativeScript/tree/feat/ns7-finishing-touches/packages/webpack/templates - * @see https://github.com/NativeScript/NativeScript/pull/8801/files - */ -const webpackConfig = require('./webpack.typescript'); -const webpack = require('webpack'); -const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'); - -module.exports = (env) => { - env = env || {}; - const hmr = env.hmr; - const production = env.production; - const isAnySourceMapEnabled = !!env.sourceMap || !!env.hiddenSourceMap; - - const baseConfig = webpackConfig(env); - - /** Find the rule for transpiling ts files ("ts-loader"), and modify it to test for .tsx files too. */ - const tsxRule = baseConfig.module.rules.find((rule) => rule.use && rule.use.loader === 'ts-loader'); - tsxRule.test = /\.(ts|tsx)$/; - tsxRule.use = [ - /** - * Add React Refresh HMR support. - * @see https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/55028c6355b31e697e21bf3e9a48613a7b94bee7/examples/typescript-without-babel/webpack.config.js#L18-L21 - */ - hmr && - !production && { - loader: 'babel-loader', - options: { - sourceMaps: isAnySourceMapEnabled ? 'inline' : false, - babelrc: false, - plugins: ['react-refresh/babel'], - }, - }, - tsxRule.use, - ].filter(Boolean); - - /** - * Modify "nativescript-dev-webpack/hmr/hot-loader" to test for .tsx files - * (and also js files, which it should have been doing to begin with!) - */ - const nativeScriptDevWebpackHotLoader = baseConfig.module.rules.find((rule) => rule.use === '@nativescript/webpack/hmr/hot-loader'); - nativeScriptDevWebpackHotLoader.test = /\.(ts|tsx|js|css|scss|html|xml)$/; - - /** We don't officially support JSX. Makes the webpack config rather more complicated to set up. */ - baseConfig.resolve.extensions = ['.tsx', ...baseConfig.resolve.extensions]; - baseConfig.resolve.alias['react-dom'] = 'react-nativescript'; - - /** Augment NativeScript's existing DefinePlugin definitions with a few more of our own. */ - const existingDefinePlugin = baseConfig.plugins.find((plugin) => plugin && plugin.constructor && plugin.constructor.name === 'DefinePlugin'); - baseConfig.plugins.splice( - baseConfig.plugins.indexOf(existingDefinePlugin), - 1, - new webpack.DefinePlugin({ - ...existingDefinePlugin.definitions, - /** For various libraries in the React ecosystem. */ - __DEV__: production ? 'false' : 'true', - __TEST__: 'false', - /** - * Primarily for React Fast Refresh plugin, but technically the allowHmrInProduction option could be used instead. - * Worth including anyway, as there are plenty of Node libraries that use this flag. - */ - 'process.env.NODE_ENV': JSON.stringify(production ? 'production' : 'development'), - }) - ); - - if (hmr && !production) { - baseConfig.plugins.push( - new ReactRefreshWebpackPlugin({ - /** - * Maybe one day we'll implement an Error Overlay, but the work involved is too daunting for now. - * @see https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/79#issuecomment-644324557 - */ - overlay: false, - /** - * If you (temporarily) want to enable HMR on a production build: - * 1) Set `forceEnable` to `true` - * 2) Remove the `!production` condition on `tsxRule` to ensure that babel-loader gets used. - */ - forceEnable: false, - }) - ); - } else { - baseConfig.plugins = baseConfig.plugins.filter((p) => !(p && p.constructor && p.constructor.name === 'HotModuleReplacementPlugin')); - } - - return baseConfig; -}; diff --git a/packages/webpack/templates/webpack.svelte.js b/packages/webpack/templates/webpack.svelte.js deleted file mode 100644 index 756de7d8b..000000000 --- a/packages/webpack/templates/webpack.svelte.js +++ /dev/null @@ -1,356 +0,0 @@ -const { join, relative, resolve, sep } = require('path'); -const fs = require('fs'); - -const webpack = require('webpack'); -const nsWebpack = require('@nativescript/webpack'); -const nativescriptTarget = require('@nativescript/webpack/nativescript-target'); -const { getNoEmitOnErrorFromTSConfig } = require('@nativescript/webpack/utils/tsconfig-utils'); -const { CleanWebpackPlugin } = require('clean-webpack-plugin'); -const CopyWebpackPlugin = require('copy-webpack-plugin'); -const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); -const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); -const { NativeScriptWorkerPlugin } = require('nativescript-worker-loader/NativeScriptWorkerPlugin'); -const TerserPlugin = require('terser-webpack-plugin'); -const hashSalt = Date.now().toString(); -const preprocessConfig = require('./svelte.config.js'); -const svelteNativePreprocessor = require('svelte-native-preprocessor'); - -module.exports = (env) => { - const platform = env && ((env.android && 'android') || (env.ios && 'ios') || env.platform); - if (!platform) { - throw new Error('You need to provide a target platform!'); - } - - const platforms = ['ios', 'android']; - const projectRoot = __dirname; - - if (env.platform) { - platforms.push(env.platform); - } - - // Default destination inside platforms//... - const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - - const { - // The 'appPath' and 'appResourcesPath' values are fetched from - // the nsconfig.json configuration file. - appPath = 'src', - appResourcesPath = 'App_Resources', - - // You can provide the following flags when running 'tns run android|ios' - snapshot, // --env.snapshot - production, // --env.production - uglify, // --env.uglify - report, // --env.report - sourceMap, // --env.sourceMap - hiddenSourceMap, // --env.hiddenSourceMap - hmr, // --env.hmr, - unitTesting, // --env.unitTesting, - testing, // --env.testing - verbose, // --env.verbose - ci, // --env.ci - snapshotInDocker, // --env.snapshotInDocker - skipSnapshotTools, // --env.skipSnapshotTools - compileSnapshot, // --env.compileSnapshot - appComponents = [], - entries = {}, - } = env; - - const useLibs = compileSnapshot; - const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap; - const externals = nsWebpack.getConvertedExternals(env.externals); - - let appFullPath = resolve(projectRoot, appPath); - if (!fs.existsSync(appFullPath)) { - // some apps use 'app' directory - appFullPath = resolve(projectRoot, 'app'); - } - const hasRootLevelScopedModules = nsWebpack.hasRootLevelScopedModules({ projectDir: projectRoot }); - let coreModulesPackageName = 'tns-core-modules'; - const alias = env.alias || {}; - alias['~/package.json'] = resolve(projectRoot, 'package.json'); - alias['~'] = appFullPath; - - if (hasRootLevelScopedModules) { - coreModulesPackageName = '@nativescript/core'; - alias['tns-core-modules'] = coreModulesPackageName; - } - const appResourcesFullPath = resolve(projectRoot, appResourcesPath); - - const copyIgnore = { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }; - - const entryModule = nsWebpack.getEntryModule(appFullPath, platform); - const entryPath = `.${sep}${entryModule}.ts`; - Object.assign(entries, { bundle: entryPath }, entries); - - const tsConfigPath = resolve(projectRoot, 'tsconfig.json'); - - const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some((e) => e.indexOf('@nativescript') > -1); - if (platform === 'ios' && !areCoreModulesExternal && !testing) { - entries['tns_modules/inspector_modules'] = '@nativescript/core/inspector_modules'; - } - - let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist); - - const itemsToClean = [`${dist}/**/*`]; - if (platform === 'android') { - itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'assets', 'snapshots')}`); - itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'build', 'configurations', 'nativescript-android-snapshot')}`); - } - - const noEmitOnErrorFromTSConfig = getNoEmitOnErrorFromTSConfig(tsConfigPath); - - // Add your custom Activities, Services and other android app components here. - appComponents.push('@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity'); - - nsWebpack.processAppComponents(appComponents, platform); - const config = { - mode: production ? 'production' : 'development', - context: appFullPath, - externals, - watchOptions: { - ignored: [ - appResourcesFullPath, - // Don't watch hidden files - '**/.*', - ], - }, - target: nativescriptTarget, - entry: entries, - output: { - pathinfo: false, - path: dist, - sourceMapFilename, - libraryTarget: 'commonjs2', - filename: '[name].js', - globalObject: 'global', - hashSalt, - }, - resolve: { - extensions: ['.ts', '.mjs', '.js', '.svelte', '.scss', '.css'], - // Resolve {N} system modules from @nativescript/core - modules: [resolve(__dirname, `node_modules/${coreModulesPackageName}`), resolve(__dirname, 'node_modules'), `node_modules/${coreModulesPackageName}`, 'node_modules'], - alias, - // resolve symlinks to symlinked modules - symlinks: true, - }, - resolveLoader: { - // don't resolve symlinks to symlinked loaders - symlinks: false, - }, - node: { - // Disable node shims that conflict with NativeScript - http: false, - timers: false, - setImmediate: false, - fs: 'empty', - __dirname: false, - }, - devtool: hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none', - optimization: { - runtimeChunk: 'single', - noEmitOnErrors: noEmitOnErrorFromTSConfig, - splitChunks: { - cacheGroups: { - vendor: { - name: 'vendor', - chunks: 'all', - test: (module, chunks) => { - const moduleName = module.nameForCondition ? module.nameForCondition() : ''; - return /[\\/]node_modules[\\/]/.test(moduleName) || appComponents.some((comp) => comp === moduleName); - }, - enforce: true, - }, - }, - }, - minimize: !!uglify, - minimizer: [ - new TerserPlugin({ - parallel: true, - cache: !ci, - sourceMap: isAnySourceMapEnabled, - terserOptions: { - output: { - comments: false, - semicolons: !isAnySourceMapEnabled, - }, - compress: { - // The Android SBG has problems parsing the output - // when these options are enabled - collapse_vars: platform !== 'android', - sequences: platform !== 'android', - // For v8 Compatibility - keep_infinity: true, // for V8 - reduce_funcs: false, // for V8 - // custom - drop_console: production, - drop_debugger: true, - global_defs: { - __UGLIFIED__: true, - }, - }, - // Required for Element Level CSS, Observable Events, & Android Frame - keep_classnames: true, - }, - }), - ], - }, - module: { - rules: [ - { - include: join(appFullPath, entryPath), - use: [ - // Require all Android app components - platform === 'android' && { - loader: '@nativescript/webpack/helpers/android-app-components-loader', - options: { modules: appComponents }, - }, - - { - loader: '@nativescript/webpack/bundle-config-loader', - options: { - loadCss: !snapshot, // load the application css if in debug mode - unitTesting, - appFullPath, - projectRoot, - ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform), - }, - }, - ].filter((loader) => !!loader), - }, - - { - test: /\.(ts|css|scss|html|xml)$/, - use: '@nativescript/webpack/hmr/hot-loader', - }, - - { test: /\.(html|xml)$/, use: '@nativescript/webpack/helpers/xml-namespace-loader' }, - - { - test: /\.css$/, - use: '@nativescript/webpack/helpers/css2json-loader', - }, - - { - test: /\.scss$/, - use: ['@nativescript/webpack/helpers/css2json-loader', 'sass-loader'], - }, - - { - test: /\.mjs$/, - type: 'javascript/auto', - }, - { - test: /\.ts$/, - use: { - loader: 'ts-loader', - options: { - configFile: tsConfigPath, - // https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#faster-builds - // https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#hot-module-replacement - transpileOnly: true, - allowTsInNodeModules: true, - compilerOptions: { - sourceMap: isAnySourceMapEnabled, - declaration: false, - }, - getCustomTransformers: (program) => ({ - before: [require('@nativescript/webpack/transformers/ns-transform-native-classes').default], - }), - }, - }, - }, - { - test: /\.svelte$/, - exclude: /node_modules/, - use: [ - { - loader: 'svelte-loader-hot', - options: { - dev: env.production ? false : true, - preprocess: [preprocessConfig.preprocess, svelteNativePreprocessor()], - hotReload: env.production ? false : true, - hotOptions: { - injectCss: false, - native: true, - }, - }, - }, - ], - }, - ], - }, - plugins: [ - // Define useful constants like TNS_WEBPACK - new webpack.DefinePlugin({ - 'global.TNS_WEBPACK': 'true', - 'global.isAndroid': platform === 'android', - 'global.isIOS': platform === 'ios', - process: 'global.process', - }), - // Remove all files from the out dir. - new CleanWebpackPlugin({ - cleanOnceBeforeBuildPatterns: itemsToClean, - verbose: !!verbose, - }), - // Copy assets - new CopyWebpackPlugin([{ from: { glob: 'assets/**', dot: false } }, { from: { glob: 'fonts/**', dot: false } }, { from: { glob: '**/*.jpg', dot: false } }, { from: { glob: '**/*.png', dot: false } }], copyIgnore), - new nsWebpack.GenerateNativeScriptEntryPointsPlugin('bundle'), - // For instructions on how to set up workers with webpack - // check out https://github.com/nativescript/worker-loader - new NativeScriptWorkerPlugin(), - new nsWebpack.PlatformFSPlugin({ - platform, - platforms, - }), - // Does IPC communication with the {N} CLI to notify events when running in watch mode. - new nsWebpack.WatchStateLoggerPlugin(), - // https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#faster-builds - // https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#hot-module-replacement - new ForkTsCheckerWebpackPlugin({ - async: false, - typescript: { - configFile: tsConfigPath, - memoryLimit: 4096, - diagnosticOptions: { - syntactic: true, - semantic: true, - }, - }, - }), - ], - }; - - if (report) { - // Generate report files for bundles content - config.plugins.push( - new BundleAnalyzerPlugin({ - analyzerMode: 'static', - openAnalyzer: false, - generateStatsFile: true, - reportFilename: resolve(projectRoot, 'report', `report.html`), - statsFilename: resolve(projectRoot, 'report', `stats.json`), - }) - ); - } - - if (snapshot) { - config.plugins.push( - new nsWebpack.NativeScriptSnapshotPlugin({ - chunk: 'vendor', - requireModules: ['@nativescript/core/bundle-entry-points'], - projectRoot, - webpackConfig: config, - snapshotInDocker, - skipSnapshotTools, - useLibs, - }) - ); - } - - if (hmr) { - config.plugins.push(new webpack.HotModuleReplacementPlugin()); - } - - return config; -}; diff --git a/packages/webpack/templates/webpack.typescript.js b/packages/webpack/templates/webpack.typescript.js deleted file mode 100644 index 379ca48c2..000000000 --- a/packages/webpack/templates/webpack.typescript.js +++ /dev/null @@ -1,332 +0,0 @@ -const { join, relative, resolve, sep } = require('path'); -const fs = require('fs'); - -const webpack = require('webpack'); -const nsWebpack = require('@nativescript/webpack'); -const nativescriptTarget = require('@nativescript/webpack/nativescript-target'); -const { getNoEmitOnErrorFromTSConfig } = require('@nativescript/webpack/utils/tsconfig-utils'); -const { CleanWebpackPlugin } = require('clean-webpack-plugin'); -const CopyWebpackPlugin = require('copy-webpack-plugin'); -const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); -const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); -const { NativeScriptWorkerPlugin } = require('nativescript-worker-loader/NativeScriptWorkerPlugin'); -const TerserPlugin = require('terser-webpack-plugin'); -const hashSalt = Date.now().toString(); - -module.exports = (env) => { - const platform = env && ((env.android && 'android') || (env.ios && 'ios') || env.platform); - if (!platform) { - throw new Error('You need to provide a target platform!'); - } - - const platforms = ['ios', 'android']; - const projectRoot = __dirname; - - if (env.platform) { - platforms.push(env.platform); - } - - // Default destination inside platforms//... - const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - - const { - // The 'appPath' and 'appResourcesPath' values are fetched from - // the nsconfig.json configuration file. - appPath = 'src', - appResourcesPath = 'App_Resources', - - // You can provide the following flags when running 'tns run android|ios' - snapshot, // --env.snapshot - production, // --env.production - uglify, // --env.uglify - report, // --env.report - sourceMap, // --env.sourceMap - hiddenSourceMap, // --env.hiddenSourceMap - hmr, // --env.hmr, - unitTesting, // --env.unitTesting, - testing, // --env.testing - verbose, // --env.verbose - ci, // --env.ci - snapshotInDocker, // --env.snapshotInDocker - skipSnapshotTools, // --env.skipSnapshotTools - compileSnapshot, // --env.compileSnapshot - appComponents = [], - entries = {}, - } = env; - - const useLibs = compileSnapshot; - const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap; - const externals = nsWebpack.getConvertedExternals(env.externals); - - let appFullPath = resolve(projectRoot, appPath); - if (!fs.existsSync(appFullPath)) { - // some apps use 'app' directory - appFullPath = resolve(projectRoot, 'app'); - } - const hasRootLevelScopedModules = nsWebpack.hasRootLevelScopedModules({ projectDir: projectRoot }); - let coreModulesPackageName = 'tns-core-modules'; - const alias = env.alias || {}; - alias['~/package.json'] = resolve(projectRoot, 'package.json'); - alias['~'] = appFullPath; - - if (hasRootLevelScopedModules) { - coreModulesPackageName = '@nativescript/core'; - alias['tns-core-modules'] = coreModulesPackageName; - } - const appResourcesFullPath = resolve(projectRoot, appResourcesPath); - - const copyIgnore = { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }; - - const entryModule = nsWebpack.getEntryModule(appFullPath, platform); - const entryPath = `.${sep}${entryModule}.ts`; - Object.assign(entries, { bundle: entryPath }, entries); - - const tsConfigPath = resolve(projectRoot, 'tsconfig.json'); - - const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some((e) => e.indexOf('@nativescript') > -1); - if (platform === 'ios' && !areCoreModulesExternal && !testing) { - entries['tns_modules/inspector_modules'] = '@nativescript/core/inspector_modules'; - } - - let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist); - - const itemsToClean = [`${dist}/**/*`]; - if (platform === 'android') { - itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'assets', 'snapshots')}`); - itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'build', 'configurations', 'nativescript-android-snapshot')}`); - } - - const noEmitOnErrorFromTSConfig = getNoEmitOnErrorFromTSConfig(tsConfigPath); - - // Add your custom Activities, Services and other android app components here. - appComponents.push('@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity'); - - nsWebpack.processAppComponents(appComponents, platform); - const config = { - mode: production ? 'production' : 'development', - context: appFullPath, - externals, - watchOptions: { - ignored: [ - appResourcesFullPath, - // Don't watch hidden files - '**/.*', - ], - }, - target: nativescriptTarget, - entry: entries, - output: { - pathinfo: false, - path: dist, - sourceMapFilename, - libraryTarget: 'commonjs2', - filename: '[name].js', - globalObject: 'global', - hashSalt, - }, - resolve: { - extensions: ['.ts', '.js', '.scss', '.css'], - // Resolve {N} system modules from @nativescript/core - modules: [resolve(__dirname, `node_modules/${coreModulesPackageName}`), resolve(__dirname, 'node_modules'), `node_modules/${coreModulesPackageName}`, 'node_modules'], - alias, - // resolve symlinks to symlinked modules - symlinks: true, - }, - resolveLoader: { - // don't resolve symlinks to symlinked loaders - symlinks: false, - }, - node: { - // Disable node shims that conflict with NativeScript - http: false, - timers: false, - setImmediate: false, - fs: 'empty', - __dirname: false, - }, - devtool: hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none', - optimization: { - runtimeChunk: 'single', - noEmitOnErrors: noEmitOnErrorFromTSConfig, - splitChunks: { - cacheGroups: { - vendor: { - name: 'vendor', - chunks: 'all', - test: (module, chunks) => { - const moduleName = module.nameForCondition ? module.nameForCondition() : ''; - return /[\\/]node_modules[\\/]/.test(moduleName) || appComponents.some((comp) => comp === moduleName); - }, - enforce: true, - }, - }, - }, - minimize: !!uglify, - minimizer: [ - new TerserPlugin({ - parallel: true, - cache: !ci, - sourceMap: isAnySourceMapEnabled, - terserOptions: { - output: { - comments: false, - semicolons: !isAnySourceMapEnabled, - }, - compress: { - // The Android SBG has problems parsing the output - // when these options are enabled - collapse_vars: platform !== 'android', - sequences: platform !== 'android', - // For v8 Compatibility - keep_infinity: true, // for V8 - reduce_funcs: false, // for V8 - // custom - drop_console: production, - drop_debugger: true, - global_defs: { - __UGLIFIED__: true, - }, - }, - // Required for Element Level CSS, Observable Events, & Android Frame - keep_classnames: true, - }, - }), - ], - }, - module: { - rules: [ - { - include: join(appFullPath, entryPath), - use: [ - // Require all Android app components - platform === 'android' && { - loader: '@nativescript/webpack/helpers/android-app-components-loader', - options: { modules: appComponents }, - }, - - { - loader: '@nativescript/webpack/bundle-config-loader', - options: { - loadCss: !snapshot, // load the application css if in debug mode - unitTesting, - appFullPath, - projectRoot, - ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform), - }, - }, - ].filter((loader) => !!loader), - }, - - { - test: /\.(ts|css|scss|html|xml)$/, - use: '@nativescript/webpack/hmr/hot-loader', - }, - - { test: /\.(html|xml)$/, use: '@nativescript/webpack/helpers/xml-namespace-loader' }, - - { - test: /\.css$/, - use: '@nativescript/webpack/helpers/css2json-loader', - }, - - { - test: /\.scss$/, - use: ['@nativescript/webpack/helpers/css2json-loader', 'sass-loader'], - }, - - { - test: /\.ts$/, - use: { - loader: 'ts-loader', - options: { - configFile: tsConfigPath, - // https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#faster-builds - // https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#hot-module-replacement - transpileOnly: true, - allowTsInNodeModules: true, - compilerOptions: { - sourceMap: isAnySourceMapEnabled, - declaration: false, - }, - getCustomTransformers: (program) => ({ - before: [require('@nativescript/webpack/transformers/ns-transform-native-classes').default], - }), - }, - }, - }, - ], - }, - plugins: [ - // Define useful constants like TNS_WEBPACK - new webpack.DefinePlugin({ - 'global.TNS_WEBPACK': 'true', - 'global.isAndroid': platform === 'android', - 'global.isIOS': platform === 'ios', - process: 'global.process', - }), - // Remove all files from the out dir. - new CleanWebpackPlugin({ - cleanOnceBeforeBuildPatterns: itemsToClean, - verbose: !!verbose, - }), - // Copy assets - new CopyWebpackPlugin([{ from: { glob: 'assets/**', dot: false } }, { from: { glob: 'fonts/**', dot: false } }, { from: { glob: '**/*.jpg', dot: false } }, { from: { glob: '**/*.png', dot: false } }], copyIgnore), - new nsWebpack.GenerateNativeScriptEntryPointsPlugin('bundle'), - // For instructions on how to set up workers with webpack - // check out https://github.com/nativescript/worker-loader - new NativeScriptWorkerPlugin(), - new nsWebpack.PlatformFSPlugin({ - platform, - platforms, - }), - // Does IPC communication with the {N} CLI to notify events when running in watch mode. - new nsWebpack.WatchStateLoggerPlugin(), - // https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#faster-builds - // https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#hot-module-replacement - new ForkTsCheckerWebpackPlugin({ - async: false, - typescript: { - configFile: tsConfigPath, - memoryLimit: 4096, - diagnosticOptions: { - syntactic: true, - semantic: true, - }, - }, - }), - ], - }; - - if (report) { - // Generate report files for bundles content - config.plugins.push( - new BundleAnalyzerPlugin({ - analyzerMode: 'static', - openAnalyzer: false, - generateStatsFile: true, - reportFilename: resolve(projectRoot, 'report', `report.html`), - statsFilename: resolve(projectRoot, 'report', `stats.json`), - }) - ); - } - - if (snapshot) { - config.plugins.push( - new nsWebpack.NativeScriptSnapshotPlugin({ - chunk: 'vendor', - requireModules: ['@nativescript/core/bundle-entry-points'], - projectRoot, - webpackConfig: config, - snapshotInDocker, - skipSnapshotTools, - useLibs, - }) - ); - } - - if (hmr) { - config.plugins.push(new webpack.HotModuleReplacementPlugin()); - } - - return config; -}; diff --git a/packages/webpack/templates/webpack.vue.js b/packages/webpack/templates/webpack.vue.js deleted file mode 100644 index cfcf64a73..000000000 --- a/packages/webpack/templates/webpack.vue.js +++ /dev/null @@ -1,357 +0,0 @@ -const { join, relative, resolve, sep } = require('path'); - -const webpack = require('webpack'); -const { CleanWebpackPlugin } = require('clean-webpack-plugin'); -const CopyWebpackPlugin = require('copy-webpack-plugin'); -const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); -const TerserPlugin = require('terser-webpack-plugin'); - -const VueLoaderPlugin = require('vue-loader/lib/plugin'); -const NsVueTemplateCompiler = require('nativescript-vue-template-compiler'); - -const nsWebpack = require('@nativescript/webpack'); -const nativescriptTarget = require('@nativescript/webpack/nativescript-target'); -const { NativeScriptWorkerPlugin } = require('nativescript-worker-loader/NativeScriptWorkerPlugin'); -const hashSalt = Date.now().toString(); - -module.exports = (env) => { - const platform = env && ((env.android && 'android') || (env.ios && 'ios') || env.platform); - if (!platform) { - throw new Error('You need to provide a target platform!'); - } - - const platforms = ['ios', 'android']; - const projectRoot = __dirname; - - if (env.platform) { - platforms.push(env.platform); - } - - // Default destination inside platforms//... - const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); - - const { - // The 'appPath' and 'appResourcesPath' values are fetched from - // the nsconfig.json configuration file. - appPath = 'app', - appResourcesPath = 'app/App_Resources', - - // You can provide the following flags when running 'tns run android|ios' - snapshot, // --env.snapshot - production, // --env.production - report, // --env.report - hmr, // --env.hmr - sourceMap, // --env.sourceMap - hiddenSourceMap, // --env.hiddenSourceMap - unitTesting, // --env.unitTesting - testing, // --env.testing - verbose, // --env.verbose - ci, // --env.ci - snapshotInDocker, // --env.snapshotInDocker - skipSnapshotTools, // --env.skipSnapshotTools - compileSnapshot, // --env.compileSnapshot - appComponents = [], - entries = {}, - } = env; - - const useLibs = compileSnapshot; - const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap; - const externals = nsWebpack.getConvertedExternals(env.externals); - - const mode = production ? 'production' : 'development'; - - const appFullPath = resolve(projectRoot, appPath); - const hasRootLevelScopedModules = nsWebpack.hasRootLevelScopedModules({ projectDir: projectRoot }); - let coreModulesPackageName = 'tns-core-modules'; - const alias = env.alias || {}; - alias['~/package.json'] = resolve(projectRoot, 'package.json'); - alias['~'] = appFullPath; - alias['@'] = appFullPath; - alias['vue'] = 'nativescript-vue'; - - if (hasRootLevelScopedModules) { - coreModulesPackageName = '@nativescript/core'; - alias['tns-core-modules'] = coreModulesPackageName; - } - - const appResourcesFullPath = resolve(projectRoot, appResourcesPath); - - const copyIgnore = { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }; - - const entryModule = nsWebpack.getEntryModule(appFullPath, platform); - const entryPath = `.${sep}${entryModule}`; - Object.assign(entries, { bundle: entryPath }, entries); - - const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some((e) => e.indexOf('@nativescript') > -1); - if (platform === 'ios' && !areCoreModulesExternal && !testing) { - entries['tns_modules/inspector_modules'] = '@nativescript/core/inspector_modules'; - } - console.log(`Bundling application for entryPath ${entryPath}...`); - - let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist); - - const itemsToClean = [`${dist}/**/*`]; - if (platform === 'android') { - itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'assets', 'snapshots')}`); - itemsToClean.push(`${join(projectRoot, 'platforms', 'android', 'app', 'build', 'configurations', 'nativescript-android-snapshot')}`); - } - - // Add your custom Activities, Services and other android app components here. - appComponents.push('@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity'); - - nsWebpack.processAppComponents(appComponents, platform); - const config = { - mode: mode, - context: appFullPath, - externals, - watchOptions: { - ignored: [ - appResourcesFullPath, - // Don't watch hidden files - '**/.*', - ], - }, - target: nativescriptTarget, - // target: nativeScriptVueTarget, - entry: entries, - output: { - pathinfo: false, - path: dist, - sourceMapFilename, - libraryTarget: 'commonjs2', - filename: '[name].js', - globalObject: 'global', - hashSalt, - }, - resolve: { - extensions: ['.vue', '.ts', '.js', '.scss', '.css'], - // Resolve {N} system modules from @nativescript/core - modules: [resolve(__dirname, `node_modules/${coreModulesPackageName}`), resolve(__dirname, 'node_modules'), `node_modules/${coreModulesPackageName}`, 'node_modules'], - alias, - // resolve symlinks to symlinked modules - symlinks: true, - }, - resolveLoader: { - // don't resolve symlinks to symlinked loaders - symlinks: false, - }, - node: { - // Disable node shims that conflict with NativeScript - http: false, - timers: false, - setImmediate: false, - fs: 'empty', - __dirname: false, - }, - devtool: hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none', - optimization: { - runtimeChunk: 'single', - noEmitOnErrors: true, - splitChunks: { - cacheGroups: { - vendor: { - name: 'vendor', - chunks: 'all', - test: (module) => { - const moduleName = module.nameForCondition ? module.nameForCondition() : ''; - return /[\\/]node_modules[\\/]/.test(moduleName) || appComponents.some((comp) => comp === moduleName); - }, - enforce: true, - }, - }, - }, - minimize: Boolean(production), - minimizer: [ - new TerserPlugin({ - parallel: true, - cache: !ci, - sourceMap: isAnySourceMapEnabled, - terserOptions: { - output: { - comments: false, - semicolons: !isAnySourceMapEnabled, - }, - compress: { - // The Android SBG has problems parsing the output - // when these options are enabled - collapse_vars: platform !== 'android', - sequences: platform !== 'android', - // For v8 Compatibility - keep_infinity: true, // for V8 - reduce_funcs: false, // for V8 - // custom - drop_console: production, - drop_debugger: true, - global_defs: { - __UGLIFIED__: true, - }, - }, - keep_fnames: true, - // Required for Element Level CSS, Observable Events, & Android Frame - keep_classnames: true, - }, - }), - ], - }, - module: { - rules: [ - { - include: [join(appFullPath, entryPath + '.js'), join(appFullPath, entryPath + '.ts')], - use: [ - // Require all Android app components - platform === 'android' && { - loader: '@nativescript/webpack/helpers/android-app-components-loader', - options: { modules: appComponents }, - }, - - { - loader: '@nativescript/webpack/bundle-config-loader', - options: { - registerPages: true, // applicable only for non-angular apps - loadCss: !snapshot, // load the application css if in debug mode - unitTesting, - appFullPath, - projectRoot, - ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform), - }, - }, - ].filter((loader) => Boolean(loader)), - }, - { - test: /[\/|\\]app\.css$/, - use: [ - '@nativescript/webpack/helpers/style-hot-loader', - { - loader: '@nativescript/webpack/helpers/css2json-loader', - options: { useForImports: true }, - }, - ], - }, - { - test: /[\/|\\]app\.scss$/, - use: [ - '@nativescript/webpack/helpers/style-hot-loader', - { - loader: '@nativescript/webpack/helpers/css2json-loader', - options: { useForImports: true }, - }, - 'sass-loader', - ], - }, - { - test: /\.css$/, - exclude: /[\/|\\]app\.css$/, - use: ['@nativescript/webpack/helpers/style-hot-loader', '@nativescript/webpack/helpers/apply-css-loader.js', { loader: 'css-loader', options: { url: false } }], - }, - { - test: /\.scss$/, - exclude: /[\/|\\]app\.scss$/, - use: ['@nativescript/webpack/helpers/style-hot-loader', '@nativescript/webpack/helpers/apply-css-loader.js', { loader: 'css-loader', options: { url: false } }, 'sass-loader'], - }, - { - test: /\.js$/, - loader: 'babel-loader', - }, - { - test: /\.ts$/, - loader: 'ts-loader', - options: { - appendTsSuffixTo: [/\.vue$/], - allowTsInNodeModules: true, - compilerOptions: { - declaration: false, - }, - getCustomTransformers: (program) => ({ - before: [require('@nativescript/webpack/transformers/ns-transform-native-classes').default], - }), - }, - }, - { - test: /\.vue$/, - loader: 'vue-loader', - options: { - compiler: NsVueTemplateCompiler, - }, - }, - ], - }, - plugins: [ - // ... Vue Loader plugin omitted - // make sure to include the plugin! - new VueLoaderPlugin(), - // Define useful constants like TNS_WEBPACK - new webpack.DefinePlugin({ - 'global.TNS_WEBPACK': 'true', - 'global.isAndroid': platform === 'android', - 'global.isIOS': platform === 'ios', - TNS_ENV: JSON.stringify(mode), - process: 'global.process', - }), - // Remove all files from the out dir. - new CleanWebpackPlugin({ - cleanOnceBeforeBuildPatterns: itemsToClean, - verbose: !!verbose, - }), - // Copy assets - new CopyWebpackPlugin([{ from: { glob: 'assets/**', dot: false } }, { from: { glob: 'fonts/**', dot: false } }, { from: { glob: '**/*.jpg', dot: false } }, { from: { glob: '**/*.png', dot: false } }], copyIgnore), - new nsWebpack.GenerateNativeScriptEntryPointsPlugin('bundle'), - // For instructions on how to set up workers with webpack - // check out https://github.com/nativescript/worker-loader - new NativeScriptWorkerPlugin(), - new nsWebpack.PlatformFSPlugin({ - platform, - platforms, - }), - // Does IPC communication with the {N} CLI to notify events when running in watch mode. - new nsWebpack.WatchStateLoggerPlugin(), - ], - }; - - if (unitTesting) { - config.module.rules.push( - { - test: /-page\.js$/, - use: '@nativescript/webpack/helpers/script-hot-loader', - }, - { - test: /\.(html|xml)$/, - use: '@nativescript/webpack/helpers/markup-hot-loader', - }, - - { test: /\.(html|xml)$/, use: '@nativescript/webpack/helpers/xml-namespace-loader' } - ); - } - - if (report) { - // Generate report files for bundles content - config.plugins.push( - new BundleAnalyzerPlugin({ - analyzerMode: 'static', - openAnalyzer: false, - generateStatsFile: true, - reportFilename: resolve(projectRoot, 'report', `report.html`), - statsFilename: resolve(projectRoot, 'report', `stats.json`), - }) - ); - } - - if (snapshot) { - config.plugins.push( - new nsWebpack.NativeScriptSnapshotPlugin({ - chunk: 'vendor', - requireModules: ['@nativescript/core/bundle-entry-points'], - projectRoot, - webpackConfig: config, - snapshotInDocker, - skipSnapshotTools, - useLibs, - }) - ); - } - - if (hmr) { - config.plugins.push(new webpack.HotModuleReplacementPlugin()); - } - - return config; -}; diff --git a/packages/webpack/transformers/ns-support-hmr-ng.d.ts b/packages/webpack/transformers/ns-support-hmr-ng.d.ts deleted file mode 100644 index 9170a93c6..000000000 --- a/packages/webpack/transformers/ns-support-hmr-ng.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import * as ts from 'typescript'; -import { TransformOperation } from '@ngtools/webpack/src/transformers'; -import { AngularCompilerPlugin } from '@ngtools/webpack'; -export declare function nsSupportHmrNg(getNgCompiler: () => AngularCompilerPlugin, entryPath: string): ts.TransformerFactory; -export declare function handleHmrSupport(mainFile: ts.SourceFile): TransformOperation[]; -export declare const GeneratedDynamicAppOptions = "options_Generated"; -export declare function getHmrOptionsCode(appModuleName: string, appModulePath: string): string; -export declare function getAcceptMainModuleCode(mainModulePath: string): string; diff --git a/packages/webpack/transformers/ns-support-hmr-ng.spec.d.ts b/packages/webpack/transformers/ns-support-hmr-ng.spec.d.ts deleted file mode 100644 index cb0ff5c3b..000000000 --- a/packages/webpack/transformers/ns-support-hmr-ng.spec.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/packages/webpack/transformers/ns-support-hmr-ng.spec.ts b/packages/webpack/transformers/ns-support-hmr-ng.spec.ts deleted file mode 100644 index f504b1973..000000000 --- a/packages/webpack/transformers/ns-support-hmr-ng.spec.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { tags } from '@angular-devkit/core'; -import { createTypescriptContext, transformTypescript } from '@ngtools/webpack/src/transformers/spec_helpers'; -import { nsSupportHmrNg, getHmrOptionsCode, getAcceptMainModuleCode, GeneratedDynamicAppOptions } from './ns-support-hmr-ng'; -import { AngularCompilerPlugin } from '@ngtools/webpack'; - -describe('@ngtools/webpack transformers', () => { - describe('ns-support-hmr-ng', () => { - const nsFactoryImportName = `__NgCli_bootstrap_2_1`; - const handleHmrPlatformDynamicImport = `import * as nativescript_angular_platform_Generated from "@nativescript/angular";`; - const handleHmrPlatformStaticImport = `import * as nativescript_angular_platform_Generated from "@nativescript/angular";`; - const handleAotPlatformStaticImport = `import * as __NgCli_bootstrap_1_1 from "@nativescript/angular";`; - const handleAotNgFactoryImport = `import * as ${nsFactoryImportName} from "./test-file.ts.ngfactory";`; - const handleHmrOptionsDeclaration = `var ${GeneratedDynamicAppOptions} = {};`; - const nsStaticPlatformCall = `nativescript_angular_platform_Generated.platformNativeScript`; - const nsDynamicPlatformCall = `nativescript_angular_platform_Generated.platformNativeScriptDynamic`; - const handleHmrOptionsCode = getHmrOptionsCode('AppModule', './app/app.module'); - const acceptMainModuleCode = getAcceptMainModuleCode('./app/app.module'); - const handleHmrOptionsAotCode = getHmrOptionsCode('AppModuleNgFactory', './test-file.ts.ngfactory'); - const acceptMainModuleAotCode = getAcceptMainModuleCode('./test-file.ts.ngfactory'); - const getAppOptions = (currentAppOptionsString?: string) => { - return `Object.assign(${currentAppOptionsString || '{}'}, ${GeneratedDynamicAppOptions})`; - }; - const defaultAppOptions = getAppOptions(); - const testCases = [ - { - name: 'should not handle HMR when the AppModule import cannot be found', - rawFile: ` - import { platformNativeScript } from "@nativescript/angular"; - platformNativeScript().bootstrapModule(SyntaxErrorModule); - `, - transformedFile: ` - import { platformNativeScript } from "@nativescript/angular"; - platformNativeScript().bootstrapModule(SyntaxErrorModule); - `, - transformedFileWithAot: ` - import { platformNativeScript } from "@nativescript/angular"; - platformNativeScript().bootstrapModule(SyntaxErrorModule); - `, - }, - ]; - testCases.forEach((testCase: any) => { - it(`${testCase.name}`, async () => { - const testFile = '/project/src/test-file.ts'; - const input = tags.stripIndent`${testCase.rawFile}`; - const output = tags.stripIndent`${testCase.transformedFile}`; - const { program, compilerHost } = createTypescriptContext(input); - const ngCompiler = { - typeChecker: program.getTypeChecker(), - entryModule: { - path: testFile, - className: 'AppModule', - }, - }; - const transformer = nsSupportHmrNg(() => ngCompiler, testFile); - const result = transformTypescript(undefined, [transformer], program, compilerHost); - - expect(tags.oneLine`${result}`).toEqual(tags.oneLine`${output}`); - }); - - it(`${testCase.name} (in combination with AOT transformer)`, async () => { - const projectDir = '/project/src/'; - const testFile = `${projectDir}test-file.ts`; - const input = tags.stripIndent`${testCase.rawFile}`; - const output = tags.stripIndent`${testCase.transformedFileWithAot}`; - const { program, compilerHost } = createTypescriptContext(input); - const ngCompiler = { - typeChecker: program.getTypeChecker(), - entryModule: { - path: testFile, - className: testCase.customAppModuleName || 'AppModule', - }, - }; - - const hmrTransformer = nsSupportHmrNg(() => ngCompiler, testFile); - const result = transformTypescript(undefined, [hmrTransformer], program, compilerHost); - - expect(tags.oneLine`${result}`).toEqual(tags.oneLine`${output}`); - }); - }); - }); -}); diff --git a/packages/webpack/transformers/ns-support-hmr-ng.ts b/packages/webpack/transformers/ns-support-hmr-ng.ts deleted file mode 100644 index 26ea98668..000000000 --- a/packages/webpack/transformers/ns-support-hmr-ng.ts +++ /dev/null @@ -1,103 +0,0 @@ -import { normalize } from 'path'; -import * as ts from 'typescript'; -import { AddNodeOperation, ReplaceNodeOperation, StandardTransform, TransformOperation, collectDeepNodes, makeTransform, insertStarImport } from '@ngtools/webpack/src/transformers'; -import { AngularCompilerPlugin } from '@ngtools/webpack'; -import { findBootstrappedModulePathInSource, findNativeScriptPlatformPathInSource, findBootstrapModuleCallInSource, findNativeScriptPlatformCallInSource, getExpressionName } from '../utils/ast-utils'; - -export function nsSupportHmrNg(getNgCompiler: () => AngularCompilerPlugin, entryPath: string): ts.TransformerFactory { - const standardTransform: StandardTransform = function (sourceFile: ts.SourceFile) { - let ops: TransformOperation[] = []; - - if (!entryPath || normalize(sourceFile.fileName) !== normalize(entryPath)) { - return ops; - } - - try { - ops = handleHmrSupport(sourceFile); - } catch (e) { - ops = []; - } - - return ops; - }; - - return makeTransform(standardTransform, () => getNgCompiler().typeChecker); -} - -export function handleHmrSupport(mainFile: ts.SourceFile): TransformOperation[] { - const importNodesInFile = collectDeepNodes(mainFile, ts.SyntaxKind.ImportDeclaration); - if (!importNodesInFile || !importNodesInFile.length) { - return []; - } - - const bootstrapModuleCallNode = findBootstrapModuleCallInSource(mainFile); - if (!bootstrapModuleCallNode || !bootstrapModuleCallNode.arguments || !bootstrapModuleCallNode.arguments.length) { - return []; - } - - const appModuleName = getExpressionName(bootstrapModuleCallNode.arguments[0]); - const nativeScriptPlatformCallNode = findNativeScriptPlatformCallInSource(mainFile); - if (!nativeScriptPlatformCallNode || !nativeScriptPlatformCallNode.arguments) { - return []; - } - - return handleHmrSupportCore(mainFile, importNodesInFile, appModuleName, nativeScriptPlatformCallNode); -} - -function handleHmrSupportCore(mainFile: ts.SourceFile, importNodesInFile: ts.Node[], appModuleName: string, nativeScriptPlatformCallNode: ts.CallExpression) { - const firstImportNode = importNodesInFile[0]; - const lastImportNode = importNodesInFile[importNodesInFile.length - 1]; - const appModulePath = findBootstrappedModulePathInSource(mainFile); - if (!appModuleName || !appModulePath) { - return []; - } - - let currentAppOptionsInitializationNode: ts.Expression = ts.createObjectLiteral(); - if (nativeScriptPlatformCallNode.arguments.length > 0) { - currentAppOptionsInitializationNode = nativeScriptPlatformCallNode.arguments[0]; - } - - const optionsDeclaration = ts.createVariableDeclaration(GeneratedDynamicAppOptions, undefined, ts.createObjectLiteral()); - const optionsDeclarationList = ts.createVariableDeclarationList([optionsDeclaration]); - const optionsStatement = ts.createVariableStatement(undefined, optionsDeclarationList); - - const setHmrOptionsNode = ts.createIdentifier(getHmrOptionsCode(appModuleName, appModulePath)); - - const acceptHmrNode = ts.createIdentifier(getAcceptMainModuleCode(appModulePath)); - - const objectAssignNode = ts.createPropertyAccess(ts.createIdentifier('Object'), ts.createIdentifier('assign')); - const extendAppOptionsNode = ts.createCall(objectAssignNode, undefined, [currentAppOptionsInitializationNode, ts.createIdentifier(GeneratedDynamicAppOptions)]); - - const newNsDynamicCallArgs = ts.createNodeArray([extendAppOptionsNode, ...nativeScriptPlatformCallNode.arguments.slice(1)]); - const nsPlatformPath = findNativeScriptPlatformPathInSource(mainFile); - const nsPlatformText = getExpressionName(nativeScriptPlatformCallNode.expression); - const newNsDynamicCallNode = ts.createCall(ts.createPropertyAccess(ts.createIdentifier(NsNgPlatformStarImport), ts.createIdentifier(nsPlatformText)), [], newNsDynamicCallArgs); - - return [...insertStarImport(mainFile, ts.createIdentifier(NsNgPlatformStarImport), nsPlatformPath, firstImportNode, true), new AddNodeOperation(mainFile, lastImportNode, undefined, optionsStatement), new AddNodeOperation(mainFile, lastImportNode, undefined, setHmrOptionsNode), new AddNodeOperation(mainFile, lastImportNode, undefined, acceptHmrNode), new ReplaceNodeOperation(mainFile, nativeScriptPlatformCallNode, newNsDynamicCallNode)]; -} - -export const GeneratedDynamicAppOptions = 'options_Generated'; -const NsNgPlatformStarImport = 'nativescript_angular_platform_Generated'; - -export function getHmrOptionsCode(appModuleName: string, appModulePath: string) { - return ` -if (module["hot"]) { - ${GeneratedDynamicAppOptions} = { - hmrOptions: { - moduleTypeFactory: function () { return require("${appModulePath}").${appModuleName}; }, - livesyncCallback: function (platformReboot) { setTimeout(platformReboot, 0); } - } - }; -} -`; -} - -export function getAcceptMainModuleCode(mainModulePath: string) { - return ` -if (module["hot"]) { - module["hot"].accept(["${mainModulePath}"], function () { - global["hmrRefresh"]({}); - }); -} -`; -} diff --git a/packages/webpack/transformers/ns-transform-native-classes-ng.d.ts b/packages/webpack/transformers/ns-transform-native-classes-ng.d.ts deleted file mode 100644 index 1e200c3a6..000000000 --- a/packages/webpack/transformers/ns-transform-native-classes-ng.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { AngularCompilerPlugin } from '@ngtools/webpack'; -export declare function nsTransformNativeClassesNg(acp: AngularCompilerPlugin): any; diff --git a/packages/webpack/transformers/ns-transform-native-classes-ng.ts b/packages/webpack/transformers/ns-transform-native-classes-ng.ts deleted file mode 100644 index 9e8b610b6..000000000 --- a/packages/webpack/transformers/ns-transform-native-classes-ng.ts +++ /dev/null @@ -1,7 +0,0 @@ -import * as ts from 'typescript'; -import { AngularCompilerPlugin } from '@ngtools/webpack'; -const nsTransformNativeClasses = require('./ns-transform-native-classes'); - -export function nsTransformNativeClassesNg(acp: AngularCompilerPlugin) { - return nsTransformNativeClasses.default; -} diff --git a/packages/webpack/transformers/ns-transform-native-classes.d.ts b/packages/webpack/transformers/ns-transform-native-classes.d.ts deleted file mode 100644 index 22a9c158d..000000000 --- a/packages/webpack/transformers/ns-transform-native-classes.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import * as ts from 'typescript'; -export default function (ctx: ts.TransformationContext): (source: ts.SourceFile) => ts.SourceFile; diff --git a/packages/webpack/transformers/ns-transform-native-classes.ts b/packages/webpack/transformers/ns-transform-native-classes.ts deleted file mode 100644 index ff46cc44e..000000000 --- a/packages/webpack/transformers/ns-transform-native-classes.ts +++ /dev/null @@ -1,30 +0,0 @@ -import * as ts from 'typescript'; - -export default function (ctx: ts.TransformationContext) { - function isNativeClassExtension(node: ts.ClassDeclaration) { - return ( - node.decorators && - node.decorators.filter((d) => { - const fullText = d.getFullText().trim(); - return fullText.indexOf('@NativeClass') > -1; - }).length > 0 - ); - } - function visitNode(node: ts.Node): ts.Node { - if (ts.isClassDeclaration(node) && isNativeClassExtension(node)) { - return createHelper(node); - } - return ts.visitEachChild(node, visitNode, ctx); - } - - function createHelper(node: ts.Node) { - // we remove the decorator for now! - return ts.createIdentifier( - ts.transpileModule(node.getText().replace(/@NativeClass(\((.|\n)*?\))?/gm, ''), { - compilerOptions: { noEmitHelpers: true, module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES5 }, - }).outputText.replace(/(Object\.defineProperty\(.*?{.*?)(enumerable:\s*false)(.*?}\))/gs, '$1enumerable: true$3') - ); - } - - return (source: ts.SourceFile) => ts.updateSourceFileNode(source, ts.visitNodes(source.statements, visitNode)); -} diff --git a/packages/webpack/tsconfig.json b/packages/webpack/tsconfig.json deleted file mode 100644 index 391dd6b87..000000000 --- a/packages/webpack/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compilerOptions": { - "rootDir": ".", - "target": "es2015", - "module": "commonjs", - "declaration": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "lib": [ "es2017" ], - "sourceMap": true, - "skipLibCheck": true, - "skipDefaultLibCheck": true, - "diagnostics": true, - "baseUrl": "." - }, - "exclude": [ - "node_modules", - "demo" - ] -} diff --git a/packages/webpack/unit-testing-config-loader.js b/packages/webpack/unit-testing-config-loader.js deleted file mode 100644 index 67318a7bf..000000000 --- a/packages/webpack/unit-testing-config-loader.js +++ /dev/null @@ -1,46 +0,0 @@ -const { join, relative } = require("path"); -const { existsSync } = require("fs"); -const { convertSlashesInPath } = require("./helpers/projectHelpers"); - -function getRunnerFullPath(projectRoot) { - const runnerRootPath = join(projectRoot, "node_modules", "@nativescript/unit-test-runner"); - const runnerAppPath = join(runnerRootPath, "app"); - const result = existsSync(runnerAppPath) ? runnerAppPath : runnerRootPath; - - return result; -} - -module.exports = function ({ appFullPath, projectRoot, angular, rootPagesRegExp }) { - // TODO: Consider to use the files property from karma.conf.js - const testFilesRegExp = /tests\/.*\.(ts|js)/; - const runnerFullPath = getRunnerFullPath(projectRoot); - const runnerRelativePath = convertSlashesInPath(relative(appFullPath, runnerFullPath)); - const appCssFilePath = convertSlashesInPath(join(runnerRelativePath, "app.css")); - let source = ` - require("@nativescript/core/bundle-entry-points"); - const runnerContext = require.context("${runnerRelativePath}", true, ${rootPagesRegExp}); - global.registerWebpackModules(runnerContext); - global.registerModule("${appCssFilePath}", () => require("${appCssFilePath}")); - require("@nativescript/core").Application.setCssFileName("${appCssFilePath}"); - `; - - if (angular) { - source += ` - const context = require.context("~/", true, ${testFilesRegExp}); - global.registerWebpackModules(context); - `; - } else { - const registerModules = new RegExp(`(${rootPagesRegExp.source})|(${testFilesRegExp.source})`); - source += ` - const context = require.context("~/", true, ${registerModules}); - global.registerWebpackModules(context); - `; - } - - const runnerEntryPointPath = convertSlashesInPath(join(runnerRelativePath, "bundle-app.js")); - source += ` - require("${runnerEntryPointPath}"); - `; - - return source; -} \ No newline at end of file diff --git a/packages/webpack/utils/ast-utils.d.ts b/packages/webpack/utils/ast-utils.d.ts deleted file mode 100644 index 660aa21d5..000000000 --- a/packages/webpack/utils/ast-utils.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as ts from 'typescript'; -export declare function getMainModulePath(entryFilePath: string, tsConfigName: string): string; -export declare function findBootstrapModuleCall(mainPath: string): ts.CallExpression | null; -export declare function findBootstrapModuleCallInSource(source: ts.SourceFile): ts.CallExpression | null; -export declare function findNativeScriptPlatformCallInSource(source: ts.SourceFile): ts.CallExpression | null; -export declare function findMethodCallInSource(source: ts.SourceFile, methodName: string): ts.CallExpression | null; -export declare function findBootstrappedModulePath(mainPath: string): string; -export declare function findBootstrappedModulePathInSource(source: ts.SourceFile): string; -export declare function findNativeScriptPlatformPathInSource(source: ts.SourceFile): string; -export declare function getAppModulePath(mainPath: string): string; -export declare function findIdentifierNode(node: ts.Node, text: string): ts.Node | null; -export declare function getObjectPropertyMatches(objectNode: ts.ObjectLiteralExpression, sourceFile: ts.SourceFile, targetPropertyName: string): ts.ObjectLiteralElement[]; -export declare function getDecoratorMetadata(source: ts.SourceFile, identifier: string, module: string): ts.Node[]; -export declare function angularImportsFromNode(node: ts.ImportDeclaration, _sourceFile: ts.SourceFile): { - [name: string]: string; -}; -export declare function getExpressionName(expression: ts.Expression): string; diff --git a/packages/webpack/utils/ast-utils.ts b/packages/webpack/utils/ast-utils.ts deleted file mode 100644 index c49c83e65..000000000 --- a/packages/webpack/utils/ast-utils.ts +++ /dev/null @@ -1,298 +0,0 @@ -// inspired by: -// https://github.com/angular/angular-cli/blob/d202480a1707be6575b2c8cf0383cfe6db44413c/packages/schematics/angular/utility/ast-utils.ts -// https://github.com/angular/angular-cli/blob/d202480a1707be6575b2c8cf0383cfe6db44413c/packages/schematics/angular/utility/ng-ast-utils.ts -// https://github.com/NativeScript/nativescript-schematics/blob/438b9e3ef613389980bfa9d071e28ca1f32ab04f/src/ast-utils.ts - -// important notes: -// 1) DO NOT USE `null` when building nodes or you will get `Cannot read property 'transformFlags' of null` -// https://github.com/Microsoft/TypeScript/issues/22372#issuecomment-371221056 -// 2) DO NOT USE `node.getText()` or `node.getFullText()` while analyzing the AST - it is trying to read -// the text from the source file and if the node is affected by another transformer, it will lead to -// an unexpected behavior. You can use `identifier.text` instead. -// 3) DO NOT USE `node.parent` while analyzing the AST. It will be null when the node is replaced by -// another transformer and will lead to an exception. Take a look at `findMethodCallInSource` for an -// example of a working workaround by searching for content in each parent. -// 4) Always test your transformer both single and in combinations with the other ones. - -import { dirname, join, relative } from 'path'; -import * as ts from 'typescript'; -import { readFileSync, existsSync } from 'fs'; -import { collectDeepNodes } from '@ngtools/webpack/src/transformers'; -import { getCompilerOptionsFromTSConfig } from './tsconfig-utils'; - -export function getMainModulePath(entryFilePath: string, tsConfigName: string) { - try { - // backwards compatibility - tsConfigName = tsConfigName || 'tsconfig.tns.json'; - - const tsModuleName = findBootstrappedModulePath(entryFilePath); - const result = tsResolve(tsModuleName, entryFilePath, tsConfigName); - - return result; - } catch (e) { - return null; - } -} - -/** - * Returns the real path to the ts/d.ts of the specified `moduleName` relative to the specified `containingFilePath`. (e.g. `~/app/file` -> `./app/file.ts`) - * @param moduleName The name of the module to be resolved (e.g. `~/config.js`, `lodash`, `./already-relative.js`, `@custom-path/file`). - * @param containingFilePath An absolute path to the file where the `moduleName` is imported. The relative result will be based on this file. - * @param tsConfigName The name of the tsconfig which will be used during the module resolution (e.g. `tsconfig.json`). - * We need this config in order to get its compiler options into account (e.g. resolve any custom `paths` like `~` or `@src`). - */ -function tsResolve(moduleName: string, containingFilePath: string, tsConfigName: string) { - let result = moduleName; - try { - const moduleResolutionHost: ts.ModuleResolutionHost = { - fileExists: ts.sys.fileExists, - readFile: ts.sys.readFile, - }; - - const compilerOptions = getCompilerOptionsFromTSConfig(tsConfigName); - - const resolutionResult = ts.resolveModuleName(moduleName, containingFilePath, compilerOptions, moduleResolutionHost); - - if (resolutionResult && resolutionResult.resolvedModule && resolutionResult.resolvedModule.resolvedFileName) { - result = relative(dirname(containingFilePath), resolutionResult.resolvedModule.resolvedFileName); - } - } catch (err) {} - - return result; -} - -export function findBootstrapModuleCall(mainPath: string): ts.CallExpression | null { - const source = getSourceFile(mainPath); - - return findBootstrapModuleCallInSource(source); -} - -export function findBootstrapModuleCallInSource(source: ts.SourceFile): ts.CallExpression | null { - return findMethodCallInSource(source, 'bootstrapModule') || findMethodCallInSource(source, 'bootstrapModuleFactory'); -} -export function findNativeScriptPlatformCallInSource(source: ts.SourceFile): ts.CallExpression | null { - return findMethodCallInSource(source, 'platformNativeScriptDynamic') || findMethodCallInSource(source, 'platformNativeScript'); -} - -export function findMethodCallInSource(source: ts.SourceFile, methodName: string): ts.CallExpression | null { - const allMethodCalls = collectDeepNodes(source, ts.SyntaxKind.CallExpression); - let methodCallNode: ts.CallExpression | null = null; - - for (const callNode of allMethodCalls) { - const currentMethodName = getExpressionName(callNode.expression); - if (methodName === currentMethodName) { - methodCallNode = callNode; - } - } - - return methodCallNode; -} - -export function findBootstrappedModulePath(mainPath: string): string { - const source = getSourceFile(mainPath); - - return findBootstrappedModulePathInSource(source); -} - -export function findBootstrappedModulePathInSource(source: ts.SourceFile): string { - const bootstrapCall = findBootstrapModuleCallInSource(source); - if (!bootstrapCall) { - throw new Error('Bootstrap call not found'); - } - - const appModulePath = getExpressionImportPath(source, bootstrapCall.arguments[0]); - - return appModulePath; -} - -export function findNativeScriptPlatformPathInSource(source: ts.SourceFile): string { - const nsPlatformCall = findNativeScriptPlatformCallInSource(source); - if (!nsPlatformCall) { - throw new Error('NativeScriptPlatform call not found'); - } - - const nsPlatformImportPath = getExpressionImportPath(source, nsPlatformCall.expression); - - return nsPlatformImportPath; -} - -function getImportPathInSource(source: ts.SourceFile, importName: string) { - const allImports = collectDeepNodes(source, ts.SyntaxKind.ImportDeclaration); - const importPath = allImports - .filter((imp) => { - return findIdentifierNode(imp, importName); - }) - .map((imp: ts.ImportDeclaration) => { - const modulePathStringLiteral = imp.moduleSpecifier as ts.StringLiteral; - return modulePathStringLiteral.text; - })[0]; - return importPath; -} - -export function getAppModulePath(mainPath: string): string { - const moduleRelativePath = findBootstrappedModulePath(mainPath); - const mainDir = dirname(mainPath); - const modulePath = join(mainDir, `${moduleRelativePath}.ts`); - - return modulePath; -} - -export function findIdentifierNode(node: ts.Node, text: string): ts.Node | null { - if (node.kind === ts.SyntaxKind.Identifier && (node).text === text) { - return node; - } - - let foundNode: ts.Node | null = null; - ts.forEachChild(node, (childNode) => { - foundNode = foundNode || findIdentifierNode(childNode, text); - }); - - return foundNode; -} - -export function getObjectPropertyMatches(objectNode: ts.ObjectLiteralExpression, sourceFile: ts.SourceFile, targetPropertyName: string): ts.ObjectLiteralElement[] { - return objectNode.properties - .filter((prop) => prop.kind == ts.SyntaxKind.PropertyAssignment) - .filter((prop: ts.PropertyAssignment) => { - const name = prop.name; - switch (name.kind) { - case ts.SyntaxKind.Identifier: - return (name as ts.Identifier).text == targetPropertyName; - case ts.SyntaxKind.StringLiteral: - return (name as ts.StringLiteral).text == targetPropertyName; - } - return false; - }); -} - -export function getDecoratorMetadata(source: ts.SourceFile, identifier: string, module: string): ts.Node[] { - const angularImports: { [name: string]: string } = collectDeepNodes(source, ts.SyntaxKind.ImportDeclaration) - .map((node: ts.ImportDeclaration) => angularImportsFromNode(node, source)) - .reduce((acc: { [name: string]: string }, current: { [name: string]: string }) => { - for (const key of Object.keys(current)) { - acc[key] = current[key]; - } - - return acc; - }, {}); - - return collectDeepNodes(source, ts.SyntaxKind.Decorator) - .filter((node) => { - return (node as ts.Decorator).expression.kind == ts.SyntaxKind.CallExpression; - }) - .map((node) => (node as ts.Decorator).expression as ts.CallExpression) - .filter((expr) => { - if (expr.expression.kind == ts.SyntaxKind.Identifier) { - const id = expr.expression as ts.Identifier; - - return id.getFullText(source) == identifier && angularImports[id.getFullText(source)] === module; - } else if (expr.expression.kind == ts.SyntaxKind.PropertyAccessExpression) { - // This covers foo.NgModule when importing * as foo. - const paExpr = expr.expression as ts.PropertyAccessExpression; - // If the left expression is not an identifier, just give up at that point. - if (paExpr.expression.kind !== ts.SyntaxKind.Identifier) { - return false; - } - - const id = paExpr.name.text; - const moduleId = (paExpr.expression as ts.Identifier).text; - - return id === identifier && angularImports[moduleId + '.'] === module; - } - - return false; - }) - .filter((expr) => expr.arguments[0] && (expr.arguments[0].kind == ts.SyntaxKind.ObjectLiteralExpression || expr.arguments[0].kind == ts.SyntaxKind.Identifier)) - .map((expr) => expr.arguments[0] as ts.Node); -} - -export function angularImportsFromNode(node: ts.ImportDeclaration, _sourceFile: ts.SourceFile): { [name: string]: string } { - const ms = node.moduleSpecifier; - let modulePath: string; - switch (ms.kind) { - case ts.SyntaxKind.StringLiteral: - modulePath = (ms as ts.StringLiteral).text; - break; - default: - return {}; - } - - if (!modulePath.startsWith('@angular/')) { - return {}; - } - - if (node.importClause) { - if (node.importClause.name) { - // This is of the form `import Name from 'path'`. Ignore. - return {}; - } else if (node.importClause.namedBindings) { - const nb = node.importClause.namedBindings; - if (nb.kind == ts.SyntaxKind.NamespaceImport) { - // This is of the form `import * as name from 'path'`. Return `name.`. - return { - [(nb as ts.NamespaceImport).name.text + '.']: modulePath, - }; - } else { - // This is of the form `import {a,b,c} from 'path'` - const namedImports = nb as ts.NamedImports; - - return namedImports.elements - .map((is: ts.ImportSpecifier) => (is.propertyName ? is.propertyName.text : is.name.text)) - .reduce((acc: { [name: string]: string }, curr: string) => { - acc[curr] = modulePath; - - return acc; - }, {}); - } - } - - return {}; - } else { - // This is of the form `import 'path';`. Nothing to do. - return {}; - } -} - -export function getExpressionName(expression: ts.Expression): string { - let text = ''; - if (!expression) { - return text; - } - - if (expression.kind == ts.SyntaxKind.Identifier) { - text = (expression).text; - } else if (expression.kind == ts.SyntaxKind.PropertyAccessExpression) { - text = (expression).name.text; - } - - return text; -} - -function getExpressionImportPath(source: ts.SourceFile, expression: ts.Expression): string { - let importString = ''; - if (!expression) { - return undefined; - } - - if (expression.kind == ts.SyntaxKind.Identifier) { - importString = (expression).text; - } else if (expression.kind == ts.SyntaxKind.PropertyAccessExpression) { - const targetPAArg = expression; - if (targetPAArg.expression.kind == ts.SyntaxKind.Identifier) { - importString = (targetPAArg.expression).text; - } - } - - const importPath = getImportPathInSource(source, importString); - - return importPath; -} - -function getSourceFile(mainPath: string): ts.SourceFile { - if (!existsSync(mainPath)) { - throw new Error(`Main file (${mainPath}) not found`); - } - const mainText = readFileSync(mainPath, 'utf8'); - const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true); - return source; -} diff --git a/packages/webpack/utils/transformers-utils.d.ts b/packages/webpack/utils/transformers-utils.d.ts deleted file mode 100644 index 0383d4d05..000000000 --- a/packages/webpack/utils/transformers-utils.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { AngularCompilerPlugin } from '@ngtools/webpack'; -export declare function getResolvedEntryModule(ngCompiler: AngularCompilerPlugin, projectDir: string): { - path: any; - className: string; -}; diff --git a/packages/webpack/utils/transformers-utils.ts b/packages/webpack/utils/transformers-utils.ts deleted file mode 100644 index cc97d10c3..000000000 --- a/packages/webpack/utils/transformers-utils.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { AngularCompilerPlugin } from '@ngtools/webpack'; -import * as semver from 'semver'; -import { getAngularVersion } from '../helpers/projectHelpers'; - -export function getResolvedEntryModule(ngCompiler: AngularCompilerPlugin, projectDir: string) { - const ngCoreVersion = projectDir && semver.coerce(getAngularVersion({ projectDir })); - let workaroundResolveModule; - // https://github.com/angular/angular-cli/commit/d2e22e97818c6582ce4a9942c59fcac4a8aaf60e#diff-0f65e27eb122d9efa58bf08adada7f82L364 - if (!ngCoreVersion || semver.gte(ngCoreVersion, '8.0.0')) { - workaroundResolveModule = require('@ngtools/webpack/src/utils'); - } else { - workaroundResolveModule = require('@ngtools/webpack/src/compiler_host'); - } - - return ngCompiler.entryModule ? { path: workaroundResolveModule.workaroundResolve(ngCompiler.entryModule.path), className: ngCompiler.entryModule.className } : ngCompiler.entryModule; -} diff --git a/packages/webpack/utils/tsconfig-utils.d.ts b/packages/webpack/utils/tsconfig-utils.d.ts deleted file mode 100644 index b23807d5b..000000000 --- a/packages/webpack/utils/tsconfig-utils.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import * as ts from 'typescript'; -export declare function getCompilerOptionsFromTSConfig(tsConfigPath: string): ts.CompilerOptions; -export declare function getNoEmitOnErrorFromTSConfig(tsConfigPath: string): boolean; diff --git a/packages/webpack/utils/tsconfig-utils.ts b/packages/webpack/utils/tsconfig-utils.ts deleted file mode 100644 index 70277dd19..000000000 --- a/packages/webpack/utils/tsconfig-utils.ts +++ /dev/null @@ -1,25 +0,0 @@ -import * as ts from 'typescript'; - -export function getCompilerOptionsFromTSConfig(tsConfigPath: string): ts.CompilerOptions { - const parseConfigFileHost: ts.ParseConfigFileHost = { - getCurrentDirectory: ts.sys.getCurrentDirectory, - useCaseSensitiveFileNames: false, - readDirectory: ts.sys.readDirectory, - fileExists: ts.sys.fileExists, - readFile: ts.sys.readFile, - onUnRecoverableConfigFileDiagnostic: undefined, - }; - - const tsConfig = ts.getParsedCommandLineOfConfigFile(tsConfigPath, ts.getDefaultCompilerOptions(), parseConfigFileHost); - - const compilerOptions: ts.CompilerOptions = tsConfig.options || ts.getDefaultCompilerOptions(); - - return compilerOptions; -} - -export function getNoEmitOnErrorFromTSConfig(tsConfigPath: string): boolean { - const compilerOptions = getCompilerOptionsFromTSConfig(tsConfigPath); - const noEmitOnError = !!compilerOptions.noEmitOnError; - - return noEmitOnError; -} diff --git a/packages/webpack/verify/update.js b/packages/webpack/verify/update.js deleted file mode 100644 index cceb756f8..000000000 --- a/packages/webpack/verify/update.js +++ /dev/null @@ -1,91 +0,0 @@ -const { spawn } = require("child_process"); -const { resolve: pathResolve } = require("path"); - -const { - getPackageJson, - getProjectDir, - writePackageJson, -} = require("../helpers/projectHelpers"); -const { forceUpdateProjectFiles } = require("../helpers/projectFilesManager"); -const { forceUpdateProjectDeps } = require("../helpers/dependencyManager"); - -const PLUGIN_NAME = "@nativescript/webpack"; -const PROJECT_DIR = getProjectDir(); - -function update({ - deps: shouldUpdateDeps, - configs: shouldUpdateConfigs, - projectDir = PROJECT_DIR -} = {}) { - - const commands = []; - - if (shouldUpdateDeps) { - commands.push(() => updateDeps(projectDir)); - } - - if (shouldUpdateConfigs) { - commands.push(() => Promise.resolve(updateConfigs(projectDir))); - } - - return commands.reduce((current, next) => current.then(next), Promise.resolve()); -} - -function updateDeps(projectDir) { - console.info("Updating dev dependencies..."); - - return new Promise((resolve, reject) => { - const packageJson = getPackageJson(projectDir); - const { deps } = forceUpdateProjectDeps(packageJson); - packageJson.devDependencies = deps; - writePackageJson(packageJson, projectDir); - - const command = `npm install --ignore-scripts`; - execute(command).then(resolve).catch(reject); - }); -} - -function updateConfigs(projectDir) { - console.info("Updating configuration files..."); - forceUpdateProjectFiles(projectDir); -} - -function execute(command) { - return new Promise((resolve, reject) => { - const args = command.split(" "); - spawnChildProcess(...args) - .then(resolve) - .catch(throwError) - }); -} - -function spawnChildProcess(command, ...args) { - return new Promise((resolve, reject) => { - const escapedArgs = args.map(a => `"${a}"`); - - const childProcess = spawn(command, escapedArgs, { - stdio: "inherit", - cwd: PROJECT_DIR, - shell: true, - }); - - childProcess.on("close", code => { - if (code === 0) { - resolve(); - } else { - reject({ - code, - message: `child process exited with code ${code}`, - }); - } - }); - }); -} - -function throwError(error) { - console.error(error.message); - process.exit(error.code || 1); -} - -module.exports = update; - diff --git a/workspace.json b/workspace.json index 0d93a2399..087d4d011 100644 --- a/workspace.json +++ b/workspace.json @@ -11,7 +11,6 @@ "types-ios": "packages/types-ios", "types-minimal": "packages/types-minimal", "ui-mobile-base": "packages/ui-mobile-base", - "webpack": "packages/webpack", "webpack5": "packages/webpack5" }, "$schema": "./node_modules/nx/schemas/workspace-schema.json"