Skip to content

Commit 34e51c1

Browse files
committed
* Support an empty prefix location mapping name, relates to #65. An empty name matches all paths.
1 parent 77ab1e2 commit 34e51c1

File tree

9 files changed

+41
-6
lines changed

9 files changed

+41
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
See also the [closure compiler changelog](https://github.com/google/closure-compiler/wiki/Releases).
44

5+
## 2.30.0
6+
7+
* Support an empty prefix location mapping name, relates to #65. An empty name matches all paths.
8+
59
## 2.29.0
610

711
* Update to closure compiler `v20231112`

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Then we get the two output files
144144

145145
The source map `bundle.min.map.js` now references the source files as `../../src/webapp/js/index.js`. When your project directory structure resembles your directory structure on the server, then by default, every will just work. If the directory structure is diffrent, [closure compiler offers the option source_map_location_mapping](https://github.com/google/closure-compiler/wiki/Flags-and-Options). For this plugin, this is set with the option:
146146

147-
* [closureSourceMapLocationMappings](https://blutorange.github.io/closure-compiler-maven-plugin/minify-mojo.html#closureSourceMapLocationMappings): When the file name of a source file contains the given prefix, it is replaced with the specified replacement. Here the file name is as it was passed to closure compiler, ie. **relative** to the `sourceDir`
147+
* [closureSourceMapLocationMappings](https://blutorange.github.io/closure-compiler-maven-plugin/minify-mojo.html#closureSourceMapLocationMappings): When the file name of a source file contains the given prefix, it is replaced with the specified replacement. Here the file name is as it was passed to closure compiler, i.e. **relative** to the `sourceDir`
148148

149149
For the example above, this means that the source file name would be `js/index.js`. We could now set this option to replace `js/` with `https://example.com/sources/`. Now the source map contains a reference to the source file as `https://example.com/sources/index.js`.
150150

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>com.github.blutorange</groupId>
88
<artifactId>closure-compiler-maven-plugin</artifactId>
9-
<version>2.30.0-SNAPSHOT</version>
9+
<version>2.30.0</version>
1010
<packaging>maven-plugin</packaging>
1111

1212
<name>Closure Compiler Maven Plugin</name>

src/main/java/com/github/blutorange/maven/plugin/closurecompiler/common/ClosureConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import com.google.javascript.jscomp.SourceMap.LocationMapping;
4848
import com.google.javascript.jscomp.SourceMap.PrefixLocationMapping;
4949

50+
import static org.apache.commons.lang3.StringUtils.defaultString;
51+
5052
/**
5153
* <a href="https://developers.google.com/closure/compiler/">Google Closure Compiler</a> configuration.
5254
*/
@@ -57,7 +59,7 @@ public class ClosureConfig {
5759
private static final String FILE_PREFIX = "file:";
5860

5961
private static List<? extends LocationMapping> createLocationMappings(ArrayList<ClosureSourceMapLocationMapping> mappings) {
60-
return mappings.stream().map(e -> new PrefixLocationMapping(String.valueOf(e.getName()), String.valueOf(e.getValue()))).collect(Collectors.toList());
62+
return mappings.stream().map(e -> new PrefixLocationMapping(defaultString(e.getName()), defaultString(e.getValue()))).collect(Collectors.toList());
6163
}
6264

6365
private static CompilerOptions createCompilerOptions(MinifyMojo mojo) throws MojoFailureException {

src/main/java/com/github/blutorange/maven/plugin/closurecompiler/plugin/MinifyMojo.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ public class MinifyMojo extends AbstractMojo {
585585
* Source map location mapping. This is a prefix mapping from the file system path to the web
586586
* server path. The source map contains a reference to the original source files; and this may be
587587
* different on the web server. The location of the source file is always relative to the given
588-
* {@code baseDir}. This defines a list of replacements. For each source file, the first matching
588+
* {@code sourceDir}. This defines a list of replacements. For each source file, the first matching
589589
* replacement is used. If the source file starts with the prefix as given by the name, it matches
590590
* and is replaced with the value. For example:
591591
*
@@ -602,7 +602,8 @@ public class MinifyMojo extends AbstractMojo {
602602
* them with {@code /web/www/js/file1.js} and {@code /web/www/js/file2.js}. This is then path that
603603
* will be used in the source map to reference the original source file. If no location mappings
604604
* are specified, the path of the source files relative to the created source map is used instead.
605-
*
605+
*
606+
* If you set the name to an empty string, it matches all paths.
606607
* @since 2.5.0
607608
*/
608609
@Parameter(property = "closureSourceMapLocationMappings")

src/test/resources/projects/parent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14-
<closure.compiler.maven.plugin.version>2.30.0-SNAPSHOT</closure.compiler.maven.plugin.version>
14+
<closure.compiler.maven.plugin.version>2.30.0</closure.compiler.maven.plugin.version>
1515
</properties>
1616

1717
<dependencies>

src/test/resources/projects/sourcemap/expected/location-mapping-empty.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/resources/projects/sourcemap/expected/location-mapping-empty.js.map

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/resources/projects/sourcemap/pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,24 @@
8989
<outputFilename>location-mapping.js</outputFilename>
9090
</configuration>
9191
</execution>
92+
<execution>
93+
<id>location-mapping-empty</id>
94+
<phase>generate-resources</phase>
95+
<goals>
96+
<goal>minify</goal>
97+
</goals>
98+
<configuration>
99+
<closureSourceMapLocationMappings>
100+
<closureSourceMapLocationMapping>
101+
<name></name>
102+
<value>localhost://bazbar/</value>
103+
</closureSourceMapLocationMapping>
104+
</closureSourceMapLocationMappings>
105+
<closureSourceMapOutputType>reference</closureSourceMapOutputType>
106+
<sourceDir>test2/js</sourceDir>
107+
<outputFilename>location-mapping-empty.js</outputFilename>
108+
</configuration>
109+
</execution>
92110
<execution>
93111
<id>different-source-map-path</id>
94112
<phase>generate-resources</phase>

0 commit comments

Comments
 (0)