From 7d7f24c21c85b66c68fca7d492ac78331294c0e0 Mon Sep 17 00:00:00 2001 From: Jelle De Loecker Date: Thu, 5 Oct 2023 18:35:51 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20`Alchemy#findModule()`=20a?= =?UTF-8?q?ssuming=20some=20package=20is=20a=20module=20too=20fast?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ lib/core/middleware.js | 4 ++-- lib/init/alchemy.js | 18 +++++++++++++++--- package.json | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 662ded48..04bf9596 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.3.17 (WIP) + +* Fix `Alchemy#findModule()` assuming some package is a module too fast + ## 1.3.16 (2023-10-05) * Fix `Document#saveRecord()` throwing an error when a related record does not exist diff --git a/lib/core/middleware.js b/lib/core/middleware.js index 26eb8c89..8b7dd0a6 100644 --- a/lib/core/middleware.js +++ b/lib/core/middleware.js @@ -311,7 +311,7 @@ Alchemy.setMethod(function sourcemapMiddleware(req, res, nextMiddleware) { * * @author Jelle De Loecker * @since 0.2.0 - * @version 1.3.4 + * @version 1.3.17 * * @param {String} path * @param {Object} options @@ -418,7 +418,7 @@ Alchemy.setMethod(function minifyScript(path, options, callback) { } } - if (should_minify) { + if (should_minify && typeof Terser?.minify == 'function') { // Force Blast.isNode & Blast.isBrowser to be replaced later data = data.replaceAll('Blast.isNode', '__BLAST_IS_NODE'); diff --git a/lib/init/alchemy.js b/lib/init/alchemy.js index 3eadc60f..98e7d7fb 100644 --- a/lib/init/alchemy.js +++ b/lib/init/alchemy.js @@ -1051,7 +1051,7 @@ Alchemy.setMethod(function searchModule(startPath, moduleName, recurse) { * * @author Jelle De Loecker * @since 0.0.1 - * @version 1.3.16 + * @version 1.3.17 * * @param {String} moduleName * @param {Object} options @@ -1183,10 +1183,22 @@ Alchemy.setMethod(function findModule(moduleName, options) { // Make sure this does not support CJS. // Some packages have the `module` type, but do have CJS exports too if (!supports_cjs) { - let exports = package_json.exports?.['.']; - if (exports?.require) { + if (package_json.module && package_json.main) { supports_cjs = true; + } else { + + let exports = package_json.exports?.['.']; + + if (Array.isArray(exports)) { + for (let entry of exports) { + if (entry && typeof entry == 'object' && entry.require) { + supports_cjs = true; + } + } + } else if (exports?.require) { + supports_cjs = true; + } } } diff --git a/package.json b/package.json index 776c464e..7e76068b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "alchemymvc", "description": "MVC framework for Node.js", - "version": "1.3.16", + "version": "1.3.17-alpha", "author": "Jelle De Loecker ", "keywords": [ "alchemy",