jskelet 0.3.5 → 0.4.1

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.
@@ -1,7 +1,6 @@
1
1
  /**
2
- * `views/components/**` altındaki tüm modülleri yükler ve named export'larını
3
- * tek bir nesnede birleştirir. Bu nesne EJS şablonlarına local olarak geçer,
4
- * böylece `<%- card({ … }) %>` gibi çağrılar import gerektirmeden çalışır.
2
+ * `views/components/**` (ve feature/shared köklerindeki eşleri) altındaki
3
+ * tüm modülleri yükler ve named export'larını tek bir nesnede birleştirir.
5
4
  *
6
5
  * Elle bakılan bir barrel dosyası yok: yeni bir bileşen eklemek için dosyayı
7
6
  * oluşturmak yeterli.
@@ -44,17 +43,15 @@ function collect(dir, out = []) {
44
43
  }
45
44
 
46
45
  /**
47
- * @param {string} dir `views/components` dizininin mutlak yolu. Dizin yoksa
48
- * boş nesne döner: bileşen kullanmayan bir proje de çalışmalı.
49
- * @returns {Promise<Record<string, unknown>>}
46
+ * Tek bir `components/` dizinini yükler.
47
+ *
48
+ * @param {string} dir
49
+ * @param {Record<string, unknown>} components
50
+ * @param {Map<string, string>} origin
51
+ * @returns {Promise<void>}
50
52
  */
51
- export async function loadComponents(dir) {
52
- if (!dir || !fs.existsSync(dir)) return {};
53
-
54
- /** @type {Record<string, unknown>} */
55
- const components = {};
56
- /** @type {Map<string, string>} */
57
- const origin = new Map();
53
+ async function loadDir(dir, components, origin) {
54
+ if (!dir || !fs.existsSync(dir)) return;
58
55
 
59
56
  const barrel = path.join(dir, BARREL);
60
57
  const files = [
@@ -63,23 +60,42 @@ export async function loadComponents(dir) {
63
60
  ];
64
61
 
65
62
  for (const file of files) {
66
- const relative = path.relative(dir, file).split(path.sep).join("/");
63
+ const isBarrel = path.basename(file) === BARREL;
64
+ // Kimlik mutlak yol — çoklu components kökünde göreli ad çakışmasın.
65
+ const fileId = isBarrel ? BARREL : file.split(path.sep).join("/");
67
66
  const module = await import(pathToFileURL(file).href);
68
67
 
69
68
  for (const [name, value] of Object.entries(module)) {
70
69
  if (name === "default") continue;
71
70
 
72
71
  const previous = origin.get(name);
73
- if (previous && previous !== BARREL && previous !== relative) {
74
- console.warn(
75
- `[components] '${name}' is defined twice: ${previous} and ${relative} — the second one wins.`,
72
+ // Barrel üzerine yazmak bilinçli; iki gerçek bileşen dosyası çakışması hata.
73
+ if (previous && previous !== BARREL && previous !== fileId) {
74
+ throw new Error(
75
+ `[components] '${name}' is defined twice: ${previous} and ${fileId}`,
76
76
  );
77
77
  }
78
78
 
79
79
  components[name] = value;
80
- origin.set(name, relative);
80
+ origin.set(name, fileId);
81
81
  }
82
82
  }
83
+ }
84
+
85
+ /**
86
+ * @param {string | string[]} dirs Tek dizin veya çoklu kök (feature/shared).
87
+ * @returns {Promise<Record<string, unknown>>}
88
+ */
89
+ export async function loadComponents(dirs) {
90
+ /** @type {Record<string, unknown>} */
91
+ const components = {};
92
+ /** @type {Map<string, string>} */
93
+ const origin = new Map();
94
+
95
+ const list = Array.isArray(dirs) ? dirs : [dirs];
96
+ for (const dir of list) {
97
+ await loadDir(dir, components, origin);
98
+ }
83
99
 
84
100
  return components;
85
101
  }