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

Overwrite when calling createSourceFile #273

Closed
lazarljubenovic opened this issue Mar 11, 2018 · 6 comments
Closed

Overwrite when calling createSourceFile #273

lazarljubenovic opened this issue Mar 11, 2018 · 6 comments

Comments

@lazarljubenovic
Copy link
Contributor

After a quick search, I've found that apparently this option was considered for some operations but not for all, such as save and saveSync. It would be nice if we could overwrite when saving a file.

Seems to me like I have to manually delete the file, maybe there's another way?

@dsherret
Copy link
Owner

Can you post a short snippet of code that shows the problem? It should be overwriting.

@lazarljubenovic
Copy link
Contributor Author

lazarljubenovic commented Mar 11, 2018

Oh? It tells me:

/home/lazar/ts-ast/node_modules/ts-simple-ast/dist/factories/CompilerFactory.js:154
        throw new errors.InvalidOperationError(prefixMessage + "A source file already exists at the provided file path: " + filePath);
        ^

Error: A source file already exists at the provided file path: /home/lazar/ts-ast/demo2-counter/compiled/RootPageComponent.factory.js

I'm just creating a file, writing a function into it and then saving it with saveAsync. I'll create a full repro tonight.

@dsherret
Copy link
Owner

Oh ok. That makes sense. That error happens on createSourceFile (not on save).

I’ll think about this... probably will add an options object as the third parameter.

@dsherret dsherret changed the title Overwrite when saving Overwrite when calling createsSourceFile Mar 11, 2018
@dsherret dsherret changed the title Overwrite when calling createsSourceFile Overwrite when calling createSourceFile Mar 11, 2018
@lazarljubenovic
Copy link
Contributor Author

Oh, I didn't even notice where it happens. Sorry for the confusion and thanks! 😅

@dsherret
Copy link
Owner

dsherret commented Mar 25, 2018

This will be in the next release (tomorrow evening probably Edit: Nevermind, need to finish the other issues in the version 10 milestone... sometime this week or next).

const sourceFile = project.createSourceFile("/file.ts", "", { overwrite: true });

In the future, there will probably be more options.

@dsherret dsherret added this to the Version 10 milestone Mar 25, 2018
@dsherret
Copy link
Owner

This is available now in 10.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants