Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/core/__tests__/build-artifacts.spec.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
5 changes: 5 additions & 0 deletions packages/core/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading