Module: Language::Node::Shebang

Defined in:
language/node.rb

Overview

Mixin module for Formula adding shebang rewrite features.

Constant Summary collapse

NODE_SHEBANG_REGEX =

A regex to match potential shebang permutations.

%r{^#! ?/usr/bin/(?:env )?node( |$)}
NODE_SHEBANG_MAX_LENGTH =

The length of the longest shebang matching SHEBANG_REGEX.

"#! /usr/bin/env node ".length

Class Method Summary collapse

Class Method Details

.detected_node_shebang(formula = self) ⇒ Utils::Shebang::RewriteInfo

Parameters:

  • formula (T.untyped) (defaults to: self)

Returns:

Raises:



111
112
113
114
115
116
117
# File 'language/node.rb', line 111

def detected_node_shebang(formula = self)
  node_deps = formula.deps.map(&:name).grep(/^node(@.+)?$/)
  raise ShebangDetectionError.new("Node", "formula does not depend on Node") if node_deps.empty?
  raise ShebangDetectionError.new("Node", "formula has multiple Node dependencies") if node_deps.length > 1

  node_shebang_rewrite_info(Formula[node_deps.first].opt_bin/"node")
end