Comparing version 0.7.2 to 0.8.0
@@ -31,5 +31,5 @@ var util = require('util'), | ||
(function(p) { | ||
p.getModuleId = getModuleId; | ||
function getModuleId(m) { | ||
return m.id; | ||
p.getModuleIdAst = getModuleIdAst; | ||
function getModuleIdAst(m) { | ||
return ["string", m.id]; | ||
} | ||
@@ -51,3 +51,3 @@ | ||
function makeDefine(m, subtree) { | ||
return ["call", ["name", "define"], [["string", this.getModuleId(m)], subtree]]; | ||
return getFunctionCallStatementAst("define", [this.getModuleIdAst(m), subtree]); | ||
} | ||
@@ -57,3 +57,3 @@ | ||
function renderRequireCall(m) { | ||
return ["call", ["name", "require"], [["string", this.getModuleId(m)]]]; | ||
return getFunctionCallStatementAst("require", [this.getModuleIdAst(m)]); | ||
} | ||
@@ -97,3 +97,3 @@ | ||
["dot", ["name", "module"], "exports"], | ||
["call", ["name", "require"], [["string", this.getModuleId(m.duplicateOf)]]] | ||
getFunctionCallAst("require", [this.getModuleIdAst(m.duplicateOf)]) | ||
] | ||
@@ -122,2 +122,12 @@ ]; | ||
exports.getFunctionCallAst = getFunctionCallAst; | ||
function getFunctionCallAst(name, args) { | ||
return ["call", ["name", name], args]; | ||
} | ||
exports.getFunctionCallStatementAst = getFunctionCallStatementAst; | ||
function getFunctionCallStatementAst(name, args) { | ||
return ["stat", getFunctionCallAst(name, args)]; | ||
} | ||
exports.toAstBody = toAstBody; | ||
@@ -124,0 +134,0 @@ function toAstBody(ast) { |
@@ -0,1 +1,5 @@ | ||
var DEV = 'dev', | ||
PROD = 'prod'; | ||
exports.createBuilder = createBuilder; | ||
@@ -54,3 +58,3 @@ exports.create = createBuilder; | ||
this.setDevConstant(clonedConsts, this.config.environment); | ||
this.setDevConstant(clonedConsts); | ||
@@ -66,19 +70,36 @@ result.lazyEval = lazyEval; | ||
p.setDevConstant = setDevConstant; | ||
function setDevConstant(constants, env) { | ||
var isDev; | ||
function setDevConstant(constants) { | ||
var env = this.getEnv(), | ||
isDev = env === DEV; | ||
if (typeof env !== 'string') { | ||
return; | ||
if (env === null) { return; } | ||
if ('__DEV__' in constants && constants.__DEV__ !== isDev) { | ||
var msg = 'Contradictory __DEV__ constant (' + JSON.stringify(constants.__DEV__) + ') '; | ||
msg += 'and config.environment (' + JSON.stringify(this.config.environment) + ') values.\n' | ||
msg += 'When using config.environment, avoid also setting __DEV__ constants.' | ||
throw new Error(msg); | ||
} | ||
constants.__DEV__ = isDev; | ||
} | ||
p.getEnv = function() { | ||
var config = this.config, | ||
env = config.environment; | ||
if (!('environment' in config)) { | ||
return null; | ||
} | ||
switch (env) { | ||
case 'dev': | ||
case DEV: | ||
case '__DEV__': | ||
case 'development': | ||
isDev = true; | ||
return DEV; | ||
break; | ||
case 'prod': | ||
case PROD: | ||
case '__PROD__': | ||
case 'production': | ||
isDev = false; | ||
return PROD; | ||
break; | ||
@@ -88,11 +109,2 @@ default: | ||
} | ||
if (constants && '__DEV__' in constants && constants.__DEV__ !== isDev) { | ||
var msg = 'Contradictory __DEV__ constant (' + JSON.stringify(constants.__DEV__) + ') '; | ||
msg += 'and config.environment (' + JSON.stringify(env) + ') values.\n' | ||
msg += 'When using config.environment, avoid also setting __DEV__ constants.' | ||
throw new Error(msg); | ||
} | ||
constants.__DEV__ = isDev; | ||
} | ||
@@ -102,3 +114,11 @@ | ||
function createCollector(config) { | ||
return require('./collector').create(config); | ||
var collector; | ||
if (this.getEnv() === DEV) { | ||
collector = './dev-collector'; | ||
} else if (config.minify) { | ||
collector = config.resolveIdentifiers ? './resolved-ast-collector' : './ast-collector'; | ||
} else { | ||
collector = './collector'; | ||
} | ||
return require(collector).create(config); | ||
} | ||
@@ -105,0 +125,0 @@ |
@@ -33,6 +33,5 @@ var util = require('util'), | ||
function makeDefine(m, src) { | ||
var output = '', | ||
identifier = m.indexModule ? m.indexModule.id : m.id; | ||
var output = ''; | ||
output += '\n// module: ' + m.id; | ||
output += '\n// file: ' + m.searchPath + '/' + identifier + m.ext; | ||
output += '\n// file: ' + m.relativePath; | ||
output += '\ndefine("' + m.id + '", ' + src + ');'; | ||
@@ -79,3 +78,4 @@ return output; | ||
function escapeModule(m) { | ||
return '"' + this.escape(this.getModuleSrc(m), this.config.inlineSafe) + '"'; | ||
var body = this.getModuleSrc(m) + '\n//@ sourceURL=' + m.relativePath; | ||
return '"' + this.escape(body, this.config.inlineSafe) + '"'; | ||
} | ||
@@ -82,0 +82,0 @@ |
@@ -25,7 +25,19 @@ var util = require('util'), | ||
(function(p) { | ||
p.getModuleId = getModuleId; | ||
function getModuleId(m) { | ||
return m.getHashCode(); | ||
p.setModules = setModules; | ||
function setModules(modules) { | ||
var m, _modules = {}; | ||
for (var id in modules) { | ||
m = modules[id]; | ||
if (!m.duplicateOf) { | ||
_modules[id] = m; | ||
} | ||
} | ||
this._modules = _modules; | ||
} | ||
p.getModuleIdAst = getModuleIdAst; | ||
function getModuleIdAst(m) { | ||
return ["string", m.getHashCode()]; | ||
} | ||
p.renderRuntime = renderRuntime; | ||
@@ -46,4 +58,3 @@ function renderRuntime() { | ||
args = args.slice(0); | ||
var hash = self.getModuleId(modules[ident]); | ||
args[0] = ['string', hash]; | ||
args[0] = self.getModuleIdAst(modules[ident]);; | ||
return [this[0], expr, args]; | ||
@@ -50,0 +61,0 @@ } |
@@ -43,2 +43,5 @@ var fs = require('fs'), | ||
if (err) { | ||
err.file = packageFile; | ||
err.longDesc = err.toString() + '. Malformed JSON in descriptor file:\n ' + packageFile; | ||
err.toString = function() { return err.longDesc; }; | ||
callback(err); | ||
@@ -45,0 +48,0 @@ } else { |
@@ -5,5 +5,5 @@ { | ||
"main": "./main", | ||
"version": "0.7.2", | ||
"version": "0.8.0", | ||
"dependencies": { | ||
"module-grapher": "0.10.x", | ||
"module-grapher": ">=0.10.2", | ||
"uglify-js": ">=1.0.7" | ||
@@ -10,0 +10,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29652
18
791
54
9
+ Addedmodule-grapher@0.11.0(transitive)
+ Addeduglify-js@1.3.5(transitive)
- Removedmodule-grapher@0.10.4(transitive)
Updatedmodule-grapher@>=0.10.2