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

grunt-neuter

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-neuter - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

CHANGELOG.md

43

Gruntfile.js

@@ -17,3 +17,3 @@ /*

```shell
grunt
grunt
```

@@ -26,3 +26,3 @@

* run the `neuter` config below, which will generate a bunch of files
with varying configuration optiones applied (usually by reading a
with varying configuration optiones applied (usually by reading a
fixture file from `test/fixtures` that incldues require statements)

@@ -38,3 +38,3 @@ writing their output to a tmp directory in this project.

if it failed, you'll see a notice about why and the `tmp` directory
will remain for you to inspect.
will remain for you to inspect.
*/

@@ -54,2 +54,12 @@ module.exports = function(grunt) {

// Run to test the default simple require options with a filepath transform.
filepath_transform_options: {
files: {
'tmp/simple_require_filepath_transforms' : ['test/fixtures/simple_require_filepath_transforms.js']
},
options: {
filepathTransform: function(filepath){ return 'test/fixtures/' + filepath; }
}
},
// Run to test the default simple require options.

@@ -76,3 +86,3 @@ custom_separator_options: {

// Run to test that duplicate require statemtns only write a source file to the
// destination once.
// destination once.
duplicate_require_statements: {

@@ -95,7 +105,28 @@ files: {

},
can_accept_file_patterns: {
accepts_file_patterns: {
files: {
'tmp/can_accept_file_patterns': ['test/fixtures/glob/*.js']
'tmp/accepts_file_patterns': ['test/fixtures/glob/*.js']
}
},
ignores_files_when_told: {
files: {
'tmp/ignores_files_when_told': ['test/fixtures/ignores_files_when_told.js']
},
options: {
skipFiles: ['test/fixtures/contains_commonjs_require.js']
}
},
do_not_replace_requires_in_statements: {
files: {
'tmp/do_not_replace_requires_in_statements': ['test/fixtures/do_not_replace_requires_in_statements.js']
}
},
// test that single line commented out require statements are not loaded
comment_out_require: {
files: {
'tmp/comment_out_require': ['test/fixtures/comment_out_require.js']
}
}
},

@@ -102,0 +133,0 @@ jshint: {

12

package.json
{
"name": "grunt-neuter",
"version": "0.3.0",
"version": "0.4.0",
"description": "Builds source files in the order you require.",

@@ -19,8 +19,8 @@ "main": "Gruntfile.js",

"devDependencies": {
"grunt": "~0.4.0rc5",
"grunt-contrib-jshint": "~0.1.1rc5",
"grunt-contrib-nodeunit": "0.1.2rc5",
"grunt-contrib-clean": "~0.4.0rc5",
"grunt-contrib-internal": "~0.1.1"
"grunt": "~0.4.0",
"grunt-contrib-jshint": "~0.2.0",
"grunt-contrib-nodeunit": "0.1.2",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-internal": "~0.4.3"
}
}

@@ -43,3 +43,3 @@ # grunt-neuter

3. Have files separated in debugging, combined in production: When using
3. Have files separated in debugging, combined in production: When using
good development tools you want to easily map your debugging efforts to

@@ -59,8 +59,15 @@ a specific file, not read through one giant file.

Default: `"(function){ <%= text %> })();"`
Default: `"(function){ {%= src %} })();"`
The wrapper around your code. Defaults to a closure-style function so locally delcared variables
won't leak into the gloabl scope. The text of your source JavaScript file is available as `text`
The wrapper around your code. Defaults to a closure-style function so locally declared variables
won't leak into the global scope. The text of your source JavaScript file is available as `src`
within a template.
### filepathTransform
Type: `Function`
Default: `function(filepath){ return filepath; }`
Specifying a filepath transform allows you to omit said portion of the filepath from your require statements. For example: when using `filepathTransform: function(filepath){ return 'lib/js/' + filepath; }` in your task options, require("lib/js/file.js") can instead be written as require("file.js").
### includeSourceURL

@@ -71,3 +78,3 @@ Type: Boolean`

Includes a the path to your source JavaScript file as `//@ sourceURL="path/to/my/file.js"` for
Includes the path to your source JavaScript file as `//@ sourceURL="path/to/my/file.js"` for
[nicer debugging](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl). Note that this wraps your source JavaScript file (as a string) with `eval` and should not be used in prouduction.

@@ -80,3 +87,11 @@

Neutered files will be joined on this string. If you're post-processing concatenated JavaScript files with a minifier, you may need to use a semicolon `';'` as the separator although the semicolon at the end of the
template should suffice.
Neutered files will be joined on this string. If you're post-processing concatenated JavaScript files with a minifier, you may need to use a semicolon `';'` as the separator although the semicolon at the end of the template should suffice.
### skipFiles
Type: `Array`
Default: `[]`
A list of files being required that should not be checked for further require statements.
Useful for libraries that support other module building methods and leave their requires
around in a way that isn't meaningful to neutering.

@@ -18,3 +18,3 @@ /*

// the bufffer that we appened to over this run.
// the bufffer that we appened to over this run.
var out = [];

@@ -24,11 +24,22 @@

// no need to include a .js as this will be appended for you.
var requireSplitter = /(require\([\'||\"].*[\'||\"]\));+\n*/;
var requireMatcher = /require\([\'||\"](.*)[\'||\"]\)/;
var requireSplitter = /^\s*(require\([\'||\"].*[\'||\"]\));+\n*/m;
var requireMatcher = /^require\([\'||\"](.*)[\'||\"]\)/m;
// add mustache style delimiters
grunt.template.addDelimiters('neuter', '{%', '%}');
var options = this.options({
template: "(function() {\n\n<%= src %>\n\n})();",
filepathTransform: function(filepath){ return filepath; },
template: "(function() {\n\n{%= src %}\n\n})();",
separator: "\n\n",
includeSourceURL: false
includeSourceURL: false,
skipFiles: []
});
// a poor man's Set
var skipFiles = {};
options.skipFiles.forEach(function(file){
skipFiles[file] = true;
});
var finder = function(filepath){

@@ -40,3 +51,3 @@ if (!grunt.file.exists(filepath)) {

// once a file has been required its source will
// once a file has been required its source will
// never be written to the resulting destination file again.

@@ -46,22 +57,32 @@ if (required.indexOf(filepath) === -1) {

// read the file and split it into code sections
// these will be either require(...) statements
// or blocks of code.
var src = grunt.file.read(filepath);
var sections = src.split(requireSplitter);
// loop through sections appending to out buffer.
sections.forEach(function(section){
if (!section.length) { return; }
// if the section is a require statement
// recursively call find again. Otherwise
// push the code section onto the buffer.
var match = requireMatcher.exec(section);
if (match) {
finder(match[1] + '.js');
} else {
out.push({filepath: filepath, src: section});
}
});
// if a file should not be nuetered
// it is part of the skipFiles option
// and is simply included
if (skipFiles[filepath]) {
out.push({filepath: filepath, src: src});
} else {
// split the source into code sections
// these will be either require(...) statements
// or blocks of code.
var sections = src.split(requireSplitter);
// loop through sections appending to out buffer.
sections.forEach(function(section){
if (!section.length) { return; }
// if the section is a require statement
// recursively call find again. Otherwise
// push the code section onto the buffer.
// apply the filepathTransform for matched files.
var match = requireMatcher.exec(section);
if (match) {
finder(options.filepathTransform(match[1]) + '.js');
} else {
out.push({filepath: filepath, src: section});
}
});
}
}

@@ -77,3 +98,4 @@ };

var templateData = {
data: section
data: section,
delimiters:'neuter'
};

@@ -80,0 +102,0 @@

@@ -14,2 +14,10 @@ 'use strict';

},
simple_require_filepath_transforms: function(test) {
var actual = grunt.file.read('tmp/simple_require_filepath_transforms');
var expected = grunt.file.read('test/expected/simple_require_filepath_transforms');
test.equal(actual, expected, 'files are combined in correct order');
test.done();
},
custom_separator_options: function(test){

@@ -48,3 +56,3 @@

circular_require_statements: function(test){
var actual = grunt.file.read('tmp/circular_require_statements');

@@ -64,10 +72,37 @@ var expected = grunt.file.read('test/expected/circular_require_statements');

},
can_accept_file_patterns: function(test){
accepts_file_patterns: function(test){
var actual = grunt.file.read('tmp/can_accept_file_patterns');
var expected = grunt.file.read('test/expected/can_accept_file_patterns');
var actual = grunt.file.read('tmp/accepts_file_patterns');
var expected = grunt.file.read('test/expected/accepts_file_patterns');
test.equal(actual, expected, 'file patterns can be correctly read');
test.done();
},
ignores_files_when_told: function(test){
var actual = grunt.file.read('tmp/ignores_files_when_told');
var expected = grunt.file.read('test/expected/ignores_files_when_told');
test.equal(actual, expected, 'ignores files when told');
test.done();
},
do_not_replace_requires_in_statements: function(test){
var actual = grunt.file.read('tmp/do_not_replace_requires_in_statements');
var expected = grunt.file.read('test/expected/do_not_replace_requires_in_statements');
test.equal(actual, expected, 'require() statements in javascript statements are ignored');
test.done();
},
comment_out_require: function(test){
var actual = grunt.file.read('tmp/comment_out_require');
var expected = grunt.file.read('test/expected/comment_out_require');
test.equal(actual, expected, 'single line commented require() statements are ignored');
test.done();
}
};
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