How to expand the bunker to support new Node.js methods?

Is there a way to work around errors with flow-bin when the tool reports errors, where is it really an error with flow itself?

For example, using the Flow v0.62 method and Node.js Buffer#swap64 :

 Error: lib/index.js:88 88: int64buf.swap64() // turn into Little-Endian ^^^^^^ property `swap64`. Property not found in 88: int64buf.swap64() // turn into Little-Endian ^^^^^^^^ Buffer 

According to the documentation for Node, I am sure that the method exists. I really don't want to fork the Flow project to fix something so small.

Is there a workaround while I wait for the transfer request to be accepted by Facebook?

+5
source share
1 answer

A solution has been discovered that allows me to override Node.js advertised Flow ads using internally.

Flow allows you to use the $projectRoot/flow-typed folder to include custom type declarations, which are most often used to include npm shared library declarations.

The same folder can also be used to override some of the types used by the stream inside its standard Node.js library.

I had to create a file called $projectRoot/flow-typed/node.js and copy entire sections from https://github.com/facebook/flow/blob/master/lib/node.js to this file. Copying partial sections does not work because Flow does not support extension of declared types at this time ( https://github.com/facebook/flow/issues/396 .)

For example, take a Transform stream and add arguments of type objectMode to your _transform method. Looks like this -

 declare class stream$Transform extends stream$Duplex { _transform( chunk: Buffer | string | Object, encoding: string, callback: (error: ?Error, data?: Buffer | string | Object) => void ): void; _flush( callback: (error: ?Error) => void ): void; } 

where is every Buffer | String Buffer | String been replaced by include Object .

The file /flow-typed/node.js managed in version control of the project. But as soon as the newer version of Flow supports the additional syntax in Node.js, this declaration can be removed. Meanwhile, it solves errors in the stream caused by the fact that the stream lags behind Node.js and its general incorrectness.

+4
source

Source: https://habr.com/ru/post/1274442/


All Articles