Skip to content

Commit 851470e

Browse files
committed
fix: use the correct entry file
1 parent 15da7ce commit 851470e

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/cli.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ yargs
3636
`Couldn't find a 'package.json' file in '${root}'. Are you in a project folder?`
3737
);
3838
}
39+
3940
const { source } = await inquirer.prompt({
4041
type: 'input',
4142
name: 'source',
@@ -44,16 +45,21 @@ yargs
4445
validate: input => Boolean(input),
4546
});
4647

47-
if (
48-
!(
49-
(await fs.pathExists(path.join(root, source, 'index.js'))) ||
50-
(await fs.pathExists(path.join(root, source, 'index.ts'))) ||
51-
(await fs.pathExists(path.join(root, source, 'index.tsx')))
52-
)
53-
) {
48+
let entryFile;
49+
50+
if (await fs.pathExists(path.join(root, source, 'index.js'))) {
51+
entryFile = 'index.js';
52+
} else if (await fs.pathExists(path.join(root, source, 'index.ts'))) {
53+
entryFile = 'index.ts';
54+
} else if (await fs.pathExists(path.join(root, source, 'index.tsx'))) {
55+
entryFile = 'index.tsx';
56+
}
57+
58+
if (!entryFile) {
5459
logger.exit(
5560
`Couldn't find a 'index.js'. 'index.ts' or 'index.tsx' file under '${source}'. Please re-run the CLI after creating it.`
5661
);
62+
return;
5763
}
5864

5965
const pkg = JSON.parse(await fs.readFile(pak, 'utf-8'));
@@ -88,8 +94,8 @@ yargs
8894
const entries: { [key: string]: string } = {
8995
main: target
9096
? path.join(output, target, 'index.js')
91-
: path.join(source, 'index.js'),
92-
'react-native': path.join(source, 'index.js'),
97+
: path.join(source, entryFile),
98+
'react-native': path.join(source, entryFile),
9399
};
94100

95101
if (targets.includes('module')) {

0 commit comments

Comments
 (0)