Skip to content

Commit e811747

Browse files
authored
fix(core): copy esm-shims.js to dist during tsdown bundling (#1013)
resolve #999
1 parent 55642c2 commit e811747

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import url from 'node:url';
4+
5+
import { describe, expect, it } from 'vitest';
6+
7+
const coreDir = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '..');
8+
const distDir = path.join(coreDir, 'dist');
9+
10+
describe('build artifacts', () => {
11+
it('should include esm-shims.js in dist for tsdown shims support', () => {
12+
const shimsPath = path.join(distDir, 'esm-shims.js');
13+
expect(fs.existsSync(shimsPath), `${shimsPath} should exist`).toBe(true);
14+
15+
const content = fs.readFileSync(shimsPath, 'utf8');
16+
expect(content).toContain('__dirname');
17+
expect(content).toContain('__filename');
18+
});
19+
});

packages/core/build.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@ async function bundleTsdown() {
428428
}),
429429
],
430430
});
431+
432+
// Copy esm-shims.js to dist/ so tsdown's shims option can resolve it.
433+
// tsdown resolves this file via path.resolve(import.meta.dirname, '..', 'esm-shims.js'),
434+
// which means it expects the file at dist/esm-shims.js (one level up from dist/tsdown/).
435+
await copyFile(join(tsdownSourceDir, 'esm-shims.js'), join(projectDir, 'dist/esm-shims.js'));
431436
}
432437

433438
async function brandTsdown() {

0 commit comments

Comments
 (0)