Socket
Socket
Sign inDemoInstall

systemjs-builder

Package Overview
Dependencies
Maintainers
1
Versions
139
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

systemjs-builder - npm Package Compare versions

Comparing version 0.9.0 to 0.9.1

17

compilers/register.js

@@ -5,2 +5,3 @@ var traceur = require('traceur');

var ArgumentList = traceur.get('syntax/trees/ParseTrees.js').ArgumentList;
var ArrayLiteralExpression = traceur.get('syntax/trees/ParseTrees.js').ArrayLiteralExpression;
var createStringLiteral = traceur.get('codegeneration/ParseTreeFactory.js').createStringLiteral;

@@ -11,5 +12,6 @@

// also this should be rewritten with a proper parser!
function RegisterTransformer(moduleName) {
function RegisterTransformer(moduleName, map) {
this.name = moduleName;
this.hasAnonRegister = false;
this.map = map;
return ParseTreeTransformer.call(this);

@@ -34,4 +36,11 @@ }

// normalize dependencies in array
var map = this.map;
var normalizedDepArray = new ArrayLiteralExpression(firstArg.location, firstArg.elements.map(function(el) {
var str = el.literalToken.value.toString();
return createStringLiteral(map(str.substr(1, str.length - 2)));
}));
this.hasAnonRegister = true;
return new CallExpression(tree.location, tree.operand, new ArgumentList(tree.args.location, [createStringLiteral(this.name)].concat(tree.args.args)));
return new CallExpression(tree.location, tree.operand, new ArgumentList(tree.args.location, [createStringLiteral(this.name), normalizedDepArray].concat(tree.args.args.splice(1))));
}

@@ -48,3 +57,3 @@ }

options.sourceMaps = 'memory';
if (opts.lowResolutionSourceMaps)
if (opts.lowResSourceMaps)
options.lowResolutionSourceMap = true;

@@ -58,3 +67,3 @@

var transformer = new RegisterTransformer(load.name);
var transformer = new RegisterTransformer(load.name, function(dep) { return opts.normalize ? load.depMap[dep] : dep; });
tree = transformer.transformAny(tree);

@@ -61,0 +70,0 @@

@@ -17,10 +17,18 @@ var Promise = require('rsvp').Promise;

