mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 18:12:09 +08:00
fix: detect core version before including inspector_modules on android (#10520)
This commit is contained in:
@ -435,9 +435,6 @@ exports[`angular configuration for android 1`] = `
|
|||||||
'__jest__/src/app.js',
|
'__jest__/src/app.js',
|
||||||
'@nativescript/core/ui/frame',
|
'@nativescript/core/ui/frame',
|
||||||
'@nativescript/core/ui/frame/activity'
|
'@nativescript/core/ui/frame/activity'
|
||||||
],
|
|
||||||
'tns_modules/inspector_modules': [
|
|
||||||
'@nativescript/core/inspector_modules'
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
|
@ -323,9 +323,6 @@ exports[`base configuration for android 1`] = `
|
|||||||
'__jest__/src/app.js',
|
'__jest__/src/app.js',
|
||||||
'@nativescript/core/ui/frame',
|
'@nativescript/core/ui/frame',
|
||||||
'@nativescript/core/ui/frame/activity'
|
'@nativescript/core/ui/frame/activity'
|
||||||
],
|
|
||||||
'tns_modules/inspector_modules': [
|
|
||||||
'@nativescript/core/inspector_modules'
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
|
@ -322,9 +322,6 @@ exports[`javascript configuration for android 1`] = `
|
|||||||
'__jest__/src/app.js',
|
'__jest__/src/app.js',
|
||||||
'@nativescript/core/ui/frame',
|
'@nativescript/core/ui/frame',
|
||||||
'@nativescript/core/ui/frame/activity'
|
'@nativescript/core/ui/frame/activity'
|
||||||
],
|
|
||||||
'tns_modules/inspector_modules': [
|
|
||||||
'@nativescript/core/inspector_modules'
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
|
@ -352,9 +352,6 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR
|
|||||||
'__jest__/src/app.js',
|
'__jest__/src/app.js',
|
||||||
'@nativescript/core/ui/frame',
|
'@nativescript/core/ui/frame',
|
||||||
'@nativescript/core/ui/frame/activity'
|
'@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',
|
'__jest__/src/app.js',
|
||||||
'@nativescript/core/ui/frame',
|
'@nativescript/core/ui/frame',
|
||||||
'@nativescript/core/ui/frame/activity'
|
'@nativescript/core/ui/frame/activity'
|
||||||
],
|
|
||||||
'tns_modules/inspector_modules': [
|
|
||||||
'@nativescript/core/inspector_modules'
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
|
@ -344,9 +344,6 @@ exports[`svelte configuration for android 1`] = `
|
|||||||
'__jest__/src/app.js',
|
'__jest__/src/app.js',
|
||||||
'@nativescript/core/ui/frame',
|
'@nativescript/core/ui/frame',
|
||||||
'@nativescript/core/ui/frame/activity'
|
'@nativescript/core/ui/frame/activity'
|
||||||
],
|
|
||||||
'tns_modules/inspector_modules': [
|
|
||||||
'@nativescript/core/inspector_modules'
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
|
@ -322,9 +322,6 @@ exports[`typescript configuration for android 1`] = `
|
|||||||
'__jest__/src/app.js',
|
'__jest__/src/app.js',
|
||||||
'@nativescript/core/ui/frame',
|
'@nativescript/core/ui/frame',
|
||||||
'@nativescript/core/ui/frame/activity'
|
'@nativescript/core/ui/frame/activity'
|
||||||
],
|
|
||||||
'tns_modules/inspector_modules': [
|
|
||||||
'@nativescript/core/inspector_modules'
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
|
@ -357,9 +357,6 @@ exports[`vue configuration for android 1`] = `
|
|||||||
'__jest__/src/app.js',
|
'__jest__/src/app.js',
|
||||||
'@nativescript/core/ui/frame',
|
'@nativescript/core/ui/frame',
|
||||||
'@nativescript/core/ui/frame/activity'
|
'@nativescript/core/ui/frame/activity'
|
||||||
],
|
|
||||||
'tns_modules/inspector_modules': [
|
|
||||||
'@nativescript/core/inspector_modules'
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
|
@ -4,6 +4,7 @@ import fs from 'fs';
|
|||||||
import base from '../../src/configuration/base';
|
import base from '../../src/configuration/base';
|
||||||
import { init } from '../../src';
|
import { init } from '../../src';
|
||||||
import { applyFileReplacements } from '../../src/helpers/fileReplacements';
|
import { applyFileReplacements } from '../../src/helpers/fileReplacements';
|
||||||
|
import * as dependenciesHelpers from '../../src/helpers/dependencies';
|
||||||
import { additionalCopyRules } from '../../src/helpers/copyRules';
|
import { additionalCopyRules } from '../../src/helpers/copyRules';
|
||||||
|
|
||||||
describe('base configuration', () => {
|
describe('base configuration', () => {
|
||||||
@ -221,4 +222,30 @@ describe('base configuration', () => {
|
|||||||
expect(config.output.get('sourceMapFilename')).toMatchSnapshot();
|
expect(config.output.get('sourceMapFilename')).toMatchSnapshot();
|
||||||
expect(config.get('devtool')).toBe('hidden-source-map');
|
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);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
"sass": "^1.0.0",
|
"sass": "^1.0.0",
|
||||||
"sass-loader": "^13.0.0",
|
"sass-loader": "^13.0.0",
|
||||||
"sax": "^1.0.0",
|
"sax": "^1.0.0",
|
||||||
|
"semver": "^7.0.0 || ^6.0.0",
|
||||||
"source-map": "^0.7.0",
|
"source-map": "^0.7.0",
|
||||||
"terser-webpack-plugin": "^5.0.0",
|
"terser-webpack-plugin": "^5.0.0",
|
||||||
"ts-dedent": "^2.0.0",
|
"ts-dedent": "^2.0.0",
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import { extname, resolve } from 'path';
|
import { extname, resolve } from 'path';
|
||||||
import Config from 'webpack-chain';
|
import Config from 'webpack-chain';
|
||||||
|
import { satisfies } from 'semver';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
|
|
||||||
import { getTypescript, readTsConfig } from '../helpers/typescript';
|
import { getTypescript, readTsConfig } from '../helpers/typescript';
|
||||||
import { getDependencyPath } from '../helpers/dependencies';
|
import { getDependencyVersion } from '../helpers/dependencies';
|
||||||
import { getProjectTSConfigPath } from '../helpers/project';
|
import { getProjectTSConfigPath } from '../helpers/project';
|
||||||
import { env as _env, IWebpackEnv } from '../index';
|
import { env as _env, IWebpackEnv } from '../index';
|
||||||
import { warnOnce } from '../helpers/log';
|
import { warnOnce } from '../helpers/log';
|
||||||
@ -187,13 +188,16 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
|||||||
.loader('angular-hot-loader');
|
.loader('angular-hot-loader');
|
||||||
});
|
});
|
||||||
|
|
||||||
const buildAngularMajorVersion = getBuildAngularMajorVersion();
|
const buildAngularVersion = getDependencyVersion(
|
||||||
if (buildAngularMajorVersion) {
|
'@angular-devkit/build-angular'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (buildAngularVersion) {
|
||||||
const buildAngularOptions: any = {
|
const buildAngularOptions: any = {
|
||||||
aot: !disableAOT,
|
aot: !disableAOT,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (buildAngularMajorVersion < 15) {
|
if (satisfies(buildAngularVersion, '<15.0.0')) {
|
||||||
const tsConfig = readTsConfig(tsConfigPath);
|
const tsConfig = readTsConfig(tsConfigPath);
|
||||||
const { ScriptTarget } = getTypescript();
|
const { ScriptTarget } = getTypescript();
|
||||||
buildAngularOptions.scriptTarget =
|
buildAngularOptions.scriptTarget =
|
||||||
@ -315,27 +319,6 @@ function getAngularWebpackPlugin(): any {
|
|||||||
return AngularWebpackPlugin;
|
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) {
|
function tryRequireResolve(path: string) {
|
||||||
try {
|
try {
|
||||||
return require.resolve(path);
|
return require.resolve(path);
|
||||||
@ -348,10 +331,10 @@ function getWebpackLoaderPath() {
|
|||||||
return (
|
return (
|
||||||
tryRequireResolve(
|
tryRequireResolve(
|
||||||
'@angular-devkit/build-angular/src/babel/webpack-loader'
|
'@angular-devkit/build-angular/src/babel/webpack-loader'
|
||||||
) ||
|
) ??
|
||||||
tryRequireResolve(
|
tryRequireResolve(
|
||||||
'@angular-devkit/build-angular/src/tools/babel/webpack-loader'
|
'@angular-devkit/build-angular/src/tools/babel/webpack-loader'
|
||||||
) ||
|
) ??
|
||||||
// fallback to angular 16.1+
|
// fallback to angular 16.1+
|
||||||
'@angular-devkit/build-angular/src/tools/babel/webpack-loader'
|
'@angular-devkit/build-angular/src/tools/babel/webpack-loader'
|
||||||
);
|
);
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
HotModuleReplacementPlugin,
|
HotModuleReplacementPlugin,
|
||||||
} from 'webpack';
|
} from 'webpack';
|
||||||
import Config from 'webpack-chain';
|
import Config from 'webpack-chain';
|
||||||
|
import { satisfies } from 'semver';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
|
|
||||||
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
|
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 TerserPlugin from 'terser-webpack-plugin';
|
||||||
|
|
||||||
import { getProjectFilePath, getProjectTSConfigPath } from '../helpers/project';
|
import { getProjectFilePath, getProjectTSConfigPath } from '../helpers/project';
|
||||||
|
import { getDependencyVersion, hasDependency } from '../helpers/dependencies';
|
||||||
import { PlatformSuffixPlugin } from '../plugins/PlatformSuffixPlugin';
|
import { PlatformSuffixPlugin } from '../plugins/PlatformSuffixPlugin';
|
||||||
import { applyFileReplacements } from '../helpers/fileReplacements';
|
import { applyFileReplacements } from '../helpers/fileReplacements';
|
||||||
import { addCopyRule, applyCopyRules } from '../helpers/copyRules';
|
import { addCopyRule, applyCopyRules } from '../helpers/copyRules';
|
||||||
import { WatchStatePlugin } from '../plugins/WatchStatePlugin';
|
import { WatchStatePlugin } from '../plugins/WatchStatePlugin';
|
||||||
import { hasDependency } from '../helpers/dependencies';
|
|
||||||
import { applyDotEnvPlugin } from '../helpers/dotEnv';
|
import { applyDotEnvPlugin } from '../helpers/dotEnv';
|
||||||
import { env as _env, IWebpackEnv } from '../index';
|
import { env as _env, IWebpackEnv } from '../index';
|
||||||
import { getValue } from '../helpers/config';
|
import { getValue } from '../helpers/config';
|
||||||
@ -86,7 +87,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
|||||||
const sourceMapAbsolutePath = getProjectFilePath(
|
const sourceMapAbsolutePath = getProjectFilePath(
|
||||||
`./${
|
`./${
|
||||||
env.buildPath ?? 'platforms'
|
env.buildPath ?? 'platforms'
|
||||||
}/${platform}-sourceMaps/[file].map[query]`,
|
}/${platform}-sourceMaps/[file].map[query]`
|
||||||
);
|
);
|
||||||
const sourceMapRelativePath = relative(outputPath, sourceMapAbsolutePath);
|
const sourceMapRelativePath = relative(outputPath, sourceMapAbsolutePath);
|
||||||
config.output.sourceMapFilename(sourceMapRelativePath);
|
config.output.sourceMapFilename(sourceMapRelativePath);
|
||||||
@ -272,7 +273,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
|||||||
const configFile = tsConfigPath
|
const configFile = tsConfigPath
|
||||||
? {
|
? {
|
||||||
configFile: tsConfigPath,
|
configFile: tsConfigPath,
|
||||||
}
|
}
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
// set up ts support
|
// set up ts support
|
||||||
@ -451,7 +452,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
|||||||
* +-----------------------------------------------------------------------------------------+
|
* +-----------------------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
/System.import\(\) is deprecated/,
|
/System.import\(\) is deprecated/,
|
||||||
]),
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
// todo: refine defaults
|
// todo: refine defaults
|
||||||
@ -516,7 +517,11 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
|
|||||||
|
|
||||||
function shouldIncludeInspectorModules(): boolean {
|
function shouldIncludeInspectorModules(): boolean {
|
||||||
const platform = getPlatformName();
|
const platform = getPlatformName();
|
||||||
// todo: check if core modules are external
|
const coreVersion = getDependencyVersion('@nativescript/core');
|
||||||
// todo: check if we are testing
|
|
||||||
return platform === 'ios' || platform === 'android';
|
if (coreVersion && satisfies(coreVersion, '>=8.7.0')) {
|
||||||
|
return platform === 'ios' || platform === 'android';
|
||||||
|
}
|
||||||
|
|
||||||
|
return platform === 'ios';
|
||||||
}
|
}
|
||||||
|
@ -47,3 +47,23 @@ export function getDependencyPath(dependencyName: string): string | null {
|
|||||||
return 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;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user