Skip to content

Commit

Permalink
Fixes #324, rawText build option for seeding text content for given m…
Browse files Browse the repository at this point in the history
…odule IDs.
  • Loading branch information
jrburke committed Nov 27, 2012
1 parent 5c5a5b8 commit 66f1877
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ build/tests/lib/plugins/onLayerEnd/main-built.js
build/tests/lib/plugins/optimizeAllPluginResources/www-built
build/tests/lib/pragmas/override/built
build/tests/lib/pristineSrc/built
build/tests/lib/rawText/built.js
build/tests/lib/removeCombined/app-built
build/tests/lib/removeCombined/baseUrl-built
build/tests/lib/requireHoist/perLayer/built
Expand Down
8 changes: 8 additions & 0 deletions build/example.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,14 @@
return contents.replace(/bar/g, 'foo');
},

//Introduced in 2.1.3: Seed raw text contents for the listed module IDs.
//These text contents will be used instead of doing a file IO call for
//those modules. Useful is some module ID contents are dynamically
//based on user input, which is common in web build tools.
rawText: {
'some/id': 'define(["another/id"], function () {});'
},

//Introduced in 2.0.2: if set to true, then the optimizer will add a
//define(require, exports, module) {}); wrapper around any file that seems
//to use commonjs/node module syntax (require, exports) without already
Expand Down
12 changes: 11 additions & 1 deletion build/jslib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ define(function (require) {
*/
build.traceDependencies = function (module, config) {
var include, override, layer, context, baseConfig, oldContext,
registry, id, idParts, pluginId, mod, errUrl,
registry, id, idParts, pluginId, mod, errUrl, rawTextByIds,
errMessage = '',
failedPluginMap = {},
failedPluginIds = [],
Expand Down Expand Up @@ -1241,6 +1241,16 @@ define(function (require) {
require(override);
}

//Now, populate the rawText cache with any values explicitly passed in
//via config.
rawTextByIds = require.s.contexts._.config.rawText;
if (rawTextByIds) {
lang.eachProp(rawTextByIds, function (contents, id) {
var url = require.toUrl(id);
require._cachedRawText[url] = contents;
});
}

//Figure out module layer dependencies by calling require to do the work.
//Configure the callbacks to be called.
deferred.resolve.__requireJsBuild = true;
Expand Down
4 changes: 2 additions & 2 deletions build/jslib/x.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license r.js 2.1.2 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
* @license r.js 2.1.2+ Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/requirejs for details
*/
Expand All @@ -21,7 +21,7 @@ var requirejs, require, define;

var fileName, env, fs, vm, path, exec, rhinoContext, dir, nodeRequire,
nodeDefine, exists, reqMain, loadedOptimizedLib, existsForNode,
version = '2.1.2',
version = '2.1.2+',
jsSuffixRegExp = /\.js$/,
commandOption = '',
useLibLoaded = {},
Expand Down
17 changes: 17 additions & 0 deletions build/tests/builds.js
Original file line number Diff line number Diff line change
Expand Up @@ -1661,4 +1661,21 @@ define(['build', 'env!env/file'], function (build, file) {
);
doh.run();

doh.register("rawText",
[
function rawText(t) {
file.deleteFile("lib/rawText/built.js");

build(["lib/rawText/build.js"]);

t.is(nol(c("lib/rawText/expected.js")),
nol(c("lib/rawText/built.js")));

require._buildReset();
}

]
);
doh.run();

});

0 comments on commit 66f1877

Please sign in to comment.