« get me outta code hell

upd8, data, test: export internal strings path cleanly, fix tests - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-11-09 20:16:30 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-11-09 20:16:30 -0400
commit1d991bb4bc877363532971a74f70e55939c637bb (patch)
tree45f368639455f17ba45c377e770b7763c3a3bd59
parentf6a0bf1d7b4652a7dd04ed3340010ee2a6e47b7f (diff)
upd8, data, test: export internal strings path cleanly, fix tests
-rw-r--r--src/data/language.js9
-rw-r--r--src/repl.js9
-rwxr-xr-xsrc/upd8.js7
-rw-r--r--test/lib/content-function.js4
4 files changed, 15 insertions, 14 deletions
diff --git a/src/data/language.js b/src/data/language.js
index 6ffc31e..3fc14da 100644
--- a/src/data/language.js
+++ b/src/data/language.js
@@ -1,6 +1,7 @@
 import EventEmitter from 'node:events';
 import {readFile} from 'node:fs/promises';
 import path from 'node:path';
+import {fileURLToPath} from 'node:url';
 
 import chokidar from 'chokidar';
 import he from 'he'; // It stands for "HTML Entities", apparently. Cursed.
@@ -18,6 +19,14 @@ import {
 
 const {Language} = T;
 
+export const DEFAULT_STRINGS_FILE = 'strings-default.yaml';
+
+export const internalDefaultStringsFile =
+  path.resolve(
+    path.dirname(fileURLToPath(import.meta.url)),
+    '../',
+    DEFAULT_STRINGS_FILE);
+
 export function processLanguageSpec(spec, {existingCode = null} = {}) {
   const {
     'meta.languageCode': code,
diff --git a/src/repl.js b/src/repl.js
index 7a6f5c4..3f5d752 100644
--- a/src/repl.js
+++ b/src/repl.js
@@ -5,7 +5,7 @@ import {fileURLToPath} from 'node:url';
 
 import {logError, logWarn, parseOptions} from '#cli';
 import {isMain} from '#node-utils';
-import {processLanguageFile} from '#language';
+import {internalDefaultStringsFile, processLanguageFile} from '#language';
 import {bindOpts, showAggregate} from '#sugar';
 import {generateURLs, urlSpec} from '#urls';
 import {quickLoadAllFromYAML} from '#yaml';
@@ -16,8 +16,6 @@ import * as serialize from '#serialize';
 import * as sugar from '#sugar';
 import * as wikiDataUtils from '#wiki-data';
 
-import {DEFAULT_STRINGS_FILE} from './upd8.js';
-
 const __dirname = path.dirname(fileURLToPath(import.meta.url));
 
 export async function getContextAssignments({
@@ -45,10 +43,7 @@ export async function getContextAssignments({
 
   let language;
   try {
-    language = await processLanguageFile(
-      path.join(
-        path.dirname(fileURLToPath(import.meta.url)),
-        DEFAULT_STRINGS_FILE));
+    language = await processLanguageFile(internalDefaultStringsFile);
   } catch (error) {
     console.error(error);
     logWarn`Failed to create Language object`;
diff --git a/src/upd8.js b/src/upd8.js
index 24d0b92..db73c41 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -39,7 +39,8 @@ import {fileURLToPath} from 'node:url';
 import wrap from 'word-wrap';
 
 import {displayCompositeCacheAnalysis} from '#composite';
-import {processLanguageFile, watchLanguageFile} from '#language';
+import {processLanguageFile, watchLanguageFile, internalDefaultStringsFile}
+  from '#language';
 import {isMain, traverse} from '#node-utils';
 import bootRepl from '#repl';
 import {empty, showAggregate, withEntries} from '#sugar';
@@ -93,8 +94,6 @@ try {
 
 const BUILD_TIME = new Date();
 
-export const DEFAULT_STRINGS_FILE = 'strings-default.yaml';
-
 const STATUS_NOT_STARTED       = `not started`;
 const STATUS_NOT_APPLICABLE    = `not applicable`;
 const STATUS_STARTED_NOT_DONE  = `started but not yet done`;
@@ -1104,8 +1103,6 @@ async function main() {
   let internalDefaultLanguage;
   let internalDefaultLanguageWatcher;
 
-  const internalDefaultStringsFile = path.join(__dirname, DEFAULT_STRINGS_FILE);
-
   let errorLoadingInternalDefaultLanguage = false;
 
   if (noLanguageReloading) {
diff --git a/test/lib/content-function.js b/test/lib/content-function.js
index 5cb499b..24363e6 100644
--- a/test/lib/content-function.js
+++ b/test/lib/content-function.js
@@ -8,7 +8,7 @@ import {getColors} from '#colors';
 import {quickLoadContentDependencies} from '#content-dependencies';
 import {quickEvaluate} from '#content-function';
 import * as html from '#html';
-import {processLanguageFile} from '#language';
+import {internalDefaultStringsFile, processLanguageFile} from '#language';
 import {empty, showAggregate} from '#sugar';
 import {generateURLs, thumb, urlSpec} from '#urls';
 
@@ -22,7 +22,7 @@ export function testContentFunctions(t, message, fn) {
   t.test(message, async t => {
     let loadedContentDependencies;
 
-    const language = await processLanguageFile('./src/strings-default.json');
+    const language = await processLanguageFile(internalDefaultStringsFile);
     const mocks = [];
 
     const evaluate = ({