Skip to content

Commit

Permalink
fix: give up detection
Browse files Browse the repository at this point in the history
The current detection somehow works with docker+wsl2, but it does not work with wsl2.
  • Loading branch information
sapphi-red committed Jul 9, 2022
1 parent 868808e commit 7ff0916
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 125 deletions.
27 changes: 9 additions & 18 deletions packages/vite/src/node/build.ts
Expand Up @@ -21,13 +21,12 @@ import commonjsPlugin from '@rollup/plugin-commonjs'
import type { RollupCommonJSOptions } from 'types/commonjs'
import type { RollupDynamicImportVarsOptions } from 'types/dynamicImportVars'
import type { TransformOptions } from 'esbuild'
import { detectWhetherChokidarWithDefaultOptionWorks, isWSL2 } from './watcher'
import type { InlineConfig, ResolvedConfig } from './config'
import { isDepsOptimizerEnabled, resolveConfig } from './config'
import { buildReporterPlugin } from './plugins/reporter'
import { buildEsbuildPlugin } from './plugins/esbuild'
import { terserPlugin } from './plugins/terser'
import { copyDir, emptyDir, lookupFile, normalizePath } from './utils'
import { copyDir, emptyDir, isWSL2, lookupFile, normalizePath } from './utils'
import { manifestPlugin } from './plugins/manifest'
import type { Logger } from './logger'
import { dataURIPlugin } from './plugins/dataUri'
Expand Down Expand Up @@ -515,22 +514,14 @@ async function doBuild(
}

if (isWSL2 && resolvedChokidarOptions.usePolling === undefined) {
detectWhetherChokidarWithDefaultOptionWorks(config.root).then(
({ result, warning }) => {
if (result === false) {
config.logger.warn(
colors.yellow(
colors.bold(`(!) `) +
'Default file system watching is not working with your setup due to the limitation of WSL2. ' +
'Rebuild will not happen.' +
'More information: https://vitejs.dev/config/server-options.html#server-watch'
)
)
}
if (warning) {
config.logger.warn(colors.yellow(warning))
}
}
config.logger.warn(
colors.yellow(
colors.bold(`(!) `) +
'Default file system watching might not work with your setup due to the limitation of WSL2. ' +
'Rebuild will not happen when file system watching is not working. ' +
'To suppress this warning, set true or false to "build.watch.usePolling". ' +
'More information: https://vitejs.dev/config/server-options.html#server-watch'
)
)
}

Expand Down
26 changes: 9 additions & 17 deletions packages/vite/src/node/server/index.ts
Expand Up @@ -17,6 +17,7 @@ import type { InlineConfig, ResolvedConfig } from '../config'
import { isDepsOptimizerEnabled, resolveConfig } from '../config'
import {
isParentDirectory,
isWSL2,
mergeConfig,
normalizePath,
resolveHostname
Expand All @@ -37,7 +38,6 @@ import { CLIENT_DIR } from '../constants'
import type { Logger } from '../logger'
import { printCommonServerUrls } from '../logger'
import { invalidatePackageData } from '../packages'
import { detectWhetherChokidarWithDefaultOptionWorks, isWSL2 } from '../watcher'
import type { PluginContainer } from './pluginContainer'
import { createPluginContainer } from './pluginContainer'
import type { WebSocketServer } from './ws'
Expand Down Expand Up @@ -298,22 +298,14 @@ export async function createServer(
}

if (isWSL2 && resolvedWatchOptions.usePolling === undefined) {
detectWhetherChokidarWithDefaultOptionWorks(root).then(
({ result, warning }) => {
if (result === false) {
config.logger.warn(
colors.yellow(
colors.bold(`(!) `) +
'Default file system watching is not working with your setup due to the limitation of WSL2. ' +
'HMR and other features will not work. ' +
'More information: https://vitejs.dev/config/server-options.html#server-watch'
)
)
}
if (warning) {
config.logger.warn(colors.yellow(warning))
}
}
config.logger.warn(
colors.yellow(
colors.bold(`(!) `) +
'Default file system watching might not work with your setup due to the 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 "server.watch.usePolling". ' +
'More information: https://vitejs.dev/config/server-options.html#server-watch'
)
)
}

Expand Down
19 changes: 19 additions & 0 deletions packages/vite/src/node/utils.ts
Expand Up @@ -1087,3 +1087,22 @@ 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
})()
90 changes: 0 additions & 90 deletions packages/vite/src/node/watcher.ts

This file was deleted.

0 comments on commit 7ff0916

Please sign in to comment.