Module: Jekyll::Esm::Managers::Npm

Defined in:
lib/jekyll-esm/managers/npm.rb

Defined Under Namespace

Classes: Error

Class Method Summary collapse

Class Method Details

.add(package:, site:) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jekyll-esm/managers/npm.rb', line 18

def self.add(package:, site:)
  stdout, stderr, status = Open3.capture3(
    "npm install #{package}",
    chdir: File.expand_path(File.join(site.source, '/'))
  )

  if site.config.dig('esm', 'strict')
    runtime_error = stdout =~ /ERROR in|SyntaxError/

    raise Error, stderr if stderr.size > 0
    raise Error, stdout if !runtime_error.nil?
  end
end

.dist(config) ⇒ Object



14
15
16
# File 'lib/jekyll-esm/managers/npm.rb', line 14

def self.dist(config)
  config.dig('esm', 'dist') || location(config) || 'node_modules'
end

.location(config) ⇒ Object



10
11
12
# File 'lib/jekyll-esm/managers/npm.rb', line 10

def self.location(config)
  config.dig('esm', 'npm', 'dir') || 'node_modules'
end

.remove(packages:, site:) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jekyll-esm/managers/npm.rb', line 32

def self.remove(packages:, site:)
  stdout, stderr, status = Open3.capture3(
    "npm uninstall #{packages}",
    chdir: File.expand_path(File.join(site.source, '/'))
  )

  if site.config.dig('esm', 'strict')
    runtime_error = stdout =~ /ERROR in|SyntaxError/

    raise Error, stderr if stderr.size > 0
    raise Error, stdout if !runtime_error.nil?
  end
end