« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/url-spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/url-spec.js')
-rw-r--r--src/url-spec.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/url-spec.js b/src/url-spec.js
index 75cd8006..2e8b9fc1 100644
--- a/src/url-spec.js
+++ b/src/url-spec.js
@@ -1,6 +1,7 @@
 // Exports defined here are re-exported through urls.js,
 // so they're generally imported from '#urls'.
 
+import {readFileSync} from 'node:fs';
 import {readFile} from 'node:fs/promises';
 import * as path from 'node:path';
 import {fileURLToPath} from 'node:url';
@@ -195,6 +196,24 @@ export async function processURLSpecFromFile(file) {
       error => annotateErrorWithFile(error, file));
   }
 
+  return processURLSpecFromFileContents(file, contents);
+}
+
+export function processURLSpecFromFileSync(file) {
+  let contents;
+
+  try {
+    contents = readFileSync(file, 'utf-8');
+  } catch (caughtError) {
+    throw annotateError(
+      new Error(`Failed to read URL spec file`, {cause: caughtError}),
+      error => annotateErrorWithFile(error, file));
+  }
+
+  return processURLSpecFromFileContents(file, contents);
+}
+
+function processURLSpecFromFileContents(file, contents) {
   let sourceSpec;
   let parseLanguage;