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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore esbuild warning if silent is true #643

Merged
merged 1 commit into from Jun 5, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/esbuild/index.ts
Expand Up @@ -8,7 +8,7 @@ import {
} from 'esbuild'
import { NormalizedOptions, Format } from '..'
import { getDeps, loadPkg } from '../load'
import { Logger } from '../log'
import { Logger, getSilent } from '../log'
import { nodeProtocolPlugin } from './node-protocol'
import { externalPlugin } from './external'
import { postcssPlugin } from './postcss'
Expand Down Expand Up @@ -103,8 +103,8 @@ export async function runEsbuild(
format === 'iife'
? false
: typeof options.splitting === 'boolean'
? options.splitting
: format === 'esm'
? options.splitting
: format === 'esm'

const platform = options.platform || 'node'
const loader = options.loader || {}
Expand All @@ -131,12 +131,12 @@ export async function runEsbuild(
// esbuild's `external` option doesn't support RegExp
// So here we use a custom plugin to implement it
format !== 'iife' &&
externalPlugin({
external,
noExternal: options.noExternal,
skipNodeModulesBundle: options.skipNodeModulesBundle,
tsconfigResolvePaths: options.tsconfigResolvePaths,
}),
externalPlugin({
external,
noExternal: options.noExternal,
skipNodeModulesBundle: options.skipNodeModulesBundle,
tsconfigResolvePaths: options.tsconfigResolvePaths,
}),
options.tsconfigDecoratorMetadata && swcPlugin({ logger }),
nativeNodeModulesPlugin(),
postcssPlugin({ css, inject: options.injectStyle }),
Expand Down Expand Up @@ -198,8 +198,8 @@ export async function runEsbuild(
TSUP_FORMAT: JSON.stringify(format),
...(format === 'cjs' && injectShims
? {
'import.meta.url': 'importMetaUrl',
}
'import.meta.url': 'importMetaUrl',
}
: {}),
...options.define,
...Object.keys(env).reduce((res, key) => {
Expand Down Expand Up @@ -242,7 +242,7 @@ export async function runEsbuild(
throw error
}

if (result && result.warnings) {
if (result && result.warnings && !getSilent()) {
const messages = result.warnings.filter((warning) => {
if (
warning.text.includes(
Expand Down
12 changes: 8 additions & 4 deletions src/log.ts
Expand Up @@ -9,10 +9,10 @@ export const colorize = (type: LOG_TYPE, data: any, onlyImportant = false) => {
type === 'info'
? 'blue'
: type === 'error'
? 'red'
: type === 'warn'
? 'yellow'
: 'green'
? 'red'
: type === 'warn'
? 'yellow'
: 'green'
return colors[color](data)
}

Expand All @@ -35,6 +35,10 @@ export function setSilent(isSilent?: boolean) {
silent = !!isSilent
}

export function getSilent() {
return silent
}

export type Logger = ReturnType<typeof createLogger>

export const createLogger = (name?: string) => {
Expand Down