Description
Proposal
Currently, whenever flow-node
(from the flow-remove-types package) encounters a require
statement, it considers the contents of that package to be written in Flow.
However, this is not the case for Node packages written with import
statements.
This is an issue if the import specifier refers to a symlinked package inside the same monorepo. The developer would expect flow-node to transpile the contents of such packages.
Use case
Consider a monorepo project with two packages: package-a
and package-b
packages
├── package-a
│ ├── index.js
│ └── package.json
└── package-b
├── index.js
└── package.json
The contents of package-a/index.js are
// @flow
export function log(str: string) {
console.log(str);
}
The contents of package-b/index.js are
// @flow
import { log } from "package-a";
log("abc");
When running npx flow-node packages/package-b/index.js
, you'll get an error because flow-node won't understand the flow syntax in package-a.
export function log(str: string) {
^
SyntaxError: Unexpected token ':'
at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:139:18)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:236:14)
When removing the type annotations, or converting packages to use exports/require statements, it works.