Cleanup build and make legacy command work with modularize.

Former-commit-id: 89cfa2e693bd299096f9418f5cab7f41c37ddf2a
This commit is contained in:
John-David Dalton
2013-07-30 08:53:56 -07:00
parent a51a355a53
commit 70a5efa1d6

View File

@@ -105,7 +105,7 @@
// public functions // public functions
'after': [], 'after': [],
'assign': ['createCallback', 'createIterator'], 'assign': ['createIterator'],
'at': ['baseFlatten', 'isString'], 'at': ['baseFlatten', 'isString'],
'bind': ['createBound'], 'bind': ['createBound'],
'bindAll': ['baseFlatten', 'bind', 'functions'], 'bindAll': ['baseFlatten', 'bind', 'functions'],
@@ -118,7 +118,7 @@
'countBy': ['createAggregator'], 'countBy': ['createAggregator'],
'createCallback': ['baseIsEqual', 'bind', 'identity', 'isObject', 'keys', 'setBindData'], 'createCallback': ['baseIsEqual', 'bind', 'identity', 'isObject', 'keys', 'setBindData'],
'debounce': ['isObject'], 'debounce': ['isObject'],
'defaults': ['createCallback', 'createIterator'], 'defaults': ['createIterator'],
'defer': ['bind'], 'defer': ['bind'],
'delay': [], 'delay': [],
'difference': ['baseFlatten', 'cacheIndexOf', 'createCache', 'getIndexOf', 'releaseObject'], 'difference': ['baseFlatten', 'cacheIndexOf', 'createCache', 'getIndexOf', 'releaseObject'],
@@ -773,7 +773,8 @@
propDepMap = state.propDepMap, propDepMap = state.propDepMap,
varDepMap = state.varDepMap; varDepMap = state.varDepMap;
var identifiers = buildFuncs.concat(includeProps, includeVars), var empty = [],
identifiers = buildFuncs.concat(includeProps, includeVars),
sep = '/'; sep = '/';
var categories = _.uniq(_.compact(identifiers.map(function(identifier) { var categories = _.uniq(_.compact(identifiers.map(function(identifier) {
@@ -785,17 +786,6 @@
'support': true 'support': true
}; };
// set state
state.buildFuncs = [];
state.plusFuncs = [];
state.minusFuncs = [];
state.isAMD = state.isCommonJS = state.isGlobal = state.isNode = false;
// provide a destination if one isn't given
if (!outputPath) {
outputPath = '.' + path.sep + 'modularize';
}
var getDepPath = function(dep, fromPath) { var getDepPath = function(dep, fromPath) {
if (dep == 'require') { if (dep == 'require') {
return dep; return dep;
@@ -821,6 +811,14 @@
: (getCategory(identifier, funcDepMap) || 'internals').toLowerCase() + sep; : (getCategory(identifier, funcDepMap) || 'internals').toLowerCase() + sep;
}; };
// prepare state
state.plusFuncs = state.minusFuncs = empty;
state.isAMD = state.isCommonJS = state.isGlobal = state.isNode = false;
// provide a destination if one isn't given
if (!outputPath) {
outputPath = '.' + path.sep + 'modularize';
}
// create modules for each identifier // create modules for each identifier
identifiers.forEach(function(identifier) { identifiers.forEach(function(identifier) {
var modulePath = getPath(identifier), var modulePath = getPath(identifier),
@@ -842,13 +840,11 @@
'});' '});'
); );
} }
state.buildFuncs = state.includeFuncs = state.includeProps = state.includeVars = empty;
state.iife = iife.join('\n'); state.iife = iife.join('\n');
state.outputPath = path.join(outputPath, modulePath + identifier + '.js');
var include = [identifier]; var include = [identifier];
state.buildFuncs = state.includeFuncs = [];
state.includeProps = [];
state.includeVars = [];
if (_.contains(includeProps, identifier)) { if (_.contains(includeProps, identifier)) {
state.includeProps = include; state.includeProps = include;
} }
@@ -858,14 +854,11 @@
else { else {
state.buildFuncs = state.includeFuncs = include; state.buildFuncs = state.includeFuncs = include;
} }
state.outputPath = path.join(outputPath, modulePath + identifier + '.js');
build(state); build(state);
}); });
// clear state // clear state
state.buildFuncs = state.includeFuncs = []; state.buildFuncs = state.includeFuncs = state.includeProps = state.includeVars = empty;
state.includeProps = [];
state.includeVars = [];
// create category modules // create category modules
categories.forEach(function(category) { categories.forEach(function(category) {
@@ -2701,11 +2694,13 @@
// update dependencies // update dependencies
if (isLegacy) { if (isLegacy) {
funcDepMap.defer = _.without(funcDepMap.defer, 'bind'); funcDepMap.defer = _.without(funcDepMap.defer, 'bind');
funcDepMap.isPlainObject = _.without(funcDepMap.isPlainObject, 'shimIsPlainObject'); funcDepMap.isPlainObject = funcDepMap.shimIsPlainObject.slice();
funcDepMap.keys = _.without(funcDepMap.keys, 'shimKeys'); funcDepMap.keys = funcDepMap.shimKeys.slice();
_.forOwn(varDepMap, function(deps, varName) { _.forOwn(varDepMap, function(deps, funcName) {
varDepMap[varName] = _.without(deps, 'reNative'); if (funcName != 'createBound') {
varDepMap[funcName] = _.without(deps, 'reNative');
}
}); });
} }
if (isMobile) { if (isMobile) {
@@ -2817,6 +2812,9 @@
if (!(isUnderscore && isLodash(funcName))) { if (!(isUnderscore && isLodash(funcName))) {
(varDepMap[funcName] = _.without(varDepMap[funcName], 'defaultsIteratorOptions', 'eachIteratorOptions', 'forOwnIteratorOptions')).push('objectTypes'); (varDepMap[funcName] = _.without(varDepMap[funcName], 'defaultsIteratorOptions', 'eachIteratorOptions', 'forOwnIteratorOptions')).push('objectTypes');
var deps = funcDepMap[funcName] = _.without(funcDepMap[funcName], 'createIterator'); var deps = funcDepMap[funcName] = _.without(funcDepMap[funcName], 'createIterator');
if (funcName != 'shimKeys') {
deps.push('createCallback');
}
if (funcName != 'forIn' && funcName != 'shimKeys') { if (funcName != 'forIn' && funcName != 'shimKeys') {
deps.push('keys'); deps.push('keys');
} }
@@ -2878,6 +2876,7 @@
} }
} }
if (isModularize) { if (isModularize) {
funcDepMap.createIterator.push('createCallback');
_.forOwn(funcDepMap, function(deps, funcName) { _.forOwn(funcDepMap, function(deps, funcName) {
if (_.contains(deps, 'getIndexOf')) { if (_.contains(deps, 'getIndexOf')) {
(deps = funcDepMap[funcName] = _.without(deps, 'getIndexOf')).push( 'baseIndexOf'); (deps = funcDepMap[funcName] = _.without(deps, 'getIndexOf')).push( 'baseIndexOf');
@@ -2944,7 +2943,7 @@
push.apply(result, identifiers); push.apply(result, identifiers);
buildFuncs = _.union(buildFuncs, deps); buildFuncs = _.union(buildFuncs, deps);
result = expand(result, depMap, deps); result = expand(result, depMap, deps, stack);
} }
return result; return result;
}, result)); }, result));
@@ -4182,7 +4181,6 @@
if (isNoDep) { if (isNoDep) {
source = removeAssignments(source); source = removeAssignments(source);
source = removeFromCreateIterator(source, 'lodash');
source = removeGetIndexOf(source); source = removeGetIndexOf(source);
source = removeLodashWrapper(source); source = removeLodashWrapper(source);
@@ -4208,6 +4206,11 @@
return match.replace(/(:\s*)lodash\b/, "$1{ 'escape': escape }"); return match.replace(/(:\s*)lodash\b/, "$1{ 'escape': escape }");
}); });
// replace `lodash` with `createCallback` in `createIterator`
source = source.replace(matchFunction(source, 'createIterator'), function(match) {
return match.replace(/\blodash\b/g, 'createCallback');
});
// remove unneeded variable dependencies // remove unneeded variable dependencies
_.each(varDependencies, function(varName) { _.each(varDependencies, function(varName) {
if (!_.contains(includeVars, varName)) { if (!_.contains(includeVars, varName)) {