react-manifest-rails 0.2.29 → 0.2.30

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8688e621b55d1a5b9db497668b4942fc97c8f4aad5f7778c7a7fc4a412990d04
4
- data.tar.gz: c46872893e465f9684c68688a8f8ca02d361afd7bfa8421eb1b69b0180f8c3d9
3
+ metadata.gz: 1331513cb5939f583960098fa86106a9901a0b3ef126b64f5ac9ae545a51f930
4
+ data.tar.gz: f89ef2eff49327f1e4a4a3aed0657167d5dacabd0bae3735a1a4744c0ca45332
5
5
  SHA512:
6
- metadata.gz: 76a4b4aed865531470d641be4bb0d6608d30410d66463aad17e71b37a73acafe2fb4a825c5f3f89c0bc5e6a91d7016396699572d575950dca71a242378cbc6f3
7
- data.tar.gz: 2bbd77ad7db859306d6cfdb6a75a476bfca219b1e22cf0b3aa54bd12f3c42d8a441c35a1e07dbb4e5a0c3c198b968683a15f814fd64bf59a55a91b1ca3d2b9d1
6
+ metadata.gz: 6fe469fdebbd0bb563f46c59e01c3931fbcf67485e8d0141cd9628f95969912716f42622454055f758c98e0a4e9482183f79a4a1c025c9e8a9b86a6690dd8f0c
7
+ data.tar.gz: 36fcaa4b86a562227966018d98355894526ada5f6744427749938dd64b21ed6e5cd4f390c08c309f4500201f220647fe868a7f223ede977fbbafc15960d5ed51
@@ -8,7 +8,7 @@ module ReactManifest
8
8
 
9
9
  def log_info(message)
10
10
  full = "[ReactManifest] #{message}"
11
- Rails.logger.info(full)
11
+ Rails.logger.debug(full)
12
12
  $stdout.puts(full) if stdout_logging_needed?
13
13
  end
14
14
 
@@ -9,6 +9,7 @@ module ReactManifest
9
9
  # ----------------------------------------------------------------
10
10
  initializer "react_manifest.ensure_manifests", after: :load_config_initializers do
11
11
  next unless Rails.env.development?
12
+ next if defined?(Rails::Console)
12
13
 
13
14
  config = ReactManifest.configuration
14
15
 
@@ -60,6 +61,8 @@ module ReactManifest
60
61
  # Start the file watcher in development
61
62
  # ----------------------------------------------------------------
62
63
  initializer "react_manifest.start_watcher" do
64
+ next if defined?(Rails::Console)
65
+
63
66
  if Rails.env.development? && !ReactManifest::Watcher.running?
64
67
  begin
65
68
  ReactManifest::Watcher.start(ReactManifest.configuration)
@@ -1,3 +1,3 @@
1
1
  module ReactManifest
2
- VERSION = "0.2.29".freeze
2
+ VERSION = "0.2.30".freeze
3
3
  end
@@ -14,6 +14,7 @@ module ReactManifest
14
14
  # additional regeneration is queued (not one per file event).
15
15
  module Watcher
16
16
  DEBOUNCE_SECONDS = 0.3
17
+ BRANCH_SWITCH_COOLDOWN = 3
17
18
 
18
19
  class << self
19
20
  include ReactManifest::Logging
@@ -35,6 +36,9 @@ module ReactManifest
35
36
  end
36
37
 
37
38
  @regen_mutex = Mutex.new
39
+ @git_dir = detect_git_dir
40
+ @last_git_head = read_git_head
41
+ @branch_switch_until = nil
38
42
 
39
43
  log_info "Watching #{root.sub("#{Rails.root}/", '')} for changes..."
40
44
 
@@ -73,15 +77,61 @@ module ReactManifest
73
77
  @regen_thread = nil
74
78
  @regen_pending = false
75
79
  @regen_mutex = nil
80
+ @git_dir = nil
81
+ @last_git_head = nil
82
+ @branch_switch_until = nil
76
83
  end
77
84
 
78
85
  private
79
86
 
80
87
  def handle_file_changes(modified, added, removed, config)
88
+ if branch_switch_detected?
89
+ log_info "Branch change detected — skipping regeneration"
90
+ return
91
+ end
92
+
81
93
  (modified + added + removed).each { |f| Scanner.invalidate(f) }
82
94
  schedule_regeneration(config)
83
95
  end
84
96
 
97
+ def branch_switch_detected?
98
+ return false unless @git_dir
99
+
100
+ return true if @branch_switch_until && Time.now < @branch_switch_until
101
+
102
+ current_head = read_git_head
103
+ return false unless current_head && @last_git_head
104
+
105
+ if current_head != @last_git_head
106
+ @last_git_head = current_head
107
+ @branch_switch_until = Time.now + BRANCH_SWITCH_COOLDOWN
108
+ return true
109
+ end
110
+
111
+ false
112
+ end
113
+
114
+ def detect_git_dir
115
+ git_path = File.join(Rails.root.to_s, ".git")
116
+ if File.file?(git_path)
117
+ content = File.read(git_path).strip
118
+ return content.sub("gitdir: ", "").strip if content.start_with?("gitdir: ")
119
+ elsif File.directory?(git_path)
120
+ return git_path
121
+ end
122
+ nil
123
+ rescue StandardError
124
+ nil
125
+ end
126
+
127
+ def read_git_head
128
+ return nil unless @git_dir
129
+
130
+ File.read(File.join(@git_dir, "HEAD")).strip
131
+ rescue StandardError
132
+ nil
133
+ end
134
+
85
135
  # Schedule a regeneration on the background thread. Coalesces rapid
86
136
  # back-to-back file events: if the regen thread is already running,
87
137
  # we just set @regen_pending and return immediately so the listen
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react-manifest-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.29
4
+ version: 0.2.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Noonan