Skip to content

Commit a51923d

Browse files
committed
Separate the core file from bundle
1 parent fcf4b2d commit a51923d

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

lib/elixir_script/passes/output.ex

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,7 @@ defmodule ElixirScript.Output do
4949
end
5050

5151
defp concat(code) do
52-
bootstrap_code = get_bootstrap_js()
53-
"'use strict';\nexport #{bootstrap_code}\n#{code}"
54-
end
55-
56-
defp get_bootstrap_js() do
57-
operating_path = Path.join([Mix.Project.build_path, "lib", "elixir_script", "priv"])
58-
path = Path.join([operating_path, "build", "iife", "ElixirScript.Core.js"])
59-
File.read!(path)
52+
"'use strict';\nimport ElixirScript from './ElixirScript.Core.js';\n#{code}"
6053
end
6154

6255
defp prepare_js_ast(js_ast) do
@@ -80,20 +73,27 @@ defmodule ElixirScript.Output do
8073

8174
defp output(code, path, js_modules) do
8275
file_name = get_output_file_name(path)
76+
output_dir = Path.dirname(file_name)
8377

84-
if !File.exists?(Path.dirname(file_name)) do
85-
File.mkdir_p!(Path.dirname(file_name))
78+
if !File.exists?(output_dir) do
79+
File.mkdir_p!(output_dir)
8680
end
8781

8882
apps = get_app_names()
89-
output_dir = Path.dirname(file_name)
9083
Enum.each(js_modules, fn({_, _, path, _}) ->
9184
copy_javascript_module(apps, output_dir, path)
9285
end)
9386

87+
copy_bootstrap_js(output_dir)
9488
File.write!(file_name, code)
9589
end
9690

91+
defp copy_bootstrap_js(directory) do
92+
operating_path = Path.join([Mix.Project.build_path, "lib", "elixir_script", "priv"])
93+
path = Path.join([operating_path, "build", "es", "ElixirScript.Core.js"])
94+
File.cp!(path, Path.join([directory, "ElixirScript.Core.js"]))
95+
end
96+
9797
def get_output_file_name(path) do
9898
case Path.extname(path) do
9999
".js" ->

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
},
1212
"scripts": {
1313
"lint": "eslint src/javascript/lib/**/*.js src/javascript/tests/**/*.js",
14-
"lint:fix": "eslint src/javascript/lib/**/*.js src/javascript/tests/**/*.js --fix",
14+
"lint:fix":
15+
"eslint src/javascript/lib/**/*.js src/javascript/tests/**/*.js --fix",
1516
"build": "rollup -c rollup.config.js",
1617
"clean": "rm -rf priv/build",
1718
"test": "nyc ava src/javascript/tests"
@@ -44,11 +45,12 @@
4445
"rollup-plugin-node-resolve": "^3.0.0"
4546
},
4647
"ava": {
47-
"require": [
48-
"babel-register"
49-
],
48+
"require": ["babel-register"],
5049
"babel": {
5150
"babelrc": true
5251
}
52+
},
53+
"@std/esm": {
54+
"esm": "js"
5355
}
5456
}

rollup.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@ export default {
2020
keepClassName: true,
2121
}),
2222
],
23-
output: [{ file: 'priv/build/iife/ElixirScript.Core.js', format: 'iife' }],
23+
output: [
24+
{ file: 'priv/build/iife/ElixirScript.Core.js', format: 'iife' },
25+
{ file: 'priv/build/es/ElixirScript.Core.js', format: 'es', sourcemap: 'inline' },
26+
],
2427
};

test/support/helpers.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ defmodule Helpers do
1313
|> Enum.join(",")
1414

1515
main = """
16-
import Elixir, {ElixirScript} from './#{filename}.mjs'
16+
import ElixirScript from './ElixirScript.Core.js';
17+
import Elixir from './#{filename}.mjs';
1718
1819
const mod = Elixir.#{inspect module}.__load(Elixir)
1920
const ret = mod.#{func}(#{args_to_js})

0 commit comments

Comments
 (0)