Skip to content

Commit

Permalink
fix for Deno 2 and removal of unnecessary .cjs file
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Nov 20, 2024
1 parent 517d7c7 commit 7a6a8c8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 73 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 6.6.0

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

### 6.5.2

- improve network error detection across browsers
Expand Down
43 changes: 10 additions & 33 deletions i18nextLocizeBackend.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.i18nextLocizeBackend = 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 @@ -672,15 +651,14 @@ var I18NextLocizeBackend = function () {
I18NextLocizeBackend.type = 'backend';
var _default = exports.default = I18NextLocizeBackend;
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";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
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 _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); }
Expand Down Expand Up @@ -710,8 +688,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 requestWithFetch = function requestWithFetch(options, url, payload, callback) {
var headers = {};
if (typeof window === 'undefined' && typeof global !== 'undefined' && typeof global.process !== 'undefined' && global.process.versions && global.process.versions.node) {
Expand Down Expand Up @@ -753,12 +735,7 @@ var requestWithFetch = function requestWithFetch(options, url, payload, callback
};
var requestWithXmlHttpRequest = function requestWithXmlHttpRequest(options, url, payload, callback) {
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 @@ -799,7 +776,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}],4:[function(require,module,exports){
},{"cross-fetch":4}],3:[function(require,module,exports){
"use strict";

Object.defineProperty(exports, "__esModule", {
Expand Down Expand Up @@ -926,7 +903,7 @@ function defer() {
promise.reject = rej;
return promise;
}
},{}],5:[function(require,module,exports){
},{}],4:[function(require,module,exports){

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

Large diffs are not rendered by default.

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

This file was deleted.

15 changes: 6 additions & 9 deletions lib/request.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as fetchNode from './getFetch.cjs'

let fetchApi
if (typeof fetch === 'function') {
if (typeof global !== 'undefined' && global.fetch) {
Expand All @@ -26,8 +24,12 @@ 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) {}
}

// fetch api stuff
const requestWithFetch = (options, url, payload, callback) => {
Expand Down Expand Up @@ -66,12 +68,7 @@ const requestWithFetch = (options, url, payload, callback) => {
// xml http request stuff
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 @@ -42,33 +42,37 @@
},
"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.53.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.7",
"json-server": "0.17.4",
"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"
},
"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.ts esm/index.d.ts && cp index.d.mts esm/index.d.mts && 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.ts esm/index.d.ts && cp index.d.mts esm/index.d.mts",
"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 i18nextLocizeBackend cjs/index.js -o i18nextLocizeBackend.js && uglifyjs i18nextLocizeBackend.js --compress --mangle -o i18nextLocizeBackend.min.js",
"build": "npm run compile && npm run browser",
Expand Down

0 comments on commit 7a6a8c8

Please sign in to comment.