Class: EmberCli::PathSet

Inherits:
Object
  • Object
show all
Defined in:
lib/ember_cli/path_set.rb

Constant Summary collapse

PACKAGE_MANAGERS =
%i[npm yarn pnpm].freeze
VITE_CONFIG_FILES =

Every name Vite resolves its configuration file from. An application that keeps its configuration under any of them is Vite-based.

%w[
  vite.config.js
  vite.config.mjs
  vite.config.cjs
  vite.config.ts
  vite.config.mts
  vite.config.cts
].freeze
INSTALL_INSTRUCTIONS =

npm ships with NodeJS, so it has no installation instructions of its own to point at when its executable is missing.

{
  yarn: "https://yarnpkg.com/lang/en/docs/install/",
  pnpm: "https://pnpm.io/installation",
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(app:, rails_root:, ember_cli_root:, environment:) ⇒ PathSet

Returns a new instance of PathSet.



25
26
27
28
29
30
# File 'lib/ember_cli/path_set.rb', line 25

def initialize(app:, rails_root:, ember_cli_root:, environment:)
  @app = app
  @rails_root = rails_root
  @environment = environment
  @ember_cli_root = ember_cli_root
end

Instance Method Details

#bower ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/ember_cli/path_set.rb', line 116

def bower
  @bower ||= begin
    path_for_executable("bower").tap do |bower_path|
      if bower_json.exist? && (bower_path.blank? || !bower_path.executable?)
        fail DependencyError.new <<-MSG.strip_heredoc
            Bower is required by EmberCLI

            Install it with:

                $ npm install -g bower

        MSG
      end
    end
  end
end

#bower_components ⇒ Object



133
134
135
# File 'lib/ember_cli/path_set.rb', line 133

def bower_components
  @bower_components ||= root.join("bower_components")
end

#bower_json ⇒ Object



62
63
64
# File 'lib/ember_cli/path_set.rb', line 62

def bower_json
  root.join("bower.json")
end

#build_error_file ⇒ Object



112
113
114
# File 'lib/ember_cli/path_set.rb', line 112

def build_error_file
  @build_error_file ||= tmp.join("error.txt")
end

#bundler ⇒ Object



202
203
204
# File 'lib/ember_cli/path_set.rb', line 202

def bundler
  @bundler ||= path_for_executable("bundler")
end

#cached_directories ⇒ Object



206
207
208
209
210
211
# File 'lib/ember_cli/path_set.rb', line 206

def cached_directories
  [
    node_modules,
    (bower_components if bower_json.exist?),
  ].compact
end

#dist ⇒ Object



50
51
52
# File 'lib/ember_cli/path_set.rb', line 50

def dist
  @dist ||= ember_cli_root.join("apps", app_name).tap(&:mkpath)
end

#ember ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ember_cli/path_set.rb', line 72

def ember
  @ember ||= begin
    root.join("node_modules", "ember-cli", "bin", "ember").tap do |path|
      unless path.executable?
        fail DependencyError.new <<-MSG.strip_heredoc
          No `ember-cli` executable found for `#{app_name}`.

          Install it:

              $ cd #{root}
              $ #{package_manager} install

        MSG
      end
    end
  end
end

#gemfile ⇒ Object



54
55
56
# File 'lib/ember_cli/path_set.rb', line 54

def gemfile
  @gemfile ||= root.join("Gemfile")
end

#lockfile ⇒ Object



108
109
110
# File 'lib/ember_cli/path_set.rb', line 108

def lockfile
  @lockfile ||= tmp.join("build.lock")
end

#log ⇒ Object



46
47
48
# File 'lib/ember_cli/path_set.rb', line 46

def log
  @log ||= logs.join("ember-#{app_name}.#{environment}.log")
end

#node_modules ⇒ Object



153
154
155
# File 'lib/ember_cli/path_set.rb', line 153

def node_modules
  @node_modules ||= root.join("node_modules")
end

#npm ⇒ Object



137
138
139
# File 'lib/ember_cli/path_set.rb', line 137

def npm
  @npm ||= path_for_executable("npm")
end

#package_json ⇒ Object



58
59
60
# File 'lib/ember_cli/path_set.rb', line 58

def package_json
  @package_json ||= root.join("package.json")
end

#package_manager ⇒ Object

The package manager that installs the application's NodeJS dependencies: the one the package_manager option names, else the one whose executable a yarn_path or pnpm_path option names, else npm. The deprecated yarn: true still selects yarn, with a warning.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/ember_cli/path_set.rb', line 161

def package_manager
  @package_manager ||= begin
    requested = app_options[:package_manager]

    if requested.present?
      requested.to_s.to_sym.tap do |name|
        unless PACKAGE_MANAGERS.include?(name)
          fail ArgumentError,
            "Unsupported package manager #{requested.inspect} for " \
            "`#{app_name}`; use one of #{PACKAGE_MANAGERS.inspect}"
        end
      end
    elsif app_options[:yarn].present?
      EmberCli.deprecator.warn(
        "The `yarn` option of the `#{app_name}` Ember application is " \
        "deprecated; configure it with `package_manager: :yarn` instead",
      )

      :yarn
    elsif app_options[:yarn_path].present?
      :yarn
    elsif app_options[:pnpm_path].present?
      :pnpm
    else
      :npm
    end
  end
end

#pnpm ⇒ Object



147
148
149
150
151
# File 'lib/ember_cli/path_set.rb', line 147

def pnpm
  if pnpm?
    @pnpm ||= package_manager_executable(:pnpm)
  end
end

#pnpm? ⇒ Boolean

Returns:

  • (Boolean)


194
195
196
# File 'lib/ember_cli/path_set.rb', line 194

def pnpm?
  package_manager == :pnpm
end

#root ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/ember_cli/path_set.rb', line 32

def root
  path = app_options.fetch(:path){ default_root }
  pathname = Pathname.new(path)
  if pathname.absolute?
    pathname
  else
    rails_root.join(path)
  end
end

#tee ⇒ Object



198
199
200
# File 'lib/ember_cli/path_set.rb', line 198

def tee
  @tee ||= path_for_executable("tee")
end

#tmp ⇒ Object



42
43
44
# File 'lib/ember_cli/path_set.rb', line 42

def tmp
  @tmp ||= root.join("tmp").tap(&:mkpath)
end

#vite ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/ember_cli/path_set.rb', line 90

def vite
  @vite ||= begin
    root.join("node_modules", ".bin", "vite").tap do |path|
      unless path.executable?
        fail DependencyError.new <<-MSG.strip_heredoc
          No `vite` executable found for `#{app_name}`.

          Install it:

              $ cd #{root}
              $ #{package_manager} install

        MSG
      end
    end
  end
end

#vite? ⇒ Boolean

Apps generated with the Vite-based blueprint (ember-cli >= 6.8) ship a Vite config file at their root.

Returns:

  • (Boolean)


68
69
70
# File 'lib/ember_cli/path_set.rb', line 68

def vite?
  VITE_CONFIG_FILES.any? { |config| root.join(config).exist? }
end

#yarn ⇒ Object



141
142
143
144
145
# File 'lib/ember_cli/path_set.rb', line 141

def yarn
  if yarn?
    @yarn ||= package_manager_executable(:yarn)
  end
end

#yarn? ⇒ Boolean

Returns:

  • (Boolean)


190
191
192
# File 'lib/ember_cli/path_set.rb', line 190

def yarn?
  package_manager == :yarn
end