Skip to content

Commit 750e6df

Browse files
author
ntwigg
committed
Task like npm run lint:fix get turned into npm_run_lint-fix (so the colons don't screw up Gradle)
1 parent 9a8c581 commit 750e6df

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Webtools releases
22

33
## [Unreleased]
4+
### Added
5+
- Task like `npm run lint:fix` get turned into `npm_run_lint-fix` (so the colons don't screw up Gradle)
46

57
## [1.1.0] - 2024-08-04
68
### Added

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ node {
1717
inputs.dir('somedir').withPathSensitivity(PathSensitivity.RELATIVE)
1818
outputs.dir('build/some-output')
1919
}
20+
// if an npm script contains `:` it willbe transformed into `-`
21+
npm_run 'lint:fix', {} // becomes `npm_run_lint-fix`
2022
}
2123
```
2224

src/main/java/com/diffplug/webtools/node/NodePlugin.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 DiffPlug
2+
* Copyright (C) 2024-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -53,8 +53,8 @@ public Extension(Project project) {
5353
}
5454

5555
public TaskProvider<?> npm_run(String name, Action<NpmRunTask> taskConfig) {
56-
return project.getTasks().register("npm_run_" + name, NpmRunTask.class, task -> {
57-
task.taskName = name;
56+
return project.getTasks().register("npm_run_" + name.replace(':', '-'), NpmRunTask.class, task -> {
57+
task.npmTaskName = name;
5858
try {
5959
setup.nodeVersion = nvmRc(findNvmRc(project.getProjectDir()));
6060
setup.npmVersion = "provided";
@@ -75,12 +75,12 @@ public TaskProvider<?> npm_run(String name, Action<NpmRunTask> taskConfig) {
7575

7676
@CacheableTask
7777
public abstract static class NpmRunTask extends DefaultTask {
78-
public String taskName;
78+
public String npmTaskName;
7979
private TreeMap<String, String> environment = new TreeMap<>();
8080

8181
@Input
82-
public String getTaskName() {
83-
return taskName;
82+
public String getNpmTaskName() {
83+
return npmTaskName;
8484
}
8585

8686
@Input
@@ -101,7 +101,7 @@ public void npmCiRunTask() throws Exception {
101101
setup.start(getProjectDir().get().getAsFile());
102102
// run the gulp task
103103
ProxyConfig proxyConfig = new ProxyConfig(Collections.emptyList());
104-
setup.factory().getNpmRunner(proxyConfig, null).execute("run " + taskName, environment);
104+
setup.factory().getNpmRunner(proxyConfig, null).execute("run " + npmTaskName, environment);
105105
}
106106
}
107107

0 commit comments

Comments
 (0)