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

Allow custom module paths. #12

Closed
wants to merge 1 commit 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
# master

* Added `moduleNameToPath` option.
* Added `pathToModuleName` option.

# 0.1.4

* Update dependencies
Expand Down
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -37,3 +37,7 @@ var applicationJs = compileES6(sourceTree, {

* `.wrapInEval` (boolean): Enable or disable wrapping each module in an `eval`
call with a `//# sourceURL` comment. Defaults to true, though this may change in the future.
* `.moduleNameToPath` (function): Provide a function that returns the path on disk for a
given ES6 module name.
* `.pathToModuleName` (function): Provide a function to use a custom mapping from path on disk to
ES6 module name.
12 changes: 10 additions & 2 deletions index.js
Expand Up @@ -14,6 +14,14 @@ function ES6Concatenator(inputTree, options) {

this.inputTree = inputTree

this.moduleNameToPath = function(moduleName) {
return moduleName + '.js'
}

this.pathToModuleName = function(path) {
return path.slice(0, -3)
}

for (var key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key]
Expand Down Expand Up @@ -53,7 +61,7 @@ ES6Concatenator.prototype.write = function (readTree, destDir) {
if (inputFile.slice(-3) !== '.js') {
throw new Error('ES6 file does not end in .js: ' + inputFile)
}
var moduleName = inputFile.slice(0, -3)
var moduleName = self.pathToModuleName(inputFile)
addModule(moduleName)
}

Expand All @@ -74,7 +82,7 @@ ES6Concatenator.prototype.write = function (readTree, destDir) {
if (modulesAdded[moduleName]) return
if (self.ignoredModules && self.ignoredModules.indexOf(moduleName) !== -1) return
var i
var modulePath = moduleName + '.js'
var modulePath = self.moduleNameToPath(moduleName)
var fullPath = srcDir + '/' + modulePath
var imports
try {
Expand Down