/* Very basic, null-friendly, shallow clone for object attributes only */
function clone(obj) {
obj = obj || {};
var copy = {};
for (var key in obj) {
copy[key] = obj[key];
function processOpts(opts_, outFile) {
var opts = {
config: {},
lowResSourceMaps: false,
minify: false,
normalize: false,
outFile: outFile,
runtime: false,
sourceMaps: false,
sourceMapContents: opts_ && opts_.sourceMaps == 'inline'
};
for (var key in opts_) {
if (key in opts)
opts[key] = opts_[key];
}
return copy;
return opts;
}

@@ -74,2 +82,62 @@

Builder.parseExpression = function(expressionString) {
var args = expressionString.split(' ');
var firstModule = args[0];
var operations = [];
for (var i = 1; i < args.length - 1; i = i + 2) {
var operator = args[i];
var moduleName = args[i + 1];
operations.push({
operator: operator,
moduleName: moduleName
});
}
return {firstModule: firstModule, operations: operations};
};
Builder.prototype.lookupOperatorFn = function(symbol) {
if (symbol == '+')
return this.addTrees;
else if (symbol == '-')
return this.subtractTrees;
else
throw 'Unknown operator ' + op.operator;
};
Builder.prototype.buildExpression = function(expression, cfg) {
var builder = this;
if (typeof expression == 'string')
expression = Builder.parseExpression(expression);
var firstModule = expression.firstModule;
var operations = expression.operations;
return Promise.resolve(builder.trace(firstModule, cfg))
.then(function(trace) {
// if there are no other operations, then we have the final tree
if (!operations.length)
return trace.tree;
var applyOperation = function(promise, op) {
return promise.then(function(curTree) {
return builder.trace(op.moduleName)
.then(function(nextTrace) {
var operatorFn = builder.lookupOperatorFn(op.operator);
return operatorFn.call(builder, curTree, nextTrace.tree);
});
});
};
// chain the operations, applying them with the trace of the next module
return operations.reduce(applyOperation, Promise.resolve(trace.tree));
});
};
var compilerMap = {

@@ -146,6 +214,4 @@ 'amd': amdCompiler,

var loader = this.loader;
opts = processOpts(opts, outFile);
opts = clone(opts);
opts.outFile = outFile;
return buildOutputs(loader, tree, opts, false)

@@ -160,13 +226,8 @@ .then(function(outputs) {

var loader = this.loader;
opts = processOpts(opts, outFile);
opts.normalize = true;
opts = clone(opts);
opts.outFile = outFile;
var config = opts.config;
var outputs;
var compilers = {};
opts.normalize = true;
return this.trace(moduleName, config)
return this.trace(moduleName, opts.config)
.then(function(trace) {

@@ -173,0 +234,0 @@ moduleName = trace.moduleName;

@@ -55,3 +55,3 @@ var saucy = require('./sourcemaps');

function createOutput(outputs, outFile, baseURL, createSourceMaps) {
function createOutput(outputs, outFile, baseURL, opts) {
// process output

@@ -62,5 +62,6 @@ var sourceMap;

if (createSourceMaps && outputObj.sourceMapsWithOffsets.length) {
if (opts.sourceMaps && outputObj.sourceMapsWithOffsets.length) {
var sourceRoot = outFile ? path.dirname(baseURL + outFile) + path.sep : baseURL;
sourceMap = saucy.concatenateSourceMaps(outFile, outputObj.sourceMapsWithOffsets, sourceRoot);
var mapsWithOffsets = outputObj.sourceMapsWithOffsets;
sourceMap = saucy.concatenateSourceMaps(outFile, mapsWithOffsets, sourceRoot, opts.sourceMapContents);
}

@@ -110,4 +111,5 @@

function writeOutputFile(opts, output, basePath) {
if (opts.sourceMaps) {
var sourceMapFile = path.basename(opts.outFile) + '.map';
var sourceMapFile;
if (opts.sourceMaps && output.sourceMap) {
sourceMapFile = path.basename(opts.outFile) + '.map';
output.source += '\n//# sourceMappingURL=' + sourceMapFile;

@@ -118,3 +120,3 @@ }

.then(function() {
if (!opts.sourceMaps) return;
if (!output.sourceMap || !opts.sourceMaps) return;
var sourceMapPath = path.resolve(basePath, path.dirname(opts.outFile), sourceMapFile);

@@ -129,7 +131,8 @@ return asp(fs.writeFile)(sourceMapPath, output.sourceMap);

exports.inlineSourceMap = function(output) {
exports.inlineSourceMap = inlineSourceMap;
function inlineSourceMap (output) {
return output.source +
'\n//# sourceMappingURL=data:application/json;base64,' +
new Buffer(output.sourceMap.toString()).toString('base64');
};
}

@@ -143,3 +146,3 @@ exports.writeOutput = function(opts, outputs, baseURL) {

var output = createOutput(outputs, opts.outFile, baseURL, opts.sourceMaps);
var output = createOutput(outputs, opts.outFile, baseURL, opts);

@@ -149,2 +152,7 @@ if (opts.minify)

if (opts.sourceMaps == 'inline') {
output.source = inlineSourceMap(output);
output.sourceMap = undefined;
}
if (opts.outFile)

@@ -151,0 +159,0 @@ return writeOutputFile(opts, output, basePath).then(function() { return output; });

@@ -26,3 +26,8 @@ var sourceMap = require('source-map');

exports.concatenateSourceMaps = function(sourceFilename, mapsWithOffsets, sourceRoot) {
exports.concatenateSourceMaps = function(sourceFilename, mapsWithOffsets, sourceRoot, includeSourcesContent) {
if (includeSourcesContent) {
console.log('WARNING: `includeSourcesContent` not support yet, ' +
'see https://github.com/systemjs/builder/issues/68');
}
var generated = new sourceMap.SourceMapGenerator({

@@ -29,0 +34,0 @@ file: sourceFilename

{
"name": "systemjs-builder",
"version": "0.9.0",
"version": "0.9.1",
"description": "SystemJS Build Tool ===",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -43,16 +43,17 @@ SystemJS Build Tool [![Build Status][travis-image]][travis-url]

var Builder = require('systemjs-builder');
var builder = new Builder();
var builder = new Builder({
baseURL: path.resolve('some/folder'),
builder.build('myModule', 'outfile.js', {
config: {
baseURL: path.resolve('some/folder'),
// any map config
map: {
jquery: 'jquery-1.2.3/jquery'
},
// opt in to Babel for transpiling over Traceur
transpiler: 'babel'
// any map config
map: {
jquery: 'jquery-1.2.3/jquery'
},
// etc. any SystemJS config
}
// etc. any SystemJS config
})
.build('myModule', 'outfile.js')
.then(function() {

@@ -91,3 +92,3 @@ console.log('Build complete');

To reset the loader state and configuration for a new build, run `builder.reset()`.
To reset the loader state and configuration use `builder.reset()`.

@@ -159,9 +160,7 @@

var Builder = require('systemjs-builder');
var builder = new Builder();
builder.config({
var builder = new Builder({
baseURL: '...',
map: {
}, // etc. config
} // etc. config
});

@@ -188,5 +187,4 @@

var Builder = require('systemjs-builder');
var builder = new Builder();
builder.config({
var builder = new Builder({
// ...

@@ -193,0 +191,0 @@ });

@@ -1,2 +0,2 @@

var react = System.pluginLoader._nodeRequire('react-tools');
var react = System._nodeRequire('react-tools');

@@ -3,0 +3,0 @@ exports.translate = function(load) {

@@ -1,2 +0,2 @@

System.register([], function($__export) {
System.register(['./second'], function($__export) {
return {

@@ -3,0 +3,0 @@ setters: [],

@@ -5,2 +5,6 @@ var fs = require('fs');

function atob(str) {
return new Buffer(str, 'base64').toString('binary');
}
var err = function(e) {

@@ -53,2 +57,25 @@ setTimeout(function() {

it('can render inline', function(done) {
var module = 'tree/amd-2';
var filename = 'inline-source-map.js';
var instance = new Builder('./test/cfg.js');
instance.build(module, null, { sourceMaps: 'inline' })
.then(function(output) {
assert.equal(undefined, output.sourceMap);
var source = output.source;
assert.equal(1, source.match(/sourceMappingURL=/g).length);
var lines = output.source.split("\n");
var lastLine = lines[lines.length - 1];
var commentPrefix = /^\/\/# sourceMappingURL=data:application\/json;base64,/;
assert(lastLine.match(commentPrefix));
var encoding = lastLine.replace(commentPrefix, "");
var decoded = JSON.parse(atob(encoding));
// not a regular array so tedious
assert.equal(1, decoded.sources.length);
assert.equal('tree/amd-2.js', decoded.sources[0]);
done();
});
});
describe('sources paths', function() {

@@ -55,0 +82,0 @@

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