8000 feat: warn if `@oxc-project/runtime` is missing (#233) · rolldown/tsdown@86ad52c · GitHub
[go: up one dir, main page]

Skip to content

Commit 86ad52c

Browse files
wChenonlysxzz
andauthored
feat: warn if @oxc-project/runtime is missing (#233)
Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
1 parent dfc80d9 commit 86ad52c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/features/target.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { blue } from 'ansis'
12
import minVersion from 'semver/ranges/min-version.js'
23
import { resolveComma, toArray } from '../utils/general'
34
import { generateColor, logger, prettyName } from '../utils/logger'
45
import type { PackageJson } from 'pkg-types'
6+
import type { Plugin } from 'rolldown'
57

68
export function resolveTarget(
79
target: string | string[] | false | undefined,
@@ -35,3 +37,31 @@ export function resolvePackageTarget(pkg?: PackageJson): string | undefined {
3537
if (nodeMinVersion.version === '0.0.0') return
3638
return `node${nodeMinVersion.version}`
3739
}
40+
41+
let warned = false
42+
export function RuntimeHelperCheckPlugin(targets: string[]): Plugin {
43+
return {
44+
name: 'tsdown:runtime-helper-check',
45+
resolveId: {
46+
filter: { id: /^@oxc-project\/runtime/ },
47+
async handler(id, ...args) {
48+
const EXTERNAL = { id, external: true }
49+
if (warned) return EXTERNAL
50+
51+
const resolved = await this.resolve(id, ...args)
52+
if (!resolved) {
53+
if (!warned) {
54+
warned = true
55+
logger.warn(
56+
`The target environment (${targets.join(', ')}) requires runtime helpers from ${blue`@oxc-project/runtime`}. ` +
57+
`Please install it to ensure all necessary polyfills are included.\n` +
58+
`For more information, visit: https://tsdown.dev/options/target#runtime-helpers`,
59+
)
60+
}
61+
return EXTERNAL
62+
}
63+
return resolved
64+
},
65+
},
66+
}
67+
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { publint } from './features/publint'
2121
import { ReportPlugin } from './features/report'
2222
import { getShimsInject } from './features/shims'
2323
import { shortcuts } from './features/shortcuts'
24+
import { RuntimeHelperCheckPlugin } from './features/target'
2425
import { watchBuild } from './features/watch'
2526
import {
2627
mergeUserOptions,
@@ -234,6 +235,7 @@ async function getBuildOptions(
234235
target,
235236
},
236237
}),
238+
RuntimeHelperCheckPlugin(target),
237239
)
238240
}
239241
plugins.push(ShebangPlugin(cwd, name, isMultiFormat))

0 commit comments

Comments
 (0)
0