Skip to content

Commit

Permalink
fix: generate types using tsc and stop shipping the /src directory (i…
Browse files Browse the repository at this point in the history
…18next#1027)

* generate types using tsc and stop shipping the /src directory

By using typescripts declaration mode we can generate d.ts files for all of the relevant types and stop shipping the /src directory

* fix: generate types using tsc and stop shipping the /src directory

By using typescripts declaration mode we can generate d.ts files for all of the relevant types and stop shipping the /src directory

* Remove duplicate i18n type

* Match i18n import to the one in appWithTranslation

* update serverSideTranslations.d.ts to point at the generated type

Co-authored-by: steve higgs <[email protected]>
  • Loading branch information
stevejhiggs and steve higgs authored Mar 8, 2021
1 parent 3540974 commit 770170c
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Untranspiled source and examples
examples
src

# Dependencies
node_modules
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"main": "dist/commonjs/index.js",
"module": "dist/esm/index.js",
"types": "./types.d.ts",
"types": "dist/types/types.d.ts",
"license": "MIT",
"engines": {
"node": ">=10"
Expand All @@ -32,7 +32,8 @@
"build:es": "BABEL_ENV=es babel src --extensions '.ts,.tsx' --out-dir dist/es --copy-files",
"build:cjs": "BABEL_ENV=cjs babel src --extensions '.ts,.tsx' --out-dir dist/commonjs --copy-files",
"build:esm": "BABEL_ENV=esm babel src --extensions '.ts,.tsx' --out-dir dist/esm --copy-files",
"build": "yarn clean && yarn build:cjs && yarn build:es && yarn build:esm",
"build:types": "tsc --noEmit false --declaration --emitDeclarationOnly --outDir dist/types",
"build": "yarn clean && yarn build:cjs && yarn build:es && yarn build:esm && yarn build:types",
"build:examples/simple": "yarn --cwd examples/simple && yarn --cwd examples/simple build",
"prepublishOnly": "yarn build",
"run-example": "yarn build && cd examples/simple && yarn && yarn dev",
Expand Down
2 changes: 1 addition & 1 deletion serverSideTranslations.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { serverSideTranslations } from './src/serverSideTranslations'
export { serverSideTranslations } from './dist/types/serverSideTranslations'
2 changes: 1 addition & 1 deletion src/appWithTranslation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { AppProps as NextJsAppProps } from 'next/app'
import { createConfig } from './config/createConfig'
import createClient from './createClient'

import { SSRConfig, UserConfig } from '../types'
import { SSRConfig, UserConfig } from './types'

import { i18n as I18NextClient } from 'i18next'
export { Trans, useTranslation, withTranslation } from 'react-i18next'
Expand Down
2 changes: 1 addition & 1 deletion src/config/createConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs'
import path from 'path'

import { createConfig } from './createConfig'
import { UserConfig } from '../../types'
import { UserConfig } from '../types'

jest.mock('fs', () => ({
existsSync: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion src/config/createConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defaultConfig } from './defaultConfig'
import { InternalConfig, UserConfig } from '../../types'
import { InternalConfig, UserConfig } from '../types'

const deepMergeObjects = ['backend', 'detection'] as (keyof Pick<UserConfig, 'backend' | 'detection'>)[]

Expand Down
2 changes: 1 addition & 1 deletion src/createClient/browser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import i18n from 'i18next'

import { InternalConfig, CreateClientReturn, InitPromise } from '../../types'
import { InternalConfig, CreateClientReturn, InitPromise } from '../types'

export default (config: InternalConfig): CreateClientReturn => {
const instance = i18n.createInstance(config)
Expand Down
2 changes: 1 addition & 1 deletion src/createClient/node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import i18n from 'i18next'
import i18nextFSBackend from 'i18next-fs-backend'

import { InternalConfig, CreateClientReturn, InitPromise } from '../../types'
import { InternalConfig, CreateClientReturn, InitPromise } from '../types'

export default (config: InternalConfig): CreateClientReturn => {
const instance = i18n.createInstance(config)
Expand Down
2 changes: 1 addition & 1 deletion src/serverSideTranslations.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs'
import { UserConfig } from '../types'
import { UserConfig } from './types'
import { serverSideTranslations } from './serverSideTranslations'

jest.mock('fs', () => ({
Expand Down
2 changes: 1 addition & 1 deletion src/serverSideTranslations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path'
import { createConfig } from './config/createConfig'
import createClient from './createClient'

import { UserConfig, SSRConfig } from '../types'
import { UserConfig, SSRConfig } from './types'

const DEFAULT_CONFIG_PATH = './next-i18next.config.js'

Expand Down
6 changes: 3 additions & 3 deletions types.d.ts → src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
withTranslation,
WithTranslation as ReactI18nextWithTranslation,
} from 'react-i18next'
import { InitOptions, i18n, TFunction as I18NextTFunction } from 'i18next'
import { appWithTranslation, i18n } from './src'
import { InitOptions, i18n as I18NextClient, TFunction as I18NextTFunction } from 'i18next'
import { appWithTranslation, i18n } from './'

type NextJsI18NConfig = {
defaultLocale: string
Expand Down Expand Up @@ -37,7 +37,7 @@ export type InternalConfig = Omit<UserConfig, 'i18n'> & NextJsI18NConfig & {
export type UseTranslation = typeof useTranslation
export type AppWithTranslation = typeof appWithTranslation
export type TFunction = I18NextTFunction
export type I18n = i18n
export type I18n = I18NextClient
export type WithTranslationHocType = typeof withTranslation
export type WithTranslation = ReactI18nextWithTranslation
export type InitPromise = Promise<TFunction>
Expand Down

0 comments on commit 770170c

Please sign in to comment.