Skip to content
Browse files

Remove process.chdir

  • Loading branch information...
1 parent c9ac098 commit 9b49e6d67e6bc07929dab80c87d8c87ce592ecb0 @Filirom1 committed Nov 18, 2011
Showing with 14 additions and 14 deletions.
  1. +11 −10 lib/createPkg.coffee
  2. +1 −1 package.json
  3. +2 −3 test/npm2arch.coffee
View
21 lib/createPkg.coffee
@@ -7,13 +7,17 @@ npm2arch = require './npm2PKGBUILD'
UUID = require 'uuid-js'
-module.exports = (npmName, makePkgArgv, cb, verbose) ->
+module.exports = (npmName, makePkgArgv, options, cb) ->
if typeof makePkgArgv is 'function'
cb = makePkgArgv
makePkgArgv = null
+ options = null
+ if typeof options is 'function'
+ cb = options
+ options = null
makePkgArgv or= []
- verbose = true if verbose is undefined or verbose is null
-
+ options or= verbose: true
+ verbose = options.verbose
randomId = UUID.create()
tmpDir = '/tmp/npm2archinstall-' + randomId
@@ -25,19 +29,16 @@ module.exports = (npmName, makePkgArgv, cb, verbose) ->
return cb err if err
cb2 = ->
arg = arguments
- process.chdir cwd
# Delete the tmp directory
rimraf tmpDir, (err) ->
return cb err if err
cb.apply(this, arg)
- cwd = process.cwd()
- process.chdir tmpDir
- # Write the PKGBUILD file on the cwd
- fs.writeFile 'PKGBUILD', pkgbuild, (err)->
+ # Write the PKGBUILD file in the tmpDir
+ fs.writeFile path.join(tmpDir, "PKGBUILD"), pkgbuild, (err)->
return cb2 err if err
# Spawn makepkg
- child = spawn 'makepkg', makePkgArgv
+ child = spawn 'makepkg', makePkgArgv, cwd: tmpDir, env: process.env, setsid: false
child.stdout.pipe(process.stdout, end: false) if verbose
child.stderr.pipe(process.stderr, end: false) if verbose
child.on 'exit', (code) ->
@@ -46,7 +47,7 @@ module.exports = (npmName, makePkgArgv, cb, verbose) ->
fs.readdir tmpDir, (err, files)->
return cb2 err if err
pkgFile = (files.filter (file)-> file.indexOf('nodejs-') is 0)[0]
- newPkgFile = path.join(cwd, path.basename pkgFile)
+ newPkgFile = path.join(process.cwd(), path.basename pkgFile)
fs.unlinkSync newPkgFile if path.existsSync newPkgFile
fs.move path.join(tmpDir, pkgFile), newPkgFile, (err)->
cb2 err if err
View
2 package.json
@@ -2,7 +2,7 @@
"author": "Filirom1 <filirom1@gmail.com>",
"name": "npm2arch",
"description": "Convert NPM package to a PKGBUILD for ArchLinux",
- "version": "0.1.4",
+ "version": "0.1.5",
"homepage": "https://github.com/Filirom1/npm2arch",
"repository": {
"type": "git",
View
5 test/npm2arch.coffee
@@ -45,7 +45,7 @@ vows.describe('Test npm2arch')
dir = "/tmp/test-npm2arch-#{randomId}-dir/"
fs.mkdirSync dir
process.chdir dir
- createPkg 'npm2arch', ['--source'], @callback, false
+ createPkg 'npm2arch', ['--source'], verbose: false, @callback
return
'Then a package is created': (err, file) ->
assert.isNull err
@@ -54,12 +54,11 @@ vows.describe('Test npm2arch')
assert.include file, 'nodejs-npm2arch-'
assert.include file, '.src.tar.gz'
assert.isTrue path.existsSync file
- process.chdir cwd
rimraf.sync path.dirname file
'When calling createPkg with a bad package name':
topic: ->
- createPkg 'qsdfqsdfqsd', ['--source'], @callback, false
+ createPkg 'qsdfqsdfqsd', ['--source'], verbose: false, @callback
return
'Then an error is returned': (err, file) ->
assert.isNotNull err

0 comments on commit 9b49e6d

Please sign in to comment.
Something went wrong with that request. Please try again.