Sha256: 64990f96ef0af625538c4d81e550368409947fb6405a7477debbce07ca81f317

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require 'importmap/packager'

module RailsAdmin
  class ImportmapFormatter
    attr_reader :packager

    def initialize(path = 'confing/importmap.rails_admin.rb')
      @packager = Importmap::Packager.new(path)
    end

    def format
      imports = packager.import("rails_admin@#{RailsAdmin::Version.js}", from: 'jspm.io')

      # Use ESM compatible version to work around https://github.com/cljsjs/packages/issues/1579
      imports['@popperjs/core'].gsub!('lib/index.js', 'dist/esm/popper.js')

      # Tidy up jQuery UI dependencies
      jquery_uis = imports.keys.filter { |key, _| key =~ /jquery-ui/ }
      imports['jquery-ui/'] = imports[jquery_uis.first].gsub(%r{(@[^/@]+)/[^@]+$}, '\1/')
      imports.reject! { |key, _| jquery_uis.include? key }

      pins = ['pin "rails_admin", preload: true', packager.pin_for('rails_admin/src/rails_admin/base', imports.delete('rails_admin'))]
      (pins + imports.map { |package, url| packager.pin_for(package, url) }).join("\n")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rails_admin-3.1.4 lib/generators/rails_admin/importmap_formatter.rb
rails_admin-3.1.3 lib/generators/rails_admin/importmap_formatter.rb
rails_admin-3.1.2 lib/generators/rails_admin/importmap_formatter.rb