replace-in-file icon indicating copy to clipboard operation
replace-in-file copied to clipboard

Missing type for `processor` in `ReplaceInFileConfig`

Open julrich opened this issue 2 years ago • 9 comments

I think this one is just plain missing, right? Same for the array version of it?

https://github.com/adamreisnz/replace-in-file#custom-processor https://github.com/adamreisnz/replace-in-file/blob/main/types/index.d.ts#L20-L31

... and after a small patch attempt locally... probably also need to make from and to optional, then? Maybe this could be done more elegantly with some type of discriminator?

image

This looks interesting: https://stackoverflow.com/a/49265354

julrich avatar Sep 30 '23 13:09 julrich

Hi, if you are referring to typescript types, I haven't been managing those, but you're welcome to submit a PR to fix if needed. Thanks!

adamreisnz avatar Sep 30 '23 22:09 adamreisnz

Cool, I'll have a look! Who maintained these before, do you know? Maybe makes sense to coordinate. If they're just not really maintained at all currently... it should be a quick fix!

julrich avatar Oct 01 '23 12:10 julrich

I am not sure, you could look at the past PR's related to typescript. Not really maintained though, so you're welcome to take charge!

adamreisnz avatar Oct 11 '23 06:10 adamreisnz

Cool, I'll have a go, then!

julrich avatar Oct 11 '23 09:10 julrich

hi, what happened to this? i am not sure how to fix this using typescript?

lodossDev avatar Jan 10 '24 13:01 lodossDev

Hey @lodossDev, we're still living with a local patch for this, as I haven't found the time to investigate this more in-depth. Don't want to contribute something that's working for us, but nobody else :D

If you're feeling experimental, you can try the patch we're currently using:

diff --git a/node_modules/replace-in-file/types/index.d.ts b/node_modules/replace-in-file/types/index.d.ts
index 97409d5..bd88df2 100644
--- a/node_modules/replace-in-file/types/index.d.ts
+++ b/node_modules/replace-in-file/types/index.d.ts
@@ -1,7 +1,5 @@
 
 declare module 'replace-in-file' {
-  export function replaceInFile(config: ReplaceInFileConfig): Promise<ReplaceResult[]>;
-  export function replaceInFile(config: ReplaceInFileConfig, cb: (error: Error, results: ReplaceResult[]) => void): void;
   export default replaceInFile;
 
   namespace replaceInFile {
@@ -11,9 +9,6 @@ declare module 'replace-in-file' {
     export function replaceInFile(config: ReplaceInFileConfig, cb: (error: Error, results: ReplaceResult[]) => void): void;
   }
 
-  export function sync(config: ReplaceInFileConfig): ReplaceResult[];
-  export function replaceInFileSync(config: ReplaceInFileConfig): ReplaceResult[];
-
   export type From = string | RegExp | FromCallback;
   export type To = string | ToCallback;

We're applying it using https://www.npmjs.com/package/patch-package

julrich avatar Jan 10 '24 15:01 julrich

I have a pr for this, but not permissions to the repo if someone wants to add me. Fwiw OP is correct. I also cleaned up the syntax of the type to make it consistent.

zach-babb-ef avatar Feb 09 '24 18:02 zach-babb-ef

You can simply submit your PR and I will review/approve it, thank you!

adamreisnz avatar Feb 12 '24 21:02 adamreisnz

Thank you a lot, @zach-babb-ef :raised_hands:

julrich avatar Feb 13 '24 08:02 julrich

@adamreisnz - Are we able to get this PR merged?

kduprey avatar May 24 '24 18:05 kduprey

Thank you, merged and release in 7.2.0

adamreisnz avatar May 26 '24 21:05 adamreisnz