Skip to content

Commit

Permalink
fix: ignore esbuild warning if silent is true (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcherGu committed Jun 5, 2022
1 parent c3f336d commit 36e2199
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
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

1 comment on commit 36e2199

@vercel
Copy link

@vercel vercel bot commented on 36e2199 Jun 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

tsup – ./

tsup-egoist.vercel.app
tsup.egoist.sh
tsup-git-main-egoist.vercel.app
tsup.vercel.app

Please sign in to comment.