-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 addons to customize es6 module prefix #2189
Allow addons to customize es6 module prefix #2189
Conversation
@@ -27,4 +27,4 @@ | |||
"express": "^4.1.1", | |||
"glob": "^3.2.9" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no idea why this has a diff on it, I didn't touch the file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you removed the newline character at the end of the last line :)
I did something similar in my brunch es6 module transpiler plugin at https://github.com/ahacking/es6-module-transpiler-js-brunch/blob/master/README.md but I made the option a function so that it can transform the module name arbitrarily. This was useful for being able to make a module appear under any prefix I wanted independent of the file layout and allowed my interim brunch solution to comply with the ember-cli naming conventions. |
@ahacking this is possible via overriding the |
|
||
this._includedModules = glob.sync(path.join(treePath, this._jsFileGlob())).reduce(function(ignoredModules, filePath) { | ||
ignoredModules[filePath.replace(treePath, moduleName).slice(0, -3)] = ['default']; | ||
modulePath = filePath.replace(treePath, _this.moduleName()); | ||
modulePath = modulePath.replace(path.extname(modulePath), ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering the following:
modulePath = 'bower_components/loader.js/loader.js'
modulePath = modulePath.replace('.js', '')
// => "bower_components/loader/loader.js"
This might need to be tweaked to:
modulePath = modulePath.replace(new RegExp(path.extname(modulePath) + '$'), '');
Addons can now customize the module prefix they are compiled under: ```js // index.js module.exports = { name: 'some-addon', modulePrefix: 'other-addon' } ``` Normally addons would use `name` to compile under. If `modulePrefix` is declared that is used instead. Use Case!! During the ember-validations rewrite I've realized that I'd like to have another library: ember-validations-addons or something to that effect. It will contain additional validators that don't need to be part of the original library. (like the URI validator) But I still need to lookup validators in the `ember-validations` namespace rather than attempting to manage additional namespaces. This would allow others to also write their own addons in the same namespace.
👍 |
…ixes Allow addons to customize es6 module prefix
@bcardarella. Thanks for the clarification. |
@bcardarella Great idea :) "This would allow others to also write their own addons in the same namespace." Looking forward to your ember-validations rewrite. Also check out webmake, if you need to turn node.js code into web compatible browser code which resolves in exactly the same way as in node ;) Looks pretty cool to me. https://github.com/medikoo/modules-webmake#comparison-with-other-solutions |
Addons can now customize the module prefix they are compiled under:
Normally addons would use
name
to compile under. IfmodulePrefix
isdeclared that is used instead.
Use Case!!
During the ember-validations rewrite I've realized that I'd like to have
another library: ember-validations-addons or something to that effect.
It will contain additional validators that don't need to be part of the
original library. (like the URI validator) But I still need to lookup
validators in the
ember-validations
namespace rather than attemptingto manage additional namespaces. This would allow others to also write
their own addons in the same namespace.