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

feat!: babel-plugin-react-intl to babel-plugin-formatjs migration #313

Merged
merged 6 commits into from
Sep 28, 2023
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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ documentation to learn what options are available. Example package.json::
{
"scripts": {
"build": "fedx-scripts webpack",
"i18n_extract": "BABEL_ENV=i18n fedx-scripts babel src --quiet > /dev/null",
"i18n_extract": "fedx-scripts formatjs extract",
"lint": "fedx-scripts eslint --ext .jsx,.js .",
"precommit": "npm run lint",
"snapshot": "fedx-scripts jest --updateSnapshot",
Expand Down
12 changes: 12 additions & 0 deletions bin/fedx-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ switch (commandName) {
ensureConfigOption(presets.webpackDevServer);
require('webpack-dev-server/bin/webpack-dev-server');
break;
case 'formatjs': {
const commonArgs = [
'--format', 'node_modules/@edx/frontend-build/lib/formatter.js',
'--ignore', 'src/**/*.json',
'--out-file', './temp/babel-plugin-formatjs/Default.messages.json',
'--', 'src/**/*.js*',
];
process.argv = process.argv.concat(commonArgs);
ensureConfigOption(presets.formatjs);
require('@formatjs/cli/bin/formatjs');
break;
}
case 'serve':
require('../lib/scripts/serve');
break;
Expand Down
6 changes: 1 addition & 5 deletions config/babel-preserve-modules.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ module.exports = {
i18n: {
plugins: [
[
'react-intl',
{
messagesDir: './temp/babel-plugin-react-intl',
moduleSourceName: '@edx/frontend-platform/i18n',
},
'formatjs',
],
],
},
Expand Down
6 changes: 1 addition & 5 deletions config/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ module.exports = {
i18n: {
plugins: [
[
'react-intl',
{
messagesDir: './temp/babel-plugin-react-intl',
moduleSourceName: '@edx/frontend-platform/i18n',
},
'formatjs',
],
],
},
Expand Down
10 changes: 10 additions & 0 deletions lib/formatter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
exports.format = (messages) => {
const results = Object.entries(messages).map(([id, message]) => (
{
id,
defaultMessage: message.defaultMessage,
description: message.description,
}
));
return results;
};
7 changes: 7 additions & 0 deletions lib/presets.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const babel = new ConfigPreset({
searchFilepaths,
});

const formatjs = new ConfigPreset({
defaultFilename: 'babel.config.js',
searchFilenames: ['.babelrc', '.babelrc.js', 'babel.config.js'],
searchFilepaths,
});

const babelPreserveModules = new ConfigPreset({
defaultFilename: 'babel-preserve-modules.config.js',
searchFilenames: ['.babelrc', '.babelrc.js', 'babel.config.js'],
Expand Down Expand Up @@ -52,6 +58,7 @@ const webpack = new ConfigPreset({

module.exports = {
babel,
formatjs,
babelPreserveModules,
'babel-preserve-modules': babelPreserveModules,
'babel-typescript': babelTypescript,
Expand Down
Loading