1 |
|
2 |
|
3 | import type {Config, PluginOptions} from '@parcel/types';
|
4 | import type {BabelConfig} from './types';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export default async function getFlowOptions(
|
10 | config: Config,
|
11 | options: PluginOptions,
|
12 | ): Promise<?BabelConfig> {
|
13 | if (!config.isSource) {
|
14 | return null;
|
15 | }
|
16 |
|
17 |
|
18 | let conf = await config.getConfigFrom(options.projectRoot + '/index', [
|
19 | 'package.json',
|
20 | ]);
|
21 | let pkg = conf?.contents;
|
22 | if (
|
23 | !pkg ||
|
24 | (!(pkg.dependencies && pkg.dependencies['flow-bin']) &&
|
25 | !(pkg.devDependencies && pkg.devDependencies['flow-bin']))
|
26 | ) {
|
27 | return null;
|
28 | }
|
29 |
|
30 | return {
|
31 | plugins: [
|
32 | ['@babel/plugin-transform-flow-strip-types', {requireDirective: true}],
|
33 | ],
|
34 | };
|
35 | }
|