Skip to content

Commit

Permalink
Feature: New context API (#1186)
Browse files Browse the repository at this point in the history
Feature: New context API
  • Loading branch information
Seth Bertalotto committed Apr 30, 2019
2 parents ee1dfb6 + 90aaf7a commit 9133d1a
Show file tree
Hide file tree
Showing 42 changed files with 6,725 additions and 3,684 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"env": {
"test": {
"plugins": [
"transform-es2015-modules-commonjs"
"@babel/plugin-transform-modules-commonjs"
],
"only": [
"lib/index.es.js"
Expand Down
4 changes: 2 additions & 2 deletions examples/async/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
"es2015",
"react"
"@babel/preset-env",
"@babel/preset-react"
]
}
4 changes: 2 additions & 2 deletions examples/explicit-timezone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"dependencies": {
"prop-types": "^15.5.4",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-intl": "^2.3.0"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions examples/hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"react-scripts": "0.8.4"
},
"dependencies": {
"react": "^15.3.2",
"react-dom": "^15.3.2",
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-intl": "^2.1.5"
},
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions examples/jest-snapshot-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"private": true,
"devDependencies": {
"react-scripts": "0.8.4",
"react-test-renderer": "^15.3.2"
"react-test-renderer": "^16.3.1"
},
"dependencies": {
"react": "^15.3.2",
"react-dom": "^15.3.2",
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-intl": "^2.1.5"
},
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions examples/nested/.babelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"presets": [
"es2015",
"react"
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
["react-intl", {
["babel-plugin-transform-react-remove-prop-types", {
"messagesDir": "./build/messages/"
}]
]
Expand Down
4 changes: 2 additions & 2 deletions examples/react-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"react-scripts": "0.8.4"
},
"dependencies": {
"react": "^15.3.2",
"react-dom": "^15.3.2",
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-intl": "^2.1.5",
"react-router-dom": "^4.1.2"
},
Expand Down
6 changes: 3 additions & 3 deletions examples/translations/.babelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"presets": [
"es2015",
"react"
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
["react-intl", {
["babel-plugin-transform-react-remove-prop-types", {
"messagesDir": "./build/messages/"
}]
]
Expand Down
87 changes: 46 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
],
"author": "Eric Ferraiuolo <edf@ericf.me>",
"contributors": [
"Caridy Patino <caridy@gmail.com>"
"Caridy Patino <caridy@gmail.com>",
"Marces Engel <dev.dragonraider5@gmail.com>"
],
"license": "BSD-3-Clause",
"homepage": "https://github.com/yahoo/react-intl",
Expand All @@ -42,7 +43,8 @@
"jest": {
"testRegex": "/test/(unit|functional)/.*\\.js",
"testPathIgnorePatterns": [
"/test/functional/support/"
"test/functional/support",
"/test/unit/testUtils"
],
"collectCoverageFrom": [
"src/**/*.js",
Expand All @@ -61,64 +63,70 @@
"lines": 95,
"statements": 95
}
}
},
"setupTestFrameworkScriptFile": "./test/setup.js"
},
"dependencies": {
"hoist-non-react-statics": "^2.5.5",
"intl-format-cache": "^2.0.5",
"intl-messageformat": "^2.1.0",
"intl-relativeformat": "^2.1.0",
"invariant": "^2.1.1"
"invariant": "^2.1.1",
"react-display-name": "^0.2.4"
},
"peerDependencies": {
"prop-types": "^15.5.4",
"react": "^0.14.9 || ^15.0.0 || ^16.0.0"
"react": "^16.3.1"
},
"devDependencies": {
"babel-cli": "^6.2.0",
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/node": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-transform-async-to-generator": "^7.1.0",
"@babel/plugin-transform-modules-commonjs": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"@babel/preset-react": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^7.1.1",
"babel-jest": "^19.0.0",
"babel-plugin-external-helpers": "^6.18.0",
"babel-jest": "^23.6.0",
"babel-plugin-react-intl": "^2.0.0",
"babel-plugin-transform-async-to-generator": "^6.16.0",
"babel-plugin-transform-class-properties": "^6.11.5",
"babel-plugin-transform-es2015-modules-commonjs": "^6.18.0",
"babel-plugin-transform-es3-member-expression-literals": "^6.3.13",
"babel-plugin-transform-es3-property-literals": "^6.3.13",
"babel-plugin-transform-object-rest-spread": "^6.1.18",
"babel-plugin-transform-react-remove-prop-types": "^0.3.2",
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.1.18",
"babel-plugin-transform-member-expression-literals": "^6.9.4",
"babel-plugin-transform-property-literals": "^6.9.4",
"babel-plugin-transform-react-remove-prop-types": "^0.4.18",
"babelify": "^7.2.0",
"benchmark": "^2.1.0",
"browserify": "^14.0.0",
"browserify-shim": "^3.8.11",
"cross-env": "^4.0.0",
"enzyme": "^3.6.0",
"enzyme-adapter-react-16": "^1.5.0",
"eslint": "^3.10.2",
"eslint-plugin-react": "^7.0.1",
"expect": "^1.9.0",
"expect-jsx": "^3.0.0",
"express": "^4.13.3",
"formatjs-extract-cldr-data": "^6.0.0",
"glob": "^7.0.0",
"intl": "^1.2.1",
"intl-messageformat-parser": "^1.2.0",
"jest": "^19.0.0",
"jest": "^23.6.0",
"mkdirp": "^0.5.1",
"prettier": "^1.6.1",
"prop-types": "^15.5.4",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-test-renderer": "^15.5.4",
"progress": "^2.0.3",
"promise-queue": "^2.2.5",
"prop-types": "^15.6.1",
"react": "^16.3.1",
"react-dom": "^16.3.3",
"rimraf": "^2.4.2",
"rollup": "^0.50.0",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-commonjs": "^8.2.1",
"rollup-plugin-memory": "^2.0.0",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup": "^0.66.2",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "^9.1.8",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-uglify": "^2.0.0",
"serialize-javascript": "^1.1.1",
"rollup-plugin-uglify": "^6.0.0",
"rollup-plugin-virtual": "^1.0.1",
"serialize-javascript": "^1.5.0",
"superagent": "^3.0.0",
"watchify": "^3.7.0"
},
Expand All @@ -129,21 +137,18 @@
"build:lib": "rollup -c rollup.config.lib.js",
"build:dist:dev": "cross-env NODE_ENV=development rollup -c rollup.config.dist.js",
"build:dist:prod": "cross-env NODE_ENV=production rollup -c rollup.config.dist.js",
"build:dist": "npm run build:dist:dev && npm run build:dist:prod",
"build": "npm run build:data && npm run build:lib && npm run build:dist",
"react:clean": "rimraf node_modules/{react,react-dom,react-addons-test-utils}",
"react:14": "npm run react:clean && npm i react@^0.14 react-dom@^0.14 react-addons-test-utils@^0.14",
"react:15": "npm run react:clean && npm i react@^15 react-dom@^15",
"build:dist": "yarn run build:dist:dev && yarn run build:dist:prod",
"build": "yarn run build:data && yarn run build:lib && yarn run build:dist",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test": "jest --coverage --verbose",
"test:react": "npm run react:14 && jest && npm run react:15 && jest",
"test:all": "npm run lint && npm run test && npm run test:react",
"test:react": "jest",
"test:all": "yarn run lint && yarn run test && yarn run test:react",
"test:watch": "jest --watch",
"test:perf": "cross-env NODE_ENV=production babel-node test/perf",
"examples:install": "babel-node scripts/examples npm install",
"examples:link": "npm link && babel-node scripts/examples npm link react-intl",
"preversion": "npm run clean && npm run build && npm run test:all",
"prepare": "npm run clean && npm run build"
"examples:install": "babel-node scripts/examples yarn install",
"examples:link": "yarn link && babel-node scripts/examples yarn link react-intl",
"preversion": "yarn run clean && yarn run build && yarn run test:all",
"prepare": "yarn run clean && yarn run build"
}
}
18 changes: 9 additions & 9 deletions rollup.config.dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import babel from 'rollup-plugin-babel';
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import replace from 'rollup-plugin-replace';
import uglify from 'rollup-plugin-uglify';
import {uglify} from 'rollup-plugin-uglify';

