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

Using a config to include ember-data/debug in the build #6599

Merged
merged 1 commit into from
Nov 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions packages/debug/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,51 @@ const name = require('./package').name;
const addonBuildConfigForDataPackage = require('@ember-data/private-build-infra/src/addon-build-config-for-data-package');
const addonBaseConfig = addonBuildConfigForDataPackage(name);

function getApp(addon) {
while (addon && !addon.app) {
addon = addon.parent;
}
if (!addon) {
throw new Error(`Unable to find the parent application`);
}
return addon.app;
}

module.exports = Object.assign({}, addonBaseConfig, {
shouldRollupPrivate: false,
__isEnabled: null,
externalDependenciesForPrivateModule() {
return [];
},
treeFor() {
// Nested addons don't call isEnabled automatically,
// So this ensures that we return empty trees whenever
// we are not enabled.
if (this.isEnabled()) {
return this._super.treeFor.call(this, ...arguments);
}
},
isEnabled() {
if (this.__isEnabled !== null) {
return this.__isEnabled;
}
const options = this.setupOptions();
const env = getApp(this).env;

this.__isEnabled = env !== 'production' || options.includeDataAdapterInProduction === true;

return this.__isEnabled;
},
setupOptions() {
const app = getApp(this);
const parentIsEmberDataAddon = this.parent.pkg.name === 'ember-data';

let options = (app.options = app.options || {});
options.emberData = options.emberData || {};

if (options.emberData.includeDataAdapterInProduction === undefined) {
options.emberData.includeDataAdapterInProduction = parentIsEmberDataAddon;
}
return options.emberData;
},
});