@utilarium/cardigantime 0.0.24 → 0.0.25
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/cardigantime.cjs +102 -5
- package/dist/cardigantime.cjs.map +1 -1
- package/dist/constants.js +1 -1
- package/dist/read.js +28 -2
- package/dist/read.js.map +1 -1
- package/dist/types.d.ts +11 -0
- package/dist/types.js.map +1 -1
- package/dist/util/hierarchical.js +28 -2
- package/dist/util/hierarchical.js.map +1 -1
- package/dist/util/path-detection.d.ts +11 -0
- package/dist/util/path-normalization.d.ts +10 -0
- package/dist/util/path-normalization.js +49 -0
- package/dist/util/path-normalization.js.map +1 -0
- package/dist/util/path-validation.d.ts +12 -0
- package/package.json +1 -1
package/dist/cardigantime.cjs
CHANGED
|
@@ -198,7 +198,7 @@ function _define_property$2(obj, key, value) {
|
|
|
198
198
|
return retCommand;
|
|
199
199
|
};
|
|
200
200
|
|
|
201
|
-
/** Version string populated at build time with git and system information */ const VERSION = '0.0.
|
|
201
|
+
/** Version string populated at build time with git and system information */ const VERSION = '0.0.25 (HEAD/7f2faa1 T:v0.0.25 2026-01-31 10:25:42 -0800) linux x64 v24.13.0';
|
|
202
202
|
/** The program name used in CLI help and error messages */ const PROGRAM_NAME = 'cardigantime';
|
|
203
203
|
/** Default file encoding for reading configuration files */ const DEFAULT_ENCODING = 'utf8';
|
|
204
204
|
/** Default configuration file name to look for in the config directory */ const DEFAULT_CONFIG_FILE = 'config.yaml';
|
|
@@ -436,6 +436,53 @@ const create$1 = (params)=>{
|
|
|
436
436
|
};
|
|
437
437
|
};
|
|
438
438
|
|
|
439
|
+
/**
|
|
440
|
+
* Path normalization utilities for handling file:// URLs and rejecting non-file URLs
|
|
441
|
+
*/ /**
|
|
442
|
+
* Normalizes path input by converting file:// URLs to paths and rejecting non-file URLs
|
|
443
|
+
* @param value - The value to normalize (string, array, object, or other)
|
|
444
|
+
* @returns Normalized value with file:// URLs converted to paths
|
|
445
|
+
* @throws Error if value contains http://, https://, or other non-file URLs
|
|
446
|
+
*/ function normalizePathInput(value) {
|
|
447
|
+
if (typeof value === 'string') {
|
|
448
|
+
return normalizePathString(value);
|
|
449
|
+
}
|
|
450
|
+
if (Array.isArray(value)) {
|
|
451
|
+
return value.map((item)=>typeof item === 'string' ? normalizePathString(item) : item);
|
|
452
|
+
}
|
|
453
|
+
if (value && typeof value === 'object') {
|
|
454
|
+
const normalized = {};
|
|
455
|
+
for (const [key, val] of Object.entries(value)){
|
|
456
|
+
normalized[key] = normalizePathInput(val); // Recursive for nested objects
|
|
457
|
+
}
|
|
458
|
+
return normalized;
|
|
459
|
+
}
|
|
460
|
+
return value;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Normalizes a single path string by converting file:// URLs and rejecting non-file URLs
|
|
464
|
+
* @param str - The string to normalize
|
|
465
|
+
* @returns Normalized path string
|
|
466
|
+
* @throws Error if string contains non-file URLs
|
|
467
|
+
*/ function normalizePathString(str) {
|
|
468
|
+
// Check for non-file URLs and reject them
|
|
469
|
+
if (/^https?:\/\//i.test(str)) {
|
|
470
|
+
throw new Error(`Non-file URLs are not supported in path fields: ${str}`);
|
|
471
|
+
}
|
|
472
|
+
// Convert file:// URLs to regular paths
|
|
473
|
+
if (/^file:\/\//i.test(str)) {
|
|
474
|
+
try {
|
|
475
|
+
const url = new URL(str);
|
|
476
|
+
// Decode URL-encoded characters (like %20 for spaces)
|
|
477
|
+
return decodeURIComponent(url.pathname);
|
|
478
|
+
} catch {
|
|
479
|
+
throw new Error(`Invalid file:// URL: ${str}`);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
// Return regular paths unchanged
|
|
483
|
+
return str;
|
|
484
|
+
}
|
|
485
|
+
|
|
439
486
|
/**
|
|
440
487
|
* Resolves relative paths in configuration values relative to the configuration file's directory.
|
|
441
488
|
*/ function resolveConfigPaths$1(config, configDir, pathFields = [], resolvePathArray = []) {
|
|
@@ -448,8 +495,11 @@ const create$1 = (params)=>{
|
|
|
448
495
|
for (const fieldPath of pathFields){
|
|
449
496
|
const value = getNestedValue$1(resolvedConfig, fieldPath);
|
|
450
497
|
if (value !== undefined) {
|
|
498
|
+
// Step 1: Normalize input (convert file:// URLs, reject http/https)
|
|
499
|
+
const normalizedValue = normalizePathInput(value);
|
|
500
|
+
// Step 2: Resolve paths relative to config directory
|
|
451
501
|
const shouldResolveArrayElements = resolvePathArray.includes(fieldPath);
|
|
452
|
-
const resolvedValue = resolvePathValue$1(
|
|
502
|
+
const resolvedValue = resolvePathValue$1(normalizedValue, configDir, shouldResolveArrayElements);
|
|
453
503
|
setNestedValue$1(resolvedConfig, fieldPath, resolvedValue);
|
|
454
504
|
}
|
|
455
505
|
}
|
|
@@ -485,7 +535,13 @@ function setNestedValue$1(obj, path, value) {
|
|
|
485
535
|
target[lastKey] = value;
|
|
486
536
|
}
|
|
487
537
|
/**
|
|
488
|
-
* Resolves a path value (string
|
|
538
|
+
* Resolves a path value (string, array, or object) relative to the config directory.
|
|
539
|
+
*
|
|
540
|
+
* Handles:
|
|
541
|
+
* - Strings: Resolved relative to configDir
|
|
542
|
+
* - Arrays: Elements resolved if resolveArrayElements is true
|
|
543
|
+
* - Objects: All string values and array elements resolved recursively
|
|
544
|
+
* - Other types: Returned unchanged
|
|
489
545
|
*/ function resolvePathValue$1(value, configDir, resolveArrayElements) {
|
|
490
546
|
if (typeof value === 'string') {
|
|
491
547
|
return resolveSinglePath$1(value, configDir);
|
|
@@ -493,6 +549,22 @@ function setNestedValue$1(obj, path, value) {
|
|
|
493
549
|
if (Array.isArray(value) && resolveArrayElements) {
|
|
494
550
|
return value.map((item)=>typeof item === 'string' ? resolveSinglePath$1(item, configDir) : item);
|
|
495
551
|
}
|
|
552
|
+
// NEW: Handle objects with string values
|
|
553
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
554
|
+
const resolved = {};
|
|
555
|
+
for (const [key, val] of Object.entries(value)){
|
|
556
|
+
if (typeof val === 'string') {
|
|
557
|
+
resolved[key] = resolveSinglePath$1(val, configDir);
|
|
558
|
+
} else if (Array.isArray(val)) {
|
|
559
|
+
// Also handle arrays within objects
|
|
560
|
+
resolved[key] = val.map((item)=>typeof item === 'string' ? resolveSinglePath$1(item, configDir) : item);
|
|
561
|
+
} else {
|
|
562
|
+
// Keep other types unchanged
|
|
563
|
+
resolved[key] = val;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return resolved;
|
|
567
|
+
}
|
|
496
568
|
return value;
|
|
497
569
|
}
|
|
498
570
|
/**
|
|
@@ -893,8 +965,11 @@ function setNestedValue$1(obj, path, value) {
|
|
|
893
965
|
for (const fieldPath of pathFields){
|
|
894
966
|
const value = getNestedValue(resolvedConfig, fieldPath);
|
|
895
967
|
if (value !== undefined) {
|
|
968
|
+
// Step 1: Normalize input (convert file:// URLs, reject http/https)
|
|
969
|
+
const normalizedValue = normalizePathInput(value);
|
|
970
|
+
// Step 2: Resolve paths relative to config directory
|
|
896
971
|
const shouldResolveArrayElements = resolvePathArray.includes(fieldPath);
|
|
897
|
-
const resolvedValue = resolvePathValue(
|
|
972
|
+
const resolvedValue = resolvePathValue(normalizedValue, configDir, shouldResolveArrayElements);
|
|
898
973
|
setNestedValue(resolvedConfig, fieldPath, resolvedValue);
|
|
899
974
|
}
|
|
900
975
|
}
|
|
@@ -933,7 +1008,13 @@ function setNestedValue$1(obj, path, value) {
|
|
|
933
1008
|
target[lastKey] = value;
|
|
934
1009
|
}
|
|
935
1010
|
/**
|
|
936
|
-
* Resolves a path value (string
|
|
1011
|
+
* Resolves a path value (string, array, or object) relative to the config directory.
|
|
1012
|
+
*
|
|
1013
|
+
* Handles:
|
|
1014
|
+
* - Strings: Resolved relative to configDir
|
|
1015
|
+
* - Arrays: Elements resolved if resolveArrayElements is true
|
|
1016
|
+
* - Objects: All string values and array elements resolved recursively
|
|
1017
|
+
* - Other types: Returned unchanged
|
|
937
1018
|
*/ function resolvePathValue(value, configDir, resolveArrayElements) {
|
|
938
1019
|
if (typeof value === 'string') {
|
|
939
1020
|
return resolveSinglePath(value, configDir);
|
|
@@ -941,6 +1022,22 @@ function setNestedValue$1(obj, path, value) {
|
|
|
941
1022
|
if (Array.isArray(value) && resolveArrayElements) {
|
|
942
1023
|
return value.map((item)=>typeof item === 'string' ? resolveSinglePath(item, configDir) : item);
|
|
943
1024
|
}
|
|
1025
|
+
// NEW: Handle objects with string values
|
|
1026
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
1027
|
+
const resolved = {};
|
|
1028
|
+
for (const [key, val] of Object.entries(value)){
|
|
1029
|
+
if (typeof val === 'string') {
|
|
1030
|
+
resolved[key] = resolveSinglePath(val, configDir);
|
|
1031
|
+
} else if (Array.isArray(val)) {
|
|
1032
|
+
// Also handle arrays within objects
|
|
1033
|
+
resolved[key] = val.map((item)=>typeof item === 'string' ? resolveSinglePath(item, configDir) : item);
|
|
1034
|
+
} else {
|
|
1035
|
+
// Keep other types unchanged
|
|
1036
|
+
resolved[key] = val;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
return resolved;
|
|
1040
|
+
}
|
|
944
1041
|
return value;
|
|
945
1042
|
}
|
|
946
1043
|
/**
|