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 +4 -4
- data/lib/react_manifest/logging.rb +1 -1
- data/lib/react_manifest/railtie.rb +3 -0
- data/lib/react_manifest/version.rb +1 -1
- data/lib/react_manifest/watcher.rb +50 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1331513cb5939f583960098fa86106a9901a0b3ef126b64f5ac9ae545a51f930
|
|
4
|
+
data.tar.gz: f89ef2eff49327f1e4a4a3aed0657167d5dacabd0bae3735a1a4744c0ca45332
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6fe469fdebbd0bb563f46c59e01c3931fbcf67485e8d0141cd9628f95969912716f42622454055f758c98e0a4e9482183f79a4a1c025c9e8a9b86a6690dd8f0c
|
|
7
|
+
data.tar.gz: 36fcaa4b86a562227966018d98355894526ada5f6744427749938dd64b21ed6e5cd4f390c08c309f4500201f220647fe868a7f223ede977fbbafc15960d5ed51
|
|
@@ -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)
|
|
@@ -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
|