Skip to content

Commit 0a112f3

Browse files
authored
fix: properly handle missing App_Resources (#5536)
1 parent 6ba5cd6 commit 0a112f3

File tree

3 files changed

+38
-26
lines changed

3 files changed

+38
-26
lines changed

lib/project-data.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,11 @@ export class ProjectData implements IProjectData {
257257
return this.nsConfig[constants.CONFIG_NS_APP_RESOURCES_ENTRY];
258258
}
259259

260-
return path.join(
261-
this.getAppDirectoryRelativePath(),
262-
constants.APP_RESOURCES_FOLDER_NAME
263-
);
260+
return constants.APP_RESOURCES_FOLDER_NAME;
261+
// return path.join(
262+
// this.getAppDirectoryRelativePath(),
263+
// constants.APP_RESOURCES_FOLDER_NAME
264+
// );
264265
}
265266

266267
public getAppDirectoryPath(projectDir?: string): string {

lib/services/project-config-service.ts

+26-21
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export default {
140140
this.$logger.trace(
141141
"Project Config Service using legacy configuration..."
142142
);
143-
if (!this.forceUsingLegacyConfig) {
143+
if (!this.forceUsingLegacyConfig && info.hasNSConfig) {
144144
this.warnUsingLegacyNSConfig();
145145
}
146146
return this.fallbackToLegacyNSConfig(info);
@@ -329,31 +329,36 @@ export default {
329329
// ignore if the file doesn't exist
330330
}
331331

332-
const packageJson = this.$fs.readJson(
333-
path.join(this.projectHelper.projectDir, "package.json")
334-
);
332+
try {
333+
const packageJson = this.$fs.readJson(
334+
path.join(this.projectHelper.projectDir, "package.json")
335+
);
335336

336-
// add app id to additionalData for backwards compatibility
337-
if (
338-
!NSConfig.id &&
339-
packageJson &&
340-
packageJson.nativescript &&
341-
packageJson.nativescript.id
342-
) {
343-
const ids = packageJson.nativescript.id;
344-
if (typeof ids === "string") {
345-
additionalData.push({
346-
id: packageJson.nativescript.id,
347-
});
348-
} else if (typeof ids === "object") {
349-
for (const platform of Object.keys(ids)) {
337+
// add app id to additionalData for backwards compatibility
338+
if (
339+
!NSConfig.id &&
340+
packageJson &&
341+
packageJson.nativescript &&
342+
packageJson.nativescript.id
343+
) {
344+
const ids = packageJson.nativescript.id;
345+
if (typeof ids === "string") {
350346
additionalData.push({
351-
[platform]: {
352-
id: packageJson.nativescript.id[platform],
353-
},
347+
id: packageJson.nativescript.id,
354348
});
349+
} else if (typeof ids === "object") {
350+
for (const platform of Object.keys(ids)) {
351+
additionalData.push({
352+
[platform]: {
353+
id: packageJson.nativescript.id[platform],
354+
},
355+
});
356+
}
355357
}
356358
}
359+
} catch (err) {
360+
this.$logger.trace("failed to read package.json data for config", err);
361+
// ignore if the file doesn't exist
357362
}
358363

359364
return _.defaultsDeep({}, ...additionalData, NSConfig);

lib/services/project-service.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ export class ProjectService implements IProjectService {
108108
try {
109109
await this.$childProcess.exec(`git init ${projectDir}`);
110110
await this.$childProcess.exec(`git -C ${projectDir} add --all`);
111-
await this.$childProcess.exec(`git -C ${projectDir} commit --no-verify -m "init"`);
111+
await this.$childProcess.exec(
112+
`git -C ${projectDir} commit --no-verify -m "init"`
113+
);
112114
} catch (err) {
113115
this.$logger.trace(
114116
"Unable to initialize git repository. Error is: ",
@@ -218,6 +220,9 @@ export class ProjectService implements IProjectService {
218220
);
219221

220222
if (!this.$fs.exists(appResourcesDestinationPath)) {
223+
this.$logger.trace(
224+
"Project does not have App_Resources - fetching from default template."
225+
);
221226
this.$fs.createDirectory(appResourcesDestinationPath);
222227
const tempDir = await this.$tempService.mkdirSync("ns-default-template");
223228
// the template installed doesn't have App_Resources -> get from a default template
@@ -265,4 +270,5 @@ export class ProjectService implements IProjectService {
265270
};
266271
}
267272
}
273+
268274
injector.register("projectService", ProjectService);

0 commit comments

Comments
 (0)