From fc84c39ca2187129b10ad183aea2da7582660a50 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Wed, 29 Apr 2020 14:02:17 +0200 Subject: [PATCH 1/2] feat: remove deep requires 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 | 7 +++++ README_js.md | 7 +++++ 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, 14 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..b70db986 100644 --- a/README.md +++ b/README.md @@ -363,6 +363,13 @@ 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 + +### 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..dafefc16 100644 --- a/README_js.md +++ b/README_js.md @@ -353,6 +353,13 @@ 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 + +### 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.", -); From ab07f75d022ce0ac7b33e5415e9d8fd2a2132f4e Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Wed, 29 Apr 2020 14:09:02 +0200 Subject: [PATCH 2/2] docs: document native Node.js ESM pitfalls --- README.md | 20 ++++++++++++++++++++ README_js.md | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/README.md b/README.md index b70db986..c550e2ec 100644 --- a/README.md +++ b/README.md @@ -365,6 +365,26 @@ 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 diff --git a/README_js.md b/README_js.md index dafefc16..b0442aa0 100644 --- a/README_js.md +++ b/README_js.md @@ -355,6 +355,26 @@ 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