Skip to content

Commit 93dca72

Browse files
committed
Remove support for CommonJS and UMD modules output
ElixirScript now only supports ES Modules. The default output path has also been changed.
1 parent 83be891 commit 93dca72

File tree

12 files changed

+37
-227
lines changed

12 files changed

+37
-227
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77
## [Unreleased]
88

99
### Added
10-
- ElixirScript now has an FFI layer for interoperability with JavaScript. For more details, see documentation at `ElixirScript.FFI`
10+
- ElixirScript now has a Foreign Function Interface (FFI) for interoperability with JavaScript. For more details, see documentation at `ElixirScript.FFI`
1111
- `ElixirScript.JS.mutate/3`
1212
- `ElixirScript.JS.map_to_object/1`
1313

1414
### Changed
1515
- Compiler has been completely rewritten. ElixirScript now requires Erlang 20+ and Elixir 1.5+
1616
- `JS` module renamed to `ElixirScript.JS`
17+
- Default output path is now `priv/elixir_script/build`
18+
19+
### Removed
20+
- Support for CommonJS and UMD output formats has been removed. Output will be in ES module format
21+
- The `js_modules` option has been removed in favor of the new FFI
1722

1823
## [0.28.0] - 2017-06-11
1924

GettingStarted.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Adding Elixirscript to your mix project gives you the ability to add it to your
77
Add dependency to your deps in mix.exs:
88

99
``` elixir
10-
{:elixir_script, "~> 0.29"}
10+
{:elixir_script, "~> 0.30"}
1111
```
1212

