Skip to content

Commit

Permalink
Using a config to include ember-data/debug in the build
Browse files Browse the repository at this point in the history
Updates with @runspired...and lots of console.log to see what's going on
Polish off

Co-authored-by: Chris Thoburn <runspired@gmail.com>
  • Loading branch information
pliljegr and runspired committed Nov 12, 2019
1 parent 9902526 commit e9ebff7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/-ember-data/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ module.exports = function(defaults) {
'ember-cli-babel': {
throwUnlessParallelizable: true,
},
/* emberData: {
includeDataAdapterInProduction: false,
}, */
});

/*
Expand Down
43 changes: 43 additions & 0 deletions packages/debug/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,52 @@ 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();
console.log('calculated options', options);
const env = getApp(this).env;

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

return this.__isEnabled;
},
setupOptions() {
const app = getApp(this);
const parentIsEmberDataAddon = !this.app && 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;
},
});

0 comments on commit e9ebff7

Please sign in to comment.