@cldmv/slothlet 2.4.0 → 2.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.
- package/dist/lib/modes/slothlet_eager.mjs +86 -11
- package/dist/lib/modes/slothlet_lazy.mjs +47 -10
- package/dist/slothlet.mjs +11 -5
- package/package.json +3 -3
- package/types/dist/lib/modes/slothlet_eager.d.mts.map +1 -1
- package/types/dist/lib/modes/slothlet_lazy.d.mts.map +1 -1
- package/types/dist/slothlet.d.mts.map +1 -1
|
@@ -38,23 +38,88 @@ export async function create(dir, rootLevel = true, maxDepth = Infinity, current
|
|
|
38
38
|
let rootDefaultFunction = null;
|
|
39
39
|
|
|
40
40
|
if (rootLevel) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
|
|
42
|
+
const moduleFiles = entries.filter((e) => this._shouldIncludeFile(e));
|
|
43
|
+
const defaultExportFiles = [];
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
for (const entry of moduleFiles) {
|
|
47
|
+
const ext = path.extname(entry.name);
|
|
48
|
+
const fileName = path.basename(entry.name, ext);
|
|
49
|
+
const mod = await this._loadSingleModule(path.join(dir, entry.name), true);
|
|
50
|
+
|
|
51
|
+
if (this.config.debug) {
|
|
52
|
+
console.log(`[DEBUG] First pass - ${fileName}: hasDefault=${mod && "default" in mod}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (mod && "default" in mod) {
|
|
56
|
+
defaultExportFiles.push({ entry, fileName, mod });
|
|
57
|
+
if (this.config.debug) {
|
|
58
|
+
console.log(`[DEBUG] Added ${fileName} to defaultExportFiles`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const hasMultipleDefaultExports = defaultExportFiles.length > 1;
|
|
63
|
+
|
|
64
|
+
if (this.config.debug) {
|
|
65
|
+
console.log(
|
|
66
|
+
`[DEBUG] Detection result: ${defaultExportFiles.length} default exports found, hasMultipleDefaultExports=${hasMultipleDefaultExports}`
|
|
67
|
+
);
|
|
68
|
+
console.log(
|
|
69
|
+
`[DEBUG] Default export files:`,
|
|
70
|
+
defaultExportFiles.map((f) => f.fileName)
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
for (const entry of moduleFiles) {
|
|
76
|
+
const ext = path.extname(entry.name);
|
|
77
|
+
const fileName = path.basename(entry.name, ext);
|
|
78
|
+
const apiKey = this._toApiKey(fileName);
|
|
79
|
+
const mod = await this._loadSingleModule(path.join(dir, entry.name), true);
|
|
80
|
+
|
|
81
|
+
if (mod && typeof mod.default === "function") {
|
|
82
|
+
if (hasMultipleDefaultExports) {
|
|
83
|
+
|
|
84
|
+
api[apiKey] = mod.default;
|
|
85
|
+
|
|
86
|
+
|
|
49
87
|
for (const [key, value] of Object.entries(mod)) {
|
|
50
|
-
if (key !== "default")
|
|
88
|
+
if (key !== "default") {
|
|
89
|
+
api[apiKey][key] = value;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (this.config.debug) {
|
|
94
|
+
console.log(`[DEBUG] Multi-default in eager mode: using filename '${apiKey}' for default export`);
|
|
51
95
|
}
|
|
52
96
|
} else {
|
|
53
|
-
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
if (this.config.debug) {
|
|
100
|
+
console.log(
|
|
101
|
+
`[DEBUG] Processing traditional default: hasMultipleDefaultExports=${hasMultipleDefaultExports}, rootDefaultFunction=${!!rootDefaultFunction}`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
if (!hasMultipleDefaultExports && !rootDefaultFunction) {
|
|
105
|
+
rootDefaultFunction = mod.default;
|
|
106
|
+
if (this.config.debug) {
|
|
107
|
+
console.log(`[DEBUG] Set rootDefaultFunction to:`, mod.default.name);
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
if (this.config.debug) {
|
|
111
|
+
console.log(`[DEBUG] Skipped setting rootDefaultFunction due to multi-default scenario`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
54
114
|
for (const [key, value] of Object.entries(mod)) {
|
|
55
|
-
|
|
115
|
+
if (key !== "default") api[key] = value;
|
|
56
116
|
}
|
|
57
117
|
}
|
|
118
|
+
} else {
|
|
119
|
+
api[apiKey] = mod;
|
|
120
|
+
for (const [key, value] of Object.entries(mod)) {
|
|
121
|
+
rootNamedExports[key] = value;
|
|
122
|
+
}
|
|
58
123
|
}
|
|
59
124
|
}
|
|
60
125
|
}
|
|
@@ -67,11 +132,21 @@ export async function create(dir, rootLevel = true, maxDepth = Infinity, current
|
|
|
67
132
|
}
|
|
68
133
|
|
|
69
134
|
let finalApi;
|
|
135
|
+
if (this.config.debug) {
|
|
136
|
+
console.log(`[DEBUG] Final assembly: rootDefaultFunction=${!!rootDefaultFunction}`);
|
|
137
|
+
console.log(`[DEBUG] API object keys before final assembly:`, Object.keys(api));
|
|
138
|
+
}
|
|
70
139
|
if (rootDefaultFunction) {
|
|
71
140
|
Object.assign(rootDefaultFunction, api);
|
|
72
141
|
finalApi = rootDefaultFunction;
|
|
142
|
+
if (this.config.debug) {
|
|
143
|
+
console.log(`[DEBUG] Applied root contributor pattern - final API is function`);
|
|
144
|
+
}
|
|
73
145
|
} else {
|
|
74
146
|
finalApi = api;
|
|
147
|
+
if (this.config.debug) {
|
|
148
|
+
console.log(`[DEBUG] No root function - final API is object`);
|
|
149
|
+
}
|
|
75
150
|
}
|
|
76
151
|
|
|
77
152
|
|
|
@@ -30,20 +30,57 @@ export async function create(dir, rootLevel = true, maxDepth = Infinity, current
|
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
if (rootLevel) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
|
|
34
|
+
const moduleFiles = entries.filter((e) => instance._shouldIncludeFile(e));
|
|
35
|
+
const defaultExportFiles = [];
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
for (const entry of moduleFiles) {
|
|
39
|
+
const ext = path.extname(entry.name);
|
|
40
|
+
const fileName = path.basename(entry.name, ext);
|
|
41
|
+
const mod = await instance._loadSingleModule(path.join(dir, entry.name), true);
|
|
42
|
+
|
|
43
|
+
if (mod && "default" in mod) {
|
|
44
|
+
defaultExportFiles.push({ entry, fileName, mod });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const hasMultipleDefaultExports = defaultExportFiles.length > 1;
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
for (const entry of moduleFiles) {
|
|
52
|
+
const ext = path.extname(entry.name);
|
|
53
|
+
const fileName = path.basename(entry.name, ext);
|
|
54
|
+
const apiKey = instance._toApiKey(fileName);
|
|
55
|
+
const mod = await instance._loadSingleModule(path.join(dir, entry.name), true);
|
|
56
|
+
|
|
57
|
+
if (mod && typeof mod.default === "function") {
|
|
58
|
+
if (hasMultipleDefaultExports) {
|
|
59
|
+
|
|
60
|
+
api[apiKey] = mod.default;
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
for (const [key, value] of Object.entries(mod)) {
|
|
64
|
+
if (key !== "default") {
|
|
65
|
+
api[apiKey][key] = value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (instance.config.debug) {
|
|
70
|
+
console.log(`[DEBUG] Multi-default in lazy mode: using filename '${apiKey}' for default export`);
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if (!hasMultipleDefaultExports && !rootDefaultFn) {
|
|
76
|
+
rootDefaultFn = mod.default;
|
|
77
|
+
}
|
|
41
78
|
for (const [k, v] of Object.entries(mod)) {
|
|
42
79
|
if (k !== "default") api[k] = v;
|
|
43
80
|
}
|
|
44
|
-
} else {
|
|
45
|
-
api[apiKey] = mod;
|
|
46
81
|
}
|
|
82
|
+
} else {
|
|
83
|
+
api[apiKey] = mod;
|
|
47
84
|
}
|
|
48
85
|
}
|
|
49
86
|
}
|
package/dist/slothlet.mjs
CHANGED
|
@@ -420,21 +420,26 @@ const slothletObject = {
|
|
|
420
420
|
|
|
421
421
|
|
|
422
422
|
const categoryModules = {};
|
|
423
|
-
|
|
423
|
+
|
|
424
424
|
|
|
425
425
|
const defaultExportFiles = [];
|
|
426
426
|
for (const file of moduleFiles) {
|
|
427
427
|
const moduleExt = path.extname(file.name);
|
|
428
428
|
const moduleName = this._toApiKey(path.basename(file.name, moduleExt));
|
|
429
429
|
const tempMod = await this._loadSingleModule(path.join(categoryPath, file.name));
|
|
430
|
+
|
|
430
431
|
|
|
431
|
-
|
|
432
|
+
|
|
433
|
+
if (tempMod && tempMod.__slothletDefault === true) {
|
|
432
434
|
defaultExportFiles.push({ file, moduleName, mod: tempMod });
|
|
435
|
+
if (this.config.debug) {
|
|
436
|
+
console.log(`[DEBUG] Found default export in ${file.name}`);
|
|
437
|
+
}
|
|
433
438
|
}
|
|
434
439
|
}
|
|
435
|
-
|
|
440
|
+
|
|
436
441
|
const hasMultipleDefaultExports = defaultExportFiles.length > 1;
|
|
437
|
-
|
|
442
|
+
|
|
438
443
|
for (const file of moduleFiles) {
|
|
439
444
|
const moduleExt = path.extname(file.name);
|
|
440
445
|
const moduleName = this._toApiKey(path.basename(file.name, moduleExt));
|
|
@@ -461,7 +466,7 @@ const slothletObject = {
|
|
|
461
466
|
} else if (typeof mod === "function") {
|
|
462
467
|
|
|
463
468
|
let apiKey;
|
|
464
|
-
if (hasMultipleDefaultExports &&
|
|
469
|
+
if (hasMultipleDefaultExports && mod.__slothletDefault === true) {
|
|
465
470
|
|
|
466
471
|
apiKey = moduleName;
|
|
467
472
|
try {
|
|
@@ -617,6 +622,7 @@ const slothletObject = {
|
|
|
617
622
|
}
|
|
618
623
|
}
|
|
619
624
|
}
|
|
625
|
+
|
|
620
626
|
return categoryModules;
|
|
621
627
|
},
|
|
622
628
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cldmv/slothlet",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"moduleVersions": {
|
|
5
|
-
"lazy": "1.
|
|
6
|
-
"eager": "1.
|
|
5
|
+
"lazy": "1.1.0",
|
|
6
|
+
"eager": "1.1.0"
|
|
7
7
|
},
|
|
8
8
|
"description": "Slothlet: Modular API Loader for Node.js. Lazy mode dynamically loads API modules and submodules only when accessed, supporting both lazy and eager loading.",
|
|
9
9
|
"main": "./index.cjs",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slothlet_eager.d.mts","sourceRoot":"","sources":["../../../../dist/lib/modes/slothlet_eager.mjs"],"names":[],"mappings":"AA2IA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAsDH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,4BAtBW,MAAM,cACN,OAAO,aACP,MAAM,iBACN,MAAM,GACJ,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"slothlet_eager.d.mts","sourceRoot":"","sources":["../../../../dist/lib/modes/slothlet_eager.mjs"],"names":[],"mappings":"AA2IA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAsDH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,4BAtBW,MAAM,cACN,OAAO,aACP,MAAM,iBACN,MAAM,GACJ,OAAO,CAAC,MAAM,CAAC,CAgJ3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slothlet_lazy.d.mts","sourceRoot":"","sources":["../../../../dist/lib/modes/slothlet_lazy.mjs"],"names":[],"mappings":"AA6JA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,4BAvBW,MAAM,cACN,OAAO,aACP,MAAM,iBACN,MAAM,GACJ,OAAO,CAAC,WAAS,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"slothlet_lazy.d.mts","sourceRoot":"","sources":["../../../../dist/lib/modes/slothlet_lazy.mjs"],"names":[],"mappings":"AA6JA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,4BAvBW,MAAM,cACN,OAAO,aACP,MAAM,iBACN,MAAM,GACJ,OAAO,CAAC,WAAS,MAAM,CAAC,CA6GpC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slothlet.d.mts","sourceRoot":"","sources":["../../dist/slothlet.mjs"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"slothlet.d.mts","sourceRoot":"","sources":["../../dist/slothlet.mjs"],"names":[],"mappings":"AA86CA;;;;;;;;;GASG;AACH,kDARW,WAAS,MAAM,UACf,WAAS,MAAM,QAwCzB;AAz0CD;;;;;;;GAOG;AACH,mBAJU,MAAM,CAIO;AAEvB;;;;;GAKG;AACH,sBAJU,MAAM,CAIU;AAE1B;;;;;GAKG;AACH,wBAJU,MAAM,CAIY;;;;;;;;;UA4zCd,MAAM;;;;;;WAIN,OAAO;;;;;;;eAGP,MAAM;;;;;;;;YAIN,OAAO;;;;;;;;WAKP,MAAM;;;;;;;eAKN,MAAM;;;;;;cAIN,MAAM;;;;;;gBAGN,MAAM;;;;;;eAMjB;QAA8B,UAAU,GAA7B,OAAO;QACY,gBAAgB,GAAnC,OAAO;QACY,gBAAgB,GAAnC,OAAO;QACW,KAAK,GAClC;YAAqC,KAAK,GAA/B,MAAM,EAAE;YACkB,gBAAgB,GAA1C,MAAM,EAAE;YACkB,KAAK,GAA/B,MAAM,EAAE;YACkB,KAAK,GAA/B,MAAM,EAAE;SACrB;KAAA;;AAp2CD;;;;;;;;GAQG;AACH,mCAJW,eAAe,GACb,OAAO,CAAC,WAAS,MAAM,CAAC,CAiCpC"}
|