Skip to content

Commit

Permalink
fix: add flow types and fix package exports
Browse files Browse the repository at this point in the history
Closes #250
  • Loading branch information
tricoder42 committed Aug 3, 2018
1 parent 567e730 commit b93d0ee
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 59 deletions.
1 change: 1 addition & 0 deletions .flowconfig
@@ -1,4 +1,5 @@
[ignore]
.*/build/.*
.*/examples/.*
.*/node_modules/config-chain/.*
.*/node_modules/conventional-changelog-core/.*
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/api.js
@@ -1,3 +1 @@
// Replace in Babel 7.x (https://github.com/babel/babel/issues/2877):
// export * from "./src/api"
module.exports = require("./src/api")
export * from "./src/api"
4 changes: 1 addition & 3 deletions packages/cli/index.js
@@ -1,3 +1 @@
// Replace in Babel 7.x (https://github.com/babel/babel/issues/2877):
// export * from "./src/lingui"
module.exports = require("./src/lingui")
export * from "./src/lingui"
3 changes: 2 additions & 1 deletion packages/cli/package.json
Expand Up @@ -32,7 +32,8 @@
"lingui.js",
"lingui-add-locale.js",
"lingui-compile.js",
"lingui-extract.js"
"lingui-extract.js",
"*.js.flow"
],
"dependencies": {
"@lingui/babel-plugin-extract-messages": "0.0.0-managed-by-release-script",
Expand Down
4 changes: 1 addition & 3 deletions packages/conf/index.js
@@ -1,3 +1 @@
// Replace in Babel 7.x (https://github.com/babel/babel/issues/2877):
// export * from "./src"
module.exports = require("./src")
export * from "./src"
4 changes: 1 addition & 3 deletions packages/core/index.js
@@ -1,3 +1 @@
// Replace in Babel 7.x (https://github.com/babel/babel/issues/2877):
// export * from "./src"
module.exports = require("./src")
export * from "./src"
1 change: 1 addition & 0 deletions packages/core/package.json
Expand Up @@ -26,6 +26,7 @@
"README.md",
"index.js",
"dev.js",
"*.js.flow",
"cjs/"
],
"dependencies": {
Expand Down
4 changes: 1 addition & 3 deletions packages/loader/index.js
@@ -1,3 +1 @@
// Replace in Babel 7.x (https://github.com/babel/babel/issues/2877):
// export { default } from "./src"
module.exports = require("./src")
export { default } from "./src"
4 changes: 1 addition & 3 deletions packages/react/index.js
@@ -1,3 +1 @@
// Replace in Babel 7.x (https://github.com/babel/babel/issues/2877):
// export * from "./src"
module.exports = require("./src")
export * from "./src"
14 changes: 11 additions & 3 deletions packages/react/package.json
Expand Up @@ -26,12 +26,20 @@
"bugs": {
"url": "https://github.com/lingui/js-lingui/issues"
},
"peerDependencies": {
"react": "^15.0.0 || ^16.0.0"
},
"engines": {
"node": ">=4.0"
},
"files": [
"LICENSE",
"README.md",
"index.js",
"dev.js",
"*.js.flow",
"cjs/"
],
"peerDependencies": {
"react": "^15.0.0 || ^16.0.0"
},
"dependencies": {
"@lingui/core": "0.0.0-managed-by-release-script",
"babel-runtime": "^6.26.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/react/src/I18nProvider.js
@@ -1,4 +1,4 @@
/* @flow */
// @flow
import * as React from "react"
import PropTypes from "prop-types"
import hashSum from "hash-sum"
Expand All @@ -7,13 +7,13 @@ import { setupI18n } from "@lingui/core"
import type { I18n, Catalogs, Locales } from "@lingui/core"

export type I18nProviderProps = {
children?: React.Node,
children?: any,
language: string,
locales?: Locales,
catalogs?: Catalogs,
i18n?: I18n,

defaultRender: Node
defaultRender: ?any
}

/*
Expand Down Expand Up @@ -102,6 +102,6 @@ export default class I18nProvider extends React.Component<I18nProviderProps> {
}

render() {
return <React.Fragment>{this.props.children}</React.Fragment>
return this.props.children
}
}
2 changes: 1 addition & 1 deletion packages/react/src/Trans.test.js
@@ -1,4 +1,4 @@
/* @flow */
// @flow
import * as React from "react"
import { mount, shallow } from "enzyme"

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/format.js
Expand Up @@ -14,7 +14,7 @@ const nlRe = /(?:\r\n|\r|\n)/g
*/
function formatElements(
value: string,
elements: Array<React$Element<any>> = []
elements: Array<any> = []
): string | Array<any> {
// TODO: warn if there're any unprocessed elements
// TODO: warn if element at `index` doesn't exist
Expand Down
28 changes: 18 additions & 10 deletions packages/react/src/index.js
@@ -1,18 +1,26 @@
// @flow
import { date, number } from "@lingui/core"

import createFormat from "./createFormat"
import I18nProvider from "./I18nProvider"
import Trans from "./Trans"
import { Plural, Select, SelectOrdinal } from "./Select"

import createFormat from "./createFormat"
import withI18n from "./withI18n"
import type { withI18nProps } from "./withI18n"
export { withI18n }
export type { withI18nProps }

export { default as I18nProvider } from "./I18nProvider"
export { default as Trans } from "./Trans"
export { Plural, Select, SelectOrdinal } from "./Select"
const DateFormat = withI18n()(createFormat(date))
const NumberFormat = withI18n()(createFormat(number))

export const DateFormat = withI18n()(createFormat(date))
export const NumberFormat = withI18n()(createFormat(number))
const i18nMark = (id: string) => id

export const i18nMark = (id: string) => id
export {
i18nMark,
withI18n,
I18nProvider,
Trans,
Plural,
Select,
SelectOrdinal,
DateFormat,
NumberFormat
}
2 changes: 2 additions & 0 deletions packages/react/src/withI18n.test.js
Expand Up @@ -2,6 +2,8 @@
import * as React from "react"
import { mount } from "enzyme"

// Don't import from @lingui/react,
// otherwise we're not able to mockEnv in integration test
import { withI18n } from "."
import { mockEnv, mockConsole } from "./mocks"

Expand Down
31 changes: 20 additions & 11 deletions scripts/build/babel.config.js
Expand Up @@ -2,18 +2,27 @@
// Rollup, however, needs `modules: false, babel modules: true`
module.exports = function(options) {
const config = {
// Workaround for transform-runtime bug with export * from "./module"
// https://github.com/babel/babel/issues/2877#issuecomment-245402025
passPerPreset: true,
presets: [
"react",
[
"env",
{
targets: {
node: 4,
browsers: "> 1%, last 2 versions"
},
modules: options.modules === false ? false : "commonjs"
}
]
{ plugins: ["transform-runtime"] },
{
passPerPreset: false,
presets: [
"react",
[
"env",
{
targets: {
node: 4,
browsers: "> 1%, last 2 versions"
},
modules: options.modules === false ? false : "commonjs"
}
]
]
}
],
plugins: [
["transform-class-properties", { loose: false }],
Expand Down
13 changes: 12 additions & 1 deletion scripts/build/index.js
Expand Up @@ -4,7 +4,7 @@ const Modules = require("./modules")
const Bundles = require("./bundles")
const Packaging = require("./packaging")
const Stats = require("./stats")
const { asyncCopyTo, asyncRimRaf } = require("./utils")
const { asyncCopyTo, asyncRimRaf, asyncExecuteCommand } = require("./utils")

const rollup = require("./rollup")
const babel = require("./babel")
Expand Down Expand Up @@ -34,6 +34,13 @@ function shouldSkipBundle(bundle, bundleType) {
return false
}

async function copyFlowTypes(srcDir, outDir) {
console.log('Generating flow types')
return asyncExecuteCommand(
`flow gen-flow-files --ignore ".*\.test\.js$" --out-dir ${outDir} ${srcDir}`
)
}

async function buildEverything() {
await asyncRimRaf("build")

Expand All @@ -49,6 +56,10 @@ async function buildEverything() {
}

await builder(bundle)
if (bundle.type === UNIVERSAL || bundle.type === NODE) {
const name = bundle.entry.replace("@lingui/", "")
await copyFlowTypes(`packages/${name}/src`, `build/packages/${name}`)
}
}

console.log(Stats.printResults())
Expand Down
16 changes: 8 additions & 8 deletions scripts/build/results.json
@@ -1,20 +1,20 @@
{
"bundleSizes": {
"@lingui/core.development.js (NODE_DEV)": {
"size": 13974,
"gzip": 3692
"size": 13895,
"gzip": 3636
},
"@lingui/core.production.min.js (NODE_PROD)": {
"size": 5741,
"gzip": 1892
"size": 5800,
"gzip": 1902
},
"@lingui/react.development.js (NODE_DEV)": {
"size": 18214,
"gzip": 5063
"size": 18086,
"gzip": 4999
},
"@lingui/react.production.min.js (NODE_PROD)": {
"size": 8598,
"gzip": 3084
"size": 8664,
"gzip": 3099
}
}
}
1 change: 0 additions & 1 deletion scripts/build/rollup.js
Expand Up @@ -16,7 +16,6 @@ const argv = require("minimist")(process.argv.slice(2))
const Stats = require("./stats")
const sizes = require("./plugins/sizes")
const codeFrame = require("babel-code-frame")
// const Wrappers = require("./wrappers")
const babelConfig = require("./babel.config")

const Modules = require("./modules")
Expand Down

0 comments on commit b93d0ee

Please sign in to comment.