Skip to content

Commit

Permalink
🐛 Fix Alchemy#findModule() assuming some package is a module too fast
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Oct 5, 2023
1 parent 12b58a1 commit 7d7f24c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/core/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ Alchemy.setMethod(function sourcemapMiddleware(req, res, nextMiddleware) {
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.2.0
* @version 1.3.4
* @version 1.3.17
*
* @param {String} path
* @param {Object} options
Expand Down Expand Up @@ -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');
Expand Down
18 changes: 15 additions & 3 deletions lib/init/alchemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ Alchemy.setMethod(function searchModule(startPath, moduleName, recurse) {
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.0.1
* @version 1.3.16
* @version 1.3.17
*
* @param {String} moduleName
* @param {Object} options
Expand Down Expand Up @@ -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;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <jelle@elevenways.be>",
"keywords": [
"alchemy",
Expand Down

0 comments on commit 7d7f24c

Please sign in to comment.