Skip to content

Commit

Permalink
Merge pull request #11352 from keymanapp/fix/developer/11351-kps-hand…
Browse files Browse the repository at this point in the history
…le-missing-name-element-in-file

fix(developer): handle missing Name element for File element in package compiler
  • Loading branch information
mcdurdin authored May 3, 2024
2 parents 28144af + 78902e3 commit f0695bf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
10 changes: 10 additions & 0 deletions developer/src/kmc-package/src/compiler/kmp-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ export class KmpCompiler implements KeymanCompiler {
// note: we don't emit fileType as that is not permitted in kmp.json
};
});
if(!kmp.files.reduce((result: boolean, file) => {
if(!file.name) {
// as the filename field is missing or blank, we'll try with the description instead
this.callbacks.reportMessage(CompilerMessages.Error_FileRecordIsMissingName({description: file.description ?? '(no description)'}));
return false;
}
return result;
}, true)) {
return null;
}
}
kmp.files = kmp.files ?? [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,9 @@ export class CompilerMessages {
static ERROR_InvalidPackageFile = SevError | 0x001E;
static Error_InvalidPackageFile = (o:{e:any}) => m(this.ERROR_InvalidPackageFile,
`Package source file is invalid: ${(o.e ?? 'unknown error').toString()}`);

static ERROR_FileRecordIsMissingName = SevError | 0x001F;
static Error_FileRecordIsMissingName = (o:{description:string}) => m(this.ERROR_FileRecordIsMissingName,
`File record in the package with description '${o.description}' is missing a filename.`);
}

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class PackageKeyboardTargetValidator {
// package also includes the .js
const targets = KeymanTargets.keymanTargetsFromString(targetsText, {expandTargets: true});
if(targets.some(target => KeymanTargets.TouchKeymanTargets.includes(target))) {
if(!kmp.files.find(file => this.callbacks.path.basename(file.name, '.js') == keyboard.id)) {
if(!kmp.files.find(file => this.callbacks.path.basename(file.name ?? '', '.js') == keyboard.id)) {
// .js version of the keyboard is not found, warn
this.callbacks.reportMessage(CompilerMessages.Warn_JsKeyboardFileIsMissing({id: keyboard.id}));
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,21 @@ export class PackageMetadataCollector {
): KeyboardMetadata {

let isJavascript = false;
let file = kmp.files.find(file => this.callbacks.path.basename(file.name, KeymanFileTypes.Binary.Keyboard) == keyboard.id);
let file = kmp.files.find(file => this.callbacks.path.basename(file.name ?? '', KeymanFileTypes.Binary.Keyboard) == keyboard.id);
if(!file) {
isJavascript = true;
file = kmp.files.find(file => this.callbacks.path.basename(file.name, KeymanFileTypes.Binary.WebKeyboard) == keyboard.id);
file = kmp.files.find(file => this.callbacks.path.basename(file.name ?? '', KeymanFileTypes.Binary.WebKeyboard) == keyboard.id);
if(!file) {
this.callbacks.reportMessage(CompilerMessages.Error_KeyboardContentFileNotFound({id:keyboard.id}));
return null;
}
}

if(!file.name) {
this.callbacks.reportMessage(CompilerMessages.Error_FileRecordIsMissingName({description: file.description ?? '(no description)'}));
return null;
}

const filename = this.callbacks.resolveFilename(kpsFilename, file.name);
if(!this.callbacks.fs.existsSync(filename)) {
this.callbacks.reportMessage(CompilerMessages.Error_KeyboardFileNotFound({filename}));
Expand Down

0 comments on commit f0695bf

Please sign in to comment.