adamreisnz / replace-in-file

A simple utility to quickly replace contents in one or more files
580 stars 65 forks source link

Missing type for `processor` in `ReplaceInFileConfig` #170

Closed julrich closed 4 months ago

julrich commented 1 year ago

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

adamreisnz commented 1 year ago

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!

julrich commented 1 year ago

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!

adamreisnz commented 1 year ago

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!

julrich commented 1 year ago

Cool, I'll have a go, then!

lodossDev commented 9 months ago

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

julrich commented 9 months ago

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

zach-babb-ef commented 8 months ago

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.

adamreisnz commented 8 months ago

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

julrich commented 8 months ago

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

kduprey commented 4 months ago

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

adamreisnz commented 4 months ago

Thank you, merged and release in 7.2.0