Skip to content

Commit

Permalink
output mithril, stream and ospec esm versions on build - fixes #2112 (#…
Browse files Browse the repository at this point in the history
…2194)

* output mithril, stream and ospec esm versions on build

* Add esm bundles

* [request] Clearer error message for JSON deserialization failure (#2195)

* Bundled output for commit fd7cf80 [skip ci]

* Fix #1714 conditionally halting stream (#2200)

* Fix #1714 conditionally halting stream

* Add note in changelog

* Do not include stream as named export in mithril.esm.js

* Rename mithril.min.esm.js to mithril.esm.min.js

* Add esm files to eslintignore

* Add named exports

* Add hyperscript `m` as named export

* Add builds with export changes

* checkout regular bundled files

* Change .esm.js to .mjs

* Update pkg module to point to .mjs

* Fix for export names to avoid collision

* Updated bundled files
  • Loading branch information
porsager authored and dead-claudia committed Nov 14, 2018
1 parent 0d36d0d commit c3896b9
Show file tree
Hide file tree
Showing 11 changed files with 2,196 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ coverage/
docs/lib/
examples/
/mithril.js
/mithril.mjs
/mithril.min.js
/mithril.min.mjs
/stream/stream.mjs
node_modules/
68 changes: 68 additions & 0 deletions esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"use strict"

/*
This script will create esm compatible scripts
from the already compiled versions of:
- mithril.js > mithril.mjs
- mithril.min.js > mithril.min.mjs
- /stream/stream.js > stream.mjs
*/

var fs = require("fs")

var namedExports = [
"m",
"trust",
"fragment",
"mount",
"route",
"withAttr",
"render",
"redraw",
"request",
"jsonp",
"parseQueryString",
"buildQueryString",
"version",
"vnode",
"PromisePolyfill"
]

var mithril = fs.readFileSync("mithril.js", "utf8")
fs.writeFileSync("mithril.mjs",
mithril.slice(
mithril.indexOf("\"use strict\"") + 13,
mithril.lastIndexOf("if (typeof module")
)
+ "\nexport default m"
// The exports are declared with prefixed underscores to avoid overwriting previously
// declared variables with the same name
+ "\nvar " + namedExports.map(function(n) { return "_" + n + " = m." + n }).join(",")
+ "\nexport {" + namedExports.map(function(n) { return "_" + n + " as " + n }).join(",") + "}"
)

var mithrilMin = fs.readFileSync("mithril.min.js", "utf8")
var mName = mithrilMin.match(/window\.m=([a-z])}/)[1]
fs.writeFileSync("mithril.min.mjs",
mithrilMin.slice(
12,
mithrilMin.lastIndexOf("\"undefined\"!==typeof module")
)
+ "export default " + mName + ";"
// The exports are declared with prefixed underscores to avoid overwriting previously
// declared variables with the same name
+ "var " + namedExports.map(function(n) { return "_" + n + "=m." + n }).join(",") + ";"
+ "export {" + namedExports.map(function(n) { return "_" + n + " as " + n }).join(",") + "};"
)

var stream = fs.readFileSync("stream/stream.js", "utf8")
fs.writeFileSync("stream/stream.mjs",
stream.slice(
stream.indexOf("\"use strict\"") + 13,
stream.lastIndexOf("if (typeof module")
)
+ "\nexport default createStream"
)
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"use strict"

var m = require("./hyperscript")
var hyperscript = require("./hyperscript")
var m = function m() { return hyperscript.apply(this, arguments) }
m.m = hyperscript
m.trust = hyperscript.trust
m.fragment = hyperscript.fragment

var requestService = require("./request")
var redrawService = require("./redraw")

Expand Down
48 changes: 48 additions & 0 deletions mithril.min.mjs

Large diffs are not rendered by default.

Loading

0 comments on commit c3896b9

Please sign in to comment.