| 691 | } |
| 692 | |
| 693 | async function buildRollupDts( |
| 694 | input: string, |
| 695 | output: string, |
| 696 | banner: string, |
| 697 | packageName: string |
| 698 | ) { |
| 699 | log(`Bundling '${styleText("cyan", output)}' with rollup ...`); |
| 700 | |
| 701 | let external; |
| 702 | let imports; |
| 703 | if (packageName) { |
| 704 | const pkgJSON = require("./" + packageName + "/package.json"); |
| 705 | const { |
| 706 | dependencies = {}, |
| 707 | devDependencies = {}, |
| 708 | peerDependencies = {}, |
| 709 | } = pkgJSON; |
| 710 | external = [ |
| 711 | ...Object.keys(dependencies), |
| 712 | ...Object.keys(peerDependencies), |
| 713 | // TODO: These should all be moved to dependencies |
| 714 | ...Object.keys(devDependencies), |
| 715 | ].map(dep => new RegExp(`^${dep}(?:/.+)?$`)); |
| 716 | |
| 717 | imports = pkgJSON.imports; |
| 718 | } |
| 719 | |
| 720 | const bundle = await rollup({ |
| 721 | input, |
| 722 | plugins: ( |
| 723 | [ |
| 724 | { |
| 725 | name: "rollup-babel-internal-define-BABEL_8_BREAKING", |
| 726 | transform: code => |
| 727 | code.replace( |
| 728 | /type BABEL_8_BREAKING\s*=\s*boolean/g, |
| 729 | `type BABEL_8_BREAKING = true` |
| 730 | ), |
| 731 | }, |
| 732 | rollupDts(), |
| 733 | imports && { |
| 734 | name: "resolve-dts-package.json-imports", |
| 735 | resolveId: { |
| 736 | order: "post", |
| 737 | handler(importee: string, importer: string | undefined) { |
| 738 | if (importer && importee.startsWith("#")) { |
| 739 | const mapped = imports?.[importee]?.types?.replace( |
| 740 | "/lib/", |
| 741 | "/src/" |
| 742 | ); |
| 743 | if (mapped) { |
| 744 | return require.resolve(`./dts/${packageName}/${mapped}`); |
| 745 | } |
| 746 | return null; |
| 747 | } |
| 748 | }, |
| 749 | }, |
| 750 | }, |