From f4f03551096c384d2ea1be5cf591953f8ce56c64 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Mon, 2 Dec 2024 15:40:54 -0600 Subject: [PATCH] feat(developer): local imports directory fixes - use path.join instead of path.resolve - rename importsPath to cldrImportsPath - remove k_015_importlocal from core, as it duplicated tests in common and developer Fixes: #10649 --- .../unit/ldml/keyboards/k_015_importlocal.xml | 22 ------------------- .../keyboards/keys-Zyyy-morepunctuation.xml | 6 ----- core/tests/unit/ldml/keyboards/meson.build | 1 - .../ldml-keyboard/ldml-keyboard-xml-reader.ts | 6 ++--- .../test/helpers/reader-callback-test.ts | 8 +++---- developer/src/kmc-ldml/test/helpers/index.ts | 4 ++-- .../buildClasses/BuildLdmlKeyboard.ts | 6 ++--- .../kmc/src/commands/buildTestData/index.ts | 6 ++--- 8 files changed, 15 insertions(+), 44 deletions(-) delete mode 100644 core/tests/unit/ldml/keyboards/k_015_importlocal.xml delete mode 100644 core/tests/unit/ldml/keyboards/keys-Zyyy-morepunctuation.xml diff --git a/core/tests/unit/ldml/keyboards/k_015_importlocal.xml b/core/tests/unit/ldml/keyboards/k_015_importlocal.xml deleted file mode 100644 index 36bd5c6942f..00000000000 --- a/core/tests/unit/ldml/keyboards/k_015_importlocal.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/core/tests/unit/ldml/keyboards/keys-Zyyy-morepunctuation.xml b/core/tests/unit/ldml/keyboards/keys-Zyyy-morepunctuation.xml deleted file mode 100644 index 768e81e7cd2..00000000000 --- a/core/tests/unit/ldml/keyboards/keys-Zyyy-morepunctuation.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/core/tests/unit/ldml/keyboards/meson.build b/core/tests/unit/ldml/keyboards/meson.build index 949acb78996..15f458c587f 100644 --- a/core/tests/unit/ldml/keyboards/meson.build +++ b/core/tests/unit/ldml/keyboards/meson.build @@ -26,7 +26,6 @@ tests_without_testdata = [ 'k_010_mt', 'k_011_mt_iso', 'k_012_other', - 'k_015_importlocal', 'k_030_transform_plus', 'k_100_keytest', 'k_101_keytest', diff --git a/developer/src/common/web/utils/src/types/ldml-keyboard/ldml-keyboard-xml-reader.ts b/developer/src/common/web/utils/src/types/ldml-keyboard/ldml-keyboard-xml-reader.ts index 2a5754b45b2..928bb94bef7 100644 --- a/developer/src/common/web/utils/src/types/ldml-keyboard/ldml-keyboard-xml-reader.ts +++ b/developer/src/common/web/utils/src/types/ldml-keyboard/ldml-keyboard-xml-reader.ts @@ -20,7 +20,7 @@ interface NameAndProps { export class LDMLKeyboardXMLSourceFileReaderOptions { /** path to the CLDR imports */ - importsPath: string; + cldrImportsPath: string; /** ordered list of paths for local imports */ localImportsPaths: string[]; }; @@ -34,14 +34,14 @@ export class LDMLKeyboardXMLSourceFileReader { } readImportFile(version: string, subpath: string): Uint8Array { - const importPath = this.callbacks.resolveFilename(this.options.importsPath, `${version}/${subpath}`); + const importPath = this.callbacks.resolveFilename(this.options.cldrImportsPath, `${version}/${subpath}`); return this.callbacks.loadFile(importPath); } readLocalImportFile(path: string): Uint8Array { // try each of the local imports paths for (const localPath of this.options.localImportsPaths) { - const importPath = this.callbacks.resolveFilename(localPath, path); + const importPath = this.callbacks.path.join(localPath, path); if(this.callbacks.fs.existsSync(importPath)) { return this.callbacks.loadFile(importPath); } diff --git a/developer/src/common/web/utils/test/helpers/reader-callback-test.ts b/developer/src/common/web/utils/test/helpers/reader-callback-test.ts index 8c2e4295209..d865ab2f46a 100644 --- a/developer/src/common/web/utils/test/helpers/reader-callback-test.ts +++ b/developer/src/common/web/utils/test/helpers/reader-callback-test.ts @@ -7,10 +7,10 @@ import { LDMLKeyboardXMLSourceFile } from '../../src/types/ldml-keyboard/ldml-ke import { LDMLKeyboardTestDataXMLSourceFile } from '../../src/types/ldml-keyboard/ldml-keyboard-testdata-xml.js'; import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers'; import { fileURLToPath } from 'url'; -import { dirname, sep } from 'node:path'; +import { dirname } from 'node:path'; const readerOptions: LDMLKeyboardXMLSourceFileReaderOptions = { - importsPath: fileURLToPath(new URL(...LDMLKeyboardXMLSourceFileReader.defaultImportsURL)), + cldrImportsPath: fileURLToPath(new URL(...LDMLKeyboardXMLSourceFileReader.defaultImportsURL)), localImportsPaths: [], }; @@ -85,8 +85,8 @@ export function testReaderCases(cases : CompilationCase[]) { it(testHeading, function () { callbacks.clear(); const path = makePathToFixture('ldml-keyboard', testcase.subpath); - // update readerOptions to point to the source dir. Need a trailing separator. - readerOptions.localImportsPaths = [ dirname(path) + sep ]; + // update readerOptions to point to the source dir. + readerOptions.localImportsPaths = [ dirname(path) ]; const reader = new LDMLKeyboardXMLSourceFileReader(readerOptions, callbacks); const data = loadFile(path); assert.ok(data, `reading ${testcase.subpath}`); diff --git a/developer/src/kmc-ldml/test/helpers/index.ts b/developer/src/kmc-ldml/test/helpers/index.ts index 283459688fe..bd438c4ca11 100644 --- a/developer/src/kmc-ldml/test/helpers/index.ts +++ b/developer/src/kmc-ldml/test/helpers/index.ts @@ -38,7 +38,7 @@ export const compilerTestCallbacks = new TestCompilerCallbacks(); export const compilerTestOptions: LdmlCompilerOptions = { readerOptions: { - importsPath: fileURLToPath(new URL(...LDMLKeyboardXMLSourceFileReader.defaultImportsURL)), + cldrImportsPath: fileURLToPath(new URL(...LDMLKeyboardXMLSourceFileReader.defaultImportsURL)), localImportsPaths: [], // will be fixed up in loadSectionFixture } }; @@ -60,7 +60,7 @@ export async function loadSectionFixture(compilerClass: SectionCompilerNew, file const data = callbacks.loadFile(inputFilename); assert.isNotNull(data, `Failed to read file ${inputFilename}`); - compilerTestOptions.readerOptions.localImportsPaths = [ path.dirname(inputFilename) + path.sep ]; + compilerTestOptions.readerOptions.localImportsPaths = [ path.dirname(inputFilename) ]; const reader = new LDMLKeyboardXMLSourceFileReader(compilerTestOptions.readerOptions, callbacks); const source = reader.load(data); diff --git a/developer/src/kmc/src/commands/buildClasses/BuildLdmlKeyboard.ts b/developer/src/kmc/src/commands/buildClasses/BuildLdmlKeyboard.ts index 643f31e9596..6a6300b646b 100644 --- a/developer/src/kmc/src/commands/buildClasses/BuildLdmlKeyboard.ts +++ b/developer/src/kmc/src/commands/buildClasses/BuildLdmlKeyboard.ts @@ -4,7 +4,7 @@ import { CompilerOptions, CompilerCallbacks } from '@keymanapp/developer-utils'; import { LDMLKeyboardXMLSourceFileReader } from '@keymanapp/developer-utils'; import { BuildActivity } from './BuildActivity.js'; import { fileURLToPath } from 'url'; -import { dirname, sep } from 'node:path'; +import { dirname } from 'node:path'; export class BuildLdmlKeyboard extends BuildActivity { public get name(): string { return 'LDML keyboard'; } @@ -14,8 +14,8 @@ export class BuildLdmlKeyboard extends BuildActivity { public async build(infile: string, outfile: string, callbacks: CompilerCallbacks, options: CompilerOptions): Promise { // TODO-LDML: consider hardware vs touch -- touch-only layout will not have a .kvk const ldmlCompilerOptions: kmcLdml.LdmlCompilerOptions = {...options, readerOptions: { - importsPath: fileURLToPath(new URL(...LDMLKeyboardXMLSourceFileReader.defaultImportsURL)), - localImportsPaths: [ dirname(infile) + sep ], // local dir + cldrImportsPath: fileURLToPath(new URL(...LDMLKeyboardXMLSourceFileReader.defaultImportsURL)), + localImportsPaths: [ dirname(infile) ], // local dir }}; const compiler = new kmcLdml.LdmlKeyboardCompiler(); return await super.runCompiler(compiler, infile, outfile, callbacks, ldmlCompilerOptions); diff --git a/developer/src/kmc/src/commands/buildTestData/index.ts b/developer/src/kmc/src/commands/buildTestData/index.ts index 39b149765c5..5343c81702d 100644 --- a/developer/src/kmc/src/commands/buildTestData/index.ts +++ b/developer/src/kmc/src/commands/buildTestData/index.ts @@ -7,7 +7,7 @@ import { fileURLToPath } from 'url'; import { CommandLineBaseOptions } from 'src/util/baseOptions.js'; import { exitProcess } from '../../util/sysexits.js'; import { InfrastructureMessages } from '../../messages/infrastructureMessages.js'; -import { dirname, sep } from 'node:path'; +import { dirname } from 'node:path'; export async function buildTestData(infile: string, _options: any, commander: any): Promise { const options: CommandLineBaseOptions = commander.optsWithGlobals(); @@ -18,8 +18,8 @@ export async function buildTestData(infile: string, _options: any, commander: an saveDebug: false, shouldAddCompilerVersion: false, readerOptions: { - importsPath: fileURLToPath(new URL(...LDMLKeyboardXMLSourceFileReader.defaultImportsURL)), - localImportsPaths: [ dirname(infile) + sep ], // local dir + cldrImportsPath: fileURLToPath(new URL(...LDMLKeyboardXMLSourceFileReader.defaultImportsURL)), + localImportsPaths: [ dirname(infile) ], // local dir } };