Skip to content

Commit

Permalink
fix for Deno 2 and removal of unnecessare .cjs file
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Nov 20, 2024
1 parent 8353d94 commit f66f693
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 78 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
node_modules
package-lock.json
cjs
esm
esm
deno.lock
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ package-lock.json
README.md
tsconfig.json
example
.babelrc
.babelrc
deno.lock
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 2.7.0

- fix for Deno 2 and removal of unnecessare .cjs file

### 2.6.2

- improve network error detection across browsers [152](https://github.com/i18next/i18next-http-backend/pull/152)
Expand Down
47 changes: 12 additions & 35 deletions i18nextHttpBackend.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.i18nextHttpBackend = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
(function (global){(function (){
var fetchApi
if (typeof fetch === 'function') {
if (typeof global !== 'undefined' && global.fetch) {
fetchApi = global.fetch
} else if (typeof window !== 'undefined' && window.fetch) {
fetchApi = window.fetch
} else {
fetchApi = fetch
}
}

if (typeof require !== 'undefined' && typeof window === 'undefined') {
var f = fetchApi || require('cross-fetch')
if (f.default) f = f.default
exports.default = f
module.exports = exports.default
}

}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"cross-fetch":5}],2:[function(require,module,exports){
"use strict";

Object.defineProperty(exports, "__esModule", {
Expand Down Expand Up @@ -220,7 +199,7 @@ var Backend = function () {
Backend.type = 'backend';
var _default = exports.default = Backend;
module.exports = exports.default;
},{"./request.js":3,"./utils.js":4}],3:[function(require,module,exports){
},{"./request.js":2,"./utils.js":3}],2:[function(require,module,exports){
(function (global){(function (){
"use strict";

Expand All @@ -229,15 +208,14 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = void 0;
var _utils = require("./utils.js");
var fetchNode = _interopRequireWildcard(require("./getFetch.js"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
var fetchApi;
if (typeof fetch === 'function') {
if (typeof global !== 'undefined' && global.fetch) {
Expand All @@ -264,8 +242,12 @@ if (typeof ActiveXObject === 'function') {
ActiveXObjectApi = window.ActiveXObject;
}
}
if (!fetchApi && fetchNode && !XmlHttpRequestApi && !ActiveXObjectApi) fetchApi = fetchNode.default || fetchNode;
if (typeof fetchApi !== 'function') fetchApi = undefined;
if (!fetchApi && !XmlHttpRequestApi && !ActiveXObjectApi) {
try {
fetchApi = require('cross-fetch');
} catch (e) {}
}
var addQueryString = function addQueryString(url, params) {
if (params && _typeof(params) === 'object') {
var queryString = '';
Expand Down Expand Up @@ -344,12 +326,7 @@ var requestWithXmlHttpRequest = function requestWithXmlHttpRequest(options, url,
url = addQueryString(url, options.queryStringParams);
}
try {
var x;
if (XmlHttpRequestApi) {
x = new XmlHttpRequestApi();
} else {
x = new ActiveXObjectApi('MSXML2.XMLHTTP.3.0');
}
var x = XmlHttpRequestApi ? new XmlHttpRequestApi() : new ActiveXObjectApi('MSXML2.XMLHTTP.3.0');
x.open(payload ? 'POST' : 'GET', url, 1);
if (!options.crossDomain) {
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
Expand Down Expand Up @@ -396,7 +373,7 @@ var request = function request(options, url, payload, callback) {
var _default = exports.default = request;
module.exports = exports.default;
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./getFetch.js":1,"./utils.js":4}],4:[function(require,module,exports){
},{"./utils.js":3,"cross-fetch":4}],3:[function(require,module,exports){
"use strict";

Object.defineProperty(exports, "__esModule", {
Expand Down Expand Up @@ -431,7 +408,7 @@ function makePromise(maybePromise) {
}
return Promise.resolve(maybePromise);
}
},{}],5:[function(require,module,exports){
},{}],4:[function(require,module,exports){

},{}]},{},[2])(2)
},{}]},{},[1])(1)
});
2 changes: 1 addition & 1 deletion i18nextHttpBackend.min.js

Large diffs are not rendered by default.

18 changes: 0 additions & 18 deletions lib/getFetch.cjs

This file was deleted.

16 changes: 8 additions & 8 deletions lib/request.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { hasXMLHttpRequest } from './utils.js'
import * as fetchNode from './getFetch.cjs'

let fetchApi
if (typeof fetch === 'function') {
Expand Down Expand Up @@ -27,9 +26,15 @@ if (typeof ActiveXObject === 'function') {
ActiveXObjectApi = window.ActiveXObject
}
}
if (!fetchApi && fetchNode && !XmlHttpRequestApi && !ActiveXObjectApi) fetchApi = fetchNode.default || fetchNode // because of strange export

if (typeof fetchApi !== 'function') fetchApi = undefined

if (!fetchApi && !XmlHttpRequestApi && !ActiveXObjectApi) {
try {
fetchApi = (await import('cross-fetch')).default
} catch (e) {}
}

const addQueryString = (url, params) => {
if (params && typeof params === 'object') {
let queryString = ''
Expand Down Expand Up @@ -119,12 +124,7 @@ const requestWithXmlHttpRequest = (options, url, payload, callback) => {
}

try {
let x
if (XmlHttpRequestApi) {
x = new XmlHttpRequestApi()
} else {
x = new ActiveXObjectApi('MSXML2.XMLHTTP.3.0')
}
const x = XmlHttpRequestApi ? new XmlHttpRequestApi() : new ActiveXObjectApi('MSXML2.XMLHTTP.3.0')
x.open(payload ? 'POST' : 'GET', url, 1)
if (!options.crossDomain) {
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
Expand Down
28 changes: 16 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,28 @@
},
"types": "./index.d.mts",
"devDependencies": {
"@babel/cli": "7.24.8",
"@babel/core": "7.25.2",
"@babel/preset-env": "7.25.3",
"@babel/cli": "7.25.9",
"@babel/core": "7.26.0",
"@babel/preset-env": "7.26.0",
"babel-plugin-add-module-exports": "1.0.4",
"browserify": "17.0.0",
"browserify": "17.0.1",
"dtslint": "4.2.1",
"eslint": "8.56.0",
"eslint-config-standard": "17.1.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-import": "2.31.0",
"eslint-plugin-n": "16.6.2",
"eslint-plugin-promise": "6.1.1",
"eslint-plugin-require-path-exists": "1.1.9",
"eslint-plugin-standard": "5.0.0",
"expect.js": "0.3.1",
"i18next": "23.14.0",
"i18next": "23.16.6",
"json-server": "0.17.4",
"json5": "2.2.3",
"mocha": "10.7.3",
"mocha": "10.8.2",
"tslint": "5.20.1",
"tsd": "0.31.1",
"typescript": "5.5.4",
"uglify-js": "3.19.2",
"tsd": "0.31.2",
"typescript": "5.6.3",
"uglify-js": "3.19.3",
"xmlhttprequest": "1.8.0"
},
"description": "i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.",
Expand All @@ -70,10 +70,14 @@
"url": "https://github.com/i18next/i18next-http-backend/issues"
},
"license": "MIT",
"config": {
"fixcjs": "fs.writeFileSync('cjs/request.js', fs.readFileSync('cjs/request.js').toString().replace(`(await Promise.resolve().then(function () {\n return _interopRequireWildcard(require('cross-fetch'));\n })).default`, `require('cross-fetch')`))"
},
"scripts": {
"lint": "eslint .",
"compile:esm": "rm -rf esm && mkdir esm && BABEL_ENV=esm babel lib -d esm && cp index.d.mts esm/index.d.mts && cp index.d.ts esm/index.d.ts && cp lib/getFetch.cjs esm/getFetch.cjs && rm -f esm/getFetch.js && node -e \"fs.writeFileSync('esm/getFetch.cjs', fs.readFileSync('esm/getFetch.cjs').toString().replace('/* eslint-disable no-var, no-undef */\\n', ''))\"",
"compile:cjs": "rm -rf cjs && mkdir cjs && BABEL_ENV=cjs babel lib -d cjs && cp index.d.ts cjs/index.d.ts && echo '{\"type\":\"commonjs\"}' > cjs/package.json && cp lib/getFetch.cjs cjs/getFetch.js && node -e \"fs.writeFileSync('cjs/getFetch.js', fs.readFileSync('cjs/getFetch.js').toString().replace('/* eslint-disable no-var, no-undef */\\n', ''))\" && node -e \"fs.writeFileSync('cjs/request.js', fs.readFileSync('cjs/request.js').toString().replace('getFetch.cjs', 'getFetch.js'))\"",
"fixcjs": "node -e \"$npm_package_config_fixcjs\"",
"compile:esm": "rm -rf esm && mkdir esm && BABEL_ENV=esm babel lib -d esm && cp index.d.mts esm/index.d.mts && cp index.d.ts esm/index.d.ts",
"compile:cjs": "rm -rf cjs && mkdir cjs && BABEL_ENV=cjs babel lib -d cjs && cp index.d.ts cjs/index.d.ts && echo '{\"type\":\"commonjs\"}' > cjs/package.json && npm run fixcjs",
"compile": "npm run compile:esm && npm run compile:cjs",
"browser": "browserify --ignore cross-fetch --standalone i18nextHttpBackend cjs/index.js -o i18nextHttpBackend.js && uglifyjs i18nextHttpBackend.js --compress --mangle -o i18nextHttpBackend.min.js",
"build": "npm run compile && npm run browser",
Expand Down
3 changes: 2 additions & 1 deletion test/deno/backendConnector.load.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ test('BackendConnector basic load', async () => {
i18next.init()
const connector = i18next.services.backendConnector
connector.backend = new Http(i18next.services, {
loadPath: 'http://localhost:5001/locales/{{lng}}/{{ns}}'
loadPath: 'http://localhost:5001/locales/{{lng}}/{{ns}}',
reloadInterval: false
})
const app = await server()

Expand Down
3 changes: 2 additions & 1 deletion test/deno/http.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ test('http backend', async () => {
interpolator: i18next.services.interpolator
},
{
loadPath: 'http://localhost:5001/locales/{{lng}}/{{ns}}'
loadPath: 'http://localhost:5001/locales/{{lng}}/{{ns}}',
reloadInterval: false
}
)
const app = await server()
Expand Down

0 comments on commit f66f693

Please sign in to comment.