From 1fbce9a88a1e1c4466387f343903f7b5c4daa085 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Mon, 15 Apr 2024 17:44:24 +0200 Subject: [PATCH 1/3] fix: detect core version before including inspector_modules on android --- .../__snapshots__/angular.spec.ts.snap | 3 -- .../__snapshots__/base.spec.ts.snap | 3 -- .../__snapshots__/javascript.spec.ts.snap | 3 -- .../__snapshots__/react.spec.ts.snap | 6 --- .../__snapshots__/svelte.spec.ts.snap | 3 -- .../__snapshots__/typescript.spec.ts.snap | 3 -- .../__snapshots__/vue.spec.ts.snap | 3 -- .../__tests__/configuration/base.spec.ts | 27 ++++++++++++++ packages/webpack5/package.json | 1 + .../webpack5/src/configuration/angular.ts | 37 +++++-------------- packages/webpack5/src/configuration/base.ts | 19 ++++++---- packages/webpack5/src/helpers/dependencies.ts | 20 ++++++++++ 12 files changed, 70 insertions(+), 58 deletions(-) diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap index 312b302dd7..052a93546b 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap @@ -435,9 +435,6 @@ exports[`angular configuration for android 1`] = ` '__jest__/src/app.js', '@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity' - ], - 'tns_modules/inspector_modules': [ - '@nativescript/core/inspector_modules' ] } }" diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap index df1f7b73b8..85186700e1 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap @@ -323,9 +323,6 @@ exports[`base configuration for android 1`] = ` '__jest__/src/app.js', '@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity' - ], - 'tns_modules/inspector_modules': [ - '@nativescript/core/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 8bd1b9d502..05db5382e0 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap @@ -322,9 +322,6 @@ exports[`javascript configuration for android 1`] = ` '__jest__/src/app.js', '@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity' - ], - 'tns_modules/inspector_modules': [ - '@nativescript/core/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 7c9e4c21f8..f5f97000a2 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap @@ -352,9 +352,6 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR '__jest__/src/app.js', '@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity' - ], - 'tns_modules/inspector_modules': [ - '@nativescript/core/inspector_modules' ] } }" @@ -683,9 +680,6 @@ exports[`react configuration > android > base config 1`] = ` '__jest__/src/app.js', '@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity' - ], - 'tns_modules/inspector_modules': [ - '@nativescript/core/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 19276b868f..276d6790ad 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap @@ -344,9 +344,6 @@ exports[`svelte configuration for android 1`] = ` '__jest__/src/app.js', '@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity' - ], - 'tns_modules/inspector_modules': [ - '@nativescript/core/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 59e4f1f108..4c59228e5e 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap @@ -322,9 +322,6 @@ exports[`typescript configuration for android 1`] = ` '__jest__/src/app.js', '@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity' - ], - 'tns_modules/inspector_modules': [ - '@nativescript/core/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 43758bc192..da0ab5b34f 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap @@ -357,9 +357,6 @@ exports[`vue configuration for android 1`] = ` '__jest__/src/app.js', '@nativescript/core/ui/frame', '@nativescript/core/ui/frame/activity' - ], - 'tns_modules/inspector_modules': [ - '@nativescript/core/inspector_modules' ] } }" diff --git a/packages/webpack5/__tests__/configuration/base.spec.ts b/packages/webpack5/__tests__/configuration/base.spec.ts index 3a5690f313..98d431eb45 100644 --- a/packages/webpack5/__tests__/configuration/base.spec.ts +++ b/packages/webpack5/__tests__/configuration/base.spec.ts @@ -4,6 +4,7 @@ import fs from 'fs'; import base from '../../src/configuration/base'; import { init } from '../../src'; import { applyFileReplacements } from '../../src/helpers/fileReplacements'; +import * as dependenciesHelpers from '../../src/helpers/dependencies'; import { additionalCopyRules } from '../../src/helpers/copyRules'; describe('base configuration', () => { @@ -221,4 +222,30 @@ describe('base configuration', () => { expect(config.output.get('sourceMapFilename')).toMatchSnapshot(); expect(config.get('devtool')).toBe('hidden-source-map'); }); + + it('includes inspector_modules on android when @nativescript/core version is >= 8.7.0', () => { + const getDependencyVersionSpy = jest.spyOn( + dependenciesHelpers, + 'getDependencyVersion' + ); + getDependencyVersionSpy.withImplementation( + (name) => { + if (name === '@nativescript/core') { + return '8.7.0'; + } + return null; + }, + () => { + init({ + android: true, + }); + + const config = base(new Config()); + const entry = config.entryPoints.get('tns_modules/inspector_modules'); + + expect(entry).toBeDefined(); + expect(entry.values().length).toBe(1); + } + ); + }); }); diff --git a/packages/webpack5/package.json b/packages/webpack5/package.json index e2e598cb1b..ccc7e2c4b6 100644 --- a/packages/webpack5/package.json +++ b/packages/webpack5/package.json @@ -41,6 +41,7 @@ "sass": "^1.0.0", "sass-loader": "^13.0.0", "sax": "^1.0.0", + "semver": "^7.6.0", "source-map": "^0.7.0", "terser-webpack-plugin": "^5.0.0", "ts-dedent": "^2.0.0", diff --git a/packages/webpack5/src/configuration/angular.ts b/packages/webpack5/src/configuration/angular.ts index 18fddf47b6..31c2a845c4 100644 --- a/packages/webpack5/src/configuration/angular.ts +++ b/packages/webpack5/src/configuration/angular.ts @@ -3,7 +3,7 @@ import Config from 'webpack-chain'; import { existsSync } from 'fs'; import { getTypescript, readTsConfig } from '../helpers/typescript'; -import { getDependencyPath } from '../helpers/dependencies'; +import { getDependencyVersion } from '../helpers/dependencies'; import { getProjectTSConfigPath } from '../helpers/project'; import { env as _env, IWebpackEnv } from '../index'; import { warnOnce } from '../helpers/log'; @@ -13,6 +13,7 @@ import { getPlatformName, } from '../helpers/platform'; import base from './base'; +import { satisfies } from 'semver'; // until we can switch to async/await on the webpack config, copy this from '@angular/compiler-cli' const GLOBAL_DEFS_FOR_TERSER = { @@ -187,13 +188,16 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { .loader('angular-hot-loader'); }); - const buildAngularMajorVersion = getBuildAngularMajorVersion(); - if (buildAngularMajorVersion) { + const buildAngularVersion = getDependencyVersion( + '@angular-devkit/build-angular' + ); + + if (buildAngularVersion) { const buildAngularOptions: any = { aot: !disableAOT, }; - if (buildAngularMajorVersion < 15) { + if (satisfies(buildAngularVersion, '<15.0.0')) { const tsConfig = readTsConfig(tsConfigPath); const { ScriptTarget } = getTypescript(); buildAngularOptions.scriptTarget = @@ -315,27 +319,6 @@ function getAngularWebpackPlugin(): any { return AngularWebpackPlugin; } -const MAJOR_VER_RE = /^(\d+)\./; -function getBuildAngularMajorVersion() { - const buildAngularPath = getDependencyPath('@angular-devkit/build-angular'); - if (!buildAngularPath) { - return null; - } - - try { - const buildAngularVersion = - require(`${buildAngularPath}/package.json`).version; - - const [_, majorStr] = buildAngularVersion.match(MAJOR_VER_RE); - - return Number(majorStr); - } catch (err) { - // ignore - } - - return null; -} - function tryRequireResolve(path: string) { try { return require.resolve(path); @@ -348,10 +331,10 @@ function getWebpackLoaderPath() { return ( tryRequireResolve( '@angular-devkit/build-angular/src/babel/webpack-loader' - ) || + ) ?? tryRequireResolve( '@angular-devkit/build-angular/src/tools/babel/webpack-loader' - ) || + ) ?? // fallback to angular 16.1+ '@angular-devkit/build-angular/src/tools/babel/webpack-loader' ); diff --git a/packages/webpack5/src/configuration/base.ts b/packages/webpack5/src/configuration/base.ts index 3d4b070b80..bb86f17960 100644 --- a/packages/webpack5/src/configuration/base.ts +++ b/packages/webpack5/src/configuration/base.ts @@ -5,6 +5,7 @@ import { HotModuleReplacementPlugin, } from 'webpack'; import Config from 'webpack-chain'; +import { satisfies } from 'semver'; import { existsSync } from 'fs'; import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'; @@ -12,11 +13,11 @@ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; import TerserPlugin from 'terser-webpack-plugin'; import { getProjectFilePath, getProjectTSConfigPath } from '../helpers/project'; +import { getDependencyVersion, hasDependency } from '../helpers/dependencies'; import { PlatformSuffixPlugin } from '../plugins/PlatformSuffixPlugin'; import { applyFileReplacements } from '../helpers/fileReplacements'; import { addCopyRule, applyCopyRules } from '../helpers/copyRules'; import { WatchStatePlugin } from '../plugins/WatchStatePlugin'; -import { hasDependency } from '../helpers/dependencies'; import { applyDotEnvPlugin } from '../helpers/dotEnv'; import { env as _env, IWebpackEnv } from '../index'; import { getValue } from '../helpers/config'; @@ -86,7 +87,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { const sourceMapAbsolutePath = getProjectFilePath( `./${ env.buildPath ?? 'platforms' - }/${platform}-sourceMaps/[file].map[query]`, + }/${platform}-sourceMaps/[file].map[query]` ); const sourceMapRelativePath = relative(outputPath, sourceMapAbsolutePath); config.output.sourceMapFilename(sourceMapRelativePath); @@ -272,7 +273,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { const configFile = tsConfigPath ? { configFile: tsConfigPath, - } + } : undefined; // set up ts support @@ -451,7 +452,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { * +-----------------------------------------------------------------------------------------+ */ /System.import\(\) is deprecated/, - ]), + ]) ); // todo: refine defaults @@ -516,7 +517,11 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { function shouldIncludeInspectorModules(): boolean { const platform = getPlatformName(); - // todo: check if core modules are external - // todo: check if we are testing - return platform === 'ios' || platform === 'android'; + const coreVersion = getDependencyVersion('@nativescript/core'); + + if (coreVersion && satisfies(coreVersion, '>=8.7.0')) { + return platform === 'ios' || platform === 'android'; + } + + return platform === 'ios'; } diff --git a/packages/webpack5/src/helpers/dependencies.ts b/packages/webpack5/src/helpers/dependencies.ts index 99828ec271..97f2528278 100644 --- a/packages/webpack5/src/helpers/dependencies.ts +++ b/packages/webpack5/src/helpers/dependencies.ts @@ -47,3 +47,23 @@ export function getDependencyPath(dependencyName: string): string | null { return null; } } + +/** + * Utility to get the version of a dependency. + * + * @param dependencyName + * @returns string | null - version of the dependency or null if not found + */ +export function getDependencyVersion(dependencyName: string): string | null { + const dependencyPath = getDependencyPath(dependencyName); + if (!dependencyPath) { + return null; + } + + try { + return require(`${dependencyPath}/package.json`).version; + } catch (err) { + // ignore + } + return null; +} From 77460ff452b625125c893bee9d8b62f8d5d0587b Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Mon, 15 Apr 2024 17:48:24 +0200 Subject: [PATCH 2/3] chore: use more permissive semver range --- 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 ccc7e2c4b6..51fb8aa394 100644 --- a/packages/webpack5/package.json +++ b/packages/webpack5/package.json @@ -41,7 +41,7 @@ "sass": "^1.0.0", "sass-loader": "^13.0.0", "sax": "^1.0.0", - "semver": "^7.6.0", + "semver": "^7.0.0 || ^6.0.0", "source-map": "^0.7.0", "terser-webpack-plugin": "^5.0.0", "ts-dedent": "^2.0.0", From 8aed5cb181db8e1155dc742421af3034b2e20bc0 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Mon, 15 Apr 2024 17:49:01 +0200 Subject: [PATCH 3/3] chore: cleanup --- packages/webpack5/src/configuration/angular.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webpack5/src/configuration/angular.ts b/packages/webpack5/src/configuration/angular.ts index 31c2a845c4..943e63b8f1 100644 --- a/packages/webpack5/src/configuration/angular.ts +++ b/packages/webpack5/src/configuration/angular.ts @@ -1,5 +1,6 @@ import { extname, resolve } from 'path'; import Config from 'webpack-chain'; +import { satisfies } from 'semver'; import { existsSync } from 'fs'; import { getTypescript, readTsConfig } from '../helpers/typescript'; @@ -13,7 +14,6 @@ import { getPlatformName, } from '../helpers/platform'; import base from './base'; -import { satisfies } from 'semver'; // until we can switch to async/await on the webpack config, copy this from '@angular/compiler-cli' const GLOBAL_DEFS_FOR_TERSER = { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy