Skip to content

Commit

Permalink
add support for node 6
Browse files Browse the repository at this point in the history
* add support for node 6
* run build script on travis
* adding 'index.js' to the files array
* use babel-plugin-transform-object-rest-spread instead of stage-2 preset
  • Loading branch information
ranyitz authored and terkelg committed Jun 19, 2018
1 parent c02d584 commit 6e18992
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 16 deletions.
10 changes: 10 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
["env", {
"targets": {
"node": "6"
}
}]
],
"plugins": ["transform-object-rest-spread"]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.DS_Store
dist
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
language: node_js
script:
- npm run build
- npm test
node_js:
- 8
- "8"
- "6"
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports =
parseInt(process.versions.node, 10) < 8
? require('./dist/index.js')
: require('./lib/index.js');
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
"description": "Lightweight, beautiful and user-friendly prompts",
"homepage": "https://github.com/terkelg/prompts",
"repository": "terkelg/prompts",
"main": "lib/index.js",
"main": "index.js",
"author": {
"name": "Terkel Gjervig",
"email": "[email protected]",
"url": "https://terkel.com"
},
"files": [
"lib"
"lib",
"dist",
"index.js"
],
"scripts": {
"start": "node lib/index.js",
"build": "babel lib -d dist",
"test": "tape test/*.js | tap-spec"
},
"keywords": [
Expand All @@ -31,10 +34,13 @@
"sisteransi": "^0.1.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"tap-spec": "^4.1.1",
"tape": "^4.8.0"
},
"engines": {
"node": ">= 8"
"node": ">= 6"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
$ npm install --save prompts
```

> This package uses async/await and requires Node.js 7.6
> This package supports Node 6 and above
![split](https://github.com/terkelg/prompts/raw/master/media/split.png)

Expand Down
25 changes: 14 additions & 11 deletions test/prompts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const test = require('tape');
const prompt = require('../lib');
const prompt = require('../');
const { prompts } = prompt;

test('basics', t => {
Expand Down Expand Up @@ -36,18 +36,21 @@ test('prompts', t => {
t.equal(Object.keys(prompts).length, types.length, 'all prompts are exported');
});

test('injects', async t => {
test('injects', t => {
let obj = { a:1, b:2, c:3 };
prompt.inject(obj);
t.same(prompt._map, obj, 'injects key:val object of answers');

let foo = await prompt({ name:'a' });
t.same(foo, { a:1 }, 'immediately returns object with injected answer');
t.same(prompt._map, { b:2, c:3 }, 'deletes the `a` key from internal map');

let bar = await prompt([{ name:'b' }, { name:'c' }]);
t.same(bar, { b:2, c:3 }, 'immediately handles two prompts at once');
t.same(prompt._map, {}, 'leaves behind empty internal mapping when exhausted');

t.end();
prompt({ name:'a' })
.then(foo => {
t.same(foo, { a:1 }, 'immediately returns object with injected answer');
t.same(prompt._map, { b:2, c:3 }, 'deletes the `a` key from internal map');

prompt([{ name:'b' }, { name:'c' }])
.then(bar => {
t.same(bar, { b:2, c:3 }, 'immediately handles two prompts at once');
t.same(prompt._map, {}, 'leaves behind empty internal mapping when exhausted');
t.end();
})
})
})

0 comments on commit 6e18992

Please sign in to comment.