Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nameless UMD export. #109

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/bundler/builders/defaultsMode/umd.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import packageResult from 'utils/packageResult';
import standaloneUmdIntro from 'utils/umd/standaloneUmdIntro';
import defaultUmdIntro from 'utils/umd/defaultUmdIntro';
import requireName from 'utils/umd/requireName';
import { getId, getName } from 'utils/mappers';

export default function umd ( bundle, body, options ) {
requireName( options );

var entry = bundle.entryModule;

var hasImports = bundle.externalModules.length > 0;
Expand Down
5 changes: 1 addition & 4 deletions src/bundler/builders/strictMode/umd.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import standaloneUmdIntro from 'utils/umd/standaloneUmdIntro';
import strictUmdIntro from 'utils/umd/strictUmdIntro';
import requireName from 'utils/umd/requireName';
import packageResult from 'utils/packageResult';
import { getId, getName } from 'utils/mappers';
import getExportBlock from './utils/getExportBlock';

export default function umd ( bundle, body, options ) {
requireName( options );

var entry = bundle.entryModule;

var hasImports = bundle.externalModules.length > 0;
Expand Down Expand Up @@ -44,4 +41,4 @@ export default function umd ( bundle, body, options ) {

function needsDefault ( externalModule ) {
return externalModule.needsDefault;
}
}
3 changes: 0 additions & 3 deletions src/standalone/builders/defaultsMode/umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ import packageResult from 'utils/packageResult';
import hasOwnProp from 'utils/hasOwnProp';
import standaloneUmdIntro from 'utils/umd/standaloneUmdIntro';
import defaultUmdIntro from 'utils/umd/defaultUmdIntro';
import requireName from 'utils/umd/requireName';

export default function umd ( mod, body, options ) {
var importNames = [];
var importPaths = [];
var seen = {};
var placeholders = 0;

requireName( options );

var hasImports = mod.imports.length > 0;
var hasExports = mod.exports.length > 0;

Expand Down
3 changes: 0 additions & 3 deletions src/standalone/builders/strictMode/umd.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import packageResult from 'utils/packageResult';
import standaloneUmdIntro from 'utils/umd/standaloneUmdIntro';
import strictUmdIntro from 'utils/umd/strictUmdIntro';
import requireName from 'utils/umd/requireName';
import transformBody from './utils/transformBody';
import getImportSummary from './utils/getImportSummary';

export default function umd ( mod, body, options ) {
requireName( options );

var [ importPaths, importNames ] = getImportSummary( mod );

var hasImports = mod.imports.length > 0;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/umd/defaultUmdIntro.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function defaultUmdIntro ( options, indentStr ) {
(hasExports ? 'module.exports = ' : '') + `factory(${cjsDeps})`;

var globalExport =
(hasExports ? `global.${options.name} = ` : '') + `factory(${globalDeps})`;
(hasExports && options.name ? `global.${options.name} = ` : '') + `factory(${globalDeps})`;


var intro =
Expand All @@ -31,4 +31,4 @@ export default function defaultUmdIntro ( options, indentStr ) {
`;

return intro.replace( /\t/g, indentStr );
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruh roh : [

i will undo this

9 changes: 0 additions & 9 deletions src/utils/umd/requireName.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/utils/umd/strictUmdIntro.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function strictUmdIntro ( options, indentStr ) {
'], ' :
'';
var cjsDeps = ( hasExports ? [ 'exports' ] : [] ).concat( options.importPaths.map( req ) ).join( ', ' );
var globalDeps = ( hasExports ? [ `(global.${options.name} = {})` ] : [] )
var globalDeps = ( hasExports && options.name ? [ `(global.${options.name} = {})` ] : [] )
.concat( options.importNames.map( globalify ) ).join( ', ' );
var args = ( hasExports ? [ 'exports' ] : [] ).concat( options.importNames ).join( ', ' );

Expand Down
1 change: 1 addition & 0 deletions test/bundle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module.exports = function () {
{ description: 'bundle.concat()', method: 'concat', outputdir: 'concat' },
{ description: 'bundle.toAmd()', method: 'toAmd', outputdir: 'amdDefaults' },
{ description: 'bundle.toUmd()', method: 'toUmd', outputdir: 'umdDefaults', options: { name: 'myModule' } },
{ description: 'bundle.toUmd()', method: 'toUmd', outputdir: 'umdDefaultsNameless', options: {} },
{ description: 'bundle.toCjs()', method: 'toCjs', outputdir: 'cjsDefaults' },
{ description: 'bundle.toAmd({ strict: true })', method: 'toAmd', outputdir: 'amd', options: { strict: true } },
{ description: 'bundle.toUmd({ strict: true })', method: 'toUmd', outputdir: 'umd', options: { strict: true, name: 'myModule' } },
Expand Down