46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/esbuild/flags.rb', line 46
def flags_for_build_options(options)
flags = []
options = options.dup
push_log_flags(flags, options, :info)
push_common_flags(flags, options)
get_flag(options, :source_map, STRING_OR_BOOL) { |v| flags << "--source-map#{v == true ? "" : "=#{v}"}" if v }
get_flag(options, :bundle, BOOL) { |v| flags << "--bundle" if v }
watch_mode = nil
get_flag(options, :watch, BOOL_OR_OBJECT) do |v|
break unless v
flags << "--watch"
watch_mode = {}
unless v == true
watch_options = v.dup
get_flag(watch_options, :on_rebuild, Proc) { |v| watch_mode[:on_rebuild] = v }
raise ArgumentError, "Invalid option in watch options: #{watch_options.keys.first}" unless watch_options.empty?
end
end
get_flag(options, :splitting, BOOL) { |v| flags << "--splitting" if v }
get_flag(options, :preserve_symlinks, BOOL) { |v| flags << "--preserve-symlinks" if v }
get_flag(options, :metafile, BOOL) { |v| flags << "--metafile" if v }
get_flag(options, :outfile, String) { |v| flags << "--outfile=#{v}" }
get_flag(options, :outdir, String) { |v| flags << "--outdir=#{v}" }
get_flag(options, :outbase, String) { |v| flags << "--outbase=#{v}" }
get_flag(options, :platform, String) { |v| flags << "--platform=#{v}" }
get_flag(options, :tsconfig, String) { |v| flags << "--tsconfig=#{v}" }
get_flag(options, :resolve_extensions, Array) do |v|
exts = v.map do |ext|
ext = ext.to_s
raise ArgumentError, "Invalid resolve extension: #{ext}" if ext.include?(",")
ext
end
flags << "--resolve-extensions=#{exts.join(",")}"
end
get_flag(options, :public_path, String) { |v| flags << "--public-path=#{v}" }
get_flag(options, :entry_names, String) { |v| flags << "--entry-names=#{v}" }
get_flag(options, :chunk_names, String) { |v| flags << "--chunk-names=#{v}" }
get_flag(options, :asset_names, String) { |v| flags << "--asset-names=#{v}" }
get_flag(options, :main_fields, Array) do |v|
values = v.map do |value|
value = value.to_s
raise ArgumentError, "Invalid main field: #{value}" if value.include?(",")
value
end
flags << "--main-fields=#{values.join(",")}"
end
get_flag(options, :conditions, Array) do |v|
values = v.map do |value|
value = value.to_s
raise ArgumentError, "Invalid condition: #{value}" if value.include?(",")
value
end
flags << "--conditions=#{values.join(",")}"
end
get_flag(options, :external, Array) { |v| v.each { |name| flags << "--external:#{name}" } }
get_flag(options, :banner, Hash) do |v|
v.each do |type, value|
type = type.to_s
raise ArgumentError, "Invalid banner file type: #{type}" if type.include?("=")
flags << "--banner:#{type}=#{value}"
end
end
get_flag(options, :footer, Hash) do |v|
v.each do |type, value|
type = type.to_s
raise ArgumentError, "Invalid footer file type: #{type}" if type.include?("=")
flags << "--footer:#{type}=#{value}"
end
end
get_flag(options, :inject, Array) { |v| v.each { |name| flags << "--inject:#{name}" } }
get_flag(options, :loader, Hash) do |v|
v.each do |ext, loader|
ext = ext.to_s
raise ArgumentError, "Invalid loader extension: #{ext}" if ext.include?("=")
flags << "--loader:#{ext}=#{loader}"
end
end
get_flag(options, :out_extension, Hash) do |v|
v.each do |ext, extension|
ext = ext.to_s
raise ArgumentError, "Invalid out extension: #{ext}" if ext.include?("=")
flags << "--out-extension:#{ext}=#{extension}"
end
end
entries = []
get_flag(options, :entry_points, ARRAY_OR_OBJECT) do |v|
if v.is_a?(Array)
v.each { |entry_point| entries << ["", entry_point] }
else
v.each { |key, entry_point| entries << [key.to_s, entry_point.to_s] }
end
end
stdin_resolve_dir = nil
stdin_contents = nil
get_flag(options, :stdin, Hash) do |v|
stdin_options = v.dup
stdin_contents = ""
get_flag(stdin_options, :contents, String) { |v| stdin_contents = v }
get_flag(stdin_options, :resolve_dir, String) { |v| stdin_resolve_dir = v }
get_flag(stdin_options, :sourcefile, String) { |v| flags << "--sourcefile=#{v}" }
get_flag(stdin_options, :loader, String) { |v| flags << "--loader=#{v}" }
raise ArgumentError, "Invalid option in stdin options: #{stdin_options.keys.first}" unless stdin_options.empty?
end
node_paths = []
get_flag(options, :node_paths, Array) { |v| v.each { |path| node_paths << path.to_s } }
write = true
get_flag(options, :write, BOOL) { |v| write = v }
abs_working_dir = nil
get_flag(options, :abs_working_dir, String) { |v| abs_working_dir = v }
incremental = false
get_flag(options, :incremental, BOOL) { |v| incremental = v }
raise ArgumentError, "Invalid option in build() call: #{options.keys.first}" unless options.empty?
{
entries: entries,
flags: flags,
write: write,
stdin_contents: stdin_contents,
stdin_resolve_dir: stdin_resolve_dir,
abs_working_dir: abs_working_dir,
incremental: incremental,
node_paths: node_paths,
watch: watch_mode
}
end
|