New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

grunt-terser

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-terser - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

.eslintignore

48

Gruntfile.js

@@ -5,21 +5,11 @@ /*

*
* Copyright (c) 2018 Alexandr Dascal
* Copyright (c) 2021 Alexandr Dascal
* Licensed under the MIT license.
*/
'use strict';
module.exports = function(grunt) {
module.exports = (grunt) => {
// Project configuration.
grunt.initConfig({
jshint: {
all: [
'Gruntfile.js',
'tasks/*.js',
'<%= nodeunit.tests %>'
],
options: {
jshintrc: '.jshintrc'
}
eslint: {
all: ['Gruntfile.js', 'tasks/*.js', '<%= nodeunit.tests %>'],
},

@@ -29,3 +19,3 @@

clean: {
tests: ['tmp']
tests: ['tmp'],
},

@@ -36,17 +26,15 @@

default_options: {
options: {
files: {
'tmp/default_options': ['test/fixtures/*.js'],
},
files: {
'tmp/default_options': ['test/fixtures/testing', 'test/fixtures/123']
}
},
custom_options: {
options: {
separator: ': ',
punctuation: ' !!!'
module: true,
sourceMap: true,
},
files: {
'tmp/custom_options': ['test/fixtures/testing', 'test/fixtures/123']
}
}
'tmp/custom_options': ['test/fixtures/*.js'],
},
},
},

@@ -56,5 +44,4 @@

nodeunit: {
tests: ['test/*_test.js']
}
tests: ['test/*_test.js'],
},
});

@@ -66,3 +53,3 @@

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-contrib-clean');

@@ -75,5 +62,6 @@ grunt.loadNpmTasks('grunt-contrib-nodeunit');

grunt.registerTask('lint', ['eslint']);
// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'test']);
grunt.registerTask('default', ['lint', 'test']);
};
{
"name": "grunt-terser",
"description": "Grunt plugin for A JavaScript parser, mangler/compressor and beautifier toolkit for ES6+.",
"version": "1.0.0",
"version": "2.0.0",
"homepage": "https://github.com/adascal/grunt-terser",

@@ -20,19 +20,24 @@ "author": {

"type": "MIT",
"url": "https://github.com/adascal/grunt-terser/blob/master/LICENSE-MIT"
"url": "https://github.com/adascal/grunt-terser/blob/master/LICENSE"
}
],
"engines": {
"node": ">=6.0.0"
"node": ">=10.0.0"
},
"scripts": {
"test": "grunt test"
"test": "grunt test",
"lint": "grunt lint"
},
"dependencies": {
"terser": "^4.3.9"
"peerDependencies": {
"grunt": "1.x",
"terser": "5.x"
},
"devDependencies": {
"grunt": "^1.0.4",
"eslint": "^7.2.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-import": "^2.22.1",
"grunt-contrib-clean": "^2.0.0",
"grunt-contrib-jshint": "^2.1.0",
"grunt-contrib-nodeunit": "^2.0.0"
"grunt-contrib-nodeunit": "^2.0.0",
"grunt-eslint": "^23.0.0"
},

@@ -61,3 +66,6 @@ "keywords": [

"await"
]
],
"dependencies": {
"grunt": "^1.1.0"
}
}

@@ -6,4 +6,5 @@ # grunt-terser

## Getting Started
This plugin requires Grunt `~0.4.5`
This plugin requires Grunt `^1.x`
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

@@ -24,2 +25,3 @@

### Overview
In your project's Gruntfile, add a section named `terser` to the data object passed into `grunt.initConfig()`.

@@ -45,5 +47,7 @@

## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
## Release History
_(Nothing yet)_
- 2021-02-27   v2.0.0   Support terser v5 and async code minify

