From 29803364fe54cc1a7a8543d61e694c90b4cdce6a Mon Sep 17 00:00:00 2001 From: Ryan Christian <33403762+rschristian@users.noreply.github.com> Date: Wed, 6 Oct 2021 09:07:28 -0500 Subject: [PATCH] feat: Expands generateTypes flag to support TS entries (#865) * feat: Expands generateTypes flag to support TS entries * fix: Returning previous .d.ts generation * test: Modifying `--generateTypes false` test for use on TS projects * docs: Adding changeset --- .changeset/slimy-roses-explain.md | 5 +++++ src/index.js | 6 ++++-- test/__snapshots__/index.test.js.snap | 3 ++- test/fixtures/ts-custom-declaration/package.json | 2 +- .../ts-custom-declaration/src/{index.js => index.ts} | 0 5 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 .changeset/slimy-roses-explain.md rename test/fixtures/ts-custom-declaration/src/{index.js => index.ts} (100%) 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 7ad55a0f..27619981 100644 --- a/src/index.js +++ b/src/index.js @@ -524,10 +524,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 a2a9d88b..6f4aacb9 100644 --- a/test/__snapshots__/index.test.js.snap +++ b/test/__snapshots__/index.test.js.snap @@ -2730,9 +2730,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