Skip to content

Commit

Permalink
Drop includePolyfill support
Browse files Browse the repository at this point in the history
  • Loading branch information
bertdeblock committed Oct 1, 2022
1 parent 84c6081 commit be7dc9c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 139 deletions.
22 changes: 0 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ allow you to use latest Javascript in your Ember CLI project.
- [Compatibility](#compatibility)
- [Usage](#usage)
* [Options](#options)
+ [Polyfill](#polyfill)
+ [External Helpers](#external-helpers)
+ [Enabling Source Maps](#enabling-source-maps)
+ [Modules](#modules)
Expand Down Expand Up @@ -115,7 +114,6 @@ interface EmberCLIBabelConfig {
Configuration options for ember-cli-babel itself.
*/
'ember-cli-babel'?: {
includePolyfill?: boolean;
includeExternalHelpers?: boolean;
compileModules?: boolean;
disableDebugTooling?: boolean;
Expand Down Expand Up @@ -165,26 +163,6 @@ module.exports = {
};
```

#### Polyfill

Babel comes with a polyfill that includes a custom [regenerator
runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) and
[core-js](https://github.com/zloirock/core-js). Many transformations will work
without it, but for full support you may need to include the polyfill in your
app.

To include it in your app, pass `includePolyfill: true` in your `ember-cli-babel` options.

```js
// ember-cli-build.js

let app = new EmberApp(defaults, {
'ember-cli-babel': {
includePolyfill: true
}
});
```

#### External Helpers

Babel often includes helper functions to handle some of the more complex logic
Expand Down
1 change: 0 additions & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module.exports = function(defaults) {

let app = new EmberAddon(defaults, {
'ember-cli-babel': {
includePolyfill: true,
includeExternalHelpers: true,
// ember-cli-babels defaults, should be parallelizable. If they are not,
// it should fail to build. This flag being enabled ensure that to be the
Expand Down
53 changes: 1 addition & 52 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,30 +181,6 @@ module.exports = {
});
},

_shouldIncludePolyfill() {
let addonOptions = this._getAddonOptions();
let customOptions = addonOptions['ember-cli-babel'];

if (customOptions && 'includePolyfill' in customOptions) {
return customOptions.includePolyfill === true;
} else {
return false;
}
},

_importPolyfill(app) {
let polyfillPath = 'vendor/babel-polyfill/polyfill.js';

if (this.import) { // support for ember-cli >= 2.7
this.import(polyfillPath, { prepend: true });
} else if (app.import) { // support ember-cli < 2.7
app.import(polyfillPath, { prepend: true });
} else {
// eslint-disable-next-line no-console
console.warn('Please run: ember install ember-cli-import-polyfill');
}
},

_getHelperVersion() {
if (!APP_BABEL_RUNTIME_VERSION.has(this.project)) {
let checker = new VersionChecker(this.project);
Expand Down Expand Up @@ -258,26 +234,8 @@ module.exports = {
});
},

treeForVendor() {
if (!this._shouldIncludePolyfill()) return;

const Funnel = require('broccoli-funnel');
const UnwatchedDir = require('broccoli-source').UnwatchedDir;

// Find babel-core's browser polyfill and use its directory as our vendor tree
let polyfillDir = path.dirname(require.resolve('@babel/polyfill/dist/polyfill'));

let polyfillTree = new Funnel(new UnwatchedDir(polyfillDir), {
destDir: 'babel-polyfill'
});

return polyfillTree;
},

cacheKeyForTree(treeType) {
if (treeType === 'vendor') {
return cacheKeyForTree('vendor', this, [this._shouldIncludePolyfill()]);
} else if (treeType === 'addon') {
if (treeType === 'addon') {
let isRootBabel = this.parent === this.project;
let shouldIncludeHelpers = isRootBabel && _shouldIncludeHelpers(this._getAppOptions(), this);

Expand All @@ -287,15 +245,6 @@ module.exports = {
return cacheKeyForTree(treeType, this);
},

included: function(app) {
this._super.included.apply(this, arguments);
this.app = app;

if (this._shouldIncludePolyfill()) {
this._importPolyfill(app);
}
},

isPluginRequired(pluginName) {
let targets = this._getTargets();

Expand Down
66 changes: 4 additions & 62 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ describe('ember-cli-babel', function() {
input.write({
"foo.js": `import Component from '@glimmer/component';\nimport { tracked } from '@glimmer/tracking';\nexport default class Foo extends Component { @tracked thisIsTracked = true; }`,
});

this.addon.project.targets = {
browsers: ["last 2 chrome versions"],
};

subject = this.addon.transpileTree(input.path(), {});

output = createBuilder(subject);

yield output.build();
expect(output.read()["foo.js"]).not.to.include(
"_initializerWarningHelper(_descriptor, this)"
Expand Down Expand Up @@ -1333,64 +1333,6 @@ describe('ember-cli-babel', function() {
});
});

describe('_shouldIncludePolyfill()', function() {
describe('without any includePolyfill option set', function() {
it('should return false', function() {
expect(this.addon._shouldIncludePolyfill()).to.be.false;
});

it('should not print deprecation messages', function() {
this.addon._shouldIncludePolyfill();

let deprecationMessages = this.ui.output.split('\n').filter(function(line) {
return line.indexOf('Putting the "includePolyfill" option in "babel" is deprecated') !== -1;
});

expect(deprecationMessages).to.have.lengthOf(0);
});
});

describe('with ember-cli-babel.includePolyfill = true', function() {
beforeEach(function() {
this.addon.parent.options = { 'ember-cli-babel': { includePolyfill: true } };
});

it('should return true', function() {
expect(this.addon._shouldIncludePolyfill()).to.be.true;
});

it('should not print deprecation messages', function() {
this.addon._shouldIncludePolyfill();

let deprecationMessages = this.ui.output.split('\n').filter(function(line) {
return line.indexOf('Putting the "includePolyfill" option in "babel" is deprecated') !== -1;
});

expect(deprecationMessages).to.have.lengthOf(0);
});
});

describe('with ember-cli-babel.includePolyfill = false', function() {
beforeEach(function() {
this.addon.parent.options = { 'ember-cli-babel': { includePolyfill: false } };
});

it('should return false', function() {
expect(this.addon._shouldIncludePolyfill()).to.be.false;
});

it('should not print deprecation messages', function() {
this.addon._shouldIncludePolyfill();

let deprecationMessages = this.ui.output.split('\n').filter(function(line) {
return line.indexOf('Putting the "includePolyfill" option in "babel" is deprecated') !== -1;
});

expect(deprecationMessages).to.have.lengthOf(0);
});
});
});

describe('_shouldHandleTypeScript', function() {
let project;
let unlink;
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"@babel/plugin-transform-modules-amd": "^7.13.0",
"@babel/plugin-transform-runtime": "^7.13.9",
"@babel/plugin-transform-typescript": "^7.13.0",
"@babel/polyfill": "^7.11.5",
"@babel/preset-env": "^7.16.5",
"@babel/runtime": "7.12.18",
"amd-name-resolver": "^1.3.1",
Expand Down Expand Up @@ -87,7 +86,6 @@
"core-object": "^3.1.5",
"ember-cli": "~3.5.0",
"ember-cli-dependency-checker": "^3.0.0",
"eslint": "^4.0.0",
"ember-cli-htmlbars": "^3.0.0",
"ember-cli-htmlbars-inline-precompile": "^1.0.3",
"ember-cli-inject-live-reload": "^1.8.2",
Expand All @@ -97,6 +95,7 @@
"ember-resolver": "^5.0.1",
"ember-source": "~3.28.8",
"ember-source-channel-url": "^1.1.0",
"eslint": "^4.0.0",
"eslint-plugin-ember": "^5.2.0",
"eslint-plugin-node": "^7.0.1",
"lerna-changelog": "^0.8.0",
Expand Down

0 comments on commit be7dc9c

Please sign in to comment.