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

Commit

Permalink
path.resolve argv[1] for non-default entrypoint. fixes #671
Browse files Browse the repository at this point in the history
  • Loading branch information
igorklopov committed May 1, 2019
1 parent e736f85 commit 3775ab6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
5 changes: 5 additions & 0 deletions prelude/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ if (process.argv[1] !== 'PKG_DUMMY_ENTRYPOINT') {

if (process.env.PKG_EXECPATH === EXECPATH) {
process.argv.splice(1, 1);

if (process.argv[1] && process.argv[1] !== '-') {
// https://github.com/nodejs/node/blob/1a96d83a223ff9f05f7d942fb84440d323f7b596/lib/internal/bootstrap/node.js#L269
process.argv[1] = require('path').resolve(process.argv[1]);
}
} else {
process.argv[1] = DEFAULT_ENTRYPOINT;
}
Expand Down
11 changes: 8 additions & 3 deletions test/test-50-spawn/test-spawn-a-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

'use strict';

var path = require('path');
var spawn = require('child_process').spawn;

if (process.send) {
require('./test-spawn-a-child.js');
return;
}

var child = spawn(
process.execPath, [
require.resolve('./test-spawn-a-child.js'), 'argvx', '--argvy'
], { stdio: [ 'inherit', 'inherit', 'inherit', 'ipc' ] }
process.execPath, [ path.basename(__filename), 'argvx', '--argvy' ],
{ stdio: [ 'inherit', 'inherit', 'inherit', 'ipc' ] }
);

child.on('message', function (value) {
Expand Down
10 changes: 3 additions & 7 deletions test/test-50-spawn/test-spawn-a-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@

var spawn = require('child_process').spawn;

if (process.send) {
require('./test-spawn-a-child.js');
return;
}

var child = spawn(
process.execPath, [ process.argv[1], 'argvx', '--argvy' ],
{ stdio: [ 'inherit', 'inherit', 'inherit', 'ipc' ] }
process.execPath, [
require.resolve('./test-spawn-a-child.js'), 'argvx', '--argvy'
], { stdio: [ 'inherit', 'inherit', 'inherit', 'ipc' ] }
);

child.on('message', function (value) {
Expand Down
6 changes: 2 additions & 4 deletions test/test-50-spawn/test-spawn-a-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

'use strict';

var path = require('path');
var spawn = require('child_process').spawn;

if (process.send) {
Expand All @@ -11,9 +10,8 @@ if (process.send) {
}

var child = spawn(
process.argv[0], [
path.join(process.cwd(), path.basename(__filename)), 'argvx', '--argvy'
], { stdio: [ 'inherit', 'inherit', 'inherit', 'ipc' ] }
process.execPath, [ process.argv[1], 'argvx', '--argvy' ],
{ stdio: [ 'inherit', 'inherit', 'inherit', 'ipc' ] }
);

child.on('message', function (value) {
Expand Down
28 changes: 28 additions & 0 deletions test/test-50-spawn/test-spawn-a-5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env node

'use strict';

var path = require('path');
var spawn = require('child_process').spawn;

if (process.send) {
require('./test-spawn-a-child.js');
return;
}

var child = spawn(
process.argv[0], [
path.join(process.cwd(), path.basename(__filename)), 'argvx', '--argvy'
], { stdio: [ 'inherit', 'inherit', 'inherit', 'ipc' ] }
);

child.on('message', function (value) {
console.log(value.toString());
child.send(value);
});

child.send(2);

child.on('exit', function (code) {
console.log('Child exited with code', code);
});

0 comments on commit 3775ab6

Please sign in to comment.