Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/packages/firebird-core/tsdown.config.ts is written in an unsupported language. File is not indexed.

0001 import { readFileSync } from 'node:fs';
0002 import { defineConfig } from 'tsdown';
0003 
0004 // One build config, byte-identical in every plain-TypeScript library that
0005 // uses it. What differs between packages lives in their package.json.
0006 
0007 type ExportTarget = string | { types?: string; default?: string };
0008 
0009 /**
0010  * The build entries, read from the package's own "exports" map. The dist
0011  * tree mirrors src: a subpath exported as `./dist/<path>.js` builds from
0012  * `src/<path>.ts` (`.` is `./dist/index.js` from `src/index.ts`, `./model` may
0013  * be `./dist/model/index.js` from `src/model/index.ts`). A package adds a
0014  * subpath by adding it to "exports"; code shared between entries lands in
0015  * chunks, so a class stays one class whichever subpath imports it.
0016  */
0017 function entriesFromExports(): Record<string, string> {
0018   const packageJson = JSON.parse(readFileSync('package.json', 'utf8'));
0019   const entries: Record<string, string> = {};
0020   for (const [subpath, target] of Object.entries(packageJson.exports as Record<string, ExportTarget>)) {
0021     const runtime = typeof target === 'string' ? target : target.default;
0022     const name = runtime?.match(/^\.\/dist\/(.+)\.js$/)?.[1];
0023     if (!name) {
0024       throw new Error(`package.json exports '${subpath}': expected "./dist/<path>.js", got ${JSON.stringify(runtime)}`);
0025     }
0026     if (typeof target !== 'string' && target.types !== `./dist/${name}.d.ts`) {
0027       throw new Error(`package.json exports '${subpath}': "types" must be "./dist/${name}.d.ts"`);
0028     }
0029     entries[name] = `src/${name}.ts`;
0030   }
0031   return entries;
0032 }
0033 
0034 export default defineConfig({
0035   entry: entriesFromExports(),
0036   // A browser library: 'neutral' adds no runtime-specific handling and keeps
0037   // the output extension tied to package.json "type" (index.js, index.d.ts)
0038   // instead of the platform-'node' default (.mjs, .d.mts).
0039   platform: 'neutral',
0040   sourcemap: true,
0041   // One bundled .d.ts per entry. No declaration maps: they point into src/,
0042   // which the package does not ship.
0043   dts: { sourcemap: false },
0044 });