Skip to content

Commit

Permalink
Ensure ember-data/-private module is emitted properly for ember-cli…
Browse files Browse the repository at this point in the history
… < 2.12. (#5031)

ember-cli@2.12 and higher have the addon itself responsible for transpiling
modules so that the output of the `treeForAddon` hook is expected to be
AMD.

Prior versions of ember-cli (i.e. < 2.12) do second pass (that is not possible
to disable) to transpile the output of `treeForAddon` **again** (to transpile
modules).

This commit changes things around leveraging ember-cli-babel@6's built in
ability to detect the various ember-cli version scenarios and either
transpile `ember-data/-private` down to AMD or not correctly.
  • Loading branch information
stefanpenner authored and bmac committed Jun 24, 2017
1 parent 17bf1b7 commit 5cda400
Show file tree
Hide file tree
Showing 3 changed files with 370 additions and 639 deletions.
22 changes: 17 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Babel = require('broccoli-babel-transpiler');
const merge = require('broccoli-merge-trees');
const semver = require('semver');
const version = require('./lib/version');
const BroccoliDebug = require('broccoli-debug');

// allow toggling of heimdall instrumentation
let INSTRUMENT_HEIMDALL = false;
Expand Down Expand Up @@ -52,6 +53,8 @@ module.exports = {
init() {
this._super.init && this._super.init.apply(this, arguments);

this.debugTree = BroccoliDebug.buildDebugCallback('ember-data');

let bowerDeps = this.project.bowerDependencies();

let VersionChecker = require('ember-cli-version-checker');
Expand Down Expand Up @@ -113,6 +116,8 @@ module.exports = {
treeForAddon(tree) {
if (this._forceBowerUsage) { return NOOP_TREE(tree); }

tree = this.debugTree(tree, 'input');

let babel = this.addons.find(addon => addon.name === 'ember-cli-babel');

let treeWithVersion = merge([
Expand All @@ -130,21 +135,25 @@ module.exports = {
destDir: 'ember-data'
});

let privateTree = babel.transpileTree(withPrivate, {
let privateTree = babel.transpileTree(this.debugTree(withPrivate, 'babel-private:input'), {
babel: this.buildBabelOptions(),
'ember-cli-babel': {
compileModules: false
}
});

privateTree = this.debugTree(privateTree, 'babel-private:output');

// use the default options
let publicTree = babel.transpileTree(withoutPrivate);
let publicTree = babel.transpileTree(this.debugTree(withoutPrivate, 'babel-public:input'));

publicTree = this.debugTree(publicTree, 'babel-public:output');

privateTree = new Rollup(privateTree, {
rollup: {
entry: '-private/index.js',
targets: [
{ dest: '-private.js', format: 'amd', moduleId: 'ember-data/-private' }
{ dest: 'ember-data/-private.js', format: babel.shouldCompileModules() ? 'amd' : 'es', moduleId: 'ember-data/-private' }
],
external: [
'ember',
Expand All @@ -157,14 +166,16 @@ module.exports = {
}
});

privateTree = this.debugTree(privateTree, 'rollup-output');

// the output of treeForAddon is required to be modules/<your files>
publicTree = new Funnel(publicTree, { destDir: 'modules' });
privateTree = new Funnel(privateTree, { destDir: 'modules' });

return merge([
return this.debugTree(merge([
publicTree,
privateTree
]);
]), 'final');
},

buildBabelOptions() {
Expand Down Expand Up @@ -204,3 +215,4 @@ module.exports = {
}
}
};

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
"babel6-plugin-strip-class-callcheck": "^6.0.0",
"babel6-plugin-strip-heimdall": "^6.0.1",
"broccoli-babel-transpiler": "^6.0.0",
"broccoli-debug": "^0.6.2",
"broccoli-file-creator": "^1.0.0",
"broccoli-funnel": "^1.2.0",
"broccoli-merge-trees": "^1.0.0",
"broccoli-rollup": "^1.2.0",
"chalk": "^1.1.1",
"ember-cli-babel": "^6.1.0",
"ember-cli-babel": "^6.4.1",
"ember-cli-path-utils": "^1.0.0",
"ember-cli-string-utils": "^1.0.0",
"ember-cli-test-info": "^1.0.0",
Expand Down
Loading

0 comments on commit 5cda400

Please sign in to comment.