diff --git a/src/cli/program.ts b/src/cli/program.ts index a0c6537..9c24504 100644 --- a/src/cli/program.ts +++ b/src/cli/program.ts @@ -1,4 +1,7 @@ -import { calculate_coverage, type Coverage, type CoverageResult } from '../lib/index.js' +// import from absolute package name instead of relative import (like ../lib/index.ts) +// to prevent lib/index.js being bundled into cli.js, which would mean that indexjs +// ends up in our /dist twice which is wasteful +import { calculate_coverage, type Coverage, type CoverageResult } from '@projectwallace/css-code-coverage' export type Report = { context: { diff --git a/tsconfig.json b/tsconfig.json index d6d0a9b..a84a797 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,7 +18,11 @@ ], "declaration": true, "rootDirs": ["src/lib", "src/cli"], - "outDir": "dist" + "outDir": "dist", + "paths": { + // So we can import like an external in the CLI + "@projectwallace/css-code-coverage": ["./src/lib/index.ts"] + } }, "include": [ "src/lib/index.ts", diff --git a/tsdown.config.ts b/tsdown.config.ts index 017ef18..52e545d 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -20,6 +20,9 @@ export default defineConfig([ platform: 'node', format: 'esm', dts: false, + // The CLI references the Core via 'external' reference to prevent it + // from ending up as duplicate code in cli.js + external: ['@projectwallace/css-code-coverage'], plugins: [ codecovVitePlugin({ enableBundleAnalysis: process.env.CODECOV_TOKEN !== undefined,