Skip to content

Commit

Permalink
fix: make deep require deprecation warning work in browsers
Browse files Browse the repository at this point in the history
Relates to #408
  • Loading branch information
ctavan committed Mar 30, 2020
1 parent 8977966 commit 48b30cc
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
20 changes: 20 additions & 0 deletions deprecate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Extracted from: https://github.com/TooTallNate/util-deprecate
let deprecate;
try {
const util = require('util');
deprecate = util.deprecate;
} catch (err) {
deprecate = function deprecate(fn, msg) {
var warned = false;
function deprecated() {
if (!warned) {
console.warn(msg);
warned = true;
}
return fn.apply(this, arguments);
}

return deprecated;
};
}
module.exports = deprecate;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"CONTRIBUTING.md",
"LICENSE.md",
"README.md",
"deprecate.js",
"dist",
"v1.js",
"v3.js",
Expand Down
4 changes: 2 additions & 2 deletions v1.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const util = require('util');
const deprecate = require('./deprecate.js');

const v1 = require('./dist/v1.js');

module.exports = util.deprecate(
module.exports = deprecate(
v1,
"Deep requiring like `const uuidv1 = require('uuid/v1');` is deprecated as of [email protected]. Please require the top-level module when using the Node.js CommonJS module or use ECMAScript Modules when bundling for the browser. See https://github.com/uuidjs/uuid#deep-requires-now-deprecated for more information.",
);
4 changes: 2 additions & 2 deletions v3.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const util = require('util');
const deprecate = require('./deprecate.js');

const v3 = require('./dist/v3.js');

module.exports = util.deprecate(
module.exports = deprecate(
v3,
"Deep requiring like `const uuidv3 = require('uuid/v3');` is deprecated as of [email protected]. Please require the top-level module when using the Node.js CommonJS module or use ECMAScript Modules when bundling for the browser. See https://github.com/uuidjs/uuid#deep-requires-now-deprecated for more information.",
);
4 changes: 2 additions & 2 deletions v4.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const util = require('util');
const deprecate = require('./deprecate.js');

const v4 = require('./dist/v4.js');

module.exports = util.deprecate(
module.exports = deprecate(
v4,
"Deep requiring like `const uuidv4 = require('uuid/v4');` is deprecated as of [email protected]. Please require the top-level module when using the Node.js CommonJS module or use ECMAScript Modules when bundling for the browser. See https://github.com/uuidjs/uuid#deep-requires-now-deprecated for more information.",
);
4 changes: 2 additions & 2 deletions v5.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const util = require('util');
const deprecate = require('./deprecate.js');

const v5 = require('./dist/v5.js');

module.exports = util.deprecate(
module.exports = deprecate(
v5,
"Deep requiring like `const uuidv5 = require('uuid/v5');` is deprecated as of [email protected]. Please require the top-level module when using the Node.js CommonJS module or use ECMAScript Modules when bundling for the browser. See https://github.com/uuidjs/uuid#deep-requires-now-deprecated for more information.",
);

0 comments on commit 48b30cc

Please sign in to comment.