From e46176a7cfce5018cfce2e2eefa94bca65fbf01e Mon Sep 17 00:00:00 2001 From: Mradul Singh Date: Sat, 14 Nov 2026 00:45:35 +0530 Subject: [PATCH 1/4] fix(mcp): load the import entry of an engine with separate import and require exports resolveEntry resolved the package with createRequire().resolve, which uses the require conditions, and only read the import entry when that threw ERR_PACKAGE_PATH_NOT_EXPORTED. The entry is then loaded with import(), so a package exporting both entries gave the require one. Read the import target from exports first; keep require resolution for packages whose exports give no import target or that have no exports. Fixes #1758 --- .changeset/mcp-engine-import-entry.md | 5 +++++ packages/e2e/src/mcp/default-engine.ts | 13 ++++++++----- packages/e2e/tests/unit/mcp-default-engine.test.ts | 11 +++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 .changeset/mcp-engine-import-entry.md diff --git a/.changeset/mcp-engine-import-entry.md b/.changeset/mcp-engine-import-entry.md new file mode 100644 index 0000000000..3e0608f7be --- /dev/null +++ b/.changeset/mcp-engine-import-entry.md @@ -0,0 +1,5 @@ +--- +"e2e": patch +--- + +`open_session` loads the `import` entry of an engine package that exports separate `import` and `require` entries, as `import()` would, instead of the `require` one. diff --git a/packages/e2e/src/mcp/default-engine.ts b/packages/e2e/src/mcp/default-engine.ts index 4931780300..21d203384b 100644 --- a/packages/e2e/src/mcp/default-engine.ts +++ b/packages/e2e/src/mcp/default-engine.ts @@ -156,12 +156,15 @@ function resolveEntry(name: string, lookup: EngineLookup, role: 'engine' | 'opti const directory = installedAt(installable, root); if (directory === undefined) continue; try { - // The file need not exist: it only says which node_modules directories to walk. - return createRequire(path.join(root, 'package.json')).resolve(name); + // The entry is loaded with `import()`, so the `import` entry wins over the one `require` conditions pick. + const imported = importEntry(directory, name.slice(installable.length)); + if (imported === undefined) { + // The file need not exist: it only says which node_modules directories to walk. + return createRequire(path.join(root, 'package.json')).resolve(name); + } + if (!existsSync(imported)) throw new Error(`Cannot find module '${imported}'`); + return imported; } catch (cause) { - // `require` conditions miss an entry a package exports to `import` alone. - const imported = (cause as NodeJS.ErrnoException).code === 'ERR_PACKAGE_PATH_NOT_EXPORTED' ? importEntry(directory, name.slice(installable.length)) : undefined; - if (imported !== undefined) return imported; throw new ConfigurationError('INVALID_CONFIG', `package ${name} is installed at ${directory} but its entry cannot be resolved: ${errorMessage(cause)}`, { cause }); } } diff --git a/packages/e2e/tests/unit/mcp-default-engine.test.ts b/packages/e2e/tests/unit/mcp-default-engine.test.ts index 3645f4570e..286753877f 100644 --- a/packages/e2e/tests/unit/mcp-default-engine.test.ts +++ b/packages/e2e/tests/unit/mcp-default-engine.test.ts @@ -49,6 +49,17 @@ describe('loadEngine', () => { expect(await loadEngine({ package: 'esm-only/web' }, lookup)).toMatchObject({ name: 'from-subpath' }); }); + it('loads the import entry of a package that exports separate import and require entries', async () => { + install(lookup.cwd, 'dual', FACTORY.replace("'fake'", "'from-import'")); + const packageDir = path.join(lookup.cwd, 'node_modules', 'dual'); + const exports = { '.': { types: './index.d.ts', import: './index.js', require: './index.cjs' }, './web': { require: './web.cjs', import: './web.js' } }; + writeFileSync(path.join(packageDir, 'package.json'), JSON.stringify({ name: 'dual', type: 'module', exports })); + writeFileSync(path.join(packageDir, 'web.js'), FACTORY.replace("'fake'", "'from-import'")); + for (const file of ['index.cjs', 'web.cjs']) writeFileSync(path.join(packageDir, file), `module.exports = () => ({ [Symbol.for('e2e.engine.v1')]: true, spiVersion: 1, name: 'from-require' });\n`); + expect(await loadEngine({ package: 'dual' }, lookup)).toMatchObject({ name: 'from-import' }); + expect(await loadEngine({ package: 'dual/web' }, lookup)).toMatchObject({ name: 'from-import' }); + }); + it('makes the factory calls among the options first, so an engine gets a provider JSON cannot carry', async () => { install(lookup.cwd, 'engine', FACTORY); install(lookup.enginesDir, 'cloud', `export const devices = (options) => ({ name: 'cloud', region: options?.region, acquire: () => 'leased' });\n`); From 0f2bdf6e0ba165de93fc08e74600d6e1aa70e73a Mon Sep 17 00:00:00 2001 From: Mradul Singh Date: Sat, 14 Nov 2026 01:07:20 +0530 Subject: [PATCH 2/4] fix(mcp): match wildcard export patterns when picking the import entry A subpath that only a "./*" style exports key matches got no import target, so resolution fell back to require.resolve and loaded the CommonJS file. Match patterns the way Node.js does: longest part before "*" wins, then the longest key, and the matched text replaces every "*" in the target. --- packages/e2e/src/mcp/default-engine.ts | 25 +++++++++++++++++-- .../e2e/tests/unit/mcp-default-engine.test.ts | 19 ++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/packages/e2e/src/mcp/default-engine.ts b/packages/e2e/src/mcp/default-engine.ts index 21d203384b..bd411a43c6 100644 --- a/packages/e2e/src/mcp/default-engine.ts +++ b/packages/e2e/src/mcp/default-engine.ts @@ -191,8 +191,29 @@ function importEntry(directory: string, subpath: string): string | undefined { const exports = typeof manifest === 'object' && manifest !== null && 'exports' in manifest ? manifest.exports : undefined; const key = `.${subpath}`; const keyed = typeof exports === 'object' && exports !== null && !Array.isArray(exports) && Object.keys(exports).some((entry) => entry.startsWith('.')); - const target = importTarget(keyed ? (exports as Record)[key] : key === '.' ? exports : undefined); - return target === undefined ? undefined : path.join(directory, target); + if (!keyed) { + const target = key === '.' ? importTarget(exports) : undefined; + return target === undefined ? undefined : path.join(directory, target); + } + const entries = exports as Record; + if (Object.hasOwn(entries, key) && !key.includes('*')) { + const target = importTarget(entries[key]); + return target === undefined ? undefined : path.join(directory, target); + } + // A `./*` style pattern: Node.js picks the matching key with the longest part before `*`, then the longest key, and puts the matched text in place of every `*` in the target. + let best: { pattern: string; match: string } | undefined; + for (const pattern of Object.keys(entries)) { + const star = pattern.indexOf('*'); + if (star === -1 || star !== pattern.lastIndexOf('*')) continue; + const prefix = pattern.slice(0, star); + const suffix = pattern.slice(star + 1); + if (key.length < pattern.length || !key.startsWith(prefix) || !key.endsWith(suffix)) continue; + if (best !== undefined && (prefix.length < best.pattern.indexOf('*') || (prefix.length === best.pattern.indexOf('*') && pattern.length <= best.pattern.length))) continue; + best = { pattern, match: key.slice(star, key.length - suffix.length) }; + } + if (best === undefined) return undefined; + const target = importTarget(entries[best.pattern]); + return target === undefined ? undefined : path.join(directory, target.replaceAll('*', best.match)); } /** The first target an `import` of this `exports` value selects: a path, or the first matching condition's, in the order written. */ diff --git a/packages/e2e/tests/unit/mcp-default-engine.test.ts b/packages/e2e/tests/unit/mcp-default-engine.test.ts index 286753877f..0f47fc138c 100644 --- a/packages/e2e/tests/unit/mcp-default-engine.test.ts +++ b/packages/e2e/tests/unit/mcp-default-engine.test.ts @@ -60,6 +60,25 @@ describe('loadEngine', () => { expect(await loadEngine({ package: 'dual/web' }, lookup)).toMatchObject({ name: 'from-import' }); }); + it('loads the import entry of a subpath that only a wildcard export pattern matches', async () => { + install(lookup.cwd, 'patterned', FACTORY); + const packageDir = path.join(lookup.cwd, 'node_modules', 'patterned'); + const exports = { + '.': './index.js', + './*': { require: './cjs/*.cjs', import: './esm/*.js' }, + './engines/*': { require: './cjs/engines/*.cjs', import: './esm/engines/*.js' }, + }; + writeFileSync(path.join(packageDir, 'package.json'), JSON.stringify({ name: 'patterned', type: 'module', exports })); + const cjs = (name: string) => `module.exports = () => ({ [Symbol.for('e2e.engine.v1')]: true, spiVersion: 1, name: '${name}' });\n`; + for (const dir of ['esm/engines', 'cjs/engines']) mkdirSync(path.join(packageDir, dir), { recursive: true }); + writeFileSync(path.join(packageDir, 'esm', 'web.js'), FACTORY.replace("'fake'", "'from-import'")); + writeFileSync(path.join(packageDir, 'esm', 'engines', 'kiosk.js'), FACTORY.replace("'fake'", "'from-longest-pattern'")); + writeFileSync(path.join(packageDir, 'cjs', 'web.cjs'), cjs('from-require')); + writeFileSync(path.join(packageDir, 'cjs', 'engines', 'kiosk.cjs'), cjs('from-require')); + expect(await loadEngine({ package: 'patterned/web' }, lookup)).toMatchObject({ name: 'from-import' }); + expect(await loadEngine({ package: 'patterned/engines/kiosk' }, lookup)).toMatchObject({ name: 'from-longest-pattern' }); + }); + it('makes the factory calls among the options first, so an engine gets a provider JSON cannot carry', async () => { install(lookup.cwd, 'engine', FACTORY); install(lookup.enginesDir, 'cloud', `export const devices = (options) => ({ name: 'cloud', region: options?.region, acquire: () => 'leased' });\n`); From 471719ee2a5501d92c50f5273fbe8a6ea572d060 Mon Sep 17 00:00:00 2001 From: Mradul Singh Date: Sat, 14 Nov 2026 04:16:13 +0530 Subject: [PATCH 3/4] fix(mcp): resolve engine export targets the way import() does Follow Node.js's target rules: targets must start with ./ and stay in the package, null excludes, arrays fall back past invalid or null items, module-sync counts as a condition. The entry check moves out of the try so its own catch no longer wraps it. --- .changeset/mcp-engine-import-entry.md | 2 +- packages/e2e/src/mcp/default-engine.ts | 118 +++++++++++++----- .../e2e/tests/unit/mcp-default-engine.test.ts | 37 ++++++ 3 files changed, 123 insertions(+), 34 deletions(-) diff --git a/.changeset/mcp-engine-import-entry.md b/.changeset/mcp-engine-import-entry.md index 3e0608f7be..a426e74558 100644 --- a/.changeset/mcp-engine-import-entry.md +++ b/.changeset/mcp-engine-import-entry.md @@ -2,4 +2,4 @@ "e2e": patch --- -`open_session` loads the `import` entry of an engine package that exports separate `import` and `require` entries, as `import()` would, instead of the `require` one. +`open_session` loads the entry of an engine package that `import()` would load, instead of its `require` entry, and reports an `exports` entry that `import()` refuses instead of loading the `require` one. diff --git a/packages/e2e/src/mcp/default-engine.ts b/packages/e2e/src/mcp/default-engine.ts index bd411a43c6..903ddf7366 100644 --- a/packages/e2e/src/mcp/default-engine.ts +++ b/packages/e2e/src/mcp/default-engine.ts @@ -155,18 +155,16 @@ function resolveEntry(name: string, lookup: EngineLookup, role: 'engine' | 'opti for (const root of [lookup.cwd, path.dirname(fileURLToPath(import.meta.url)), lookup.enginesDir]) { const directory = installedAt(installable, root); if (directory === undefined) continue; + let entry: string; try { // The entry is loaded with `import()`, so the `import` entry wins over the one `require` conditions pick. - const imported = importEntry(directory, name.slice(installable.length)); - if (imported === undefined) { - // The file need not exist: it only says which node_modules directories to walk. - return createRequire(path.join(root, 'package.json')).resolve(name); - } - if (!existsSync(imported)) throw new Error(`Cannot find module '${imported}'`); - return imported; + // The file need not exist: it only says which node_modules directories to walk. + entry = importEntry(directory, name.slice(installable.length)) ?? createRequire(path.join(root, 'package.json')).resolve(name); } catch (cause) { - throw new ConfigurationError('INVALID_CONFIG', `package ${name} is installed at ${directory} but its entry cannot be resolved: ${errorMessage(cause)}`, { cause }); + throw unresolvable(name, directory, errorMessage(cause), cause); } + if (!existsSync(entry)) throw unresolvable(name, directory, `Cannot find module '${entry}'`); + return entry; } // An option is only read as a call by its shape, so the message says how it was read before it names a command. const read = role === 'engine' ? '' : `an option value with only package, export, and options keys is read as a factory call, and `; @@ -176,6 +174,10 @@ function resolveEntry(name: string, lookup: EngineLookup, role: 'engine' | 'opti ); } +function unresolvable(name: string, directory: string, reason: string, cause?: unknown): ConfigurationError { + return new ConfigurationError('INVALID_CONFIG', `package ${name} is installed at ${directory} but its entry cannot be resolved: ${reason}`, { cause }); +} + /** The directory of `name` in the nearest `node_modules` from `root` upward, as Node.js looks a package up. */ function installedAt(name: string, root: string): string | undefined { for (let directory = root; ; directory = path.dirname(directory)) { @@ -185,44 +187,94 @@ function installedAt(name: string, root: string): string | undefined { } } -/** The file `subpath` (`''` for the main entry) of the package at `directory` exports to `import`, when its `exports` names one. */ +/** Conditions Node.js matches for `import()`, besides `default`. */ +const IMPORT_CONDITIONS = new Set(['node', 'import', 'module-sync', 'default']); + +/** A target Node.js refuses: it does not start with `./`, or a segment is empty, `.`, `..` or `node_modules`. */ +class InvalidTarget extends Error {} + +/** + * The file `subpath` (`''` for the main entry) of the package at `directory` exports to `import`, as Node.js resolves it, + * or undefined when `exports` does not name the subpath for `import`, so `require` resolution decides as before. + */ function importEntry(directory: string, subpath: string): string | undefined { const manifest: unknown = JSON.parse(readFileSync(path.join(directory, 'package.json'), 'utf8')); const exports = typeof manifest === 'object' && manifest !== null && 'exports' in manifest ? manifest.exports : undefined; + if (exports === undefined) return undefined; const key = `.${subpath}`; const keyed = typeof exports === 'object' && exports !== null && !Array.isArray(exports) && Object.keys(exports).some((entry) => entry.startsWith('.')); + let resolved: string | null | undefined; if (!keyed) { - const target = key === '.' ? importTarget(exports) : undefined; - return target === undefined ? undefined : path.join(directory, target); - } - const entries = exports as Record; - if (Object.hasOwn(entries, key) && !key.includes('*')) { - const target = importTarget(entries[key]); - return target === undefined ? undefined : path.join(directory, target); + resolved = key === '.' ? exportTarget(directory, exports) : undefined; + } else { + const entries = exports as Record; + const pattern = Object.hasOwn(entries, key) && !key.includes('*') ? undefined : bestPattern(Object.keys(entries), key); + if (pattern === undefined && !Object.hasOwn(entries, key)) return undefined; + resolved = pattern === undefined ? exportTarget(directory, entries[key]) : exportTarget(directory, entries[pattern.key], pattern.match); } - // A `./*` style pattern: Node.js picks the matching key with the longest part before `*`, then the longest key, and puts the matched text in place of every `*` in the target. - let best: { pattern: string; match: string } | undefined; - for (const pattern of Object.keys(entries)) { + if (resolved === null) throw new Error(`${key} is not exported to import by ${path.join(directory, 'package.json')}`); + return resolved; +} + +/** The `./*` style key that matches `key`: the one with the longest part before `*`, then the longest key. */ +function bestPattern(keys: readonly string[], key: string): { key: string; match: string } | undefined { + let best: { key: string; match: string } | undefined; + for (const pattern of keys) { const star = pattern.indexOf('*'); if (star === -1 || star !== pattern.lastIndexOf('*')) continue; const prefix = pattern.slice(0, star); const suffix = pattern.slice(star + 1); if (key.length < pattern.length || !key.startsWith(prefix) || !key.endsWith(suffix)) continue; - if (best !== undefined && (prefix.length < best.pattern.indexOf('*') || (prefix.length === best.pattern.indexOf('*') && pattern.length <= best.pattern.length))) continue; - best = { pattern, match: key.slice(star, key.length - suffix.length) }; + if (best !== undefined && (prefix.length < best.key.indexOf('*') || (prefix.length === best.key.indexOf('*') && pattern.length <= best.key.length))) continue; + best = { key: pattern, match: key.slice(star, key.length - suffix.length) }; + } + return best; +} + +/** + * The file an `import` of this `exports` value selects, following Node.js's PACKAGE_TARGET_RESOLVE: null when the + * package excludes it, undefined when no condition matches. `match` replaces every `*` of a pattern's target. + */ +function exportTarget(directory: string, target: unknown, match?: string): string | null | undefined { + if (typeof target === 'string') { + if (!target.startsWith('./') || hasInvalidSegment(target.slice(2)) || (match !== undefined && hasInvalidSegment(match))) { + throw new InvalidTarget(`invalid exports target ${JSON.stringify(target)}${match === undefined ? '' : ` for ${JSON.stringify(match)}`}: it must start with ./ and stay inside the package`); + } + return path.join(directory, match === undefined ? target : target.replaceAll('*', match)); } - if (best === undefined) return undefined; - const target = importTarget(entries[best.pattern]); - return target === undefined ? undefined : path.join(directory, target.replaceAll('*', best.match)); -} - -/** The first target an `import` of this `exports` value selects: a path, or the first matching condition's, in the order written. */ -function importTarget(value: unknown): string | undefined { - if (typeof value === 'string') return value; - if (typeof value !== 'object' || value === null || Array.isArray(value)) return undefined; - for (const [condition, target] of Object.entries(value)) { - const selected = condition === 'import' || condition === 'node' || condition === 'default' ? importTarget(target) : undefined; - if (selected !== undefined) return selected; + if (Array.isArray(target)) { + if (target.length === 0) return null; + // Like Node.js: an invalid item or a null one moves on to the next, and the last of them is the answer when none resolves. + let last: InvalidTarget | null | undefined; + for (const item of target) { + let resolved: string | null | undefined; + try { + resolved = exportTarget(directory, item, match); + } catch (error) { + if (!(error instanceof InvalidTarget)) throw error; + last = error; + continue; + } + if (resolved === undefined) continue; + if (resolved === null) { + last = null; + continue; + } + return resolved; + } + if (last instanceof InvalidTarget) throw last; + return last; + } + if (target === null) return null; + if (typeof target !== 'object') throw new InvalidTarget(`invalid exports target ${JSON.stringify(target)}`); + for (const [condition, value] of Object.entries(target)) { + if (!IMPORT_CONDITIONS.has(condition)) continue; + const resolved = exportTarget(directory, value, match); + if (resolved !== undefined) return resolved; } return undefined; } + +function hasInvalidSegment(relative: string): boolean { + return relative.split(/[\\/]/).some((segment) => segment === '' || segment === '.' || segment === '..' || segment.toLowerCase() === 'node_modules'); +} diff --git a/packages/e2e/tests/unit/mcp-default-engine.test.ts b/packages/e2e/tests/unit/mcp-default-engine.test.ts index 0f47fc138c..e6d36d3916 100644 --- a/packages/e2e/tests/unit/mcp-default-engine.test.ts +++ b/packages/e2e/tests/unit/mcp-default-engine.test.ts @@ -79,6 +79,43 @@ describe('loadEngine', () => { expect(await loadEngine({ package: 'patterned/engines/kiosk' }, lookup)).toMatchObject({ name: 'from-longest-pattern' }); }); + /** Installs `shaped` with `exports`: index.js and sync.js are ESM factories, index.cjs a CommonJS one. */ + function installShaped(exports: unknown): void { + install(lookup.cwd, 'shaped', FACTORY.replace("'fake'", "'from-import'")); + const packageDir = path.join(lookup.cwd, 'node_modules', 'shaped'); + writeFileSync(path.join(packageDir, 'package.json'), JSON.stringify({ name: 'shaped', type: 'module', exports })); + writeFileSync(path.join(packageDir, 'sync.js'), FACTORY.replace("'fake'", "'from-module-sync'")); + writeFileSync(path.join(packageDir, 'index.cjs'), `module.exports = () => ({ [Symbol.for('e2e.engine.v1')]: true, spiVersion: 1, name: 'from-require' });\n`); + } + + it.each<[string, unknown, string]>([ + ['an array of condition objects', { '.': [{ import: './index.js', require: './index.cjs' }] }, 'from-import'], + ['a top-level array that skips an invalid target', ['index.cjs', { import: './index.js' }], 'from-import'], + ['an array item excluded with null', { '.': [null, { import: './index.js' }] }, 'from-import'], + ['module-sync before require', { '.': { 'module-sync': './sync.js', require: './index.cjs' } }, 'from-module-sync'], + ['require before module-sync', { '.': { require: './index.cjs', 'module-sync': './sync.js' } }, 'from-module-sync'], + ['require alone, read as before', { '.': { require: './index.cjs' } }, 'from-require'], + ])('loads the entry import() loads for %s', async (_shape, exports, name) => { + installShaped(exports); + expect(await loadEngine({ package: 'shaped' }, lookup)).toMatchObject({ name }); + }); + + it.each<[string, unknown, string]>([ + ['an import excluded with null', { '.': { import: null, require: './index.cjs' } }, '. is not exported to import'], + ['an import array whose first file is missing', { '.': { import: ['./missing.js', './index.js'], require: './index.cjs' } }, 'missing.js'], + ['a target outside the package', { '.': { import: '../other/index.js', require: './index.cjs' } }, 'invalid exports target "../other/index.js"'], + ['a target without ./', { '.': { import: 'index.js', require: './index.cjs' } }, 'invalid exports target "index.js"'], + ['a target through node_modules', { '.': { import: './node_modules/other/index.js' } }, 'invalid exports target'], + ])('refuses %s, as import() does, instead of loading the require entry', async (_shape, exports, message) => { + installShaped(exports); + await expect(loadEngine({ package: 'shaped' }, lookup)).rejects.toMatchObject({ code: 'INVALID_CONFIG', message: expect.stringContaining(message) }); + }); + + it('refuses a wildcard match that runs through node_modules', async () => { + installShaped({ '.': './index.js', './*': { import: './*.js' } }); + await expect(loadEngine({ package: 'shaped/node_modules/other' }, lookup)).rejects.toMatchObject({ code: 'INVALID_CONFIG', message: expect.stringContaining('invalid exports target') }); + }); + it('makes the factory calls among the options first, so an engine gets a provider JSON cannot carry', async () => { install(lookup.cwd, 'engine', FACTORY); install(lookup.enginesDir, 'cloud', `export const devices = (options) => ({ name: 'cloud', region: options?.region, acquire: () => 'leased' });\n`); From 795a9bee03e1c9b0f1840b3d029ac9e37b1fdb2b Mon Sep 17 00:00:00 2001 From: Mradul Singh Date: Sat, 14 Nov 2026 04:49:38 +0530 Subject: [PATCH 4/4] fix(mcp): accept export targets with an empty segment, as import() does --- packages/e2e/src/mcp/default-engine.ts | 4 ++-- packages/e2e/tests/unit/mcp-default-engine.test.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/e2e/src/mcp/default-engine.ts b/packages/e2e/src/mcp/default-engine.ts index 903ddf7366..fccc62bbac 100644 --- a/packages/e2e/src/mcp/default-engine.ts +++ b/packages/e2e/src/mcp/default-engine.ts @@ -190,7 +190,7 @@ function installedAt(name: string, root: string): string | undefined { /** Conditions Node.js matches for `import()`, besides `default`. */ const IMPORT_CONDITIONS = new Set(['node', 'import', 'module-sync', 'default']); -/** A target Node.js refuses: it does not start with `./`, or a segment is empty, `.`, `..` or `node_modules`. */ +/** A target Node.js refuses: it does not start with `./`, or a segment is `.`, `..` or `node_modules` (an empty one only gets a deprecation warning). */ class InvalidTarget extends Error {} /** @@ -276,5 +276,5 @@ function exportTarget(directory: string, target: unknown, match?: string): strin } function hasInvalidSegment(relative: string): boolean { - return relative.split(/[\\/]/).some((segment) => segment === '' || segment === '.' || segment === '..' || segment.toLowerCase() === 'node_modules'); + return relative.split(/[\\/]/).some((segment) => segment === '.' || segment === '..' || segment.toLowerCase() === 'node_modules'); } diff --git a/packages/e2e/tests/unit/mcp-default-engine.test.ts b/packages/e2e/tests/unit/mcp-default-engine.test.ts index e6d36d3916..3adccb2955 100644 --- a/packages/e2e/tests/unit/mcp-default-engine.test.ts +++ b/packages/e2e/tests/unit/mcp-default-engine.test.ts @@ -95,6 +95,7 @@ describe('loadEngine', () => { ['module-sync before require', { '.': { 'module-sync': './sync.js', require: './index.cjs' } }, 'from-module-sync'], ['require before module-sync', { '.': { require: './index.cjs', 'module-sync': './sync.js' } }, 'from-module-sync'], ['require alone, read as before', { '.': { require: './index.cjs' } }, 'from-require'], + ['a target with an empty segment, which Node.js only warns about', { '.': { import: './/index.js', require: './index.cjs' } }, 'from-import'], ])('loads the entry import() loads for %s', async (_shape, exports, name) => { installShaped(exports); expect(await loadEngine({ package: 'shaped' }, lookup)).toMatchObject({ name });