diff --git a/DOMUtils.js b/DOMUtils.js new file mode 100644 index 000000000..c4f93d31a --- /dev/null +++ b/DOMUtils.js @@ -0,0 +1,3 @@ +'use strict'; +require('./warnAboutDeprecatedCJSRequire.js')('DOMUtils'); +module.exports = require('./index.js').DOMUtils; diff --git a/ExecutionEnvironment.js b/ExecutionEnvironment.js new file mode 100644 index 000000000..44de3b2f0 --- /dev/null +++ b/ExecutionEnvironment.js @@ -0,0 +1,3 @@ +'use strict'; +require('./warnAboutDeprecatedCJSRequire.js')('ExecutionEnvironment'); +module.exports = require('./index.js').ExecutionEnvironment; diff --git a/LocationUtils.js b/LocationUtils.js new file mode 100644 index 000000000..a86120560 --- /dev/null +++ b/LocationUtils.js @@ -0,0 +1,3 @@ +'use strict'; +require('./warnAboutDeprecatedCJSRequire.js')('LocationUtils'); +module.exports = require('./index.js').LocationUtils; diff --git a/PathUtils.js b/PathUtils.js new file mode 100644 index 000000000..7dc98c205 --- /dev/null +++ b/PathUtils.js @@ -0,0 +1,3 @@ +'use strict'; +require('./warnAboutDeprecatedCJSRequire.js')('PathUtils'); +module.exports = require('./index.js').PathUtils; diff --git a/createBrowserHistory.js b/createBrowserHistory.js new file mode 100644 index 000000000..34f12c399 --- /dev/null +++ b/createBrowserHistory.js @@ -0,0 +1,3 @@ +'use strict'; +require('./warnAboutDeprecatedCJSRequire.js')('createBrowserHistory'); +module.exports = require('./index.js').createBrowserHistory; diff --git a/createHashHistory.js b/createHashHistory.js new file mode 100644 index 000000000..7686422de --- /dev/null +++ b/createHashHistory.js @@ -0,0 +1,3 @@ +'use strict'; +require('./warnAboutDeprecatedCJSRequire.js')('createHashHistory'); +module.exports = require('./index.js').createHashHistory; diff --git a/createMemoryHistory.js b/createMemoryHistory.js new file mode 100644 index 000000000..a0ce3ff40 --- /dev/null +++ b/createMemoryHistory.js @@ -0,0 +1,3 @@ +'use strict'; +require('./warnAboutDeprecatedCJSRequire.js')('createMemoryHistory'); +module.exports = require('./index.js').createMemoryHistory; diff --git a/createTransitionManager.js b/createTransitionManager.js new file mode 100644 index 000000000..f8cf2f6b7 --- /dev/null +++ b/createTransitionManager.js @@ -0,0 +1,3 @@ +'use strict'; +require('./warnAboutDeprecatedCJSRequire.js')('createTransitionManager'); +module.exports = require('./index.js').createTransitionManager; diff --git a/es/DOMUtils.js b/es/DOMUtils.js new file mode 100644 index 000000000..265a991c4 --- /dev/null +++ b/es/DOMUtils.js @@ -0,0 +1,7 @@ +'use strict'; + +import warnAboutDeprecatedESMImport from './warnAboutDeprecatedESMImport.js'; +warnAboutDeprecatedESMImport('DOMUtils'); + +import { DOMUtils } from '../esm/history.js'; +export default DOMUtils; diff --git a/es/ExecutionEnvironment.js b/es/ExecutionEnvironment.js new file mode 100644 index 000000000..9043609bc --- /dev/null +++ b/es/ExecutionEnvironment.js @@ -0,0 +1,7 @@ +'use strict'; + +import warnAboutDeprecatedESMImport from './warnAboutDeprecatedESMImport.js'; +warnAboutDeprecatedESMImport('ExecutionEnvironment'); + +import { ExecutionEnvironment } from '../esm/history.js'; +export default ExecutionEnvironment; diff --git a/es/LocationUtils.js b/es/LocationUtils.js new file mode 100644 index 000000000..3dc1816b6 --- /dev/null +++ b/es/LocationUtils.js @@ -0,0 +1,7 @@ +'use strict'; + +import warnAboutDeprecatedESMImport from './warnAboutDeprecatedESMImport.js'; +warnAboutDeprecatedESMImport('LocationUtils'); + +import { LocationUtils } from '../esm/history.js'; +export default LocationUtils; diff --git a/es/PathUtils.js b/es/PathUtils.js new file mode 100644 index 000000000..7414d2662 --- /dev/null +++ b/es/PathUtils.js @@ -0,0 +1,7 @@ +'use strict'; + +import warnAboutDeprecatedESMImport from './warnAboutDeprecatedESMImport.js'; +warnAboutDeprecatedESMImport('PathUtils'); + +import { PathUtils } from '../esm/history.js'; +export default PathUtils; diff --git a/es/createBrowserHistory.js b/es/createBrowserHistory.js new file mode 100644 index 000000000..c05b10528 --- /dev/null +++ b/es/createBrowserHistory.js @@ -0,0 +1,7 @@ +'use strict'; + +import warnAboutDeprecatedESMImport from './warnAboutDeprecatedESMImport.js'; +warnAboutDeprecatedESMImport('createBrowserHistory'); + +import { createBrowserHistory } from '../esm/history.js'; +export default createBrowserHistory; diff --git a/es/createHashHistory.js b/es/createHashHistory.js new file mode 100644 index 000000000..ff40c25b8 --- /dev/null +++ b/es/createHashHistory.js @@ -0,0 +1,7 @@ +'use strict'; + +import warnAboutDeprecatedESMImport from './warnAboutDeprecatedESMImport.js'; +warnAboutDeprecatedESMImport('createHashHistory'); + +import { createHashHistory } from '../esm/history.js'; +export default createHashHistory; diff --git a/es/createMemoryHistory.js b/es/createMemoryHistory.js new file mode 100644 index 000000000..1cc4caab4 --- /dev/null +++ b/es/createMemoryHistory.js @@ -0,0 +1,7 @@ +'use strict'; + +import warnAboutDeprecatedESMImport from './warnAboutDeprecatedESMImport.js'; +warnAboutDeprecatedESMImport('createMemoryHistory'); + +import { createMemoryHistory } from '../esm/history.js'; +export default createMemoryHistory; diff --git a/es/createTransitionManager.js b/es/createTransitionManager.js new file mode 100644 index 000000000..37d454068 --- /dev/null +++ b/es/createTransitionManager.js @@ -0,0 +1,7 @@ +'use strict'; + +import warnAboutDeprecatedESMImport from './warnAboutDeprecatedESMImport.js'; +warnAboutDeprecatedESMImport('createTransitionManager'); + +import { createTransitionManager } from '../esm/history.js'; +export default createTransitionManager; diff --git a/es/warnAboutDeprecatedESMImport.js b/es/warnAboutDeprecatedESMImport.js new file mode 100644 index 000000000..8215fb286 --- /dev/null +++ b/es/warnAboutDeprecatedESMImport.js @@ -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] + ); +} diff --git a/package.json b/package.json index 6fd285841..12516580d 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/warnAboutDeprecatedCJSRequire.js b/warnAboutDeprecatedCJSRequire.js new file mode 100644 index 000000000..39578596b --- /dev/null +++ b/warnAboutDeprecatedCJSRequire.js @@ -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] + ); +};