Skip to content

Commit

Permalink
Revert "Remove support for deprecated import/require"
Browse files Browse the repository at this point in the history
This reverts commit baac270.
  • Loading branch information
mjackson committed Sep 11, 2019
1 parent 1c2a1fe commit ec0c152
Show file tree
Hide file tree
Showing 19 changed files with 161 additions and 1 deletion.
3 changes: 3 additions & 0 deletions DOMUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';
require('./warnAboutDeprecatedCJSRequire.js')('DOMUtils');
module.exports = require('./index.js').DOMUtils;
3 changes: 3 additions & 0 deletions ExecutionEnvironment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';
require('./warnAboutDeprecatedCJSRequire.js')('ExecutionEnvironment');
module.exports = require('./index.js').ExecutionEnvironment;
3 changes: 3 additions & 0 deletions LocationUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';
require('./warnAboutDeprecatedCJSRequire.js')('LocationUtils');
module.exports = require('./index.js').LocationUtils;
3 changes: 3 additions & 0 deletions PathUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';
require('./warnAboutDeprecatedCJSRequire.js')('PathUtils');
module.exports = require('./index.js').PathUtils;
3 changes: 3 additions & 0 deletions createBrowserHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';
require('./warnAboutDeprecatedCJSRequire.js')('createBrowserHistory');
module.exports = require('./index.js').createBrowserHistory;
3 changes: 3 additions & 0 deletions createHashHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';
require('./warnAboutDeprecatedCJSRequire.js')('createHashHistory');
module.exports = require('./index.js').createHashHistory;
3 changes: 3 additions & 0 deletions createMemoryHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';
require('./warnAboutDeprecatedCJSRequire.js')('createMemoryHistory');
module.exports = require('./index.js').createMemoryHistory;
3 changes: 3 additions & 0 deletions createTransitionManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';
require('./warnAboutDeprecatedCJSRequire.js')('createTransitionManager');
module.exports = require('./index.js').createTransitionManager;
7 changes: 7 additions & 0 deletions es/DOMUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

import warnAboutDeprecatedESMImport from './warnAboutDeprecatedESMImport.js';
warnAboutDeprecatedESMImport('DOMUtils');

import { DOMUtils } from '../esm/history.js';
export default DOMUtils;
7 changes: 7 additions & 0 deletions es/ExecutionEnvironment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

import warnAboutDeprecatedESMImport from './warnAboutDeprecatedESMImport.js';
warnAboutDeprecatedESMImport('ExecutionEnvironment');

import { ExecutionEnvironment } from '../esm/history.js';
export default ExecutionEnvironment;
7 changes: 7 additions & 0 deletions es/LocationUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

import warnAboutDeprecatedESMImport from './warnAboutDeprecatedESMImport.js';
warnAboutDeprecatedESMImport('LocationUtils');

import { LocationUtils } from '../esm/history.js';
export default LocationUtils;
7 changes: 7 additions & 0 deletions es/PathUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

import warnAboutDeprecatedESMImport from './warnAboutDeprecatedESMImport.js';
warnAboutDeprecatedESMImport('PathUtils');

import { PathUtils } from '../esm/history.js';
export default PathUtils;
7 changes: 7 additions & 0 deletions es/createBrowserHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

import warnAboutDeprecatedESMImport from './warnAboutDeprecatedESMImport.js';
warnAboutDeprecatedESMImport('createBrowserHistory');

import { createBrowserHistory } from '../esm/history.js';
export default createBrowserHistory;
7 changes: 7 additions & 0 deletions es/createHashHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

import warnAboutDeprecatedESMImport from './warnAboutDeprecatedESMImport.js';
warnAboutDeprecatedESMImport('createHashHistory');

import { createHashHistory } from '../esm/history.js';
export default createHashHistory;
7 changes: 7 additions & 0 deletions es/createMemoryHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

import warnAboutDeprecatedESMImport from './warnAboutDeprecatedESMImport.js';
warnAboutDeprecatedESMImport('createMemoryHistory');

import { createMemoryHistory } from '../esm/history.js';
export default createMemoryHistory;
7 changes: 7 additions & 0 deletions es/createTransitionManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

import warnAboutDeprecatedESMImport from './warnAboutDeprecatedESMImport.js';
warnAboutDeprecatedESMImport('createTransitionManager');

import { createTransitionManager } from '../esm/history.js';
export default createTransitionManager;
35 changes: 35 additions & 0 deletions es/warnAboutDeprecatedESMImport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

var printWarning = function() {};

if (process.env.NODE_ENV !== 'production') {
printWarning = function(format, subs) {
var index = 0;
var message =
'Warning: ' +
(subs.length > 0
? format.replace(/%s/g, function() {
return subs[index++];
})
: format);

if (typeof console !== 'undefined') {
console.error(message);
}

try {
// --- Welcome to debugging history ---
// This error was thrown as a convenience so that you can use the
// stack trace to find the callsite that triggered this warning.
throw new Error(message);
} catch (e) {}
};
}

export default function(member) {
printWarning(
'Please use `import { %s } from "history"` instead of `import %s from "history/es/%s"`. ' +
'Support for the latter will be removed in the next major release.',
[member, member]
);
}
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@
"module": "esm/history.js",
"unpkg": "umd/history.js",
"files": [
"DOMUtils.js",
"ExecutionEnvironment.js",
"LocationUtils.js",
"PathUtils.js",
"cjs",
"createBrowserHistory.js",
"createHashHistory.js",
"createMemoryHistory.js",
"createTransitionManager.js",
"es",
"esm",
"umd"
"umd",
"warnAboutDeprecatedCJSRequire.js"
],
"sideEffects": false,
"scripts": {
Expand Down
35 changes: 35 additions & 0 deletions warnAboutDeprecatedCJSRequire.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

var printWarning = function() {};

if (process.env.NODE_ENV !== 'production') {
printWarning = function(format, subs) {
var index = 0;
var message =
'Warning: ' +
(subs.length > 0
? format.replace(/%s/g, function() {
return subs[index++];
})
: format);

if (typeof console !== 'undefined') {
console.error(message);
}

try {
// --- Welcome to debugging history ---
// This error was thrown as a convenience so that you can use the
// stack trace to find the callsite that triggered this warning.
throw new Error(message);
} catch (e) {}
};
}

module.exports = function(member) {
printWarning(
'Please use `require("history").%s` instead of `require("history/%s")`. ' +
'Support for the latter will be removed in the next major release.',
[member, member]
);
};

0 comments on commit ec0c152

Please sign in to comment.