Skip to content

Commit

Permalink
Merge pull request #32 from steelbrain/steelbrain/support-dev
Browse files Browse the repository at this point in the history
Support guessing name of packages in non-traditional path
  • Loading branch information
steelbrain committed Dec 3, 2015
2 parents 6222652 + a5b6d04 commit c5f34be
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
### Upcoming

* Supports guessing names of packages outside of main root

### 3.0.5

* Replace Linux-specific dependency `callsite` with cross-platform `sb-callsite`

### 3.0.4

* Fix a scenario when error would be thrown if package name guessign fails
* Fix a scenario when error would be thrown if package name guessing fails

### 3.0.3

Expand Down Expand Up @@ -38,7 +42,7 @@

### 2.1.0

* Introduced second parameter to install method
* Introduced second parameter to install method

### 2.0.x

Expand Down
23 changes: 20 additions & 3 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,28 @@

import {BufferedProcess} from 'atom'
const extractionRegex = /Installing (.*?) to .* (.*)/
const nameRegex = /(\\|\/)packages(\\|\/)(.*?)(\\|\/)/
const nameRegexes = [
/(\\|\/)packages(\\|\/)(.*?)(\\|\/)/,
/(\\|\/)([\w-_]+)(\\|\/)(lib|src)(\\|\/)/i,
/(\\|\/)([\w-_]+)(\\|\/)[\w-_]+\..+$/
]

export function guessName(filePath) {
const matches = nameRegex.exec(filePath)
return matches ? matches[3] : null
let matches

matches = nameRegexes[0].exec(filePath)
if (matches) {
return matches[3]
}
matches = nameRegexes[1].exec(filePath)
if (matches) {
return matches[2]
}
matches = nameRegexes[2].exec(filePath)
if (matches) {
return matches[2]
}
return null
}

export function installPackages(dependencies, progressCallback) {
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
"url": "https://github.com/AtomLinter/package-deps/issues"
},
"homepage": "https://github.com/AtomLinter/package-deps#readme",
"devDependencies": {
"event-kit": "^1.3.0"
},
"dependencies": {
"sb-callsite": "^1.0.0"
}
Expand Down
13 changes: 10 additions & 3 deletions spec/package-deps-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ describe 'Package-Deps', ->
describe 'guessName', ->
Helpers = require('../lib/helpers')

it 'works for nix', ->
it 'works for packages in the correct place', ->
expect(Helpers.guessName('/home/steel/.atom/packages/linter/lib/main.js')).toBe('linter')
it 'works for windows', ->
expect(Helpers.guessName('C:\\Users\\Anees Iqbal\\.atom\\packages\\linter\\lib\\main.js')).toBe('linter')
expect(Helpers.guessName('C:\\Users\\Steel Brain\\.atom\\packages\\linter\\lib\\main.js')).toBe('linter')

it 'works for packages that use the lib or src folder', ->
expect(Helpers.guessName('/home/steel/github/linter/lib/main.js')).toBe('linter')
expect(Helpers.guessName('C:\\Users\\Steel Brain\\github\\linter\\lib\\main.js')).toBe('linter')

it 'works for packages that have the main file in root folder', ->
expect(Helpers.guessName('/home/steel/github/linter/main.js')).toBe('linter')
expect(Helpers.guessName('C:\\Users\\Steel Brain\\github\\linter\\main.js')).toBe('linter')

0 comments on commit c5f34be

Please sign in to comment.