Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 Feature: Export types #531

Closed
3 tasks done
joel-daros opened this issue Jun 12, 2024 · 9 comments · Fixed by #574 or #583
Closed
3 tasks done

🚀 Feature: Export types #531

joel-daros opened this issue Jun 12, 2024 · 9 comments · Fixed by #574 or #583
Assignees
Labels
status: accepting prs Please, send a pull request to resolve this! 🙏 type: feature New enhancement or request 🚀

Comments

@joel-daros
Copy link
Contributor

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Overview

I’m testing console-fail-test in one of our projects within our monorepo.
Our Vitest env is configured using a single vitest.config file pointing to a setupTest.ts file inside each monorepo project, so I can’t change the shared vitest config, because it will affect all projects.

Note that my setupTest.ts is a TS file, so when I’m importing console-fail-test TS is complaining about missing declaration types for this package:

As a workaround I had to add a couple of TS and Eslint ignores to bypass this issue:

// setupTest.ts

// @ts-expect-error console-fail-test is not exporting types
import { cft } from "console-fail-test";

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
cft();

Additional Info

No response

@joel-daros joel-daros added the type: feature New enhancement or request 🚀 label Jun 12, 2024
@JoshuaKGoldberg
Copy link
Owner

Ah, I would have thought this would have already been done by #209. Definitely a bug that should be fixed. Thanks for filing!

@JoshuaKGoldberg JoshuaKGoldberg added the status: accepting prs Please, send a pull request to resolve this! 🙏 label Jun 16, 2024
@JoshuaKGoldberg
Copy link
Owner

@all-contributors please add @joel-daros for ideas.

🤖 Beep boop! This comment was added automatically by all-contributors-auto-action.
Not all contributions can be detected from Git & GitHub alone. Please comment any missing contribution types this bot missed.
...and of course, thank you for contributing! 💙

Copy link
Contributor

@JoshuaKGoldberg

I've put up a pull request to add @joel-daros! 🎉

I couldn't determine any contributions to add, did you specify any contributions?
Please make sure to use valid contribution names.

JoshuaKGoldberg pushed a commit that referenced this issue Jun 17, 2024
Adds @joel-daros as a contributor for ideas.

This was requested by JoshuaKGoldberg [in this
comment](#531 (comment))

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
@joel-daros
Copy link
Contributor Author

@JoshuaKGoldberg I was inspecting this issue and it looks like there is something related to the package release action.

The build process is generating the types correctly in the lib folder, but there is something weird happening when the Github pipeline is trying to generate the release and upload it to npm. I think you’re using your JoshuaKGoldberg/release-it-action script for this, which I’m not familiar with.

I don’t know if there is anything related but, the code published in the npm isn’t actually the code built in lib folder but the source code.

@JoshuaKGoldberg
Copy link
Owner

Interesting! I also see the published package doesn't have provenance noted, the way more recent create-typescript-app projects do. I wonder if I'd manually published, forgot to create the .d.ts files at the time, and forgotten about it since?

Let me refresh the tooling now, publish a new patch version, and see where that goes...

@JoshuaKGoldberg JoshuaKGoldberg self-assigned this Jul 10, 2024
JoshuaKGoldberg added a commit that referenced this issue Jul 10, 2024
## PR Checklist

- [x] Addresses an existing open issue: fixes #531
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/console-fail-test/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/console-fail-test/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

Runs `npx create-typescript-app --auto --mode migrate`. Also runs an
`ncu -u` for everything (except `eslint`, as `typescript-eslint` doesn't
support ESLint v9 in stable yet).

This doesn't actually change build settings directly. But I'm betting
that getting all build-related packages up-to-date will resolve any
build oddities.
@JoshuaKGoldberg
Copy link
Owner

Ok looks like the 0.4.0 publish from #574 fixed things!

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYwGbwL51VCI4BEyEAdgM4QA2ApgLSoCGwltM1ZMBA3AFA9owAFAEouQA

import { cft } from "console-fail-test";

cft(); // This is typed now, hooray!

Thanks for the issue @joel-daros, I'm a bit relieved that this is working!

@joel-daros
Copy link
Contributor Author

joel-daros commented Jul 10, 2024

I really appreciate the fixes @JoshuaKGoldberg , but I think we still have an issue that is preventing the types from working correctly.

There are no errors in the TS playground, but when the package is installed locally in a real project, it still complains about missing types for console-fail-test.

I think the way you’re exposing the "exports" types in package.json is the culprit:

	"exports": {
		".": {
			"types": {
				"import": "./lib/index.d.mts",
				"require": "./lib/index.d.ts"
			},
			"import": "./lib/index.mjs",
			"require": "./lib/index.js"
		}
	},

I made some changes in my local env and looks like the changes bellow solve the issue:

"exports": {
  ".": {
      "import": {
        "types": "./lib/index.d.ts",
        "default": "./lib/index.js"
      },
      "require": {
        "types": "./lib/index.d.cts",
        "default": "./lib/index.cjs"
      }
    }
},

I’ll be happy to submit a PR with these changes if you agree that’s right way to solve it.

@JoshuaKGoldberg
Copy link
Owner

@arethetypeswrong/cli agrees:

$ npx -y @arethetypeswrong/cli -P
^[
console-fail-test v0.4.0

Build tools:
- typescript@5.5.3
- tsup@8.1.0

⚠️ A require call resolved to an ESM JavaScript file, which is an error in Node and some bundlers. CommonJS consumers will need to use a dynamic import. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/CJSResolvesToESM.md

💀 Import failed to resolve to type declarations or JavaScript files. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/NoResolution.md


┌───────────────────┬──────────────────────────────┐
│                   │ "console-fail-test"          │
├───────────────────┼──────────────────────────────┤
│ node10            │ 🟢                           │
├───────────────────┼──────────────────────────────┤
│ node16 (from CJS) │ ⚠️ ESM (dynamic import only) │
├───────────────────┼──────────────────────────────┤
│ node16 (from ESM) │ 💀 Resolution failed         │
├───────────────────┼──────────────────────────────┤
│ bundler           │ 💀 Resolution failed         │
└───────────────────┴──────────────────────────────┘

...and you're right @joel-daros - I was only checking the one module resolution mode on the playground. A PR would be lovely, yes please!

@joel-daros joel-daros mentioned this issue Jul 11, 2024
3 tasks
JoshuaKGoldberg pushed a commit that referenced this issue Jul 11, 2024
<!-- 👋 Hi, thanks for sending a PR to console-fail-test! 💖.
Please fill out all fields below and make sure each item is true and [x]
checked.
Otherwise we may not be able to review your PR. -->

## PR Checklist

- [X] Addresses an existing open issue: fixes #531
- [X] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/console-fail-test/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [X] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/console-fail-test/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

Fixed an issue regarding the exported types definitions in the
`package.json` :

```shell
$ npx -y @arethetypeswrong/cli -P

console-fail-test v0.4.0

Build tools:
- typescript@5.5.3
- tsup@8.1.0

 No problems found 🌟


┌───────────────────┬─────────────────────┐
│                   │ "console-fail-test" │
├───────────────────┼─────────────────────┤
│ node10            │ 🟢                  │
├───────────────────┼─────────────────────┤
│ node16 (from CJS) │ 🟢 (CJS)            │
├───────────────────┼─────────────────────┤
│ node16 (from ESM) │ 🟢 (ESM)            │
├───────────────────┼─────────────────────┤
│ bundler           │ 🟢                  │
└───────────────────┴─────────────────────┘
```

💖

Co-authored-by: Joel Daros <joel.daros@corteva.com>
Copy link

🎉 This is included in version v0.4.1 🎉

The release is available on:

Cheers! 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Please, send a pull request to resolve this! 🙏 type: feature New enhancement or request 🚀
Projects
None yet
2 participants