Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix inline object types, add auxiliary comment types
  • Loading branch information
sokra committed May 28, 2018
1 parent ed9d024 commit 9c7100b
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions lib/UmdMainTemplatePlugin.js
Expand Up @@ -38,9 +38,21 @@ const accessorAccess = (base, accessor, joinWith = "; ") => {
.join(joinWith);
};

/** @typedef {string | string[] | Record<string, string | string[]>} UmdMainTemplatePluginName */

/**
* @typedef {Object} AuxiliaryCommentObject
* @property {string} root
* @property {string} commonjs
* @property {string} commonjs2
* @property {string} amd
*/

/**
* @typedef {string | string[] | {[k: string]: string | string[]}} UmdMainTemplatePluginName
* @typedef {{optionalAmdExternalAsGlobal: boolean, namedDefine: boolean, auxiliaryComment: TODO}} UmdMainTemplatePluginOption
* @typedef {Object} UmdMainTemplatePluginOption
* @property {boolean=} optionalAmdExternalAsGlobal
* @property {boolean} namedDefine
* @property {string | AuxiliaryCommentObject} auxiliaryComment
*/

class UmdMainTemplatePlugin {
Expand Down Expand Up @@ -181,23 +193,27 @@ class UmdMainTemplatePlugin {
amdFactory = "factory";
}

const auxiliaryComment = this.auxiliaryComment;

const getAuxilaryComment = type => {
if (auxiliaryComment) {
if (typeof auxiliaryComment === "string")
return "\t//" + auxiliaryComment + "\n";
if (auxiliaryComment[type])
return "\t//" + auxiliaryComment[type] + "\n";
}
return "";
};

return new ConcatSource(
new OriginalSource(
"(function webpackUniversalModuleDefinition(root, factory) {\n" +
(this.auxiliaryComment && typeof this.auxiliaryComment === "string"
? " //" + this.auxiliaryComment + "\n"
: this.auxiliaryComment.commonjs2
? " //" + this.auxiliaryComment.commonjs2 + "\n"
: "") +
getAuxilaryComment("commonjs2") +
" if(typeof exports === 'object' && typeof module === 'object')\n" +
" module.exports = factory(" +
externalsRequireArray("commonjs2") +
");\n" +
(this.auxiliaryComment && typeof this.auxiliaryComment === "string"
? " //" + this.auxiliaryComment + "\n"
: this.auxiliaryComment.amd
? " //" + this.auxiliaryComment.amd + "\n"
: "") +
getAuxilaryComment("amd") +
" else if(typeof define === 'function' && define.amd)\n" +
(requiredExternals.length > 0
? this.names.amd && this.namedDefine === true
Expand All @@ -221,24 +237,14 @@ class UmdMainTemplatePlugin {
");\n"
: " define([], " + amdFactory + ");\n") +
(this.names.root || this.names.commonjs
? (this.auxiliaryComment &&
typeof this.auxiliaryComment === "string"
? " //" + this.auxiliaryComment + "\n"
: this.auxiliaryComment.commonjs
? " //" + this.auxiliaryComment.commonjs + "\n"
: "") +
? getAuxilaryComment("commonjs") +
" else if(typeof exports === 'object')\n" +
" exports[" +
libraryName(this.names.commonjs || this.names.root) +
"] = factory(" +
externalsRequireArray("commonjs") +
");\n" +
(this.auxiliaryComment &&
typeof this.auxiliaryComment === "string"
? " //" + this.auxiliaryComment + "\n"
: this.auxiliaryComment.root
? " //" + this.auxiliaryComment.root + "\n"
: "") +
getAuxilaryComment("root") +
" else\n" +
" " +
replaceKeys(
Expand Down

0 comments on commit 9c7100b

Please sign in to comment.