const isProduction = process.env.NODE_ENV === 'production';

Expand All @@ -24,14 +24,14 @@ export default {
output: {
file: p.resolve(`dist/react-intl.${isProduction ? 'min.js' : 'js'}`),
format: 'umd',
},
name: 'ReactIntl',
banner: copyright,
intro: reactCheck,
sourcemap: true,
globals: {
react: 'React',
'prop-types': 'PropTypes',
name: 'ReactIntl',
banner: copyright,
intro: reactCheck,
sourcemap: true,
globals: {
react: 'React',
'prop-types': 'PropTypes',
},
},
external: ['react', 'prop-types'],
plugins: [
Expand Down
15 changes: 11 additions & 4 deletions rollup.config.lib.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as p from 'path';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';

const copyright = `/*
* Copyright ${new Date().getFullYear()}, Yahoo Inc.
Expand All @@ -11,10 +13,9 @@ const copyright = `/*
export default {
input: p.resolve('src/index.js'),
output: [
{file: 'lib/index.js', format: 'cjs'},
{file: 'lib/index.es.js', format: 'es'},
{file: 'lib/index.js', format: 'cjs', banner: copyright},
{file: 'lib/index.es.js', format: 'es', banner: copyright},
],
banner: copyright,
external: [
'intl-format-cache',
'intl-messageformat',
Expand All @@ -24,5 +25,11 @@ export default {
'prop-types',
p.resolve('locale-data/index.js'),
],
plugins: [babel()],
plugins: [
babel(),
commonjs(),
nodeResolve({
jsnext: true
})
],
};
2 changes: 1 addition & 1 deletion scripts/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
"es2015"
"@babel/preset-env"
]
}
34 changes: 25 additions & 9 deletions scripts/build-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import {sync as mkdirpSync} from 'mkdirp';
import extractCLDRData from 'formatjs-extract-cldr-data';
import serialize from 'serialize-javascript';
import {rollup} from 'rollup';
import memory from 'rollup-plugin-memory';
import uglify from 'rollup-plugin-uglify';
import virtual from 'rollup-plugin-virtual';
import {uglify} from 'rollup-plugin-uglify';
import ProgressBar from 'progress';
import PromiseQueue from 'promise-queue';

const DEFAULT_LOCALE = 'en';
const CONCURRENCY = require('os').cpus().length - 1;

const cldrData = extractCLDRData({
pluralRules: true,
Expand Down Expand Up @@ -36,9 +39,8 @@ function writeUMDFile(filename, module) {
return rollup({
input: filename,
plugins: [
memory({
path: filename,
contents: module,
virtual({
[filename]: module
}),
uglify(),
],
Expand Down Expand Up @@ -69,17 +71,31 @@ function writeFile(filename, contents) {

mkdirpSync('locale-data/');

console.log('Building locale data...');

const progressBar = new ProgressBar(':percent [:bar] eta. :etas', {
callback: () => console.log('...done!'),
clear: true,
total: cldrDataByLang.size + 2
});

const defaultData = createDataModule(cldrDataByLocale.get(DEFAULT_LOCALE));
writeFile(`src/${DEFAULT_LOCALE}.js`, defaultData);
writeFile(`src/${DEFAULT_LOCALE}.js`, defaultData)
.then(() => progressBar.tick())

const allData = createDataModule([...cldrDataByLocale.values()]);
writeUMDFile('locale-data/index.js', allData);
writeUMDFile('locale-data/index.js', allData)
.then(() => progressBar.tick())

const promiseQueue = new PromiseQueue(CONCURRENCY, Infinity);

cldrDataByLang.forEach((cldrData, lang) => {
writeUMDFile(`locale-data/${lang}.js`, createDataModule(cldrData));
promiseQueue.add(() =>
writeUMDFile(`locale-data/${lang}.js`, createDataModule(cldrData))
.then(() => progressBar.tick())
);
});

process.on('unhandledRejection', reason => {
throw reason;
});
console.log('> Writing locale data files...');

0 comments on commit 9133d1a

Please sign in to comment.