diff --git a/developer/src/kmc-package/src/compiler/kmp-compiler.ts b/developer/src/kmc-package/src/compiler/kmp-compiler.ts index 420477d474e..c9ee1fa492b 100644 --- a/developer/src/kmc-package/src/compiler/kmp-compiler.ts +++ b/developer/src/kmc-package/src/compiler/kmp-compiler.ts @@ -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 ?? []; diff --git a/developer/src/kmc-package/src/compiler/package-compiler-messages.ts b/developer/src/kmc-package/src/compiler/package-compiler-messages.ts index 7e0ab61865d..1b286686ed9 100644 --- a/developer/src/kmc-package/src/compiler/package-compiler-messages.ts +++ b/developer/src/kmc-package/src/compiler/package-compiler-messages.ts @@ -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.`); } diff --git a/developer/src/kmc-package/src/compiler/package-keyboard-target-validator.ts b/developer/src/kmc-package/src/compiler/package-keyboard-target-validator.ts index 8927e557f4e..01d2d3ca011 100644 --- a/developer/src/kmc-package/src/compiler/package-keyboard-target-validator.ts +++ b/developer/src/kmc-package/src/compiler/package-keyboard-target-validator.ts @@ -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; diff --git a/developer/src/kmc-package/src/compiler/package-metadata-collector.ts b/developer/src/kmc-package/src/compiler/package-metadata-collector.ts index 7fb0952de09..346e23a7278 100644 --- a/developer/src/kmc-package/src/compiler/package-metadata-collector.ts +++ b/developer/src/kmc-package/src/compiler/package-metadata-collector.ts @@ -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}));