From d88b0ac79eff2c10c1b4bbbeb1272bc46ec318e2 Mon Sep 17 00:00:00 2001 From: jrburke Date: Sun, 26 Aug 2018 21:56:57 -0700 Subject: [PATCH] Fixes #988 Pass layer module ID and path to builder write method --- build/jslib/build.js | 6 +- build/tests/builds.js | 2 +- .../lib/plugins/expected-buildPluginFirst.js | 61 +++++++++++++++++++ build/tests/lib/plugins/expected.js | 9 +-- build/tests/lib/plugins/plug.js | 4 +- 5 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 build/tests/lib/plugins/expected-buildPluginFirst.js diff --git a/build/jslib/build.js b/build/jslib/build.js index 11def56f..adc729e0 100644 --- a/build/jslib/build.js +++ b/build/jslib/build.js @@ -1977,7 +1977,11 @@ define(function (require) { singleContents = config.onBuildWrite(moduleName, path, singleContents); } }; - builder.write(parts.prefix, parts.name, writeApi); + + builder.write(parts.prefix, parts.name, writeApi, { + name: module.onCompleteData.name, + path: module.onCompleteData.path + }); } return; } else { diff --git a/build/tests/builds.js b/build/tests/builds.js index a10f4765..0cb64dfc 100644 --- a/build/tests/builds.js +++ b/build/tests/builds.js @@ -866,7 +866,7 @@ define(['build', 'env!env/file', 'env', 'lang'], function (build, file, env, lan build(["lib/plugins/buildPluginFirst.js"]); - t.is(nol(c("lib/plugins/expected.js")), + t.is(nol(c("lib/plugins/expected-buildPluginFirst.js")), nol(c("lib/plugins/main-builtPluginFirst.js"))); require._buildReset(); diff --git a/build/tests/lib/plugins/expected-buildPluginFirst.js b/build/tests/lib/plugins/expected-buildPluginFirst.js new file mode 100644 index 00000000..84febc03 --- /dev/null +++ b/build/tests/lib/plugins/expected-buildPluginFirst.js @@ -0,0 +1,61 @@ +define('util',[],function () { + function upper(text) { + return text.toUpperCase(); + }; + + return upper; +}); + +if (typeof define === 'function' && define.amd) { + define('converter',['util'], function (util) { + + return { + version: '2', + convert: function (text) { + return util(text); + } + }; + }); +}; +define('plug',['converter'], function (converter) { + var buildMap = {}; + + function jsEscape(content) { + return content.replace(/(['\\])/g, '\\$1') + .replace(/[\f]/g, "\\f") + .replace(/[\b]/g, "\\b") + .replace(/[\n]/g, "\\n") + .replace(/[\t]/g, "\\t") + .replace(/[\r]/g, "\\r"); + } + + return { + version: '1', + load: function (name, require, onLoad, config) { + var converted = converter.convert(name); + buildMap[name] = converted; + onLoad(converted); + }, + + write: function (pluginName, moduleName, write, data) { + if (moduleName in buildMap) { + var content = jsEscape(buildMap[moduleName]); + write("define('" + pluginName + "!" + moduleName + + "', function () { /* name: " + data.name + " path: " + data.path.split(/[\/\\]/).pop() + " */ return '" + content + "';});\n"); + } + } + }; +}); + + +define('plug!shouldbeuppercasetext', function () { /* name: plug path: main-builtPluginFirst.js */ return 'SHOULDBEUPPERCASETEXT';}); + +require(['plug', 'converter', 'plug!shouldbeuppercasetext'], +function (plug, converter, text) { + console.log('plugin version: ' + plug.version); + console.log('converter version: ' + converter.version); + console.log('converted text: ' + text); +}); + +define("main", function(){}); + diff --git a/build/tests/lib/plugins/expected.js b/build/tests/lib/plugins/expected.js index 8f6c502c..422c683f 100644 --- a/build/tests/lib/plugins/expected.js +++ b/build/tests/lib/plugins/expected.js @@ -1,4 +1,3 @@ - define('util',[],function () { function upper(text) { return text.toUpperCase(); @@ -38,17 +37,18 @@ define('plug',['converter'], function (converter) { onLoad(converted); }, - write: function (pluginName, moduleName, write, config) { + write: function (pluginName, moduleName, write, data) { if (moduleName in buildMap) { var content = jsEscape(buildMap[moduleName]); write("define('" + pluginName + "!" + moduleName + - "', function () { return '" + content + "';});\n"); + "', function () { /* name: " + data.name + " path: " + data.path.split(/[\/\\]/).pop() + " */ return '" + content + "';});\n"); } } }; }); -define('plug!shouldbeuppercasetext', function () { return 'SHOULDBEUPPERCASETEXT';}); + +define('plug!shouldbeuppercasetext', function () { /* name: main path: main-built.js */ return 'SHOULDBEUPPERCASETEXT';}); require(['plug', 'converter', 'plug!shouldbeuppercasetext'], function (plug, converter, text) { @@ -58,3 +58,4 @@ function (plug, converter, text) { }); define("main", function(){}); + diff --git a/build/tests/lib/plugins/plug.js b/build/tests/lib/plugins/plug.js index 24cdca45..e4bcab2b 100644 --- a/build/tests/lib/plugins/plug.js +++ b/build/tests/lib/plugins/plug.js @@ -18,11 +18,11 @@ define(['converter'], function (converter) { onLoad(converted); }, - write: function (pluginName, moduleName, write, config) { + write: function (pluginName, moduleName, write, data) { if (moduleName in buildMap) { var content = jsEscape(buildMap[moduleName]); write("define('" + pluginName + "!" + moduleName + - "', function () { return '" + content + "';});\n"); + "', function () { /* name: " + data.name + " path: " + data.path.split(/[\/\\]/).pop() + " */ return '" + content + "';});\n"); } } };