flow-api-translator 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +44 -0
- package/dist/flowDefToTSDef.js +2325 -0
- package/dist/flowDefToTSDef.js.flow +2507 -0
- package/dist/flowImportTo.js +73 -0
- package/dist/flowImportTo.js.flow +73 -0
- package/dist/flowToFlowDef.js +932 -0
- package/dist/flowToFlowDef.js.flow +1303 -0
- package/dist/flowToJS.js +188 -0
- package/dist/flowToJS.js.flow +166 -0
- package/dist/index.js +78 -0
- package/dist/index.js.flow +84 -0
- package/dist/utils/DocblockUtils.js +33 -0
- package/dist/utils/DocblockUtils.js.flow +36 -0
- package/dist/utils/ErrorUtils.js +102 -0
- package/dist/utils/ErrorUtils.js.flow +100 -0
- package/dist/utils/FlowAnalyze.js +55 -0
- package/dist/utils/FlowAnalyze.js.flow +47 -0
- package/dist/utils/TranslationUtils.js +42 -0
- package/dist/utils/TranslationUtils.js.flow +44 -0
- package/dist/utils/ts-estree-ast-types.js +30 -0
- package/dist/utils/ts-estree-ast-types.js.flow +2052 -0
- package/package.json +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# flow-api-translator
|
|
2
|
+
|
|
3
|
+
`flow-api-translator` enables creating Flow and TypeScript compatible libraries from Flow source code.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
This package provides a toolkit of different translation tools to support a number of different JavaScript based language targets from Flow source code.
|
|
8
|
+
|
|
9
|
+
An important distinction with this translator and others is this is not intended as a migration tool away from Flow, instead the expectation is the source code will continue to be checked by Flow but this translator provides the ability to seamlessly integrate with external Flow, TypeScript and JavaScript based projects.
|
|
10
|
+
|
|
11
|
+
Below are some common use cases:
|
|
12
|
+
|
|
13
|
+
### Flow -> Flow Lib
|
|
14
|
+
|
|
15
|
+
Creating a Flow type definition and runtime files from Flow source code is simple. Just get the source text then pass it to the respective translators:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
const sourceFile = await fs.readFile('myFile.js', 'utf8');
|
|
19
|
+
await fs.writeFile('output/myFile.js.flow', translate.translateFlowToFlowDef(sourceFile, prettierConfig));
|
|
20
|
+
await fs.writeFile('output/myFile.js', translate.translateFlowToJS(sourceFile, prettierConfig));
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Flow -> TS Lib
|
|
24
|
+
|
|
25
|
+
Further conversion to TypeScript definition files is supported. To do this, get the source text and pass it to the respective translators:
|
|
26
|
+
```
|
|
27
|
+
const sourceFile = await fs.readFile('myFile.js', 'utf8');
|
|
28
|
+
await fs.writeFile('output/myFile.d.ts', translate.translateFlowToTSDef(sourceFile, prettierConfig));
|
|
29
|
+
await fs.writeFile('output/myFile.js', translate.translateFlowToJS(sourceFile, prettierConfig));
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Flow (with Haste modules) -> TS Lib
|
|
33
|
+
|
|
34
|
+
Haste module paths are commonly used with Flow libraries. TypeScript does not support this so they needs to be converted back to relative paths first:
|
|
35
|
+
```
|
|
36
|
+
const sourceFile = await fs.readFile('myFile.js', 'utf8');
|
|
37
|
+
const mappedSourceFile = translate.translateFlowImportsTo(
|
|
38
|
+
fileContents,
|
|
39
|
+
prettierConfig,
|
|
40
|
+
{sourceMapper: ({module}) => path.relative(currentLocation, ModuleMap.getModulePath(module))},
|
|
41
|
+
);
|
|
42
|
+
await fs.writeFile('output/myFile.js.flow', translate.translateFlowToTSDef(mappedSourceFile, prettierConfig));
|
|
43
|
+
await fs.writeFile('output/myFile.js', translate.translateFlowToJS(mappedSourceFile, prettierConfig));
|
|
44
|
+
```
|