-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
chore: output type definitions #2392
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
base: develop
Are you sure you want to change the base?
Conversation
…ked up in consumer projects
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand it, this PR is intended to support users who are consuming Docsify as an ESM module, correct?
If so, I don't think we should be distributing TypeScript definitions until end users are able to actually benefit from them. Since Docsify currently can not be consumed as an ESM module, there is no real-world benefit to generating a d.ts file. That may change in the future, but until then these changes only add complexity to the project and stand to confuse users who may wonder why we offer a d.ts file when there is no way to use it.
My concern here is with merging code to support future work that we don't have commitments for or documentation to support. I've implemented similar configurations in my own projects (e.g. mergician) so I am not opposed to the approach used in the PR. I simply prefer to see these changes incorporated as part of a larger "Docsify as ESM module" effort since the benefits of the changes in the PR are only realized when the larger effort is complete.
… package for people to start importing `Docsify` and passing in non-global configs
|
IMO,for current propose to replace |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good example of why these types of changes should be introduced as either a new issue (better for triage/tracking) or discussion (better for higher-level discussions that produce issue(s) to track/triage) instead of a PR. What started off as a PR about generating TypeScript types has evolved into a discussion involving ESM modules, deprecating globals, and componentization. These are all good things to discuss, but the comments section of this PR is not the right place IMHO.
@trusktr -- There's some good stuff in here, so please don't take the above comment negatively. I am onboard with the core concepts of what is being proposed here, but I'd like us to align and execute efficiently since we have limited resources available. For example:
- We cannot deprecate Docsify globals because we have agreed to keep v5 compatible with v4 with the exception of SSR and legacy browser support. Deprecating globals would therefore have to be targeted for a future release.
- We could offer Docsify as an ESM export for v5 in addition to our current IIFE version, but if we do this we also have to consider if/how we export plugins and themes.
- I like the idea of providing better IntelliSense for docsify configurations, but the implementation I would use is different than the one in this PR.
Can we create / move to separate issues so can align and triage?
- ESM export => New issue
TypeScript / IntelliSense support can be part of this discussion. - Docsify encapsulation => #2135
I've updated this thread with high-level POC. Deprecation of globals can be part of this discussion.
Thanks!
|
Hi Joe @trusktr , no offense. Based on current @jhildenbiddle mentioned here, I think I may have some misunderstood on the scope. Is it a planning or something? If it were a planning, thats fine and we could have more discussions on it, I apologize that I declined it directly. If I do miss some details plz let me know. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Yeah, of course. That wasn't the intent. The PR was in Draft mode, and lots of type issues. Types have been updated (I updated the description with details). All tests are green, including a new test to ensure types flow into consumer projects using the same project in The PR is now marked as ready. |
Removed deprecation messages from global API. Makes sense, as ESM mode works but is not great yet (see the new
The PR is doing this now in a way that doesn't conflict with global stuff.
What's the implementation? |
|
The only feature change of this PR is the ability to pass config directly to So the question is, do we want this? These changes are non-breaking. If we keep Based on this, I propose we move forward because introducing the custom element API later can be non-breaking. This is a nice small stepping stone, if we agree. I want to move forward more quickly, so if this doesn't get approved, we need a viable alternative to be presented so we're not waiting. |
@Koooooo-7 I updated the PR description. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds TypeScript declaration file generation to enable type-safe ESM consumption of Docsify while maintaining the plain JavaScript codebase. It introduces a new Docsify(config) constructor API for ESM users, outputs .d.ts files alongside source code, and includes comprehensive JSDoc type annotations for improved type checking.
Key changes:
- TypeScript configuration and declaration file generation (
build:typesscript) - New ESM constructor API accepting config directly
- Test infrastructure to validate type consumption (
test/consume-types)
Reviewed Changes
Copilot reviewed 56 out of 62 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.json | Configures TypeScript for declaration-only output with JSDoc checking |
| package.json | Adds types field, moves runtime deps, includes src/ in published files |
| src/core/Docsify.js | Exports public APIs and adds constructor parameter for config |
| src/core/config.js | Refactored to accept config parameter, added type definitions |
| src/core/globals.ts | Global type declarations for window objects |
| test/consume-types/* | Test infrastructure for validating type consumption in vanilla ESM |
| src/plugins/* | Added type annotations and fixed global variable references |
| src/core/event/index.js | Extensive type annotations for event handlers |
| test/e2e/*.test.js | Filter deprecation warnings from console output |
Files not reviewed (1)
- test/consume-types/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
…type-definitions * 'type-definitions' of github.com:docsifyjs/docsify: Update src/core/event/index.js
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: trusktr <297678+trusktr@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: trusktr <297678+trusktr@users.noreply.github.com>
and adjust package.json so that types are picked up in consumer projects
Summary
The code base is still plain JS as before (the build did not change) but this now allows outputting declaration files so that consumers that can start to import
Docsifyvia ES Modules with type definitions. This also type checks our own code (more details below), allowing us to improve our code base over time in a new way.Related issue, if any:
What kind of change does this PR introduce?
Feature (dev experience)
Build-related changes (adds a build step that outputs declaration files, but otherwise does not change the build in any other way)
For any code change,
Does this PR introduce a breaking change?
No
Tested in the following browsers:
Additional info
Several changes:
anyand can be fixed later.noImplicitAnyoption is set tofalseintsconfig.jsonto disable ~600 type errors that will otherwise happen..d.ts) alongside files insrc/. We do not output types todist/because that conflicts with the folder structure there. Thedist/folder is only for the global build, and we may optionally place bundled ESM builds there later, but otherwise ESM imports are directly fromsrc/and the sibling output.d.tsfiles automatically provide type awareness for consuming TypeScript projects.src/folder is now added to thefilesarray inpackage.json.tsconfig.jsonsets up TypeScript rules.build:typesscripts causes.d.tsand.d.ts.mapfiles to be emitted next to.jsfiles insrc/. This step does not do anything with the.jsfiles, those are handled in the pre-existing build separately..d.tsfiles provide declarations for consumption, and the.d.ts.mapfiles allow features likeGo To Definitionon Docsify APIs to take someone directly to the source definition in their IDEs.test/consume-typeswhich is a sample project thatimportsDocsifyto bootstrap a Docsify site (see those files for more details).prismjs(which is in CommonJS format) andcommon-tags(which has bespoke import specifiers pointing to folders instead of JS files).test:consume-typesscript goes intotest/consume-typesdirectory, installs Docsify and Docsify's dependencies into its localnode_modules, and runs type checking with TypeScript to verify the types are imported as expected via ESM.new Docsify(config)APIDocsify, they can now pass options directly to theDocsifyconstructor, while getting type checking and intellisense on all the available options: