Skip to content

Commit

Permalink
--extend option support for UMD builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Jul 3, 2017
1 parent b0f366e commit a001e6b
Show file tree
Hide file tree
Showing 25 changed files with 117 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/finalisers/umd.js
Expand Up @@ -49,7 +49,7 @@ export default function umd ( bundle, magicString, { exportMode, indentString, i
if ( exportMode === 'named' ) {
amdDeps.unshift( `'exports'` );
cjsDeps.unshift( `exports` );
globalDeps.unshift( `(${setupNamespace(options.moduleName)} = ${globalProp(options.moduleName)} || {})` );
globalDeps.unshift( `(${setupNamespace(options.moduleName)} = ${options.extend ? `${globalProp(options.moduleName)} || ` : '' }{})` );

args.unshift( 'exports' );
}
Expand Down
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.myModule = global.myModule || {})));
(factory((global.myModule = {})));
}(this, (function (exports) { 'use strict';

exports.Foo = class Foo {};
Expand Down
2 changes: 1 addition & 1 deletion test/form/assignment-to-exports/_expected/umd.js
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.bundle = global.bundle || {})));
(factory((global.bundle = {})));
}(this, (function (exports) { 'use strict';

exports.foo = 1;
Expand Down
2 changes: 1 addition & 1 deletion test/form/computed-properties/_expected/umd.js
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.computedProperties = global.computedProperties || {})));
(factory((global.computedProperties = {})));
}(this, (function (exports) { 'use strict';

var foo = 'foo';
Expand Down
2 changes: 1 addition & 1 deletion test/form/dedupes-external-imports/_expected/umd.js
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('external')) :
typeof define === 'function' && define.amd ? define(['exports', 'external'], factory) :
(factory((global.myBundle = global.myBundle || {}),global.external));
(factory((global.myBundle = {}),global.external));
}(this, (function (exports,external) { 'use strict';

class Foo extends external.Component {
Expand Down
2 changes: 1 addition & 1 deletion test/form/export-all-from-internal/_expected/umd.js
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.exposedInternals = global.exposedInternals || {})));
(factory((global.exposedInternals = {})));
}(this, (function (exports) { 'use strict';

const a = 1;
Expand Down
2 changes: 1 addition & 1 deletion test/form/export-all-multiple/_expected/umd.js
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('foo'), require('bar'), require('baz')) :
typeof define === 'function' && define.amd ? define(['exports', 'foo', 'bar', 'baz'], factory) :
(factory((global.myBundle = global.myBundle || {}),global.foo,global.bar,global.baz));
(factory((global.myBundle = {}),global.foo,global.bar,global.baz));
}(this, (function (exports,foo,bar,baz) { 'use strict';

Object.keys(foo).forEach(function (key) { exports[key] = foo[key]; });
Expand Down
2 changes: 1 addition & 1 deletion test/form/export-default-import/_expected/umd.js
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('x')) :
typeof define === 'function' && define.amd ? define(['exports', 'x'], factory) :
(factory((global.myBundle = global.myBundle || {}),global.x));
(factory((global.myBundle = {}),global.x));
}(this, (function (exports,x) { 'use strict';

x = x && 'default' in x ? x['default'] : x;
Expand Down
2 changes: 1 addition & 1 deletion test/form/exports-at-end-if-possible/_expected/umd.js
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.myBundle = global.myBundle || {})));
(factory((global.myBundle = {})));
}(this, (function (exports) { 'use strict';

var FOO = 'foo';
Expand Down
2 changes: 1 addition & 1 deletion test/form/legacy-getter/_expected/umd.js
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.foo = global.foo || {})));
(factory((global.foo = {})));
}(this, (function (exports) { 'use strict';

var browserSpecificThing;
Expand Down
2 changes: 1 addition & 1 deletion test/form/legacy/_expected/umd.js
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.myBundle = global.myBundle || {})));
(factory((global.myBundle = {})));
}(this, (function (exports) { 'use strict';

const foo = 1;
Expand Down
2 changes: 1 addition & 1 deletion test/form/module-name-wat/_expected/umd.js
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.foo = global.foo || {}, global.foo['@scoped/npm-package'] = global.foo['@scoped/npm-package'] || {}, global.foo['@scoped/npm-package'].bar = global.foo['@scoped/npm-package'].bar || {}, global.foo['@scoped/npm-package'].bar['why-would-you-do-this'] = global.foo['@scoped/npm-package'].bar['why-would-you-do-this'] || {})));
(factory((global.foo = global.foo || {}, global.foo['@scoped/npm-package'] = global.foo['@scoped/npm-package'] || {}, global.foo['@scoped/npm-package'].bar = global.foo['@scoped/npm-package'].bar || {}, global.foo['@scoped/npm-package'].bar['why-would-you-do-this'] = {})));
}(this, (function (exports) { 'use strict';

let foo = 'foo';
Expand Down
2 changes: 1 addition & 1 deletion test/form/multiple-exports/_expected/umd.js
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.myBundle = global.myBundle || {})));
(factory((global.myBundle = {})));
}(this, (function (exports) { 'use strict';

var foo = 1;
Expand Down
2 changes: 1 addition & 1 deletion test/form/namespaced-named-exports/_expected/umd.js
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.foo = global.foo || {}, global.foo.bar = global.foo.bar || {}, global.foo.bar.baz = global.foo.bar.baz || {})));
(factory((global.foo = global.foo || {}, global.foo.bar = global.foo.bar || {}, global.foo.bar.baz = {})));
}(this, (function (exports) { 'use strict';

var answer = 42;
Expand Down
2 changes: 1 addition & 1 deletion test/form/no-treeshake/_expected/umd.js
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('external')) :
typeof define === 'function' && define.amd ? define(['exports', 'external'], factory) :
(factory((global.stirred = global.stirred || {}),global.external));
(factory((global.stirred = {}),global.external));
}(this, (function (exports,external) { 'use strict';

var foo = 'unused';
Expand Down
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.myBundle = global.myBundle || {})));
(factory((global.myBundle = {})));
}(this, (function (exports) { 'use strict';

/** A comment for a number */
Expand Down
2 changes: 1 addition & 1 deletion test/form/reexports-from-external/_expected/umd.js
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('external')) :
typeof define === 'function' && define.amd ? define(['exports', 'external'], factory) :
(factory((global.myBundle = global.myBundle || {}),global.external));
(factory((global.myBundle = {}),global.external));
}(this, (function (exports,external) { 'use strict';

Object.keys(external).forEach(function (key) { exports[key] = external[key]; });
Expand Down
9 changes: 9 additions & 0 deletions test/form/umd-noconflict-extend/_config.js
@@ -0,0 +1,9 @@
module.exports = {
description: 'exports noConflict method for default umd when requested',
options: {
extend: true,
noConflict: true,
moduleName: 'FooBar'
}
};

17 changes: 17 additions & 0 deletions test/form/umd-noconflict-extend/_expected/amd.js
@@ -0,0 +1,17 @@
define(['exports'], function (exports) { 'use strict';

function doThings() {
console.log( 'doing things...' );
}

const number = 42;

var setting = 'no';

exports.doThings = doThings;
exports.number = number;
exports.setting = setting;

Object.defineProperty(exports, '__esModule', { value: true });

});
15 changes: 15 additions & 0 deletions test/form/umd-noconflict-extend/_expected/cjs.js
@@ -0,0 +1,15 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

function doThings() {
console.log( 'doing things...' );
}

const number = 42;

var setting = 'no';

exports.doThings = doThings;
exports.number = number;
exports.setting = setting;
9 changes: 9 additions & 0 deletions test/form/umd-noconflict-extend/_expected/es.js
@@ -0,0 +1,9 @@
function doThings() {
console.log( 'doing things...' );
}

const number = 42;

var setting = 'no';

export { doThings, number, setting };
16 changes: 16 additions & 0 deletions test/form/umd-noconflict-extend/_expected/iife.js
@@ -0,0 +1,16 @@
(function (exports) {
'use strict';

function doThings() {
console.log( 'doing things...' );
}

const number = 42;

var setting = 'no';

exports.doThings = doThings;
exports.number = number;
exports.setting = setting;

}((this.FooBar = this.FooBar || {})));
26 changes: 26 additions & 0 deletions test/form/umd-noconflict-extend/_expected/umd.js
@@ -0,0 +1,26 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(function() {
var current = global.FooBar;
var exports = factory((global.FooBar = global.FooBar || {}));
global.FooBar = exports;
exports.noConflict = function() { global.FooBar = current; return exports; };
})();
}(this, (function (exports) { 'use strict';

function doThings() {
console.log( 'doing things...' );
}

const number = 42;

var setting = 'no';

exports.doThings = doThings;
exports.number = number;
exports.setting = setting;

Object.defineProperty(exports, '__esModule', { value: true });

})));
7 changes: 7 additions & 0 deletions test/form/umd-noconflict-extend/main.js
@@ -0,0 +1,7 @@
export function doThings() {
console.log( 'doing things...' );
}

export const number = 42;

export var setting = 'no';
2 changes: 1 addition & 1 deletion test/form/umd-noconflict/_expected/umd.js
Expand Up @@ -3,7 +3,7 @@
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(function() {
var current = global.FooBar;
var exports = factory((global.FooBar = global.FooBar || {}));
var exports = factory((global.FooBar = {}));
global.FooBar = exports;
exports.noConflict = function() { global.FooBar = current; return exports; };
})();
Expand Down

0 comments on commit a001e6b

Please sign in to comment.