Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ampproject/google-closure-compiler

Package Overview
Dependencies
Maintainers
16
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ampproject/google-closure-compiler - npm Package Compare versions

Comparing version 20210406.0.0 to 20210601.0.0

lib/gulp/concat-to-json.js

28

cli.js

@@ -18,5 +18,29 @@ #!/usr/bin/env node

'use strict';
const fs = require('fs');
const path = require('path');
const {getNativeImagePath, getFirstSupportedPlatform} = require('./lib/utils');
const parseArgs = require('minimist');
/** @see https://stackoverflow.com/a/40686853/1211524 */
function mkDirByPathSync(targetDir, {isRelativeToScript = false} = {}) {
const sep = path.sep;
const initDir = path.isAbsolute(targetDir) ? sep : '';
const baseDir = isRelativeToScript ? __dirname : '.';
targetDir.split(sep).reduce((parentDir, childDir) => {
const curDir = path.resolve(baseDir, parentDir, childDir);
try {
if (!fs.existsSync(curDir)) {
fs.mkdirSync(curDir);
}
} catch (err) {
if (err.code !== 'EEXIST') {
throw err;
}
}
return curDir;
}, initDir);
}
const compilerFlags = parseArgs(process.argv.slice(2));

@@ -28,3 +52,3 @@

if (compilerFlags.hasOwnProperty('platform')) {
platform = compilerFlags.platform;
platform = getFirstSupportedPlatform(compilerFlags.platform.split(','));
delete compilerFlags.platform;

@@ -56,3 +80,3 @@ } else {

// convert them to true booleans.
Object.keys(compilerFlags).forEach(flag => {
Object.keys(compilerFlags).forEach((flag) => {
if (compilerFlags[flag] === 'true') {

@@ -59,0 +83,0 @@ compilerFlags[flag] = true;

191

lib/gulp/index.js

@@ -29,15 +29,4 @@ /*

"use strict";
'use strict';
const stringifyFiles = require("./stringify-files");
const jsonToVinyl = require("./json-to-vinyl");
const stream = require("stream");
const { getNativeImagePath, getFirstSupportedPlatform } = require("../utils");
/** @const */
const PLUGIN_NAME = "gulp-google-closure-compiler";
const applySourceMap = require("vinyl-sourcemaps-apply");
const kleur = require("kleur");
const File = require("vinyl");
/**

@@ -53,5 +42,3 @@ * Rethrow an error with a custom message.

// Compose both the current stack and the original stack
this.stack = `${this.stack.split("\n").slice(0, 2).join("\n")}\n${
message.stack
}`;
this.stack = `${this.stack.split('\n').slice(0,2).join('\n')}\n${message.stack}`;
} else {

@@ -67,11 +54,20 @@ super(`${plugin}: ${message}`);

*/
module.exports = function (initOptions) {
const extraCommandArguments = initOptions
? initOptions.extraArguments
: undefined;
module.exports = function(initOptions) {
const filesToJson = require('./concat-to-json');
const jsonToVinyl = require('./json-to-vinyl');
const stream = require('stream');
const {getNativeImagePath, getFirstSupportedPlatform} = require('../utils');
/** @const */
const PLUGIN_NAME = 'gulp-google-closure-compiler';
const applySourceMap = require('vinyl-sourcemaps-apply');
const kleur = require('kleur');
const File = require('vinyl');
const extraCommandArguments = initOptions ? initOptions.extraArguments : undefined;
let PluginError;
try {
PluginError = require("gulp-util").PluginError;
} catch (e) {
PluginError = require('gulp-util').PluginError;
} catch(e) {
PluginError = CustomError;

@@ -82,4 +78,4 @@ }

try {
gulpLog = require("gulp-util").log;
} catch (e) {
gulpLog = require('gulp-util').log;
} catch(e) {
gulpLog = console;

@@ -89,3 +85,3 @@ }

function getCompiler(platform) {
return require("../node/closure-compiler");
return require('../node/closure-compiler');
}

@@ -95,7 +91,7 @@

constructor(compilationOptions, pluginOptions) {
super({ objectMode: true });
super({objectMode: true});
pluginOptions = pluginOptions || {};
this.compilationOptions_ = compilationOptions;
this.streamMode_ = pluginOptions.streamMode || "BOTH";
this.streamMode_ = pluginOptions.streamMode || 'BOTH';
this.logger_ = pluginOptions.logger || gulpLog;

@@ -107,6 +103,3 @@ this.PLUGIN_NAME_ = pluginOptions.pluginName || PLUGIN_NAME;

let platforms = (pluginOptions && pluginOptions.platform) || [
"native",
"java",
];
let platforms = (pluginOptions && pluginOptions.platform) || ['native', 'java'];
if (!Array.isArray(platforms)) {

@@ -121,7 +114,5 @@ platforms = [platforms];

process.nextTick(() => {
const stdInStream = new stream.Readable({
read: function () {
return new File();
},
});
const stdInStream = new stream.Readable({ read: function() {
return new File();
}});
stdInStream.pipe(this);

@@ -141,6 +132,3 @@ stdInStream.push(null);

if (file.isStream()) {
this.emit(
"error",
new PluginError(this.PLUGIN_NAME_, "Streaming not supported")
);
this.emit('error', new PluginError(this.PLUGIN_NAME_, 'Streaming not supported'));
cb();

@@ -150,6 +138,2 @@ return;

if (file.sourceMap && this.platform === "javascript") {
this.compilationOptions_.createSourceMap = true;
}
this.fileList_.push(file);

@@ -160,13 +144,26 @@ cb();

_flush(cb) {
let jsonFiles;
if (this.fileList_.length > 0) {
// Input files are present. Convert them to a JSON encoded string
jsonFiles = filesToJson(this.fileList_);
} else {
// If files in the stream were required, no compilation needed here.
if (this._streamInputRequired) {
this.push(null);
cb();
return;
}
// The compiler will always expect something on standard-in. So pass it an empty
// list if no files were piped into this plugin.
jsonFiles = [];
}
const Compiler = getCompiler(this.platform);
const compiler = new Compiler(
this.compilationOptions_,
extraCommandArguments
);
if (this.platform === "native") {
const compiler = new Compiler(this.compilationOptions_, extraCommandArguments);
if (this.platform === 'native') {
compiler.JAR_PATH = null;
compiler.javaPath = getNativeImagePath();
}
let stdOutData = "";
let stdErrData = "";
let stdOutData = '';
let stdErrData = '';

@@ -176,23 +173,18 @@ // Add the gulp-specific argument so the compiler will understand the JSON encoded input

// a stream mode of 'IN'
compiler.commandArguments.push("--json_streams", this.streamMode_);
compiler.commandArguments.push('--json_streams', this.streamMode_);
const compilerProcess = compiler.run();
compilerProcess.stdout.on("data", (data) => {
compilerProcess.stdout.on('data', data => {
stdOutData += data;
});
compilerProcess.stderr.on("data", (data) => {
compilerProcess.stderr.on('data', data => {
stdErrData += data;
});
// Error events occur when there was a problem spawning the compiler process
compilerProcess.on("error", (err) => {
this.emit(
"error",
new PluginError(
this.PLUGIN_NAME_,
"Process spawn error. Is java in the path?\n" + err.message
)
);
compilerProcess.on('error', err => {
this.emit('error', new PluginError(this.PLUGIN_NAME_,
'Process spawn error. Is java in the path?\n' + err.message));
cb();
});
compilerProcess.stdin.on("error", (err) => {
compilerProcess.stdin.on('error', err => {
stdErrData += `Error writing to stdin of the compiler. ${err.message}`;

@@ -202,44 +194,39 @@ });

Promise.all([
new Promise((resolve) => compilerProcess.on("close", resolve)),
new Promise((resolve) => compilerProcess.stdout.on("end", resolve)),
new Promise((resolve) => compilerProcess.stderr.on("end", resolve)),
])
.then((results) => {
const code = results[0];
new Promise(resolve => compilerProcess.on('close', resolve)),
new Promise(resolve => compilerProcess.stdout.on('end', resolve)),
new Promise(resolve => compilerProcess.stderr.on('end', resolve))
]).then(results => {
const code = results[0];
// If present, standard output will be a string of JSON encoded files.
// Convert these back to vinyl
let outputFiles = [];
if (stdOutData.trim().length > 0) {
// stdOutData = stdOutData.substr(stdOutData.indexOf('{'));
try {
outputFiles = JSON.parse(stdOutData);
} catch (e) {
this.emit(
"error",
new PluginError(
this.PLUGIN_NAME_,
"Error parsing json encoded files"
)
);
cb();
return;
}
// If present, standard output will be a string of JSON encoded files.
// Convert these back to vinyl
let outputFiles = [];
if (stdOutData.trim().length > 0) {
if (code !== 0) {
this.emit('error', new PluginError(this.PLUGIN_NAME_, 'Compiler error.\n' + stdOutData + '\n' + stdErrData));
cb();
return;
}
// stdOutData = stdOutData.substr(stdOutData.indexOf('{'));
try {
outputFiles = JSON.parse(stdOutData);
} catch (e) {
this.emit('error', new PluginError(this.PLUGIN_NAME_, 'Error parsing json encoded files'));
cb();
return;
}
}
this._compilationComplete(code, outputFiles, stdErrData);
cb();
})
.catch((err) => {
this.emit(
"error",
new PluginError(this.PLUGIN_NAME_, err, { showStack: true })
);
cb();
});
this._compilationComplete(code, outputFiles, stdErrData);
cb();
}).catch(err => {
this.emit('error', new PluginError(this.PLUGIN_NAME_, err, { showStack: true }));
cb();
});
const stdInStream = new stream.Readable({ read: function () {} });
const stdInStream = new stream.Readable({ read: function() {}});
stdInStream.pipe(compilerProcess.stdin);
process.nextTick(() => {
stdInStream.push(stringifyFiles(this.fileList_));
stdInStream.push(JSON.stringify(jsonFiles));
stdInStream.push(null);

@@ -264,6 +251,3 @@ });

if (exitCode !== 0) {
this.emit(
"error",
new PluginError(this.PLUGIN_NAME_, `Compilation errors occurred`)
);
this.emit('error', new PluginError(this.PLUGIN_NAME_, `Compilation errors occurred`));
}

@@ -284,4 +268,3 @@

return (compilationOptions, pluginOptions) =>
new CompilationStream(compilationOptions, pluginOptions);
return (compilationOptions, pluginOptions) => new CompilationStream(compilationOptions, pluginOptions);
};

@@ -16,2 +16,10 @@ /*

*/
/**
* @fileoverview Convert a string of JSON encoded files
* back to an array of vinyl files
*
* @author Chad Killingsworth (chadkillingsworth@gmail.com)
*/
'use strict';

@@ -27,11 +35,11 @@

let outputFiles = [];
for (const file of fileList) {
const newFile = new File({
path: file.path,
contents: Buffer.from(file.src)
for (let i = 0; i < fileList.length; i++) {
const file = new File({
path: fileList[i].path,
contents: Buffer.from(fileList[i].src)
});
if (file.source_map || file.sourceMap) {
newFile.sourceMap = JSON.parse(file.source_map || file.sourceMap);
if (fileList[i].source_map || fileList[i].sourceMap) {
file.sourceMap = JSON.parse(fileList[i].source_map || fileList[i].sourceMap);
}
outputFiles.push(newFile);
outputFiles.push(file);
}

@@ -38,0 +46,0 @@

{
"name": "@ampproject/google-closure-compiler",
"version": "20210406.0.0",
"version": "20210601.0.0",
"description": "Forked Closure Compiler Publishing using AMP Command Line Runner",

@@ -19,3 +19,3 @@ "bin": {

"dependencies": {
"@ampproject/google-closure-compiler-java": "20210406.0.0",
"@ampproject/google-closure-compiler-java": "20210601.0.0",
"kleur": "4.1.4",

@@ -26,5 +26,5 @@ "vinyl": "2.2.1",

"optionalDependencies": {
"@ampproject/google-closure-compiler-linux": "20210406.0.0",
"@ampproject/google-closure-compiler-osx": "20210406.0.0",
"@ampproject/google-closure-compiler-windows": "20210406.0.0"
"@ampproject/google-closure-compiler-linux": "20210601.0.0",
"@ampproject/google-closure-compiler-osx": "20210601.0.0",
"@ampproject/google-closure-compiler-windows": "20210601.0.0"
},

@@ -31,0 +31,0 @@ "scripts": {

@@ -10,2 +10,5 @@ # google-closure-compiler

**The JS version of closure-compiler is no longer supported or maintained.**
[Read why](https://github.com/google/closure-compiler-npm/blob/master/packages/google-closure-compiler-js/readme.md)
## Getting Started

@@ -26,6 +29,6 @@ If you are new to [Closure-Compiler](https://developers.google.com/closure/compiler/), make

The compiler is distributed as a Java jar and a JavaScript library. Mac OS, Linux and Windows also have native binaries.
The compiler is distributed as a Java jar or as Mac OS, Linux and Windows native binaries.
### Native Binary Version
On Linux, and Mac OS, optional dependencies will install a native binary of the compiler.
On Linux, Mac OS and Windows, optional dependencies will install a native binary of the compiler.
Native binaries offer faster compile times without requiring Java to be installed and available.

@@ -37,8 +40,2 @@ Compilations with a very large number of source files may be slightly slower than the java version.

### JavaScript Version
This is a transpiled version of the Java source to native JavaScript. It can be used in environments without
java installed and even in a browser.
*Note: not all flags are available for the JavaScript version.*
## Usage

@@ -159,22 +156,2 @@ The simplest way to invoke the compiler (e.g. if you're just trying it out) is with [`npx`](https://www.npmjs.com/package/npx):

### JavaScript Version
```js
const ClosureCompiler = require('@ampproject/google-closure-compiler').jsCompiler;
console.log(ClosureCompiler.CONTRIB_PATH); // absolute path to the contrib folder which contains externs
const closureCompiler = new ClosureCompiler({
compilation_level: 'ADVANCED'
});
const compilerProcess = closureCompiler.run([{
path: 'file-one.js',
src: 'alert("hello world")',
sourceMap: null // optional input source map
}], (exitCode, stdOut, stdErr) => {
//compilation complete
});
```
## License

@@ -181,0 +158,0 @@ Copyright 2015 The Closure Compiler Authors

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc