|
| 1 | +import { readFile } from 'node:fs/promises' |
| 2 | +import path from 'node:path' |
1 | 3 | import { exec } from 'tinyexec' |
2 | 4 | import { describe, expect, test } from 'vitest' |
3 | 5 | import { testBuild } from './utils.ts' |
@@ -113,4 +115,58 @@ describe('issues', () => { |
113 | 115 | }, |
114 | 116 | }) |
115 | 117 | }) |
| 118 | + |
| 119 | + test('#566', async (context) => { |
| 120 | + const { testDir } = await testBuild({ |
| 121 | + context, |
| 122 | + files: { |
| 123 | + 'src/index.browser.ts': `export const platform = 'browser'`, |
| 124 | + 'src/index.node.ts': `export const platform = 'node'`, |
| 125 | + 'tsdown.config.ts': ` |
| 126 | + export default [ |
| 127 | + { |
| 128 | + entry: './src/index.browser.ts', |
| 129 | + format: 'es', |
| 130 | + exports: true, |
| 131 | + hash: false, |
| 132 | + platform: 'browser', |
| 133 | + }, |
| 134 | + { |
| 135 | + entry: './src/index.node.ts', |
| 136 | + format: 'cjs', |
| 137 | + exports: true, |
| 138 | + hash: false, |
| 139 | + platform: 'node', |
| 140 | + }, |
| 141 | + ] |
| 142 | + `, |
| 143 | + 'package.json': JSON.stringify({ |
| 144 | + name: 'issue-566', |
| 145 | + version: '1.0.0', |
| 146 | + }), |
| 147 | + 'tsconfig.json': JSON.stringify({ |
| 148 | + compilerOptions: { moduleResolution: 'bundler' }, |
| 149 | + }), |
| 150 | + }, |
| 151 | + options: { |
| 152 | + entry: undefined, |
| 153 | + config: 'tsdown.config.ts', |
| 154 | + dts: false, |
| 155 | + }, |
| 156 | + expectPattern: '**/*.{js,cjs,d.mts}', |
| 157 | + }) |
| 158 | + |
| 159 | + const pkg = JSON.parse( |
| 160 | + await readFile(path.join(testDir, 'package.json'), 'utf8'), |
| 161 | + ) |
| 162 | + expect(pkg.main).toBe('./dist/index.node.cjs') |
| 163 | + expect(pkg.module).toBe('./dist/index.browser.mjs') |
| 164 | + expect(pkg.exports).toEqual({ |
| 165 | + '.': { |
| 166 | + import: './dist/index.browser.mjs', |
| 167 | + require: './dist/index.node.cjs', |
| 168 | + }, |
| 169 | + './package.json': './package.json', |
| 170 | + }) |
| 171 | + }) |
116 | 172 | }) |
0 commit comments