Skip to content

Commit b18c9a7

Browse files
committed
refactor: Use ember-cli-babel-plugin-helpers
Also update addon's ember-cli-babel version to latest
1 parent d13c745 commit b18c9a7

File tree

3 files changed

+1048
-89
lines changed

3 files changed

+1048
-89
lines changed

index.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
11
'use strict';
22

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

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

89
included() {
910
this._super.included.apply(this, arguments);
1011

11-
this.patchEmberModulesAPIPolyfill();
12+
this.addBabelPlugin();
1213
},
1314

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

19-
if (babel.__CachedDecoratorPolyfillApplied) return;
20-
babel.__CachedDecoratorPolyfillApplied = true;
21-
22-
const { _getEmberModulesAPIPolyfill } = babel;
23-
24-
babel._getEmberModulesAPIPolyfill = function (...args) {
25-
const plugins = _getEmberModulesAPIPolyfill.apply(this, args);
26-
if (!plugins) return;
27-
28-
return [[resolve(__dirname, './lib/transpile-modules.js')], ...plugins];
29-
};
18+
if (!hasPlugin(app, 'ember-cache-decorator-polyfill')) {
19+
addPlugin(app, resolve(__dirname, './lib/transpile-modules.js'));
20+
}
3021
}
3122
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"dependencies": {
4242
"@glimmer/tracking": "^1.0.4",
4343
"ember-cache-primitive-polyfill": "^1.0.1",
44-
"ember-cli-babel": "^7.21.0"
44+
"ember-cli-babel": "^7.21.0",
45+
"ember-cli-babel-plugin-helpers": "^1.1.1"
4546
},
4647
"devDependencies": {
4748
"@ember/optional-features": "^2.0.0",

0 commit comments

Comments
 (0)