1313
Elixirscript uses default output and module formats if options are not given. If you wish to change any or all options, add an `elixir_script` key to your project configuration.
14-
14+
1515
``` elixir
1616
def project do
1717
[
@@ -21,13 +21,7 @@ Elixirscript uses default output and module formats if options are not given. If
2121
deps: deps,
2222
elixir_script: [
2323
input: MyEntryModule,
24-
output: "priv/elixirscript/Elixir.App.js",
25-
format: :es,
26-
js_modules: [
27-
{React, "react"},
28-
{ReactDOM, "react-dom"},
29-
{Phoenix, "phoenix", default: false}
30-
]
24+
output: "priv/elixir_script/build/Elixir.App.js"
3125
],
3226
compilers: Mix.compilers ++ [:elixir_script]
3327
]
@@ -38,22 +32,24 @@ Available options are:
3832

3933
* `input`: The entry module(s) for your application or library
4034

41-
* `output`: The path of the generated JavaScript file. (defaults to `priv/elixirscript`)
35+
* `output`: The path of the generated JavaScript file. (defaults to `priv/elixir_script/build`)
4236

4337
If path ends in `.js` then that will be the name of the file. If a directory is given,
4438
file will be named `Elixir.App.js`
4539

46-
* `format`: The module format of generated JavaScript code. (defaults to `:es`). Choices are:    
47-
48-
* `:es` - ES Modules
4940

50-
* `:common` - CommonJS
41+
Now run `mix compile` and you should see a JavaScript file named `Elixir.App.js` in the `priv/elixir_script/build/` directory. ElixirScript outputs JavaScript in the ES Module format. If your browser supports it, you can include the output in a script tag with the type "module"
5142

52-
* `:umd` - UMD
43+
```html
44+
<script type="module">
45+
import Elixir from './Elixir.App.js'
46+
const myInitialArgs = []
5347
54-
* `js_modules`: A list of JavaScript imports to add. Each item must be 2-tuple or a 3-tuple. The third element is an optional keyword list of options:
48+
Elixir.start(Elixir.MyEntryModule, myInitialArgs)
49+
</script>
50+
```
5551

56-
* `default` - Defaults to true. Set to false if the imported module has no default export.
52+
If your browser does not yet support ES modules directly, use a tool such as [webpack](https://webpack.js.org/) or [brunch](http://brunch.io/) to convert it into something that can be used in the browser
5753

5854
### Macros
5955

lib/elixir_script/cli.ex

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ defmodule ElixirScript.CLI do
77
output: :string,
88
help: :boolean,
99
version: :boolean,
10-
watch: :boolean,
11-
format: :string
10+
watch: :boolean
1211
]
1312

1413
@aliases [
1514
o: :output,
1615
h: :help,
17-
v: :version,
18-
f: :format
16+
v: :version
1917
]
2018

2119
def parse_args(args) do
@@ -42,7 +40,6 @@ defmodule ElixirScript.CLI do
4240
<module> the entry module of your application
4341
4442
options:
45-
-f --format [format] module format of output. options: es (default), common, umd
4643
-o --output [path] places output at the given path.
4744
Can be a directory or filename.
4845
-v --version the current version number
@@ -70,8 +67,7 @@ defmodule ElixirScript.CLI do
7067
{watch, options} = Keyword.pop(options, :watch, false)
7168

7269
compile_opts = [
73-
output: Keyword.get(options, :output, :stdout),
74-
format: String.to_atom(Keyword.get(options, :format, "es"))
70+
output: Keyword.get(options, :output, :stdout)
7571
]
7672

7773
input = handle_input(input)

lib/elixir_script/compiler.ex

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,10 @@ defmodule ElixirScript.Compiler do
3434
defp build_compiler_options(opts, entry_modules) do
3535
default_options = Map.new
3636
|> Map.put(:output, Keyword.get(opts, :output))
37-
|> Map.put(:format, Keyword.get(opts, :format, :es))
37+
|> Map.put(:format, :es)
3838
|> Map.put(:entry_modules, entry_modules)
3939

4040
options = default_options
41-
Map.put(options, :module_formatter, get_module_formatter(options[:format]))
42-
end
43-
44-
defp get_module_formatter(:umd) do
45-
ElixirScript.ModuleSystems.UMD
46-
end
47-
48-
defp get_module_formatter(:common) do
49-
ElixirScript.ModuleSystems.Common
50-
end
51-
52-
defp get_module_formatter(_) do
53-
ElixirScript.ModuleSystems.ES
41+
Map.put(options, :module_formatter, ElixirScript.ModuleSystems.ES)
5442
end
5543
end

lib/elixir_script/module_systems/common.ex

Lines changed: 0 additions & 50 deletions
This file was deleted.

lib/elixir_script/module_systems/umd.ex

Lines changed: 0 additions & 106 deletions
This file was deleted.

lib/mix/tasks/compile.elixir_script.ex

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,10 @@ defmodule Mix.Tasks.Compile.ElixirScript do
2121
2222
Available options are:
2323
* `input`: The module or modules that are the entry to your application (required)
24-
* `output`: The path of the generated JavaScript file. (defaults to `priv/elixirscript`)
24+
* `output`: The path of the generated JavaScript file. (defaults to `priv/elixir_script/build`)
2525
2626
If path ends in `.js` then that will be the name of the file. If a directory is given,
2727
file will be named `Elixir.App.js`
28-
* `format`: The module format of generated JavaScript code. (defaults to `:es`).
29-
Choices are:
30-
* `:es` - ES Modules
31-
* `:common` - CommonJS
32-
* `:umd` - UMD
3328
3429
The mix compiler will also compile any dependencies that have the elixirscript compiler in its mix compilers as well
3530
"""
@@ -64,8 +59,7 @@ defmodule Mix.Tasks.Compile.ElixirScript do
6459
elixirscript_config = get_elixirscript_config()
6560
input = Keyword.fetch!(elixirscript_config, :input)
6661
opts = [
67-
output: Keyword.get(elixirscript_config, :output),
68-
format: Keyword.get(elixirscript_config, :format)
62+
output: Keyword.get(elixirscript_config, :output)
6963
]
7064

7165
{input, opts}
@@ -87,8 +81,7 @@ defmodule Mix.Tasks.Compile.ElixirScript do
8781

8882
defp defaults() do
8983
[
90-
output: "priv/elixirscript",
91-
format: :es
84+
output: "priv/elixir_script/build"
9285
]
9386
end
9487

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule ElixirScript.Mixfile do
44
def project do
55
[
66
app: :elixir_script,
7-
version: "0.29.0-dev",
7+
version: "0.30.0-dev",
88
elixir: "~> 1.5-dev",
99
elixirc_paths: elixirc_paths(Mix.env),
1010
deps: deps(),

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"build": "rollup -c rollup.config.js",
1313
"clean": "rm -rf priv/build",
1414
"test": "nyc ava src/javascript/tests",
15-
"build:test-app": "MIX_ENV=test mix elixirscript Main -f common -o test/app/build/",
15+
"build:test-app": "MIX_ENV=test mix elixirscript Main -o test/app/build/",
1616
"test-app": "yarn build:test-app && NODE_ENV=test ava 'test/app/spec/**/*.spec.js'"
1717
},
1818
"repository": {
@@ -41,9 +41,7 @@
4141
"sinon": "^2.4.1"
4242
},
4343
"ava": {
44-
"require": [
45-
"babel-register"
46-
],
44+
"require": ["babel-register"],
4745
"babel": {
4846
"babelrc": true
4947
}

test/app/spec/main.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from 'ava';
2-
const sinon = require('sinon');
2+
import Elixir from '../build/Elixir.App';
33

4-
const Elixir = require('../build/Elixir.App');
4+
const sinon = require('sinon');
55

66
test('Elixir.start:calls the modules start function', t => {
77
const callback = sinon.spy();

0 commit comments

Comments
 (0)