Skip to content

Commit 6dc5404

Browse files
JP-EllisYOU54F
authored andcommitted
fix: simplify argument parsing
Get rid of the bespoke argument escaping, and instead spawn subprocesses directly. The arguments from `process.argv` and passed through `spawnSync` are already escaped (as we are spawning directly). This also removes the use of `shell` to avoid issues that might arise from using shells. Ref: #99 Signed-off-by: JP-Ellis <[email protected]>
1 parent d300b23 commit 6dc5404

14 files changed

+85
-231
lines changed

bin/pact-broker.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
#!/usr/bin/env node
22

3-
import childProcess = require('child_process');
4-
import {
5-
standalone,
6-
standaloneUseShell,
7-
setStandaloneArgs,
8-
} from '../src/pact-standalone';
3+
import { spawnSync, standalone } from '../src/pact-standalone';
94

10-
const args = process.argv.slice(2);
11-
const opts = standaloneUseShell ? { shell: true } : {};
12-
const { error, status } = childProcess.spawnSync(
5+
const { error, status } = spawnSync(
136
standalone().brokerFullPath,
14-
setStandaloneArgs(args, standaloneUseShell),
15-
{
16-
stdio: 'inherit',
17-
...opts,
18-
}
7+
process.argv.slice(2)
198
);
209
if (error) throw error;
2110
process.exit(status as number);

bin/pact-message.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
#!/usr/bin/env node
22

3-
import childProcess = require('child_process');
4-
import {
5-
standalone,
6-
standaloneUseShell,
7-
setStandaloneArgs,
8-
} from '../src/pact-standalone';
3+
import { spawnSync, standalone } from '../src/pact-standalone';
94

10-
const args = process.argv.slice(2);
11-
const opts = standaloneUseShell ? { shell: true } : {};
12-
13-
const { error, status } = childProcess.spawnSync(
5+
const { error, status } = spawnSync(
146
standalone().messageFullPath,
15-
setStandaloneArgs(args, standaloneUseShell),
16-
{
17-
stdio: 'inherit',
18-
...opts,
19-
}
7+
process.argv.slice(2)
208
);
219
if (error) throw error;
2210
process.exit(status as number);

bin/pact-mock-server.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
#!/usr/bin/env node
22

3-
import childProcess = require('child_process');
4-
import {
5-
standalone,
6-
standaloneUseShell,
7-
setStandaloneArgs,
8-
} from '../src/pact-standalone';
3+
import { spawnSync, standalone } from '../src/pact-standalone';
94

10-
const args = process.argv.slice(2);
11-
const opts = standaloneUseShell ? { shell: true } : {};
12-
13-
const { error, status } = childProcess.spawnSync(
5+
const { error, status } = spawnSync(
146
standalone().mockServerFullPath,
15-
setStandaloneArgs(args, standaloneUseShell),
16-
{
17-
stdio: 'inherit',
18-
...opts,
19-
}
7+
process.argv.slice(2)
208
);
219
if (error) throw error;
2210
process.exit(status as number);

bin/pact-mock-service.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
#!/usr/bin/env node
22

3-
import childProcess = require('child_process');
4-
import {
5-
standalone,
6-
standaloneUseShell,
7-
setStandaloneArgs,
8-
} from '../src/pact-standalone';
3+
import { spawnSync, standalone } from '../src/pact-standalone';
94

10-
const args = process.argv.slice(2);
11-
const opts = standaloneUseShell ? { shell: true } : {};
12-
13-
const { error, status } = childProcess.spawnSync(
5+
const { error, status } = spawnSync(
146
standalone().mockServiceFullPath,
15-
setStandaloneArgs(args, standaloneUseShell),
16-
{
17-
stdio: 'inherit',
18-
...opts,
19-
}
7+
process.argv.slice(2)
208
);
219
if (error) throw error;
2210
process.exit(status as number);

bin/pact-plugin.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
#!/usr/bin/env node
22

3-
import childProcess = require('child_process');
4-
import {
5-
standalone,
6-
standaloneUseShell,
7-
setStandaloneArgs,
8-
} from '../src/pact-standalone';
3+
import { spawnSync, standalone } from '../src/pact-standalone';
94

10-
const args = process.argv.slice(2);
11-
const opts = standaloneUseShell ? { shell: true } : {};
12-
13-
const { error, status } = childProcess.spawnSync(
5+
const { error, status } = spawnSync(
146
standalone().pluginFullPath,
15-
setStandaloneArgs(args, standaloneUseShell),
16-
{
17-
stdio: 'inherit',
18-
...opts,
19-
}
7+
process.argv.slice(2)
208
);
219
if (error) throw error;
2210
process.exit(status as number);

bin/pact-provider-verifier.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
#!/usr/bin/env node
22

3-
import childProcess = require('child_process');
4-
import {
5-
standalone,
6-
standaloneUseShell,
7-
setStandaloneArgs,
8-
} from '../src/pact-standalone';
3+
import { spawnSync, standalone } from '../src/pact-standalone';
94

10-
const args = process.argv.slice(2);
11-
const opts = standaloneUseShell ? { shell: true } : {};
12-
13-
const { error, status } = childProcess.spawnSync(
5+
const { error, status } = spawnSync(
146
standalone().verifierFullPath,
15-
setStandaloneArgs(args, standaloneUseShell),
16-
{
17-
stdio: 'inherit',
18-
...opts,
19-
}
7+
process.argv.slice(2)
208
);
219
if (error) throw error;
2210
process.exit(status as number);

bin/pact-stub-server.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
#!/usr/bin/env node
22

3-
import childProcess = require('child_process');
4-
import {
5-
standalone,
6-
standaloneUseShell,
7-
setStandaloneArgs,
8-
} from '../src/pact-standalone';
3+
import { spawnSync, standalone } from '../src/pact-standalone';
94

10-
const args = process.argv.slice(2);
11-
const opts = standaloneUseShell ? { shell: true } : {};
12-
13-
const { error, status } = childProcess.spawnSync(
5+
const { error, status } = spawnSync(
146
standalone().stubServerFullPath,
15-
setStandaloneArgs(args, standaloneUseShell),
16-
{
17-
stdio: 'inherit',
18-
...opts,
19-
}
7+
process.argv.slice(2)
208
);
219
if (error) throw error;
2210
process.exit(status as number);

bin/pact-stub-service.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
#!/usr/bin/env node
22

3-
import childProcess = require('child_process');
4-
import {
5-
standalone,
6-
standaloneUseShell,
7-
setStandaloneArgs,
8-
} from '../src/pact-standalone';
3+
import { spawnSync, standalone } from '../src/pact-standalone';
94

10-
const args = process.argv.slice(2);
11-
const opts = standaloneUseShell ? { shell: true } : {};
12-
13-
const { error, status } = childProcess.spawnSync(
14-
standalone().stubFullPath,
15-
setStandaloneArgs(args, standaloneUseShell),
16-
{
17-
stdio: 'inherit',
18-
...opts,
19-
}
5+
const { error, status } = spawnSync(
6+
standalone().stubServerFullPath,
7+
process.argv.slice(2)
208
);
219
if (error) throw error;
2210
process.exit(status as number);

bin/pact-verifier.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
#!/usr/bin/env node
22

3-
import childProcess = require('child_process');
4-
import {
5-
standalone,
6-
standaloneUseShell,
7-
setStandaloneArgs,
8-
} from '../src/pact-standalone';
3+
import { spawnSync, standalone } from '../src/pact-standalone';
94

10-
const args = process.argv.slice(2);
11-
const opts = standaloneUseShell ? { shell: true } : {};
12-
13-
const { error, status } = childProcess.spawnSync(
14-
standalone().verifierRustFullPath,
15-
setStandaloneArgs(args, standaloneUseShell),
16-
{
17-
stdio: 'inherit',
18-
...opts,
19-
}
5+
const { error, status } = spawnSync(
6+
standalone().verifierFullPath,
7+
process.argv.slice(2)
208
);
219
if (error) throw error;
2210
process.exit(status as number);

bin/pact.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
#!/usr/bin/env node
22

3-
import childProcess = require('child_process');
4-
import {
5-
standalone,
6-
standaloneUseShell,
7-
setStandaloneArgs,
8-
} from '../src/pact-standalone';
3+
import { spawnSync, standalone } from '../src/pact-standalone';
94

10-
const args = process.argv.slice(2);
11-
const opts = standaloneUseShell ? { shell: true } : {};
12-
13-
const { error, status } = childProcess.spawnSync(
5+
const { error, status } = spawnSync(
146
standalone().pactFullPath,
15-
setStandaloneArgs(args, standaloneUseShell),
16-
{
17-
stdio: 'inherit',
18-
...opts,
19-
}
7+
process.argv.slice(2)
208
);
219
if (error) throw error;
2210
process.exit(status as number);

0 commit comments

Comments
 (0)