@kimesh/layers 0.2.7 → 0.2.8-nightly.20260126032211
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.mjs +54 -5
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -403,18 +403,40 @@ async function scanLayersDirectory(layersDir, startPriority, visited) {
|
|
|
403
403
|
return layers;
|
|
404
404
|
}
|
|
405
405
|
/**
|
|
406
|
+
* Wrap a function with defineKmConfig injected into globalThis.
|
|
407
|
+
* This allows layer config files to use defineKmConfig without explicit import.
|
|
408
|
+
*
|
|
409
|
+
* Following Nuxt's approach: the function is just a passthrough identity function.
|
|
410
|
+
* @see https://github.com/nuxt/nuxt/blob/main/packages/kit/src/loader/config.ts
|
|
411
|
+
*/
|
|
412
|
+
async function withDefineKmConfig$1(fn) {
|
|
413
|
+
const key = "defineKmConfig";
|
|
414
|
+
const globalSelf = globalThis;
|
|
415
|
+
if (!globalSelf[key]) {
|
|
416
|
+
globalSelf[key] = (c) => c;
|
|
417
|
+
globalSelf[key].count = 0;
|
|
418
|
+
}
|
|
419
|
+
globalSelf[key].count++;
|
|
420
|
+
try {
|
|
421
|
+
return await fn();
|
|
422
|
+
} finally {
|
|
423
|
+
globalSelf[key].count--;
|
|
424
|
+
if (!globalSelf[key].count) delete globalSelf[key];
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
406
428
|
* Load kimesh.config.ts from a layer directory using c12
|
|
407
429
|
*/
|
|
408
430
|
async function loadLayerConfig(layerPath) {
|
|
409
431
|
const configPath = path.join(layerPath, "kimesh.config.ts");
|
|
410
432
|
if (!fs.existsSync(configPath)) return null;
|
|
411
433
|
try {
|
|
412
|
-
const { loadConfig
|
|
413
|
-
const { config } = await
|
|
434
|
+
const { loadConfig } = await import("c12");
|
|
435
|
+
const { config } = await withDefineKmConfig$1(() => loadConfig({
|
|
414
436
|
name: "kimesh",
|
|
415
437
|
cwd: layerPath,
|
|
416
438
|
extend: false
|
|
417
|
-
});
|
|
439
|
+
}));
|
|
418
440
|
if (config) {
|
|
419
441
|
logger$1.debug(`Loaded config from ${configPath}`);
|
|
420
442
|
const { runtimeConfig, ...layerConfig } = config;
|
|
@@ -671,16 +693,43 @@ function detectConflicts(merged) {
|
|
|
671
693
|
* @packageDocumentation
|
|
672
694
|
*/
|
|
673
695
|
/**
|
|
696
|
+
* Identity function for defining Kimesh configuration.
|
|
697
|
+
* This function is injected into globalThis before loading config files
|
|
698
|
+
* so that kimesh.config.ts files can use it without explicit imports.
|
|
699
|
+
*
|
|
700
|
+
* @internal
|
|
701
|
+
*/
|
|
702
|
+
function defineKmConfig(config) {
|
|
703
|
+
return config;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Execute a function with defineKmConfig available in globalThis.
|
|
707
|
+
* This ensures config files can use defineKmConfig without importing it.
|
|
708
|
+
*
|
|
709
|
+
* @internal
|
|
710
|
+
*/
|
|
711
|
+
async function withDefineKmConfig(fn) {
|
|
712
|
+
const hadDefineKmConfig = "defineKmConfig" in globalThis;
|
|
713
|
+
const previousValue = globalThis.defineKmConfig;
|
|
714
|
+
globalThis.defineKmConfig = defineKmConfig;
|
|
715
|
+
try {
|
|
716
|
+
return await fn();
|
|
717
|
+
} finally {
|
|
718
|
+
if (hadDefineKmConfig) globalThis.defineKmConfig = previousValue;
|
|
719
|
+
else delete globalThis.defineKmConfig;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
674
723
|
* Extract extends array from config file without c12 merging
|
|
675
724
|
*/
|
|
676
725
|
async function extractExtendsFromConfig(root) {
|
|
677
726
|
const configPath = path.join(root, "kimesh.config.ts");
|
|
678
727
|
if (!fs.existsSync(configPath)) return [];
|
|
679
|
-
const { config } = await loadConfig({
|
|
728
|
+
const { config } = await withDefineKmConfig(() => loadConfig({
|
|
680
729
|
name: "kimesh",
|
|
681
730
|
cwd: root,
|
|
682
731
|
extend: false
|
|
683
|
-
});
|
|
732
|
+
}));
|
|
684
733
|
return config?.extends ?? [];
|
|
685
734
|
}
|
|
686
735
|
/**
|
package/package.json
CHANGED