Skip to content

Commit

Permalink
refactor: Use ember-cli-babel-plugin-helpers
Browse files Browse the repository at this point in the history
Also update addon's ember-cli-babel version to latest
  • Loading branch information
mydea committed May 19, 2021
1 parent d13c745 commit b18c9a7
Show file tree
Hide file tree
Showing 3 changed files with 1,048 additions and 89 deletions.
23 changes: 7 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
'use strict';

const { resolve } = require('path');
const { hasPlugin, addPlugin } = require('ember-cli-babel-plugin-helpers');

module.exports = {
name: require('./package').name,

included() {
this._super.included.apply(this, arguments);

this.patchEmberModulesAPIPolyfill();
this.addBabelPlugin();
},

patchEmberModulesAPIPolyfill() {
const babel = this.parent.findOwnAddonByName
? this.parent.findOwnAddonByName('ember-cli-babel') // parent is an addon
: this.parent.findAddonByName('ember-cli-babel'); // parent is an app
addBabelPlugin() {
let app = this._findHost();

if (babel.__CachedDecoratorPolyfillApplied) return;
babel.__CachedDecoratorPolyfillApplied = true;

const { _getEmberModulesAPIPolyfill } = babel;

babel._getEmberModulesAPIPolyfill = function (...args) {
const plugins = _getEmberModulesAPIPolyfill.apply(this, args);
if (!plugins) return;

return [[resolve(__dirname, './lib/transpile-modules.js')], ...plugins];
};
if (!hasPlugin(app, 'ember-cache-decorator-polyfill')) {
addPlugin(app, resolve(__dirname, './lib/transpile-modules.js'));
}
}
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"dependencies": {
"@glimmer/tracking": "^1.0.4",
"ember-cache-primitive-polyfill": "^1.0.1",
"ember-cli-babel": "^7.21.0"
"ember-cli-babel": "^7.21.0",
"ember-cli-babel-plugin-helpers": "^1.1.1"
},
"devDependencies": {
"@ember/optional-features": "^2.0.0",
Expand Down
Loading

0 comments on commit b18c9a7

Please sign in to comment.