Skip to content

Commit d88b0ac

Browse files
committed
Fixes #988 Pass layer module ID and path to builder write method
1 parent e86dbb2 commit d88b0ac

File tree

5 files changed

+74
-8
lines changed

5 files changed

+74
-8
lines changed

build/jslib/build.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,11 @@ define(function (require) {
19771977
singleContents = config.onBuildWrite(moduleName, path, singleContents);
19781978
}
19791979
};
1980-
builder.write(parts.prefix, parts.name, writeApi);
1980+
1981+
builder.write(parts.prefix, parts.name, writeApi, {
1982+
name: module.onCompleteData.name,
1983+
path: module.onCompleteData.path
1984+
});
19811985
}
19821986
return;
19831987
} else {

build/tests/builds.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ define(['build', 'env!env/file', 'env', 'lang'], function (build, file, env, lan
866866

867867
build(["lib/plugins/buildPluginFirst.js"]);
868868

869-
t.is(nol(c("lib/plugins/expected.js")),
869+
t.is(nol(c("lib/plugins/expected-buildPluginFirst.js")),
870870
nol(c("lib/plugins/main-builtPluginFirst.js")));
871871

872872
require._buildReset();
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
define('util',[],function () {
2+
function upper(text) {
3+
return text.toUpperCase();
4+
};
5+
6+
return upper;
7+
});
8+
9+
if (typeof define === 'function' && define.amd) {
10+
define('converter',['util'], function (util) {
11+
12+
return {
13+
version: '2',
14+
convert: function (text) {
15+
return util(text);
16+
}
17+
};
18+
});
19+
};
20+
define('plug',['converter'], function (converter) {
21+
var buildMap = {};
22+
23+
function jsEscape(content) {
24+
return content.replace(/(['\\])/g, '\\$1')
25+
.replace(/[\f]/g, "\\f")
26+
.replace(/[\b]/g, "\\b")
27+
.replace(/[\n]/g, "\\n")
28+
.replace(/[\t]/g, "\\t")
29+
.replace(/[\r]/g, "\\r");
30+
}
31+
32+
return {
33+
version: '1',
34+
load: function (name, require, onLoad, config) {
35+
var converted = converter.convert(name);
36+
buildMap[name] = converted;
37+
onLoad(converted);
38+
},
39+
40+
write: function (pluginName, moduleName, write, data) {
41+
if (moduleName in buildMap) {
42+
var content = jsEscape(buildMap[moduleName]);
43+
write("define('" + pluginName + "!" + moduleName +
44+
"', function () { /* name: " + data.name + " path: " + data.path.split(/[\/\\]/).pop() + " */ return '" + content + "';});\n");
45+
}
46+
}
47+
};
48+
});
49+
50+
51+
define('plug!shouldbeuppercasetext', function () { /* name: plug path: main-builtPluginFirst.js */ return 'SHOULDBEUPPERCASETEXT';});
52+
53+
require(['plug', 'converter', 'plug!shouldbeuppercasetext'],
54+
function (plug, converter, text) {
55+
console.log('plugin version: ' + plug.version);
56+
console.log('converter version: ' + converter.version);
57+
console.log('converted text: ' + text);
58+
});
59+
60+
define("main", function(){});
61+

build/tests/lib/plugins/expected.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
define('util',[],function () {
32
function upper(text) {
43
return text.toUpperCase();
@@ -38,17 +37,18 @@ define('plug',['converter'], function (converter) {
3837
onLoad(converted);
3938
},
4039

41-
write: function (pluginName, moduleName, write, config) {
40+
write: function (pluginName, moduleName, write, data) {
4241
if (moduleName in buildMap) {
4342
var content = jsEscape(buildMap[moduleName]);
4443
write("define('" + pluginName + "!" + moduleName +
45-
"', function () { return '" + content + "';});\n");
44+
"', function () { /* name: " + data.name + " path: " + data.path.split(/[\/\\]/).pop() + " */ return '" + content + "';});\n");
4645
}
4746
}
4847
};
4948
});
5049

51-
define('plug!shouldbeuppercasetext', function () { return 'SHOULDBEUPPERCASETEXT';});
50+
51+
define('plug!shouldbeuppercasetext', function () { /* name: main path: main-built.js */ return 'SHOULDBEUPPERCASETEXT';});
5252

5353
require(['plug', 'converter', 'plug!shouldbeuppercasetext'],
5454
function (plug, converter, text) {
@@ -58,3 +58,4 @@ function (plug, converter, text) {
5858
});
5959

6060
define("main", function(){});
61+

build/tests/lib/plugins/plug.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ define(['converter'], function (converter) {
1818
onLoad(converted);
1919
},
2020

21-
write: function (pluginName, moduleName, write, config) {
21+
write: function (pluginName, moduleName, write, data) {
2222
if (moduleName in buildMap) {
2323
var content = jsEscape(buildMap[moduleName]);
2424
write("define('" + pluginName + "!" + moduleName +
25-
"', function () { return '" + content + "';});\n");
25+
"', function () { /* name: " + data.name + " path: " + data.path.split(/[\/\\]/).pop() + " */ return '" + content + "';});\n");
2626
}
2727
}
2828
};

0 commit comments

Comments
 (0)