Sha256: 3eed4260b07b4ebe2ad6a039d7066d4687dc3c132fc9af1ffce29f4eb9a8fb6b

Contents?: true

Size: 1.17 KB

Versions: 11

Compression:

Stored size: 1.17 KB

Contents

require "webpacker/base_strategy"

module Webpacker
  class MtimeStrategy < BaseStrategy
    # Returns true if manifest file mtime is newer than the timestamp of the last modified watched file
    def fresh?
      manifest_mtime > latest_modified_timestamp
    end

    # Returns true if manifest file mtime is older than the timestamp of the last modified watched file
    def stale?
      !fresh?
    end

    private

      def manifest_mtime
        config.manifest_path.exist? ? File.mtime(config.manifest_path).to_i : 0
      end

      def latest_modified_timestamp
        if Rails.env.development?
          warn <<~MSG.strip
          Webpacker::Compiler - Slow setup for development

          Prepare JS assets with either:
          1. Running `bin/webpacker-dev-server`
          2. Set `compile` to false in webpacker.yml and run `bin/webpacker -w`
        MSG
        end

        root_path = Pathname.new(File.expand_path(config.root_path))
        expanded_paths = [*default_watched_paths].map do |path|
          root_path.join(path)
        end
        latest_modified = Dir[*expanded_paths].max_by { |f| File.mtime(f) }
        File.mtime(latest_modified).to_i
      end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
shakapacker-6.6.0 lib/webpacker/mtime_strategy.rb
shakapacker-6.5.6 lib/webpacker/mtime_strategy.rb
shakapacker-6.5.5 lib/webpacker/mtime_strategy.rb
shakapacker-6.5.4 lib/webpacker/mtime_strategy.rb
shakapacker-6.5.3 lib/webpacker/mtime_strategy.rb
shakapacker-6.5.2 lib/webpacker/mtime_strategy.rb
shakapacker-6.5.1 lib/webpacker/mtime_strategy.rb
shakapacker-6.5.0 lib/webpacker/mtime_strategy.rb
shakapacker-6.4.1 lib/webpacker/mtime_strategy.rb
shakapacker-6.4.0 lib/webpacker/mtime_strategy.rb
shakapacker-6.3.0 lib/webpacker/mtime_strategy.rb