Skip to content

Commit

Permalink
refactor(babel): remove dependency on babel
Browse files Browse the repository at this point in the history
remove dependency on babel, simplifying build process
also moving devDependencies into Travis steps

BREAKING CHANGE: module exports path changed to just `lib/index.js`

Closes: #44
  • Loading branch information
Ahmad Nassri committed Dec 16, 2016
1 parent 5bdb0ce commit 451f0ac
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 117 deletions.
23 changes: 0 additions & 23 deletions .babelrc

This file was deleted.

2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ engines:

ratings:
paths:
- src/**
- lib/**
- test/**
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
*.log
/lib
/node_modules
/.nyc_output
29 changes: 15 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
language: node_js

node_js:
- 4
- 6
- 7

env:
- BABEL_ENV=test
- 6
- 4

matrix:
fast_finish: true
Expand All @@ -15,16 +12,20 @@ cache:
directories:
- node_modules

before_script:
- npm prune

after_success:
- npm run coverage
- npm run codeclimate
- BABEL_ENV=v4 npm run compile -- -d lib
- BABEL_ENV=v6 npm run compile -- -d lib/node6
- BABEL_ENV=v7 npm run compile -- -d lib/node7
- npm run semantic-release
- npm install --only=production codeclimate-test-reporter semantic-release

before_deploy:
- npm run coverage -- --coverage-report=text-lcov | codeclimate-test-reporter

deploy:
skip_cleanup: true
provider: script
script: semantic-release pre && npm publish && semantic-release post || true

on:
branch: master
node: 7

branches:
except:
Expand Down
44 changes: 11 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# glob-promise [![version][npm-version]][npm-url] [![License][npm-license]][license-url]
# glob-promise [![version][npm-version]][npm-url] [![License][license-image]][license-url]

[Promise] version of [glob]:
[`Promise`][Promise] version of [`glob`][glob]

> Match files using the patterns the shell uses, like stars and stuff.
Expand All @@ -17,39 +17,17 @@
npm install --only=production --save glob-promise
```

## Usage

I recommend using an optimized build matching your Node.js environment version, otherwise, the standard `require` would work just fine with any version of Node `>= v4.0` .

```js
/*
* Node 7
*/
const glob = require('glob-promise/lib/node7')

/*
* Node 6
*/
const glob = require('glob-promise/lib/node6')

/*
* Node 4 (Default)
* Note: additional ES2015 polyfills may be required
*/
var glob = require('glob-promise')
```

## API

### glob(pattern [, options])

*pattern*: `String` (glob pattern)
*options*: `Object` or `String`
_pattern_: `String` (glob pattern)
_options_: `Object` or `String`
Return: `Object` ([Promise])

When it finishes, it will be [*fulfilled*](http://promisesaplus.com/#point-26) with an `Array` of filenames as its first argument.
When it finishes, it will be [_fulfilled_](http://promisesaplus.com/#point-26) with an `Array` of filenames as its first argument.

When it fails to read the files, it will be [*rejected*](http://promisesaplus.com/#point-30) with an error as its first argument.
When it fails to read the files, it will be [_rejected_](http://promisesaplus.com/#point-30) with an error as its first argument.

```js
glob('**/*')
Expand All @@ -67,19 +45,19 @@ glob('{foo,bar.baz}.txt', { nobrace: true })

The option object will be directly passed to [glob](https://github.com/isaacs/node-glob#options).

----
> :copyright: [ahmadnassri.com](https://www.ahmadnassri.com/)  · 
> License: [ISC][license-url]  · 
> Github: [@ahmadnassri](https://github.com/ahmadnassri)  · 
---
> :copyright: [ahmadnassri.com](https://www.ahmadnassri.com/)  · 
> License: [ISC][license-url]  · 
> Github: [@ahmadnassri](https://github.com/ahmadnassri)  · 
> Twitter: [@ahmadnassri](https://twitter.com/ahmadnassri)
[license-url]: http://choosealicense.com/licenses/isc/
[license-image]: https://img.shields.io/github/license/ahmadnassri/glob-promise.svg?style=flat-square

[travis-url]: https://travis-ci.org/ahmadnassri/glob-promise
[travis-image]: https://img.shields.io/travis/ahmadnassri/glob-promise.svg?style=flat-square

[npm-url]: https://www.npmjs.com/package/glob-promise
[npm-license]: https://img.shields.io/npm/l/glob-promise.svg?style=flat-square
[npm-version]: https://img.shields.io/npm/v/glob-promise.svg?style=flat-square
[npm-downloads]: https://img.shields.io/npm/dm/glob-promise.svg?style=flat-square

Expand Down
6 changes: 4 additions & 2 deletions src/index.js → lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import glob from 'glob'
'ust strict'

export default function (pattern, options) {
const glob = require('glob')

module.exports = function (pattern, options) {
return new Promise((resolve, reject) => {
glob(pattern, options, (err, files) => err === null ? resolve(files) : reject(err))
})
Expand Down
41 changes: 8 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,23 @@
"node": ">=4"
},
"files": [
"lib",
"src"
"lib"
],
"bugs": {
"url": "https://github.com/ahmadnassri/glob-promise/issues"
},
"scripts": {
"compile": "babel -q src",
"test": "BABEL_ENV=test tap test/*.js --reporter spec --node-arg=--require --node-arg=babel-register",
"pretest": "snazzy && echint",
"coverage": "BABEL_ENV=test tap test/*.js --reporter silent --coverage --nyc-arg=--require --nyc-arg=babel-register",
"codeclimate": "BABEL_ENV=test tap --coverage-report=text-lcov | codeclimate-test-reporter",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"standard": {
"ignore": [
"lib/**"
]
},
"echint": {
"ignore": [
"lib/**"
]
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"peerDependencies": {
"glob": "*"
"lint": "snazzy && echint",
"pretest": "npm run lint",
"test": "tap test",
"coverage": "tap test --reporter silent --coverage"
},
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-env": "1.1.1",
"babel-register": "^6.18.0",
"codeclimate-test-reporter": "^0.4.0",
"cz-conventional-changelog": "^1.2.0",
"echint": "^2.1.0",
"semantic-release": "^6.3.2",
"snazzy": "^5.0.0",
"tap": "^8.0.1"
},
"peerDependencies": {
"glob": "*"
}
}
22 changes: 12 additions & 10 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
import glob from '../src/index'
import { test } from 'tap'
'use strict'

test('should successfully parse', (assert) => {
const glob = require('../src/index')
const test = require('tap').test

test('should successfully parse', assert => {
assert.plan(2)

glob('test/**')
.then((files) => {
.then(files => {
assert.type(files, Array)
assert.same(files, [ 'test', 'test/index.js' ])
})
})

test('should be rejected when globbing fails', (assert) => {
test('should be rejected when globbing fails', assert => {
assert.plan(1)

glob('/**/*')
.catch((err) => assert.equal(err.code, 'EACCES'))
.catch(err => assert.equal(err.code, 'EACCES'))
})

test('should throw a type error when the first argument is not a string.', (assert) => {
test('should throw a type error when the first argument is not a string.', assert => {
assert.plan(1)

glob({})
.catch((err) => assert.equal(err.message, 'glob pattern string required'))
.catch(err => assert.equal(err.message, 'glob pattern string required'))
})

test('should throw a type error when it takes no arguments.', (assert) => {
test('should throw a type error when it takes no arguments.', assert => {
assert.plan(1)

glob()
.catch((err) => assert.equal(err.message, 'glob pattern string required'))
.catch(err => assert.equal(err.message, 'glob pattern string required'))
})

0 comments on commit 451f0ac

Please sign in to comment.