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

fix: default package exports #15869

Draft
wants to merge 4 commits into
base: next
Choose a base branch
from

Conversation

userquin
Copy link

@userquin userquin commented Jan 25, 2025

This PR includes the following changes to the packages/tailwindcss package (check Context):

  • fixes the default packages exports for node10 and node16 cjs types
  • export types in plugin.ts module, cannot be used with Typescript 5.7
  • add "type": "commonjs" to package.json
  • add ./lib/util/flattenColorPalette.js variant to package.json exports (publishConfig)

Context
The current version at npm registry has all types broken for all packages exports. The problem seems to be with tsup since it is not applying the .cts hack, all d.ts files using export { X as default };, check https://arethetypeswrong.github.io/?p=tailwindcss%404.0.0 .

With this PR (for context check this PR unjs/unbuild#475 and this md file https://github.com/unjs/unbuild/blob/a011a7831e2004688bf44716f5e9c9377d08ebec/src/builders/rollup/plugins/cjs.md):

image

This PR includes a new script module that runs after tsup finish building the dist, extracting the default export and applying some replacements in the files including the default export correclty: export = X; and remaining named exports in the default export statement.

About exporting the types in the plugin.ts module, when using TypeScript 5.7 there is an error. Using the following code with any module resolution

import plugin from 'tailwindcss/plugin'

const exportedPlugin = plugin.withOptions(() => {
	return ({ matchComponents }) => {
		matchComponents({
			test: (content: string) => {
				return {
					color: content,
				};
			},
		});
	};
});

export default exportedPlugin;

and building it via tsc -b, there is an error about required annotation:

image

Using a local tgz from this PR, TypeScript is fine when building the module:

image

You can generate the local tgz using this PR in the following repository (use packages/plugin): https://github.com/iconify/iconify-tailwind

@userquin userquin requested a review from a team as a code owner January 25, 2025 21:28
@userquin
Copy link
Author

We should add "type": "commonjs" to the package.json.

@userquin
Copy link
Author

We should add "type": "commonjs" to the package.json.

@userquin userquin changed the title fix(tailwind): default package exports fix(tailwindcss): default package exports Jan 25, 2025
@userquin
Copy link
Author

userquin commented Jan 27, 2025

Looks like @tailwindcss/node package also broken, this is the index.d.ts content (index.d.mts with same imports)

Downloaded tgz file from npm registry: https://registry.npmjs.org/@tailwindcss/node/-/node-4.0.0.tgz

image

@userquin userquin marked this pull request as draft January 27, 2025 15:00
@userquin userquin changed the title fix(tailwindcss): default package exports fix: default package exports Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant