From 02a7bfe4fea9edc5ff131be798e7c61f5b17d3cc Mon Sep 17 00:00:00 2001 From: eastagiletracker <310448263+eastagiletracker@users.noreply.github.com> Date: Thu, 13 Aug 2026 18:13:32 +0700 Subject: [PATCH] Fix the package entry point failing to load under Node ESM src/plugins/shareIntoApp.ts imported '../utils/listener' without a file extension, so dist/plugins/shareIntoApp.js carries the same specifier and Node's ESM resolver, which does no extension guessing, fails the whole entry graph with ERR_MODULE_NOT_FOUND. Every other module already uses an explicit .js specifier. Restore it here, and on the type-only import in msdynamics.ts that is erased at build time today. Add a test that imports the built dist/index.js through the real ESM loader, which is the check that was missing when this regressed. --- src/plugins/msdynamics.ts | 2 +- src/plugins/shareIntoApp.ts | 2 +- test/bundle.test.js | 47 +++++++++++++++++++++++++------------ 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/plugins/msdynamics.ts b/src/plugins/msdynamics.ts index dd34c68..17d8b9d 100644 --- a/src/plugins/msdynamics.ts +++ b/src/plugins/msdynamics.ts @@ -1,4 +1,4 @@ -import { DeviceInfo } from '../commands/general'; +import { DeviceInfo } from '../commands/general.js'; import { CallbackData, CallbackParams, PermissionStatusData } from '../types/index.js'; import { addCommandCallback } from '../utils/index.js'; diff --git a/src/plugins/shareIntoApp.ts b/src/plugins/shareIntoApp.ts index 0f936c2..cf0d910 100644 --- a/src/plugins/shareIntoApp.ts +++ b/src/plugins/shareIntoApp.ts @@ -1,4 +1,4 @@ -import { createListener } from '../utils/listener'; +import { createListener } from '../utils/listener.js'; export type ShareToAppData = { url: string; subject: string }; diff --git a/test/bundle.test.js b/test/bundle.test.js index 9546af6..d4998fb 100644 --- a/test/bundle.test.js +++ b/test/bundle.test.js @@ -1,12 +1,15 @@ /** - * Basic test to verify the rollup IIFE bundle exports Median correctly. + * Basic test to verify the rollup IIFE bundle exports Median correctly, + * and that the package entry point loads for npm consumers. * Run with: npm test */ const fs = require('fs'); const path = require('path'); +const { pathToFileURL } = require('url'); const bundlePath = path.join(__dirname, '../dist/median.min.js'); +const entryPath = path.join(__dirname, '../dist/index.js'); // Check bundle exists if (!fs.existsSync(bundlePath)) { @@ -43,6 +46,16 @@ const tests = [ { name: 'Median.appResumed exists', check: () => typeof Median.appResumed === 'object' }, { name: 'Median.appResumed.addListener is function', check: () => typeof Median.appResumed?.addListener === 'function' }, { name: 'Median.jsNavigation exists', check: () => typeof Median.jsNavigation === 'object' }, + + // Package entry point โ€” Node's ESM resolver does no extension guessing, so a + // relative import emitted without `.js` fails the whole graph for npm users. + { + name: 'dist/index.js resolves through the Node ESM loader', + check: async () => { + const module = await import(pathToFileURL(entryPath).href); + return typeof module.default === 'object' && typeof module.default.shareIntoApp === 'object'; + }, + }, ]; let passed = 0; @@ -50,23 +63,27 @@ let failed = 0; console.log('\n๐Ÿงช Testing Median IIFE bundle...\n'); -for (const test of tests) { - try { - if (test.check()) { - console.log(` โœ… ${test.name}`); - passed++; - } else { - console.log(` โŒ ${test.name}`); +async function run() { + for (const test of tests) { + try { + if (await test.check()) { + console.log(` โœ… ${test.name}`); + passed++; + } else { + console.log(` โŒ ${test.name}`); + failed++; + } + } catch (err) { + console.log(` โŒ ${test.name} (Error: ${err.message})`); failed++; } - } catch (err) { - console.log(` โŒ ${test.name} (Error: ${err.message})`); - failed++; } -} -console.log(`\n๐Ÿ“Š Results: ${passed} passed, ${failed} failed\n`); + console.log(`\n๐Ÿ“Š Results: ${passed} passed, ${failed} failed\n`); -if (failed > 0) { - process.exit(1); + if (failed > 0) { + process.exit(1); + } } + +run();