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

broccoli-sourcemap-concat

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

broccoli-sourcemap-concat - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

154

concat-with-maps.js

@@ -7,88 +7,96 @@ var helpers = require('broccoli-kitchen-sink-helpers');

module.exports = CachingWriter.extend({
enforceSingleInputTree: true,
module.exports = ConcatWithMaps;
ConcatWithMaps.prototype = Object.create(CachingWriter.prototype);
ConcatWithMaps.prototype.constructor = ConcatWithMaps;
function ConcatWithMaps(inputNode, options) {
if (!(this instanceof ConcatWithMaps)) return new ConcatWithMaps(inputNode, options);
if (!options || !options.outputFile || !options.inputFiles) {
throw new Error('inputFiles and outputFile options ware required');
}
init: function() {
this._super.apply(this, arguments);
CachingWriter.call(this, [inputNode], {
inputFiles: options.inputFiles,
annotation: options.annotation
});
if (!this.separator) {
this.separator = '\n';
this.inputFiles = options.inputFiles;
this.outputFile = options.outputFile;
this.allowNone = options.allowNone;
this.header = options.header;
this.headerFiles = options.headerFiles;
this.footer = options.footer;
this.footerFiles = options.footerFiles;
this.separator = (options.separator != null) ? options.separator : '\n';
this.encoderCache = {};
}
ConcatWithMaps.prototype.build = function() {
var separator = this.separator;
var firstSection = true;
var concat = this.concat = new ConcatWithSourcemap({
outputFile: path.join(this.outputPath, this.outputFile),
sourceRoot: this.sourceRoot,
baseDir: this.inputPaths[0],
cache: this.encoderCache
});
function beginSection() {
if (firstSection) {
firstSection = false;
} else {
concat.addSpace(separator);
}
if (!this.outputFile) {
throw new Error("outputFile is required");
}
this.encoderCache = {};
},
description: 'ConcatWithMaps',
}
updateCache: function(inDir, outDir) {
var separator = this.separator;
var firstSection = true;
if (this.header) {
beginSection();
concat.addSpace(this.header);
}
var concat = this.concat = new ConcatWithSourcemap({
outputFile: path.join(outDir, this.outputFile),
sourceRoot: this.sourceRoot,
baseDir: inDir,
cache: this.encoderCache
if (this.headerFiles) {
this.headerFiles.forEach(function(hf) {
beginSection();
concat.addFile(hf);
});
}
function beginSection() {
if (firstSection) {
firstSection = false;
} else {
concat.addSpace(separator);
}
try {
this.addFiles(this.inputPaths[0], beginSection);
} catch(error) {
// multiGlob is obtuse.
if (!error.message.match("did not match any files") || !this.allowNone) {
throw error;
}
}
if (this.header) {
if (this.footer) {
beginSection();
concat.addSpace(this.footer);
}
if (this.footerFiles) {
this.footerFiles.forEach(function(ff) {
beginSection();
concat.addSpace(this.header);
}
concat.addFile(ff);
});
}
return this.concat.end();
}
if (this.headerFiles) {
this.headerFiles.forEach(function(hf) {
beginSection();
concat.addFile(hf);
});
}
ConcatWithMaps.prototype.addFiles = function(inputPath, beginSection) {
helpers.multiGlob(this.inputFiles, {
cwd: inputPath,
root: inputPath,
nomount: false
}).forEach(function(file) {
var stat;
try {
this.addFiles(inDir, beginSection);
} catch(error) {
// multiGlob is obtuse.
if (!error.message.match("did not match any files") || !this.allowNone) {
throw error;
}
}
if (this.footer) {
stat = fs.statSync(path.join(inputPath, file));
} catch(err) {}
if (stat && !stat.isDirectory()) {
beginSection();
concat.addSpace(this.footer);
this.concat.addFile(file);
}
if (this.footerFiles) {
this.footerFiles.forEach(function(ff) {
beginSection();
concat.addFile(ff);
});
}
return this.concat.end();
},
addFiles: function(inDir, beginSection) {
helpers.multiGlob(this.inputFiles, {
cwd: inDir,
root: inDir,
nomount: false
}).forEach(function(file) {
var stat;
try {
stat = fs.statSync(path.join(inDir, file));
} catch(err) {}
if (stat && !stat.isDirectory()) {
beginSection();
this.concat.addFile(file);
}
}.bind(this));
},
});
}.bind(this));
}

@@ -5,3 +5,3 @@ var ConcatWithMaps = require('./concat-with-maps');

module.exports = function(inputTree, options) {
module.exports = function(inputNode, options) {
if (!options || !options.outputFile) {

@@ -17,3 +17,3 @@ throw new Error("outputFile is required");

if (options.outputFile.slice(-1 * ext.length) === ext) {
return new ConcatWithMaps(inputTree, options);
return new ConcatWithMaps(inputNode, options);
}

@@ -23,3 +23,3 @@ }

return new SimpleConcat(inputTree, options);
return new SimpleConcat(inputNode, options);
};
{
"name": "broccoli-sourcemap-concat",
"version": "1.0.2",
"version": "1.1.0",
"description": "Fast, good-enough concatenation with source maps.",

@@ -24,5 +24,4 @@ "main": "index.js",

"dependencies": {
"broccoli-caching-writer": "^1.0.0",
"broccoli-caching-writer": "^2.0.0",
"broccoli-kitchen-sink-helpers": "^0.2.5",
"broccoli-writer": "^0.1.1",
"fast-sourcemap-concat": " ^0.2.4",

@@ -29,0 +28,0 @@ "lodash-node": "^2.4.1",

@@ -12,3 +12,3 @@ Broccoli concatenator that generates & propagates sourcemaps

```js
var tree = concat(tree, {
var node = concat(node, {
outputFile: '/output.js',

@@ -15,0 +15,0 @@ inputFiles: ['loader.js', '**/*']

@@ -23,96 +23,103 @@ var CachingWriter = require('broccoli-caching-writer');

module.exports = CachingWriter.extend({
enforceSingleInputTree: true,
module.exports = SimpleConcat;
SimpleConcat.prototype = Object.create(CachingWriter.prototype);
SimpleConcat.prototype.constructor = SimpleConcat;
function SimpleConcat(inputNode, options) {
if (!(this instanceof SimpleConcat)) return new SimpleConcat(inputNode, options);
if (!options || !options.outputFile || !options.inputFiles) {
throw new Error('inputFiles and outputFile options ware required');
}
init: function() {
this._super.apply(this, arguments);
CachingWriter.call(this, [inputNode], {
inputFiles: options.inputFiles,
annotation: options.annotation
});
if (!this.separator) {
this.separator = '\n';
}
this.inputFiles = options.inputFiles;
this.outputFile = options.outputFile;
this.allowNone = options.allowNone;
this.header = options.header;
this.headerFiles = options.headerFiles;
this.footer = options.footer;
this.footerFiles = options.footerFiles;
this.separator = (options.separator != null) ? options.separator : '\n';
}
if (!this.outputFile) {
throw new Error('outputFile is required');
SimpleConcat.prototype.build = function() {
var combined = new Combined();
var firstSection = true;
var separator = this.separator;
function beginSection() {
if (firstSection) {
firstSection = false;
} else {
combined.append(separator);
}
},
}
description: 'SimpleConcat',
updateCache: function(inDir, outDir) {
var combined = new Combined();
var firstSection = true;
var separator = this.separator;
if (this.header) {
beginSection();
combined.append(this.header);
}
function beginSection() {
if (firstSection) {
firstSection = false;
} else {
combined.append(separator);
}
}
if (this.header) {
if (this.headerFiles) {
this.headerFiles.forEach(function(file) {
beginSection();
combined.append(this.header);
}
combined.append(fs.readFileSync(path.join(this.inputPaths[0], file), 'UTF-8'));
});
}
if (this.headerFiles) {
this.headerFiles.forEach(function(file) {
beginSection();
combined.append(fs.readFileSync(path.join(inDir, file), 'UTF-8'));
});
try {
this._addFiles(combined, this.inputPaths[0], beginSection);
} catch(error) {
// multiGlob is obtuse.
if (!error.message.match('did not match any files') || !this.allowNone) {
throw error;
}
}
try {
this._addFiles(combined, inDir, beginSection);
} catch(error) {
// multiGlob is obtuse.
if (!error.message.match('did not match any files') || !this.allowNone) {
throw error;
}
}
if (this.footer) {
beginSection();
combined.append(this.footer);
}
if (this.footer) {
if (this.footerFiles) {
this.footerFiles.forEach(function(file) {
beginSection();
combined.append(this.footer);
}
combined.append(fs.readFileSync(path.join(this.inputPaths[0], file), 'UTF-8'));
}.bind(this));
}
if (this.footerFiles) {
this.footerFiles.forEach(function(file) {
beginSection();
combined.append(fs.readFileSync(path.join(inDir, file), 'UTF-8'));
}.bind(this));
}
var filePath = path.join(this.outputPath, this.outputFile);
var filePath = path.join(outDir, this.outputFile);
mkdirp.sync(path.dirname(filePath));
mkdirp.sync(path.dirname(filePath));
if (firstSection) {
combined.append('');
}
if (firstSection) {
combined.append('');
}
fs.writeFileSync(filePath, combined);
}
fs.writeFileSync(filePath, combined);
},
SimpleConcat.prototype._addFiles = function(combined, inputPath, beginSection) {
helpers.multiGlob(this.inputFiles, {
cwd: inputPath,
root: inputPath,
nomount: false
}).forEach(function(file) {
var filePath = path.join(inputPath, file);
var stat;
_addFiles: function(combined, inDir, beginSection) {
helpers.multiGlob(this.inputFiles, {
cwd: inDir,
root: inDir,
nomount: false
}).forEach(function(file) {
var filePath = path.join(inDir, file);
var stat;
try {
stat = fs.statSync(filePath);
} catch(err) {}
try {
stat = fs.statSync(filePath);
} catch(err) {}
if (stat && !stat.isDirectory()) {
beginSection();
combined.append(fs.readFileSync(filePath, 'UTF-8'));
}
});
if (stat && !stat.isDirectory()) {
beginSection();
combined.append(fs.readFileSync(filePath, 'UTF-8'));
}
});
return combined;
}
});
return combined;
}

@@ -16,7 +16,7 @@ /* global describe, afterEach, it, expect */

it('concatenates files in one dir', function() {
var tree = concat(fixtures, {
var node = concat(fixtures, {
outputFile: '/all-inner.js',
inputFiles: ['inner/*.js']
});
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build().then(function(result) {

@@ -29,7 +29,7 @@ expectFile('all-inner.js').in(result);

it('concatenates files across dirs', function() {
var tree = concat(fixtures, {
var node = concat(fixtures, {
outputFile: '/all.js',
inputFiles: ['**/*.js']
});
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build().then(function(result) {

@@ -42,3 +42,3 @@ expectFile('all.js').in(result);

it('inserts header', function() {
var tree = concat(fixtures, {
var node = concat(fixtures, {
outputFile: '/all-with-header.js',

@@ -48,3 +48,3 @@ inputFiles: ['**/*.js'],

});
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build().then(function(result) {

@@ -57,3 +57,3 @@ expectFile('all-with-header.js').in(result);

it('inserts header when sourcemaps are disabled', function() {
var tree = concat(fixtures, {
var node = concat(fixtures, {
outputFile: '/all-with-header.js',

@@ -64,3 +64,3 @@ inputFiles: ['**/*.js'],

});
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build().then(function(result) {

@@ -73,3 +73,3 @@ expectFile('all-with-header.js').withoutSrcURL().in(result);

it('disables sourcemaps when requested', function() {
var tree = concat(fixtures, {
var node = concat(fixtures, {
outputFile: '/no-sourcemap.js',

@@ -80,3 +80,3 @@ inputFiles: ['**/*.js'],

});
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build().then(function(result) {

@@ -112,3 +112,3 @@ expectFile('no-sourcemap.js').in(result);

it('appends footer files', function() {
var tree = concat(fixtures, {
var node = concat(fixtures, {
outputFile: '/inner-with-footers.js',

@@ -118,3 +118,3 @@ inputFiles: ['inner/*.js'],

});
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build().then(function(result) {

@@ -127,3 +127,3 @@ expectFile('inner-with-footers.js').in(result);

it('appends footer files when sourcemaps are disabled', function() {
var tree = concat(fixtures, {
var node = concat(fixtures, {
outputFile: '/inner-with-footers.js',

@@ -134,3 +134,3 @@ inputFiles: ['inner/*.js'],

});
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build().then(function(result) {

@@ -143,3 +143,3 @@ expectFile('inner-with-footers.js').withoutSrcURL().in(result);

it('can ignore empty content', function() {
var tree = concat(fixtures, {
var node = concat(fixtures, {
outputFile: '/nothing.js',

@@ -149,3 +149,3 @@ inputFiles: ['nothing/*.js'],

});
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build().then(function(result) {

@@ -158,3 +158,3 @@ expectFile('nothing.js').in(result);

it('can ignore empty content when sourcemaps are disabled', function() {
var tree = concat(fixtures, {
var node = concat(fixtures, {
outputFile: '/nothing.css',

@@ -164,3 +164,3 @@ inputFiles: ['nothing/*.css'],

});
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build().then(function(result) {

@@ -172,3 +172,3 @@ expectFile('nothing.css').in(result);

it('does not ignore empty content when allowNone is not explicitly set', function() {
var tree = concat(fixtures, {
var node = concat(fixtures, {
outputFile: '/nothing.js',

@@ -178,3 +178,3 @@ inputFiles: ['nothing/*.js']

var failure = sinon.spy();
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build().catch(failure).then(function(){

@@ -186,3 +186,3 @@ expect(failure.called).to.be.true();

it('does not ignore empty content when allowNone is not explicitly set and sourcemaps are disabled', function() {
var tree = concat(fixtures, {
var node = concat(fixtures, {
outputFile: '/nothing.css',

@@ -192,3 +192,3 @@ inputFiles: ['nothing/*.css']

var failure = sinon.spy();
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build().catch(failure).then(function(){

@@ -195,0 +195,0 @@ expect(failure.called).to.be.true();

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