Skip to content

Commit

Permalink
fix: import/require to respect export maps
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Apr 30, 2022
1 parent 96cb30a commit 8f1fdf4
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 19 deletions.
2 changes: 0 additions & 2 deletions src/utils/get-rollup-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ const getConfig = {
}),
nodeResolve({
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'],
// Order from https://nodejs.org/api/packages.html#conditional-exports
exportConditions: ['node', 'import', 'require', 'default'],
}),
...(
Object.keys(env).length > 0
Expand Down

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

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

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

This file was deleted.

This file was deleted.

3 changes: 3 additions & 0 deletions tests/fixture-package/src/dependency-exports-import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import esm from 'dependency-exports-dual';

console.log(esm);
5 changes: 1 addition & 4 deletions tests/fixture-package/src/dependency-exports-require.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
import someValue from 'dependency-exports-require';

console.log(someValue);

console.log(require('dependency-exports-dual'));
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default testSuite(({ describe }, nodePath: string) => {
await fixture.cleanup();
});

test('dependency with exports.require', async () => {
test('dual package - require', async () => {
const fixture = await createFixture('./tests/fixture-package');

await fixture.writeJson('package.json', {
Expand All @@ -38,7 +38,25 @@ export default testSuite(({ describe }, nodePath: string) => {
expect(pkgrollProcess.stderr).toBe('');

const content = await fixture.readFile('dist/dependency-exports-require.js', 'utf8');
expect(content).toMatch('1234');
expect(content).toMatch('cjs');

await fixture.cleanup();
});

test('dual package - import', async () => {
const fixture = await createFixture('./tests/fixture-package');

await fixture.writeJson('package.json', {
main: './dist/dependency-exports-import.js',
});

const pkgrollProcess = await pkgroll([], { cwd: fixture.path, nodePath });

expect(pkgrollProcess.exitCode).toBe(0);
expect(pkgrollProcess.stderr).toBe('');

const content = await fixture.readFile('dist/dependency-exports-import.js', 'utf8');
expect(content).toMatch('esm');

await fixture.cleanup();
});
Expand Down
4 changes: 2 additions & 2 deletions tests/specs/builds/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import specTypes from './types';
import specPackageExports from './package-exports';
import specPackageImports from './package-imports';
import specBin from './bin';
import specExternalizeDependencies from './externalize-dependencies';
import specDependencies from './dependencies';
import specSrcDist from './src-dist';

export default testSuite(({ describe }, nodePath: string) => {
Expand All @@ -22,7 +22,7 @@ export default testSuite(({ describe }, nodePath: string) => {
runTestSuite(specPackageExports, nodePath);
runTestSuite(specPackageImports, nodePath);
runTestSuite(specBin, nodePath);
runTestSuite(specExternalizeDependencies, nodePath);
runTestSuite(specDependencies, nodePath);
runTestSuite(specSrcDist, nodePath);
});
});

0 comments on commit 8f1fdf4

Please sign in to comment.