Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Feat/watching nonexistant dependencies#97

Closed
staeke wants to merge 2 commits intowclr:masterfrom
staeke:feat/watching-nonexistant-dependencies
Closed

Feat/watching nonexistant dependencies#97
staeke wants to merge 2 commits intowclr:masterfrom
staeke:feat/watching-nonexistant-dependencies

Conversation

@staeke
Copy link

@staeke staeke commented Oct 4, 2019

Branched off #93

Fixes for dependencies on not (yet) existing files

@staeke
Copy link
Author

staeke commented Oct 4, 2019

ping @whitecolor - separated this out now

var lastRequire = m.lastRequire
if (m.code === 'MODULE_NOT_FOUND' && lastRequire && lastRequire.path.startsWith('.')) {
var pathNoExt = path.normalize(path.join(path.dirname(lastRequire.filename), lastRequire.path))
var watch = chokidar.watch([pathNoExt + '.ts', pathNoExt + '.tsx'])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just call watcher.add() here? What does chokidar do that filewatcher() cant?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonjaques Please enlighten me if I missed something, but watcher.add() didn't work with non-existant files when I tried

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naw, was legit curious.

As I understand it this PR is to handle the case where you're in an existing file and you import something that doesn't yet exist:

import {something} from './nonexistent'

This handles the error that would shut down ts-node-dev and then sets up a watcher for what would be ./nonexistent.ts|tsx.

I guess what I meant was, both filewatcher and chokidar are wrappers around the FS.watch, it just seems like conceptually this project should use one or the other.

So different question— could we switch all the filewatcher code to use chokidar instead? Last publish on filewatcher was 3 years ago.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm all for doing that @jonjaques! I think chokidar is more mature

However, I'm no official contributor. Could coordinate if @whitecolor made me

@wclr
Copy link
Owner

wclr commented Nov 30, 2019

Why need to add chokidar? And what are "nonexistant dependencies" could you elaborate workflow for this case?

@staeke
Copy link
Author

staeke commented Dec 29, 2019

@whitecolor I think @jonjaques explained it quite well

  1. A.ts requires B.ts but B.ts doesn't exist
  2. B.ts is created. This should lead to a recompile

That requires "watching" files that don't yet exist. I found no such support outside of chokidar. Again, I'm willing to migrate to using chokidar throughout.

@staeke
Copy link
Author

staeke commented Mar 21, 2020

ping again @whitecolor

@wclr
Copy link
Owner

wclr commented Jul 5, 2020

This doesn't work in the general case, as it is not possible to correctly resolve not existing dependency.

@wclr wclr closed this Jul 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants