diff --git a/packages/core/__tests__/build-artifacts.spec.ts b/packages/core/__tests__/build-artifacts.spec.ts new file mode 100644 index 0000000000..995ad5edb8 --- /dev/null +++ b/packages/core/__tests__/build-artifacts.spec.ts @@ -0,0 +1,19 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import url from 'node:url'; + +import { describe, expect, it } from 'vitest'; + +const coreDir = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '..'); +const distDir = path.join(coreDir, 'dist'); + +describe('build artifacts', () => { + it('should include esm-shims.js in dist for tsdown shims support', () => { + const shimsPath = path.join(distDir, 'esm-shims.js'); + expect(fs.existsSync(shimsPath), `${shimsPath} should exist`).toBe(true); + + const content = fs.readFileSync(shimsPath, 'utf8'); + expect(content).toContain('__dirname'); + expect(content).toContain('__filename'); + }); +}); diff --git a/packages/core/build.ts b/packages/core/build.ts index 3bc80533f7..d375eafd03 100644 --- a/packages/core/build.ts +++ b/packages/core/build.ts @@ -428,6 +428,11 @@ async function bundleTsdown() { }), ], }); + + // Copy esm-shims.js to dist/ so tsdown's shims option can resolve it. + // tsdown resolves this file via path.resolve(import.meta.dirname, '..', 'esm-shims.js'), + // which means it expects the file at dist/esm-shims.js (one level up from dist/tsdown/). + await copyFile(join(tsdownSourceDir, 'esm-shims.js'), join(projectDir, 'dist/esm-shims.js')); } async function brandTsdown() {