Skip to content

Commit

Permalink
feat: allow matching controllers without prefix (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timmitry authored Sep 12, 2022
1 parent e349b0d commit f49d190
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[Stimulus HMR plugin]: https://github.com/ElMassimo/vite-plugin-stimulus-hmr

## Unpublished

- Allow matching controllers without prefix in sidecar directories (fix #3).

## stimulus-vite-helpers 1.0.4 (2021-05-24)

- Fix regexp to avoid namespacing controllers incorrectly (fix #1).
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Application, Definition } from '@hotwired/stimulus'
import type { ImportedModules, Entry } from './types'

export const CONTROLLER_FILENAME_REGEX = /^(?:.*?(?:controllers|components)\/|\.?\.\/)?(.+)(?:[_-]controller\..+?)$/
export const CONTROLLER_FILENAME_REGEX = /^(?:.*?(?:controllers|components)\/|\.?\.\/)?(.+)(?:[/_-]controller\..+?)$/

export function registerControllers (application: Application, controllerModules: ImportedModules) {
application.load(definitionsFromGlob(controllerModules))
Expand Down
2 changes: 2 additions & 0 deletions tests/glob.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const withoutDefaultExport = { }

const modules = {
'../components/home_controller.js': mod,
'../components/page/controller.js': mod,
'../controllers/hello_controller.js': mod,
'../controllers/image/reveal_controller.js': mod,
'./controllers/dashboard_controller.ts': mod,
Expand All @@ -18,6 +19,7 @@ const modules = {
test('definitionsFromGlob', () => {
expect(definitionsFromGlob(modules)).toEqual([
{ identifier: 'home', controllerConstructor },
{ identifier: 'page', controllerConstructor },
{ identifier: 'hello', controllerConstructor },
{ identifier: 'image--reveal', controllerConstructor },
{ identifier: 'dashboard', controllerConstructor },
Expand Down

0 comments on commit f49d190

Please sign in to comment.