CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-google-closure-compiler

Node.js wrapper and build tool plugins for Google's Closure Compiler that compiles, optimizes, and compresses JavaScript code

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Google Closure Compiler

Google Closure Compiler is a Node.js wrapper and build tool integration for Google's Closure Compiler, providing JavaScript optimization, compilation, and compression with support for multiple compilation levels and runtime platforms (native binaries and Java).

Package Information

  • Package Name: google-closure-compiler
  • Package Type: npm
  • Language: JavaScript (ES Modules)
  • Installation: npm install google-closure-compiler
  • License: Apache-2.0

Core Imports

import ClosureCompiler, { 
  JAR_PATH, 
  CONTRIB_PATH, 
  EXTERNS_PATH,
  grunt,
  gulp,
  javaPath
} from "google-closure-compiler";

For CommonJS:

const ClosureCompiler = require("google-closure-compiler");
const { grunt, gulp, JAR_PATH } = require("google-closure-compiler");

Basic Usage

import ClosureCompiler from "google-closure-compiler";

// Basic compilation
const compiler = new ClosureCompiler({
  js: 'src/app.js',
  compilation_level: 'SIMPLE',
  js_output_file: 'dist/app.min.js'
});

compiler.run((exitCode, stdout, stderr) => {
  if (exitCode === 0) {
    console.log('Compilation successful');
  } else {
    console.error('Compilation failed:', stderr);
  }
});

Architecture

Google Closure Compiler npm package is built around several key components:

  • Core Compiler: Main Compiler class that wraps the Java or native binary
  • Build Tool Plugins: Integration with Grunt and Gulp build systems
  • Platform Detection: Automatic selection between native binaries and Java runtime
  • Stream Processing: Vinyl file stream support for build tool integration
  • Configuration Management: Flexible argument parsing and option handling

Capabilities

Core Compiler

Main compiler functionality for direct JavaScript compilation and optimization with support for various compilation levels and platform selection.

class Compiler {
  constructor(args: Object | Array<string>, extraCommandArgs?: Array<string>);
  run(callback?: (exitCode: number, stdout: string, stderr: string) => void): ChildProcess;
  getFullCommand(): string;
  formatArgument(key: string, val?: string | boolean): string;
}

Core Compiler

Command Line Interface

Executable command-line interface with argument parsing, platform selection, and direct compiler invocation.

// CLI executable available as: google-closure-compiler
// Supports all Closure Compiler flags plus:
// --platform: 'native' | 'java' | 'native,java'

Command Line Interface

Grunt Plugin

Grunt task integration for automated builds with support for multiple file sets and parallel compilation.

function gruntPlugin(grunt: any, pluginOptions?: {
  platform?: string | Array<string>;
  extraArguments?: Array<string>;
  max_parallel_compilations?: number;
}): Function;

Grunt Integration

Gulp Plugin

Gulp plugin providing stream-based compilation with vinyl file support and source map integration.

function gulpPlugin(
  compilationOptions: Object | Array<string>,
  pluginOptions?: {
    streamMode?: 'BOTH' | 'IN';
    logger?: any;
    pluginName?: string;
    platform?: string | Array<string>;
    requireStreamInput?: boolean;
  }
): CompilationStream;

Gulp Integration

Utility Functions

Platform detection and native binary utilities for determining compiler availability. These are internal utilities used by the CLI and build plugins.

// Internal utilities (not exported from main module)
// Available from: import { getNativeImagePath, getFirstSupportedPlatform } from 'google-closure-compiler/lib/utils.js';

/**
 * Get path to native binary compiler for current platform
 * @returns Path to native compiler binary or undefined if not available
 */
function getNativeImagePath(): string | undefined;

/**
 * Get first supported platform from preference list
 * @param platforms - Array of platform preferences ('native' | 'java')
 * @returns First available platform
 * @throws Error if no platform is supported
 */
function getFirstSupportedPlatform(platforms: Array<'native' | 'java'>): 'native' | 'java';

Constants and Paths

// Compiler JAR file path (when using Java platform)
const JAR_PATH: string;

// Path to contrib directory containing additional resources
const CONTRIB_PATH: string;

// Path to externs directory containing type definitions
const EXTERNS_PATH: string;

// Default Java executable path
const javaPath: string;

Types

interface CompilerOptions {
  // Input/Output
  js?: string | Array<string>;
  js_output_file?: string;
  externs?: string | Array<string>;
  
  // Compilation
  compilation_level?: 'WHITESPACE_ONLY' | 'SIMPLE' | 'ADVANCED';
  language_in?: 'ECMASCRIPT3' | 'ECMASCRIPT5' | 'ECMASCRIPT_2015' | 'ECMASCRIPT_2017' | 'ECMASCRIPT_2018' | 'ECMASCRIPT_2019' | 'ECMASCRIPT_2020' | 'ECMASCRIPT_NEXT';
  language_out?: 'ECMASCRIPT3' | 'ECMASCRIPT5' | 'ECMASCRIPT_2015' | 'ECMASCRIPT_2017' | 'ECMASCRIPT_2018' | 'ECMASCRIPT_2019' | 'ECMASCRIPT_2020';
  
  // Modules and Resolution
  module_resolution?: 'BROWSER' | 'NODE' | 'WEBPACK';
  process_common_js_modules?: boolean;
  entry_point?: string | Array<string>;
  
  // Source Maps
  create_source_map?: boolean | string;
  source_map_format?: 'DEFAULT' | 'V3';
  source_map_location_mapping?: Array<string>;
  
  // Output Formatting
  output_wrapper?: string;
  output_manifest?: string;
  formatting?: 'PRETTY_PRINT' | 'PRINT_INPUT_DELIMITER' | 'SINGLE_QUOTES';
  
  // Warnings and Debugging
  warning_level?: 'QUIET' | 'DEFAULT' | 'VERBOSE';
  debug?: boolean;
  checks_only?: boolean;
  
  // Advanced Options
  define?: Array<string>;
  jscomp_warning?: string;
  jscomp_error?: string;
  
  [key: string]: any; // All Closure Compiler flags supported
}

interface PlatformOptions {
  platform?: 'native' | 'java' | Array<'native' | 'java'>;
  extraArguments?: Array<string>;
}

interface CompilerCallbackResult {
  exitCode: number;
  stdout: string;
  stderr: string;
}

// Error types
interface PluginError extends Error {
  plugin: string;
  message: string;
  cause?: Error;
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/google-closure-compiler@20250901.0.x
Publish Source
CLI
Badge
tessl/npm-google-closure-compiler badge