Skip to content

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

Open
lennyburdette wants to merge 2 commits into
ember-cli:masterfrom
lennyburdette:deprecate-makeDefaultExport
Open

feat(makeDefaultExport): add deprecation message for generated default exports#128
lennyburdette wants to merge 2 commits into
ember-cli:masterfrom
lennyburdette:deprecate-makeDefaultExport

Conversation

@lennyburdette

Copy link
Copy Markdown
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
lennyburdetteforce-pushed the deprecate-makeDefaultExport branch 2 times, most recently from f43ec01 to 14e8348CompareJune 24, 2017 00:36
Comment threadbuild.js Outdated

var instrumented = transform(source, {
plugins: ['transform-es2015-destructuring']
plugins: [

Copy link
Copy Markdown
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?

Comment threadindex.js Outdated

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

Copy link
Copy Markdown
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';

Comment threadindex.js Outdated
var target = parentAddon || app;

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

Copy link
Copy Markdown
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...

Comment threadindex.js Outdated
prepend: true
})
});
} else if (target.options.loader.debug) {

Copy link
Copy Markdown
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) {

Comment threadlib/loader/loader.js Outdated
'generated one anyway. This behavior is deprecated and will be removed in v5.0.0.';
};

Object.defineProperty(requirejs, 'deprecationLogger', {

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
Member

Sorry for the delay in reviewing @lennyburdette

@trentmwillistrentmwillis left a comment

Copy link
Copy Markdown
Member

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
lennyburdetteforce-pushed the deprecate-makeDefaultExport branch from 14e8348 to fc83edbCompareAugust 1, 2017 20:25
@lennyburdette

Copy link
Copy Markdown
ContributorAuthor

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

@lennyburdette

Copy link
Copy Markdown
ContributorAuthor

@rwjblue thanks for the review!

Sign up for freeto 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

@lennyburdette@rwjblue@trentmwillis