Skip to content

Commit

Permalink
Upgrade resolve.exports to v2 (#1457)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Skoufis <[email protected]>
  • Loading branch information
emonadeo and askoufis authored Aug 18, 2024
1 parent b4a9b23 commit 06f35aa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"prettier": "^2.8.8",
"resolve.exports": "^1.1.0",
"resolve.exports": "^2.0.2",
"rollup": "^2.7.0",
"rollup-plugin-dts": "^4.2.2",
"rollup-plugin-node-externals": "^5.0.0",
Expand Down
10 changes: 2 additions & 8 deletions pnpm-lock.yaml

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

18 changes: 14 additions & 4 deletions scripts/build-dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ import { rollup } from 'rollup';
import dts from 'rollup-plugin-dts';
import { externals } from 'rollup-plugin-node-externals';

function resolveEntry<PackageJson>(pkg: PackageJson, entryName?: string) {
function resolveEntry<PackageJson>(
pkg: PackageJson,
entryName?: string,
): string {
const entryPath = entryName
? resolve(pkg, entryName, { conditions: ['node', 'default'] })
? resolve(pkg, entryName, { browser: false, require: true })
: legacy(pkg, { browser: false, fields: ['main'] })!;

if (!entryPath) {
if (!entryPath || entryPath.length === 0) {
throw new Error('No entry found. Invalid package.json?');
}

if (Array.isArray(entryPath)) {
return entryPath[0];
}

return entryPath;
}

Expand All @@ -27,7 +34,10 @@ async function buildEntry(packageDir: string, entryPath: string) {
const dtsEntryPath = path.relative(process.cwd(), dtsEntryPathAbsolute);
const outDir = path.dirname(dtsEntryPath);

if (!existsSync(dtsEntryPath)) return;
if (!existsSync(dtsEntryPath)) {
console.warn('Skipping', dtsEntryPath, '(Not Found)');
return;
}

console.log('Bundling', dtsEntryPath);

Expand Down

0 comments on commit 06f35aa

Please sign in to comment.