Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
chdir to proc.env.PWD, that can be passed explicitly. fixes #231
Browse files Browse the repository at this point in the history
  • Loading branch information
igorklopov committed Sep 15, 2017
1 parent 4a2055e commit 939c0df
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/bin.js
Expand Up @@ -4,6 +4,13 @@ import { exec } from './index.js';
import { log } from './log.js';

async function main () {
if (process.env.CHDIR &&
process.env.CHDIR !== process.cwd()) {
// allow to override cwd by CHDIR env var
// https://github.com/resin-io/etcher/pull/1713
process.chdir(process.env.CHDIR);
}

await exec(process.argv.slice(2));
}

Expand Down
32 changes: 32 additions & 0 deletions test/test-50-chdir-env-var/main.js
@@ -0,0 +1,32 @@
#!/usr/bin/env node

'use strict';

const path = require('path');
const assert = require('assert');
const utils = require('../utils.js');

assert(!module.parent);
assert(__dirname === process.cwd());

const target = process.argv[2] || 'host';
const input = './test-x-index.js';
const output = './run-time/test-output.exe';

let right;

utils.pkg.sync([
'--target', target,
'--output', output, input
], { env: {
CHDIR: 'source',
PATH: process.env.PATH
} });

right = utils.spawn.sync(
'./' + path.basename(output), [],
{ cwd: path.dirname('source/' + output) }
);

assert.equal(right, 'ok\n');
utils.vacuum.sync(path.dirname('source/' + output));
3 changes: 3 additions & 0 deletions test/test-50-chdir-env-var/source/test-x-index.js
@@ -0,0 +1,3 @@
'use strict';

console.log('ok');

0 comments on commit 939c0df

Please sign in to comment.