diff --git a/.changeset/slimy-roses-explain.md b/.changeset/slimy-roses-explain.md new file mode 100644 index 00000000..0a4c75ae --- /dev/null +++ b/.changeset/slimy-roses-explain.md @@ -0,0 +1,5 @@ +--- +'microbundle': patch +--- + +Expands generateTypes flag to support libs with TS entrypoints diff --git a/src/index.js b/src/index.js index 47448a08..e3314d9a 100644 --- a/src/index.js +++ b/src/index.js @@ -518,10 +518,12 @@ function createConfig(options, entry, format, writeMeta) { tsconfigDefaults: { compilerOptions: { sourceMap: options.sourcemap, - declaration: true, + declaration: options.generateTypes !== false, allowJs: true, emitDeclarationOnly: options.generateTypes && !useTypescript, - declarationDir: getDeclarationDir({ options, pkg }), + ...(options.generateTypes !== false && { + declarationDir: getDeclarationDir({ options, pkg }), + }), jsx: 'preserve', jsxFactory: // TypeScript fails to resolve Fragments when jsxFactory diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap index e70c9176..3f5ad93e 100644 --- a/test/__snapshots__/index.test.js.snap +++ b/test/__snapshots__/index.test.js.snap @@ -2728,9 +2728,10 @@ ts-custom-declaration index.js.map index.umd.js index.umd.js.map + node_modules package.json src - index.js + index.ts tsconfig.json types index.d.ts diff --git a/test/fixtures/ts-custom-declaration/package.json b/test/fixtures/ts-custom-declaration/package.json index 2fd7573b..00a923ee 100644 --- a/test/fixtures/ts-custom-declaration/package.json +++ b/test/fixtures/ts-custom-declaration/package.json @@ -2,7 +2,7 @@ "name": "ts-custom-declarations", "main": "dist/index.js", "types": "types/index.d.ts", - "source": "src/index.js", + "source": "src/index.ts", "scripts": { "build": "microbundle --generateTypes false" } diff --git a/test/fixtures/ts-custom-declaration/src/index.js b/test/fixtures/ts-custom-declaration/src/index.ts similarity index 100% rename from test/fixtures/ts-custom-declaration/src/index.js rename to test/fixtures/ts-custom-declaration/src/index.ts