Skip to content

Commit

Permalink
Fixes #988 Pass layer module ID and path to builder write method
Browse files Browse the repository at this point in the history
  • Loading branch information
jrburke committed Aug 27, 2018
1 parent e86dbb2 commit d88b0ac
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 8 deletions.
6 changes: 5 additions & 1 deletion build/jslib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion build/tests/builds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
61 changes: 61 additions & 0 deletions build/tests/lib/plugins/expected-buildPluginFirst.js
Original file line number Diff line number Diff line change
@@ -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(){});

9 changes: 5 additions & 4 deletions build/tests/lib/plugins/expected.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

define('util',[],function () {
function upper(text) {
return text.toUpperCase();
Expand Down Expand Up @@ -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) {
Expand All @@ -58,3 +58,4 @@ function (plug, converter, text) {
});

define("main", function(){});

4 changes: 2 additions & 2 deletions build/tests/lib/plugins/plug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
};
Expand Down

0 comments on commit d88b0ac

Please sign in to comment.