Skip to content

fix: properly handle missing App_Resources #5536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/project-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,11 @@ export class ProjectData implements IProjectData {
return this.nsConfig[constants.CONFIG_NS_APP_RESOURCES_ENTRY];
}

return path.join(
this.getAppDirectoryRelativePath(),
constants.APP_RESOURCES_FOLDER_NAME
);
return constants.APP_RESOURCES_FOLDER_NAME;
// return path.join(
// this.getAppDirectoryRelativePath(),
// constants.APP_RESOURCES_FOLDER_NAME
// );
}

public getAppDirectoryPath(projectDir?: string): string {
Expand Down
47 changes: 26 additions & 21 deletions lib/services/project-config-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default {
this.$logger.trace(
"Project Config Service using legacy configuration..."
);
if (!this.forceUsingLegacyConfig) {
if (!this.forceUsingLegacyConfig && info.hasNSConfig) {
this.warnUsingLegacyNSConfig();
}
return this.fallbackToLegacyNSConfig(info);
Expand Down Expand Up @@ -329,31 +329,36 @@ export default {
// ignore if the file doesn't exist
}

const packageJson = this.$fs.readJson(
path.join(this.projectHelper.projectDir, "package.json")
);
try {
const packageJson = this.$fs.readJson(
path.join(this.projectHelper.projectDir, "package.json")
);

// add app id to additionalData for backwards compatibility
if (
!NSConfig.id &&
packageJson &&
packageJson.nativescript &&
packageJson.nativescript.id
) {
const ids = packageJson.nativescript.id;
if (typeof ids === "string") {
additionalData.push({
id: packageJson.nativescript.id,
});
} else if (typeof ids === "object") {
for (const platform of Object.keys(ids)) {
// add app id to additionalData for backwards compatibility
if (
!NSConfig.id &&
packageJson &&
packageJson.nativescript &&
packageJson.nativescript.id
) {
const ids = packageJson.nativescript.id;
if (typeof ids === "string") {
additionalData.push({
[platform]: {
id: packageJson.nativescript.id[platform],
},
id: packageJson.nativescript.id,
});
} else if (typeof ids === "object") {
for (const platform of Object.keys(ids)) {
additionalData.push({
[platform]: {
id: packageJson.nativescript.id[platform],
},
});
}
}
}
} catch (err) {
this.$logger.trace("failed to read package.json data for config", err);
// ignore if the file doesn't exist
}

return _.defaultsDeep({}, ...additionalData, NSConfig);
Expand Down
8 changes: 7 additions & 1 deletion lib/services/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ export class ProjectService implements IProjectService {
try {
await this.$childProcess.exec(`git init ${projectDir}`);
await this.$childProcess.exec(`git -C ${projectDir} add --all`);
await this.$childProcess.exec(`git -C ${projectDir} commit --no-verify -m "init"`);
await this.$childProcess.exec(
`git -C ${projectDir} commit --no-verify -m "init"`
);
} catch (err) {
this.$logger.trace(
"Unable to initialize git repository. Error is: ",
Expand Down Expand Up @@ -218,6 +220,9 @@ export class ProjectService implements IProjectService {
);

if (!this.$fs.exists(appResourcesDestinationPath)) {
this.$logger.trace(
"Project does not have App_Resources - fetching from default template."
);
this.$fs.createDirectory(appResourcesDestinationPath);
const tempDir = await this.$tempService.mkdirSync("ns-default-template");
// the template installed doesn't have App_Resources -> get from a default template
Expand Down Expand Up @@ -265,4 +270,5 @@ export class ProjectService implements IProjectService {
};
}
}

injector.register("projectService", ProjectService);