Skip to content

Commit 05c5479

Browse files
authored
Merge pull request webpack#5849 from cdata/fix-5843
Fixes webpack#5843
2 parents 801a253 + e5d03cb commit 05c5479

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

lib/UmdMainTemplatePlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class UmdMainTemplatePlugin {
171171
" for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n" +
172172
" }\n"
173173
) +
174-
"})(this, function(" + externalsArguments(externals) + ") {\nreturn ", "webpack/universalModuleDefinition"), source, ";\n})");
174+
"})(typeof self !== 'undefined' ? self : this, function(" + externalsArguments(externals) + ") {\nreturn ", "webpack/universalModuleDefinition"), source, ";\n})");
175175
});
176176
mainTemplate.plugin("global-hash-paths", (paths) => {
177177
if(this.names.root) paths = paths.concat(this.names.root);
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* global describe, beforeEach, it */
2+
"use strict";
3+
4+
const should = require("should");
5+
const TemplatePluginEnvironment = require("./helpers/TemplatePluginEnvironment");
6+
const ConcatSource = require("webpack-sources").ConcatSource;
7+
const UmdMainTemplatePlugin = require("../lib/UmdMainTemplatePlugin");
8+
9+
describe("UmdMainTemplatePlugin", () => {
10+
11+
const setupBasicTemplatePlugin = name => {
12+
const plugin = new UmdMainTemplatePlugin({
13+
amd: name
14+
}, {
15+
auxiliaryComment: {}
16+
});
17+
const templatePlugin = new TemplatePluginEnvironment();
18+
const environment = templatePlugin.getEnvironmentStub();
19+
environment.mainTemplate.applyPluginsWaterfall = () => [];
20+
plugin.apply(environment);
21+
return templatePlugin;
22+
};
23+
24+
let templatePlugin;
25+
26+
beforeEach(() => {
27+
templatePlugin = setupBasicTemplatePlugin("foo");
28+
});
29+
30+
describe("when applied", () => {
31+
describe("event handlers", () => {
32+
let eventBindings;
33+
34+
beforeEach(() => {
35+
eventBindings = templatePlugin.getEventBindings();
36+
});
37+
38+
describe("handling render-with-entry", () => {
39+
let eventHandler;
40+
41+
beforeEach(() => {
42+
eventHandler = eventBindings
43+
.filter(eventBinding => eventBinding.name === 'render-with-entry')
44+
.map(eventBinding => eventBinding.handler)
45+
.pop();
46+
});
47+
48+
it("creates source that safely detects the global object", () => {
49+
const source = eventHandler("{ foo: true }", {
50+
getModules: () => []
51+
}, "bar");
52+
53+
source.should.be.instanceof(ConcatSource);
54+
source.source().should.be.exactly(`(function webpackUniversalModuleDefinition(root, factory) {
55+
if(typeof exports === 'object' && typeof module === 'object')
56+
module.exports = factory();
57+
else if(typeof define === 'function' && define.amd)
58+
define([], factory);
59+
else {
60+
var a = factory();
61+
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
62+
}
63+
})(typeof self !== 'undefined' ? self : this, function() {
64+
return { foo: true };
65+
})`);
66+
});
67+
});
68+
});
69+
});
70+
});

0 commit comments

Comments
 (0)