From 0df5aa9712811db31b29aa2013ce8c95b31d6073 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Wed, 22 Dec 2021 16:54:17 -0300 Subject: [PATCH 1/9] 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 2/9] 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 3/9] 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 4/9] 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 5/9] 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"); From 0634b8af05bb4fababdac6fba279d5a5c3bc73f9 Mon Sep 17 00:00:00 2001 From: Anil Seervi <61609033+AnilSeervi@users.noreply.github.com> Date: Sun, 23 Jan 2022 22:32:21 +0530 Subject: [PATCH 6/9] chore: update license type badge (#9717) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 153f98b65..94ba16a31 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,6 @@ Outside the source centralized in this repo, NativeScript consists of a few othe - This repo contains the NativeScript framework documentation, which is available at . The docs are written in Markdown. ## License -[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/NativeScript/NativeScript/blob/master/LICENSE) +[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/NativeScript/NativeScript/blob/master/LICENSE)

Made with ❤️

From aa0180c3f1818600dc81b8f8d4bfa7236208e6e6 Mon Sep 17 00:00:00 2001 From: Shiva Prasad Date: Wed, 2 Feb 2022 14:54:32 +1300 Subject: [PATCH 7/9] Update bug_report.yaml --- .github/ISSUE_TEMPLATE/bug_report.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 5b8192ca7..027de0815 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -72,14 +72,14 @@ body: Provide information about your environment. Run ```shell - npx -y nativescript-envinfo + npx nativescript-envinfo -y ``` inside the project and paste the output directly without manual formatting. placeholder: | Paste the result of - npx -y nativescript-envinfo + npx nativescript-envinfo -y - type: markdown attributes: From 980eb213f9871e89a62f883bbd9fb540f6370295 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Wed, 2 Feb 2022 14:34:34 +0100 Subject: [PATCH 8/9] chore: update envinfo command --- .github/ISSUE_TEMPLATE/bug_report.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 027de0815..c192ceaab 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -72,14 +72,14 @@ body: Provide information about your environment. Run ```shell - npx nativescript-envinfo -y + echo 'y' | npx nativescript-envinfo ``` inside the project and paste the output directly without manual formatting. placeholder: | Paste the result of - npx nativescript-envinfo -y + echo 'y' | npx nativescript-envinfo - type: markdown attributes: From 1601caff4e175024248a548a39755d98b175705a Mon Sep 17 00:00:00 2001 From: Ikko Ashimine Date: Thu, 17 Feb 2022 00:07:43 +0900 Subject: [PATCH 9/9] chore: fix typo in moduleid-compat-loader.js (#9776) occurences -> occurrences --- packages/webpack/helpers/moduleid-compat-loader.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webpack/helpers/moduleid-compat-loader.js b/packages/webpack/helpers/moduleid-compat-loader.js index ec8ec963d..6ade9e7f7 100644 --- a/packages/webpack/helpers/moduleid-compat-loader.js +++ b/packages/webpack/helpers/moduleid-compat-loader.js @@ -6,11 +6,11 @@ module.exports = function (source, map) { this.cacheable(); - // Strips occurences of `moduleId: module.id,`, since it is no longer needed for webpack builds + // Strips occurrences of `moduleId: module.id,`, since it is no longer needed for webpack builds const noModuleIdsSource = source.replace(/moduleId\:\s*module\.id\s*(\,)?/g, result => // Try to preserve char count so sourcemaps may remain intact "/*" + result.substring(2, result.length - 2) + "*/" ); this.callback(null, noModuleIdsSource, map); -}; \ No newline at end of file +};