diff --git a/README.md b/README.md index 1afe900..620222d 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,7 @@ JSDoc 3 options: - *(Must declare this or `requirejs.options`)* requirejs.buildprofile = File reference for config [example](https://github.com/eriwen/gradle-js-plugin/blob/master/src/test/resources/requirejs/build.js) - requirejs.options = Map of options [require.js docs](http://requirejs.org/docs/optimization.html#options) - *(Optional)* ignoreExitCode = Fail build if `false` and require.js did not run successfully. Default is `false`. +- *(Optional)* impl = r.js implementation file. Version 2.1.4 is provided within this plugin. Specifying this option allows users to specify a version of the require optimizer of their own choosing What, you want more? [Tell me!](https://github.com/eriwen/gradle-js-plugin/issues) @@ -184,6 +185,7 @@ This project is made possible due to the efforts of these fine people: * Martin Ziel - Allowing minifyJs task to accept multiple files as input * [Joe Fitzgerald](https://github.com/joefitzgerald) - JSHint and RequireJS features * [levsa](https://github.com/levsa) - JSHint predef and checkstyle reporter +* [Martin Snyder](https://github.com/MartinSnyder) - requireJs impl option ## See Also The [Gradle CSS Plugin](https://github.com/eriwen/gradle-css-plugin)! diff --git a/src/main/groovy/com/eriwen/gradle/js/tasks/RequireJsTask.groovy b/src/main/groovy/com/eriwen/gradle/js/tasks/RequireJsTask.groovy index e5e178c..0017952 100644 --- a/src/main/groovy/com/eriwen/gradle/js/tasks/RequireJsTask.groovy +++ b/src/main/groovy/com/eriwen/gradle/js/tasks/RequireJsTask.groovy @@ -24,6 +24,7 @@ import org.gradle.api.tasks.OutputFile class RequireJsTask extends SourceTask { private static final String REQUIREJS_PATH = 'r.js' + private static final String REQUIREJS_IMPLEMENTATION_OPTION = "impl" private static final String TMP_DIR = "tmp${File.separator}js" private static final ResourceUtil RESOURCE_UTIL = new ResourceUtil() private final RhinoExec rhino = new RhinoExec(project) @@ -37,10 +38,19 @@ class RequireJsTask extends SourceTask { @TaskAction def run() { - final File requireJsFile = RESOURCE_UTIL.extractFileToDirectory(new File(project.buildDir, TMP_DIR), REQUIREJS_PATH) LinkedHashMap options = [] // [optimize: "none", logLevel: 2, skipModuleInsertion: false, out: dest] options.putAll(project.requirejs.options) + final File requireJsFile + if (options.containsKey(REQUIREJS_IMPLEMENTATION_OPTION)) { + requireJsFile = new File(options.get(REQUIREJS_IMPLEMENTATION_OPTION)) + + // This option applies to the task itself, and does not need to be passed on to Rhino or the r.js script itself + options.remove(REQUIREJS_IMPLEMENTATION_OPTION) + } else { + requireJsFile = RESOURCE_UTIL.extractFileToDirectory(new File(project.buildDir, TMP_DIR), REQUIREJS_PATH) + } + final List args = [requireJsFile.canonicalPath] args.add("-o") if (project.requirejs.buildprofile != null && project.requirejs.buildprofile.class == File && project.requirejs.buildprofile.exists()) { diff --git a/src/test/groovy/com/eriwen/gradle/js/RequireJsTaskTest.groovy b/src/test/groovy/com/eriwen/gradle/js/RequireJsTaskTest.groovy index 6c25bc8..83eac55 100644 --- a/src/test/groovy/com/eriwen/gradle/js/RequireJsTaskTest.groovy +++ b/src/test/groovy/com/eriwen/gradle/js/RequireJsTaskTest.groovy @@ -50,6 +50,34 @@ class RequireJsTaskTest extends Specification { ExecException e = thrown() } + def "runWithInvalidRequireImplementation"() { + given: + project.requirejs.options = [baseUrl: ".", "paths.jquery": "jam/jquery/dist/jquery", name: "main", out: "main-built.js", "impl": "bad.r.js"] + task.ignoreExitCode = false + addMainFile() + addJamDir() + + when: + task.run() + + then: + ExecException e = thrown() + } + + def "runWithAlternateRequireImplementation"() { + given: + project.requirejs.options = [baseUrl: ".", "paths.jquery": "jam/jquery/dist/jquery", name: "main", out: "main-built.js", "impl": "src/test/resources/requirejs/r.2.1.4.js"] + task.ignoreExitCode = false + addMainFile() + addJamDir() + + when: + task.run() + + then: + notThrown ExecException + } + def "runWithBuildProfile"() { given: project.requirejs.buildprofile = new File("${project.projectDir.absolutePath}${File.separator}build.js")