@hkdigital/lib-core 0.5.66 → 0.5.67
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/package.json +1 -1
- package/scripts/validate-imports.mjs +15 -4
package/package.json
CHANGED
|
@@ -287,20 +287,31 @@ async function validateFile(filePath) {
|
|
|
287
287
|
if (!hasAnyExtension) {
|
|
288
288
|
// Check if it's a directory with index.js
|
|
289
289
|
if (await isDirectoryWithIndex(fsPath)) {
|
|
290
|
-
//
|
|
291
|
-
//
|
|
292
|
-
|
|
290
|
+
// For $lib/ imports, suggest creating a barrel export file
|
|
291
|
+
// following the library pattern: folder → matching .js file
|
|
292
|
+
if (importPath.startsWith('$lib/')) {
|
|
293
|
+
errors.push(
|
|
294
|
+
`${relativePath}:${lineNum}\n` +
|
|
295
|
+
` from '${importPath}'\n` +
|
|
296
|
+
` => Create export file: ${importPath}.js (remove index.js)`
|
|
297
|
+
);
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
293
300
|
|
|
301
|
+
// For relative imports with parent navigation,
|
|
302
|
+
// suggest creating export file
|
|
303
|
+
const wouldBeParentNavigation = importPath.match(/^\.\.\//);
|
|
294
304
|
if (wouldBeParentNavigation) {
|
|
295
305
|
errors.push(
|
|
296
306
|
`${relativePath}:${lineNum}\n` +
|
|
297
307
|
` from '${importPath}'\n` +
|
|
298
|
-
` => Create export file
|
|
308
|
+
` => Create export file: ${importPath}.js or ` +
|
|
299
309
|
`import specific file`
|
|
300
310
|
);
|
|
301
311
|
continue;
|
|
302
312
|
}
|
|
303
313
|
|
|
314
|
+
// For local relative imports (./path), suggest index.js
|
|
304
315
|
const suggestion = importPath.endsWith('/') ?
|
|
305
316
|
`${importPath}index.js` : `${importPath}/index.js`;
|
|
306
317
|
errors.push(
|