Class: Proscenium::Resolver

Inherits:
ActiveSupport::CurrentAttributes
  • Object
show all
Defined in:
lib/proscenium/resolver.rb

Class Method Summary collapse

Class Method Details

.resolve(path) ⇒ String

Resolve the given ‘path` to a fully qualified URL path.

Parameters:

  • path (String)

    URL path, file system path, or bare specifier (ie. NPM package).

Returns:

  • (String)

    URL path.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/proscenium/resolver.rb', line 14

def self.resolve(path)
  self.resolved ||= {}

  if path.start_with?('./', '../')
    raise ArgumentError, '`path` must be an absolute file system or URL path'
  end

  self.resolved[path] ||= if (gem = BundledGems.paths.find { |_, v| path.start_with? "#{v}/" })
                            # If the path is a rubygem, and it is installed with npm via the
                            # @rubygems scope, then resolve the path to the symlinked location
                            # in node_modules.
                            # npm_path = Rails.root.join("node_modules/@rubygems/#{gem.first}")
                            # if npm_path.symlink?
                            #   npm_path.realpath.join(path.sub(/^#{gem.last}/, '.')).to_s
                            #           .delete_prefix(Rails.root.to_s)
                            # else
                            path.sub(/^#{gem.last}/, "/node_modules/@rubygems/#{gem.first}")
                            # end
                          elsif path.start_with?("#{Rails.root}/")
                            path.delete_prefix Rails.root.to_s
                          else
                            Builder.resolve path
                          end
end