From 8878c3bc6be5c061e95da74249998b51797d71d9 Mon Sep 17 00:00:00 2001 From: farfromrefuge Date: Thu, 14 Oct 2021 04:25:05 +0200 Subject: [PATCH 01/35] fix(android): autofillType on apiLevel < 26 (#9610) * chore: rollback unwanted change --- packages/core/ui/editable-text-base/index.android.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/core/ui/editable-text-base/index.android.ts b/packages/core/ui/editable-text-base/index.android.ts index 7501b1c3b..c01273699 100644 --- a/packages/core/ui/editable-text-base/index.android.ts +++ b/packages/core/ui/editable-text-base/index.android.ts @@ -143,8 +143,6 @@ function initializeEditTextListeners(): void { EditTextListeners = EditTextListenersImpl; } -let apiLevel: number; - export abstract class EditableTextBase extends EditableTextBaseCommon { /* tslint:disable */ _dirtyTextAccumulator: string; @@ -164,9 +162,6 @@ export abstract class EditableTextBase extends EditableTextBaseCommon { } public createNativeView() { - if (!apiLevel) { - apiLevel = sdkVersion(); - } return new android.widget.EditText(this._context); } @@ -304,7 +299,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon { } [autofillTypeProperty.setNative](value: CoreTypes.AutofillType) { - if (apiLevel < 26) { + if (sdkVersion() < 26) { return; } let newOptions; From 2ad280deb0e9b6098d4ad76ccf703e257196a023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20de=20Dios=20Mart=C3=ADnez=20Vallejo?= Date: Wed, 20 Oct 2021 18:24:53 +0200 Subject: [PATCH 02/35] fix(android): version Android text-align justify (#9620) --- packages/core/ui/text-base/index.android.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/ui/text-base/index.android.ts b/packages/core/ui/text-base/index.android.ts index 7cdb34ebc..8265425c3 100644 --- a/packages/core/ui/text-base/index.android.ts +++ b/packages/core/ui/text-base/index.android.ts @@ -296,7 +296,7 @@ export class TextBase extends TextBaseCommon { this.nativeTextViewProtected.setGravity(android.view.Gravity.START | verticalGravity); break; } - if (android.os.Build.VERSION.SDK_INT >= 25) { + if (android.os.Build.VERSION.SDK_INT >= 26) { if (value === 'justify') { this.nativeTextViewProtected.setJustificationMode(android.text.Layout.JUSTIFICATION_MODE_INTER_WORD); } else { From a3823ffc38abfa05619ed1da371787ed7ed4cb4d Mon Sep 17 00:00:00 2001 From: Siddharth Mishra Date: Tue, 26 Oct 2021 21:25:08 +0530 Subject: [PATCH 03/35] chore(repo): GitHub Issue Forms (#9594) Co-authored-by: Igor Randjelovic --- .github/ISSUE_TEMPLATE/bug_report.md | 30 ------ .github/ISSUE_TEMPLATE/bug_report.yaml | 112 ++++++++++++++++++++ .github/ISSUE_TEMPLATE/config.yml | 14 +++ .github/ISSUE_TEMPLATE/feature_request.md | 17 --- .github/ISSUE_TEMPLATE/feature_request.yaml | 69 ++++++++++++ 5 files changed, 195 insertions(+), 47 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yaml create mode 100644 .github/ISSUE_TEMPLATE/config.yml delete mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yaml diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 810b02be0..000000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -name: Bug report -about: 'We really appreciate your effort to provide feedback. Before opening a new - issue, please make sure that this case is not already reported in GitHub as an - issue or in StackOverflow as a question.' - ---- - -**Environment** -Provide version numbers for the following components (information can be retrieved by running `tns info` in your project folder or by inspecting the `package.json` of the project): - - CLI: - - Cross-platform modules: - - Android Runtime: - - iOS Runtime: - - XCode Version: - - Plugin(s): - -**Describe the bug** - - -**To Reproduce** - - -**Expected behavior** - -**Sample project** - - -**Additional context** - diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml new file mode 100644 index 000000000..7092af5eb --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -0,0 +1,112 @@ +name: 🐞 Bug report +description: Create a bug report to help us improve NativeScript +labels: [bug-pending-triage] + +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to report an issue. + + > ## Important! :warning: + > + > The issue list is reserved exclusively for bug reports and feature requests. That means we do not accept usage questions. If you open an issue that does not conform to the requirements, it will be closed. + > + > For usage questions, please refer to the following resources: + > * Search the [docs](https://docs.nativescript.org/) + > * Search or ask in [Discord](https://nativescript.org/discord) + > * Search or ask in [Discussions](https://github.com/NativeScript/NativeScript/discussions) + > * Search or ask on [StackOverflow](https://stackoverflow.com/questions/tagged/nativescript) + > * Watch [video tutorials](https://nativescripting.com/) + + - type: textarea + validations: + required: true + attributes: + label: Issue Description + description: | + A clear and concise description of what the bug is. + Please, explain whether it's a build-time error or a runtime error. + + If you intend to submit a PR for this issue, tell us in the description. + placeholder: | + When I do , happens and I see the following error message: + + ``` + + ``` + + Expected behavior: + + When I do , should happen instead. + + - type: textarea + attributes: + label: Reproduction + description: | + Add commands used or steps taken to reproduce the behaviour. + Include links, references or anything else that will give us more context about the issue you are encountering. + placeholder: | + e.g: + https://github.com/NativeScript/Nativescript + + 1. clone, and run with `ns run ios` + 2. Click on '...' + 3. See error + + - type: textarea + attributes: + label: Relevant log output (if applicable) + description: | + Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. + + Using the `--log trace` flag will usuall print more verbose logs that will help identify the issue quicker. + + When pasting verbose logs, please make sure you remove any sensitive information. + render: shell + + - type: textarea + attributes: + label: Environment + description: | + Provide information about your environment. Run + + ```shell + npx -y nativescript-envinfo + ``` + + inside the project and paste the output directly without manual formatting. + placeholder: | + Paste the result of + + npx -y nativescript-envinfo + + - type: markdown + attributes: + value: | + --- + + Before you submit this issue, please confirm the following: + + **1. Is there an existing issue for this?** + + Please search to see if an issue already exists for the bug you encountered or is not already reported on [StackOverflow](https://stackoverflow.com/questions/tagged/nativescript) as a question. + + **2. Confirm you are submitting a bug report** + + Please confirm you are submitting a bug report and not a usage question. + + **3. Code of Conduct** + + By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#coc) + + --- + - type: checkboxes + attributes: + options: + - label: I have searched the [existing issues](https://github.com/NativeScript/NativeScript/issues) as well as [StackOverflow](https://stackoverflow.com/questions/tagged/nativescript) and this has not been posted before + required: true + - label: This is a bug report + required: true + - label: I agree to follow this project's [Code of Conduct](https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#coc) + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 000000000..7c53936a5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,14 @@ +blank_issues_enabled: false +contact_links: + - name: Search the Docs + url: https://docs.nativescript.org + about: Refer to the docs and search for what you are looking for. + - name: Search or ask in Discord + url: https://nativescript.org/discord + about: Ask questions and discuss with other NativeScript users in real-time. + - name: Search or ask in Discussions + url: https://github.com/NativeScript/NativeScript/discussions + about: Use GitHub discussions for message-board style questions and discussions. + - name: Search or ask on StackOverflow + url: https://stackoverflow.com/questions/tagged/nativescript + about: Use StackOverflow to look for answered questions that may be similar to yours. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 397090987..000000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project - ---- - -**Is your feature request related to a problem? Please describe.** - - -**Describe the solution you'd like** - - -**Describe alternatives you've considered** - - -**Additional context** - diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml new file mode 100644 index 000000000..89954258d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yaml @@ -0,0 +1,69 @@ +name: 🚀 Feature request +description: Suggest an idea for NativeScript +labels: ["enhancement-pending-triage"] + +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to request a feature for NativeScript! + + > ## Important! :warning: + > + > The issue list is reserved exclusively for bug reports and feature requests. That means we do not accept usage questions. If you open an issue that does not conform to the requirements, it will be closed. + > + > For usage questions, please refer to the following resources: + > * Search the [docs](https://docs.nativescript.org/) + > * Search or ask in [Discord](https://nativescript.org/discord) + > * Search or ask in [Discussions](https://github.com/NativeScript/NativeScript/discussions) + > * Search or ask on [StackOverflow](https://stackoverflow.com/questions/tagged/nativescript) + > * Watch [video tutorials](https://nativescripting.com/) + + - type: textarea + attributes: + label: Is your feature request related to a problem? Please describe. + description: A clear and concise description of what the problem is. + placeholder: | + I wish I could use NativeScript to do [...] + or + I'm always frustrated when [...] + + - type: textarea + attributes: + label: Describe the solution you'd like + description: A clear and concise description of what you want to happen. + + - type: textarea + attributes: + label: Describe alternatives you've considered + description: A clear and concise description of any alternative solutions or features you've considered. + + - type: textarea + attributes: + label: Anything else? + description: Add any other context, code examples, or references to existing implementations about the feature request here. + + - type: markdown + attributes: + value: | + --- + + Before you submit this feature request, please confirm the following: + + **1. Is there an existing issue for this?** + + Please search to see if an issue related to this feature request already exists. + + **2. Code of Conduct** + + By submitting this feature request, you agree to follow our [Code of Conduct](https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#coc) + + --- + + - type: checkboxes + attributes: + options: + - label: I have searched the [existing issues](https://github.com/NativeScript/NativeScript/issues) as well as [StackOverflow](https://stackoverflow.com/questions/tagged/nativescript) and this has not been posted before + required: true + - label: I agree to follow this project's [Code of Conduct](https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#coc) + required: true From 7c75966b3b33f3268574fe110ee3ce58374f5280 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Thu, 28 Oct 2021 16:17:35 -0700 Subject: [PATCH 04/35] chore(release): @nativescript/core@8.1.5 --- CHANGELOG.md | 10 ++++++++++ package.json | 2 +- packages/core/package.json | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6e70a7c7..89af4f691 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## [8.1.5](https://github.com/NativeScript/NativeScript/compare/8.1.4-core...8.1.5) (2021-10-28) + + +### Bug Fixes + +* **android:** autofillType on apiLevel < 26 ([#9610](https://github.com/NativeScript/NativeScript/issues/9610)) ([8878c3b](https://github.com/NativeScript/NativeScript/commit/8878c3bc6be5c061e95da74249998b51797d71d9)) +* **android:** version Android text-align justify ([#9620](https://github.com/NativeScript/NativeScript/issues/9620)) ([2ad280d](https://github.com/NativeScript/NativeScript/commit/2ad280deb0e9b6098d4ad76ccf703e257196a023)) + + + ## [8.1.4](https://github.com/NativeScript/NativeScript/compare/8.1.3-core...8.1.4) (2021-10-09) diff --git a/package.json b/package.json index 7515c769d..91406a5e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nativescript", - "version": "8.1.4", + "version": "8.1.5", "license": "MIT", "scripts": { "clean": "git clean -f -X -d --exclude=!.idea/ --exclude=!.vscode/*", diff --git a/packages/core/package.json b/packages/core/package.json index fb9243132..dede394d6 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -3,7 +3,7 @@ "main": "index", "types": "index.d.ts", "description": "A JavaScript library providing an easy to use api for interacting with iOS and Android platform APIs.", - "version": "8.1.4", + "version": "8.1.5", "homepage": "https://nativescript.org", "repository": { "type": "git", From 78e9c17be3054466142a003c17033294b22bb126 Mon Sep 17 00:00:00 2001 From: halfnelson Date: Fri, 29 Oct 2021 20:32:56 +1000 Subject: [PATCH 05/35] fix(webpack): map 'svelte' to 'svelte/internal' to avoid forced ssr (#9627) --- packages/webpack5/src/configuration/svelte.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/webpack5/src/configuration/svelte.ts b/packages/webpack5/src/configuration/svelte.ts index e5feea09e..4d4f239e0 100644 --- a/packages/webpack5/src/configuration/svelte.ts +++ b/packages/webpack5/src/configuration/svelte.ts @@ -1,4 +1,3 @@ -import { merge } from 'webpack-merge'; import Config from 'webpack-chain'; import { getProjectFilePath } from '../helpers/project'; @@ -19,6 +18,10 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { // electron-main sneaks us past the target == 'node' check and gets us HMR config.target('electron-main'); + // turns out this isn't enough now. svelte uses "node" of which "electron-main" is a subset in its export map forcing imports + // for 'svelte' to 'ssr.mjs'. We define an alias here to force it back. + config.resolve.alias.set('svelte$', 'svelte/internal'); + // svelte-hmr still references tns-core-modules, so we shim it here for compat. config.resolve.alias.set('tns-core-modules', '@nativescript/core'); From 483217934c679222ed04387421d3a3c7241ae4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20de=20Dios=20Mart=C3=ADnez=20Vallejo?= Date: Sat, 30 Oct 2021 03:43:14 +0200 Subject: [PATCH 06/35] fix(ios): box-shadow and border-radius (#9612) Co-authored-by: Nathan Walker --- packages/core/ui/core/view/index.ios.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/ui/core/view/index.ios.ts b/packages/core/ui/core/view/index.ios.ts index 8e7993a17..acc7b116c 100644 --- a/packages/core/ui/core/view/index.ios.ts +++ b/packages/core/ui/core/view/index.ios.ts @@ -853,7 +853,7 @@ export class View extends ViewCommon implements ViewDefinition { _setNativeClipToBounds() { const backgroundInternal = this.style.backgroundInternal; - this.nativeViewProtected.clipsToBounds = this.nativeViewProtected instanceof UIScrollView || backgroundInternal.hasBorderWidth() || backgroundInternal.hasBorderRadius(); + this.nativeViewProtected.clipsToBounds = (this.nativeViewProtected instanceof UIScrollView || backgroundInternal.hasBorderWidth() || backgroundInternal.hasBorderRadius()) && !backgroundInternal.hasBoxShadow(); } private _setupPopoverControllerDelegate(controller: UIViewController, parent: View) { From 002ecc379f7f74f61f8ababa7404bd44c52ac6ee Mon Sep 17 00:00:00 2001 From: wanderer163 <93438190+wanderer163@users.noreply.github.com> Date: Wed, 3 Nov 2021 00:58:27 +0530 Subject: [PATCH 07/35] chore: grammar and typos in .md files (#9632) --- README.md | 2 +- apps/ui/README.md | 4 ++-- tools/notes/CONTRIBUTING-webpack.md | 8 ++++---- tools/notes/CONTRIBUTING.md | 12 ++++++------ tools/notes/CodingConvention.md | 2 +- tools/notes/DevelopmentWorkflow.md | 2 +- tools/notes/HandlingErrors.md | 6 +++--- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index e1de911ba..153f98b65 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ We love you and your PR's 🤗. Please follow our [contributing guide](https://g ## Other source repos -Outside of the source centralized in this repo, NativeScript consists of a few other source repos. Here are the major ones: +Outside the source centralized in this repo, NativeScript consists of a few other source repos. Here are the major ones: - **[iOS runtime](https://github.com/NativeScript/ns-v8ios-runtime)** - [![npm](https://img.shields.io/npm/dm/tns-ios.svg)](https://www.npmjs.com/package/@nativescript/ios) diff --git a/apps/ui/README.md b/apps/ui/README.md index 56395869e..96c6addbb 100644 --- a/apps/ui/README.md +++ b/apps/ui/README.md @@ -1,7 +1,7 @@ ***e2e tests execution*** 1. Local setup - - install appium and all requirments related to `nativescript-dev-appium` plugin usage + - install appium and all requirements related to `nativescript-dev-appium` plugin usage - download images: ```npm run load-images Emulator-Api23-Default "iPhone X 12"``` @@ -36,7 +36,7 @@ - Run: `npm run e2e-debug [android|ios]` -run in separate console and don't kill it. This command will start appium server and driver and use the installed app on the device but it will not execute tests. +run in separate console and don't kill it. This command will start appium server and driver and use the installed app on the device, but it will not execute tests. - Go to vs code debugging and use a config like: ``` diff --git a/tools/notes/CONTRIBUTING-webpack.md b/tools/notes/CONTRIBUTING-webpack.md index f65a4183d..1750d3ab9 100644 --- a/tools/notes/CONTRIBUTING-webpack.md +++ b/tools/notes/CONTRIBUTING-webpack.md @@ -23,7 +23,7 @@ Before starting, make yourself familiar with the `@nativescript/webpack`'s [docu ## Project Structure The repository contains several ingredients: -* `installer.js` - combination of postinstall scripts for adding or removing webpack configurations and necessary dependecies when installing the plugin. +* `installer.js` - combination of postinstall scripts for adding or removing webpack configurations and necessary dependencies when installing the plugin. * `templates/` - webpack config templates for different types of projects - NativeScript with JavaScript, NativeScript with TypeScript and NativeScript Angular projects. * `plugins/` - several [Webpack plugins](https://webpack.js.org/concepts/plugins/) necessary for bundling NativeScript applications. * `snapshot/android/` - tools used with the `NativeScriptSnapshot` plugin for generating V8 Heap Snapshots. @@ -164,7 +164,7 @@ git checkout release && git pull git merge --ff-only origin/master ``` *** Note: If there are commits in release branch which are not merged in master branch '-ff-merge' command will fail. -In this case the commits should be merge firstly from release in master branch as explained in section 'Merge changes from release into master' and then repeat step 1. +In this case the commits should be merged firstly from release in master branch as explained in section 'Merge changes from release into master' and then repeat step 1. 2. Execute `npm i` to install dependencies: ``` @@ -233,7 +233,7 @@ git commit git push ``` -6. Create pull request. Replace replace env ${MERGE_BRANCH} with its value +6. Create pull request. Replace env ${MERGE_BRANCH} with its value ``` curl -d '{"title": "chore: merge release in master","body": "chore: merge release in master","head": "merge-release-in-master","base": "master"}' -X POST https://api.github.com/repos/NativeScript/NativeScript/pulls -H "Authorization: token ${GIT_TOKEN}" ``` @@ -244,4 +244,4 @@ git checkout origin/master tns-platform-declarations/package.json tns-core-modul git commit --amend git push --force-with-lease ``` -This will require to repeat steps from 1 to 4, since we need to keep the branches with the same history +This will require repeating steps from 1 to 4, since we need to keep the branches with the same history diff --git a/tools/notes/CONTRIBUTING.md b/tools/notes/CONTRIBUTING.md index a0f9abb1c..3453fbcbb 100644 --- a/tools/notes/CONTRIBUTING.md +++ b/tools/notes/CONTRIBUTING.md @@ -94,12 +94,12 @@ When you click on the button, you will be redirected to the report page. On the > Note: Each item name consists of the application name, type of device and platform version: `pr-e2e-tests-[application-name]-[device-type]-[platform-version]`. Usually, the test applications, that are executed for PRs are part of NativeScript repository. -Based on the executed suite, one of the following or all of the following files will be generated: `mochawesome.html` | `index.html` | `unit-tests.log`. Some of the reports also might include `*.png`, `*.logs` or `[page source].xml` files that can help in understanding where is the problem. +Based on the executed suite, one of the following or all of the following files will be generated: `mochawesome.html` | `index.html` | `unit-tests.log`. Some reports also might include `*.png`, `*.logs` or `[page source].xml` files that can help in understanding where is the problem. For example: 1. When you select the `index.html` page, an additional `TestNG Results` sidebar will be displayed. There you can find a list of all failures. 2. When you select one of them, you will see on the right side all tests, that have been executed. The problematic ones will be coloured in red. -3. If you click on one of them, detailed info or error log will be displayed. As we've mentioned above in some of the test reports, you will also find screenshots, that demonstrates the problem visually. Those images can be found below the info/ error log. +3. If you click on one of them, detailed info or error log will be displayed. As we've mentioned above in some test reports, you will also find screenshots, that demonstrates the problem visually. Those images can be found below the info/ error log. ## Commit Message Guidelines @@ -248,7 +248,7 @@ git checkout release git merge --ff-only origin/master ``` *** Note: If there are commits in release branch which are not merged in master branch '-ff-merge' command will fail. -In this case the commits should be merge firstly from release in master branch as explained in section 'Merge changes from release into master' and then repeat step 1. +In this case the commits should be merged firstly from release in master branch as explained in section 'Merge changes from release into master' and then repeat step 1. 2. Execute `npm i` to install dependencies: ``` @@ -277,7 +277,7 @@ npm --no-git-tag-version version [major|minor|patch] -m "release: cut the %s rel cd .. ``` 6. Set correct version of **tns-core-modules-widgets** in tns-core-modules/package.json. -Usually tns-core-modules-widgets should already have been released and we need to set the official version. +Usually tns-core-modules-widgets should already have been released, and we need to set the official version. 7. Create release-branch with change log ``` @@ -333,7 +333,7 @@ git commit git push ``` -6. Create pull request. Replace replace env ${MERGE_BRANCH} with its value +6. Create pull request. Replace env ${MERGE_BRANCH} with its value ``` curl -d '{"title": "chore: merge release in master","body": "chore: merge release in master","head": "merge-release-in-master","base": "master"}' -X POST https://api.github.com/repos/NativeScript/NativeScript/pulls -H "Authorization: token ${GIT_TOKEN}" ``` @@ -344,4 +344,4 @@ git checkout origin/master tns-platform-declarations/package.json tns-core-modul git commit --amend git push --force-with-lease ``` -This will require to repeat steps from 1 to 4, since we need to keep the branches with the same history +This will require repeating steps from 1 to 4, since we need to keep the branches with the same history diff --git a/tools/notes/CodingConvention.md b/tools/notes/CodingConvention.md index 4ac32c31c..e20320c82 100644 --- a/tools/notes/CodingConvention.md +++ b/tools/notes/CodingConvention.md @@ -509,7 +509,7 @@ class Foo { ``` ## TypeScript optional parameters -**Do not** use optional parameters in IMPLEMENTATION files. This is because the TS compiler generates additional array and populates its from the **arguments** object. Still, it is OK to use these in a definition file (as declarations ONLY). +**Do not** use optional parameters in IMPLEMENTATION files. This is because the TS compiler generates additional array and populates it from the **arguments** object. Still, it is OK to use these in a definition file (as declarations ONLY). *Right:* ```TypeScript diff --git a/tools/notes/DevelopmentWorkflow.md b/tools/notes/DevelopmentWorkflow.md index 8cbe0c277..17d449523 100644 --- a/tools/notes/DevelopmentWorkflow.md +++ b/tools/notes/DevelopmentWorkflow.md @@ -50,7 +50,7 @@ You can do changes in the test app and `nativescript-core` and rely on HMR to re ## Running the `e2e` Test Apps -There are couple of application used for development and testing. +There are a couple of application used for development and testing. The `ui-test-app` is the more frequently used for development and validation. It is an ordinary NativeScript app that logs the test results on the go. After the [initial setup](#initial-setup) run the e2e apps with: diff --git a/tools/notes/HandlingErrors.md b/tools/notes/HandlingErrors.md index fca8056bf..37278fc9b 100644 --- a/tools/notes/HandlingErrors.md +++ b/tools/notes/HandlingErrors.md @@ -10,7 +10,7 @@ The `tns-core-modules/trace` utility module provides a good way to streamline er Here are the guidelines how to use this when contributing to core-modules or creating your own plugins. ### Use `trace.write()` -Use trace.write() with the appropriate type to log non critical errors. +Use trace.write() with the appropriate type to log non-critical errors. >Note: For the `error` message level all loggers will be notified unconditionally, for all other levels (`log`,`info`,`warn`), tracing should be enabled and the corresponding categories should be added. @@ -21,7 +21,7 @@ Use the `error()` when an error has occurred which compromises the stability of After calling `trace.error()` consider just returning from the function you are currently in without completing. -There are cases when code execution jumps between native code (ex. Android/iOS SDKs) and JavaScript trough callbacks. In those cases it is most difficult to determine if an error (ex. expected argument is `undefined` or current state of components is invalid) is critical or not. Although, it seems that error is unrecoverable, it might be the case that the callback is called when the app has gone to the background or trough activity/window that is not longer visible. So just reporting the error with `write()` or `error()` is a good option in such cases. +There are cases when code execution jumps between native code (ex. Android/iOS SDKs) and JavaScript trough callbacks. In those cases it is most difficult to determine if an error (ex. expected argument is `undefined` or current state of components is invalid) is critical or not. Although, it seems that error is unrecoverable, it might be the case that the callback is called when the app has gone to the background or trough activity/window that is no longer visible. So just reporting the error with `write()` or `error()` is a good option in such cases. ## Throw the Error directly in code @@ -31,6 +31,6 @@ Avoid throwing errors directly, especially in code that is not directly called f 2. Obviously misused public APIs (ex. wrong arguments types) which developers will call directly. ## Clearing Legacy Code -Not all the code in the `tns-core-modules` might conform to this guide as it might be written before some of the improvements of the trace modules (ex. `error()`). If you came across to such code you can always [give us a PR](CONTRIBUTING.md) referencing [this issue](https://github.com/NativeScript/NativeScript/issues/5914). +Not all the code in the `tns-core-modules` might conform to this guide as it might be written before some improvements of the trace modules (ex. `error()`). If you came across to such code you can always [give us a PR](CONTRIBUTING.md) referencing [this issue](https://github.com/NativeScript/NativeScript/issues/5914). From c26779735f09906720da726aef062649da5ef28e Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Wed, 10 Nov 2021 21:01:09 +0100 Subject: [PATCH 08/35] test(webpack): update snapshots --- .../__tests__/configuration/__snapshots__/svelte.spec.ts.snap | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap index f17a1d443..7e56d0469 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap @@ -34,6 +34,7 @@ exports[`svelte configuration for android 1`] = ` alias: { '~': '__jest__/src', '@': '__jest__/src', + svelte$: 'svelte/internal', 'tns-core-modules': '@nativescript/core' }, extensions: [ @@ -365,6 +366,7 @@ exports[`svelte configuration for ios 1`] = ` alias: { '~': '__jest__/src', '@': '__jest__/src', + svelte$: 'svelte/internal', 'tns-core-modules': '@nativescript/core' }, extensions: [ From 1b0414c6ae79b5398bcdd9979c61a9afffa7d3df Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Wed, 10 Nov 2021 21:02:34 +0100 Subject: [PATCH 09/35] chore(release): @nativescript/webpack 5.0.1 --- packages/webpack5/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webpack5/package.json b/packages/webpack5/package.json index f7227b303..a25caf2d1 100644 --- a/packages/webpack5/package.json +++ b/packages/webpack5/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/webpack", - "version": "5.0.0", + "version": "5.0.1", "private": false, "main": "dist/index.js", "files": [ From e57a9bdedb1f699773c93d8b248b88efcab2d618 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Sat, 13 Nov 2021 18:28:29 +0100 Subject: [PATCH 10/35] chore: enable blank issues temporarily --- .github/ISSUE_TEMPLATE/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 7c53936a5..eb2027557 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,4 +1,4 @@ -blank_issues_enabled: false +blank_issues_enabled: true contact_links: - name: Search the Docs url: https://docs.nativescript.org From c0fdc61a94a8c4cdb6c53e26d83a7ebdf59cfd94 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Mon, 15 Nov 2021 12:14:32 +0100 Subject: [PATCH 11/35] chore(issue-forms): add id to checkboxes --- .github/ISSUE_TEMPLATE/bug_report.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 7092af5eb..026b0c635 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -102,6 +102,7 @@ body: --- - type: checkboxes + id: terms attributes: options: - label: I have searched the [existing issues](https://github.com/NativeScript/NativeScript/issues) as well as [StackOverflow](https://stackoverflow.com/questions/tagged/nativescript) and this has not been posted before From 410a94dcdf6c5219ce95f4c635c0e9e210b55625 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Mon, 15 Nov 2021 12:14:57 +0100 Subject: [PATCH 12/35] chore(issue-forms): add unique id to checkboxes --- .github/ISSUE_TEMPLATE/feature_request.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml index 89954258d..2558c2d49 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yaml +++ b/.github/ISSUE_TEMPLATE/feature_request.yaml @@ -61,6 +61,7 @@ body: --- - type: checkboxes + id: terms attributes: options: - label: I have searched the [existing issues](https://github.com/NativeScript/NativeScript/issues) as well as [StackOverflow](https://stackoverflow.com/questions/tagged/nativescript) and this has not been posted before From fa47eb47ff2050228c7ff06596bc2c072d443c4f Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Mon, 15 Nov 2021 12:20:19 +0100 Subject: [PATCH 13/35] chore: disable blank issues --- .github/ISSUE_TEMPLATE/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index eb2027557..7c53936a5 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,4 +1,4 @@ -blank_issues_enabled: true +blank_issues_enabled: false contact_links: - name: Search the Docs url: https://docs.nativescript.org From bbd2aa9540ad249140a876e495a85c78f67c76e3 Mon Sep 17 00:00:00 2001 From: William Sedlacek Date: Sun, 21 Nov 2021 08:51:12 -0800 Subject: [PATCH 14/35] chore(webpack5): update react-refresh (#9675) --- packages/webpack5/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webpack5/package.json b/packages/webpack5/package.json index a25caf2d1..0723d3af3 100644 --- a/packages/webpack5/package.json +++ b/packages/webpack5/package.json @@ -18,7 +18,7 @@ }, "dependencies": { "@babel/core": "^7.0.0", - "@pmmmwh/react-refresh-webpack-plugin": "^0.4.0", + "@pmmmwh/react-refresh-webpack-plugin": "^0.5.2", "acorn": "^8.0.0", "acorn-stage3": "^4.0.0", "babel-loader": "^8.0.0", @@ -37,7 +37,7 @@ "postcss-import": "^14.0.0", "postcss-loader": "^6.0.0", "raw-loader": "^4.0.0", - "react-refresh": "~0.8.3", + "react-refresh": "~0.11.0", "sass": "^1.0.0", "sass-loader": "^12.0.0", "sax": "^1.0.0", From 57eac49128d81d0bd2ef209b076158dcb5de4c73 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Sun, 21 Nov 2021 18:12:14 +0100 Subject: [PATCH 15/35] chore(webpack5): update snapshots --- .../__tests__/configuration/__snapshots__/react.spec.ts.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap index 10de0bf00..102570df6 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap @@ -317,7 +317,7 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR overlay: false, forceEnable: false, exclude: /node_modules/i, - include: /\\\\.([jt]sx?|flow)$/i + include: /\\\\.([cm]js|[jt]sx?|flow)$/i } ) ], @@ -961,7 +961,7 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena overlay: false, forceEnable: false, exclude: /node_modules/i, - include: /\\\\.([jt]sx?|flow)$/i + include: /\\\\.([cm]js|[jt]sx?|flow)$/i } ) ], From 05082b1aec1cd4b87b4dd60f79712035c29e5ac1 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Mon, 29 Nov 2021 13:55:10 -0300 Subject: [PATCH 16/35] fix(webpack5): include hmr handling only when enabled (#9685) * fix(webpack): respect hmr flag * fix(webpack): ensure correct loader order is used * chore: cleanup Co-authored-by: Igor Randjelovic --- .../__snapshots__/angular.spec.ts.snap | 42 +++------ .../__snapshots__/base.spec.ts.snap | 50 ++++------- .../__snapshots__/javascript.spec.ts.snap | 84 ++++------------- .../__snapshots__/react.spec.ts.snap | 90 ++++++++----------- .../__snapshots__/svelte.spec.ts.snap | 50 ++++------- .../__snapshots__/typescript.spec.ts.snap | 84 ++++------------- .../__snapshots__/vue.spec.ts.snap | 50 ++++------- packages/webpack5/src/configuration/base.ts | 30 ++++--- .../webpack5/src/configuration/javascript.ts | 27 +++--- .../webpack5/src/configuration/typescript.ts | 27 +++--- 10 files changed, 190 insertions(+), 344 deletions(-) diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap index c888c2aad..0e9e5f8a2 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap @@ -84,23 +84,9 @@ exports[`angular configuration for android 1`] = ` options: { platform: 'android' } - }, - /* config.module.rule('bundle').use('nativescript-hot-loader') */ - { - loader: 'nativescript-hot-loader', - options: { - injectHMRRuntime: true - } } ] }, - /* config.module.rule('js') */ - { - test: /\\\\.js$/, - exclude: [ - /node_modules/ - ] - }, /* config.module.rule('workers') */ { test: /\\\\.(js|ts)$/, @@ -111,6 +97,13 @@ exports[`angular configuration for android 1`] = ` } ] }, + /* config.module.rule('js') */ + { + test: /\\\\.js$/, + exclude: [ + /node_modules/ + ] + }, /* config.module.rule('xml') */ { test: /\\\\.xml$/, @@ -472,23 +465,9 @@ exports[`angular configuration for ios 1`] = ` options: { platform: 'ios' } - }, - /* config.module.rule('bundle').use('nativescript-hot-loader') */ - { - loader: 'nativescript-hot-loader', - options: { - injectHMRRuntime: true - } } ] }, - /* config.module.rule('js') */ - { - test: /\\\\.js$/, - exclude: [ - /node_modules/ - ] - }, /* config.module.rule('workers') */ { test: /\\\\.(js|ts)$/, @@ -499,6 +478,13 @@ exports[`angular configuration for ios 1`] = ` } ] }, + /* config.module.rule('js') */ + { + test: /\\\\.js$/, + exclude: [ + /node_modules/ + ] + }, /* config.module.rule('xml') */ { test: /\\\\.xml$/, diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap index 9209dd850..07ce49456 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap @@ -72,13 +72,16 @@ exports[`base configuration for android 1`] = ` options: { platform: 'android' } - }, - /* config.module.rule('bundle').use('nativescript-hot-loader') */ + } + ] + }, + /* config.module.rule('workers') */ + { + test: /\\\\.(js|ts)$/, + use: [ + /* config.module.rule('workers').use('nativescript-worker-loader') */ { - loader: 'nativescript-hot-loader', - options: { - injectHMRRuntime: true - } + loader: 'nativescript-worker-loader' } ] }, @@ -110,16 +113,6 @@ exports[`base configuration for android 1`] = ` /node_modules/ ] }, - /* config.module.rule('workers') */ - { - test: /\\\\.(js|ts)$/, - use: [ - /* config.module.rule('workers').use('nativescript-worker-loader') */ - { - loader: 'nativescript-worker-loader' - } - ] - }, /* config.module.rule('xml') */ { test: /\\\\.xml$/, @@ -383,13 +376,16 @@ exports[`base configuration for ios 1`] = ` options: { platform: 'ios' } - }, - /* config.module.rule('bundle').use('nativescript-hot-loader') */ + } + ] + }, + /* config.module.rule('workers') */ + { + test: /\\\\.(js|ts)$/, + use: [ + /* config.module.rule('workers').use('nativescript-worker-loader') */ { - loader: 'nativescript-hot-loader', - options: { - injectHMRRuntime: true - } + loader: 'nativescript-worker-loader' } ] }, @@ -421,16 +417,6 @@ exports[`base configuration for ios 1`] = ` /node_modules/ ] }, - /* config.module.rule('workers') */ - { - test: /\\\\.(js|ts)$/, - use: [ - /* config.module.rule('workers').use('nativescript-worker-loader') */ - { - loader: 'nativescript-worker-loader' - } - ] - }, /* config.module.rule('xml') */ { test: /\\\\.xml$/, diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap index 8e642f69f..4347d13a6 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap @@ -72,13 +72,16 @@ exports[`javascript configuration for android 1`] = ` options: { platform: 'android' } - }, - /* config.module.rule('bundle').use('nativescript-hot-loader') */ + } + ] + }, + /* config.module.rule('workers') */ + { + test: /\\\\.(js|ts)$/, + use: [ + /* config.module.rule('workers').use('nativescript-worker-loader') */ { - loader: 'nativescript-hot-loader', - options: { - injectHMRRuntime: true - } + loader: 'nativescript-worker-loader' } ] }, @@ -110,16 +113,6 @@ exports[`javascript configuration for android 1`] = ` /node_modules/ ] }, - /* config.module.rule('workers') */ - { - test: /\\\\.(js|ts)$/, - use: [ - /* config.module.rule('workers').use('nativescript-worker-loader') */ - { - loader: 'nativescript-worker-loader' - } - ] - }, /* config.module.rule('xml') */ { test: /\\\\.xml$/, @@ -183,23 +176,6 @@ exports[`javascript configuration for android 1`] = ` loader: 'sass-loader' } ] - }, - /* config.module.rule('hmr-core') */ - { - test: /\\\\.js$/, - exclude: [ - /node_modules/, - '__jest__/src/app.js' - ], - use: [ - /* config.module.rule('hmr-core').use('nativescript-hot-loader') */ - { - loader: 'nativescript-hot-loader', - options: { - appPath: '__jest__/src' - } - } - ] } ] }, @@ -409,13 +385,16 @@ exports[`javascript configuration for ios 1`] = ` options: { platform: 'ios' } - }, - /* config.module.rule('bundle').use('nativescript-hot-loader') */ + } + ] + }, + /* config.module.rule('workers') */ + { + test: /\\\\.(js|ts)$/, + use: [ + /* config.module.rule('workers').use('nativescript-worker-loader') */ { - loader: 'nativescript-hot-loader', - options: { - injectHMRRuntime: true - } + loader: 'nativescript-worker-loader' } ] }, @@ -447,16 +426,6 @@ exports[`javascript configuration for ios 1`] = ` /node_modules/ ] }, - /* config.module.rule('workers') */ - { - test: /\\\\.(js|ts)$/, - use: [ - /* config.module.rule('workers').use('nativescript-worker-loader') */ - { - loader: 'nativescript-worker-loader' - } - ] - }, /* config.module.rule('xml') */ { test: /\\\\.xml$/, @@ -520,23 +489,6 @@ exports[`javascript configuration for ios 1`] = ` loader: 'sass-loader' } ] - }, - /* config.module.rule('hmr-core') */ - { - test: /\\\\.js$/, - exclude: [ - /node_modules/, - '__jest__/src/app.js' - ], - use: [ - /* config.module.rule('hmr-core').use('nativescript-hot-loader') */ - { - loader: 'nativescript-hot-loader', - options: { - appPath: '__jest__/src' - } - } - ] } ] }, diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap index 102570df6..c875a21e6 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap @@ -85,6 +85,16 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR } ] }, + /* config.module.rule('workers') */ + { + test: /\\\\.(js|ts)$/, + use: [ + /* config.module.rule('workers').use('nativescript-worker-loader') */ + { + loader: 'nativescript-worker-loader' + } + ] + }, /* config.module.rule('ts') */ { test: [ @@ -125,16 +135,6 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR /node_modules/ ] }, - /* config.module.rule('workers') */ - { - test: /\\\\.(js|ts)$/, - use: [ - /* config.module.rule('workers').use('nativescript-worker-loader') */ - { - loader: 'nativescript-worker-loader' - } - ] - }, /* config.module.rule('xml') */ { test: /\\\\.xml$/, @@ -408,13 +408,16 @@ exports[`react configuration > android > base config 1`] = ` options: { platform: 'android' } - }, - /* config.module.rule('bundle').use('nativescript-hot-loader') */ + } + ] + }, + /* config.module.rule('workers') */ + { + test: /\\\\.(js|ts)$/, + use: [ + /* config.module.rule('workers').use('nativescript-worker-loader') */ { - loader: 'nativescript-hot-loader', - options: { - injectHMRRuntime: true - } + loader: 'nativescript-worker-loader' } ] }, @@ -447,16 +450,6 @@ exports[`react configuration > android > base config 1`] = ` /node_modules/ ] }, - /* config.module.rule('workers') */ - { - test: /\\\\.(js|ts)$/, - use: [ - /* config.module.rule('workers').use('nativescript-worker-loader') */ - { - loader: 'nativescript-worker-loader' - } - ] - }, /* config.module.rule('xml') */ { test: /\\\\.xml$/, @@ -729,6 +722,16 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena } ] }, + /* config.module.rule('workers') */ + { + test: /\\\\.(js|ts)$/, + use: [ + /* config.module.rule('workers').use('nativescript-worker-loader') */ + { + loader: 'nativescript-worker-loader' + } + ] + }, /* config.module.rule('ts') */ { test: [ @@ -769,16 +772,6 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena /node_modules/ ] }, - /* config.module.rule('workers') */ - { - test: /\\\\.(js|ts)$/, - use: [ - /* config.module.rule('workers').use('nativescript-worker-loader') */ - { - loader: 'nativescript-worker-loader' - } - ] - }, /* config.module.rule('xml') */ { test: /\\\\.xml$/, @@ -1053,13 +1046,16 @@ exports[`react configuration > ios > base config 1`] = ` options: { platform: 'ios' } - }, - /* config.module.rule('bundle').use('nativescript-hot-loader') */ + } + ] + }, + /* config.module.rule('workers') */ + { + test: /\\\\.(js|ts)$/, + use: [ + /* config.module.rule('workers').use('nativescript-worker-loader') */ { - loader: 'nativescript-hot-loader', - options: { - injectHMRRuntime: true - } + loader: 'nativescript-worker-loader' } ] }, @@ -1092,16 +1088,6 @@ exports[`react configuration > ios > base config 1`] = ` /node_modules/ ] }, - /* config.module.rule('workers') */ - { - test: /\\\\.(js|ts)$/, - use: [ - /* config.module.rule('workers').use('nativescript-worker-loader') */ - { - loader: 'nativescript-worker-loader' - } - ] - }, /* config.module.rule('xml') */ { test: /\\\\.xml$/, diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap index 7e56d0469..1e311c402 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap @@ -76,13 +76,16 @@ exports[`svelte configuration for android 1`] = ` options: { platform: 'android' } - }, - /* config.module.rule('bundle').use('nativescript-hot-loader') */ + } + ] + }, + /* config.module.rule('workers') */ + { + test: /\\\\.(js|ts|svelte)$/, + use: [ + /* config.module.rule('workers').use('nativescript-worker-loader') */ { - loader: 'nativescript-hot-loader', - options: { - injectHMRRuntime: true - } + loader: 'nativescript-worker-loader' } ] }, @@ -114,16 +117,6 @@ exports[`svelte configuration for android 1`] = ` /node_modules/ ] }, - /* config.module.rule('workers') */ - { - test: /\\\\.(js|ts|svelte)$/, - use: [ - /* config.module.rule('workers').use('nativescript-worker-loader') */ - { - loader: 'nativescript-worker-loader' - } - ] - }, /* config.module.rule('xml') */ { test: /\\\\.xml$/, @@ -408,13 +401,16 @@ exports[`svelte configuration for ios 1`] = ` options: { platform: 'ios' } - }, - /* config.module.rule('bundle').use('nativescript-hot-loader') */ + } + ] + }, + /* config.module.rule('workers') */ + { + test: /\\\\.(js|ts|svelte)$/, + use: [ + /* config.module.rule('workers').use('nativescript-worker-loader') */ { - loader: 'nativescript-hot-loader', - options: { - injectHMRRuntime: true - } + loader: 'nativescript-worker-loader' } ] }, @@ -446,16 +442,6 @@ exports[`svelte configuration for ios 1`] = ` /node_modules/ ] }, - /* config.module.rule('workers') */ - { - test: /\\\\.(js|ts|svelte)$/, - use: [ - /* config.module.rule('workers').use('nativescript-worker-loader') */ - { - loader: 'nativescript-worker-loader' - } - ] - }, /* config.module.rule('xml') */ { test: /\\\\.xml$/, diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap index c3ccd94a5..f8807fd5a 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap @@ -72,13 +72,16 @@ exports[`typescript configuration for android 1`] = ` options: { platform: 'android' } - }, - /* config.module.rule('bundle').use('nativescript-hot-loader') */ + } + ] + }, + /* config.module.rule('workers') */ + { + test: /\\\\.(js|ts)$/, + use: [ + /* config.module.rule('workers').use('nativescript-worker-loader') */ { - loader: 'nativescript-hot-loader', - options: { - injectHMRRuntime: true - } + loader: 'nativescript-worker-loader' } ] }, @@ -110,16 +113,6 @@ exports[`typescript configuration for android 1`] = ` /node_modules/ ] }, - /* config.module.rule('workers') */ - { - test: /\\\\.(js|ts)$/, - use: [ - /* config.module.rule('workers').use('nativescript-worker-loader') */ - { - loader: 'nativescript-worker-loader' - } - ] - }, /* config.module.rule('xml') */ { test: /\\\\.xml$/, @@ -183,23 +176,6 @@ exports[`typescript configuration for android 1`] = ` loader: 'sass-loader' } ] - }, - /* config.module.rule('hmr-core') */ - { - test: /\\\\.(js|ts)$/, - exclude: [ - /node_modules/, - '__jest__/src/app.js' - ], - use: [ - /* config.module.rule('hmr-core').use('nativescript-hot-loader') */ - { - loader: 'nativescript-hot-loader', - options: { - appPath: '__jest__/src' - } - } - ] } ] }, @@ -409,13 +385,16 @@ exports[`typescript configuration for ios 1`] = ` options: { platform: 'ios' } - }, - /* config.module.rule('bundle').use('nativescript-hot-loader') */ + } + ] + }, + /* config.module.rule('workers') */ + { + test: /\\\\.(js|ts)$/, + use: [ + /* config.module.rule('workers').use('nativescript-worker-loader') */ { - loader: 'nativescript-hot-loader', - options: { - injectHMRRuntime: true - } + loader: 'nativescript-worker-loader' } ] }, @@ -447,16 +426,6 @@ exports[`typescript configuration for ios 1`] = ` /node_modules/ ] }, - /* config.module.rule('workers') */ - { - test: /\\\\.(js|ts)$/, - use: [ - /* config.module.rule('workers').use('nativescript-worker-loader') */ - { - loader: 'nativescript-worker-loader' - } - ] - }, /* config.module.rule('xml') */ { test: /\\\\.xml$/, @@ -520,23 +489,6 @@ exports[`typescript configuration for ios 1`] = ` loader: 'sass-loader' } ] - }, - /* config.module.rule('hmr-core') */ - { - test: /\\\\.(js|ts)$/, - exclude: [ - /node_modules/, - '__jest__/src/app.js' - ], - use: [ - /* config.module.rule('hmr-core').use('nativescript-hot-loader') */ - { - loader: 'nativescript-hot-loader', - options: { - appPath: '__jest__/src' - } - } - ] } ] }, diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap index 4282ea2d1..ce9e6407f 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap @@ -75,13 +75,16 @@ exports[`vue configuration for android 1`] = ` options: { platform: 'android' } - }, - /* config.module.rule('bundle').use('nativescript-hot-loader') */ + } + ] + }, + /* config.module.rule('workers') */ + { + test: /\\\\.(js|ts)$/, + use: [ + /* config.module.rule('workers').use('nativescript-worker-loader') */ { - loader: 'nativescript-hot-loader', - options: { - injectHMRRuntime: true - } + loader: 'nativescript-worker-loader' } ] }, @@ -116,16 +119,6 @@ exports[`vue configuration for android 1`] = ` /node_modules/ ] }, - /* config.module.rule('workers') */ - { - test: /\\\\.(js|ts)$/, - use: [ - /* config.module.rule('workers').use('nativescript-worker-loader') */ - { - loader: 'nativescript-worker-loader' - } - ] - }, /* config.module.rule('xml') */ { test: /\\\\.xml$/, @@ -420,13 +413,16 @@ exports[`vue configuration for ios 1`] = ` options: { platform: 'ios' } - }, - /* config.module.rule('bundle').use('nativescript-hot-loader') */ + } + ] + }, + /* config.module.rule('workers') */ + { + test: /\\\\.(js|ts)$/, + use: [ + /* config.module.rule('workers').use('nativescript-worker-loader') */ { - loader: 'nativescript-hot-loader', - options: { - injectHMRRuntime: true - } + loader: 'nativescript-worker-loader' } ] }, @@ -461,16 +457,6 @@ exports[`vue configuration for ios 1`] = ` /node_modules/ ] }, - /* config.module.rule('workers') */ - { - test: /\\\\.(js|ts)$/, - use: [ - /* config.module.rule('workers').use('nativescript-worker-loader') */ - { - loader: 'nativescript-worker-loader' - } - ] - }, /* config.module.rule('xml') */ { test: /\\\\.xml$/, diff --git a/packages/webpack5/src/configuration/base.ts b/packages/webpack5/src/configuration/base.ts index 37d85c86d..e618b5d68 100644 --- a/packages/webpack5/src/configuration/base.ts +++ b/packages/webpack5/src/configuration/base.ts @@ -198,12 +198,24 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { .options({ platform, }) - .end() - .use('nativescript-hot-loader') - .loader('nativescript-hot-loader') - .options({ - injectHMRRuntime: true, - }); + .end(); + + config.when(env.hmr, (config) => { + config.module + .rule('bundle') + .use('nativescript-hot-loader') + .loader('nativescript-hot-loader') + .options({ + injectHMRRuntime: true, + }); + }); + + // worker-loader should be declared before ts-loader + config.module + .rule('workers') + .test(/\.(js|ts)$/) + .use('nativescript-worker-loader') + .loader('nativescript-worker-loader'); // set up ts support config.module @@ -249,12 +261,6 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { .exclude.add(/node_modules/) .end(); - config.module - .rule('workers') - .test(/\.(js|ts)$/) - .use('nativescript-worker-loader') - .loader('nativescript-worker-loader'); - // config.resolve.extensions.add('.xml'); // set up xml config.module diff --git a/packages/webpack5/src/configuration/javascript.ts b/packages/webpack5/src/configuration/javascript.ts index 0696e9b7b..ae9eb3ff6 100644 --- a/packages/webpack5/src/configuration/javascript.ts +++ b/packages/webpack5/src/configuration/javascript.ts @@ -34,18 +34,21 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { virtualEntryPath ); - // set up core HMR - config.module - .rule('hmr-core') - .test(/\.js$/) - .exclude.add(/node_modules/) - .add(entryPath) - .end() - .use('nativescript-hot-loader') - .loader('nativescript-hot-loader') - .options({ - appPath: getEntryDirPath(), - }); + config.when(env.hmr, (config) => { + // set up core HMR + config.module + .rule('hmr-core') + .before('js') + .test(/\.js$/) + .exclude.add(/node_modules/) + .add(entryPath) + .end() + .use('nativescript-hot-loader') + .loader('nativescript-hot-loader') + .options({ + appPath: getEntryDirPath(), + }); + }); return config; } diff --git a/packages/webpack5/src/configuration/typescript.ts b/packages/webpack5/src/configuration/typescript.ts index b8b9492a2..539471b03 100644 --- a/packages/webpack5/src/configuration/typescript.ts +++ b/packages/webpack5/src/configuration/typescript.ts @@ -34,18 +34,21 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { virtualEntryPath ); - // set up core HMR - config.module - .rule('hmr-core') - .test(/\.(js|ts)$/) - .exclude.add(/node_modules/) - .add(entryPath) - .end() - .use('nativescript-hot-loader') - .loader('nativescript-hot-loader') - .options({ - appPath: getEntryDirPath(), - }); + config.when(env.hmr, (config) => { + // set up core HMR + config.module + .rule('hmr-core') + .before('ts') + .test(/\.(js|ts)$/) + .exclude.add(/node_modules/) + .add(entryPath) + .end() + .use('nativescript-hot-loader') + .loader('nativescript-hot-loader') + .options({ + appPath: getEntryDirPath(), + }); + }); return config; } From 37cc612263b8904f09ba936f597a52c8688a0d5a Mon Sep 17 00:00:00 2001 From: Adam Bird Date: Mon, 29 Nov 2021 13:17:43 -0500 Subject: [PATCH 17/35] types: cli and hooks types for config (#9625) --- packages/core/config/config.interface.ts | 56 ++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/packages/core/config/config.interface.ts b/packages/core/config/config.interface.ts index 6cf425b79..996979e6c 100644 --- a/packages/core/config/config.interface.ts +++ b/packages/core/config/config.interface.ts @@ -94,6 +94,52 @@ interface IConfigAndroid extends IConfigPlatform { enableMultithreadedJavascript?: boolean; } +interface IConfigCLI { + /** + * Set the package manager to use for this project. + * Defaults to the CLI set package manager, or `npm` if not set globally + */ + packageManager: 'yarn' | 'pnpm' | 'npm'; +} + +interface IConfigHook { + // prettier-ignore + /** + * Event name for when to run the hook. + * Possible event names are any of the following with the pattern + * `before-*` and `after-*` + * + * * `buildAndroidPlugin` - Builds aar file for Android plugin, runs during prepareNativeApp + * * `buildAndroid` - Builds Android app + * * `buildIOS` - Builds iOS app + * * `checkEnvironment` - Validate project env, runs during ns doctor, clean, and most build commands + * * `checkForChanges` - Changes occured during watch + * * `install` - Application installed to device/emulator + * * `prepare` - Compiles webpack and prepares native app in platforms folder + * * `prepareNativeApp` - Preparing the actual native app, runs during prepare/watch hook + * * `resolveCommand` - Resolves command and arguments, runs before all cli commands + * * `watch` - Setup watchers for live sync, runs during prepare hook + * * `watchPatterns` - Setup watch patterns, runs during watch hook + */ + type: + | 'before-buildAndroidPlugin' | 'after-buildAndroidPlugin' + | 'before-buildAndroid' | 'after-buildAndroid' + | 'before-buildIOS' | 'after-buildIOS' + | 'before-checkEnvironment' | 'after-checkEnvironment' + | 'before-checkForChanges' | 'after-checkForChanges' + | 'before-install' | 'after-install' + | 'before-prepare' | 'after-prepare' + | 'before-prepareNativeApp' | 'after-prepareNativeApp' + | 'before-resolveCommand' | 'after-resolveCommand' + | 'before-watch' | 'after-watch' + | 'before-watchPatterns' | 'after-watchPatterns'; + + /** + * Path to the hook script file to run + */ + script: string; +} + export interface NativeScriptConfig { /** * App's bundle id @@ -147,4 +193,14 @@ export interface NativeScriptConfig { * Optionally specify a list of npm package names for which you would like the NativeScript CLI to ignore when attaching native dependencies to the build */ ignoredNativeDependencies?: string[]; + + /** + * Set cli options + */ + cli?: IConfigCLI; + + /** + * Set project persistent hooks to run + */ + hooks?: IConfigHook[]; } From c68f40f8719d34a599d51441c2ad385626b1dd50 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Tue, 30 Nov 2021 12:51:34 -0300 Subject: [PATCH 18/35] feat(webpack): support NG 13 and zone async/await (#9676) * feat(webpack): support NG 13 and zone async/await * chore: cleanup * chore: remove require.resolve and update snapshots Co-authored-by: Igor Randjelovic --- .../__snapshots__/angular.spec.ts.snap | 40 +++++++++++++++++++ .../webpack5/src/configuration/angular.ts | 19 ++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap index 0e9e5f8a2..e02d474aa 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap @@ -178,6 +178,26 @@ exports[`angular configuration for android 1`] = ` } ] }, + /* config.module.rule('angular-webpack-loader') */ + { + test: /\\\\.[cm]?[tj]sx?$/, + exclude: [ + /[/\\\\\\\\](?:core-js|@babel|tslib|web-animations-js|web-streams-polyfill)[/\\\\\\\\]/ + ], + use: [ + /* config.module.rule('angular-webpack-loader').use('webpack-loader') */ + { + loader: '@angular-devkit/build-angular/src/babel/webpack-loader', + options: { + scriptTarget: 99, + aot: true + } + } + ], + resolve: { + fullySpecified: false + } + }, /* config.module.rule('angular') */ { test: /(?:\\\\.ngfactory.js|\\\\.ngstyle\\\\.js|\\\\.ts)$/, @@ -559,6 +579,26 @@ exports[`angular configuration for ios 1`] = ` } ] }, + /* config.module.rule('angular-webpack-loader') */ + { + test: /\\\\.[cm]?[tj]sx?$/, + exclude: [ + /[/\\\\\\\\](?:core-js|@babel|tslib|web-animations-js|web-streams-polyfill)[/\\\\\\\\]/ + ], + use: [ + /* config.module.rule('angular-webpack-loader').use('webpack-loader') */ + { + loader: '@angular-devkit/build-angular/src/babel/webpack-loader', + options: { + scriptTarget: 99, + aot: true + } + } + ], + resolve: { + fullySpecified: false + } + }, /* config.module.rule('angular') */ { test: /(?:\\\\.ngfactory.js|\\\\.ngstyle\\\\.js|\\\\.ts)$/, diff --git a/packages/webpack5/src/configuration/angular.ts b/packages/webpack5/src/configuration/angular.ts index c50754244..629efdaaa 100644 --- a/packages/webpack5/src/configuration/angular.ts +++ b/packages/webpack5/src/configuration/angular.ts @@ -1,5 +1,5 @@ +import { ScriptTarget } from 'typescript'; import { extname, resolve } from 'path'; -import { merge } from 'webpack-merge'; import Config from 'webpack-chain'; import { existsSync } from 'fs'; @@ -167,6 +167,23 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { .use('angular-hot-loader') .loader('angular-hot-loader'); }); + // zone + async/await + config.module + .rule('angular-webpack-loader') + .test(/\.[cm]?[tj]sx?$/) + .exclude.add( + /[/\\](?:core-js|@babel|tslib|web-animations-js|web-streams-polyfill)[/\\]/ + ) + .end() + .resolve.set('fullySpecified', false) + .end() + .before('angular') + .use('webpack-loader') + .loader('@angular-devkit/build-angular/src/babel/webpack-loader') + .options({ + scriptTarget: ScriptTarget.ESNext, + aot: true, + }); } // look for platform specific polyfills first From e8955b4ed4e3c00f0c0e9b3c2df12af47540a8ab Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Tue, 30 Nov 2021 16:53:37 +0100 Subject: [PATCH 19/35] chore(release): @nativescript/webpack 5.0.2-alpha.0 --- .../__tests__/configuration/__snapshots__/react.spec.ts.snap | 4 ++-- packages/webpack5/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap index c875a21e6..8e8aafff9 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap @@ -317,7 +317,7 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR overlay: false, forceEnable: false, exclude: /node_modules/i, - include: /\\\\.([cm]js|[jt]sx?|flow)$/i + include: /\\\\.([jt]sx?|flow)$/i } ) ], @@ -954,7 +954,7 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena overlay: false, forceEnable: false, exclude: /node_modules/i, - include: /\\\\.([cm]js|[jt]sx?|flow)$/i + include: /\\\\.([jt]sx?|flow)$/i } ) ], diff --git a/packages/webpack5/package.json b/packages/webpack5/package.json index 0723d3af3..feeff7e63 100644 --- a/packages/webpack5/package.json +++ b/packages/webpack5/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/webpack", - "version": "5.0.1", + "version": "5.0.2-alpha.0", "private": false, "main": "dist/index.js", "files": [ From e72980c85bfb1d0696734a4f742c77489b35191a Mon Sep 17 00:00:00 2001 From: Osei Fortune Date: Sat, 4 Dec 2021 22:52:51 -0400 Subject: [PATCH 20/35] chore: add WebView disableZoom typing --- packages/core/ui/web-view/index.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/core/ui/web-view/index.d.ts b/packages/core/ui/web-view/index.d.ts index 8a60f1e3a..9a4c15c75 100644 --- a/packages/core/ui/web-view/index.d.ts +++ b/packages/core/ui/web-view/index.d.ts @@ -55,6 +55,11 @@ export class WebView extends View { */ canGoForward: boolean; + /** + * Disable scrolling in the WebView + */ + disableZoom: boolean; + /** * Stops loading the current content (if any). */ From fae6582a61d1e074edfaad0914eb3486165bf7e3 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Fri, 10 Dec 2021 18:31:05 -0300 Subject: [PATCH 21/35] fix(webpack): prepend NativeClass transformer in angular config (#9698) This fixes angular JIT compilation --- packages/webpack5/src/configuration/angular.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/webpack5/src/configuration/angular.ts b/packages/webpack5/src/configuration/angular.ts index 629efdaaa..aa591cf50 100644 --- a/packages/webpack5/src/configuration/angular.ts +++ b/packages/webpack5/src/configuration/angular.ts @@ -148,7 +148,9 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { if (!transformers.before) { transformers.before = []; } - transformers.before.push(require('../transformers/NativeClass').default); + transformers.before.unshift( + require('../transformers/NativeClass').default + ); args[1] = transformers; return originalCreateFileEmitter.apply(this, args); }; From 5cf948688e1195707886aed6660244f020567670 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Fri, 10 Dec 2021 22:32:55 +0100 Subject: [PATCH 22/35] chore: update snapshots --- .../__tests__/configuration/__snapshots__/react.spec.ts.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap index 8e8aafff9..c875a21e6 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap @@ -317,7 +317,7 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR overlay: false, forceEnable: false, exclude: /node_modules/i, - include: /\\\\.([jt]sx?|flow)$/i + include: /\\\\.([cm]js|[jt]sx?|flow)$/i } ) ], @@ -954,7 +954,7 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena overlay: false, forceEnable: false, exclude: /node_modules/i, - include: /\\\\.([jt]sx?|flow)$/i + include: /\\\\.([cm]js|[jt]sx?|flow)$/i } ) ], From 3c1264dcefa1ec9e67117f76255f41725d0683ad Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Fri, 10 Dec 2021 18:31:05 -0300 Subject: [PATCH 23/35] fix(webpack): prepend NativeClass transformer in angular config (#9698) This fixes angular JIT compilation --- packages/webpack5/src/configuration/angular.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/webpack5/src/configuration/angular.ts b/packages/webpack5/src/configuration/angular.ts index c50754244..187d83c7b 100644 --- a/packages/webpack5/src/configuration/angular.ts +++ b/packages/webpack5/src/configuration/angular.ts @@ -148,7 +148,9 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { if (!transformers.before) { transformers.before = []; } - transformers.before.push(require('../transformers/NativeClass').default); + transformers.before.unshift( + require('../transformers/NativeClass').default + ); args[1] = transformers; return originalCreateFileEmitter.apply(this, args); }; From efaa0e52d279cd65668395f7fe1d7a05211c5989 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Fri, 10 Dec 2021 22:38:43 +0100 Subject: [PATCH 24/35] chore(release): @nativescript/webpack 5.0.2 --- packages/webpack5/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webpack5/package.json b/packages/webpack5/package.json index a25caf2d1..0208cd280 100644 --- a/packages/webpack5/package.json +++ b/packages/webpack5/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/webpack", - "version": "5.0.1", + "version": "5.0.2", "private": false, "main": "dist/index.js", "files": [ From 00a5b5bc7d54e5fc49219fccb7aaf64c4799e7f7 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Fri, 10 Dec 2021 22:39:55 +0100 Subject: [PATCH 25/35] chore: update snapshots --- .../__tests__/configuration/__snapshots__/react.spec.ts.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap index 10de0bf00..102570df6 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap @@ -317,7 +317,7 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR overlay: false, forceEnable: false, exclude: /node_modules/i, - include: /\\\\.([jt]sx?|flow)$/i + include: /\\\\.([cm]js|[jt]sx?|flow)$/i } ) ], @@ -961,7 +961,7 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena overlay: false, forceEnable: false, exclude: /node_modules/i, - include: /\\\\.([jt]sx?|flow)$/i + include: /\\\\.([cm]js|[jt]sx?|flow)$/i } ) ], From 80d92dbc5b9b95c04463752a1399df63299065c5 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Fri, 10 Dec 2021 22:43:52 +0100 Subject: [PATCH 26/35] chore(release): @nativescript/webpack 5.0.2-alpha.1 --- packages/webpack5/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webpack5/package.json b/packages/webpack5/package.json index feeff7e63..efe0c2228 100644 --- a/packages/webpack5/package.json +++ b/packages/webpack5/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/webpack", - "version": "5.0.2-alpha.0", + "version": "5.0.2-alpha.1", "private": false, "main": "dist/index.js", "files": [ From c2f87395938c317dd933219e438c77b319948329 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Wed, 15 Dec 2021 22:11:25 +0100 Subject: [PATCH 27/35] chore: fix feature request template --- .github/ISSUE_TEMPLATE/feature_request.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml index 2558c2d49..19c5528be 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yaml +++ b/.github/ISSUE_TEMPLATE/feature_request.yaml @@ -63,6 +63,7 @@ body: - type: checkboxes id: terms attributes: + label: Please accept these terms options: - label: I have searched the [existing issues](https://github.com/NativeScript/NativeScript/issues) as well as [StackOverflow](https://stackoverflow.com/questions/tagged/nativescript) and this has not been posted before required: true From 04c0f8783d9fc803f256ee8d259e68118910f912 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Wed, 15 Dec 2021 22:11:43 +0100 Subject: [PATCH 28/35] chore: fix bug report template --- .github/ISSUE_TEMPLATE/bug_report.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 026b0c635..5b8192ca7 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -104,6 +104,7 @@ body: - type: checkboxes id: terms attributes: + label: Please accept these terms options: - label: I have searched the [existing issues](https://github.com/NativeScript/NativeScript/issues) as well as [StackOverflow](https://stackoverflow.com/questions/tagged/nativescript) and this has not been posted before required: true From a88cacab89b52418661e01e0617c47fd845931fa Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Tue, 21 Dec 2021 18:47:33 +0100 Subject: [PATCH 29/35] chore(migrate): apps/* to webpack5 (#9606) --- .gitignore | 1 + apps/automated/.gitignore | 2 +- apps/automated/nativescript.config.ts | 3 +- apps/automated/package.json | 2 +- apps/automated/src/app.css | 0 apps/automated/src/http/http-string-worker.ts | 5 ++ apps/automated/src/http/http-tests.ts | 5 +- .../src/name-resolvers-tests/files/other.xml | 2 +- .../name-resolvers-tests/files/test.land.xml | 2 +- .../files/test.minWH600.xml | 2 +- .../src/name-resolvers-tests/files/test.xml | 2 +- apps/automated/src/package.json | 3 - apps/automated/src/ui/button/button-tests.ts | 18 ++-- .../src/ui/core/bindable/bindable-tests.ts | 89 ++++++++++--------- .../weak-event-listener-tests.ts | 68 +++++++------- .../src/ui/label/label-tests-wrong-page.css | 4 +- apps/automated/src/ui/label/label-tests.ts | 16 ++-- .../src/ui/lifecycle/lifecycle-tests.ts | 33 +++---- .../src/ui/list-view/list-view-tests.ts | 28 +++--- .../root-modules/custom-component-root.xml | 2 +- apps/automated/src/ui/styling/style-tests.ts | 21 ++--- .../ui/tab-view/tab-view-tests-native.ios.ts | 13 ++- .../src/ui/text-field/text-field-tests.ts | 18 ++-- .../src/ui/text-view/text-view-tests.ts | 18 ++-- .../src/xml-declaration/mymodule/package.json | 4 - apps/automated/webpack.config.js | 21 +++++ apps/automated/webpack.custom.config.js | 22 ----- apps/toolbox/.gitignore | 2 +- apps/toolbox/nativescript.config.ts | 3 +- apps/toolbox/package.json | 2 +- ....android.css => _app-platform.android.css} | 0 ...platform.ios.css => _app-platform.ios.css} | 0 apps/toolbox/src/app.css | 4 +- apps/toolbox/webpack.config.js | 19 ++++ apps/toolbox/webpack.custom.config.js | 18 ---- apps/ui/.gitignore | 2 +- apps/ui/nativescript.config.ts | 3 +- apps/ui/package.json | 2 +- apps/ui/src/css/styles-page.css | 5 +- apps/ui/tsconfig.json | 17 ++-- apps/ui/webpack.config.js | 20 +++++ apps/ui/webpack.custom.config.js | 18 ---- package.json | 5 +- packages/core/debugger/dom-node.ts | 2 +- packages/core/ui/builder/xml2ui.ts | 8 +- packages/core/ui/core/bindable/index.ts | 6 +- packages/core/ui/styling/style-scope.ts | 18 ++-- .../__snapshots__/angular.spec.ts.snap | 56 +++++++++--- .../__snapshots__/base.spec.ts.snap | 36 ++++++-- .../__snapshots__/javascript.spec.ts.snap | 36 ++++++-- .../__snapshots__/react.spec.ts.snap | 72 +++++++++++---- .../__snapshots__/svelte.spec.ts.snap | 36 ++++++-- .../__snapshots__/typescript.spec.ts.snap | 36 ++++++-- .../__snapshots__/vue.spec.ts.snap | 36 ++++++-- .../loaders/xml-namespace-loader.spec.ts | 72 +++++++-------- .../webpack5/src/configuration/angular.ts | 6 +- packages/webpack5/src/configuration/base.ts | 39 +++++++- .../webpack5/src/configuration/javascript.ts | 2 +- .../webpack5/src/configuration/typescript.ts | 2 +- .../src/loaders/xml-namespace-loader/index.ts | 19 ++-- tools/scripts/pack-webpack5.mjs | 25 ++++++ workspace.json | 16 +--- 62 files changed, 643 insertions(+), 404 deletions(-) delete mode 100644 apps/automated/src/app.css delete mode 100644 apps/automated/src/package.json delete mode 100644 apps/automated/src/xml-declaration/mymodule/package.json create mode 100644 apps/automated/webpack.config.js delete mode 100644 apps/automated/webpack.custom.config.js rename apps/toolbox/src/{app-platform.android.css => _app-platform.android.css} (100%) rename apps/toolbox/src/{app-platform.ios.css => _app-platform.ios.css} (100%) create mode 100644 apps/toolbox/webpack.config.js delete mode 100644 apps/toolbox/webpack.custom.config.js create mode 100644 apps/ui/webpack.config.js delete mode 100644 apps/ui/webpack.custom.config.js create mode 100755 tools/scripts/pack-webpack5.mjs diff --git a/.gitignore b/.gitignore index 9143c0795..c29b090ad 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ **/package-lock.json **/yarn.lock **/pnpm-lock.yaml +.npmrc # IDEs and editors .idea diff --git a/apps/automated/.gitignore b/apps/automated/.gitignore index a6a2bfdd5..512c68e15 100644 --- a/apps/automated/.gitignore +++ b/apps/automated/.gitignore @@ -1 +1 @@ -!webpack.custom.config.js +!webpack.config.js diff --git a/apps/automated/nativescript.config.ts b/apps/automated/nativescript.config.ts index e69de915a..413b3e554 100644 --- a/apps/automated/nativescript.config.ts +++ b/apps/automated/nativescript.config.ts @@ -2,10 +2,9 @@ import { NativeScriptConfig } from '@nativescript/core'; export default { id: 'org.nativescript.UnitTestApp', + appPath: 'src', appResourcesPath: '../../tools/assets/App_Resources', - webpackConfigPath: 'webpack.custom.config.js', android: { v8Flags: '--expose_gc', - markingMode: 'none', }, } as NativeScriptConfig; diff --git a/apps/automated/package.json b/apps/automated/package.json index 2c270a37f..414312b7d 100644 --- a/apps/automated/package.json +++ b/apps/automated/package.json @@ -1,5 +1,5 @@ { - "main": "main.js", + "main": "src/main.ts", "description": "NativeScript Application", "license": "MIT", "repository": { diff --git a/apps/automated/src/app.css b/apps/automated/src/app.css deleted file mode 100644 index e69de29bb..000000000 diff --git a/apps/automated/src/http/http-string-worker.ts b/apps/automated/src/http/http-string-worker.ts index 629acf1d6..a45ebb62d 100644 --- a/apps/automated/src/http/http-string-worker.ts +++ b/apps/automated/src/http/http-string-worker.ts @@ -1,3 +1,8 @@ +// todo: figure out why this worker is including the whole core and not just the Http module +// ie. tree-shaking is not working as expected here. (same setup works in a separate app) +import { initGlobal } from '@nativescript/core/globals/index'; +initGlobal(); + import { Http } from '@nativescript/core'; declare var postMessage: any; diff --git a/apps/automated/src/http/http-tests.ts b/apps/automated/src/http/http-tests.ts index d60eafbf1..344c6fc25 100644 --- a/apps/automated/src/http/http-tests.ts +++ b/apps/automated/src/http/http-tests.ts @@ -689,15 +689,14 @@ export var test_request_jsonAsContentSentAndReceivedProperly = function (done) { }; export var test_getString_WorksProperlyInWorker = function (done) { - const HttpStringWorker = require('nativescript-worker-loader!./http-string-worker'); - let worker = new HttpStringWorker(); + const worker = new Worker('./http-string-worker'); console.log('Worker Created'); worker.onmessage = function (msg) { console.log('Message received'); done(); }; worker.onerror = function (e) { - console.log('error received'); + console.log('Error received'); done(e); }; }; diff --git a/apps/automated/src/name-resolvers-tests/files/other.xml b/apps/automated/src/name-resolvers-tests/files/other.xml index 07baef738..79919a7a8 100644 --- a/apps/automated/src/name-resolvers-tests/files/other.xml +++ b/apps/automated/src/name-resolvers-tests/files/other.xml @@ -1 +1 @@ -other.xml + diff --git a/apps/automated/src/name-resolvers-tests/files/test.land.xml b/apps/automated/src/name-resolvers-tests/files/test.land.xml index 0f2b16d84..b2a58d383 100644 --- a/apps/automated/src/name-resolvers-tests/files/test.land.xml +++ b/apps/automated/src/name-resolvers-tests/files/test.land.xml @@ -1 +1 @@ -test.minWH300.xml + diff --git a/apps/automated/src/name-resolvers-tests/files/test.minWH600.xml b/apps/automated/src/name-resolvers-tests/files/test.minWH600.xml index a4af10111..c8faaf81d 100644 --- a/apps/automated/src/name-resolvers-tests/files/test.minWH600.xml +++ b/apps/automated/src/name-resolvers-tests/files/test.minWH600.xml @@ -1 +1 @@ -test.monWH450.xml + diff --git a/apps/automated/src/name-resolvers-tests/files/test.xml b/apps/automated/src/name-resolvers-tests/files/test.xml index a6535f35d..492c17a0e 100644 --- a/apps/automated/src/name-resolvers-tests/files/test.xml +++ b/apps/automated/src/name-resolvers-tests/files/test.xml @@ -1 +1 @@ -test.xml + diff --git a/apps/automated/src/package.json b/apps/automated/src/package.json deleted file mode 100644 index a60376465..000000000 --- a/apps/automated/src/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "main": "main.js" -} \ No newline at end of file diff --git a/apps/automated/src/ui/button/button-tests.ts b/apps/automated/src/ui/button/button-tests.ts index 8e3c68807..4d56c61a4 100644 --- a/apps/automated/src/ui/button/button-tests.ts +++ b/apps/automated/src/ui/button/button-tests.ts @@ -64,15 +64,15 @@ export var testNativeBackgroundColorFromLocal = function () { helper.buildUIAndRunTest(_createButtonFunc(), _testNativeBackgroundColorFromLocal); }; -export var testMemoryLeak = function (done) { - helper.buildUIWithWeakRefAndInteract( - _createButtonFunc, - function (button) { - buttonTestsNative.performNativeClick(button); - }, - done - ); -}; +// export var testMemoryLeak = function (done) { +// helper.buildUIWithWeakRefAndInteract( +// _createButtonFunc, +// function (button) { +// buttonTestsNative.performNativeClick(button); +// }, +// done +// ); +// }; var _createButtonFunc = function (): Button { // >>button-create diff --git a/apps/automated/src/ui/core/bindable/bindable-tests.ts b/apps/automated/src/ui/core/bindable/bindable-tests.ts index 8e67984a1..10e6b6edb 100644 --- a/apps/automated/src/ui/core/bindable/bindable-tests.ts +++ b/apps/automated/src/ui/core/bindable/bindable-tests.ts @@ -191,60 +191,63 @@ export function test_bindingContext_Change_IsReflected_Properly() { helper.do_PageTest_WithButton(test); } -export function test_WhenBindingIsSetToAnElement_AndElementIsRemoved_ShouldBeCollectedByGC(done) { - let testFinished = false; +// disabled test because in latest v8 engine we rely on built-in WeakRef implementation +// which does not guarantee releasing objects after a GC call. - let page = helper.getCurrentPage(); - let stack = new StackLayout(); +// export function test_WhenBindingIsSetToAnElement_AndElementIsRemoved_ShouldBeCollectedByGC(done) { +// let testFinished = false; - let expectedValue = 'testValue'; - let sourcePropertyName = 'testProperty'; - let targetPropertyName = 'text'; +// let page = helper.getCurrentPage(); +// let stack = new StackLayout(); - stack.on(View.loadedEvent, () => { - const model = new Observable(); - model.set(sourcePropertyName, expectedValue); +// let expectedValue = 'testValue'; +// let sourcePropertyName = 'testProperty'; +// let targetPropertyName = 'text'; - function createButton(bindContext) { - let button = new Button(); - button.bind( - { - sourceProperty: sourcePropertyName, - targetProperty: targetPropertyName, - }, - bindContext - ); +// stack.on(View.loadedEvent, () => { +// const model = new Observable(); +// model.set(sourcePropertyName, expectedValue); - return new WeakRef(button); - } +// function createButton(bindContext) { +// let button = new Button(); +// button.bind( +// { +// sourceProperty: sourcePropertyName, +// targetProperty: targetPropertyName, +// }, +// bindContext +// ); - const weakRef = createButton(model); +// return new WeakRef(button); +// } - try { - stack.addChild(weakRef.get()); - TKUnit.waitUntilReady(() => weakRef.get().isLoaded); +// const weakRef = createButton(model); - TKUnit.assertEqual(weakRef.get().text, expectedValue, 'Binding is not working properly!'); - stack.removeChild(weakRef.get()); - TKUnit.waitUntilReady(() => !weakRef.get().isLoaded); +// try { +// stack.addChild(weakRef.get()); +// TKUnit.waitUntilReady(() => weakRef.get().isLoaded); - utils.GC(); - // Give time for the GC to kick in - setTimeout(() => { - utils.GC(); - TKUnit.assert(!weakRef.get(), 'UIElement is still alive!'); - testFinished = true; - }, 100); - } catch (e) { - done(e); - } - }); +// TKUnit.assertEqual(weakRef.get().text, expectedValue, 'Binding is not working properly!'); +// stack.removeChild(weakRef.get()); +// TKUnit.waitUntilReady(() => !weakRef.get().isLoaded); - page.content = stack; +// utils.GC(); +// // Give time for the GC to kick in +// setTimeout(() => { +// utils.GC(); +// TKUnit.assert(!weakRef.get(), 'UIElement is still alive!'); +// testFinished = true; +// }, 100); +// } catch (e) { +// done(e); +// } +// }); - TKUnit.waitUntilReady(() => testFinished); - done(null); -} +// page.content = stack; + +// TKUnit.waitUntilReady(() => testFinished); +// done(null); +// } export function test_OneBindableToBindMoreThanOneProperty_ToSameSource() { const model = new Observable(); diff --git a/apps/automated/src/ui/core/weak-event-listener/weak-event-listener-tests.ts b/apps/automated/src/ui/core/weak-event-listener/weak-event-listener-tests.ts index 9edb26b7e..d535584d0 100644 --- a/apps/automated/src/ui/core/weak-event-listener/weak-event-listener-tests.ts +++ b/apps/automated/src/ui/core/weak-event-listener/weak-event-listener-tests.ts @@ -93,43 +93,47 @@ function getTargetAsWeakRef(): WeakRef { return new WeakRef(new Target()); } -export function test_listenerDoesNotRetainTarget(done) { - const sourceRef = getSourceAsWeakRef(); - const targetRef = getTargetAsWeakRef(); +// commented out tests because the latest v8 runtime uses the built-in WeakRef implementation +// which does not guarantee releases after a GC call - it uses heuristics to determine when +// a WeakRef should be released - so we don't really need to test this. - // with the v8 6.5 the GC does not release WeakRefs so fast if you pass them to a method - // that's why we are making the call to the addWeakEventListener in a closure so that the WeakRef will be easier released - (function () { - addWeakEventListener(sourceRef.get(), Observable.propertyChangeEvent, emptyHandler, targetRef.get()); - })(); - forceGC(); +// export function test_listenerDoesNotRetainTarget(done) { +// const sourceRef = getSourceAsWeakRef(); +// const targetRef = getTargetAsWeakRef(); - try { - TKUnit.assert(!targetRef.get(), 'Target should be released after GC'); - done(null); - } catch (e) { - done(e); - } -} +// // with the v8 6.5 the GC does not release WeakRefs so fast if you pass them to a method +// // that's why we are making the call to the addWeakEventListener in a closure so that the WeakRef will be easier released +// (function () { +// addWeakEventListener(sourceRef.get(), Observable.propertyChangeEvent, emptyHandler, targetRef.get()); +// })(); +// forceGC(); -export function test_listenerDoesNotRetainSource(done) { - const sourceRef = getSourceAsWeakRef(); - const targetRef = getTargetAsWeakRef(); +// try { +// TKUnit.assert(!targetRef.get(), 'Target should be released after GC'); +// done(null); +// } catch (e) { +// done(e); +// } +// } - // with the v8 6.5 the GC does not release WeakRefs so fast if you pass them to a method - // that's why we are making the call to the addWeakEventListener in a closure so that the WeakRef will be easier released - (function () { - addWeakEventListener(sourceRef.get(), Observable.propertyChangeEvent, targetRef.get().onEvent, targetRef.get()); - })(); - forceGC(); +// export function test_listenerDoesNotRetainSource(done) { +// const sourceRef = getSourceAsWeakRef(); +// const targetRef = getTargetAsWeakRef(); - try { - TKUnit.assert(!sourceRef.get(), 'Source should be released after GC'); - done(null); - } catch (e) { - done(e); - } -} +// // with the v8 6.5 the GC does not release WeakRefs so fast if you pass them to a method +// // that's why we are making the call to the addWeakEventListener in a closure so that the WeakRef will be easier released +// (function () { +// addWeakEventListener(sourceRef.get(), Observable.propertyChangeEvent, targetRef.get().onEvent, targetRef.get()); +// })(); +// forceGC(); + +// try { +// TKUnit.assert(!sourceRef.get(), 'Source should be released after GC'); +// done(null); +// } catch (e) { +// done(e); +// } +// } export function test_handlerIsDetached_WhenAllListenersAreRemoved() { const source = new Observable(); diff --git a/apps/automated/src/ui/label/label-tests-wrong-page.css b/apps/automated/src/ui/label/label-tests-wrong-page.css index 1b71ea07c..860a586f4 100644 --- a/apps/automated/src/ui/label/label-tests-wrong-page.css +++ b/apps/automated/src/ui/label/label-tests-wrong-page.css @@ -1,3 +1,3 @@ -label { +/* label { < !--Test wrong comment-->background-color: red; -} +} */ diff --git a/apps/automated/src/ui/label/label-tests.ts b/apps/automated/src/ui/label/label-tests.ts index a9b28d871..3ad6bafea 100644 --- a/apps/automated/src/ui/label/label-tests.ts +++ b/apps/automated/src/ui/label/label-tests.ts @@ -545,15 +545,15 @@ export class LabelTest extends testModule.UITest { TKUnit.assertEqual(actualResult, this.expectedTextAlignment); } - public testErrorMessageWhenWrongCssIsAddedWithFile() { - const view = this.testView; - const page = this.testPage; - this.waitUntilTestElementIsLoaded(); + // public testErrorMessageWhenWrongCssIsAddedWithFile() { + // const view = this.testView; + // const page = this.testPage; + // this.waitUntilTestElementIsLoaded(); - view.id = 'testLabel'; - page.addCssFile(fs.path.join(testDir, 'label-tests-wrong-page.css')); - TKUnit.assertNotEqual(this.errorMessage, undefined); - } + // view.id = 'testLabel'; + // page.addCssFile(fs.path.join(testDir, 'label-tests-wrong-page.css')); + // TKUnit.assertNotEqual(this.errorMessage, undefined); + // } // public testErrorMessageWhenWrongCssIsAdded() { // const view = this.testView; diff --git a/apps/automated/src/ui/lifecycle/lifecycle-tests.ts b/apps/automated/src/ui/lifecycle/lifecycle-tests.ts index 92f7a8309..7457cc6d9 100644 --- a/apps/automated/src/ui/lifecycle/lifecycle-tests.ts +++ b/apps/automated/src/ui/lifecycle/lifecycle-tests.ts @@ -75,26 +75,29 @@ export function test_setting_one_property_while_suspedned_does_not_call_other_pr TKUnit.assertEqual(btn1.fontInternalSetNativeCount, 2, 'fontInternal.setNative at step4'); } -export function test_css_properties_reset_only_once() { - const page = helper.navigateToModule('ui/lifecycle/pages/page-one'); - const btn2 = page.getViewById('btn2'); +// +// Commented out because in webpack5 css loading has been rewritten, and does not use page.css +// +// export function test_css_properties_reset_only_once() { +// const page = helper.navigateToModule('ui/lifecycle/pages/page-one'); +// const btn2 = page.getViewById('btn2'); - TKUnit.assertEqual(btn2.backgroundInternalSetNativeCount, 1, `Expected ${btn2.id}'s backgroundInternal.setNative to be exactly once when inflating from xml.`); - TKUnit.assertEqual(btn2.fontInternalSetNativeCount, 1, `Expected ${btn2.id}'s fontInternal.setNative to be called exactly once when inflating from xml.`); - TKUnit.assertEqual(btn2.nativeBackgroundRedraws, 1, `Expected ${btn2.id}'s native background to propagated exactly once when inflating from xml.`); +// TKUnit.assertEqual(btn2.backgroundInternalSetNativeCount, 1, `1: Expected ${btn2.id}'s backgroundInternal.setNative to be exactly once when inflating from xml.`); +// TKUnit.assertEqual(btn2.fontInternalSetNativeCount, 1, `1: Expected ${btn2.id}'s fontInternal.setNative to be called exactly once when inflating from xml.`); +// TKUnit.assertEqual(btn2.nativeBackgroundRedraws, 1, `1: Expected ${btn2.id}'s native background to propagated exactly once when inflating from xml.`); - page.css = ''; +// page.css = ''; - TKUnit.assertEqual(btn2.backgroundInternalSetNativeCount, 2, `Expected ${btn2.id}'s backgroundInternal.setNative to be exactly once when inflating from xml.`); - TKUnit.assertEqual(btn2.fontInternalSetNativeCount, 2, `Expected ${btn2.id}'s fontInternal.setNative to be called exactly once when inflating from xml.`); - TKUnit.assertEqual(btn2.nativeBackgroundRedraws, isIOS ? 1 : 2, `Expected ${btn2.id}'s native background to propagated exactly once when inflating from xml.`); +// TKUnit.assertEqual(btn2.backgroundInternalSetNativeCount, 2, `2: Expected ${btn2.id}'s backgroundInternal.setNative to be exactly once when inflating from xml.`); +// TKUnit.assertEqual(btn2.fontInternalSetNativeCount, 2, `2: Expected ${btn2.id}'s fontInternal.setNative to be called exactly once when inflating from xml.`); +// TKUnit.assertEqual(btn2.nativeBackgroundRedraws, isIOS ? 1 : 2, `2: Expected ${btn2.id}'s native background to propagated exactly once when inflating from xml.`); - helper.waitUntilLayoutReady(btn2); +// helper.waitUntilLayoutReady(btn2); - TKUnit.assertEqual(btn2.backgroundInternalSetNativeCount, 2, `Expected ${btn2.id}'s backgroundInternal.setNative to be exactly once when inflating from xml.`); - TKUnit.assertEqual(btn2.fontInternalSetNativeCount, 2, `Expected ${btn2.id}'s fontInternal.setNative to be called exactly once when inflating from xml.`); - TKUnit.assertEqual(btn2.nativeBackgroundRedraws, 2, `Expected ${btn2.id}'s native background to propagated exactly once when inflating from xml.`); -} +// TKUnit.assertEqual(btn2.backgroundInternalSetNativeCount, 2, `3: Expected ${btn2.id}'s backgroundInternal.setNative to be exactly once when inflating from xml.`); +// TKUnit.assertEqual(btn2.fontInternalSetNativeCount, 2, `3: Expected ${btn2.id}'s fontInternal.setNative to be called exactly once when inflating from xml.`); +// TKUnit.assertEqual(btn2.nativeBackgroundRedraws, 2, `3: Expected ${btn2.id}'s native background to propagated exactly once when inflating from xml.`); +// } export function test_navigating_away_does_not_excessively_reset() { const page = helper.navigateToModule('ui/lifecycle/pages/page-one'); diff --git a/apps/automated/src/ui/list-view/list-view-tests.ts b/apps/automated/src/ui/list-view/list-view-tests.ts index a748f44ec..4e32eeef0 100644 --- a/apps/automated/src/ui/list-view/list-view-tests.ts +++ b/apps/automated/src/ui/list-view/list-view-tests.ts @@ -753,19 +753,23 @@ export class ListViewTest extends UITest { private assertNoMemoryLeak(weakRef: WeakRef) { this.tearDown(); - TKUnit.waitUntilReady(() => { - if (isIOS) { - /* tslint:disable:no-unused-expression */ - // Could cause GC on the next call. - // NOTE: Don't replace this with forceGC(); - new ArrayBuffer(4 * 1024 * 1024); - } - Utils.GC(); + // + // commented out because with latest engines we use the built-in v8 WeakRef implementation + // which does not guarantee releases after a GC pass. + // + // TKUnit.waitUntilReady(() => { + // if (isIOS) { + // /* tslint:disable:no-unused-expression */ + // // Could cause GC on the next call. + // // NOTE: Don't replace this with forceGC(); + // new ArrayBuffer(4 * 1024 * 1024); + // } + // Utils.GC(); + // + // return !weakRef.get(); + // }); - return !weakRef.get(); - }); - - TKUnit.assert(!weakRef.get(), weakRef.get() + ' leaked!'); + // TKUnit.assert(!weakRef.get(), weakRef.get() + ' leaked!'); } private loadViewWithItemNumber(args: ItemEventData) { diff --git a/apps/automated/src/ui/root-view/root-modules/custom-component-root.xml b/apps/automated/src/ui/root-view/root-modules/custom-component-root.xml index 5687d7512..9f5185bdc 100644 --- a/apps/automated/src/ui/root-view/root-modules/custom-component-root.xml +++ b/apps/automated/src/ui/root-view/root-modules/custom-component-root.xml @@ -1,2 +1,2 @@ - + diff --git a/apps/automated/src/ui/styling/style-tests.ts b/apps/automated/src/ui/styling/style-tests.ts index a40eb38ba..3a70b7837 100644 --- a/apps/automated/src/ui/styling/style-tests.ts +++ b/apps/automated/src/ui/styling/style-tests.ts @@ -679,21 +679,22 @@ export function test_CSS_isAppliedOnPage_From_Import() { helper.buildUIAndRunTest(testButton, function (views: Array) { const page: Page = views[1]; - page.css = "@import url('ui/styling/test-page.css');"; + // page.css = "@import url('ui/styling/test-page.css');"; + page.addCssFile('ui/styling/test-page.css'); helper.assertViewBackgroundColor(page, '#FF0000'); }); } -export function test_CSS_isAppliedOnPage_From_Import_Without_Url() { - const testButton = new Button(); - testButton.text = 'Test'; +// export function test_CSS_isAppliedOnPage_From_Import_Without_Url() { +// const testButton = new Button(); +// testButton.text = 'Test'; - helper.buildUIAndRunTest(testButton, function (views: Array) { - const page: Page = views[1]; - page.css = "@import 'ui/styling/test-page.css';"; - helper.assertViewBackgroundColor(page, '#FF0000'); - }); -} +// helper.buildUIAndRunTest(testButton, function (views: Array) { +// const page: Page = views[1]; +// page.css = "@import 'ui/styling/test-page.css';"; +// helper.assertViewBackgroundColor(page, '#FF0000'); +// }); +// } export function test_CSS_isAppliedOnPage_From_addCssFile() { const testButton = new Button(); diff --git a/apps/automated/src/ui/tab-view/tab-view-tests-native.ios.ts b/apps/automated/src/ui/tab-view/tab-view-tests-native.ios.ts index 080f36607..080a52220 100644 --- a/apps/automated/src/ui/tab-view/tab-view-tests-native.ios.ts +++ b/apps/automated/src/ui/tab-view/tab-view-tests-native.ios.ts @@ -1,7 +1,6 @@ -import tabViewModule = require('@nativescript/core/ui/tab-view'); -import { Font } from '@nativescript/core/ui/styling/font'; +import { Font, TabView } from '@nativescript/core'; -export function getNativeTabCount(tabView: tabViewModule.TabView): number { +export function getNativeTabCount(tabView: TabView): number { if (!tabView.ios.viewControllers) { return 0; } @@ -9,16 +8,16 @@ export function getNativeTabCount(tabView: tabViewModule.TabView): number { return tabView.ios.viewControllers.count; } -export function selectNativeTab(tabView: tabViewModule.TabView, index: number): void { +export function selectNativeTab(tabView: TabView, index: number): void { tabView.ios.selectedIndex = index; tabView.ios.delegate.tabBarControllerDidSelectViewController(tabView.ios, tabView.ios.selectedViewController); } -export function getNativeSelectedIndex(tabView: tabViewModule.TabView): number { +export function getNativeSelectedIndex(tabView: TabView): number { return tabView.ios.selectedIndex; } -export function getNativeFont(tabView: tabViewModule.TabView): UIFont { +export function getNativeFont(tabView: TabView): UIFont { const tabBar = tabView.ios.tabBar; if (tabBar.items.count > 0) { const currentAttrs = tabBar.items[0].titleTextAttributesForState(UIControlState.Normal); @@ -30,6 +29,6 @@ export function getNativeFont(tabView: tabViewModule.TabView): UIFont { return null; } -export function getOriginalFont(tabView: tabViewModule.TabView): UIFont { +export function getOriginalFont(tabView: TabView): UIFont { return (tabView.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(10)); } diff --git a/apps/automated/src/ui/text-field/text-field-tests.ts b/apps/automated/src/ui/text-field/text-field-tests.ts index 89ae45ed5..46b656b1a 100644 --- a/apps/automated/src/ui/text-field/text-field-tests.ts +++ b/apps/automated/src/ui/text-field/text-field-tests.ts @@ -619,15 +619,15 @@ export var testNativeTextAlignmentFromLocal = function () { }); }; -export var testMemoryLeak = function (done) { - helper.buildUIWithWeakRefAndInteract( - _createTextFieldFunc, - function (textField) { - typeTextNatively(textField, 'Hello, world!'); - }, - done - ); -}; +// export var testMemoryLeak = function (done) { +// helper.buildUIWithWeakRefAndInteract( +// _createTextFieldFunc, +// function (textField) { +// typeTextNatively(textField, 'Hello, world!'); +// }, +// done +// ); +// }; export var test_WhenFormattedTextPropertyChanges_TextIsUpdated_TextBase = function () { var firstSpan = new Span(); diff --git a/apps/automated/src/ui/text-view/text-view-tests.ts b/apps/automated/src/ui/text-view/text-view-tests.ts index 692269d4f..21996144e 100644 --- a/apps/automated/src/ui/text-view/text-view-tests.ts +++ b/apps/automated/src/ui/text-view/text-view-tests.ts @@ -508,15 +508,15 @@ export var testNativeTextAlignmentFromLocal = function () { }); }; -export var testMemoryLeak = function (done) { - helper.buildUIWithWeakRefAndInteract( - _createTextViewFunc, - function (textView) { - textViewTestsNative.typeTextNatively(textView, 'Hello, world!'); - }, - done - ); -}; +// export var testMemoryLeak = function (done) { +// helper.buildUIWithWeakRefAndInteract( +// _createTextViewFunc, +// function (textView) { +// textViewTestsNative.typeTextNatively(textView, 'Hello, world!'); +// }, +// done +// ); +// }; export function test_watch_listerer_is_removed_at_onDetach() { if (platform.isAndroid) { diff --git a/apps/automated/src/xml-declaration/mymodule/package.json b/apps/automated/src/xml-declaration/mymodule/package.json deleted file mode 100644 index 74604969c..000000000 --- a/apps/automated/src/xml-declaration/mymodule/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "MyControl", - "main": "MyControl.js" -} diff --git a/apps/automated/webpack.config.js b/apps/automated/webpack.config.js new file mode 100644 index 000000000..389f19d63 --- /dev/null +++ b/apps/automated/webpack.config.js @@ -0,0 +1,21 @@ +const webpack = require("@nativescript/webpack"); + +module.exports = (env) => { + webpack.init(env); + + webpack.Utils.addCopyRule('ui/web-view/*.html'); + + webpack.chainWebpack(config => { + config.plugin('DefinePlugin').tap(args => { + Object.assign(args[0], { + __CI__: !!process.env.CI, + }) + + return args + }) + }) + + return webpack.resolveConfig(); +}; + + diff --git a/apps/automated/webpack.custom.config.js b/apps/automated/webpack.custom.config.js deleted file mode 100644 index 02e1478d4..000000000 --- a/apps/automated/webpack.custom.config.js +++ /dev/null @@ -1,22 +0,0 @@ -const webpack = require('webpack'); -const CopyWebpackPlugin = require('copy-webpack-plugin'); - -const webpackConfig = require('./webpack.config'); - -module.exports = (env) => { - env = env || {}; - const baseConfig = webpackConfig(env); - - baseConfig.plugins.push(new CopyWebpackPlugin([ - { from: { glob: 'ui/web-view/*.html', dot: false } } - ])) - - baseConfig.plugins.push(new webpack.DefinePlugin({ - __CI__: !!process.env.CI, - __UI_USE_XML_PARSER__: true, - __UI_USE_EXTERNAL_RENDERER__: false, - __CSS_PARSER__: JSON.stringify('css-tree') - })) - - return baseConfig; -}; diff --git a/apps/toolbox/.gitignore b/apps/toolbox/.gitignore index b5d843b53..604359893 100644 --- a/apps/toolbox/.gitignore +++ b/apps/toolbox/.gitignore @@ -40,4 +40,4 @@ app/app.scss package-lock.json !tools/** -!webpack.custom.config.js +!webpack.config.js diff --git a/apps/toolbox/nativescript.config.ts b/apps/toolbox/nativescript.config.ts index 5b3e82b55..1f93e6add 100644 --- a/apps/toolbox/nativescript.config.ts +++ b/apps/toolbox/nativescript.config.ts @@ -2,11 +2,10 @@ import { NativeScriptConfig } from '@nativescript/core'; export default { id: 'org.nativescript.ToolBox', + appPath: 'src', appResourcesPath: '../../tools/assets/App_Resources', - webpackConfigPath: 'webpack.custom.config.js', android: { v8Flags: '--expose_gc', - markingMode: 'none', suppressCallJSMethodExceptions: false, }, } as NativeScriptConfig; diff --git a/apps/toolbox/package.json b/apps/toolbox/package.json index f265e7dfa..778084d24 100644 --- a/apps/toolbox/package.json +++ b/apps/toolbox/package.json @@ -1,5 +1,5 @@ { - "main": "main.js", + "main": "src/main.ts", "description": "NativeScript Application", "license": "MIT", "repository": { diff --git a/apps/toolbox/src/app-platform.android.css b/apps/toolbox/src/_app-platform.android.css similarity index 100% rename from apps/toolbox/src/app-platform.android.css rename to apps/toolbox/src/_app-platform.android.css diff --git a/apps/toolbox/src/app-platform.ios.css b/apps/toolbox/src/_app-platform.ios.css similarity index 100% rename from apps/toolbox/src/app-platform.ios.css rename to apps/toolbox/src/_app-platform.ios.css diff --git a/apps/toolbox/src/app.css b/apps/toolbox/src/app.css index b8800b7a5..e52432cd1 100644 --- a/apps/toolbox/src/app.css +++ b/apps/toolbox/src/app.css @@ -1,5 +1,5 @@ -@import '~nativescript-theme-core/css/core.light.css'; -@import './app-platform.css'; +@import 'nativescript-theme-core/css/core.light.css'; +@import './_app-platform.css'; /* The following CSS rule changes the font size of all UI diff --git a/apps/toolbox/webpack.config.js b/apps/toolbox/webpack.config.js new file mode 100644 index 000000000..509672c37 --- /dev/null +++ b/apps/toolbox/webpack.config.js @@ -0,0 +1,19 @@ +const webpack = require("@nativescript/webpack"); + +module.exports = (env) => { + webpack.init(env); + + webpack.chainWebpack(config => { + config.plugin('DefinePlugin').tap(args => { + Object.assign(args[0], { + __CI__: !!process.env.CI, + }) + + return args + }) + }) + + return webpack.resolveConfig(); +}; + + diff --git a/apps/toolbox/webpack.custom.config.js b/apps/toolbox/webpack.custom.config.js deleted file mode 100644 index b6ffd7b43..000000000 --- a/apps/toolbox/webpack.custom.config.js +++ /dev/null @@ -1,18 +0,0 @@ -const webpack = require('webpack'); -const CopyWebpackPlugin = require('copy-webpack-plugin'); - -const webpackConfig = require('./webpack.config'); - -module.exports = (env) => { - env = env || {}; - const baseConfig = webpackConfig(env); - - baseConfig.plugins.push(new webpack.DefinePlugin({ - __CI__: !!process.env.CI, - __UI_USE_XML_PARSER__: true, - __UI_USE_EXTERNAL_RENDERER__: false, - __CSS_PARSER__: JSON.stringify('css-tree') - })) - - return baseConfig; -}; diff --git a/apps/ui/.gitignore b/apps/ui/.gitignore index 9eccb5027..901706c8e 100644 --- a/apps/ui/.gitignore +++ b/apps/ui/.gitignore @@ -1 +1 @@ -!webpack.custom.config.js \ No newline at end of file +!webpack.config.js \ No newline at end of file diff --git a/apps/ui/nativescript.config.ts b/apps/ui/nativescript.config.ts index 0ffc08f2f..d355e9993 100644 --- a/apps/ui/nativescript.config.ts +++ b/apps/ui/nativescript.config.ts @@ -2,10 +2,9 @@ import { NativeScriptConfig } from '@nativescript/core'; export default { id: 'org.nativescript.uitestsapp', + appPath: 'src', appResourcesPath: '../../tools/assets/App_Resources', - webpackConfigPath: 'webpack.custom.config.js', android: { v8Flags: '--expose_gc', - markingMode: 'none', }, } as NativeScriptConfig; diff --git a/apps/ui/package.json b/apps/ui/package.json index 07ed191df..4ea1009e3 100644 --- a/apps/ui/package.json +++ b/apps/ui/package.json @@ -1,5 +1,5 @@ { - "main": "main.js", + "main": "src/main.ts", "description": "NativeScript Application", "license": "MIT", "repository": { diff --git a/apps/ui/src/css/styles-page.css b/apps/ui/src/css/styles-page.css index 1bd47cec9..e6bfaeacd 100644 --- a/apps/ui/src/css/styles-page.css +++ b/apps/ui/src/css/styles-page.css @@ -1,5 +1,6 @@ -#page { +@import url("../css/import.css"); + +#page { background-color: lightcoral; } -@import url("../css/import.css"); diff --git a/apps/ui/tsconfig.json b/apps/ui/tsconfig.json index ab1c7ad8b..be54020e7 100644 --- a/apps/ui/tsconfig.json +++ b/apps/ui/tsconfig.json @@ -1,10 +1,11 @@ { - "extends": "../../tsconfig.json", - "compilerOptions": { - "diagnostics": false, - "paths": { - "~/*": ["src/*"], - "tns-core-modules/*": ["@nativescript/core/*"] - } - } + "extends": "../../tsconfig.json", + "compilerOptions": { + "diagnostics": false, + "paths": { + "~/*": ["src/*"], + "tns-core-modules/*": ["@nativescript/core/*"] + } + }, + "exclude": ["e2e"] } diff --git a/apps/ui/webpack.config.js b/apps/ui/webpack.config.js new file mode 100644 index 000000000..97dc89508 --- /dev/null +++ b/apps/ui/webpack.config.js @@ -0,0 +1,20 @@ +const webpack = require("@nativescript/webpack"); +const { ContextExclusionPlugin } = require('webpack') + +module.exports = (env) => { + webpack.init(env); + + webpack.chainWebpack(config => { + config.plugin('DefinePlugin').tap(args => { + Object.assign(args[0], { + __CI__: !!process.env.CI, + }) + + return args + }) + }) + + return webpack.resolveConfig(); +}; + + diff --git a/apps/ui/webpack.custom.config.js b/apps/ui/webpack.custom.config.js deleted file mode 100644 index b6ffd7b43..000000000 --- a/apps/ui/webpack.custom.config.js +++ /dev/null @@ -1,18 +0,0 @@ -const webpack = require('webpack'); -const CopyWebpackPlugin = require('copy-webpack-plugin'); - -const webpackConfig = require('./webpack.config'); - -module.exports = (env) => { - env = env || {}; - const baseConfig = webpackConfig(env); - - baseConfig.plugins.push(new webpack.DefinePlugin({ - __CI__: !!process.env.CI, - __UI_USE_XML_PARSER__: true, - __UI_USE_EXTERNAL_RENDERER__: false, - __CSS_PARSER__: JSON.stringify('css-tree') - })) - - return baseConfig; -}; diff --git a/package.json b/package.json index 91406a5e6..1c832df65 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "setup": "npm run clean && npm install --legacy-peer-deps", "setup:yarn": "yarn clean && yarn", "setup:pnpm": "pnpm run clean && pnpm install", - "postinstall": "ts-patch install && husky install && nx run core:setup", + "postinstall": "ts-patch install && husky install && nx run webpack5:build", "start": "nps", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s" }, @@ -70,7 +70,8 @@ "typedoc": "^0.20.14", "typescript": "4.1.4", "webpack": "~4.44.1", - "webpack-cli": "~3.3.12" + "webpack-cli": "~3.3.12", + "zx": "^4.2.0" }, "lint-staged": { "**/*": [ diff --git a/packages/core/debugger/dom-node.ts b/packages/core/debugger/dom-node.ts index 21d4909e9..f7f229ffb 100644 --- a/packages/core/debugger/dom-node.ts +++ b/packages/core/debugger/dom-node.ts @@ -175,7 +175,7 @@ export class DOMNode { dispose() { unregisterNode(this); - this.viewRef.clear(); + // this.viewRef.clear(); } public toObject() { diff --git a/packages/core/ui/builder/xml2ui.ts b/packages/core/ui/builder/xml2ui.ts index f0f041d78..5dc732311 100644 --- a/packages/core/ui/builder/xml2ui.ts +++ b/packages/core/ui/builder/xml2ui.ts @@ -3,7 +3,7 @@ import { ScopeError, SourceError, Source } from '../../utils/debug'; import * as xml from '../../xml'; import { isString, isObject } from '../../utils/types'; import { getComponentModule } from './component-builder'; -import { ComponentModule } from './component-builder'; +import type { ComponentModule } from './component-builder'; import { Device } from '../../platform'; import { profile } from '../../profiling'; import { android, ios, loadCustomComponent, defaultNameSpaceMatcher, getExports, Builder } from './index'; @@ -296,7 +296,7 @@ export namespace xml2ui { return this._value; } - constructor(private parent: XmlStateConsumer, private templateProperty: TemplateProperty) { } + constructor(private parent: XmlStateConsumer, private templateProperty: TemplateProperty) {} public parse(args: xml.ParserEvent): XmlStateConsumer { if (args.eventType === xml.ParserEventType.StartElement && args.elementName === 'template') { @@ -331,7 +331,7 @@ export namespace xml2ui { export const enum State { EXPECTING_START, PARSING, - FINISHED + FINISHED, } } @@ -514,7 +514,7 @@ export namespace xml2ui { parent: ComponentModule; name: string; items?: Array; - parser?: { value: any; }; + parser?: { value: any }; } } } diff --git a/packages/core/ui/core/bindable/index.ts b/packages/core/ui/core/bindable/index.ts index 429d930d3..d0dad11f6 100644 --- a/packages/core/ui/core/bindable/index.ts +++ b/packages/core/ui/core/bindable/index.ts @@ -164,9 +164,9 @@ export class Binding { this.propertyChangeListeners.clear(); - if (this.source) { - this.source.clear(); - } + // if (this.source) { + // this.source.clear(); + // } if (this.sourceOptions) { this.sourceOptions.instance.clear(); diff --git a/packages/core/ui/styling/style-scope.ts b/packages/core/ui/styling/style-scope.ts index 659b3b6f4..cb0bffdd9 100644 --- a/packages/core/ui/styling/style-scope.ts +++ b/packages/core/ui/styling/style-scope.ts @@ -92,13 +92,19 @@ class CSSSource { if (typeof cssOrAst === 'string') { // raw-loader return CSSSource.fromSource(cssOrAst, keyframes, fileName); - } else if (typeof cssOrAst === 'object' && cssOrAst.type === 'stylesheet' && cssOrAst.stylesheet && cssOrAst.stylesheet.rules) { - // css-loader - return CSSSource.fromAST(cssOrAst, keyframes, fileName); - } else { - // css2json-loader - return CSSSource.fromSource(cssOrAst.toString(), keyframes, fileName); + } else if (typeof cssOrAst === 'object') { + if (cssOrAst.default) { + cssOrAst = cssOrAst.default; + } + + if (cssOrAst.type === 'stylesheet' && cssOrAst.stylesheet && cssOrAst.stylesheet.rules) { + // css-loader + return CSSSource.fromAST(cssOrAst, keyframes, fileName); + } } + + // css2json-loader + return CSSSource.fromSource(cssOrAst.toString(), keyframes, fileName); } public static fromURI(uri: string, keyframes: KeyframesMap): CSSSource { diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap index e02d474aa..0327df79e 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap @@ -137,7 +137,12 @@ exports[`angular configuration for android 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -167,7 +172,12 @@ exports[`angular configuration for android 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -259,7 +269,12 @@ exports[`angular configuration for android 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -391,8 +406,8 @@ exports[`angular configuration for android 1`] = ` ], entry: { bundle: [ - '@nativescript/core/globals/index.js', - '@nativescript/core/bundle-entry-points.js', + '@nativescript/core/globals/index', + '@nativescript/core/bundle-entry-points', '__jest__/src/app.js', '@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity' @@ -538,7 +553,12 @@ exports[`angular configuration for ios 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -568,7 +588,12 @@ exports[`angular configuration for ios 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -660,7 +685,12 @@ exports[`angular configuration for ios 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -792,8 +822,8 @@ exports[`angular configuration for ios 1`] = ` ], entry: { bundle: [ - '@nativescript/core/globals/index.js', - '@nativescript/core/bundle-entry-points.js', + '@nativescript/core/globals/index', + '@nativescript/core/bundle-entry-points', '__jest__/src/app.js' ], 'tns_modules/inspector_modules': [ @@ -806,7 +836,7 @@ exports[`angular configuration for ios 1`] = ` exports[`angular configuration loads polyfills.android.ts into the bundle entry if it exists 1`] = ` Array [ "__jest__/src/polyfills.android.ts", - "@nativescript/core/bundle-entry-points.js", + "@nativescript/core/bundle-entry-points", "__jest__/src/app.js", "@nativescript/core/ui/frame", "@nativescript/core/ui/frame/activity", @@ -816,7 +846,7 @@ Array [ exports[`angular configuration loads polyfills.ios.ts into the bundle entry if it exists 1`] = ` Array [ "__jest__/src/polyfills.ios.ts", - "@nativescript/core/bundle-entry-points.js", + "@nativescript/core/bundle-entry-points", "__jest__/src/app.js", ] `; @@ -824,7 +854,7 @@ Array [ exports[`angular configuration loads polyfills.ts into the bundle entry if it exists 1`] = ` Array [ "__jest__/src/polyfills.ts", - "@nativescript/core/bundle-entry-points.js", + "@nativescript/core/bundle-entry-points", "__jest__/src/app.js", ] `; diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap index 07ce49456..658a93148 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap @@ -141,7 +141,12 @@ exports[`base configuration for android 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -166,7 +171,12 @@ exports[`base configuration for android 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -294,8 +304,8 @@ exports[`base configuration for android 1`] = ` ], entry: { bundle: [ - '@nativescript/core/globals/index.js', - '@nativescript/core/bundle-entry-points.js', + '@nativescript/core/globals/index', + '@nativescript/core/bundle-entry-points', '__jest__/src/app.js', '@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity' @@ -445,7 +455,12 @@ exports[`base configuration for ios 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -470,7 +485,12 @@ exports[`base configuration for ios 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -598,8 +618,8 @@ exports[`base configuration for ios 1`] = ` ], entry: { bundle: [ - '@nativescript/core/globals/index.js', - '@nativescript/core/bundle-entry-points.js', + '@nativescript/core/globals/index', + '@nativescript/core/bundle-entry-points', '__jest__/src/app.js' ], 'tns_modules/inspector_modules': [ diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap index 4347d13a6..22ba2df01 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap @@ -141,7 +141,12 @@ exports[`javascript configuration for android 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -166,7 +171,12 @@ exports[`javascript configuration for android 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -302,9 +312,9 @@ exports[`javascript configuration for android 1`] = ` ], entry: { bundle: [ - '@nativescript/core/globals/index.js', + '@nativescript/core/globals/index', '__jest__/src/__@nativescript_webpack_virtual_entry_javascript__', - '@nativescript/core/bundle-entry-points.js', + '@nativescript/core/bundle-entry-points', '__jest__/src/app.js', '@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity' @@ -454,7 +464,12 @@ exports[`javascript configuration for ios 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -479,7 +494,12 @@ exports[`javascript configuration for ios 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -615,9 +635,9 @@ exports[`javascript configuration for ios 1`] = ` ], entry: { bundle: [ - '@nativescript/core/globals/index.js', + '@nativescript/core/globals/index', '__jest__/src/__@nativescript_webpack_virtual_entry_javascript__', - '@nativescript/core/bundle-entry-points.js', + '@nativescript/core/bundle-entry-points', '__jest__/src/app.js' ], 'tns_modules/inspector_modules': [ diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap index c875a21e6..501497ffe 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap @@ -163,7 +163,12 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -188,7 +193,12 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -323,8 +333,8 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR ], entry: { bundle: [ - '@nativescript/core/globals/index.js', - '@nativescript/core/bundle-entry-points.js', + '@nativescript/core/globals/index', + '@nativescript/core/bundle-entry-points', '__jest__/src/app.js', '@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity' @@ -478,7 +488,12 @@ exports[`react configuration > android > base config 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -503,7 +518,12 @@ exports[`react configuration > android > base config 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -627,8 +647,8 @@ exports[`react configuration > android > base config 1`] = ` ], entry: { bundle: [ - '@nativescript/core/globals/index.js', - '@nativescript/core/bundle-entry-points.js', + '@nativescript/core/globals/index', + '@nativescript/core/bundle-entry-points', '__jest__/src/app.js', '@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity' @@ -800,7 +820,12 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -825,7 +850,12 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -960,8 +990,8 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena ], entry: { bundle: [ - '@nativescript/core/globals/index.js', - '@nativescript/core/bundle-entry-points.js', + '@nativescript/core/globals/index', + '@nativescript/core/bundle-entry-points', '__jest__/src/app.js' ], 'tns_modules/inspector_modules': [ @@ -1116,7 +1146,12 @@ exports[`react configuration > ios > base config 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -1141,7 +1176,12 @@ exports[`react configuration > ios > base config 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -1265,8 +1305,8 @@ exports[`react configuration > ios > base config 1`] = ` ], entry: { bundle: [ - '@nativescript/core/globals/index.js', - '@nativescript/core/bundle-entry-points.js', + '@nativescript/core/globals/index', + '@nativescript/core/bundle-entry-points', '__jest__/src/app.js' ], 'tns_modules/inspector_modules': [ diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap index 1e311c402..e55821c56 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap @@ -145,7 +145,12 @@ exports[`svelte configuration for android 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -170,7 +175,12 @@ exports[`svelte configuration for android 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -315,8 +325,8 @@ exports[`svelte configuration for android 1`] = ` ], entry: { bundle: [ - '@nativescript/core/globals/index.js', - '@nativescript/core/bundle-entry-points.js', + '@nativescript/core/globals/index', + '@nativescript/core/bundle-entry-points', '__jest__/src/app.js', '@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity' @@ -470,7 +480,12 @@ exports[`svelte configuration for ios 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -495,7 +510,12 @@ exports[`svelte configuration for ios 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -640,8 +660,8 @@ exports[`svelte configuration for ios 1`] = ` ], entry: { bundle: [ - '@nativescript/core/globals/index.js', - '@nativescript/core/bundle-entry-points.js', + '@nativescript/core/globals/index', + '@nativescript/core/bundle-entry-points', '__jest__/src/app.js' ], 'tns_modules/inspector_modules': [ diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap index f8807fd5a..e5cad4940 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap @@ -141,7 +141,12 @@ exports[`typescript configuration for android 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -166,7 +171,12 @@ exports[`typescript configuration for android 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -302,9 +312,9 @@ exports[`typescript configuration for android 1`] = ` ], entry: { bundle: [ - '@nativescript/core/globals/index.js', + '@nativescript/core/globals/index', '__jest__/src/__@nativescript_webpack_virtual_entry_typescript__', - '@nativescript/core/bundle-entry-points.js', + '@nativescript/core/bundle-entry-points', '__jest__/src/app.js', '@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity' @@ -454,7 +464,12 @@ exports[`typescript configuration for ios 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -479,7 +494,12 @@ exports[`typescript configuration for ios 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -615,9 +635,9 @@ exports[`typescript configuration for ios 1`] = ` ], entry: { bundle: [ - '@nativescript/core/globals/index.js', + '@nativescript/core/globals/index', '__jest__/src/__@nativescript_webpack_virtual_entry_typescript__', - '@nativescript/core/bundle-entry-points.js', + '@nativescript/core/bundle-entry-points', '__jest__/src/app.js' ], 'tns_modules/inspector_modules': [ diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap index ce9e6407f..87bf13417 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap @@ -151,7 +151,12 @@ exports[`vue configuration for android 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -180,7 +185,12 @@ exports[`vue configuration for android 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -328,8 +338,8 @@ exports[`vue configuration for android 1`] = ` ], entry: { bundle: [ - '@nativescript/core/globals/index.js', - '@nativescript/core/bundle-entry-points.js', + '@nativescript/core/globals/index', + '@nativescript/core/bundle-entry-points', '__jest__/src/app.js', '@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity' @@ -489,7 +499,12 @@ exports[`vue configuration for ios 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -518,7 +533,12 @@ exports[`vue configuration for ios 1`] = ` options: { postcssOptions: { plugins: [ - 'postcss-import' + [ + 'postcss-import', + { + resolve: function () { /* omitted long function */ } + } + ] ] } } @@ -666,8 +686,8 @@ exports[`vue configuration for ios 1`] = ` ], entry: { bundle: [ - '@nativescript/core/globals/index.js', - '@nativescript/core/bundle-entry-points.js', + '@nativescript/core/globals/index', + '@nativescript/core/bundle-entry-points', '__jest__/src/app.js' ], 'tns_modules/inspector_modules': [ diff --git a/packages/webpack5/__tests__/loaders/xml-namespace-loader.spec.ts b/packages/webpack5/__tests__/loaders/xml-namespace-loader.spec.ts index adcde7dc9..d1a27eedf 100644 --- a/packages/webpack5/__tests__/loaders/xml-namespace-loader.spec.ts +++ b/packages/webpack5/__tests__/loaders/xml-namespace-loader.spec.ts @@ -44,41 +44,43 @@ function getContext( return { rootContext: 'app', context: 'app/component', - async: () => (error, source: string) => { - if (callbackCalled) { - done.fail('Callback called more than once!'); - } - callbackCalled = true; + async() { + return (error, source: string) => { + if (callbackCalled) { + throw new Error('Callback called more than once!'); + } + callbackCalled = true; - expectedDeps.forEach((expectedDep) => { - expect(actualDeps).toContain(expectedDep); - }); + expectedDeps.forEach((expectedDep) => { + expect(actualDeps).toContain(expectedDep); + }); - expectedRegs.forEach(({ name, path }) => { - expect(source).toContain(dedent` + expectedRegs.forEach(({ name, path }) => { + expect(source).toContain(dedent` global.registerModule( '${name}', () => require("${path}") ) `); - }); + }); - if (assureNoDeps) { - expect(actualDeps.length).toBe(0); - expect(source).not.toContain('global.registerModule'); - } + if (assureNoDeps) { + expect(actualDeps.length).toBe(0); + expect(source).not.toContain('global.registerModule'); + } - if (expectWarnings) { - expect(actualWarnings.length).toEqual(expectWarnings); - } + if (expectWarnings) { + expect(actualWarnings.length).toEqual(expectWarnings); + } - if (error && !expectError) { - done.fail(error); - } else if (!error && expectError) { - done.fail('Error expected here'); - } else { - done(); - } + if (error && !expectError) { + throw error; + } else if (!error && expectError) { + throw new Error('Error expected here'); + } else { + done(); + } + }; }, resolve: ( context: string, @@ -272,10 +274,13 @@ describe('xml-namespace-loader', () => { const expectedDeps = []; const expectedRegs = [ - { name: 'nativescript-ui-chart', path: 'nativescript-ui-chart' }, + { + name: 'nativescript-ui-chart', + path: 'node_modules/nativescript-ui-chart/ui-chart.js', + }, { name: 'nativescript-ui-chart/RadCartesianChart', - path: 'nativescript-ui-chart', + path: 'node_modules/nativescript-ui-chart/ui-chart.js', }, ]; @@ -392,25 +397,16 @@ describe('xml-namespace-loader', () => { }); it("with '&&', '||', '<=' and '>=' in binding expression, emits warnings, but does not fail", (done) => { - const resolveMap = { - 'nativescript-ui-chart': 'node_modules/nativescript-ui-chart/ui-chart.js', - }; + const resolveMap = {}; const expectedDeps = []; - const expectedRegs = [ - { name: 'nativescript-ui-chart', path: 'nativescript-ui-chart' }, - { - name: 'nativescript-ui-chart/RadCartesianChart', - path: 'nativescript-ui-chart', - }, - ]; + const expectedRegs = []; const testXml = ` - `; diff --git a/packages/webpack5/src/configuration/angular.ts b/packages/webpack5/src/configuration/angular.ts index aa591cf50..bc7478942 100644 --- a/packages/webpack5/src/configuration/angular.ts +++ b/packages/webpack5/src/configuration/angular.ts @@ -201,10 +201,8 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { // replace globals with the polyfills file which // should handle loading the correct globals // and any additional polyfills required. - if (paths.includes('@nativescript/core/globals/index.js')) { - paths[ - paths.indexOf('@nativescript/core/globals/index.js') - ] = polyfillsPath; + if (paths.includes('@nativescript/core/globals/index')) { + paths[paths.indexOf('@nativescript/core/globals/index')] = polyfillsPath; // replace paths with the updated paths config.entry('bundle').clear().merge(paths); diff --git a/packages/webpack5/src/configuration/base.ts b/packages/webpack5/src/configuration/base.ts index e618b5d68..0c2659f6d 100644 --- a/packages/webpack5/src/configuration/base.ts +++ b/packages/webpack5/src/configuration/base.ts @@ -1,10 +1,11 @@ +import { extname, resolve } from 'path'; import { ContextExclusionPlugin, DefinePlugin, HotModuleReplacementPlugin, } from 'webpack'; import Config from 'webpack-chain'; -import { resolve } from 'path'; +import { existsSync } from 'fs'; import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'; import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; @@ -86,8 +87,8 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { config .entry('bundle') // ensure we load nativescript globals first - .add('@nativescript/core/globals/index.js') - .add('@nativescript/core/bundle-entry-points.js') + .add('@nativescript/core/globals/index') + .add('@nativescript/core/bundle-entry-points') .add(entryPath); // Add android app components to the bundle to SBG can generate the java classes @@ -126,6 +127,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { config.optimization.minimizer('TerserPlugin').use(TerserPlugin, [ { terserOptions: { + // @ts-ignore - https://github.com/webpack-contrib/terser-webpack-plugin/pull/463 broke the types? compress: { collapse_vars: platform !== 'android', sequences: platform !== 'android', @@ -276,7 +278,36 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { postcssOptions: { plugins: [ // inlines @imported stylesheets - 'postcss-import', + [ + 'postcss-import', + { + // custom resolver to resolve platform extensions in @import statements + // ie. @import "foo.css" would import "foo.ios.css" if the platform is ios and it exists + resolve(id, baseDir, importOptions) { + const ext = extname(id); + const platformExt = ext ? `.${platform}${ext}` : ''; + + if (!id.includes(platformExt)) { + const platformRequest = id.replace(ext, platformExt); + const extPath = resolve(baseDir, platformRequest); + + try { + return require.resolve(platformRequest, { + paths: [baseDir], + }); + } catch {} + + if (existsSync(extPath)) { + console.log(`resolving "${id}" to "${platformRequest}"`); + return extPath; + } + } + + // fallback to postcss-import default resolution + return id; + }, + }, + ], ], }, }; diff --git a/packages/webpack5/src/configuration/javascript.ts b/packages/webpack5/src/configuration/javascript.ts index ae9eb3ff6..914036eb2 100644 --- a/packages/webpack5/src/configuration/javascript.ts +++ b/packages/webpack5/src/configuration/javascript.ts @@ -30,7 +30,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { chainedSetAddAfter( config.entry('bundle'), - '@nativescript/core/globals/index.js', + '@nativescript/core/globals/index', virtualEntryPath ); diff --git a/packages/webpack5/src/configuration/typescript.ts b/packages/webpack5/src/configuration/typescript.ts index 539471b03..4513af52d 100644 --- a/packages/webpack5/src/configuration/typescript.ts +++ b/packages/webpack5/src/configuration/typescript.ts @@ -30,7 +30,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { chainedSetAddAfter( config.entry('bundle'), - '@nativescript/core/globals/index.js', + '@nativescript/core/globals/index', virtualEntryPath ); diff --git a/packages/webpack5/src/loaders/xml-namespace-loader/index.ts b/packages/webpack5/src/loaders/xml-namespace-loader/index.ts index f3bff1a83..edb3fbf68 100644 --- a/packages/webpack5/src/loaders/xml-namespace-loader/index.ts +++ b/packages/webpack5/src/loaders/xml-namespace-loader/index.ts @@ -78,6 +78,10 @@ async function parseXML(content: string): Promise { `${localModulePath}.xml`, moduleName, namespace, + `${moduleName}.xml`, + `~/${moduleName}`, + `~/${namespace}`, + `~/${moduleName}.xml`, ]; DEBUG && console.log({ resolvePaths }); let resolvedPath; @@ -118,12 +122,13 @@ async function parseXML(content: string): Promise { this.addDependency(xml); namespaces.push({ name: `${moduleName}.xml`, path: xml }); }) - .catch(() => { - // if there is no XML file, fall back to namespace as the path - // will become require() - namespaces.push({ name: namespace, path: namespace }); - namespaces.push({ name: moduleName, path: namespace }); - }); + .catch(noop); + // .catch(() => { + // // if there is no XML file, fall back to namespace as the path + // // will become require() + // namespaces.push({ name: namespace, path: namespace }); + // namespaces.push({ name: moduleName, path: namespace }); + // }); // look for css files with the same name await resolveAsync(this.context, `${noExtFilename}.css`) @@ -163,6 +168,8 @@ async function parseXML(content: string): Promise { distinctNamespaces.set(name, path.replace(/\\/g, '/')); }); + DEBUG && console.log({ distinctNamespaces }); + distinctNamespaces.forEach((path, name) => { moduleRegisters.push(dedent` global.registerModule( diff --git a/tools/scripts/pack-webpack5.mjs b/tools/scripts/pack-webpack5.mjs new file mode 100755 index 000000000..bceb93c17 --- /dev/null +++ b/tools/scripts/pack-webpack5.mjs @@ -0,0 +1,25 @@ +#!/usr/bin/env zx +import 'zx/globals'; + +import path from 'path'; + +const webpack5Path = path.resolve(__dirname, '../../packages/webpack5'); +const distPath = path.resolve(__dirname, '../../dist/packages'); + +const packageJSON = await fs.readJSON(`${webpack5Path}/package.json`); +const tgzName = `nativescript-webpack-${packageJSON.version}.tgz`; + +cd(webpack5Path); + +await $`npm install`; +await $`npm pack`; + +const from = path.join(webpack5Path, tgzName); +const to = path.join(distPath, 'nativescript-webpack.tgz'); + +await fs.move(from, to, { + overwrite: true, +}); + +console.log(chalk.green(`@nativescript/webpack has been built and packed.\n`)); +console.log(to); \ No newline at end of file diff --git a/workspace.json b/workspace.json index 547b38396..83b3140c9 100644 --- a/workspace.json +++ b/workspace.json @@ -26,7 +26,7 @@ "clean": { "builder": "@nrwl/workspace:run-commands", "options": { - "commands": ["npx rimraf -- hooks node_modules platforms package-lock.json webpack.config.js", "npm i --legacy-peer-deps", "npx rimraf -- package-lock.json"], + "commands": ["npx rimraf -- hooks node_modules platforms package-lock.json", "npm i --legacy-peer-deps", "npx rimraf -- package-lock.json"], "cwd": "apps/automated", "parallel": false } @@ -58,7 +58,7 @@ "clean": { "builder": "@nrwl/workspace:run-commands", "options": { - "commands": ["npx rimraf -- hooks node_modules platforms package-lock.json webpack.config.js", "npm i --legacy-peer-deps", "npx rimraf -- package-lock.json"], + "commands": ["npx rimraf -- hooks node_modules platforms package-lock.json", "npm i --legacy-peer-deps", "npx rimraf -- package-lock.json"], "cwd": "apps/toolbox", "parallel": false } @@ -90,7 +90,7 @@ "clean": { "builder": "@nrwl/workspace:run-commands", "options": { - "commands": ["npx rimraf -- hooks node_modules platforms package-lock.json webpack.config.js", "npm i --legacy-peer-deps", "npx rimraf -- package-lock.json"], + "commands": ["npx rimraf -- hooks node_modules platforms package-lock.json", "npm i --legacy-peer-deps", "npx rimraf -- package-lock.json"], "cwd": "apps/ui", "parallel": false } @@ -117,12 +117,6 @@ }, "outputs": ["coverage/packages/core"] }, - "setup": { - "builder": "@nrwl/workspace:run-commands", - "options": { - "commands": ["nx run webpack:build"] - } - }, "build": { "builder": "@nrwl/workspace:run-commands", "outputs": ["dist/packages"], @@ -288,9 +282,7 @@ "builder": "@nrwl/workspace:run-commands", "outputs": ["dist/packages"], "options": { - "commands": ["npm run build"], - "cwd": "packages/webpack5", - "parallel": false + "command": "npx zx ./tools/scripts/pack-webpack5.mjs" } } } From 9c6c84b1074231114ae1ed6ff6f6255a5081b045 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Tue, 21 Dec 2021 18:24:24 -0800 Subject: [PATCH 30/35] chore: nx migrate latest (#9709) --- apps/automated/nativescript.config.ts | 3 + apps/automated/project.json | 42 +++ apps/automated/tsconfig.json | 16 +- apps/toolbox/nativescript.config.ts | 3 + apps/toolbox/project.json | 42 +++ apps/toolbox/tsconfig.json | 14 +- apps/ui/nativescript.config.ts | 3 + apps/ui/project.json | 42 +++ apps/ui/tsconfig.json | 2 +- jest.config.js | 6 +- nx.json | 85 ++++-- package.json | 30 ++- packages/core/project.json | 55 ++++ packages/core/tsconfig.json | 12 +- packages/core/tsconfig.lib.json | 2 +- packages/core/tsconfig.spec.json | 20 +- packages/types-android/project.json | 17 ++ packages/types-ios/project.json | 16 ++ packages/types/project.json | 17 ++ packages/ui-mobile-base/project.json | 16 ++ packages/webpack/project.json | 31 +++ packages/webpack5/project.json | 21 ++ tools/scripts/project.json | 17 ++ tools/scripts/tsconfig.typedoc.json | 2 +- tools/tsconfig.tools.json | 18 +- tsconfig.base.json | 28 ++ tsconfig.eslint.json | 2 +- tsconfig.json | 28 -- workspace.json | 358 +------------------------- 29 files changed, 485 insertions(+), 463 deletions(-) create mode 100644 apps/automated/project.json create mode 100644 apps/toolbox/project.json create mode 100644 apps/ui/project.json create mode 100644 packages/core/project.json create mode 100644 packages/types-android/project.json create mode 100644 packages/types-ios/project.json create mode 100644 packages/types/project.json create mode 100644 packages/ui-mobile-base/project.json create mode 100644 packages/webpack/project.json create mode 100644 packages/webpack5/project.json create mode 100644 tools/scripts/project.json create mode 100644 tsconfig.base.json delete mode 100644 tsconfig.json diff --git a/apps/automated/nativescript.config.ts b/apps/automated/nativescript.config.ts index 413b3e554..043f59c66 100644 --- a/apps/automated/nativescript.config.ts +++ b/apps/automated/nativescript.config.ts @@ -7,4 +7,7 @@ export default { android: { v8Flags: '--expose_gc', }, + cli: { + packageManager: 'npm', + }, } as NativeScriptConfig; diff --git a/apps/automated/project.json b/apps/automated/project.json new file mode 100644 index 000000000..85cca779e --- /dev/null +++ b/apps/automated/project.json @@ -0,0 +1,42 @@ +{ + "root": "apps/automated/", + "sourceRoot": "apps/automated/app", + "projectType": "application", + "prefix": "nativescript", + "targets": { + "build": { + "executor": "@nativescript/nx:build", + "options": { + "noHmr": true, + "production": true, + "uglify": true, + "release": true, + "forDevice": true + } + }, + "ios": { + "executor": "@nativescript/nx:build", + "options": { + "platform": "ios" + } + }, + "android": { + "executor": "@nativescript/nx:build", + "options": { + "platform": "android" + } + }, + "clean": { + "executor": "@nativescript/nx:build", + "options": { + "clean": true + } + }, + "lint": { + "executor": "@nrwl/linter:eslint", + "options": { + "lintFilePatterns": ["apps/automated/**/*.ts", "apps/automated/src/**/*.html"] + } + } + } +} diff --git a/apps/automated/tsconfig.json b/apps/automated/tsconfig.json index ab1c7ad8b..6230aa69d 100644 --- a/apps/automated/tsconfig.json +++ b/apps/automated/tsconfig.json @@ -1,10 +1,10 @@ { - "extends": "../../tsconfig.json", - "compilerOptions": { - "diagnostics": false, - "paths": { - "~/*": ["src/*"], - "tns-core-modules/*": ["@nativescript/core/*"] - } - } + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "diagnostics": false, + "paths": { + "~/*": ["src/*"], + "tns-core-modules/*": ["@nativescript/core/*"] + } + } } diff --git a/apps/toolbox/nativescript.config.ts b/apps/toolbox/nativescript.config.ts index 1f93e6add..e6bcbc6d0 100644 --- a/apps/toolbox/nativescript.config.ts +++ b/apps/toolbox/nativescript.config.ts @@ -8,4 +8,7 @@ export default { v8Flags: '--expose_gc', suppressCallJSMethodExceptions: false, }, + cli: { + packageManager: 'npm', + }, } as NativeScriptConfig; diff --git a/apps/toolbox/project.json b/apps/toolbox/project.json new file mode 100644 index 000000000..cbd4bc8dc --- /dev/null +++ b/apps/toolbox/project.json @@ -0,0 +1,42 @@ +{ + "root": "apps/toolbox/", + "sourceRoot": "apps/toolbox/src", + "projectType": "application", + "prefix": "nativescript", + "targets": { + "build": { + "executor": "@nativescript/nx:build", + "options": { + "noHmr": true, + "production": true, + "uglify": true, + "release": true, + "forDevice": true + } + }, + "ios": { + "executor": "@nativescript/nx:build", + "options": { + "platform": "ios" + } + }, + "android": { + "executor": "@nativescript/nx:build", + "options": { + "platform": "android" + } + }, + "clean": { + "executor": "@nativescript/nx:build", + "options": { + "clean": true + } + }, + "lint": { + "executor": "@nrwl/linter:eslint", + "options": { + "lintFilePatterns": ["apps/toolbox/**/*.ts", "apps/toolbox/src/**/*.html"] + } + } + } +} diff --git a/apps/toolbox/tsconfig.json b/apps/toolbox/tsconfig.json index 27d27ebd9..0d0dc494b 100644 --- a/apps/toolbox/tsconfig.json +++ b/apps/toolbox/tsconfig.json @@ -1,9 +1,9 @@ { - "extends": "../../tsconfig.json", - "compilerOptions": { - "diagnostics": false, - "paths": { - "~/*": ["src/*"] - } - } + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "diagnostics": false, + "paths": { + "~/*": ["src/*"] + } + } } diff --git a/apps/ui/nativescript.config.ts b/apps/ui/nativescript.config.ts index d355e9993..3303902b2 100644 --- a/apps/ui/nativescript.config.ts +++ b/apps/ui/nativescript.config.ts @@ -7,4 +7,7 @@ export default { android: { v8Flags: '--expose_gc', }, + cli: { + packageManager: 'npm', + }, } as NativeScriptConfig; diff --git a/apps/ui/project.json b/apps/ui/project.json new file mode 100644 index 000000000..01150a335 --- /dev/null +++ b/apps/ui/project.json @@ -0,0 +1,42 @@ +{ + "root": "apps/ui/", + "sourceRoot": "apps/ui/src", + "projectType": "application", + "prefix": "nativescript", + "targets": { + "build": { + "executor": "@nativescript/nx:build", + "options": { + "noHmr": true, + "production": true, + "uglify": true, + "release": true, + "forDevice": true + } + }, + "ios": { + "executor": "@nativescript/nx:build", + "options": { + "platform": "ios" + } + }, + "android": { + "executor": "@nativescript/nx:build", + "options": { + "platform": "android" + } + }, + "clean": { + "executor": "@nativescript/nx:build", + "options": { + "clean": true + } + }, + "lint": { + "executor": "@nrwl/linter:eslint", + "options": { + "lintFilePatterns": ["apps/ui/**/*.ts", "apps/ui/src/**/*.html"] + } + } + } +} diff --git a/apps/ui/tsconfig.json b/apps/ui/tsconfig.json index be54020e7..6d0ed95c0 100644 --- a/apps/ui/tsconfig.json +++ b/apps/ui/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "diagnostics": false, "paths": { diff --git a/jest.config.js b/jest.config.js index 8c858feaf..d08e9812c 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,3 +1,3 @@ -module.exports = { - projects: ['/packages/core'], -}; +const { getJestProjects } = require('@nrwl/jest'); + +module.exports = { projects: getJestProjects() }; diff --git a/nx.json b/nx.json index 4de54dd12..e92f224f4 100644 --- a/nx.json +++ b/nx.json @@ -15,39 +15,74 @@ "nx.json": "*", ".eslintrc.json": "*" }, - "projects": { - "apps-automated": { - "tags": [] + "targetDependencies": { + "build": [ + { + "target": "build", + "projects": "dependencies" + } + ] + }, + "cli": { + "defaultCollection": "@nrwl/workspace" + }, + "generators": { + "@nrwl/workspace": { + "library": { + "linter": "eslint" + } }, - "apps-toolbox": { - "tags": [] + "@nrwl/cypress": { + "cypress-project": { + "linter": "eslint" + } }, - "apps-ui": { - "tags": [] + "@nrwl/react": { + "application": { + "linter": "eslint" + }, + "library": { + "linter": "eslint" + } }, - "core": { - "tags": [] + "@nrwl/next": { + "application": { + "linter": "eslint" + } }, - "core-api-docs": { - "tags": [] + "@nrwl/web": { + "application": { + "linter": "eslint" + } }, - "types": { - "tags": [] + "@nrwl/node": { + "application": { + "linter": "eslint" + }, + "library": { + "linter": "eslint" + } }, - "types-ios": { - "tags": [] + "@nrwl/nx-plugin": { + "plugin": { + "linter": "eslint" + } }, - "types-android": { - "tags": [] + "@nrwl/nest": { + "application": { + "linter": "eslint" + } }, - "ui-mobile-base": { - "tags": [] - }, - "webpack": { - "tags": [] - }, - "webpack5": { - "tags": [] + "@nrwl/express": { + "application": { + "linter": "eslint" + }, + "library": { + "linter": "eslint" + } } + }, + "affected": { + "defaultBase": "master" } } diff --git a/package.json b/package.json index 1c832df65..d26207c7a 100644 --- a/package.json +++ b/package.json @@ -22,17 +22,18 @@ "devDependencies": { "@nativescript/eslint-plugin": "~0.0.4", "@nativescript/hook": "^2.0.0", - "@nrwl/cli": "12.0.8", - "@nrwl/eslint-plugin-nx": "12.0.8", - "@nrwl/jest": "12.0.8", - "@nrwl/node": "12.0.8", - "@nrwl/tao": "12.0.8", - "@nrwl/workspace": "12.0.8", - "@nstudio/focus": "~11.1.0", + "@nativescript/nx": "~2.0.8", + "@nrwl/cli": "13.3.12", + "@nrwl/eslint-plugin-nx": "13.3.12", + "@nrwl/jest": "13.3.12", + "@nrwl/node": "13.3.12", + "@nrwl/tao": "13.3.12", + "@nrwl/workspace": "13.3.12", + "@nstudio/focus": "~13.0.1", "@nstudio/nps-i": "~1.1.0", "@prettier/plugin-xml": "^0.13.1", "@types/chai": "^4.2.11", - "@types/jest": "~26.0.8", + "@types/jest": "27.0.2", "@types/mocha": "^7.0.2", "@types/node": "14.14.33", "@typescript-eslint/eslint-plugin": "4.19.0", @@ -42,33 +43,33 @@ "copyfiles": "^2.4.0", "css": "^3.0.0", "css-tree": "^1.0.0-alpha.39", - "dotenv": "8.2.0", + "dotenv": "10.0.0", "eslint": "7.22.0", "eslint-config-prettier": "8.1.0", "eslint-plugin-prettier": "^3.3.1", "gonzales": "^1.0.7", "husky": "^5.1.3", - "jest": "~26.2.2", + "jest": "27.2.3", "lint-staged": "^10.5.0", "mocha": "^8.0.1", "mocha-typescript": "^1.1.17", "module-alias": "^2.2.2", - "nativescript": "~8.1.3", + "nativescript": "~8.1.5", "nativescript-typedoc-theme": "1.1.0", "parse-css": "git+https://github.com/tabatkins/parse-css.git", "parserlib": "^1.1.1", - "prettier": "~2.2.1", + "prettier": "2.5.1", "reduce-css-calc": "~2.1.7", "sass": "~1.32.8", "shady-css-parser": "^0.1.0", "terser-webpack-plugin": "~3.0.6", "tree-kill": "^1.2.2", - "ts-jest": "26.4.0", + "ts-jest": "27.0.5", "ts-node": "9.1.1", "ts-patch": "^1.3.0", "tslint": "6.1.3", "typedoc": "^0.20.14", - "typescript": "4.1.4", + "typescript": "4.3.5", "webpack": "~4.44.1", "webpack-cli": "~3.3.12", "zx": "^4.2.0" @@ -79,3 +80,4 @@ ] } } + diff --git a/packages/core/project.json b/packages/core/project.json new file mode 100644 index 000000000..06a72f824 --- /dev/null +++ b/packages/core/project.json @@ -0,0 +1,55 @@ +{ + "root": "packages/core", + "sourceRoot": "packages/core", + "projectType": "library", + "generators": {}, + "targets": { + "lint": { + "executor": "@nrwl/linter:eslint", + "options": { + "lintFilePatterns": ["packages/core/**/*.ts", "packages/core/references.d.ts", "packages/core/**/*.spec.ts", "packages/core/**/*.spec.tsx", "packages/core/**/*.spec.js", "packages/core/**/*.spec.jsx", "packages/core/**/*.d.ts"] + } + }, + "test": { + "executor": "@nrwl/jest:jest", + "options": { + "jestConfig": "packages/core/jest.config.js", + "passWithNoTests": true + }, + "outputs": ["coverage/packages/core"] + }, + "build": { + "executor": "@nrwl/workspace:run-commands", + "outputs": ["dist/packages"], + "options": { + "commands": [ + "npx rimraf dist/packages/core", + "./node_modules/.bin/tsc -p packages/core/tsconfig.lib.json", + "./node_modules/.bin/copyfiles -e \"packages/core/__tests__/**/*\" \"packages/core/**/*.d.ts\" dist && ./node_modules/.bin/copyfiles -e \"packages/core/__tests__/**/*\" \"packages/core/js-libs/**/*\" dist && ./node_modules/.bin/copyfiles -e \"packages/core/__tests__/**/*\" \"packages/core/cli-hooks/**/*.js\" dist && ./node_modules/.bin/copyfiles -e \"packages/core/__tests__/**/*\" \"packages/core/platforms/**/*\" dist && ./node_modules/.bin/copyfiles -e \"packages/core/__tests__/**/*\" \"packages/core/fetch/**/*\" dist && ./node_modules/.bin/copyfiles -e \"packages/core/__tests__/**/*\" \"packages/core/css/**/*\" dist && ./node_modules/.bin/copyfiles -e \"packages/core/__tests__/**/*\" \"packages/core/css-value/**/*\" dist", + "cp packages/core/package.json dist/packages/core", + "cp packages/core/README.md dist/packages/core", + "cp LICENSE dist/packages/core", + "cd dist/packages/core && npm pack && mv *.tgz .." + ], + "cwd": ".", + "parallel": false + } + }, + "unit": { + "executor": "@nrwl/workspace:run-commands", + "options": { + "commands": ["../../../node_modules/.bin/tsc -p tsconfig.json && ../../../node_modules/.bin/mocha --config=.mocharc.yml"], + "cwd": "packages/core/__tests__", + "parallel": false + } + }, + "unit.watch": { + "executor": "@nrwl/workspace:run-commands", + "options": { + "commands": ["../../../node_modules/.bin/tsc -p tsconfig.json && ../../../node_modules/.bin/mocha --watch --config=.mocharc.yml"], + "cwd": "packages/core/__tests__", + "parallel": false + } + } + } +} diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index e9722048f..d1689fde9 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -1,8 +1,8 @@ { - "extends": "../../tsconfig.json", - "compilerOptions": { - "baseUrl": "." - }, - "include": ["**/*.ts", "./references.d.ts"], - "exclude": ["dist", "__tests__"] + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "baseUrl": "." + }, + "include": ["**/*.ts", "./references.d.ts"], + "exclude": ["dist", "__tests__"] } diff --git a/packages/core/tsconfig.lib.json b/packages/core/tsconfig.lib.json index 1c189dfd0..3ee2ce705 100644 --- a/packages/core/tsconfig.lib.json +++ b/packages/core/tsconfig.lib.json @@ -22,6 +22,6 @@ } ] }, - "exclude": ["**/*.spec.ts", "dist", "__tests__"], + "exclude": ["**/*.spec.ts", "**/*.test.ts", "dist", "__tests__"], "include": ["**/*.ts", "./references.d.ts"] } diff --git a/packages/core/tsconfig.spec.json b/packages/core/tsconfig.spec.json index 559410b96..3d95b817d 100644 --- a/packages/core/tsconfig.spec.json +++ b/packages/core/tsconfig.spec.json @@ -1,15 +1,9 @@ { - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "../../dist/out-tsc", - "module": "commonjs", - "types": ["jest", "node"] - }, - "include": [ - "**/*.spec.ts", - "**/*.spec.tsx", - "**/*.spec.js", - "**/*.spec.jsx", - "**/*.d.ts" - ] + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": ["**/*.spec.ts", "**/*.test.ts", "**/*.spec.tsx", "**/*.test.tsx", "**/*.spec.js", "**/*.test.js", "**/*.spec.jsx", "**/*.test.jsx", "**/*.d.ts"] } diff --git a/packages/types-android/project.json b/packages/types-android/project.json new file mode 100644 index 000000000..d7a1a62bc --- /dev/null +++ b/packages/types-android/project.json @@ -0,0 +1,17 @@ +{ + "root": "packages/types-android", + "sourceRoot": "packages/types-android/src", + "projectType": "library", + "generators": {}, + "targets": { + "build": { + "executor": "@nrwl/workspace:run-commands", + "outputs": ["dist/packages"], + "options": { + "commands": ["mkdir -p ../../dist/packages/types-android", "cp -R src/* ../../dist/packages/types-android", "cp package.json *.md ../../dist/packages/types-android"], + "cwd": "packages/types-android", + "parallel": false + } + } + } +} diff --git a/packages/types-ios/project.json b/packages/types-ios/project.json new file mode 100644 index 000000000..6ba53b059 --- /dev/null +++ b/packages/types-ios/project.json @@ -0,0 +1,16 @@ +{ + "root": "packages/types-ios", + "sourceRoot": "packages/types-ios/src", + "projectType": "library", + "generators": {}, + "targets": { + "build": { + "executor": "@nrwl/workspace:run-commands", + "outputs": ["dist/packages"], + "options": { + "commands": ["./tools/scripts/typings-gen.sh latest", "mkdir -p dist/packages/types-ios", "cp -R packages/types-ios/src/* dist/packages/types-ios", "cp packages/types-ios/package.json dist/packages/types-ios", "cp packages/types-ios/README.md dist/packages/types-ios/README.md"], + "parallel": false + } + } + } +} diff --git a/packages/types/project.json b/packages/types/project.json new file mode 100644 index 000000000..3616cfddc --- /dev/null +++ b/packages/types/project.json @@ -0,0 +1,17 @@ +{ + "root": "packages/types", + "sourceRoot": "packages/types", + "projectType": "library", + "generators": {}, + "targets": { + "build": { + "executor": "@nrwl/workspace:run-commands", + "outputs": ["dist/packages"], + "options": { + "commands": ["mkdir -p ../../dist/packages/types", "cp -R * ../../dist/packages/types"], + "cwd": "packages/types", + "parallel": false + } + } + } +} diff --git a/packages/ui-mobile-base/project.json b/packages/ui-mobile-base/project.json new file mode 100644 index 000000000..46f6fd7b6 --- /dev/null +++ b/packages/ui-mobile-base/project.json @@ -0,0 +1,16 @@ +{ + "root": "packages/ui-mobile-base", + "sourceRoot": "packages/ui-mobile-base", + "projectType": "library", + "generators": {}, + "targets": { + "build": { + "executor": "@nrwl/workspace:run-commands", + "options": { + "commands": ["./build.sh", "cp -R dist/package/platforms/* ../../packages/core/platforms"], + "cwd": "packages/ui-mobile-base", + "parallel": false + } + } + } +} diff --git a/packages/webpack/project.json b/packages/webpack/project.json new file mode 100644 index 000000000..3d87956c2 --- /dev/null +++ b/packages/webpack/project.json @@ -0,0 +1,31 @@ +{ + "root": "packages/webpack", + "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/webpack5/project.json b/packages/webpack5/project.json new file mode 100644 index 000000000..b83ad29cd --- /dev/null +++ b/packages/webpack5/project.json @@ -0,0 +1,21 @@ +{ + "root": "packages/webpack5", + "sourceRoot": "packages/webpack5", + "projectType": "library", + "generators": {}, + "targets": { + "lint": { + "executor": "@nrwl/linter:eslint", + "options": { + "lintFilePatterns": [] + } + }, + "build": { + "executor": "@nrwl/workspace:run-commands", + "outputs": ["dist/packages"], + "options": { + "command": "npx zx ./tools/scripts/pack-webpack5.mjs" + } + } + } +} diff --git a/tools/scripts/project.json b/tools/scripts/project.json new file mode 100644 index 000000000..a5aa21ebd --- /dev/null +++ b/tools/scripts/project.json @@ -0,0 +1,17 @@ +{ + "root": "tools/scripts", + "sourceRoot": "tools/scripts", + "projectType": "library", + "generators": {}, + "targets": { + "build": { + "executor": "@nrwl/workspace:run-commands", + "outputs": ["tools/scripts/dist"], + "options": { + "commands": ["./build-docs.sh"], + "cwd": "tools/scripts", + "parallel": false + } + } + } +} diff --git a/tools/scripts/tsconfig.typedoc.json b/tools/scripts/tsconfig.typedoc.json index 290e69cf6..1e04a3340 100644 --- a/tools/scripts/tsconfig.typedoc.json +++ b/tools/scripts/tsconfig.typedoc.json @@ -1,5 +1,5 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "../../dist/packages/core", "target": "es5", diff --git a/tools/tsconfig.tools.json b/tools/tsconfig.tools.json index 82bd1f098..600c137a6 100644 --- a/tools/tsconfig.tools.json +++ b/tools/tsconfig.tools.json @@ -1,11 +1,11 @@ { - "extends": "../tsconfig.json", - "compilerOptions": { - "outDir": "../dist/out-tsc/tools", - "rootDir": ".", - "module": "commonjs", - "target": "es5", - "types": ["node"] - }, - "include": ["**/*.ts"] + "extends": "../tsconfig.base.json", + "compilerOptions": { + "outDir": "../dist/out-tsc/tools", + "rootDir": ".", + "module": "commonjs", + "target": "es5", + "types": ["node"] + }, + "include": ["**/*.ts"] } diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 000000000..b3dfa14cd --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,28 @@ +{ + "compileOnSave": false, + "compilerOptions": { + "rootDir": ".", + "target": "ES2017", + "module": "esnext", + "sourceMap": true, + "declaration": true, + "moduleResolution": "node", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "noEmitOnError": true, + "noEmitHelpers": true, + "diagnostics": true, + "skipLibCheck": true, + "skipDefaultLibCheck": true, + "lib": ["es2017", "dom"], + "types": ["node", "jest"], + "baseUrl": ".", + "paths": { + "@nativescript/core": ["packages/core/index.ts"], + "@nativescript/core/*": ["packages/core/*"], + "@nativescript/types-android": ["packages/types-android/src/index.ts"], + "@nativescript/types-ios": ["packages/types-ios/src/index.ts"] + } + }, + "exclude": ["node_modules", "tmp", "platforms", "__tests__"] +} diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 5d8f21e45..6ca1bac23 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -1,4 +1,4 @@ { - "extends": "./tsconfig.json", + "extends": "./tsconfig.base.json", "include": ["packages/**/*"] } diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 84a284c7c..000000000 --- a/tsconfig.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "compileOnSave": false, - "compilerOptions": { - "rootDir": ".", - "target": "ES2017", - "module": "esnext", - "sourceMap": true, - "declaration": true, - "moduleResolution": "node", - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "noEmitOnError": true, - "noEmitHelpers": true, - "diagnostics": true, - "skipLibCheck": true, - "skipDefaultLibCheck": true, - "lib": ["es2017", "dom"], - "types": ["node", "jest"], - "baseUrl": ".", - "paths": { - "@nativescript/core": ["packages/core/index.ts"], - "@nativescript/core/*": ["packages/core/*"], - "@nativescript/types-ios": ["packages/types-ios/src/index.ts"], - "@nativescript/types-android": ["packages/types-android/src/index.ts"] - } - }, - "exclude": ["node_modules", "tmp", "platforms", "__tests__"] -} diff --git a/workspace.json b/workspace.json index 83b3140c9..528c22834 100644 --- a/workspace.json +++ b/workspace.json @@ -1,350 +1,16 @@ { - "version": 1, + "version": 2, "projects": { - "apps-automated": { - "root": "apps/automated/", - "sourceRoot": "apps/automated/app", - "projectType": "application", - "prefix": "nativescript", - "architect": { - "ios": { - "builder": "@nrwl/workspace:run-commands", - "options": { - "commands": ["ns debug ios --no-hmr --emulator --env.testing"], - "cwd": "apps/automated", - "parallel": false - } - }, - "android": { - "builder": "@nrwl/workspace:run-commands", - "options": { - "commands": ["ns debug android --no-hmr --emulator --env.testing"], - "cwd": "apps/automated", - "parallel": false - } - }, - "clean": { - "builder": "@nrwl/workspace:run-commands", - "options": { - "commands": ["npx rimraf -- hooks node_modules platforms package-lock.json", "npm i --legacy-peer-deps", "npx rimraf -- package-lock.json"], - "cwd": "apps/automated", - "parallel": false - } - } - } - }, - "apps-toolbox": { - "root": "apps/toolbox/", - "sourceRoot": "apps/toolbox/src", - "projectType": "application", - "prefix": "nativescript", - "architect": { - "ios": { - "builder": "@nrwl/workspace:run-commands", - "options": { - "commands": ["ns debug ios --no-hmr --emulator --env.testing"], - "cwd": "apps/toolbox", - "parallel": false - } - }, - "android": { - "builder": "@nrwl/workspace:run-commands", - "options": { - "commands": ["ns debug android --no-hmr --emulator --env.testing"], - "cwd": "apps/toolbox", - "parallel": false - } - }, - "clean": { - "builder": "@nrwl/workspace:run-commands", - "options": { - "commands": ["npx rimraf -- hooks node_modules platforms package-lock.json", "npm i --legacy-peer-deps", "npx rimraf -- package-lock.json"], - "cwd": "apps/toolbox", - "parallel": false - } - } - } - }, - "apps-ui": { - "root": "apps/ui/", - "sourceRoot": "apps/ui/src", - "projectType": "application", - "prefix": "nativescript", - "architect": { - "ios": { - "builder": "@nrwl/workspace:run-commands", - "options": { - "commands": ["ns debug ios --no-hmr --emulator --env.testing"], - "cwd": "apps/ui", - "parallel": false - } - }, - "android": { - "builder": "@nrwl/workspace:run-commands", - "options": { - "commands": ["ns debug android --no-hmr --emulator --env.testing"], - "cwd": "apps/ui", - "parallel": false - } - }, - "clean": { - "builder": "@nrwl/workspace:run-commands", - "options": { - "commands": ["npx rimraf -- hooks node_modules platforms package-lock.json", "npm i --legacy-peer-deps", "npx rimraf -- package-lock.json"], - "cwd": "apps/ui", - "parallel": false - } - } - } - }, - "core": { - "root": "packages/core", - "sourceRoot": "packages/core", - "projectType": "library", - "schematics": {}, - "architect": { - "lint": { - "builder": "@nrwl/linter:eslint", - "options": { - "lintFilePatterns": ["packages/core/**/*.ts", "packages/core/references.d.ts", "packages/core/**/*.spec.ts", "packages/core/**/*.spec.tsx", "packages/core/**/*.spec.js", "packages/core/**/*.spec.jsx", "packages/core/**/*.d.ts"] - } - }, - "test": { - "builder": "@nrwl/jest:jest", - "options": { - "jestConfig": "packages/core/jest.config.js", - "passWithNoTests": true - }, - "outputs": ["coverage/packages/core"] - }, - "build": { - "builder": "@nrwl/workspace:run-commands", - "outputs": ["dist/packages"], - "options": { - "commands": [ - "npx rimraf dist/packages/core", - "./node_modules/.bin/tsc -p packages/core/tsconfig.lib.json", - "./node_modules/.bin/copyfiles -e \"packages/core/__tests__/**/*\" \"packages/core/**/*.d.ts\" dist && ./node_modules/.bin/copyfiles -e \"packages/core/__tests__/**/*\" \"packages/core/js-libs/**/*\" dist && ./node_modules/.bin/copyfiles -e \"packages/core/__tests__/**/*\" \"packages/core/cli-hooks/**/*.js\" dist && ./node_modules/.bin/copyfiles -e \"packages/core/__tests__/**/*\" \"packages/core/platforms/**/*\" dist && ./node_modules/.bin/copyfiles -e \"packages/core/__tests__/**/*\" \"packages/core/fetch/**/*\" dist && ./node_modules/.bin/copyfiles -e \"packages/core/__tests__/**/*\" \"packages/core/css/**/*\" dist && ./node_modules/.bin/copyfiles -e \"packages/core/__tests__/**/*\" \"packages/core/css-value/**/*\" dist", - "cp packages/core/package.json dist/packages/core", - "cp packages/core/README.md dist/packages/core", - "cp LICENSE dist/packages/core", - "cd dist/packages/core && npm pack && mv *.tgz .." - ], - "cwd": ".", - "parallel": false - } - }, - "unit": { - "builder": "@nrwl/workspace:run-commands", - "options": { - "commands": ["../../../node_modules/.bin/tsc -p tsconfig.json && ../../../node_modules/.bin/mocha --config=.mocharc.yml"], - "cwd": "packages/core/__tests__", - "parallel": false - } - }, - "unit.watch": { - "builder": "@nrwl/workspace:run-commands", - "options": { - "commands": ["../../../node_modules/.bin/tsc -p tsconfig.json && ../../../node_modules/.bin/mocha --watch --config=.mocharc.yml"], - "cwd": "packages/core/__tests__", - "parallel": false - } - } - } - }, - "core-api-docs": { - "root": "tools/scripts", - "sourceRoot": "tools/scripts", - "projectType": "library", - "schematics": {}, - "architect": { - "build": { - "builder": "@nrwl/workspace:run-commands", - "outputs": ["tools/scripts/dist"], - "options": { - "commands": ["./build-docs.sh"], - "cwd": "tools/scripts", - "parallel": false - } - } - } - }, - "types": { - "root": "packages/types", - "sourceRoot": "packages/types", - "projectType": "library", - "schematics": {}, - "architect": { - "build": { - "builder": "@nrwl/workspace:run-commands", - "outputs": ["dist/packages"], - "options": { - "commands": ["mkdir -p ../../dist/packages/types", "cp -R * ../../dist/packages/types"], - "cwd": "packages/types", - "parallel": false - } - } - } - }, - "types-ios": { - "root": "packages/types-ios", - "sourceRoot": "packages/types-ios/src", - "projectType": "library", - "schematics": {}, - "architect": { - "build": { - "builder": "@nrwl/workspace:run-commands", - "outputs": ["dist/packages"], - "options": { - "commands": ["./tools/scripts/typings-gen.sh latest", "mkdir -p dist/packages/types-ios", "cp -R packages/types-ios/src/* dist/packages/types-ios", "cp packages/types-ios/package.json dist/packages/types-ios", "cp packages/types-ios/README.md dist/packages/types-ios/README.md"], - "parallel": false - } - } - } - }, - "types-android": { - "root": "packages/types-android", - "sourceRoot": "packages/types-android/src", - "projectType": "library", - "schematics": {}, - "architect": { - "build": { - "builder": "@nrwl/workspace:run-commands", - "outputs": ["dist/packages"], - "options": { - "commands": ["mkdir -p ../../dist/packages/types-android", "cp -R src/* ../../dist/packages/types-android", "cp package.json *.md ../../dist/packages/types-android"], - "cwd": "packages/types-android", - "parallel": false - } - } - } - }, - "ui-mobile-base": { - "root": "packages/ui-mobile-base", - "sourceRoot": "packages/ui-mobile-base", - "projectType": "library", - "schematics": {}, - "architect": { - "build": { - "builder": "@nrwl/workspace:run-commands", - "options": { - "commands": ["./build.sh", "cp -R dist/package/platforms/* ../../packages/core/platforms"], - "cwd": "packages/ui-mobile-base", - "parallel": false - } - } - } - }, - "webpack": { - "root": "packages/webpack", - "sourceRoot": "packages/webpack", - "projectType": "library", - "schematics": {}, - "architect": { - "lint": { - "builder": "@nrwl/linter:eslint", - "options": { - "lintFilePatterns": [] - } - }, - "test": { - "builder": "@nrwl/workspace:run-commands", - "options": { - "commands": ["npm run tsc", "npm run jasmine"], - "cwd": "packages/webpack", - "parallel": false - } - }, - "build": { - "builder": "@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 - } - } - } - }, - "webpack5": { - "root": "packages/webpack5", - "sourceRoot": "packages/webpack5", - "projectType": "library", - "schematics": {}, - "architect": { - "lint": { - "builder": "@nrwl/linter:eslint", - "options": { - "lintFilePatterns": [] - } - }, - "build": { - "builder": "@nrwl/workspace:run-commands", - "outputs": ["dist/packages"], - "options": { - "command": "npx zx ./tools/scripts/pack-webpack5.mjs" - } - } - } - } - }, - "cli": { - "defaultCollection": "@nrwl/workspace" - }, - "schematics": { - "@nrwl/workspace": { - "library": { - "linter": "eslint" - } - }, - "@nrwl/cypress": { - "cypress-project": { - "linter": "eslint" - } - }, - "@nrwl/react": { - "application": { - "linter": "eslint" - }, - "library": { - "linter": "eslint" - } - }, - "@nrwl/next": { - "application": { - "linter": "eslint" - } - }, - "@nrwl/web": { - "application": { - "linter": "eslint" - } - }, - "@nrwl/node": { - "application": { - "linter": "eslint" - }, - "library": { - "linter": "eslint" - } - }, - "@nrwl/nx-plugin": { - "plugin": { - "linter": "eslint" - } - }, - "@nrwl/nest": { - "application": { - "linter": "eslint" - } - }, - "@nrwl/express": { - "application": { - "linter": "eslint" - }, - "library": { - "linter": "eslint" - } - } + "apps-automated": "apps/automated", + "apps-toolbox": "apps/toolbox", + "apps-ui": "apps/ui", + "core": "packages/core", + "core-api-docs": "tools/scripts", + "types": "packages/types", + "types-android": "packages/types-android", + "types-ios": "packages/types-ios", + "ui-mobile-base": "packages/ui-mobile-base", + "webpack": "packages/webpack", + "webpack5": "packages/webpack5" } } From 0df5aa9712811db31b29aa2013ce8c95b31d6073 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Wed, 22 Dec 2021 16:54:17 -0300 Subject: [PATCH 31/35] feat(webpack): disable aot flag, optional angular dep and tsconfig utils (#9711) Co-authored-by: Igor Randjelovic --- .../__snapshots__/angular.spec.ts.snap | 6 +- packages/webpack5/package.json | 1 + .../webpack5/src/configuration/angular.ts | 57 +++++++++++++------ packages/webpack5/src/helpers/index.ts | 4 ++ packages/webpack5/src/helpers/tsconfig.ts | 19 +++++++ 5 files changed, 68 insertions(+), 19 deletions(-) create mode 100644 packages/webpack5/src/helpers/tsconfig.ts diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap index 0327df79e..51ea03a17 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap @@ -400,7 +400,8 @@ exports[`angular configuration for android 1`] = ` new AngularWebpackPlugin( { tsconfig: '__jest__/tsconfig.json', - directTemplateLoading: false + directTemplateLoading: false, + jitMode: false } ) ], @@ -816,7 +817,8 @@ exports[`angular configuration for ios 1`] = ` new AngularWebpackPlugin( { tsconfig: '__jest__/tsconfig.json', - directTemplateLoading: false + directTemplateLoading: false, + jitMode: false } ) ], diff --git a/packages/webpack5/package.json b/packages/webpack5/package.json index efe0c2228..6f6fb84ca 100644 --- a/packages/webpack5/package.json +++ b/packages/webpack5/package.json @@ -54,6 +54,7 @@ "webpack-virtual-modules": "^0.4.0" }, "devDependencies": { + "@angular-devkit/build-angular": "^13.1.2", "@types/css": "0.0.33", "@types/jest": "27.0.1", "@types/loader-utils": "2.0.3", diff --git a/packages/webpack5/src/configuration/angular.ts b/packages/webpack5/src/configuration/angular.ts index bc7478942..74237fa2a 100644 --- a/packages/webpack5/src/configuration/angular.ts +++ b/packages/webpack5/src/configuration/angular.ts @@ -3,8 +3,11 @@ import { extname, resolve } from 'path'; import Config from 'webpack-chain'; import { existsSync } from 'fs'; +import { getDependencyPath } from '../helpers/dependencies'; import { getProjectFilePath } from '../helpers/project'; import { env as _env, IWebpackEnv } from '../index'; +import { readTsConfig } from '../helpers/tsconfig'; +import { warnOnce } from '../helpers/log'; import { getEntryDirPath, getEntryPath, @@ -22,6 +25,8 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { getProjectFilePath('tsconfig.json'), ].find((path) => existsSync(path)); + const disableAOT = !!env.disableAOT; + // remove default ts rule config.module.rules.delete('ts'); @@ -158,6 +163,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { { tsconfig: tsConfigPath, directTemplateLoading: false, + jitMode: disableAOT, }, ]); @@ -169,23 +175,40 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { .use('angular-hot-loader') .loader('angular-hot-loader'); }); - // zone + async/await - config.module - .rule('angular-webpack-loader') - .test(/\.[cm]?[tj]sx?$/) - .exclude.add( - /[/\\](?:core-js|@babel|tslib|web-animations-js|web-streams-polyfill)[/\\]/ - ) - .end() - .resolve.set('fullySpecified', false) - .end() - .before('angular') - .use('webpack-loader') - .loader('@angular-devkit/build-angular/src/babel/webpack-loader') - .options({ - scriptTarget: ScriptTarget.ESNext, - aot: true, - }); + + const buildAngularPath = getDependencyPath('@angular-devkit/build-angular'); + if (buildAngularPath) { + const tsConfig = readTsConfig(tsConfigPath); + const scriptTarget = tsConfig.options.target ?? ScriptTarget.ESNext; + const buildAngularOptions: any = { + scriptTarget, + aot: !disableAOT, + }; + if (disableAOT) { + buildAngularOptions.optimize = false; + } + // zone + async/await + config.module + .rule('angular-webpack-loader') + .test(/\.[cm]?[tj]sx?$/) + .exclude.add( + /[/\\](?:core-js|@babel|tslib|web-animations-js|web-streams-polyfill)[/\\]/ + ) + .end() + .resolve.set('fullySpecified', false) + .end() + .before('angular') + .use('webpack-loader') + .loader('@angular-devkit/build-angular/src/babel/webpack-loader') + .options(buildAngularOptions); + } else { + warnOnce( + 'build-angular-missing', + ` + @angular-devkit/build-angular is missing! Some features may not work as expected. Please install it manually to get rid of this warning. + ` + ); + } } // look for platform specific polyfills first diff --git a/packages/webpack5/src/helpers/index.ts b/packages/webpack5/src/helpers/index.ts index 56637d566..2bd6ababb 100644 --- a/packages/webpack5/src/helpers/index.ts +++ b/packages/webpack5/src/helpers/index.ts @@ -26,6 +26,7 @@ import { getPlatform, getPlatformName, } from './platform'; +import { readTsConfig } from './tsconfig'; // intentionally populated manually // as this generates nicer typings @@ -75,4 +76,7 @@ export default { addVirtualEntry, addVirtualModule, }, + tsconfig: { + readTsConfig, + }, }; diff --git a/packages/webpack5/src/helpers/tsconfig.ts b/packages/webpack5/src/helpers/tsconfig.ts new file mode 100644 index 000000000..25fd5b604 --- /dev/null +++ b/packages/webpack5/src/helpers/tsconfig.ts @@ -0,0 +1,19 @@ +import { readConfigFile, parseJsonConfigFileContent, sys } from 'typescript'; +import { dirname } from 'path'; + +export function readTsConfig(path: string) { + const f = readConfigFile(path, sys.readFile); + + const parsed = parseJsonConfigFileContent( + f.config, + { + fileExists: sys.fileExists, + readFile: sys.readFile, + readDirectory: sys.readDirectory, + useCaseSensitiveFileNames: true, + }, + dirname(path) + ); + + return parsed; +} From 6ca3d353ead1f9e1d8b5e682ce5fe8d324361d6f Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Wed, 22 Dec 2021 21:01:30 +0100 Subject: [PATCH 32/35] chore(release): @nativescript/webpack 5.0.3 --- packages/webpack5/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webpack5/package.json b/packages/webpack5/package.json index 6f6fb84ca..d4d9cbc40 100644 --- a/packages/webpack5/package.json +++ b/packages/webpack5/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/webpack", - "version": "5.0.2-alpha.1", + "version": "5.0.3", "private": false, "main": "dist/index.js", "files": [ From 965ccb4aec57a874399586801880e028169b1f20 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Thu, 23 Dec 2021 22:48:00 +0100 Subject: [PATCH 33/35] fix(webpack): typescript imports in non-ts projects (#9714) --- .../webpack5/src/configuration/angular.ts | 4 +- packages/webpack5/src/helpers/index.ts | 2 +- packages/webpack5/src/helpers/tsconfig.ts | 19 ------- packages/webpack5/src/helpers/typescript.ts | 54 +++++++++++++++++++ 4 files changed, 57 insertions(+), 22 deletions(-) delete mode 100644 packages/webpack5/src/helpers/tsconfig.ts create mode 100644 packages/webpack5/src/helpers/typescript.ts diff --git a/packages/webpack5/src/configuration/angular.ts b/packages/webpack5/src/configuration/angular.ts index 74237fa2a..8b9b5e498 100644 --- a/packages/webpack5/src/configuration/angular.ts +++ b/packages/webpack5/src/configuration/angular.ts @@ -1,12 +1,11 @@ -import { ScriptTarget } from 'typescript'; import { extname, resolve } from 'path'; import Config from 'webpack-chain'; import { existsSync } from 'fs'; +import { getTypescript, readTsConfig } from '../helpers/typescript'; import { getDependencyPath } from '../helpers/dependencies'; import { getProjectFilePath } from '../helpers/project'; import { env as _env, IWebpackEnv } from '../index'; -import { readTsConfig } from '../helpers/tsconfig'; import { warnOnce } from '../helpers/log'; import { getEntryDirPath, @@ -179,6 +178,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { const buildAngularPath = getDependencyPath('@angular-devkit/build-angular'); if (buildAngularPath) { const tsConfig = readTsConfig(tsConfigPath); + const { ScriptTarget } = getTypescript(); const scriptTarget = tsConfig.options.target ?? ScriptTarget.ESNext; const buildAngularOptions: any = { scriptTarget, diff --git a/packages/webpack5/src/helpers/index.ts b/packages/webpack5/src/helpers/index.ts index 2bd6ababb..88c5b6267 100644 --- a/packages/webpack5/src/helpers/index.ts +++ b/packages/webpack5/src/helpers/index.ts @@ -26,7 +26,7 @@ import { getPlatform, getPlatformName, } from './platform'; -import { readTsConfig } from './tsconfig'; +import { readTsConfig } from './typescript'; // intentionally populated manually // as this generates nicer typings diff --git a/packages/webpack5/src/helpers/tsconfig.ts b/packages/webpack5/src/helpers/tsconfig.ts deleted file mode 100644 index 25fd5b604..000000000 --- a/packages/webpack5/src/helpers/tsconfig.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { readConfigFile, parseJsonConfigFileContent, sys } from 'typescript'; -import { dirname } from 'path'; - -export function readTsConfig(path: string) { - const f = readConfigFile(path, sys.readFile); - - const parsed = parseJsonConfigFileContent( - f.config, - { - fileExists: sys.fileExists, - readFile: sys.readFile, - readDirectory: sys.readDirectory, - useCaseSensitiveFileNames: true, - }, - dirname(path) - ); - - return parsed; -} diff --git a/packages/webpack5/src/helpers/typescript.ts b/packages/webpack5/src/helpers/typescript.ts new file mode 100644 index 000000000..8e1cccc05 --- /dev/null +++ b/packages/webpack5/src/helpers/typescript.ts @@ -0,0 +1,54 @@ +import { dirname } from 'path'; +import { env } from '..'; + +import { warnOnce } from './log'; + +/** + * @internal + */ +let typescript: typeof import('typescript'); + +/** + * Helper used to import typescript. + * + * The reason this exists is that not all flavors use Typescript, and + * in those cases just importing this helper will throw an exception. + */ +export function getTypescript(): typeof import('typescript') { + if (typescript) { + return typescript; + } + + try { + typescript = require('typescript'); + return typescript; + } catch (err) { + warnOnce( + 'typescript-missing', + `TypeScript is not installed in this project, but a config is trying to use it.`, + env.verbose + ? new Error().stack + : 'Run with --env.verbose to log a stack trace to help debug this further.' + ); + + return {} as any; + } +} + +export function readTsConfig(path: string) { + const { readConfigFile, parseJsonConfigFileContent, sys } = getTypescript(); + const f = readConfigFile(path, sys.readFile); + + const parsed = parseJsonConfigFileContent( + f.config, + { + fileExists: sys.fileExists, + readFile: sys.readFile, + readDirectory: sys.readDirectory, + useCaseSensitiveFileNames: true, + }, + dirname(path) + ); + + return parsed; +} From d8d624a154f8b02814e797ce0c6b76aba969dbf3 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Thu, 23 Dec 2021 22:49:18 +0100 Subject: [PATCH 34/35] chore(release): @nativescript/webpack 5.0.4 --- packages/webpack5/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webpack5/package.json b/packages/webpack5/package.json index d4d9cbc40..565c50ff0 100644 --- a/packages/webpack5/package.json +++ b/packages/webpack5/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/webpack", - "version": "5.0.3", + "version": "5.0.4", "private": false, "main": "dist/index.js", "files": [ From c6bfc05bb766f2fca386b694a2cb464a13c99319 Mon Sep 17 00:00:00 2001 From: Ikko Ashimine Date: Fri, 24 Dec 2021 08:03:11 +0900 Subject: [PATCH 35/35] chore(core): fix typo in timer readme.md (#9634) --- packages/core/timer/Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/timer/Readme.md b/packages/core/timer/Readme.md index 1f96d1bb8..bbb1384a4 100644 --- a/packages/core/timer/Readme.md +++ b/packages/core/timer/Readme.md @@ -1,4 +1,4 @@ -Timer module. Functions also can be availble in the global context if you require *globals* module. +Timer module. Functions also can be available in the global context if you require *globals* module. ```js require("globals");