Permalink
Browse files

Fixes #125, make sure minified files not part of build layers still h…

…ave transport work done to pull out dependencies for simplifed cjs wrapping.
  • Loading branch information...
1 parent 2516ab7 commit 2407d6a726a2460d1ccba70566c541f4966136da @jrburke jrburke committed Apr 20, 2012
View
@@ -28,6 +28,7 @@ build/tests/lib/nestedHas/main-builtNeedB.js
build/tests/lib/nestedHas/main-builtNeedC.js
build/tests/lib/nestedHas/main-builtNeedD.js
build/tests/lib/nestedHas/main-builtNested.js
+build/tests/lib/transportBeforeMinify/www-built
build/tests/override/node_modules
build/tests/override/one-built.js
tests/node/node_modules
View
@@ -138,7 +138,7 @@ function (lang, logger, file, parse, optimize, pragma,
baseConfig, config,
modules, builtModule, srcPath, buildContext,
destPath, moduleName, moduleMap, parentModuleMap, context,
- resources, resource, pluginProcessed = {}, plugin;
+ resources, resource, pluginProcessed = {}, plugin, fileContents;
//Can now run the patches to require.js to allow it to be used for
//build generation. Do it here instead of at the top of the module
@@ -341,7 +341,7 @@ function (lang, logger, file, parse, optimize, pragma,
if (config.out && !config.cssIn) {
//Just need to worry about one JS file.
fileName = config.modules[0]._buildPath;
- optimize.jsFile(fileName, fileName, config);
+ optimize.jsFile(fileName, null, fileName, config);
} else if (!config.cssIn) {
//Normal optimizations across modules.
@@ -352,7 +352,18 @@ function (lang, logger, file, parse, optimize, pragma,
moduleName = fileName.replace(config.dir, '');
//Get rid of the extension
moduleName = moduleName.substring(0, moduleName.length - 3);
- optimize.jsFile(fileName, fileName, config, moduleName, pluginCollector);
+
+ //Convert the file to transport format, but without a name
+ //inserted (by passing null for moduleName) since the files are
+ //standalone, one module per file.
+ fileContents = file.readFile(fileName);
+ fileContents = build.toTransport(config.anonDefRegExp,
+ config.namespaceWithDot,
+ null,
+ fileName,
+ fileContents);
+
+ optimize.jsFile(fileName, fileContents, fileName, config, pluginCollector);
}
//Normalize all the plugin resources.
@@ -1075,7 +1086,8 @@ function (lang, logger, file, parse, optimize, pragma,
layer.modulesWithNames[moduleName] = true;
}
- var deps = null;
+ var deps = null,
+ finalName;
//Look for CommonJS require calls inside the function if this is
//an anonymous define call that just has a function registered.
@@ -1093,7 +1105,12 @@ function (lang, logger, file, parse, optimize, pragma,
}
}
- return start + namespace + "define('" + (namedModule || moduleName) + "'," +
+ finalName = namedModule || moduleName || '';
+ if (finalName) {
+ finalName = "'" + (namedModule || moduleName) + "',";
+ }
+
+ return start + namespace + "define(" + finalName +
(deps ? ('[' + deps.toString() + '],') : '') +
(namedModule ? namedFuncStart.replace(build.leadingCommaRegExp, '') : suffix);
});
View
@@ -159,21 +159,22 @@ function (lang, logger, envOptimize, file, parse,
* through an minifier if one is specified via config.optimize.
*
* @param {String} fileName the name of the file to optimize
+ * @param {String} fileContents the contents to optimize. If this is
+ * a null value, then fileName will be used to read the fileContents.
* @param {String} outFileName the name of the file to use for the
* saved optimized content.
* @param {Object} config the build config object.
- * @param {String} [moduleName] the module name to use for the file.
- * Used for plugin resource collection.
* @param {Array} [pluginCollector] storage for any plugin resources
* found.
*/
- jsFile: function (fileName, outFileName, config, moduleName, pluginCollector) {
+ jsFile: function (fileName, fileContents, outFileName, config, pluginCollector) {
var parts = (config.optimize + "").split('.'),
optimizerName = parts[0],
- keepLines = parts[1] === 'keepLines',
- fileContents;
+ keepLines = parts[1] === 'keepLines';
- fileContents = file.readFile(fileName);
+ if (!fileContents) {
+ fileContents = file.readFile(fileName);
+ }
fileContents = optimize.js(fileName, fileContents, optimizerName,
keepLines, config, pluginCollector);
View
@@ -846,4 +846,24 @@ define(['build', 'env!env/file'], function (build, file) {
);
doh.run();
+ //Tests https://github.com/jrburke/r.js/issues/125
+ doh.register("transportBeforeMinify",
+ [
+ function transportBeforeMinify(t) {
+ file.deleteFile("lib/transportBeforeMinify/www-built");
+
+ build(["lib/transportBeforeMinify/build.js"]);
+
+ //Make sure the dependencies are listed as an array in the
+ //file that is not part of a build layer, but still uglified
+ var contents = nol(c("lib/transportBeforeMinify/www-built/js/b.js"));
+ t.is(true, /define\(\["require"\,"a"\]\,function/.test(contents));
+
+ require._buildReset();
+ }
+
+ ]
+ );
+ doh.run();
+
});
@@ -0,0 +1,9 @@
+{
+ appDir: 'www',
+ baseUrl: 'js',
+ name: 'app',
+ dir: 'www-built',
+ modules: [{
+ name: 'app'
+ }]
+}
@@ -0,0 +1,4 @@
+define({
+ name: 'a'
+});
+
@@ -0,0 +1,4 @@
+
+require(['somelib'], function (somelib) {
+
+});
@@ -0,0 +1,3 @@
+define(function (require) {
+ return require('a');
+});
@@ -0,0 +1,3 @@
+define(function (require) {
+ return require('a');
+});

0 comments on commit 2407d6a

Please sign in to comment.