stringham / move-ts

A Visual Studio Code plugin for updating relative imports when moving typescript files and folders in your workspace.
MIT License
52 stars 15 forks source link

Support updating references in JS files #15

Open OliverJAsh opened 6 years ago

OliverJAsh commented 6 years ago

I have a TS project that uses the allowJs and checkJs compiler options.

Currently, if I use this extension to move a TS file/folder, none of the references from JS files are updated.

Is this due to https://github.com/stringham/move-ts/blob/b07397650865ef385d5ff49068bf7ae8d4bf28b4/src/index/referenceindexer.ts#L32?

Would this be easy to add support for?

stringham commented 6 years ago

Are you using es6 style import/export in your .js files?

OliverJAsh commented 6 years ago

@stringham Yes we are.

stringham commented 6 years ago

It would be possible to make this work, but I don't know how to tell the difference between a generated Js file and one that is part of the sources we care about. A lot of projects put the compiled js files next to their ts sources.

To make it work, changing the following might do it: 1) include .js and .jsx in the extensions array (we could make this user configurable). 2) Set the movets.filesToScan user preference to include the javascript files you care about in your project.

I don't have a project to test this on though, but if we tried this, it definitely won't affect users who don't care about allowJs/checkJs.

OliverJAsh commented 6 years ago

Couldn't we check if the file is in the dependency graph of the current TS project? I.e. by tracing the graph from the files, include and exclude options in tsconfig.json.

tnrich commented 4 years ago

@stringham @OliverJAsh I just tried @stringham 's suggestion above and it does indeed work for JS-only projects. I'm not sure about mixed js-ts projects. Maybe @OliverJAsh's suggestion would work:

Couldn't we check if the file is in the dependency graph of the current TS project? I.e. by tracing the graph from the files, include and exclude options in tsconfig.json.

@stringham I definitely think adding a "Move JS" command would be super useful. In the meantime I'm going to publish a fork of this repo that allows for JS to be moved.

stringham commented 4 years ago

@tnrich I'm happy to accept a pull request for this feature.

tnrich commented 4 years ago

@stringham I just published my fork which should do the trick for me. https://marketplace.visualstudio.com/items?itemName=tnrich.move-ts-js

I'm afraid that making a whole new command might be a bit too much work for me atm.

OliverJAsh commented 4 years ago

VS Code now has this functionality out of the box, so isn't this package now redundant?

tnrich commented 4 years ago

@OliverJAsh I haven't found that it works very well.. Maybe I'm mistaken but don't all the files in question have to be open for the path updates to take place?