Skip to content

Commit 8ee20bf

Browse files
committed
fix: don't external shim file
closes #351
1 parent e70f9f0 commit 8ee20bf

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

src/features/external.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { builtinModules } from 'node:module'
22
import Debug from 'debug'
3+
import { shimFile } from '../index'
34
import { toArray } from '../utils/general'
45
import type { ResolvedOptions } from '../options'
56
import type { PackageJson } from 'pkg-types'
@@ -13,6 +14,7 @@ export function ExternalPlugin(options: ResolvedOptions): Plugin {
1314
name: 'tsdown:external',
1415
async resolveId(id, importer, extraOptions) {
1516
if (extraOptions.isEntry) return
17+
if (id === shimFile) return
1618

1719
const { noExternal } = options
1820
if (typeof noExternal === 'function' && noExternal(id, importer)) {

src/features/shims.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import path from 'node:path'
2-
import { pkgRoot } from '../index'
1+
import { shimFile } from '../index'
32
import type { NormalizedFormat, ResolvedOptions } from '../options'
43

54
export function getShimsInject(
65
format: NormalizedFormat,
76
platform: ResolvedOptions['platform'],
87
): Record<string, [string, string]> | undefined {
98
if (format === 'es' && platform === 'node') {
10-
const shimFile = path.resolve(pkgRoot, 'esm-shims.js')
119
return {
1210
__dirname: [shimFile, '__dirname'],
1311
__filename: [shimFile, '__filename'],

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export async function build(userOptions: Options = {}): Promise<void> {
8181
}
8282

8383
const dirname = path.dirname(fileURLToPath(import.meta.url))
84-
export const pkgRoot: string = path.resolve(dirname, '..')
84+
const pkgRoot: string = path.resolve(dirname, '..')
85+
export const shimFile: string = path.resolve(pkgRoot, 'esm-shims.js')
8586

8687
export type TsdownChunks = Partial<
8788
Record<NormalizedFormat, Array<OutputChunk | OutputAsset>>

0 commit comments

Comments
 (0)