diff --git a/.changeset/clean-peas-wonder.md b/.changeset/clean-peas-wonder.md new file mode 100644 index 0000000..6805d1b --- /dev/null +++ b/.changeset/clean-peas-wonder.md @@ -0,0 +1,5 @@ +--- +'harmonix': patch +--- + +Prevent commands root dir from being categorized diff --git a/packages/harmonix/src/module.ts b/packages/harmonix/src/module.ts index 0af5631..1ee0b56 100644 --- a/packages/harmonix/src/module.ts +++ b/packages/harmonix/src/module.ts @@ -31,7 +31,7 @@ const handleChanges = debounce(async (harmonix: Harmonix, events: Event[]) => { for (const event of events) { const path = resolve(event.path) harmonix.logger.info( - `\u001B[38;2;75;67;238mhmr update\u001B[0m ${colors.dim(relative(harmonix.options.srcDir, path))}` + `\u001B[38;2;75;67;238mhmr ${event.type}\u001B[0m ${colors.dim(relative(harmonix.options.srcDir, path))}` ) if (event.type === 'delete') { diff --git a/packages/harmonix/src/runtime/internal/module.ts b/packages/harmonix/src/runtime/internal/module.ts index 59adae8..108a868 100644 --- a/packages/harmonix/src/runtime/internal/module.ts +++ b/packages/harmonix/src/runtime/internal/module.ts @@ -27,10 +27,9 @@ export const loadModule = async ( module.type === ModuleType.Command && harmonixOptions.categorization.inferFromPath ) { - const category = filename(dirname(path))! + const inferred = inferCategoryFromPath(filePath, harmonixOptions) - module.category ??= - harmonixOptions.categorization.categories[category] ?? category + module.category ??= inferred } if (module.type === ModuleType.Event) { @@ -98,3 +97,18 @@ export const disposeModule = async (harmonix: Harmonix, path: string) => { } } } + +const inferCategoryFromPath = ( + filePath: string, + harmonixOptions: HarmonixOptions +) => { + const parentDir = dirname(filePath) + + if (parentDir === harmonixOptions.dirs.commands) { + return undefined + } + + const category = filename(parentDir)! + + return harmonixOptions.categorization.categories[category] ?? category +}