Skip to content

Commit c75796a

Browse files
FatmeFatme
Fatme
authored and
Fatme
committed
Merge pull request #992 from NativeScript/fatme/missing-modules-after-upgrade
Do not crash application after upgrade to 1.3.0
2 parents 9e96b91 + 2ffdcdd commit c75796a

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

lib/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export let APP_RESOURCES_FOLDER_NAME = "App_Resources";
66
export let PROJECT_FRAMEWORK_FOLDER_NAME = "framework";
77
export let NATIVESCRIPT_KEY_NAME = "nativescript";
88
export let NODE_MODULES_FOLDER_NAME = "node_modules";
9+
export let TNS_MODULES_FOLDER_NAME = "tns_modules";
910
export let TNS_CORE_MODULES_NAME = "tns-core-modules";
1011
export let PACKAGE_JSON_FILE_NAME = "package.json";
1112
export let NODE_MODULE_CACHE_PATH_KEY_NAME = "node-modules-cache-path";

lib/definitions/project.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface IProjectData {
99
platformsDir: string;
1010
projectFilePath: string;
1111
projectId?: string;
12+
dependencies: any;
1213
}
1314

1415
interface IProjectDataService {

lib/project-data.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class ProjectData implements IProjectData {
1212
public projectFilePath: string;
1313
public projectId: string;
1414
public projectName: string;
15+
public dependencies: any;
1516

1617
constructor(private $fs: IFileSystem,
1718
private $errors: IErrors,
@@ -31,8 +32,9 @@ export class ProjectData implements IProjectData {
3132
let data: any = null;
3233

3334
if (this.$fs.exists(this.projectFilePath).wait()) {
35+
let fileContent: any = null;
3436
try {
35-
let fileContent = this.$fs.readJson(this.projectFilePath).wait();
37+
fileContent = this.$fs.readJson(this.projectFilePath).wait();
3638
data = fileContent[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE];
3739
} catch (err) {
3840
this.$errors.fail({formatStr: "The project file %s is corrupted." + os.EOL +
@@ -44,6 +46,7 @@ export class ProjectData implements IProjectData {
4446

4547
if(data) {
4648
this.projectId = data.id;
49+
this.dependencies = fileContent.dependencies;
4750
} else { // This is the case when we have package.json file but nativescipt key is not presented in it
4851
this.tryToUpgradeProject().wait();
4952
}

lib/services/platform-service.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,22 @@ export class PlatformService implements IPlatformService {
157157
let contents = this.$fs.readDirectory(appDestinationDirectoryPath).wait();
158158

159159
_(contents)
160-
.filter(directoryName => directoryName !== "tns_modules")
160+
.filter(directoryName => directoryName !== constants.TNS_MODULES_FOLDER_NAME)
161161
.each(directoryName => this.$fs.deleteDirectory(path.join(appDestinationDirectoryPath, directoryName)).wait())
162162
.value();
163163

164164
// Copy all files from app dir, but make sure to exclude tns_modules
165165
let sourceFiles = this.$fs.readDirectory(appSourceDirectoryPath).wait();
166-
if(_.contains(sourceFiles, "tns_modules")) {
167-
this.$logger.warn("You have tns_modules dir in your app folder. It will not be used and you can safely remove it.");
166+
let hasTnsModulesInAppFolder = _.contains(sourceFiles, constants.TNS_MODULES_FOLDER_NAME);
167+
if(hasTnsModulesInAppFolder && this.$projectData.dependencies && this.$projectData.dependencies[constants.TNS_CORE_MODULES_NAME]) {
168+
this.$logger.warn("You have tns_modules dir in your app folder and tns-core-modules in your package.json file. Tns_modules dir in your app folder will not be used and you can safely remove it.");
169+
sourceFiles.filter(source => source !== constants.TNS_MODULES_FOLDER_NAME)
170+
.map(source => path.join(appSourceDirectoryPath, source))
171+
.forEach(source => shell.cp("-Rf", source, appDestinationDirectoryPath));
172+
} else {
173+
shell.cp("-Rf", path.join(appSourceDirectoryPath, "*"), appDestinationDirectoryPath);
168174
}
169175

170-
sourceFiles.filter(source => source !== "tns_modules")
171-
.map(source => path.join(appSourceDirectoryPath, source))
172-
.forEach(source => shell.cp("-Rf", source, appDestinationDirectoryPath));
173-
174176
// Copy App_Resources to project root folder
175177
this.$fs.ensureDirectoryExists(platformData.platformProjectService.getAppResourcesDestinationDirectoryPath().wait()).wait(); // Should be deleted
176178
let appResourcesDirectoryPath = path.join(appDestinationDirectoryPath, constants.APP_RESOURCES_FOLDER_NAME);

test/stubs.ts

+1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ export class ProjectDataStub implements IProjectData {
236236
}
237237
projectFilePath: string;
238238
projectId: string;
239+
dependencies: any;
239240
}
240241

241242
export class PlatformsDataStub implements IPlatformsData {

0 commit comments

Comments
 (0)