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

Watching of serve command doesn't seem to be recursive #15

Closed
mnn opened this issue Jun 7, 2020 · 6 comments
Closed

Watching of serve command doesn't seem to be recursive #15

mnn opened this issue Jun 7, 2020 · 6 comments
Labels
bug Something isn't working

Comments

@mnn
Copy link

mnn commented Jun 7, 2020

I am not sure if it is a bug (if recursive watching is intended to work), but I believe such feature would be useful.

$ tree docs
docs
├── assets
│   ├── codedoc-bundle.entry.js
│   ├── codedoc-bundle.js
│   ├── codedoc-bundle.meta.json
│   └── codedoc-styles.css
├── dist
│   ├── api
│   │   └── index.html
│   ├── codedoc-bundle.entry.js
│   ├── codedoc-bundle.js
│   ├── codedoc-bundle.meta.json
│   ├── codedoc-styles.css
│   └── index.html
└── md
    ├── api
    │   └── index.md
    ├── index.md
    └── _toc.md

when I run codedoc serve, it doesn't pickup changes in docs/md/api/index.md (it detects changes in docs/md/index.md correctly).

It's possible I have it misconfigured, my config.ts (which works for serve and build, meaning it compiles and paths are correct):

import {configuration} from '@codedoc/core';

import {theme} from './theme';


export const config = /*#__PURE__*/configuration({
  theme,                                  // --> add the theme. modify `./theme.ts` for chaning the theme.

  page: {
    title: {
      base: 'Golden Gadget'               // --> the base title of your doc pages
    }
  },

  dest: {
    html: 'docs/dist',
    assets: 'docs/dist',
    bundle: '.',
    styles: '.',
    namespace: '/golden-gadget'
  }

});

I don't think I changed any other file (except index.tsx in content, but that should not be related, just the hamburger being opened by default).


If anyone encounters similar issue, here is my current workaround:

find docs/md | entr -r codedoc serve
@loreanvictor loreanvictor added the bug Something isn't working label Jun 7, 2020
@loreanvictor
Copy link
Contributor

loreanvictor commented Jun 7, 2020

This is a bug. The recursive watching of source markdown files (src.base parameter in configs, which defaults to docs/md) should be supported.

I am unable to reproduce locally (node v 12.16.0 / macOS). What is your node version / OS? Apparently there are issues with ts-node-dev's recursive file watching and node 14.

I am not sure if it will actually be fixed anytime soon or if lower versions of node will solve the issue, as this seems to be a caveat of node's own fs.watch API which stops it from properly functioning on platforms other than Windows and macOS. The behavior change that results in raised issues is evidently due to node 14 throwing an error vs previous versions silently ignoring it.

I'll keep this issue open to monitor the situation with ts-node-dev issues. If there is no fix in near future for this, I suspect the best course of action would be to look for an alternative at least for non-Windows/macOs machines (though that perhaps leads to slower reload times on dev).

P.S. @mnn in the meantime you can actually add your work-around in .codedoc/watch.ts, so that codedoc serve (or codedoc s) would work for you (if it is more convenient). I suspect it would look something like this:

// .codedoc/watch.ts

import { exec, spawn } from 'child_process';
import { config } from './config';

const cmd = 'find'; 
const params = `${config.src.base} | entr -r ts-node .codedoc/serve`;

// ...

(Though you would need to test to ensure this works).

@mnn
Copy link
Author

mnn commented Jun 7, 2020

I am using Linux 64b (Manjaro) and node 13.12.0.

Oh yes, multiplatform file watching is rather problematic. This is not a first time I hit similar issue, most likely caused by the same underlying cause.

Thank you very much for the tip, it lead me to this (a bit convoluted) solution:

const cmd = 'find';
const params = `${config.src.base} | entr -r npx --no-install ts-node -P .codedoc/tsconfig.json .codedoc/serve`;

@loreanvictor
Copy link
Contributor

thats a nice work-around.

unfortunately, filewatcher (which is used by ts-node-dev for watching files) itself seems to be dead, so a stable/performant solution might not come soon. I will play around with a fork of filewatcher / ts-node-dev that uses this package instead, see if it works out.

if this drags out long, I will add your solution to the boilerplate repo so that new repositories will use entr instead of ts-node-dev on linux machines. I am just a bit hesitant due to the performance drawback.

@loreanvictor
Copy link
Contributor

as part of this commit, this also should be fixed. the fix is deployed via the combination of @codedoc/[email protected] and @codedoc/[email protected], and you should be able to update to it like this:

npm i -g @codedoc/cli@latest
codedoc update latest

in this update, tiered watching is used, and markdown files are now watched using node-watch, which should be able to properly watch recursive file changes on Linux machines as well. ts-node-dev is only used for watching TypeScript code, which should already be working properly with recursive watching even on Linux machines.

@mnn since I do not have a Linux machine for testing, I am going to keep this issue open for now until you confirm this update fixes the recursive watching issue.

@mnn
Copy link
Author

mnn commented Jun 11, 2020

Sorry, don't have much free time now. Just quickly tested it on a fresh project (same directory structure as my original project), and change detection is working now 🙂. Thank you very much.

@mnn mnn closed this as completed Jun 11, 2020
@loreanvictor
Copy link
Contributor

Sorry, don't have much free time now. Just quickly tested it on a fresh project (same directory structure as my original project), and change detection is working now 🙂. Thank you very much.

thank you for testing, and that was still pretty fast!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants