Skip to content

Commit ad02098

Browse files
committed
fix: add the types entry only when typescript target is present
1 parent 9aabd4c commit ad02098

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/cli.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,31 @@ yargs
8080
},
8181
]);
8282

83-
const target = targets[0];
84-
const entries = {
85-
main: path.join(output, target, 'index.js'),
86-
module: path.join(output, 'module', 'index.js'),
87-
types: path.join(output, 'typescript', source, 'index.d.ts'),
83+
const target =
84+
targets[0] === 'commonjs' || targets[0] === 'module'
85+
? targets[0]
86+
: undefined;
87+
88+
const entries: { [key: string]: string } = {
89+
main: target
90+
? path.join(output, target, 'index.js')
91+
: path.join(source, 'index.js'),
8892
'react-native': path.join(source, 'index.js'),
8993
};
9094

95+
if (targets.includes('module')) {
96+
entries.module = path.join(output, 'module', 'index.js');
97+
}
98+
99+
if (targets.includes('typescript')) {
100+
entries.types = path.join(output, 'typescript', source, 'index.d.ts');
101+
}
102+
91103
const prepare = 'bob build';
92104
const files = [source, output];
93105

94106
for (const key in entries) {
95-
// @ts-ignore
96-
const entry = entries[key] as string;
107+
const entry = entries[key];
97108

98109
if (pkg[key] && pkg[key] !== entry) {
99110
const { replace } = await inquirer.prompt({

src/targets/typescript.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ export default async function build({ root, output }: Input) {
1515
'--outDir',
1616
output,
1717
]);
18+
19+
logger.info(`wrote definition files to ${path.relative(root, output)}`);
1820
}

0 commit comments

Comments
 (0)