From df9fa32b8281f84f349f8438b0ec756e035f9f57 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 13 Jan 2015 01:12:14 +1100 Subject: [PATCH] add optional to keep module id extensions - fixes #420 --- bin/6to5/index.js | 28 +++++++++-------- lib/6to5/file.js | 33 +++++++++++---------- lib/6to5/transformation/modules/_default.js | 6 ++-- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/bin/6to5/index.js b/bin/6to5/index.js index 09d7925e43..ea5cc727d5 100755 --- a/bin/6to5/index.js +++ b/bin/6to5/index.js @@ -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("-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("--keep-module-id-extensions", "Keep extensions when generating module ids", false); commander.on("--help", function(){ var outKeys = function (title, obj) { @@ -101,19 +102,20 @@ if (errors.length) { // exports.opts = { - includeRegenerator: commander.includeRegenerator, - sourceMapName: commander.outFile, - experimental: commander.experimental, - reactCompat: commander.reactCompat, - playground: commander.playground, - moduleIds: commander.amdModuleIds || commander.moduleIds, - blacklist: commander.blacklist, - whitelist: commander.whitelist, - sourceMap: commander.sourceMaps || commander.sourceMapsInline, - optional: commander.optional, - comments: !commander.removeComments, - runtime: commander.runtime, - modules: commander.modules, + keepModuleIdExtensions: commander.keepModuleIdExtensions, + includeRegenerator: commander.includeRegenerator, + sourceMapName: commander.outFile, + experimental: commander.experimental, + reactCompat: commander.reactCompat, + playground: commander.playground, + moduleIds: commander.amdModuleIds || commander.moduleIds, + blacklist: commander.blacklist, + whitelist: commander.whitelist, + sourceMap: commander.sourceMaps || commander.sourceMapsInline, + optional: commander.optional, + comments: !commander.removeComments, + runtime: commander.runtime, + modules: commander.modules, format: { indent: { style: util.repeat(parseInt(commander.indent)) diff --git a/lib/6to5/file.js b/lib/6to5/file.js index 17d29b3e99..70a0b900b6 100644 --- a/lib/6to5/file.js +++ b/lib/6to5/file.js @@ -48,22 +48,23 @@ File.normaliseOptions = function (opts) { opts = _.cloneDeep(opts || {}); _.defaults(opts, { - includeRegenerator: false, - experimental: false, - reactCompat: false, - playground: false, - whitespace: true, - moduleIds: opts.amdModuleIds || false, - blacklist: [], - whitelist: [], - sourceMap: false, - optional: [], - comments: true, - filename: "unknown", - modules: "common", - runtime: false, - code: true, - ast: true + keepModuleIdExtensions: false, + includeRegenerator: false, + experimental: false, + reactCompat: false, + playground: false, + whitespace: true, + moduleIds: opts.amdModuleIds || false, + blacklist: [], + whitelist: [], + sourceMap: false, + optional: [], + comments: true, + filename: "unknown", + modules: "common", + runtime: false, + code: true, + ast: true }); // normalise windows path separators to unix diff --git a/lib/6to5/transformation/modules/_default.js b/lib/6to5/transformation/modules/_default.js index a70db37f50..5e8ceb12a7 100644 --- a/lib/6to5/transformation/modules/_default.js +++ b/lib/6to5/transformation/modules/_default.js @@ -156,8 +156,10 @@ DefaultFormatter.prototype.getModuleName = function () { filenameRelative = filenameRelative.replace(sourceRootRegEx, ""); } - // remove extension - filenameRelative = filenameRelative.replace(/\.(.*?)$/, ""); + if (!opts.keepModuleIdExtensions) { + // remove extension + filenameRelative = filenameRelative.replace(/\.(.*?)$/, ""); + } moduleName += filenameRelative;