task-closure-tools

raw JSON →
0.1.10 verified Fri May 01 auth: no javascript maintenance

Core library for Google Closure Tools tasks, providing Compiler (JS minification using the Closure Compiler), Builder (concatenation and optional compilation), and DepsWriter (dependency graph generation for deps.js files). Current version 0.1.10, last updated June 2015 (infrequent updates). Primarily used as a base for Grunt plugins (grunt-closure-tools) and other build systems (Mantri). Differentiators: integrates directly with Google Closure Library ecosystem, supports Java-based Closure Compiler and Python-based DepsWriter, but node >=0.8.0 only, no modern ESM support.

error Error: Cannot find module 'task-closure-tools'
cause Package not installed or incorrect import path.
fix
Run npm install task-closure-tools and use require('task-closure-tools') or import { ... } from 'task-closure-tools'.
error Java not found. Please install Java.
cause Java Runtime Environment not installed or not in PATH.
fix
Install Java (JRE) version 8 or later and ensure java command is accessible.
error python: not found
cause Python not installed for DepsWriter.
fix
Install Python 2.7 (older, may work) or Python 3 and ensure python command is in PATH.
error TypeError: taskClosureTools is not a function
cause Using default import instead of named exports.
fix
Use named imports: import { Compiler, Builder, DepsWriter } from 'task-closure-tools'.
error Error: ENOENT: no such file or directory, open '.../closure-library/closure/goog/base.js'
cause Closure Library path not correctly configured or missing.
fix
Set closureLibraryPath option to the root of the installed google-closure-library package.
gotcha Package last updated June 2015; no longer actively maintained. May have compatibility issues with modern Node.js versions (>=10).
fix Consider using official Closure Compiler npm package 'google-closure-compiler' or other modern build tools.
gotcha Requires Java Runtime Environment (JRE) to run the Closure Compiler and Python to run DepsWriter. Not explicitly mentioned in npm metadata.
fix Ensure Java and Python are installed and available in PATH.
gotcha Closure Library path must be provided manually via options; package does not automatically resolve it.
fix Install google-closure-library and pass its path (e.g., './node_modules/google-closure-library').
gotcha Compiler and Builder options are passed directly to the underlying Java command; incorrect flags may cause silent failures.
fix Refer to official Closure Compiler documentation for valid compilation_level and other options.
npm install task-closure-tools
yarn add task-closure-tools
pnpm add task-closure-tools

Shows basic usage of Compiler, Builder, and DepsWriter for compilation, bundling, and dependency generation.

import { Compiler, Builder, DepsWriter } from 'task-closure-tools';

// Example: compile a single JS file
const compiler = new Compiler({
  closureLibraryPath: './node_modules/google-closure-library',
  bootstrap: false
});

compiler.compile({
  js: 'src/main.js',
  compilation_level: 'ADVANCED_OPTIMIZATIONS',
  js_output_file: 'dist/bundle.min.js',
  extra_annotation_name: 'api'
}, function(err, stdout, stderr) {
  if (err) { console.error('Compilation failed:', err); }
  else { console.log('Compilation succeeded:', stdout); }
});

// Builder: concatenate dependencies and optionally compile
const builder = new Builder({
  closureLibraryPath: './node_modules/google-closure-library'
});
builder.build({
  inputs: 'src/main.js',
  compile: true,
  output_file: 'dist/bundle.js'
}, function(err, stdout) {
  if (err) { console.error('Build failed:', err); }
  else { console.log('Build completed'); }
});

// DepsWriter: generate deps.js
const depsWriter = new DepsWriter({
  closureLibraryPath: './node_modules/google-closure-library'
});
depsWriter.writeDeps({
  root: ['src', 'test'],
  output_file: 'dist/deps.js'
}, function(err) {
  if (err) { console.error('Deps write failed:', err); }
  else { console.log('Deps written'); }
});