Skip to content

Commit e4f55cb

Browse files
committed
fix bug when script has the same name as the target os script
1 parent 6aab0fa commit e4f55cb

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cross-os",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Allow to add OS-specific scripts in your package.json!",
55
"main": "source/index.js",
66
"bin": "source/index.js",

source/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const pipeline = new Promise(resolve => {
1818
let script = process.argv.pop(),
1919
property = 'scripts';
2020

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

test/package.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@
99
"third": "echo 'it is working just fine'",
1010
"fourth": "node ../source/index.js first",
1111
"sixth": "node ../source/index.js first",
12-
"seventh": "node ../source/index.js fifth"
12+
"seventh": "node ../source/index.js fifth",
13+
"foo": "node ../source/index.js foo"
1314
},
1415
"cross-os": {
1516
"fifth": {
1617
"win32": "echo hello from cross-os win32",
1718
"linux": "echo hello from cross-os linux",
1819
"darwin": "echo hello from cross-os darwin"
1920
},
20-
"sixth": "echo i should not been seen"
21+
"sixth": "echo i should not been seen",
22+
"foo": {
23+
"win32": "echo bar from win32",
24+
"linux": "echo bar from linux",
25+
"darwin": "echo bar from darwin"
26+
}
2127
}
2228
}

test/test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,22 @@ describe('Loader', () => {
108108

109109
})
110110

111+
it('should not conflict with script containing the same name as its callee', done => {
112+
113+
const child = exec('npm run foo --silent')
114+
115+
let output = '';
116+
117+
child.stdout.on('data', (buffer: Buffer) => {
118+
output += buffer.toString('utf-8')
119+
})
120+
121+
child.on('exit', code => {
122+
expect(output.trim()).to.match(/bar/)
123+
expect(code).to.be(0)
124+
done()
125+
})
126+
127+
})
128+
111129
})

0 commit comments

Comments
 (0)