Skip to content

Commit

Permalink
fix(cjs): resolve ts extensions from js when namespaced
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Sep 12, 2024
1 parent ac77527 commit 44ed37f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/cjs/api/module-resolve-filename/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ export const createResolveFilename = (

nextResolveSimple = createTsExtensionResolver(
nextResolveSimple,
Boolean(parent?.filename && tsExtensionsPattern.test(parent.filename)),
Boolean(
// If register.namespace is used (e.g. tsx.require())
namespace

// If parent is a TS file
|| (parent?.filename && tsExtensionsPattern.test(parent.filename)),
),
);

nextResolveSimple = createImplicitResolver(nextResolveSimple);
Expand Down
5 changes: 3 additions & 2 deletions tests/specs/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'node:path';
import { execaNode } from 'execa';
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import { outdent } from 'outdent';
import {
tsxCjsPath,
tsxCjsApiPath,
Expand All @@ -11,7 +12,6 @@ import {
type NodeApis,
} from '../utils/tsx.js';
import { createPackageJson, createTsconfig, expectErrors } from '../fixtures.js';
import { outdent } from 'outdent';

const tsFiles = {
'file.ts': outdent`
Expand Down Expand Up @@ -266,7 +266,8 @@ export default testSuite(({ describe }, node: NodeApis) => {
...tsFiles,
});

const { stdout } = await execaNode(fixture.getPath('require.cjs'), [], {
const { stdout } = await execaNode('./require.cjs', [], {
cwd: fixture.path,
nodePath: node.path,
nodeOptions: [],
});
Expand Down

0 comments on commit 44ed37f

Please sign in to comment.