Skip to content

Commit b5c3396

Browse files
committed
Merge branch 'main' of github.com:farfromrefug/nativescript-cli
2 parents 0b6884b + 6b25143 commit b5c3396

1 file changed

Lines changed: 57 additions & 11 deletions

File tree

lib/controllers/prepare-controller.ts

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import {
1717
CONFIG_FILE_NAME_TS,
1818
PACKAGE_JSON_FILE_NAME,
1919
PLATFORMS_DIR_NAME,
20+
PlatformTypes,
2021
PREPARE_READY_EVENT_NAME,
22+
SCOPED_ANDROID_RUNTIME_NAME,
23+
SCOPED_IOS_RUNTIME_NAME,
2124
SupportedPlatform,
2225
TrackActionNames,
2326
WEBPACK_COMPILATION_COMPLETE,
@@ -36,6 +39,7 @@ import {
3639
IProjectDataService,
3740
IProjectService,
3841
} from "../definitions/project";
42+
import { resolvePackageJSONPath } from "@rigor789/resolve-package-path";
3943

4044
interface IPlatformWatcherData {
4145
hasWebpackCompilerProcess: boolean;
@@ -449,30 +453,72 @@ export class PrepareController extends EventEmitter {
449453
this.$logger.info(
450454
"Updating runtime package.json with configuration values..."
451455
);
452-
const nsConfig = this.$projectConfigService.readConfig(
456+
457+
458+
const {hooks, ignoredNativeDependencies, webpackPackageName, webpackConfigPath, appResourcesPath, buildPath, appPath, ...nsConfig} = this.$projectConfigService.readConfig(
453459
projectData.projectDir
454460
);
461+
462+
const platform = platformData.platformNameLowerCase;
463+
let installedRuntimePackageJSON;
464+
let runtimePackageName: string;
465+
if (platform === PlatformTypes.ios) {
466+
runtimePackageName = projectData.nsConfig.ios?.runtimePackageName || SCOPED_IOS_RUNTIME_NAME;
467+
} else if (platform === PlatformTypes.android) {
468+
runtimePackageName = projectData.nsConfig.android?.runtimePackageName || SCOPED_ANDROID_RUNTIME_NAME;
469+
}
470+
// try reading from installed runtime first before reading from the npm registry...
471+
const installedRuntimePackageJSONPath = resolvePackageJSONPath(
472+
runtimePackageName,
473+
{
474+
paths: [projectData.projectDir],
475+
}
476+
);
477+
478+
if (installedRuntimePackageJSONPath) {
479+
installedRuntimePackageJSON = this.$fs.readJson(
480+
installedRuntimePackageJSONPath
481+
);
482+
}
455483
const packageData: any = {
456484
..._.pick(projectData.packageJsonData, ["name"]),
457485
...nsConfig,
458486
main: "bundle",
487+
...(installedRuntimePackageJSON? {}:{})
459488
};
460-
461489
if (
462-
platformData.platformNameLowerCase === "ios" &&
463-
packageData.ios &&
464-
packageData.ios.discardUncaughtJsExceptions
490+
platform === PlatformTypes.ios
465491
) {
466-
packageData.discardUncaughtJsExceptions =
492+
if (installedRuntimePackageJSON) {
493+
packageData.ios = packageData.ios || {};
494+
packageData.ios.runtime = {
495+
version: installedRuntimePackageJSON.version
496+
};
497+
}
498+
if (packageData.ios &&
499+
packageData.ios.discardUncaughtJsExceptions) {
500+
packageData.discardUncaughtJsExceptions =
467501
packageData.ios.discardUncaughtJsExceptions;
502+
}
503+
delete packageData.android;
468504
}
469505
if (
470-
platformData.platformNameLowerCase === "android" &&
471-
packageData.android &&
472-
packageData.android.discardUncaughtJsExceptions
506+
platform === PlatformTypes.android
473507
) {
474-
packageData.discardUncaughtJsExceptions =
475-
packageData.android.discardUncaughtJsExceptions;
508+
if (installedRuntimePackageJSON) {
509+
packageData.android = packageData.android || {};
510+
packageData.android.runtime = {
511+
version: installedRuntimePackageJSON.version,
512+
version_info: installedRuntimePackageJSON.version_info,
513+
gradle:installedRuntimePackageJSON.gradle
514+
};
515+
}
516+
if (packageData.android &&
517+
packageData.android.discardUncaughtJsExceptions) {
518+
packageData.discardUncaughtJsExceptions =
519+
packageData.android.discardUncaughtJsExceptions;
520+
}
521+
delete packageData.ios;
476522
}
477523
let packagePath: string;
478524
if (

0 commit comments

Comments
 (0)