From 7b2e67c6897bdcff0e1d92221eafae8b525ecd2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20Rosen=C3=B6gger?= <123haynes@gmail.com> Date: Sat, 4 Nov 2023 18:49:12 +0100 Subject: [PATCH] Fix the order of additional arguments for npx. fixes #1030 --- .../maven/plugins/frontend/lib/ArgumentsParser.java | 7 +++++-- .../eirslett/maven/plugins/frontend/lib/NpxRunner.java | 5 ++--- .../maven/plugins/frontend/lib/ArgumentsParserTest.java | 4 ++-- .../maven/plugins/frontend/lib/DefaultNpxRunnerTest.java | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/ArgumentsParser.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/ArgumentsParser.java index b18ad6c0f..bd917e927 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/ArgumentsParser.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/ArgumentsParser.java @@ -39,6 +39,7 @@ List parse(String args) { } final List arguments = new LinkedList<>(); + final List allArguments = new LinkedList<>(); final StringBuilder argumentBuilder = new StringBuilder(); Character quote = null; @@ -64,13 +65,15 @@ List parse(String args) { addArgument(argumentBuilder, arguments); + // Prepend additionalArguments before the other arguments for (String argument : this.additionalArguments) { if (!arguments.contains(argument)) { - arguments.add(argument); + allArguments.add(argument); } } + allArguments.addAll(arguments); - return new ArrayList<>(arguments); + return new ArrayList<>(allArguments); } private static void addArgument(StringBuilder argumentBuilder, List arguments) { diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NpxRunner.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NpxRunner.java index b4f4db1d3..7380c6808 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NpxRunner.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NpxRunner.java @@ -16,10 +16,10 @@ public DefaultNpxRunner(NodeExecutorConfig config, ProxyConfig proxyConfig, Stri // Visible for testing only. /** - * These are, in fact, npm arguments, that need to be split from the npx arguments by '--'. + * These are, in fact, npm arguments, that need to come before the package arguments. * * See an example: - * npx some-package -- --registry=http://myspecialregisty.com + * npx --registry=http://myspecialregisty.com some-package */ static List buildNpmArguments(ProxyConfig proxyConfig, String npmRegistryURL) { List arguments = new ArrayList<>(); @@ -51,7 +51,6 @@ static List buildNpmArguments(ProxyConfig proxyConfig, String npmRegistr npmArguments = arguments; } else { npmArguments = new ArrayList<>(); - npmArguments.add("--"); npmArguments.addAll(arguments); } diff --git a/frontend-plugin-core/src/test/java/com/github/eirslett/maven/plugins/frontend/lib/ArgumentsParserTest.java b/frontend-plugin-core/src/test/java/com/github/eirslett/maven/plugins/frontend/lib/ArgumentsParserTest.java index f92e89da3..b7b49c06a 100644 --- a/frontend-plugin-core/src/test/java/com/github/eirslett/maven/plugins/frontend/lib/ArgumentsParserTest.java +++ b/frontend-plugin-core/src/test/java/com/github/eirslett/maven/plugins/frontend/lib/ArgumentsParserTest.java @@ -60,13 +60,13 @@ public void repeatedArgumentsAreAccepted() { public void testAdditionalArgumentsNoIntersection() { ArgumentsParser parser = new ArgumentsParser(Arrays.asList("foo", "bar")); - assertArrayEquals(new Object[] { "foobar", "foo", "bar" }, parser.parse("foobar").toArray()); + assertArrayEquals(new Object[] { "foo", "bar", "foobar" }, parser.parse("foobar").toArray()); } @Test public void testAdditionalArgumentsWithIntersection() { ArgumentsParser parser = new ArgumentsParser(Arrays.asList("foo", "foobar")); - assertArrayEquals(new Object[] { "bar", "foobar", "foo" }, parser.parse("bar foobar").toArray()); + assertArrayEquals(new Object[] { "foo", "bar", "foobar" }, parser.parse("bar foobar").toArray()); } } diff --git a/frontend-plugin-core/src/test/java/com/github/eirslett/maven/plugins/frontend/lib/DefaultNpxRunnerTest.java b/frontend-plugin-core/src/test/java/com/github/eirslett/maven/plugins/frontend/lib/DefaultNpxRunnerTest.java index d1618024b..f2fbd03df 100644 --- a/frontend-plugin-core/src/test/java/com/github/eirslett/maven/plugins/frontend/lib/DefaultNpxRunnerTest.java +++ b/frontend-plugin-core/src/test/java/com/github/eirslett/maven/plugins/frontend/lib/DefaultNpxRunnerTest.java @@ -23,7 +23,7 @@ public void buildArgument_basicTest() { @Test public void buildArgument_withRegistryUrl() { List arguments = DefaultNpxRunner.buildNpmArguments(new ProxyConfig(Collections.emptyList()), registryUrl); - Assertions.assertEquals(2, arguments.size()); - assertThat(arguments, CoreMatchers.hasItems("--", "--registry=" + registryUrl)); + Assertions.assertEquals(1, arguments.size()); + assertThat(arguments, CoreMatchers.hasItems("--registry=" + registryUrl)); } }