Skip to content

Commit 299c1f5

Browse files
committed
fix: update runtime package.json when config changes
1 parent 21839ff commit 299c1f5

File tree

3 files changed

+48
-32
lines changed

3 files changed

+48
-32
lines changed

lib/controllers/platform-controller.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class PlatformController implements IPlatformController {
106106
`Invalid frameworkPath: ${frameworkPath}. Please ensure the specified frameworkPath exists.`
107107
);
108108
}
109-
result = path.resolve(frameworkPath);
109+
result = "file:" + path.resolve(frameworkPath);
110110
} else {
111111
if (!version) {
112112
version = projectData.devDependencies

lib/controllers/prepare-controller.ts

+39-27
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
import * as choki from "chokidar";
22
import { hook } from "../common/helpers";
3-
import { performanceLog, cache } from "../common/decorators";
3+
import { cache, performanceLog } from "../common/decorators";
44
import { EventEmitter } from "events";
55
import * as path from "path";
66
import {
7-
PREPARE_READY_EVENT_NAME,
8-
WEBPACK_COMPILATION_COMPLETE,
9-
PACKAGE_JSON_FILE_NAME,
10-
PLATFORMS_DIR_NAME,
11-
TrackActionNames,
127
AnalyticsEventLabelDelimiter,
138
CONFIG_FILE_NAME_JS,
149
CONFIG_FILE_NAME_TS,
10+
PACKAGE_JSON_FILE_NAME,
11+
PLATFORMS_DIR_NAME,
12+
PREPARE_READY_EVENT_NAME,
1513
SupportedPlatform,
14+
TrackActionNames,
15+
WEBPACK_COMPILATION_COMPLETE,
1616
} from "../constants";
1717
import {
18-
IProjectDataService,
19-
IProjectData,
2018
IProjectConfigService,
19+
IProjectData,
20+
IProjectDataService,
2121
} from "../definitions/project";
2222
import {
23-
IPlatformController,
2423
INodeModulesDependenciesBuilder,
25-
IPlatformsDataService,
24+
IPlatformController,
2625
IPlatformData,
26+
IPlatformsDataService,
2727
} from "../definitions/platform";
2828
import { IPluginsService } from "../definitions/plugins";
2929
import { IWatchIgnoreListService } from "../declarations";
3030
import {
31-
IDictionary,
32-
IHooksService,
3331
IAnalyticsService,
32+
IDictionary,
3433
IFileSystem,
34+
IHooksService,
3535
} from "../common/declarations";
3636
import { injector } from "../common/yok";
37+
import * as _ from "lodash";
3738
// import { project } from "nativescript-dev-xcode";
3839
// import { platform } from "os";
3940
interface IPlatformWatcherData {
@@ -76,14 +77,6 @@ export class PrepareController extends EventEmitter {
7677
await this.$markingModeService.handleMarkingModeFullDeprecation({
7778
projectDir: projectData.projectDir,
7879
});
79-
80-
this.$projectConfigService.writeLegacyNSConfigIfNeeded(
81-
projectData.projectDir,
82-
this.$projectDataService.getRuntimePackage(
83-
projectData.projectDir,
84-
prepareData.platform as SupportedPlatform
85-
)
86-
);
8780
}
8881

8982
await this.trackRuntimeVersion(prepareData.platform, projectData);
@@ -138,6 +131,17 @@ export class PrepareController extends EventEmitter {
138131
await this.$platformController.addPlatformIfNeeded(prepareData);
139132

140133
this.$logger.info("Preparing project...");
134+
135+
if (this.$mobileHelper.isAndroidPlatform(prepareData.platform)) {
136+
this.$projectConfigService.writeLegacyNSConfigIfNeeded(
137+
projectData.projectDir,
138+
this.$projectDataService.getRuntimePackage(
139+
projectData.projectDir,
140+
prepareData.platform as SupportedPlatform
141+
)
142+
);
143+
}
144+
141145
let result = null;
142146

143147
const platformData = this.$platformsDataService.getPlatformData(
@@ -335,6 +339,7 @@ export class PrepareController extends EventEmitter {
335339
this.$watchIgnoreListService.removeFileFromIgnoreList(filePath);
336340
} else {
337341
this.$logger.info(`Chokidar raised event ${event} for ${filePath}.`);
342+
await this.writeRuntimePackageJson(projectData, platformData);
338343
this.emitPrepareEvent({
339344
files: [],
340345
hasOnlyHotUpdateFiles: false,
@@ -391,21 +396,27 @@ export class PrepareController extends EventEmitter {
391396
projectData: IProjectData,
392397
platformData: IPlatformData
393398
) {
399+
this.$logger.info(
400+
"Updating runtime package.json with configuration values..."
401+
);
394402
const nsConfig = this.$projectConfigService.readConfig(
395403
projectData.projectDir
396404
);
397-
const packageData = {
398-
...projectData.packageJsonData,
399-
...nsConfig,
405+
const packageData: any = {
400406
main: "bundle",
407+
..._.pick(projectData.packageJsonData, ["name"]),
408+
...nsConfig,
401409
};
402-
delete packageData.dependencies;
403-
delete packageData.devDependencies;
404-
if (packageData.ios && packageData.ios.discardUncaughtJsExceptions) {
410+
if (
411+
platformData.platformNameLowerCase === "ios" &&
412+
packageData.ios &&
413+
packageData.ios.discardUncaughtJsExceptions
414+
) {
405415
packageData.discardUncaughtJsExceptions =
406416
packageData.ios.discardUncaughtJsExceptions;
407417
}
408418
if (
419+
platformData.platformNameLowerCase === "android" &&
409420
packageData.android &&
410421
packageData.android.discardUncaughtJsExceptions
411422
) {
@@ -431,7 +442,7 @@ export class PrepareController extends EventEmitter {
431442
"package.json"
432443
);
433444
}
434-
this.$logger.info("packagePath:", packagePath);
445+
435446
this.$fs.writeJson(packagePath, packageData);
436447
}
437448

@@ -466,4 +477,5 @@ export class PrepareController extends EventEmitter {
466477
});
467478
}
468479
}
480+
469481
injector.register("prepareController", PrepareController);

lib/services/project-config-service.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,17 @@ export default {
138138
) {
139139
return;
140140
}
141-
this.$logger.warn();
142-
this.$logger.printMarkdown(`
143-
Using __${runtimePackage.name}${
141+
142+
const runtimePackageDisplay = `${runtimePackage.name}${
144143
runtimePackage.version ? "@" + runtimePackage.version : ""
145-
}__ which requires \`nsconfig.json\` to be present.
144+
}`;
145+
146+
this.$logger.info();
147+
this.$logger.printMarkdown(`
148+
Using __${runtimePackageDisplay}__ which requires \`nsconfig.json\` to be present.
146149
Writing \`nsconfig.json\` based on the values set in \`${CONFIG_FILE_NAME_DISPLAY}\`.
147150
You may add \`nsconfig.json\` to \`.gitignore\` as the CLI will regenerate it as necessary.`);
151+
148152
const nsConfigPath = path.join(
149153
projectDir || this.projectHelper.projectDir,
150154
"nsconfig.json"

0 commit comments

Comments
 (0)