add optional to keep module id extensions - fixes #420

This commit is contained in:
Sebastian McKenzie 2015-01-13 01:12:14 +11:00
parent 831b420df3
commit df9fa32b82
3 changed files with 36 additions and 31 deletions

View File

@ -26,6 +26,7 @@ commander.option("-a, --amd-module-ids", "Insert module id in AMD modules", fals
commander.option("-m, --module-ids", "Insert module id in modules", false); commander.option("-m, --module-ids", "Insert module id in modules", false);
commander.option("-R, --react-compat", "Makes the react transformer produce pre-v0.12 code"); commander.option("-R, --react-compat", "Makes the react transformer produce pre-v0.12 code");
commander.option("-E, --include-regenerator", "Include the regenerator runtime if necessary", false); commander.option("-E, --include-regenerator", "Include the regenerator runtime if necessary", false);
commander.option("--keep-module-id-extensions", "Keep extensions when generating module ids", false);
commander.on("--help", function(){ commander.on("--help", function(){
var outKeys = function (title, obj) { var outKeys = function (title, obj) {
@ -101,19 +102,20 @@ if (errors.length) {
// //
exports.opts = { exports.opts = {
includeRegenerator: commander.includeRegenerator, keepModuleIdExtensions: commander.keepModuleIdExtensions,
sourceMapName: commander.outFile, includeRegenerator: commander.includeRegenerator,
experimental: commander.experimental, sourceMapName: commander.outFile,
reactCompat: commander.reactCompat, experimental: commander.experimental,
playground: commander.playground, reactCompat: commander.reactCompat,
moduleIds: commander.amdModuleIds || commander.moduleIds, playground: commander.playground,
blacklist: commander.blacklist, moduleIds: commander.amdModuleIds || commander.moduleIds,
whitelist: commander.whitelist, blacklist: commander.blacklist,
sourceMap: commander.sourceMaps || commander.sourceMapsInline, whitelist: commander.whitelist,
optional: commander.optional, sourceMap: commander.sourceMaps || commander.sourceMapsInline,
comments: !commander.removeComments, optional: commander.optional,
runtime: commander.runtime, comments: !commander.removeComments,
modules: commander.modules, runtime: commander.runtime,
modules: commander.modules,
format: { format: {
indent: { indent: {
style: util.repeat(parseInt(commander.indent)) style: util.repeat(parseInt(commander.indent))

View File

@ -48,22 +48,23 @@ File.normaliseOptions = function (opts) {
opts = _.cloneDeep(opts || {}); opts = _.cloneDeep(opts || {});
_.defaults(opts, { _.defaults(opts, {
includeRegenerator: false, keepModuleIdExtensions: false,
experimental: false, includeRegenerator: false,
reactCompat: false, experimental: false,
playground: false, reactCompat: false,
whitespace: true, playground: false,
moduleIds: opts.amdModuleIds || false, whitespace: true,
blacklist: [], moduleIds: opts.amdModuleIds || false,
whitelist: [], blacklist: [],
sourceMap: false, whitelist: [],
optional: [], sourceMap: false,
comments: true, optional: [],
filename: "unknown", comments: true,
modules: "common", filename: "unknown",
runtime: false, modules: "common",
code: true, runtime: false,
ast: true code: true,
ast: true
}); });
// normalise windows path separators to unix // normalise windows path separators to unix

View File

@ -156,8 +156,10 @@ DefaultFormatter.prototype.getModuleName = function () {
filenameRelative = filenameRelative.replace(sourceRootRegEx, ""); filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
} }
// remove extension if (!opts.keepModuleIdExtensions) {
filenameRelative = filenameRelative.replace(/\.(.*?)$/, ""); // remove extension
filenameRelative = filenameRelative.replace(/\.(.*?)$/, "");
}
moduleName += filenameRelative; moduleName += filenameRelative;