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

getSourceFiles returning multiple instances of the same file #348

Closed
crisbeto opened this issue Jun 19, 2018 · 7 comments
Closed

getSourceFiles returning multiple instances of the same file #348

crisbeto opened this issue Jun 19, 2018 · 7 comments
Labels

Comments

@crisbeto
Copy link

I'm sorry for the vague report, but this is part of a larger project and I haven't been able to isolate the issue. I have a setup that looks like this:

const project = new Project({
  useVirtualFileSystem: true
});

glob(someFilePattern).forEach(filePath => {
  project.createSourceFile(filePath, readFileSync(filePath).toString());
});

console.log(project.getSourceFiles().map(sf => sf.getFilePath()));

In the console.log at the end I get an array that has multiple instances of each file (for a 42-file project I get back 663 results), e.g. the array looks like ['foo.ts', 'bar.ts', 'foo.ts', 'bar.ts']. A few notes:

  • I'm confident that the logic that creates the source files in the first place doesn't have any duplicates, and even if it did, ts-simple-ast would throw an error if I tried to create the file again.
  • This started happening after updating from 10.2.0 to 12.4.0.
  • The references in the array returned by getSourceFiles are all pointing to the same object which means that it's probably not creating multiple instances of the same file.
  • The issue can be worked around using getSourceFiles('**/*.ts').
@dsherret dsherret added the bug label Jun 19, 2018
@dsherret
Copy link
Owner

Hmmm that’s strange. Usually I’m really fast at fixing bugs, but unfortunately I’m moving this week so I’ll take a look sometime next week.

@cancerberoSgx
Copy link
Contributor

Hey @crisbeto , just out of curiosity, since I can't reproduce this, could you share the value of someFilePattern and more or less the structure of the current folder ? is it a TypeScript project ? does it have tsconfig.json and package.json files ? what happen if you run it using absolute glob from another folder ? What happens if you add a minimal compilerOptions ? :

compilerOptions: {
        target: ScriptTarget.ES3
    }

Thanks

@dsherret
Copy link
Owner

It makes sense that it's a recent bug because I did some refactoring in this area recently. I haven't been able to reproduce it though, but I will do a review of the code again soon and I should be able to find the problem. Regardless, I'll submit a change that will cause an error to be throw in case it ends up in this state and that will help us catch this situation.

Unfortunately since my move I haven't been able to setup my desktop at home because I'm doing some renovations. Hopefully I'll be able to set it up this weekend and then look into this further. I'm looking forward to getting back to work on this project soon... but my home is a construction site at the moment (getting close to being done).

@dominique-mueller
Copy link

I am experiencing the same issue, suddenly 133 files become 135, two files are duplicate. Also, I can confirm that the workaround of selecting source files using getSourceFiles( "**/*.ts" ) works.

@dsherret
Copy link
Owner

dsherret commented Jul 2, 2018

@crisbeto @dominique-mueller I didn't mean to close this just yet. Since I wasn't able to reproduce this could you see if the latest fix in 12.4.1 resolved this issue? Thanks!

Also, sorry for the delay. I finally got my desk setup last night.

@dominique-mueller
Copy link

I did upgrade to 12.5.0 right away, and the issue no longer appears in my project! Thanks for the quick fix!

@crisbeto
Copy link
Author

crisbeto commented Jul 2, 2018

I can also confirm that the issue is fixed. Thank you @dsherret!

@crisbeto crisbeto closed this as completed Jul 2, 2018
dsherret added a commit that referenced this issue May 14, 2019
…instances of the same source file.

Should do a locale comparison for keeping files in "order" during the binary insert rather than a case insensitive comparison.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants