Skip to content

Commit

Permalink
Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanblock committed Dec 5, 2023
1 parent 8b1fe31 commit 2accce2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/config/project/prefs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ let { parse } = require('./dotenv')
let { homedir } = require('os')

module.exports = function getPrefs ({ scope, inventory, errors, _testing }) {
/* istanbul ignore next */
let cwd = scope === 'global'
? _testing ? join(inventory._project.cwd, homedir()) : homedir()
? homedir()
: inventory._project.cwd

/* istanbul ignore next */
if (_testing && scope === 'global') {
if (process.platform === 'win32') cwd = cwd.replace(parse(cwd).root, '')
cwd = join(inventory._project.cwd, cwd)
}

let envFilepath = join(cwd, '.env')
let hasEnvFile = scope === 'local' && existsSync(envFilepath)
let prefs = read({ type: 'preferences', cwd, errors })
Expand Down
11 changes: 7 additions & 4 deletions test/unit/src/config/project/index-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let { join } = require('path')
let { join, parse } = require('path')
let { homedir } = require('os')
let test = require('tape')
let mockTmp = require('mock-tmp')
Expand All @@ -11,7 +11,10 @@ let sut = join(cwd, 'src', 'config', 'project')
let getProjectConfig = require(sut)

let localPrefsFile = 'prefs.arc'
let globalPrefsFile = join(homedir(), 'prefs.arc')
let _homedir = homedir()
if (process.platform === 'win32') homedir = homedir.replace(parse(cwd).root, '')
let globalPrefsFile = join(_homedir, 'prefs.arc')
let _testing = true

test('Set up env', t => {
t.plan(1)
Expand Down Expand Up @@ -99,7 +102,7 @@ useAWS true`
[globalPrefsFile]: globalPrefs
})
inventory = inventoryDefaults({ cwd })
proj = getProjectConfig({ arc, errors, inventory, _testing: true })
proj = getProjectConfig({ arc, errors, inventory, _testing })
t.equal(errors.length, 0, 'Did not error')
t.ok(proj.preferences, 'Populated preferences')
t.equal(proj.preferences.env.testing.fiz, 'buz', 'Populated testing env')
Expand All @@ -117,7 +120,7 @@ useAWS true`
[globalPrefsFile]: globalPrefs,
})
inventory = inventoryDefaults({ cwd })
proj = getProjectConfig({ arc, errors, inventory, _testing: true })
proj = getProjectConfig({ arc, errors, inventory, _testing })
t.equal(errors.length, 0, 'Did not error')
t.ok(proj.preferences, 'Populated preferences')
t.equal(proj.preferences.env.testing.foo, 'bar', 'Populated testing env (preferred local to global prefs)')
Expand Down

0 comments on commit 2accce2

Please sign in to comment.