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

Change TypeScript definitions for ESM #7309

Merged
merged 2 commits into from Nov 9, 2023
Merged

Change TypeScript definitions for ESM #7309

merged 2 commits into from Nov 9, 2023

Conversation

ybiquitous
Copy link
Member

@ybiquitous ybiquitous commented Nov 7, 2023

Which issue, if any, is this issue related to?

Follow-up to #5291
Wait for #7307
Block #7160

Is there anything in the PR that needs further explanation?

This Pull Request mainly updates the TypeScript definitions for ESM.

Summary:

  • Rewrite TypeScript definitions to use ESM syntax, avoiding the specific syntax like namespace.
  • Update tsconfig.json for ESM and Node.js 18.
  • Remove no longer needed test.d.ts.
  • Add a patch for the is-plain-object package to avoid type-check errors.

See also:

Summary:
- Rewrite TypeScript definitions to use ESM syntax, avoiding the specific syntax like `namespace`.
- Update `tsconfig.json` for ESM and Node.js 18.
- Remove no longer needed `test.d.ts`.
- Add a patch for the `is-plain-object` package to avoid type-check errors.

See also:
- https://www.typescriptlang.org/tsconfig
- https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#package-json-exports-imports-and-self-referencing
- jonschlinkert/is-plain-object#28
Copy link

changeset-bot bot commented Nov 7, 2023

🦋 Changeset detected

Latest commit: bcca595

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
stylelint Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member Author

@ybiquitous ybiquitous Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note] I recommend reviewing this file ignoring whitespaces.

tsconfig.json Show resolved Hide resolved
"module": "commonjs",
"lib": ["ES2021", "DOM"],
"module": "Node16",
"moduleResolution": "Node16",
Copy link
Member

@Mouvedia Mouvedia Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

info

node16 and nodenext are currently identical, with the exception that they imply different target option values. If Node.js makes significant changes to its module system in the future, node16 will be frozen while nodenext will be updated to reflect the new behavior.

and since

--module nodenext implies --target esnext
--module node16 implies --target es2022

node16 is the right choice.

@ybiquitous ybiquitous mentioned this pull request Nov 8, 2023
10 tasks
@ybiquitous ybiquitous marked this pull request as ready for review November 9, 2023 00:26
tsconfig.json Show resolved Hide resolved
Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@ybiquitous ybiquitous merged commit a1aac9f into v16 Nov 9, 2023
14 checks passed
@ybiquitous ybiquitous deleted the fix-types-for-esm branch November 9, 2023 12:14
@remcohaszing
Copy link
Contributor

This change broke type definitions for CJS. It also didn’t add type definitions for ESM, meaning ESM types now fallback to the broken CJS types.

https://arethetypeswrong.github.io?p=stylelint@16.0.0

};
};

declare const stylelint: PublicApi;

export = stylelint;
export default stylelint;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but the removal of the stylelint namespace is related.

If you publish both CJS and ESM JavaScript code, you also need to publish both CJS and ESM type definitions. I have a hunch this is as simple as:

// index.d.mts
export * from './index.js'
export { default } from './index.js'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@remcohaszing Thank you. Is there a way to test both types on CI or localhost?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I’ll send a PR.

@ybiquitous
Copy link
Member Author

@remcohaszing @Mouvedia Thanks for the reminder! I'll open a patch PR after the ongoing 16.0.0 release.

Or I'd appreciate it if you could open a PR instead of me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants