Skip to content
Myr

Merge pull request #349 from zhiyelee/fix-global

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix executable subcommand when install globally * refactor test cases

authored by Zhiye Li · committed by Zhiye Li · parents 5ae016f, eb850dd · Browse files · 8 files+82 added−33 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

8 files+82 added−33 removed

  • tests:+43 added−18 removed
  • other:+39 added−15 removed

8 files+82 added−33 removed

added:test/fixtures/pm+10 added
1#!/usr/bin/env node23var program = require('../../');45program6 .version('0.0.1')7 .command('install [name]', 'install one or more packages')8 .command('search [query]', 'search with optional query')9 .command('list', 'list packages installed')10 .parse(process.argv);
added:test/fixtures/pm-install+3 added
1#!/usr/bin/env node2console.log('install')3
modified:test/test.command.executableSubcommand.js+23 added-18 removed
modified:index.js+9 added-3 removed
3 unmodified lines
4 */56var EventEmitter = require('events').EventEmitter;7var spawn = require('child_process').spawn;8var readlink = require('graceful-readlink').readlinkSync;9var path = require('path');10var dirname = path.dirname;11var basename = path.basename;12var fs = require('fs');
456 unmodified lines
469 args[1] = '--help';470 }471472 // executable473 var f = argv[1];474 var link = readlink(f);475 if (link !== f) {476 link = path.join(dirname(f), link)477 }472 var dir = dirname(argv[1]);473 var bin = basename(argv[1], '.js') + '-' + args[0];478 var dir = dirname(link);479 var bin = basename(f, '.js') + '-' + args[0];480481 // prefer local `./<bin>` to bin in the $PATH482 var local = path.join(dir, bin);483 try {
7 unmodified lines
491 args = args.slice(1);492493 var proc;494 if (process.platform !== 'win32') {489 proc = spawn(bin, args, { stdio: 'inherit'});495 proc = spawn(bin, args, { stdio: 'inherit', customFds: [0, 1, 2] });496 } else {497 args.unshift(local);498 proc = spawn(process.execPath, args, { stdio: 'inherit'});499 }
554 unmodified lines
modified:package.json+30 added-12 removed