Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fs.writeFile(jsFile, bundle, function (err) {
if (err) {
throw err
}
console.log('minify ', jsFile, ' -> ', minFile)
var closureCompiler = new ClosureCompiler({
js: jsFile,
compilation_level: 'SIMPLE',
js_output_file: minFile
})
closureCompiler.run(function (exitCode, stdOut, stdErr) {
fs.readFile(minFile, function (err, data) {
if (err) {
throw err
}
console.log('minified ', minFile)
console.log('stdout: ', stdOut)
console.log('stderr: ', stdErr)
writePage(file, data) // output as div tag here.
})
})
var ClosureCompiler = require('google-closure-compiler').compiler;
var opts = {
js: closurePrepareFilePath,
externs: EXTERNS_CORE,
language_out: 'ECMASCRIPT5',
compilation_level: 'ADVANCED_OPTIMIZATIONS',
assume_function_wrapper: 'true',
warning_level: 'QUIET',
rewrite_polyfills: 'false',
// formatting: 'PRETTY_PRINT',
// debug: 'true'
};
var closureCompiler = new ClosureCompiler(opts);
return new Promise((resolve, reject) => {
closureCompiler.run((exitCode: number, stdOut: string, stdErr: string) => {
if (stdErr) {
console.log('core, closureCompiler exitCode', exitCode, 'stdErr', stdErr);
reject(stdErr);
} else {
var content = stdOut;
var match = /function\(\){"tricks-are-for-closure"}/.exec(content);
if (!match) {
fs.writeFileSync(closurePrepareFilePath, content);
throw 'postClosure: something done changed!'
}
var ClosureCompiler = require('google-closure-compiler').compiler;
var opts = {
js: inputFilePath,
externs: path.join(__dirname, 'externs.js'),
language_out: 'ECMASCRIPT5',
compilation_level: 'ADVANCED_OPTIMIZATIONS',
assume_function_wrapper: 'true',
warning_level: 'VERBOSE',
rewrite_polyfills: 'false',
warning_level: 'QUIET',
// formatting: 'PRETTY_PRINT',
// debug: 'true'
};
var closureCompiler = new ClosureCompiler(opts);
return new Promise(function(resolve, reject) {
console.log(closureCompiler.commandArguments.join(' '));
closureCompiler.run(function(exitCode, stdOut, stdErr) {
if (stdErr) {
console.log('closureCompiler exitCode', exitCode, 'stdErr', stdErr);
reject(stdErr);
} else {
util.writeFile(outputFilePath, stdOut).then(() => {
resolve();
});
}
});
});
async function compile(
extendedOpts: ExtendedCompilerOptions
): Promise<{ stdout: string; stderr: string | undefined }> {
let opts = extendedOpts.compilerOptions;
if (isInAwsLambda()) {
rewriteNodePathForAwsLambda(opts);
}
// Avoid `spawn E2BIG` error for too large arguments
if (opts.js && opts.js.length > 100) {
opts = convertToFlagfile(opts);
}
if (extendedOpts.warningsWhitelist) {
opts.warnings_whitelist_file = createWarningsWhitelistFile(extendedOpts.warningsWhitelist);
}
const compiler = new ClosureCompiler(opts as any);
if (extendedOpts.batch) {
compiler.JAR_PATH = null;
try {
const { getNativeImagePath } = await import("google-closure-compiler/lib/utils");
compiler.javaPath = getNativeImagePath();
} catch {
throw new Error("Installed google-closure-compiler is too old for batch mode.");
}
}
return new Promise((resolve, reject) => {
compiler.run((exitCode: number, stdout: string, stderr?: string) => {
if (exitCode !== 0) {
return reject(new CompilerError(stderr || "No stderr", exitCode));
}
resolve({ stdout, stderr });
});
.on('close', function () {
console.log('minifying script: ', UNCHECKED_FILE)
var closureCompiler = new ClosureCompiler({
js: UNCHECKED_FILE,
compilation_level: 'SIMPLE',
js_output_file: OUTPUT_FILE
})
closureCompiler.run(function (exitCode, stdOut, stdErr) {
console.log('closure stdout:', stdOut)
console.log('closure stderr:', stdErr)
process.exit(exitCode)
})
})
return new Promise((resolve, reject) => {
console.log('Starting closure compiler build');
new Compiler({
assume_function_wrapper: true,
debug: !!doDebugBuild,
language_in: 'stable',
rewrite_polyfills: false,
generate_exports: true,
language_out: 'ES5_STRICT',
create_source_map: './dist/fontoxpath.js.map',
source_map_location_mapping: `${TEMP_BUILD_DIR}|../${TEMP_BUILD_DIR}`,
jscomp_warning: reportUnknownTypes ? ['reportUnknownTypes'] : [],
jscomp_error: [
'accessControls',
'checkDebuggerStatement',
'checkRegExp',
'checkTypes',
'checkVars',
'const',
function BundlePolyfills() {
let path = './polyfills/';
new ClosureCompiler({
js: fs.readdirSync(path).map(file => {
if (file.includes('.js')) return path + file
}),
compilation_level: 'SIMPLE',
language_in: 'ECMASCRIPT5_STRICT',
language_out: 'ECMASCRIPT5_STRICT',
js_output_file: './dist/polyfills.min.js'
}).run(() => {
console.log('Success -> Polyfills Bundled and Minified!\n');
});
}
return new Promise((resolve, reject) => {
const compiler = new closure({
js: file,
compilation_level: 'ADVANCED'
})
.run((exitCode, stdOut, stdErr) => {
if (exitCode === 0) return resolve(stdOut);
reject(stdErr);
});
});
}
return new Promise((resolve, reject) => {
const closureCompiler = new ClosureCompiler(flags);
closureCompiler.run(function(exitCode, stdOut, stdErr) {
if (!stdErr) {
resolve(stdOut);
} else {
reject(new Error(stdErr));
}
});
});
}