Skip to content

Commit

Permalink
fix bug when script has the same name as the target os script
Browse files Browse the repository at this point in the history
  • Loading branch information
milewski committed Apr 19, 2017
1 parent 6aab0fa commit e4f55cb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cross-os",
"version": "1.1.0",
"version": "1.1.1",
"description": "Allow to add OS-specific scripts in your package.json!",
"main": "source/index.js",
"bin": "source/index.js",
Expand Down
2 changes: 1 addition & 1 deletion source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const pipeline = new Promise(resolve => {
let script = process.argv.pop(),
property = 'scripts';

if (config[property] && !config[property][script]) {
if (!config[property][script] || typeof config[property][script] !== 'object') {
property = 'cross-os'
}

Expand Down
10 changes: 8 additions & 2 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@
"third": "echo 'it is working just fine'",
"fourth": "node ../source/index.js first",
"sixth": "node ../source/index.js first",
"seventh": "node ../source/index.js fifth"
"seventh": "node ../source/index.js fifth",
"foo": "node ../source/index.js foo"
},
"cross-os": {
"fifth": {
"win32": "echo hello from cross-os win32",
"linux": "echo hello from cross-os linux",
"darwin": "echo hello from cross-os darwin"
},
"sixth": "echo i should not been seen"
"sixth": "echo i should not been seen",
"foo": {
"win32": "echo bar from win32",
"linux": "echo bar from linux",
"darwin": "echo bar from darwin"
}
}
}
18 changes: 18 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,22 @@ describe('Loader', () => {

})

it('should not conflict with script containing the same name as its callee', done => {

const child = exec('npm run foo --silent')

let output = '';

child.stdout.on('data', (buffer: Buffer) => {
output += buffer.toString('utf-8')
})

child.on('exit', code => {
expect(output.trim()).to.match(/bar/)
expect(code).to.be(0)
done()
})

})

})

0 comments on commit e4f55cb

Please sign in to comment.