-
-
Notifications
You must be signed in to change notification settings - Fork 158
[WIP] Add node's "engines" option #114
Changes from 17 commits
2d51bba
3f60aeb
3036ac5
0f1b25f
3134576
b88e5f8
67f9c15
7a5da94
b97d48b
568e0dc
899b906
f1e3efd
29f7b6a
f71eac9
2d22e03
0696ea9
ef95087
1838b68
b20ff6c
be36460
f6cafdc
f4c75bc
9048897
1667ab7
419b3bc
4db8341
8d0c085
20153f0
a42a0a8
ac38247
9268e16
f16683e
d8a97f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ node_modules | |
lib | ||
.DS_Store | ||
*.log | ||
.vscode | ||
.vscode | ||
yarn.lock | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,12 @@ | |
"license": "MIT", | ||
"repository": "https://github.com/babel/babel-preset-env", | ||
"main": "lib/index.js", | ||
"engines" : { | ||
"node" : ">=0.12.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 0.10 here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, updated |
||
}, | ||
"devEngines" : { | ||
"node" : ">= 4.x" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can do 6 here (I dont remember) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
}, | ||
"scripts": { | ||
"build": "rimraf lib && babel src -d lib", | ||
"build-data": "node ./scripts/build-data.js", | ||
|
@@ -60,6 +66,7 @@ | |
"eslint-plugin-babel": "^4.0.0", | ||
"eslint-plugin-flow-vars": "^0.5.0", | ||
"eslint-plugin-flowtype": "^2.29.1", | ||
"semver": "^5.3.0", | ||
"lodash": "^4.15.0", | ||
"mocha": "^3.0.2", | ||
"rimraf": "^2.5.4" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const DEFAULT_ENV = "development"; | ||
|
||
export const _extends = Object.assign || function (target) { | ||
for (let i = 1; i < arguments.length; i++) { | ||
const source = arguments[i]; | ||
for (let key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
|
||
export const desemverify = (version) => { | ||
return parseFloat(version); | ||
}; | ||
|
||
export const semverify = (version) => { | ||
const isInt = version % 1 === 0; | ||
const stringified = version.toString(); | ||
const strEnd = isInt ? ".0.0" : ".0"; | ||
return stringified + strEnd; | ||
}; | ||
|
||
export const getEnv = (env) => { | ||
return env.BABEL_ENV || env.NODE_ENV || DEFAULT_ENV; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const a = "1"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"use strict"; | ||
|
||
var a = "1"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"presets": [ | ||
["../../../../lib", { | ||
"targets": { | ||
"node": "engines", | ||
"chrome": 55 | ||
} | ||
}] | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,49 @@ describe("babel-preset-env", () => { | |
}), { | ||
node: parseFloat(process.versions.node) | ||
}); | ||
|
||
}); | ||
|
||
it("should return the current node version with option 'engines' with BABEL_ENV='development'", function() { | ||
const prevEnv = process.env.BABEL_ENV; | ||
process.env.BABEL_ENV = "development"; | ||
|
||
assert.deepEqual(babelPresetEnv.getTargets({ | ||
node: "engines" | ||
}), { | ||
node: 4 | ||
}); | ||
|
||
process.env.BABEL_ENV = prevEnv; | ||
}); | ||
|
||
it("should return the current node version with option 'engines' with BABEL_ENV='production'", function() { | ||
const prevEnv = process.env.BABEL_ENV; | ||
process.env.BABEL_ENV = "production"; | ||
|
||
assert.deepEqual(babelPresetEnv.getTargets({ | ||
node: "engines" | ||
}), { | ||
node: 0.12 | ||
}); | ||
process.env.BABEL_ENV = prevEnv; | ||
}); | ||
}); | ||
|
||
describe("getLowestFromSemverValue", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit, but may want a test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! Need to cover |
||
it("should return the lowest supported version from semver value '>=0.12'", function() { | ||
const lowestNodeVersion = babelPresetEnv.getLowestFromSemverValue(">=0.12", [4, 5, 6]); | ||
assert.equal(lowestNodeVersion, 4); | ||
}); | ||
|
||
it("should return null from semver value '*'", function() { | ||
const lowestNodeVersion = babelPresetEnv.getLowestFromSemverValue("*", [4, 5, 6]); | ||
assert.equal(lowestNodeVersion, null); | ||
}); | ||
|
||
it("should return null if version isnt a semver value", function() { | ||
const lowestNodeVersion = babelPresetEnv.getLowestFromSemverValue("💩", [4, 5, 6]); | ||
assert.equal(lowestNodeVersion, null); | ||
}); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you ignore
yarn.lock
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abouthiroppy yarn support will be added with the separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, to prevent commiting it every time unless it will be added, let's place it to .gitignore.