Fix m.version to not depend on package.json (#2464)

* Fix `m.version` to not depend on `package.json`

Created an accidental breaking change.

* Update changelog

* Fix a failing test
This commit is contained in:
Isiah Meadows 2019-07-09 19:26:00 -04:00 committed by GitHub
parent 1f4b2cf49a
commit 1434ba313f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 13 additions and 15 deletions

View file

@ -7,3 +7,4 @@
.travis.yml
CONTRIBUTING.md
yarn.lock
scripts

View file

@ -24,10 +24,6 @@ module.exports = function (input) {
var include = /(?:((?:var|let|const|,|)[\t ]*)([\w_$\.\[\]"'`]+)(\s*=\s*))?require\(([^\)]+)\)(\s*[`\.\(\[])?/gm
var uuid = 0
var process = function(filepath, data) {
// HACK: inline Mithril's `package.json` keys without reading the whole file.
data = data.replace(/require\((['"])\.\/package\.json\1\)\.(\w+)/, function (match, quote, key) {
return JSON.stringify(pkg[key])
})
data.replace(declaration, function(match, binding) {bindings[binding] = 0})
return data.replace(include, function(match, def, variable, eq, dep, rest) {

View file

@ -320,11 +320,4 @@ o.spec("bundler", function() {
remove("a.js")
remove("b.js")
})
o("reads package.json keys", function() {
write("a.js", 'var b = require("./package.json").version')
o(bundle(ns + "a.js")).equals(";(function() {\nvar b = " + JSON.stringify(pkg.version) + "\n}());")
remove("a.js")
})
})

View file

@ -86,8 +86,6 @@
- Previously, this was possible to do in `m.route.set`, `m.request`, and `m.jsonp`, but it was wholly untested for and also undocumented.
- API: `m.buildPathname` and `m.parsePathname` added. ([#2361](https://github.com/MithrilJS/mithril.js/pull/2361))
- route: Use `m.mount(root, null)` to unsubscribe and clean up after a `m.route(root, ...)` call. ([#2453](https://github.com/MithrilJS/mithril.js/pull/2453))
- version: `m.version` returns the previous version string for what's in `next`. ([#2453](https://github.com/MithrilJS/mithril.js/pull/2453))
- If you're using `next`, you should hopefully know what you're doing. If you need stability, don't use `next`. (This is also why I'm not labelling it as a breaking change.)
- render: new `redraw` parameter exposed any time a child event handler is used ([#2458](https://github.com/MithrilJS/mithril.js/pull/2458) [@isiahmeadows](https://github.com/isiahmeadows))
#### Bug fixes

View file

@ -18,7 +18,7 @@ m.parseQueryString = require("./querystring/parse")
m.buildQueryString = require("./querystring/build")
m.parsePathname = require("./pathname/parse")
m.buildPathname = require("./pathname/build")
m.version = require("./package.json").version
m.version = "2.0.0-rc.7"
m.vnode = require("./render/vnode")
m.PromisePolyfill = require("./promise/polyfill")

View file

@ -22,7 +22,7 @@
"cover": "istanbul cover --print both ospec/bin/ospec",
"release": "npm version -m 'v%s'",
"preversion": "npm run test",
"version": "npm run build && git add mithril.js mithril.min.js",
"version": "node scripts/update-version && npm run build && git add index.js mithril.js mithril.min.js",
"postversion": "git push --follow-tags"
},
"devDependencies": {

10
scripts/update-version.js Normal file
View file

@ -0,0 +1,10 @@
"use strict"
const fs = require("fs")
const version = require("../package.json").version
const index = require.resolve("../index")
fs.writeFile(index,
fs.readFile(index, "utf-8")
.replace(/(version\s*=\s*)(['"]).*?\2/, `$1$2${version}$2`)
)