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

feat(makeDefaultExport): add deprecation message for generated default exports #128

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lennyburdette
Copy link
Contributor

If a module does not define a default export, loader.js assigns exports.default = exports for compatibility with modules that don't use _interopRequireDefault from babel6. Mutating exports is unexpected behavior and causes difficult-to-diagnose bugs. We should remove makeDefaultExport in version 5.0. This update

  • adds a deprecation warning in preparation for removing makeDefaultExport.
  • adds a debug build with the deprecation enabled.

Addresses #114

@lennyburdette lennyburdette force-pushed the deprecate-makeDefaultExport branch 2 times, most recently from f43ec01 to 14e8348 Compare June 24, 2017 00:36
build.js Outdated
var instrumented = transform(source, {
plugins: ['transform-es2015-destructuring']
plugins: [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract the babel options to a shared variable?

index.js Outdated
@@ -10,13 +10,23 @@ module.exports = {
this.treePaths['vendor'] = 'dist';
},

included: function() {
included: function(app, parentAddon) {
var isDevelopmentOrTest = app.env === 'development' || app.env === 'test';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refactor this to the following?

var isProduction = process.env.EMBER_ENV === 'production';

index.js Outdated
var target = parentAddon || app;

target.options = target.options || {};
target.options.loader = target.options.loader || { debug: isDevelopmentOrTest };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should add a config for this if we don't need to...

index.js Outdated
prepend: true
})
});
} else if (target.options.loader.debug) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we tweak the above, this becomes } else if (!isProduction) {

'generated one anyway. This behavior is deprecated and will be removed in v5.0.0.';
};

Object.defineProperty(requirejs, 'deprecationLogger', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this? If it is just for the testing, can we tweak it to just mock console?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure what you're getting at, but I simplified things a bit and changed the arguments to support setting loader.deprecationLogger = Ember.deprecate if we wanted. What do you think?

@rwjblue
Copy link
Member

rwjblue commented Jul 26, 2017

Sorry for the delay in reviewing @lennyburdette

Copy link
Member

@trentmwillis trentmwillis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably note in the deprecation message that this behavior can be turned off via loader.makeDefaultExport now.

Lenny Burdette added 2 commits August 1, 2017 13:21
…lt` exports

If a module does not define a default export, loader.js assigns `exports.default = exports` for compatibility with modules that don't use `_interopRequireDefault` from babel6. Mutating exports is unexpected behavior and causes difficult-to-diagnose [bugs][1]. We should remove `makeDefaultExport` in version 5.0. This update

* adds a deprecation warning in preparation for removing `makeDefaultExport`.
* adds a debug build with the deprecation enabled.

Addresses ember-cli#114

[1]:mike-north/ember-lodash#104
This change adds a `loader.debug` option to Ember CLI builds. It defaults to true for development and test builds. When true, it prepends loader.debug.js instead of loader.js to the application's vendor.js.
@lennyburdette
Copy link
Contributor Author

@trentmwillis Good catch. I added instructions for disabling makeDefaultExport in the deprecation message.

@lennyburdette
Copy link
Contributor Author

@rwjblue thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants