Verified Commit d12d0cc9 authored by Aral Balkan's avatar Aral Balkan
Browse files

Fixes #227: File watches now also work when serving current directory

parent 7a2bcd8c
......@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [14.5.1] - 2020-08-26
### Fixes
- File watches now also work when serving the current directory (without a path specified).
## [14.5.0] - 2020-08-26
### Added
......
......@@ -1137,7 +1137,19 @@ class Site {
// event, it gets triggered with a 'rename' when a removed/recreated folder
// is affected.) See: https://github.com/paulmillr/chokidar/issues/404#issuecomment-666669336
createFileWatcher () {
const fileWatchPath = `${this.pathToServe.replace(/\\/g, '/')}/**/*`
// Workaround for #227: https://source.small-tech.org/site.js/app/-/issues/227
//
// If the path to serve is the current path, Chokidar doesn’t pick up changes (e.g., to ./**/*).
// However, it does if a relative path is specified. So, as a workaround, we target
// ../<name of current folder>/**/* instead.
const relativePath = this.pathToServe === '.' ? (() => {
const pathFragments = path.resolve('.').split(path.sep)
const currentDirectoryName = pathFragments[pathFragments.length - 1]
return `../${currentDirectoryName}`
})() : this.pathToServe
const fileWatchPath = `${relativePath.replace(/\\/g, '/')}/**/*`
this.app.__fileWatcher = chokidar.watch(fileWatchPath, {
persistent: true,
......
{
"name": "@small-tech/site.js",
"version": "14.5.0",
"version": "14.5.1",
"description": "Small Web construction set.",
"keywords": [
"web server",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment