API for cljs.closure - clojurescript


Full namespace name: cljs.closure

Overview

Compile ClojureScript to JavaScript with optimizations from Google
 Closure Compiler producing runnable JavaScript.

 The Closure Compiler (compiler.jar) must be on the classpath.

 Use the 'build' function for end-to-end compilation.

 build = find-sources -> add-dependencies -> compile -> optimize -> output

 Two protocols are defined: IJavaScript and Compilable. The
 Compilable protocol is satisfied by something which can return one
 or more IJavaScripts.

 With IJavaScript objects in hand, calling add-dependencies will
 produce a sequence of IJavaScript objects which includes all
 required dependencies from the Closure library and ClojureScript,
 in dependency order. This function replaces the closurebuilder
 tool.

 The optimize function converts one or more IJavaScripts into a
 single string of JavaScript source code using the Closure Compiler
 API.

 The produced output is either a single string of optimized
 JavaScript or a deps file for use during development.

Protocols



Compilable

Protocol

    Known implementations: clojure.lang.PersistentList, clojure.lang.PersistentVector, java.io.File, java.lang.String, java.net.URL
    

-compile

function
Usage: (-compile this opts)
Returns one or more IJavaScripts.

      
      
      
    

-find-sources

function
Usage: (-find-sources this opts)
Returns one or more IJavascripts, without compiling them.

      
      
      
    


ISourceMap

Protocol

    Known implementations: JavaScriptFile
    

-source-map

function
Usage: (-source-map this)
Return the CLJS compiler generated JS source mapping

      
      
      
    

-source-url

function
Usage: (-source-url this)
Return the CLJS source url

      
      
      
    


Inputs

Protocol

    Known implementations: java.io.File, java.lang.String
    

-paths

function
Usage: (-paths this)
Returns the file paths to the source inputs

      
      
      
    

Types



JavaScriptFile

record

    Fields: [foreign url source-url provides requires lines source-map]
Protocols: ISourceMap, cljs.js-deps/IJavaScript
Interfaces: clojure.lang.IHashEq, clojure.lang.IKeywordLookup, clojure.lang.ILookup, clojure.lang.IObj, clojure.lang.IPersistentMap, java.io.Serializable, java.util.Map

Public Variables and Functions



->JavaScriptFile

function
Usage: (->JavaScriptFile foreign url source-url provides requires lines source-map)
Positional factory function for class cljs.closure.JavaScriptFile.

    
    
    
  


add-dep-string

function
Usage: (add-dep-string opts input)
Return a goog.addDependency string for an input.

    
    
    
  


add-dependencies

function
Usage: (add-dependencies opts & inputs)
Given one or more IJavaScript objects in dependency order, produce
a new sequence of IJavaScript objects which includes the input list
plus all dependencies in dependency order.

    
    
    
  


add-dependency-sources

function
Usage: (add-dependency-sources inputs)
       (add-dependency-sources inputs compile-opts)
Given list of IJavaScript objects, produce a new sequence of IJavaScript objects
of all dependencies of inputs.

    
    
    
  


add-js-sources

function
Usage: (add-js-sources inputs opts)
Given list of IJavaScript objects, add foreign-deps, constants-table
IJavaScript objects to the list.

    
    
    
  


add-preloads

function
Usage: (add-preloads inputs opts)
Add :preloads to a given set of inputs (IJavaScript). Returns a new
list of inputs where the preloaded namespaces and their deps come immediately after
cljs.core or the constants table depending on the optimization setting. Any
files needing copying or compilation will be compiled and/or copied to the
appropiate location.

    
    
    
  


build

function
Usage: (build source opts)
       (build source opts compiler-env)
Given a source which can be compiled, produce runnable JavaScript.

    
    
    
  


build-modules

function
Usage: (build-modules sources opts)
Given a list of IJavaScript sources in dependency order and compiler options
return a dependency sorted list of module name / description tuples. The
module descriptions will be augmented with a :closure-module entry holding
the Closure JSModule. Each module description will also be augmented with
a :foreign-deps vector containing foreign IJavaScript sources in dependency
order.

    
    
    
  


build-provides

function
Usage: (build-provides provides)
Given a vector of provides, builds required goog.provide statements

    
    
    
  


cljs-dependencies

function
Usage: (cljs-dependencies opts requires)
Given a list of all required namespaces, return a list of
IJavaScripts which are the cljs dependencies. The returned list will
not only include the explicitly required files but any transitive
dependencies as well. JavaScript files will be compiled to the
working directory if they do not already exist.

Only load dependencies from the classpath.

    
    
    
  


cljs-source-for-namespace

function
Usage: (cljs-source-for-namespace ns)
Given a namespace return the corresponding source with either a .cljs or
.cljc extension.

    
    
    
  


compile

function
Usage: (compile compilable opts)
Given a Compilable, compile it and return an IJavaScript.

    
    
    
  


compile-dir

function
Usage: (compile-dir src-dir opts)
Recursively compile all cljs files under the given source
directory. Return a list of JavaScriptFiles.

    
    
    
  


compile-file

function
Usage: (compile-file file {:keys [output-file], :as opts})
Compile a single cljs file. If no output-file is specified, returns
a string of compiled JavaScript. With an output-file option, the
compiled JavaScript will written to this location and the function
returns a JavaScriptFile. In either case the return value satisfies
IJavaScript.

    
    
    
  


compile-form-seq

function
Usage: (compile-form-seq forms)
Compile a sequence of forms to a JavaScript source string.

    
    
    
  


compile-from-jar

function
Usage: (compile-from-jar jar-file {:keys [output-file], :as opts})
Compile a file from a jar if necessary. Returns IJavaScript.

    
    
    
  


compile-sources

function
Usage: (compile-sources inputs opts)
       (compile-sources inputs compiler-stats opts)
Takes dependency ordered list of IJavaScript compatible maps from parse-ns
and compiles them.

    
    
    
  


compiled-file

function
Usage: (compiled-file m)
Given a map with at least a :file key, return a map with
{:file .. :provides .. :requires ..}.

Compiled files are cached so they will only be read once.

    
    
    
  


convert-js-module

multimethod
No usage documentation available
Takes a JavaScript module as an IJavaScript and rewrites it into a Google
Closure-compatible form. Returns an IJavaScript with the converted module
code set as source.

    
    
    
  


deps-file

function
Usage: (deps-file opts sources)
Return a deps file string for a sequence of inputs.

    
    
    
  


emit-optimized-source-map

function
Usage: (emit-optimized-source-map sm-json sources name opts)
Given a JSON parsed Google Closure JavaScript to JavaScript source map,
the entire list of original IJavaScript sources output a merged JavaScript
to ClojureScript source map file with the given file name. opts should
supply :preamble-line-count and :foreign-deps-line-count if they are
relevant.

    
    
    
  


find-cljs-dependencies

function
Usage: (find-cljs-dependencies requires)
Given set of cljs namespace symbols, find IJavaScript objects for the namespaces.

    
    
    
  


get-compiled-cljs

function
Usage: (get-compiled-cljs opts {:keys [relative-path uri]})
Return an IJavaScript for this file. Compiled output will be
written to the working directory.

    
    
    
  


get-upstream-deps*

function
Usage: (get-upstream-deps*)
       (get-upstream-deps* classloader)
returns a merged map containing all upstream dependencies defined
by libraries on the classpath.

    
    
    
  


jar-file-to-disk

function
Usage: (jar-file-to-disk url out-dir)
       (jar-file-to-disk url out-dir opts)
Copy a file contained within a jar to disk. Return the created file.

    
    
    
  


js-dependencies

function
Usage: (js-dependencies opts requires)
Given a sequence of Closure namespace strings, return the list of
all dependencies. The returned list includes all Google and
third-party library dependencies.

Third-party libraries are configured using the :libs option where
the value is a list of directories containing third-party
libraries.

    
    
    
  


js-transforms

multimethod
No usage documentation available
Takes an IJavaScript with the source code set as source, transforms the
source code and returns an IJavascript with the new code set as source.

    
    
    
  


known-opts

var

    
Set of all known compiler options.

    
    
    
  


load-externs

function
Usage: (load-externs {:keys [externs use-only-custom-externs target ups-externs]})
Externs are JavaScript files which contain empty definitions of
functions which will be provided by the environment. Any function in
an extern file will not be renamed during optimization.

Options may contain an :externs key with a list of file paths to
load. The :use-only-custom-externs flag may be used to indicate that
the default externs should be excluded.

    
    
    
  


make-options

function
Usage: (make-options opts)
Create a CompilerOptions object and set options from opts map.

    
    
    
  


map->JavaScriptFile

function
Usage: (map->JavaScriptFile m#)
Factory function for class cljs.closure.JavaScriptFile, taking a map of keywords to field values.

    
    
    
  


optimize

function
Usage: (optimize opts & sources)
Use the Closure Compiler to optimize one or more JavaScript files.

    
    
    
  


optimize-modules

function
Usage: (optimize-modules opts & sources)
Use the Closure Compiler to optimize one or more Closure JSModules. Returns
a dependency sorted list of module name and description tuples.

    
    
    
  


output-modules

function
Usage: (output-modules opts js-sources modules)
Given compiler options, original IJavaScript sources and a sequence of
module name and module description tuples output module sources to disk.
Modules description must define :output-to and supply :source entry with
the JavaScript source to write to disk.

    
    
    
  


output-unoptimized

function
Usage: (output-unoptimized opts & sources)
Ensure that all JavaScript source files are on disk (not in jars),
write the goog deps file including only the libraries that are being
used and write the deps file for the current project.

The deps file for the current project will include third-party
libraries.

    
    
    
  


path-from-jarfile

function
Usage: (path-from-jarfile url)
Given the URL of a file within a jar, return the path of the file
from the root of the jar.

    
    
    
  


path-relative-to

function
Usage: (path-relative-to base input)
Generate a string which is the path to the input IJavaScript relative
to the specified base file.

    
    
    
  


process-js-modules

function
Usage: (process-js-modules opts)
Given the current compiler options, converts JavaScript modules to Google
Closure modules and writes them to disk. Adds mapping from original module
namespace to new module namespace to compiler env. Returns modified compiler
options where new modules are passed with :libs option.

    
    
    
  


read-js

function
Usage: (read-js f)
Read a JavaScript file returning a map of file information.

    
    
    
  


rel-output-path

function
Usage: (rel-output-path js)
       (rel-output-path js opts)
Given an IJavaScript which is either in memory, in a jar file,
or is a foreign lib, return the path relative to the output
directory.

    
    
    
  


set-options

function
Usage: (set-options opts compiler-options)
TODO: Add any other options that we would like to support.

    
    
    
  


source-for-namespace

function
Usage: (source-for-namespace ns compiler-env)
Given a namespace and compilation environment return the relative path and
uri of the corresponding source regardless of the source language extension:
.cljs, .cljc, .js

    
    
    
  


source-on-disk

function
Usage: (source-on-disk opts js)
Ensure that the given IJavaScript exists on disk in the output directory.
Return updated IJavaScript with the new location if necessary.

    
    
    
  


watch

function
Usage: (watch source opts)
       (watch source opts compiler-env)
       (watch source opts compiler-env quit)
Given a source directory, produce runnable JavaScript. Watch the source
directory for changes rebuliding when necessary. Takes the same arguments as
cljs.closure/build in addition to :watch-fn, a function of no arguments to
run after a successful build.

    
    
    
  


write-javascript

function
Usage: (write-javascript opts js)
Write or copy a JavaScript file to output directory. Only write if the file
does not already exist. Return IJavaScript for the file on disk at the new
location.

    
    
    
  


write-js?

function
Usage: (write-js? js)
Returns true if IJavaScript instance needs to be written/copied to output
directory. True when in memory, in a JAR, or if foreign library.

    
    
    
  
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.