Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: exit with code (1) on build warnings #98

Merged
merged 19 commits into from Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/build.ts
Expand Up @@ -42,6 +42,7 @@ export async function build (rootDir: string, stub: boolean, inputConfig: BuildC
peerDependencies: [],
alias: {},
replace: {},
failOnWarn: true,
rollup: {
emitCJS: false,
cjsBridge: false,
Expand Down
3 changes: 3 additions & 0 deletions src/builder/rollup.ts
Expand Up @@ -140,6 +140,9 @@ export function getRollupOptions (ctx: BuildContext): RollupOptions {
return false
}
if (!isExplicitExternal) {
if (ctx.options.failOnWarn) {
throw new Error(`Implicit external ${id} detected. Either add to your project dependencies or add to \`externals\`. You can remove this protection by disabling \`failOnWarn\`.`)
pi0 marked this conversation as resolved.
Show resolved Hide resolved
}
consola.warn(`Inlining implicit external ${id}`)
}
return isExplicitExternal
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Expand Up @@ -66,6 +66,7 @@ export interface BuildOptions {
devDependencies: string[]
alias: { [find: string]: string },
replace: { [find: string]: string },
failOnWarn?: boolean
rollup: RollupBuildOptions
}

Expand Down
13 changes: 9 additions & 4 deletions src/validate.ts
Expand Up @@ -9,7 +9,7 @@ import { BuildContext } from './types'
export function validateDependencies (ctx: BuildContext) {
const usedDependencies = new Set<string>()
const unusedDependencies = new Set<string>(Object.keys(ctx.pkg.dependencies || {}))
const implicitDependnecies = new Set<string>()
const implicitDependencies = new Set<string>()
for (const id of ctx.usedImports) {
unusedDependencies.delete(id)
usedDependencies.add(id)
Expand All @@ -26,14 +26,19 @@ export function validateDependencies (ctx: BuildContext) {
!ctx.options.dependencies.includes(getpkg(id)) &&
!ctx.options.peerDependencies.includes(getpkg(id))
) {
implicitDependnecies.add(id)
implicitDependencies.add(id)
}
}
if (unusedDependencies.size) {
consola.warn('Potential unused dependencies found:', Array.from(unusedDependencies).map(id => chalk.cyan(id)).join(', '))
}
if (implicitDependnecies.size && !ctx.options.rollup.inlineDependencies) {
consola.warn('Potential implicit dependencies found:', Array.from(implicitDependnecies).map(id => chalk.cyan(id)).join(', '))
if (implicitDependencies.size && !ctx.options.rollup.inlineDependencies) {
consola.warn('Potential implicit dependencies found:', Array.from(implicitDependencies).map(id => chalk.cyan(id)).join(', '))
}
if (unusedDependencies.size || (implicitDependencies.size && !ctx.options.rollup.inlineDependencies)) {
if (ctx.options.failOnWarn) {
throw new Error('Failing build due to warnings. You can remove this protection by disabling `failOnWarn`.')
}
}
}

Expand Down