From 298682795414b07c9b17cd7ab8c8dfbb3a602ac1 Mon Sep 17 00:00:00 2001 From: konard Date: Wed, 10 Sep 2025 08:00:32 +0300 Subject: [PATCH 1/3] Initial commit with task details for issue #15 Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: https://github.com/link-foundation/use-m/issues/15 --- CLAUDE.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..4329d29 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,5 @@ +Issue to solve: https://github.com/link-foundation/use-m/issues/15 +Your prepared branch: issue-15-6f3473cd +Your prepared working directory: /tmp/gh-issue-solver-1757480429977 + +Proceed. \ No newline at end of file From dbad444e5d94fa9c488b43263736875952f5411f Mon Sep 17 00:00:00 2001 From: konard Date: Wed, 10 Sep 2025 08:00:48 +0300 Subject: [PATCH 2/3] Remove CLAUDE.md - PR created successfully --- CLAUDE.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index 4329d29..0000000 --- a/CLAUDE.md +++ /dev/null @@ -1,5 +0,0 @@ -Issue to solve: https://github.com/link-foundation/use-m/issues/15 -Your prepared branch: issue-15-6f3473cd -Your prepared working directory: /tmp/gh-issue-solver-1757480429977 - -Proceed. \ No newline at end of file From 8c78bbeeab4e57f5209be1d090f0b148bbdb56ba Mon Sep 17 00:00:00 2001 From: konard Date: Wed, 10 Sep 2025 08:14:17 +0300 Subject: [PATCH 3/3] Enhance default export handling to return .default by default for main APIs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Addresses GitHub issue #15: "It may be a good idea to return .default by default" - Adds intelligent heuristic to return default export for packages like axios where the default export is the primary API - Preserves existing behavior for packages with named exports that users commonly destructure (e.g., command-stream with $, sh) - Maintains backwards compatibility with existing code - All existing tests continue to pass Examples of improved behavior: - axios: `const axios = await use('axios')` now works (was: `(await use('axios')).default`) - lodash: `const _ = await use('lodash')` still works the same way - command-stream: `const { $ } = await use('command-stream')` still works 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- use.cjs | 17 ++++++++++++++++- use.js | 17 ++++++++++++++++- use.mjs | 17 ++++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/use.cjs b/use.cjs index 3917be3..566bc4f 100644 --- a/use.cjs +++ b/use.cjs @@ -618,7 +618,7 @@ const baseUse = async (modulePath) => { // More robust default export handling for cross-environment compatibility const keys = Object.keys(module); - // If it's a Module object with a default property, unwrap it + // If it's a Module object with a default property, decide whether to unwrap it if (module.default !== undefined) { // Check if this is likely a CommonJS module with only default export if (keys.length === 1 && keys[0] === 'default') { @@ -638,6 +638,21 @@ const baseUse = async (modulePath) => { if (nonMetadataKeys.length === 0) { return module.default; } + + // Enhanced heuristic: Return default export for packages that primarily export through default + // but are commonly used as their default export (like http clients, main APIs, etc.) + if (typeof module.default === 'function') { + // If there are many utility exports but the default seems to be the main API, + // and the module doesn't export things users typically destructure (like $, sh, cli tools) + const hasCommonDestructuredExports = nonMetadataKeys.some(key => + /^(\$|sh|cli|cmd|exec|run|create|make|build|test)$/i.test(key) + ); + + // Return default if it's a function and there are no common destructured exports + if (!hasCommonDestructuredExports) { + return module.default; + } + } } // Return the whole module if it has multiple meaningful exports or no default diff --git a/use.js b/use.js index c2dcb3b..db67b1d 100644 --- a/use.js +++ b/use.js @@ -618,7 +618,7 @@ const baseUse = async (modulePath) => { // More robust default export handling for cross-environment compatibility const keys = Object.keys(module); - // If it's a Module object with a default property, unwrap it + // If it's a Module object with a default property, decide whether to unwrap it if (module.default !== undefined) { // Check if this is likely a CommonJS module with only default export if (keys.length === 1 && keys[0] === 'default') { @@ -638,6 +638,21 @@ const baseUse = async (modulePath) => { if (nonMetadataKeys.length === 0) { return module.default; } + + // Enhanced heuristic: Return default export for packages that primarily export through default + // but are commonly used as their default export (like http clients, main APIs, etc.) + if (typeof module.default === 'function') { + // If there are many utility exports but the default seems to be the main API, + // and the module doesn't export things users typically destructure (like $, sh, cli tools) + const hasCommonDestructuredExports = nonMetadataKeys.some(key => + /^(\$|sh|cli|cmd|exec|run|create|make|build|test)$/i.test(key) + ); + + // Return default if it's a function and there are no common destructured exports + if (!hasCommonDestructuredExports) { + return module.default; + } + } } // Return the whole module if it has multiple meaningful exports or no default diff --git a/use.mjs b/use.mjs index 250fe81..478dc45 100644 --- a/use.mjs +++ b/use.mjs @@ -618,7 +618,7 @@ export const baseUse = async (modulePath) => { // More robust default export handling for cross-environment compatibility const keys = Object.keys(module); - // If it's a Module object with a default property, unwrap it + // If it's a Module object with a default property, decide whether to unwrap it if (module.default !== undefined) { // Check if this is likely a CommonJS module with only default export if (keys.length === 1 && keys[0] === 'default') { @@ -638,6 +638,21 @@ export const baseUse = async (modulePath) => { if (nonMetadataKeys.length === 0) { return module.default; } + + // Enhanced heuristic: Return default export for packages that primarily export through default + // but are commonly used as their default export (like http clients, main APIs, etc.) + if (typeof module.default === 'function') { + // If there are many utility exports but the default seems to be the main API, + // and the module doesn't export things users typically destructure (like $, sh, cli tools) + const hasCommonDestructuredExports = nonMetadataKeys.some(key => + /^(\$|sh|cli|cmd|exec|run|create|make|build|test)$/i.test(key) + ); + + // Return default if it's a function and there are no common destructured exports + if (!hasCommonDestructuredExports) { + return module.default; + } + } } // Return the whole module if it has multiple meaningful exports or no default