Skip to content

Commit

Permalink
Merge pull request #104 from steelbrain/steelbrain/fix-on-windows
Browse files Browse the repository at this point in the history
Fix git installations support on Windows
  • Loading branch information
Steel Brain committed May 7, 2017
2 parents 9f056ec + 4ccdede commit 902b690
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Upcoming

- Remove `sb-exec` in favor of `BufferedProcess` from Atom builtins

## 4.6.0

- Remove config file usage, configs are now stored in Atom config store
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"homepage": "https://github.com/AtomLinter/package-deps#readme",
"dependencies": {
"atom-package-path": "^1.1.0",
"sb-exec": "^4.0.0",
"sb-fs": "^3.0.0",
"semver": "^5.3.0"
},
Expand Down
50 changes: 35 additions & 15 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,50 @@
import FS from 'sb-fs'
import Path from 'path'
import semver from 'semver'
import { exec } from 'sb-exec'
import { BufferedProcess } from 'atom'
import type { Dependency } from './types'

let shownStorageInfo = false
const VALID_TICKS = new Set(['✓', 'done'])
const VALIDATION_REGEXP = /(?:Installing|Moving) (.*?) to .* (.*)/

function exec(command: string, parameters: Array<string>): Promise<{ stdout: string, stderr: string }> {
return new Promise(function(resolve) {
const data = { stdout: [], stderr: [] }
const spawnedProcess = new BufferedProcess({
command,
args: parameters,
stdout(chunk) {
data.stdout.push(chunk)
},
stderr(chunk) {
data.stderr.push(chunk)
},
exit() {
resolve({ stdout: data.stdout.join(''), stderr: data.stderr.join('') })
},
autoStart: false,
})
spawnedProcess.start()
})
}

export function apmInstall(dependencies: Array<Dependency>, progressCallback: ((packageName: string, status: boolean) => void)): Promise<Map<string, Error>> {
const errors = new Map()
return Promise.all(dependencies.map(function(dep) {
return exec(atom.packages.getApmPath(), ['install', dep.version ? `${dep.url}@${dep.version}` : dep.url, '--production', '--color', 'false'], {
stream: 'both',
ignoreExitCode: true,
}).then(function(output) {
const successful = VALIDATION_REGEXP.test(output.stdout) && VALID_TICKS.has(VALIDATION_REGEXP.exec(output.stdout)[2])
progressCallback(dep.name, successful)
if (!successful) {
const error = new Error(`Error installing dependency: ${dep.name}`)
error.stack = output.stderr
throw error
}
}).catch(function(error) {
errors.set(dep.name, error)
})
return exec(atom.packages.getApmPath(), ['install', dep.version ? `${dep.url}@${dep.version}` : dep.url, '--production', '--color', 'false'])
.then(function(output) {
const successful = VALIDATION_REGEXP.test(output.stdout) && VALID_TICKS.has(VALIDATION_REGEXP.exec(output.stdout)[2])
progressCallback(dep.name, successful)
if (!successful) {
const error = new Error(`Error installing dependency: ${dep.name}`)
error.stack = output.stderr
throw error
}
})
.catch(function(error) {
errors.set(dep.name, error)
})
})).then(function() {
return errors
})
Expand Down

0 comments on commit 902b690

Please sign in to comment.