elm-compiler 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/README.md +2 -1
- data/lib/elm/compiler/version.rb +1 -1
- data/lib/elm/compiler.rb +21 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28756a5b0cde783ca8b032103fe8c49fe31002f4c9a5cfa1b8f2645b867f63d7
|
4
|
+
data.tar.gz: 16cdc3ab15baa7995c9d2446cadbc4d1e37f744749c763b57c584b3b58cceb29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 966a4f9d92b274ba0dd678deb558174852d35c5050a6a4d49e85fdb86b28fcf382324533a3721b6067737885f0ba9114a45d7481428d0a226c75c199fe3adf1e
|
7
|
+
data.tar.gz: ead2697e36189e12694db5c227c69c72401b8987ab7793a2a7047e03edb2d360a74a0670cb2e6e031b5f388371101816e7e4fdb9f1c9a61b477a602a4436ebc7
|
data/.github/workflows/ci.yml
CHANGED
data/README.md
CHANGED
@@ -31,13 +31,14 @@ Or install it yourself as:
|
|
31
31
|
> NOTE: Make sure [Elm](http://elm-lang.org/install) is installed. If the `elm` executable can't be found in the current `PATH` or via the `elm_path` option, the exception `Elm::Compiler::ExecutableNotFound` will be thrown.
|
32
32
|
|
33
33
|
```ruby
|
34
|
-
Elm::Compiler.compile(elm_files, output_path: nil, elm_path: nil, debug: false)
|
34
|
+
Elm::Compiler.compile(elm_files, output_path: nil, elm_path: nil, debug: false, esm: false)
|
35
35
|
```
|
36
36
|
|
37
37
|
* `elm_files`: Accepts a single file path or an array of file paths.
|
38
38
|
* `output_path`: Path to the output file. If left blank, the compiled Javascript will be returned as a string.
|
39
39
|
* `elm_path`: Path to the `elm` executable. If left blank, the executable will be looked up in the current `PATH`, if that cannot be found, it will download elm to /tmp/elm-0.19.1 and use that.
|
40
40
|
* `debug`: Whether or not to compile in debug mode. Default is false.
|
41
|
+
* `esm`: Whether or not to rewrite the compilation result into ESM format. Default is false. Can also be set on a global basis by `Elm::Compiler.elm = true`
|
41
42
|
|
42
43
|
|
43
44
|
## Examples
|
data/lib/elm/compiler/version.rb
CHANGED
data/lib/elm/compiler.rb
CHANGED
@@ -10,25 +10,27 @@ module Elm
|
|
10
10
|
@elm_path ||= elm_from_env_path || our_elm_path
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
attr_accessor :esm
|
14
|
+
|
15
|
+
def compile(elm_files, output_path: nil, elm_path: self.elm_path, debug: false, esm: self.esm)
|
14
16
|
fail ExecutableNotFound unless elm_executable_exists?(elm_path)
|
15
17
|
if output_path
|
16
|
-
elm_make(elm_path, elm_files, output_path, debug)
|
18
|
+
elm_make(elm_path, elm_files, output_path, debug, esm)
|
17
19
|
else
|
18
|
-
compile_to_string(elm_path, elm_files, debug)
|
20
|
+
compile_to_string(elm_path, elm_files, debug, esm)
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
24
|
private
|
23
25
|
|
24
|
-
def compile_to_string(elm_path, elm_files, debug)
|
26
|
+
def compile_to_string(elm_path, elm_files, debug, esm)
|
25
27
|
Tempfile.open(['elm', '.js']) do |tempfile|
|
26
|
-
elm_make(elm_path, elm_files, tempfile.path, debug)
|
28
|
+
elm_make(elm_path, elm_files, tempfile.path, debug, esm)
|
27
29
|
return File.read tempfile.path
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
|
-
def elm_make(elm_path, elm_files, output_path, debug)
|
33
|
+
def elm_make(elm_path, elm_files, output_path, debug, esm)
|
32
34
|
args = [
|
33
35
|
{"LANG" => "en_US.UTF8" },
|
34
36
|
elm_path,
|
@@ -40,6 +42,19 @@ module Elm
|
|
40
42
|
Open3.popen3(*args) do |_stdin, _stdout, stderr, wait_thr|
|
41
43
|
fail CompileError, stderr.gets(nil) if wait_thr.value.exitstatus != 0
|
42
44
|
end
|
45
|
+
convert_file_to_esm!(output_path) if esm
|
46
|
+
end
|
47
|
+
|
48
|
+
def convert_file_to_esm!(path)
|
49
|
+
contents = File.read(path)
|
50
|
+
exports = contents[/^\s*_Platform_export\((.*)\)\;\n?\}\(this\)\)\;/, 1]
|
51
|
+
contents.gsub!(/\(function\s*\(scope\)\s*\{$/, '// -- \1')
|
52
|
+
contents.gsub!(/['"]use strict['"];$/, '// -- \1')
|
53
|
+
contents.gsub!(/function _Platform_export(.*?)\}\n/, '/*\n\1\n*/')
|
54
|
+
contents.gsub!(/function _Platform_mergeExports(.*?)\}\n\s*}/, '/*\n\1\n*/')
|
55
|
+
contents.gsub!(/^\s*_Platform_export\((.*)\)\;\n?}\(this\)\)\;/, '/*\n\1\n*/')
|
56
|
+
contents << "\nexport default #{exports};"
|
57
|
+
File.write(path, contents)
|
43
58
|
end
|
44
59
|
|
45
60
|
def elm_executable_exists?(path)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elm-compiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Bonetti
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
|
-
rubygems_version: 3.
|
97
|
+
rubygems_version: 3.2.32
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: Ruby wrapper for the Elm compiler
|