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

🐛 Enable usePolling on Windows to fix file-lock #1523

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/user/config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ There's no support for multiple config files or inheriting/overriding config fil
"language": "Default",
"permissionLevel": 2,
"plugins": [],
"mcmetaSummaryOverrides": {}
"mcmetaSummaryOverrides": {},
useFilePolling: false
},
"format": {
"blockStateBracketSpacing": { "inside": 0 },
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/common/externals/NodeJsExternals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ export const NodeJsExternals: Externals = {
unlink(location) {
return fsp.unlink(toFsPathLike(location))
},
watch(locations) {
return new ChokidarWatcherWrapper(chokidar.watch(locations.map(toPath)))
watch(locations, { usePolling = false } = {}) {
return new ChokidarWatcherWrapper(
chokidar.watch(locations.map(toPath), { usePolling }),
)
},
writeFile(location, data, options) {
return fsp.writeFile(toFsPathLike(location), data, options)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/common/externals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export interface ExternalFileSystem {
showFile(path: FsLocation): Promise<void>
stat(location: FsLocation): Promise<{ isDirectory(): boolean; isFile(): boolean }>
unlink(location: FsLocation): Promise<void>
watch(locations: FsLocation[]): FsWatcher
watch(locations: FsLocation[], options: { usePolling?: boolean }): FsWatcher
/**
* @param options `mode` - File mode bit mask (e.g. `0o775`).
*/
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/service/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ export interface EnvConfig {
>
permissionLevel: 1 | 2 | 3 | 4
plugins: string[]
/**
* Makes the file-watcher use polling to watch for file changes.
* Comes at a performance cost for very large datapacks.
*
* On Windows, enabling this can fix file-lock issues when Spyglass is running.
* See: https://github.com/SpyglassMC/Spyglass/issues/1414
*
* **You should only consider enabling this for Windows machines.**
*/
useFilePolling: boolean
}

export type LinterSeverity = 'hint' | 'information' | 'warning' | 'error'
Expand Down Expand Up @@ -352,6 +362,7 @@ export const VanillaConfig: Config = {
permissionLevel: 2,
plugins: [],
mcmetaSummaryOverrides: {},
useFilePolling: false,
},
format: {
blockStateBracketSpacing: { inside: 0 },
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/service/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,9 @@ export class Project implements ExternalEventEmitter {
}
this.#watchedFiles.clear()
this.#watcherReady = false
this.#watcher = this.externals.fs.watch(this.projectRoots).once('ready', () => {
this.#watcher = this.externals.fs.watch(this.projectRoots, {
usePolling: this.config.env.useFilePolling,
}).once('ready', () => {
this.#watcherReady = true
resolve()
}).on('add', (uri) => {
Expand Down
Loading