|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -const { resolve } = require('path'); |
| 3 | +const ReplaceImportsPreprocessor = require('./lib/replace-imports-preprocessor'); |
4 | 4 |
|
5 | 5 | module.exports = { |
6 | 6 | name: require('./package').name, |
7 | 7 |
|
8 | | - included() { |
9 | | - this._super.included.apply(this, arguments); |
10 | | - this._ensureThisImport(); |
11 | | - |
12 | | - this.import('vendor/ember-cached-decorator-polyfill/index.js'); |
13 | | - this.patchEmberModulesAPIPolyfill(); |
14 | | - }, |
15 | | - |
16 | | - treeForVendor(tree) { |
17 | | - const babel = this.addons.find(a => a.name === 'ember-cli-babel'); |
18 | | - |
19 | | - return babel.transpileTree(tree, { |
20 | | - babel: this.options.babel, |
21 | | - |
22 | | - 'ember-cli-babel': { |
23 | | - compileModules: false |
24 | | - } |
25 | | - }); |
26 | | - }, |
27 | | - |
28 | | - _ensureThisImport() { |
29 | | - if (!this.import) { |
30 | | - this._findHost = function findHostShim() { |
31 | | - let current = this; |
32 | | - let app; |
33 | | - do { |
34 | | - app = current.app || app; |
35 | | - // eslint-disable-next-line no-cond-assign |
36 | | - } while (current.parent.parent && (current = current.parent)); |
37 | | - return app; |
38 | | - }; |
39 | | - this.import = function importShim(asset, options) { |
40 | | - const app = this._findHost(); |
41 | | - app.import(asset, options); |
42 | | - }; |
| 8 | + setupPreprocessorRegistry(type, registry) { |
| 9 | + if (type !== 'parent') { |
| 10 | + return; |
43 | 11 | } |
44 | | - }, |
45 | | - |
46 | | - patchEmberModulesAPIPolyfill() { |
47 | | - const babel = this.parent.findOwnAddonByName |
48 | | - ? this.parent.findOwnAddonByName('ember-cli-babel') // parent is an addon |
49 | | - : this.parent.findAddonByName('ember-cli-babel'); // parent is an app |
50 | | - |
51 | | - if (babel.__CachedDecoratorPolyfillApplied) return; |
52 | | - babel.__CachedDecoratorPolyfillApplied = true; |
53 | | - |
54 | | - const { _getEmberModulesAPIPolyfill } = babel; |
55 | | - babel._getEmberModulesAPIPolyfill = function (...args) { |
56 | | - const plugins = _getEmberModulesAPIPolyfill.apply(this, args); |
57 | | - if (!plugins) return; |
58 | 12 |
|
59 | | - return [[resolve(__dirname, './lib/transpile-modules.js')], ...plugins]; |
60 | | - }; |
| 13 | + registry.add('js', new ReplaceImportsPreprocessor()); |
61 | 14 | } |
62 | 15 | }; |
0 commit comments