Skip to content

Commit

Permalink
Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanblock committed Dec 6, 2023
1 parent 8b1fe31 commit 35ba468
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/config/project/prefs/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let { join } = require('path')
let { join, parse: parsePath } = require('path')
let { existsSync, readFileSync } = require('fs')
let read = require('../../../read')
let validate = require('../validate')
Expand All @@ -7,11 +7,17 @@ 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') {
let _homedir = homedir()
if (process.platform === 'win32') _homedir = _homedir.replace(parsePath(cwd).root, '')
cwd = join(inventory._project.cwd, _homedir)
}

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 35ba468

Please sign in to comment.