@@ -5,11 +5,14 @@ /*

*
* Copyright (c) 2018 Alexandr Dascal
* Copyright (c) 2021 Alexandr Dascal
* Licensed under the MIT license.
*/
'use strict';
const { minify } = require('terser');
var Terser = require('terser');
module.exports = function(grunt) {
module.exports = (
/**
* @type import("grunt")
*/
grunt,
) => {
// Please see the Grunt documentation for more information regarding task

@@ -21,63 +24,77 @@ // creation: http://gruntjs.com/creating-tasks

'Grunt plugin for A JavaScript parser, mangler/compressor and beautifier toolkit for ES6+.',
function() {
async function terserTask() {
const done = this.async();
// Merge task-specific and/or target-specific options with these defaults.
var options = this.options();
var createdFiles = 0;
/**
* @type import("terser").MinifyOptions
*/
const options = this.options();
let createdFiles = 0;
// Iterate over all specified file groups.
this.files.forEach(function(f) {
// Concat specified files.
var src = f.src
.filter(function(filepath) {
// Warn on and remove invalid source files (if nonull was set).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
await Promise.all(
this.files.map(async (file) => {
// Concat specified files.
const src = file.src
.filter((filepath) => {
// Warn on and remove invalid source files (if nonull was set).
if (!grunt.file.exists(filepath)) {
grunt.log.warn(`Source file "${filepath}" not found.`);
return false;
}
return true;
}
})
.reduce(function(sources, filepath) {
sources[filepath] = grunt.file.read(filepath);
})
.reduce(
(sources, filepath) => ({
...sources,
[filepath]: grunt.file.read(filepath),
}),
{},
);
return sources;
}, {});
// Minify file code.
const result = await minify(src, options);
// Minify file code.
var result = Terser.minify(src, options);
if (result.error) {
grunt.log.error(result.error);
return false;
}
if (result.error) {
grunt.log.error(result.error);
return false;
}
if (result.warnings) {
grunt.log.warn(result.warnings.join('\n'));
}
if (result.warnings) {
grunt.log.warn(result.warnings.join('\n'));
}
// Write the destination file.
grunt.file.write(file.dest, result.code);
// Write the destination file.
grunt.file.write(f.dest, result.code);
if (options.sourceMap) {
const mapFileName = options.sourceMap.filename
? options.sourceMap.filename
: `${file.dest}.map`;
// Write the source map file.
grunt.file.write(mapFileName, result.map);
}
if (options.sourceMap) {
var mapFileName = options.sourceMap.filename
? options.sourceMap.filename
: f.dest + '.map';
// Write the source map file.
grunt.file.write(mapFileName, result.map);
}
// Print a success message for individual files only if grunt is run with --verbose flag
grunt.log.verbose.writeln(`File "${file.dest}" created.`);
// Print a success message for individual files only if grunt is run with --verbose flag
grunt.verbose.writeln('File "' + f.dest + '" created.');
// Increment created files counter
createdFiles += 1;
}),
);
// Increment created files counter
createdFiles++;
});
if (createdFiles > 0) {
grunt.log.ok(
`${createdFiles} grunt.util.pluralize(createdFiles, 'file/files') created.`
`${createdFiles} ${grunt.util.pluralize(
createdFiles,
'file/files',
)} created.`,
);
}
}
done();
},
);
};

@@ -1,5 +0,3 @@

'use strict';
const grunt = require('grunt');
var grunt = require('grunt');
/*

@@ -26,15 +24,15 @@ ======== A Handy Little Nodeunit Reference ========

exports.terser = {
setUp: function(done) {
setUp(done) {
// setup here if necessary
done();
},
default_options: function(test) {
default_options(test) {
test.expect(1);
var actual = grunt.file.read('tmp/default_options');
var expected = grunt.file.read('test/expected/default_options');
const actual = grunt.file.read('tmp/default_options');
const expected = grunt.file.read('test/expected/default_options');
test.equal(
actual,
expected,
'should describe what the default behavior is.'
'should describe what the default behavior is.',
);

@@ -44,11 +42,11 @@

},
custom_options: function(test) {
custom_options(test) {
test.expect(1);
var actual = grunt.file.read('tmp/custom_options');
var expected = grunt.file.read('test/expected/custom_options');
const actual = grunt.file.read('tmp/custom_options');
const expected = grunt.file.read('test/expected/custom_options');
test.equal(
actual,
expected,
'should describe what the custom option(s) behavior is.'
'should describe what the custom option(s) behavior is.',
);

@@ -55,0 +53,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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