Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for the includePolyfill option #458

Merged
merged 2 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
54 changes: 1 addition & 53 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const {
const VersionChecker = require('ember-cli-version-checker');
const clone = require('clone');
const babel = require('@babel/core');
const path = require('path');
const getBabelOptions = require('./lib/get-babel-options');
const findApp = require('./lib/find-app');
const emberPlugins = require('./lib/ember-plugins');
Expand Down Expand Up @@ -181,30 +180,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 +233,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 +244,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
9 changes: 6 additions & 3 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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is awesome!

"@babel/preset-env": "^7.16.5",
"@babel/runtime": "7.12.18",
"amd-name-resolver": "^1.3.1",
Expand Down Expand Up @@ -84,10 +83,11 @@
"co": "^4.6.0",
"common-tags": "^1.8.0",
"console-ui": "^2.2.2",
"core-js": "^3.25.5",
"core-object": "^3.1.5",
"ember-auto-import": "^2.4.2",
"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,14 +97,17 @@
"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",
"loader.js": "^4.7.0",
"mocha": "^5.2.0",
"regenerator-runtime": "^0.13.9",
"release-it": "^12.2.1",
"release-it-lerna-changelog": "^1.0.3",
"resolve": "^1.8.1"
"resolve": "^1.8.1",
"webpack": "^5.74.0"
},
"engines": {
"node": "14.* || 16.* || >= 18"
Expand Down
3 changes: 3 additions & 0 deletions tests/dummy/app/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import 'core-js/stable';
import 'regenerator-runtime/runtime';

import Application from '@ember/application';
import Resolver from './resolver';
import loadInitializers from 'ember-load-initializers';
Expand Down
Loading