@verbatra/sdk 0.9.0 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +119 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -13
- package/dist/index.d.ts +38 -13
- package/dist/index.js +120 -4
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -5,11 +5,12 @@ var zod = require('zod');
|
|
|
5
5
|
var crypto = require('crypto');
|
|
6
6
|
var promises = require('fs/promises');
|
|
7
7
|
var fs = require('fs');
|
|
8
|
+
var os = require('os');
|
|
8
9
|
var cosmiconfig = require('cosmiconfig');
|
|
9
10
|
var cosmiconfigTypescriptLoader = require('cosmiconfig-typescript-loader');
|
|
11
|
+
var module$1 = require('module');
|
|
10
12
|
var Anthropic = require('@anthropic-ai/sdk');
|
|
11
13
|
var deepl = require('deepl-node');
|
|
12
|
-
var module$1 = require('module');
|
|
13
14
|
var log = require('loglevel');
|
|
14
15
|
var genai = require('@google/genai');
|
|
15
16
|
var OpenAI = require('openai');
|
|
@@ -530,6 +531,67 @@ async function updateGlossaryTerm(input, deps = {}) {
|
|
|
530
531
|
return entries;
|
|
531
532
|
});
|
|
532
533
|
}
|
|
534
|
+
var SELF_ALIASED_PACKAGES = ["@verbatra/sdk", "@verbatra/cli"];
|
|
535
|
+
var ENTRY_CONDITION_ORDER = ["import", "node", "default", "require"];
|
|
536
|
+
function resolvePathsFromRunningModule(packageName) {
|
|
537
|
+
return module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).resolve.paths(packageName) ?? [];
|
|
538
|
+
}
|
|
539
|
+
function readPackageManifestFromDisk(packageRoot) {
|
|
540
|
+
try {
|
|
541
|
+
return JSON.parse(fs.readFileSync(path.join(packageRoot, "package.json"), "utf8"));
|
|
542
|
+
} catch {
|
|
543
|
+
return void 0;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
var defaultModuleAliasDeps = {
|
|
547
|
+
resolvePaths: resolvePathsFromRunningModule,
|
|
548
|
+
readPackageManifest: readPackageManifestFromDisk
|
|
549
|
+
};
|
|
550
|
+
function resolveRootExportPath(manifest) {
|
|
551
|
+
const exportsField = manifest.exports;
|
|
552
|
+
if (typeof exportsField === "string") {
|
|
553
|
+
return exportsField;
|
|
554
|
+
}
|
|
555
|
+
if (typeof exportsField === "object" && exportsField !== null) {
|
|
556
|
+
const rootExport = exportsField["."];
|
|
557
|
+
if (typeof rootExport === "string") {
|
|
558
|
+
return rootExport;
|
|
559
|
+
}
|
|
560
|
+
if (typeof rootExport === "object" && rootExport !== null) {
|
|
561
|
+
for (const condition of ENTRY_CONDITION_ORDER) {
|
|
562
|
+
const candidate = rootExport[condition];
|
|
563
|
+
if (typeof candidate === "string") {
|
|
564
|
+
return candidate;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
return manifest.main;
|
|
570
|
+
}
|
|
571
|
+
function findPackageEntry(packageName, deps) {
|
|
572
|
+
for (const candidateDir of deps.resolvePaths(packageName)) {
|
|
573
|
+
const packageRoot = path.join(candidateDir, packageName);
|
|
574
|
+
const manifest = deps.readPackageManifest(packageRoot);
|
|
575
|
+
if (manifest === void 0) {
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
const relativeEntry = resolveRootExportPath(manifest);
|
|
579
|
+
if (relativeEntry !== void 0) {
|
|
580
|
+
return path.join(packageRoot, relativeEntry);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
return void 0;
|
|
584
|
+
}
|
|
585
|
+
function resolveSelfPackageAliases(deps = defaultModuleAliasDeps) {
|
|
586
|
+
const aliases = {};
|
|
587
|
+
for (const packageName of SELF_ALIASED_PACKAGES) {
|
|
588
|
+
const entry = findPackageEntry(packageName, deps);
|
|
589
|
+
if (entry !== void 0) {
|
|
590
|
+
aliases[packageName] = entry;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return aliases;
|
|
594
|
+
}
|
|
533
595
|
async function resolveGlossary(glossary, baseDir, fs) {
|
|
534
596
|
if (glossary === void 0) {
|
|
535
597
|
return { glossary: void 0, provenance: { source: "none" } };
|
|
@@ -2194,6 +2256,50 @@ var SEARCH_PLACES = [
|
|
|
2194
2256
|
`${MODULE_NAME}.config.cjs`,
|
|
2195
2257
|
`${MODULE_NAME}.config.ts`
|
|
2196
2258
|
];
|
|
2259
|
+
function isAncestorOrSelf(ancestor, startDir) {
|
|
2260
|
+
const target = path.resolve(ancestor);
|
|
2261
|
+
let dir = path.resolve(startDir);
|
|
2262
|
+
while (true) {
|
|
2263
|
+
if (dir === target) {
|
|
2264
|
+
return true;
|
|
2265
|
+
}
|
|
2266
|
+
const parent = path.dirname(dir);
|
|
2267
|
+
if (parent === dir) {
|
|
2268
|
+
return false;
|
|
2269
|
+
}
|
|
2270
|
+
dir = parent;
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
function findSearchStopDir(startDir) {
|
|
2274
|
+
let dir = path.resolve(startDir);
|
|
2275
|
+
while (true) {
|
|
2276
|
+
if (fs.existsSync(path.join(dir, ".git"))) {
|
|
2277
|
+
return dir;
|
|
2278
|
+
}
|
|
2279
|
+
const parent = path.dirname(dir);
|
|
2280
|
+
if (parent === dir) {
|
|
2281
|
+
break;
|
|
2282
|
+
}
|
|
2283
|
+
dir = parent;
|
|
2284
|
+
}
|
|
2285
|
+
const home = path.resolve(os.homedir());
|
|
2286
|
+
return isAncestorOrSelf(home, startDir) ? home : path.resolve(startDir);
|
|
2287
|
+
}
|
|
2288
|
+
function collectSearchChain(startDir, stopDir) {
|
|
2289
|
+
const stop = path.resolve(stopDir);
|
|
2290
|
+
const chain = /* @__PURE__ */ new Set();
|
|
2291
|
+
let dir = path.resolve(startDir);
|
|
2292
|
+
while (dir !== stop) {
|
|
2293
|
+
chain.add(dir);
|
|
2294
|
+
const parent = path.dirname(dir);
|
|
2295
|
+
if (parent === dir) {
|
|
2296
|
+
break;
|
|
2297
|
+
}
|
|
2298
|
+
dir = parent;
|
|
2299
|
+
}
|
|
2300
|
+
chain.add(stop);
|
|
2301
|
+
return chain;
|
|
2302
|
+
}
|
|
2197
2303
|
function formatIssues(error) {
|
|
2198
2304
|
return error.issues.map((issue) => {
|
|
2199
2305
|
const path = issue.path.join(".");
|
|
@@ -2243,20 +2349,30 @@ async function loadConfigWithMeta(options = {}) {
|
|
|
2243
2349
|
const { config: config2, glossary: glossary2 } = await finalizeConfig(parsed2, options.cwd ?? process.cwd(), fs);
|
|
2244
2350
|
return { config: config2, source: { kind: "override" }, glossary: glossary2 };
|
|
2245
2351
|
}
|
|
2352
|
+
const cwd = options.cwd ?? process.cwd();
|
|
2353
|
+
const stopDir = findSearchStopDir(cwd);
|
|
2246
2354
|
const explorer = cosmiconfig.cosmiconfig(MODULE_NAME, {
|
|
2247
2355
|
searchPlaces: SEARCH_PLACES,
|
|
2248
|
-
loaders: { ".ts": cosmiconfigTypescriptLoader.TypeScriptLoader() }
|
|
2356
|
+
loaders: { ".ts": cosmiconfigTypescriptLoader.TypeScriptLoader({ alias: resolveSelfPackageAliases() }) },
|
|
2357
|
+
searchStrategy: "global",
|
|
2358
|
+
stopDir
|
|
2249
2359
|
});
|
|
2250
2360
|
if (options.configPath !== void 0) {
|
|
2251
2361
|
return loadExplicitWithMeta(explorer, options.configPath, options.cwd, fs);
|
|
2252
2362
|
}
|
|
2253
2363
|
let result;
|
|
2254
2364
|
try {
|
|
2255
|
-
result = await explorer.search(
|
|
2365
|
+
result = await explorer.search(cwd);
|
|
2256
2366
|
} catch (error) {
|
|
2257
2367
|
const detail = errorMessage(error);
|
|
2258
2368
|
throw new SdkError("CONFIG_INVALID", `Failed to load the verbatra configuration: ${detail}`);
|
|
2259
2369
|
}
|
|
2370
|
+
if (result !== null && result.isEmpty !== true) {
|
|
2371
|
+
const resultDir = path.dirname(path.resolve(result.filepath));
|
|
2372
|
+
if (!collectSearchChain(cwd, stopDir).has(resultDir)) {
|
|
2373
|
+
result = null;
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2260
2376
|
if (result === null || result.isEmpty === true) {
|
|
2261
2377
|
throw new SdkError(
|
|
2262
2378
|
"CONFIG_NOT_FOUND",
|