Skip to content

Commit

Permalink
fix: remove warning
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Aug 11, 2022
1 parent 4261caf commit da90b2f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 45 deletions.
4 changes: 1 addition & 3 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,7 @@ async function doBuild(
}

const resolvedChokidarOptions = resolveChokidarOptions(
config.logger,
config.build.watch.chokidar,
'build.watch.chokidar'
config.build.watch.chokidar
)

const { watch } = await import('rollup')
Expand Down
9 changes: 4 additions & 5 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,10 @@ export async function createServer(
)
const { middlewareMode } = serverConfig

const resolvedWatchOptions = resolveChokidarOptions(
config.logger,
{ disableGlobbing: true, ...serverConfig.watch },
'server.watch'
)
const resolvedWatchOptions = resolveChokidarOptions({
disableGlobbing: true,
...serverConfig.watch
})

const middlewares = connect() as Connect.Server
const httpServer = middlewareMode
Expand Down
19 changes: 0 additions & 19 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1144,22 +1144,3 @@ export const isNonDriveRelativeAbsolutePath = (p: string): boolean => {
if (!isWindows) return p.startsWith('/')
return windowsDrivePathPrefixRE.test(p)
}

/**
* returns `true` for WSL2 including docker running on WSL2
*
* https://github.com/microsoft/WSL/issues/423#issuecomment-844418910
*/
export const isWSL2 = (() => {
const release = os.release()
// Example: `5.10.102.1-microsoft-standard-WSL2`
if (release.includes('WSL2')) {
// "Docker Desktop for Windows with WSL2 backend" and "Docker installed in WSL" comes here too
return true
}

// Windows Example: `10.0.19044`
// WSL1 Example: `4.4.0-19041-Microsoft`
// Docker Desktop for Windows with WSL2 backend Example: `5.10.76-linuxkit`
return false
})()
19 changes: 1 addition & 18 deletions packages/vite/src/node/watch.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import type { WatchOptions } from 'types/chokidar'
import colors from 'picocolors'
import type { Logger } from './logger'
import { isWSL2 } from './utils'

export function resolveChokidarOptions(
logger: Logger,
options: WatchOptions | undefined,
optionName: string
options: WatchOptions | undefined
): WatchOptions {
const { ignored = [], ...otherOptions } = options ?? {}

Expand All @@ -22,17 +17,5 @@ export function resolveChokidarOptions(
...otherOptions
}

if (isWSL2 && resolvedWatchOptions.usePolling === undefined) {
logger.warn(
colors.yellow(
colors.bold(`(!) `) +
'Default file system watching might not work with your setup due to a limitation of WSL2. ' +
'HMR and other features will not work when file system watching is not working. ' +
`To suppress this warning, set true or false to "${optionName}.usePolling". ` +
'More information: https://vitejs.dev/config/server-options.html#server-watch'
)
)
}

return resolvedWatchOptions
}

0 comments on commit da90b2f

Please sign in to comment.