Skip to content

Commit

Permalink
address comments and disable the configFile option in the babel options
Browse files Browse the repository at this point in the history
  • Loading branch information
suchitadoshi1987 committed Dec 11, 2020
1 parent 09aaf01 commit 3f9a7a6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ let app = new EmberAddon(defaults, {
```js
//babel.config.js

const { emberPlugins } = require("ember-cli-babel");
const { buildEmberPlugins } = require("ember-cli-babel");

module.exports = function (api) {
api.cache(true);
Expand All @@ -339,7 +339,7 @@ module.exports = function (api) {
},
],
// this is where all the ember required plugins would reside
...emberPlugins(__dirname, { ...options }),
...buildEmberPlugins(__dirname, { /*customOptions if you want to pass in */ }),
],
};
};
Expand Down
39 changes: 23 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ const emberPlugins = require('./lib/ember-plugins');

const APP_BABEL_RUNTIME_VERSION = new WeakMap();

// Ref: https://github.com/babel/babel/blob/c6aea4e85d2b8f3e82575642d30b01c8cbe112a9/packages/babel-core/src/config/files/configuration.js#L24
// supported babel config root filenames.
const ROOT_CONFIG_FILENAMES = [
"babel.config.js",
"babel.config.cjs",
"babel.config.mjs",
"babel.config.json",
];

let count = 0;

module.exports = {
Expand Down Expand Up @@ -96,6 +87,7 @@ module.exports = {

options.highlightCode = _shouldHighlightCode(this.parent);
options.babelrc = false;
options.configFile = false;

return options;
},
Expand All @@ -108,16 +100,31 @@ module.exports = {
let options = this._getDefaultBabelOptions(config);
let output;

const babelConfigFile = ROOT_CONFIG_FILENAMES.find((fileName) =>
fs.existsSync(path.resolve(this.parent.root, fileName))
);

const customAddonConfig = config['ember-cli-babel'];
const shouldUseBabelConfigFile = customAddonConfig && customAddonConfig.useBabelConfig && babelConfigFile;

const shouldUseBabelConfigFile = customAddonConfig && customAddonConfig.useBabelConfig;
if (shouldUseBabelConfigFile) {
// Ref: https://github.com/babel/babel/blob/c6aea4e85d2b8f3e82575642d30b01c8cbe112a9/packages/babel-core/src/config/files/configuration.js#L24
// supported babel config root filenames.
const ROOT_CONFIG_FILENAMES = [
"babel.config.js",
"babel.config.cjs",
"babel.config.mjs",
"babel.config.json",
].map(fileName => path.resolve(this.parent.root, fileName));

const babelConfigFile = ROOT_CONFIG_FILENAMES.find((fileName) =>
fs.existsSync(fileName)
);
if (!babelConfigFile) {
throw new Error(
"Missing babel config file in the project root. Please double check if the babel config file exists or turn off the `useBabelConfig` option in your ember-cli-build.js file."
);
}
options = Object.assign({}, options, {
"presets":[ require.resolve(path.resolve(this.parent.root, babelConfigFile)) ],
presets: [
require.resolve(babelConfigFile),
],
});
} else {
options = Object.assign({}, options, this.buildBabelOptions(config));
Expand Down
16 changes: 16 additions & 0 deletions lib/ember-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ function _getProposalDecoratorsAndClassPlugins(config) {
}
}

/**
* This function allows returns all the required Ember specific babel plugins for the app to transpile correctly.
* As the first argument, you need to pass in the appRoot (which is usually the __dirname).
* As the second argument, which is optional, you can choose to turn the switch on and off of several plugins that this function returns.
* **List of supported configs**
* {
* disableModuleResolution: boolean, // determines if you want the module resolution enabled
* emberDataVersionRequiresPackagesPolyfill: boolean, // enable ember data's polyfill
* shouldIgnoreJQuery: boolean, // ignore jQuery
* shouldIgnoreEmberString: boolean, // ignore ember string
* shouldIgnoreDecoratorAndClassPlugins: boolean, // disable decorator plugins
* disableEmberModulesAPIPolyfill: boolean, // disable ember modules API polyfill
* }
* @param {string} appRoot - root directory of your project
* @param {object} config - config options to finetune the plugins
*/
module.exports = function (appRoot, config = {}) {
return []
.concat(
Expand Down

0 comments on commit 3f9a7a6

Please sign in to comment.