Skip to content

Commit 7b2e67c

Browse files
committed
Fix the order of additional arguments for npx.
fixes #1030
1 parent 4045aaf commit 7b2e67c

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/ArgumentsParser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ List<String> parse(String args) {
3939
}
4040

4141
final List<String> arguments = new LinkedList<>();
42+
final List<String> allArguments = new LinkedList<>();
4243
final StringBuilder argumentBuilder = new StringBuilder();
4344
Character quote = null;
4445

@@ -64,13 +65,15 @@ List<String> parse(String args) {
6465

6566
addArgument(argumentBuilder, arguments);
6667

68+
// Prepend additionalArguments before the other arguments
6769
for (String argument : this.additionalArguments) {
6870
if (!arguments.contains(argument)) {
69-
arguments.add(argument);
71+
allArguments.add(argument);
7072
}
7173
}
74+
allArguments.addAll(arguments);
7275

73-
return new ArrayList<>(arguments);
76+
return new ArrayList<>(allArguments);
7477
}
7578

7679
private static void addArgument(StringBuilder argumentBuilder, List<String> arguments) {

frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NpxRunner.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public DefaultNpxRunner(NodeExecutorConfig config, ProxyConfig proxyConfig, Stri
1616

1717
// Visible for testing only.
1818
/**
19-
* These are, in fact, npm arguments, that need to be split from the npx arguments by '--'.
19+
* These are, in fact, npm arguments, that need to come before the package arguments.
2020
*
2121
* See an example:
22-
* npx some-package -- --registry=http://myspecialregisty.com
22+
* npx --registry=http://myspecialregisty.com some-package
2323
*/
2424
static List<String> buildNpmArguments(ProxyConfig proxyConfig, String npmRegistryURL) {
2525
List<String> arguments = new ArrayList<>();
@@ -51,7 +51,6 @@ static List<String> buildNpmArguments(ProxyConfig proxyConfig, String npmRegistr
5151
npmArguments = arguments;
5252
} else {
5353
npmArguments = new ArrayList<>();
54-
npmArguments.add("--");
5554
npmArguments.addAll(arguments);
5655
}
5756

frontend-plugin-core/src/test/java/com/github/eirslett/maven/plugins/frontend/lib/ArgumentsParserTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ public void repeatedArgumentsAreAccepted() {
6060
public void testAdditionalArgumentsNoIntersection() {
6161
ArgumentsParser parser = new ArgumentsParser(Arrays.asList("foo", "bar"));
6262

63-
assertArrayEquals(new Object[] { "foobar", "foo", "bar" }, parser.parse("foobar").toArray());
63+
assertArrayEquals(new Object[] { "foo", "bar", "foobar" }, parser.parse("foobar").toArray());
6464
}
6565

6666
@Test
6767
public void testAdditionalArgumentsWithIntersection() {
6868
ArgumentsParser parser = new ArgumentsParser(Arrays.asList("foo", "foobar"));
6969

70-
assertArrayEquals(new Object[] { "bar", "foobar", "foo" }, parser.parse("bar foobar").toArray());
70+
assertArrayEquals(new Object[] { "foo", "bar", "foobar" }, parser.parse("bar foobar").toArray());
7171
}
7272
}

frontend-plugin-core/src/test/java/com/github/eirslett/maven/plugins/frontend/lib/DefaultNpxRunnerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void buildArgument_basicTest() {
2323
@Test
2424
public void buildArgument_withRegistryUrl() {
2525
List<String> arguments = DefaultNpxRunner.buildNpmArguments(new ProxyConfig(Collections.emptyList()), registryUrl);
26-
Assertions.assertEquals(2, arguments.size());
27-
assertThat(arguments, CoreMatchers.hasItems("--", "--registry=" + registryUrl));
26+
Assertions.assertEquals(1, arguments.size());
27+
assertThat(arguments, CoreMatchers.hasItems("--registry=" + registryUrl));
2828
}
2929
}

0 commit comments

Comments
 (0)