Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
fix: handle missing export map entry in ts resolution (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored Jul 23, 2022
1 parent 3709227 commit 4d460dd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ Module._resolveFilename = function (request, parent, isMain, options) {
options,
);
} catch (error) {
if ((error as any).code !== 'MODULE_NOT_FOUND') {
const { code } = error as any;
if (
code !== 'MODULE_NOT_FOUND'
&& code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED'
) {
throw error;
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/node_modules/package-exports/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/fixtures/node_modules/package-exports/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tests/specs/typescript/dependencies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { testSuite, expect } from 'manten';
import type { NodeApis } from '../../utils/node-with-loader';

export default testSuite(async ({ describe }, node: NodeApis) => {
describe('Dependencies', ({ describe }) => {
describe('export map', ({ test }) => {
const output = '{"default":"default export","namedExport":"named export"}';

test('Require', async () => {
const nodeProcess = await node.require('package-exports/index.js', {
typescript: true,
});
expect(nodeProcess.stdout).toBe(output);
});
});
});
});
2 changes: 2 additions & 0 deletions tests/specs/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import specJsx from './jsx';
import specMts from './mts';
import specCts from './cts';
import specTsconfig from './tsconfig';
import specDependencies from './dependencies';

export default testSuite(async ({ describe }, node: NodeApis) => {
describe('TypeScript', async ({ runTestSuite }) => {
Expand All @@ -15,5 +16,6 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
runTestSuite(specMts, node);
runTestSuite(specCts, node);
runTestSuite(specTsconfig, node);
runTestSuite(specDependencies, node);
});
});

0 comments on commit 4d460dd

Please sign in to comment.