Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix duplicate controllers in manifest on update #132

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/stimulus/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ module Stimulus::Manifest
extend self

def generate_from(controllers_path)
extract_controllers_from(controllers_path).collect do |controller_path|
manifest = extract_controllers_from(controllers_path).collect do |controller_path|
import_and_register_controller(controllers_path, controller_path)
end

manifest.uniq
end

def import_and_register_controller(controllers_path, controller_path)
Expand Down
15 changes: 15 additions & 0 deletions test/fixtures/controllers/hello_controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// hello_controller.ts
import { Controller } from "stimulus";

export default class extends Controller {
static targets = ["name", "output"];

declare readonly nameTarget: HTMLInputElement;
declare readonly outputTarget: HTMLElement;

greet() {
this.outputTarget.textContent =
`Hello, ${this.nameTarget.value}!`
}

}
3 changes: 3 additions & 0 deletions test/manifest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class Stimulus::Manifest::Test < ActiveSupport::TestCase
assert_includes manifest, 'import HelloController from "./hello_controller"'
assert_includes manifest, 'application.register("hello", HelloController)'

assert_equal 1, manifest.scan('import HelloController from "./hello_controller"').length
assert_equal 1, manifest.scan('application.register("hello", HelloController').length

# CoffeeScript controller
assert_includes manifest, 'import CoffeeController from "./coffee_controller"'
assert_includes manifest, 'application.register("coffee", CoffeeController)'
Expand Down