move-ts icon indicating copy to clipboard operation
move-ts copied to clipboard

Support updating references in JS files

Open OliverJAsh opened this issue 7 years ago • 9 comments

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?

OliverJAsh avatar Jan 23 '18 13:01 OliverJAsh

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

stringham avatar Feb 02 '18 05:02 stringham

@stringham Yes we are.

OliverJAsh avatar Feb 02 '18 13:02 OliverJAsh

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.

stringham avatar Feb 02 '18 18:02 stringham

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.

OliverJAsh avatar Feb 05 '18 11:02 OliverJAsh

@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.

tnrich avatar Jan 16 '20 21:01 tnrich

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

stringham avatar Jan 16 '20 22:01 stringham

@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.

tnrich avatar Jan 16 '20 22:01 tnrich

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

OliverJAsh avatar Jan 16 '20 22:01 OliverJAsh

@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?

tnrich avatar Jan 16 '20 22:01 tnrich