Permalink
Browse files

fix(resolvePaths): Use cwd-relative paths instead of absolute paths (#…

…116)

* fix(resolvePaths): return CWD-relative paths - closes #115
* chore(package): removing obsolete devDependency "tmp"

Fixes #115
  • Loading branch information...
1 parent 97ad4b4 commit 968e0d8f015ddf077e36eda93ccff495f3605b3d @rodneyrehm rodneyrehm committed with Dec 30, 2016
Showing with 9 additions and 18 deletions.
  1. +1 −2 package.json
  2. +3 −4 src/resolvePaths.js
  3. +5 −12 test/resolvePaths.spec.js
View
@@ -70,8 +70,7 @@
"npm-check": "^5.2.2",
"pre-commit": "^1.1.3",
"rewire": "^2.5.1",
- "semantic-release": "^6.3.2",
- "tmp": "^0.0.31"
+ "semantic-release": "^6.3.2"
},
"config": {
"commitizen": {
View
@@ -3,8 +3,7 @@
const path = require('path')
module.exports = function resolvePaths(filePaths, relativeTo) {
- return filePaths.map((file) => {
- if (!relativeTo) relativeTo = process.cwd() // eslint-disable-line
- return path.resolve(path.relative(process.cwd(), relativeTo), file.filename)
- })
+ const cwd = process.cwd()
+ const base = relativeTo || cwd
+ return filePaths.map(file => path.relative(cwd, path.resolve(base, file.filename)))
}
@@ -3,15 +3,13 @@
import expect from 'expect'
import path from 'path'
import fs from 'fs'
-import tmp from 'tmp'
import resolvePaths from '../src/resolvePaths'
const files = fs.readdirSync(path.resolve('test', '__fixtures__')).map(file => ({
filename: file
}))
-const cwd = process.cwd()
-const cwdParent = path.relative(cwd, '..')
+const cwdParent = path.resolve('..')
describe('resolvePaths', () => {
it('should return Array of filenames', () => {
@@ -22,22 +20,17 @@ describe('resolvePaths', () => {
'test.css',
'test.js',
'test.txt'
- ].map(file => path.resolve(cwd, file))
+ ]
)
})
- it('should return relative paths if second parameter is set', () => {
- expect(resolvePaths(files, '..')).toEqual(
+ it('should return CWD-relative paths if second parameter is set', () => {
+ expect(resolvePaths(files, cwdParent)).toEqual(
[
'test.css',
'test.js',
'test.txt'
- ].map(file => path.resolve(cwdParent, file))
+ ].map(file => path.join('..', file))
)
})
-
- it('should return absolute paths if they were absolute', () => {
- const tmpFile = tmp.fileSync()
- expect(resolvePaths([{ filename: tmpFile.name }], '..')).toEqual([tmpFile.name])
- })
})

0 comments on commit 968e0d8

Please sign in to comment.