diff --git a/build.mjs b/build.mjs index 7fbd85e..348c1fe 100644 --- a/build.mjs +++ b/build.mjs @@ -37,7 +37,7 @@ await measure(`package.json → ./dist/package.json`, `created in`, async () => maintainers: Existing.maintainers, license: Existing.license, publishConfig: Existing.publishConfig, - export: Existing.export, + exports: Existing.exports, main: Existing.main, module: Existing.module, typings: Existing.typings, diff --git a/validate_dist.mjs b/validate_dist.mjs index f7d3144..bcbf56c 100644 --- a/validate_dist.mjs +++ b/validate_dist.mjs @@ -14,3 +14,25 @@ console.log(); try { const publintResult = await $`pnpm publint ${pkgDir}`; } catch (error) {} + +// Guard against regressions in dist/package.json generation (see build.mjs): +// a missing `exports` field makes bundlers resolve the CJS build, which breaks +// the `@effector/reflect/scope` subpath and causes a dual-package hazard with +// effector-react (scope is lost inside `variant`/`reflect`). +{ + const distPkg = JSON.parse( + await fs.readFile(resolve(pkgDir, 'package.json'), { encoding: 'utf-8' }), + ); + const missing = []; + if (!distPkg.exports) missing.push('exports'); + else { + if (!distPkg.exports['.']) missing.push("exports['.']"); + if (!distPkg.exports['./scope']) missing.push("exports['./scope']"); + } + if (missing.length > 0) { + throw new Error( + `dist/package.json is missing required field(s): ${missing.join(', ')}`, + ); + } + console.log('✓ dist/package.json has valid "exports"'); +}