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

Add named exports for createInstance #1681

Merged
merged 14 commits into from
Nov 15, 2021
210 changes: 121 additions & 89 deletions i18next.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion i18next.min.js

Large diffs are not rendered by default.

3,262 changes: 2,450 additions & 812 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
"main": "./dist/cjs/i18next.js",
"module": "./dist/esm/i18next.js",
"types": "./index.d.ts",
"exports": {
adrai marked this conversation as resolved.
Show resolved Hide resolved
".": {
"import": "./dist/esm/i18next.mjs",
adrai marked this conversation as resolved.
Show resolved Hide resolved
"require": "./dist/cjs/i18next.js",
"types": "./index.d.ts"
}
},
"keywords": [
"i18next",
"internationalization",
Expand All @@ -25,15 +32,14 @@
"@babel/runtime": "^7.12.0"
},
"devDependencies": {
"@babel/core": "^7.10.1",
"@babel/plugin-proposal-async-generator-functions": "^7.2.0",
"@babel/plugin-proposal-object-rest-spread": "^7.3.2",
"@babel/plugin-transform-modules-commonjs": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/core": "^7.16.0",
"@babel/plugin-proposal-async-generator-functions": "^7.16.0",
"@babel/plugin-transform-modules-commonjs": "^7.16.0",
"@babel/plugin-transform-runtime": "^7.16.0",
"@babel/polyfill": "^7.2.5",
"@babel/preset-env": "^7.3.1",
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.0.0",
"@babel/preset-env": "^7.16.0",
"@babel/preset-react": "^7.16.0",
"@babel/register": "^7.16.0",
"@rollup/plugin-babel": "^5.2.2",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.0",
Expand Down
9 changes: 6 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ const external = (id) => !id.startsWith('.') && !id.startsWith('/') && !id.inclu
export default [
{
input,
adrai marked this conversation as resolved.
Show resolved Hide resolved
output: { format: 'cjs', file: pkg.main },
output: { format: 'cjs', file: pkg.main, exports: 'default' },
external,
plugins: [babel(getBabelOptions({ useESModules: false }))],
},

{
input,
output: { format: 'esm', file: pkg.module },
input: './src/index.esm.js',
output: [
{ format: 'esm', file: pkg.module },
{ format: 'esm', file: pkg.exports['.'].import },
adrai marked this conversation as resolved.
Show resolved Hide resolved
],
external,
plugins: [babel(getBabelOptions({ useESModules: true }))],
},
Expand Down
13 changes: 6 additions & 7 deletions src/i18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class I18n extends EventEmitter {
this.logger = baseLogger;
this.modules = { external: [] };

bindMemberFunctions(this);

if (callback && !this.isInitialized && !options.isClone) {
// https://github.com/i18next/i18next/issues/879
if (!this.options.initImmediate) {
Expand Down Expand Up @@ -559,10 +557,7 @@ class I18n extends EventEmitter {
: 'ltr';
}

/* eslint class-methods-use-this: 0 */
createInstance(options = {}, callback) {
return new I18n(options, callback);
}
static createInstance = (options = {}, callback) => new I18n(options, callback)

cloneInstance(options = {}, callback = noop) {
const mergedOptions = { ...this.options, ...options, ...{ isClone: true } };
Expand Down Expand Up @@ -599,4 +594,8 @@ class I18n extends EventEmitter {
}
}

export default new I18n();
const instance = I18n.createInstance();
instance.createInstance = I18n.createInstance;
bindMemberFunctions(instance);

export default instance;
18 changes: 18 additions & 0 deletions src/index.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import i18next from './i18next.js';

export default i18next;

export const createInstance = i18next.createInstance;

export const init = i18next.init;
export const loadResources = i18next.loadResources;
export const reloadResources = i18next.reloadResources;
export const use = i18next.use;
export const changeLanguage = i18next.changeLanguage;
export const getFixedT = i18next.getFixedT;
export const t = i18next.t;
export const exists = i18next.exists;
export const setDefaultNamespace = i18next.setDefaultNamespace;
export const hasLoadedNamespace = i18next.hasLoadedNamespace;
export const loadNamespaces = i18next.loadNamespaces;
export const loadLanguages = i18next.loadLanguages;
adrai marked this conversation as resolved.
Show resolved Hide resolved