From 41dca5d0c760489528b6f82b0e62154729bb5990 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Wed, 18 Mar 2026 15:45:26 +0900 Subject: [PATCH 1/2] fix(core): copy esm-shims.js to dist during tsdown bundling resolve #999 --- .../core/__tests__/build-artifacts.spec.ts | 19 +++++++++++++++++++ packages/core/build.ts | 8 ++++++++ 2 files changed, 27 insertions(+) create mode 100644 packages/core/__tests__/build-artifacts.spec.ts 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..29d5b4a376 100644 --- a/packages/core/build.ts +++ b/packages/core/build.ts @@ -428,6 +428,14 @@ 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() { From 1fecdf05cfd2dbf84bffec948138320136928624 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Wed, 18 Mar 2026 16:25:00 +0900 Subject: [PATCH 2/2] chore(core): format --- packages/core/build.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/core/build.ts b/packages/core/build.ts index 29d5b4a376..d375eafd03 100644 --- a/packages/core/build.ts +++ b/packages/core/build.ts @@ -432,10 +432,7 @@ 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'), - ); + await copyFile(join(tsdownSourceDir, 'esm-shims.js'), join(projectDir, 'dist/esm-shims.js')); } async function brandTsdown() {