From daf72b84ceb20272a81bb5fbddb05dd95922cbba Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Wed, 29 Apr 2020 21:57:24 +0200 Subject: [PATCH] feat: remove deep requires (#426) BREAKING CHANGE: Deep requiring specific algorithms of this library like require('uuid/v4'), which has been deprecated in uuid@7, is no longer supported. Instead use the named exports that this module exports. For ECMAScript Modules (ESM): ```javascript import { v4 as uuidv4 } from 'uuid'; uuidv4(); ``` For CommonJS: ```javascript const { v4: uuidv4 } = require('uuid'); uuidv4(); ``` No longer supported is this: ```javascript const uuidv4 = require('uuid/v4'); // <== NO LONGER SUPPORTED! uuidv4(); ``` --- README.md | 27 +++++++++++++++++ README_js.md | 27 +++++++++++++++++ deprecate.js | 20 ------------- package.json | 5 ---- test/unit/deep-require-deprecation.test.js | 35 ---------------------- v1.js | 8 ----- v3.js | 8 ----- v4.js | 8 ----- v5.js | 8 ----- 9 files changed, 54 insertions(+), 92 deletions(-) delete mode 100644 deprecate.js delete mode 100644 test/unit/deep-require-deprecation.test.js delete mode 100644 v1.js delete mode 100644 v3.js delete mode 100644 v4.js delete mode 100644 v5.js diff --git a/README.md b/README.md index 7f6958b4..c550e2ec 100644 --- a/README.md +++ b/README.md @@ -363,6 +363,33 @@ import { v4 as uuidv4 } from 'uuid'; Workers](https://caniuse.com/#feat=cryptography) and we are not aware of a polyfill (let us know if you find one, please). +## Upgrading From uuid\@7 + +### Only Named Exports Supported When Using with Node.js ESM + +uuid\@7 did not come with native ECMAScript Module (ESM) support for Node.js. Importing it in +Node.js ESM consequently imported the CommonJS source with a default export. This library now comes +with true Node.js ESM support and only provides named exports. + +Instead of doing: + +```javascript +import uuid from 'uuid'; +uuid.v4(); +``` + +you will now have to use the named exports: + +```javascript +import { v4 as uuidv4 } from 'uuid'; +uuidv4(); +``` + +### Deep Requires No Longer Supported + +Deep requires like `require('uuid/v4')` [which have been deprecated in +uuid\@7](#deep-requires-now-deprecated) are no longer supported. + ## Upgrading From uuid\@3 "_Wait... what happened to uuid\@4 - uuid\@6?!?_" diff --git a/README_js.md b/README_js.md index 9ad030a7..b0442aa0 100644 --- a/README_js.md +++ b/README_js.md @@ -353,6 +353,33 @@ import { v4 as uuidv4 } from 'uuid'; Workers](https://caniuse.com/#feat=cryptography) and we are not aware of a polyfill (let us know if you find one, please). +## Upgrading From uuid\@7 + +### Only Named Exports Supported When Using with Node.js ESM + +uuid\@7 did not come with native ECMAScript Module (ESM) support for Node.js. Importing it in +Node.js ESM consequently imported the CommonJS source with a default export. This library now comes +with true Node.js ESM support and only provides named exports. + +Instead of doing: + +```javascript +import uuid from 'uuid'; +uuid.v4(); +``` + +you will now have to use the named exports: + +```javascript +import { v4 as uuidv4 } from 'uuid'; +uuidv4(); +``` + +### Deep Requires No Longer Supported + +Deep requires like `require('uuid/v4')` [which have been deprecated in +uuid\@7](#deep-requires-now-deprecated) are no longer supported. + ## Upgrading From uuid\@3 "_Wait... what happened to uuid\@4 - uuid\@6?!?_" diff --git a/deprecate.js b/deprecate.js deleted file mode 100644 index e5ae400b..00000000 --- a/deprecate.js +++ /dev/null @@ -1,20 +0,0 @@ -// 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; diff --git a/package.json b/package.json index 124d8999..8f8add3a 100644 --- a/package.json +++ b/package.json @@ -34,12 +34,7 @@ "CONTRIBUTING.md", "LICENSE.md", "README.md", - "deprecate.js", "dist", - "v1.js", - "v3.js", - "v4.js", - "v5.js", "wrapper.mjs" ], "devDependencies": { diff --git a/test/unit/deep-require-deprecation.test.js b/test/unit/deep-require-deprecation.test.js deleted file mode 100644 index 32ac626a..00000000 --- a/test/unit/deep-require-deprecation.test.js +++ /dev/null @@ -1,35 +0,0 @@ -const assert = require('assert'); - -describe('deprecate deep require', () => { - function assertDeprecation(doRequire) { - return () => { - const uuid = doRequire(); - try { - uuid(); - assert(false); // ensure this line is never reached - } catch (error) { - assert.strictEqual(error.name, 'DeprecationWarning'); - } - }; - } - - test( - 'v1', - assertDeprecation(() => require('../../v1')), - ); - - test( - 'v3', - assertDeprecation(() => require('../../v3')), - ); - - test( - 'v4', - assertDeprecation(() => require('../../v4')), - ); - - test( - 'v5', - assertDeprecation(() => require('../../v5')), - ); -}); diff --git a/v1.js b/v1.js deleted file mode 100644 index 22660e52..00000000 --- a/v1.js +++ /dev/null @@ -1,8 +0,0 @@ -const deprecate = require('./deprecate.js'); - -const { default: v1 } = require('./dist/v1.js'); - -module.exports = deprecate( - v1, - "Deep requiring like `const uuidv1 = require('uuid/v1');` is deprecated as of uuid@7.x. 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.", -); diff --git a/v3.js b/v3.js deleted file mode 100644 index 758fd6d3..00000000 --- a/v3.js +++ /dev/null @@ -1,8 +0,0 @@ -const deprecate = require('./deprecate.js'); - -const { default: v3 } = require('./dist/v3.js'); - -module.exports = deprecate( - v3, - "Deep requiring like `const uuidv3 = require('uuid/v3');` is deprecated as of uuid@7.x. 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.", -); diff --git a/v4.js b/v4.js deleted file mode 100644 index 3ee74689..00000000 --- a/v4.js +++ /dev/null @@ -1,8 +0,0 @@ -const deprecate = require('./deprecate.js'); - -const { default: v4 } = require('./dist/v4.js'); - -module.exports = deprecate( - v4, - "Deep requiring like `const uuidv4 = require('uuid/v4');` is deprecated as of uuid@7.x. 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.", -); diff --git a/v5.js b/v5.js deleted file mode 100644 index a8906f81..00000000 --- a/v5.js +++ /dev/null @@ -1,8 +0,0 @@ -const deprecate = require('./deprecate.js'); - -const { default: v5 } = require('./dist/v5.js'); - -module.exports = deprecate( - v5, - "Deep requiring like `const uuidv5 = require('uuid/v5');` is deprecated as of uuid@7.x. 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.", -);