Commit e7655d8a authored by Jérémy Lal's avatar Jérémy Lal

Imported Upstream version 0.1.0

parent 54fafe1b
*.swp
.*.swp
.DS_Store
*~
.project
.settings
npm-debug.log
coverage.html
.idea
lib-cov
node_modules
Copyright (c) Isaac Z. Schlueter
Copyright (c) Isaac Z. Schlueter ("Author")
All rights reserved.
The BSD License
......@@ -6,20 +6,22 @@ The BSD License
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
var isWindows = process.platform === 'win32'
var windir = isWindows ? process.env.windir || 'C:\\Windows' : null
var path = require('path')
var exec = require('child_process').exec
var os = require('os')
// looking up envs is a bit costly.
// Also, sometimes we want to have a fallback
......@@ -46,14 +46,7 @@ memo('hostname', function () {
}, 'hostname')
memo('tmpdir', function () {
var t = isWindows ? 'temp' : 'tmp'
return process.env.TMPDIR ||
process.env.TMP ||
process.env.TEMP ||
( exports.home() ? path.resolve(exports.home(), t)
: isWindows ? path.resolve(windir, t)
: '/tmp'
)
return os.tmpDir()
})
memo('home', function () {
......
{
"name": "osenv",
"version": "0.0.3",
"version": "0.1.0",
"main": "osenv.js",
"directories": {
"test": "test"
},
"dependencies": {},
"devDependencies": {
"tap": "~0.2.5"
"tap": "~0.4.9"
},
"scripts": {
"test": "tap test/*.js"
......
......@@ -23,7 +23,6 @@ process.env.EDITOR = 'edit'
process.env.VISUAL = 'visualedit'
process.env.SHELL = 'zsh'
tap.test('basic unix sanity test', function (t) {
var osenv = require('../osenv.js')
......@@ -46,10 +45,6 @@ tap.test('basic unix sanity test', function (t) {
t.equal(osenv.tmpdir(), process.env.TEMP)
process.env.TEMP = ''
delete require.cache[require.resolve('../osenv.js')]
var osenv = require('../osenv.js')
t.equal(osenv.tmpdir(), '/home/sirUser/tmp')
delete require.cache[require.resolve('../osenv.js')]
var osenv = require('../osenv.js')
osenv.home = function () { return null }
......
......@@ -12,7 +12,7 @@ if (process.platform !== 'win32') {
// load this before clubbing the platform name.
var tap = require('tap')
process.env.windir = 'C:\\windows'
process.env.windir = 'c:\\windows'
process.env.USERDOMAIN = 'some-domain'
process.env.USERNAME = 'sirUser'
process.env.USERPROFILE = 'C:\\Users\\sirUser'
......@@ -29,8 +29,6 @@ process.env.ComSpec = 'some-com'
tap.test('basic windows sanity test', function (t) {
var osenv = require('../osenv.js')
var osenv = require('../osenv.js')
t.equal(osenv.user(),
process.env.USERDOMAIN + '\\' + process.env.USERNAME)
t.equal(osenv.home(), process.env.USERPROFILE)
......@@ -50,16 +48,11 @@ tap.test('basic windows sanity test', function (t) {
var osenv = require('../osenv.js')
t.equal(osenv.tmpdir(), process.env.TEMP)
process.env.TEMP = ''
delete require.cache[require.resolve('../osenv.js')]
var osenv = require('../osenv.js')
t.equal(osenv.tmpdir(), 'C:\\Users\\sirUser\\temp')
process.env.TEMP = ''
delete require.cache[require.resolve('../osenv.js')]
var osenv = require('../osenv.js')
osenv.home = function () { return null }
t.equal(osenv.tmpdir(), 'C:\\windows\\temp')
t.equal(osenv.tmpdir(), 'c:\\windows\\temp')
t.equal(osenv.editor(), 'edit')
process.env.EDITOR = ''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment