From 8acbe6d8e8ca6b5769c917ae6f433cd11ecfdb40 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 6 Sep 2023 12:12:14 +0200 Subject: [PATCH 1/2] esm: fix loading of CJS modules from ESM PR-URL: https://github.com/nodejs/node/pull/49500 Fixes: https://github.com/nodejs/node/issues/49497 Reviewed-By: Stephen Belanger Reviewed-By: Benjamin Gruenbaum Reviewed-By: Jacob Smith --- lib/internal/modules/esm/translators.js | 3 ++- test/es-module/test-esm-recursive-cjs-dependencies.mjs | 7 +++++++ test/fixtures/recursive-a.cjs | 6 ++++++ test/fixtures/recursive-b.cjs | 3 +++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/es-module/test-esm-recursive-cjs-dependencies.mjs create mode 100644 test/fixtures/recursive-a.cjs create mode 100644 test/fixtures/recursive-b.cjs diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js index c0125cd84c37c0..80228e895fafcf 100644 --- a/lib/internal/modules/esm/translators.js +++ b/lib/internal/modules/esm/translators.js @@ -279,7 +279,8 @@ translators.set('commonjs', async function commonjsStrategy(url, source, // obtained by calling the monkey-patchable CJS loader. const cjsLoader = source == null ? (module, source, url, filename) => { try { - module.load(filename); + assert(module === CJSModule._cache[filename]); + CJSModule._load(filename); } catch (err) { enrichCJSError(err, source, url); throw err; diff --git a/test/es-module/test-esm-recursive-cjs-dependencies.mjs b/test/es-module/test-esm-recursive-cjs-dependencies.mjs new file mode 100644 index 00000000000000..d75f0fae95df6c --- /dev/null +++ b/test/es-module/test-esm-recursive-cjs-dependencies.mjs @@ -0,0 +1,7 @@ +import '../common/index.mjs'; +import { strictEqual } from 'node:assert'; + +import '../fixtures/recursive-a.cjs'; + +strictEqual(global.counter, 1); +delete global.counter; diff --git a/test/fixtures/recursive-a.cjs b/test/fixtures/recursive-a.cjs new file mode 100644 index 00000000000000..a60c0a635ddf6e --- /dev/null +++ b/test/fixtures/recursive-a.cjs @@ -0,0 +1,6 @@ +'use strict'; + +global.counter ??= 0; +global.counter++; + +require('./recursive-b.cjs'); diff --git a/test/fixtures/recursive-b.cjs b/test/fixtures/recursive-b.cjs new file mode 100644 index 00000000000000..e9f0b5d0701b69 --- /dev/null +++ b/test/fixtures/recursive-b.cjs @@ -0,0 +1,3 @@ +'use strict'; + +require('./recursive-a.cjs'); From d2c7c367741bdcb6f7f77f55ce95a745f0b29fef Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Thu, 7 Sep 2023 09:31:16 -0300 Subject: [PATCH 2/2] 2023-09-08, Version 20.6.1 (Current) Notable changes: esm: * fix loading of CJS modules from ESM (Antoine du Hamel) https://github.com/nodejs/node/pull/49500 PR-URL: https://github.com/nodejs/node/pull/49528 --- CHANGELOG.md | 3 ++- doc/changelogs/CHANGELOG_V20.md | 9 +++++++++ src/node_version.h | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb99cb87318807..c30394031a0b8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,8 @@ release. -20.6.0
+20.6.1
+20.6.0
20.5.1
20.5.0
20.4.0
diff --git a/doc/changelogs/CHANGELOG_V20.md b/doc/changelogs/CHANGELOG_V20.md index a30029285dfa6b..dbd3fd45090926 100644 --- a/doc/changelogs/CHANGELOG_V20.md +++ b/doc/changelogs/CHANGELOG_V20.md @@ -8,6 +8,7 @@ +20.6.1
20.6.0
20.5.1
20.5.0
@@ -43,6 +44,14 @@ * [io.js](CHANGELOG_IOJS.md) * [Archive](CHANGELOG_ARCHIVE.md) + + +## 2023-09-08, Version 20.6.1 (Current), @RafaelGSS + +### Commits + +* \[[`8acbe6d8e8`](https://github.com/nodejs/node/commit/8acbe6d8e8)] - **esm**: fix loading of CJS modules from ESM (Antoine du Hamel) [#49500](https://github.com/nodejs/node/pull/49500) + ## 2023-09-04, Version 20.6.0 (Current), @juanarbol prepared by @UlisesGascon diff --git a/src/node_version.h b/src/node_version.h index f5c9406d949c86..e9e4ca7520d762 100644 --- a/src/node_version.h +++ b/src/node_version.h @@ -29,7 +29,7 @@ #define NODE_VERSION_IS_LTS 0 #define NODE_VERSION_LTS_CODENAME "" -#define NODE_VERSION_IS_RELEASE 0 +#define NODE_VERSION_IS_RELEASE 1 #ifndef NODE_STRINGIFY #define NODE_STRINGIFY(n) NODE_STRINGIFY_HELPER(n)