-
-
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.
|
|
Not necessary to fix, the code works as-is. Looks like GitHub doing type checking. We can fix type errors as we go along. Later we can make type definitions for the end users for the options, and for plugins, with nice docs when they hover in their editor. |
Yes. We should not merge code that fails our tests and automated checks, and we should not merge code assuming someone else will fix the issues later.
When we merge code because it "works as-is" despite the fact that it produces errors, fails tests, or fails our automated checks, ever other maintainer is forced to deal with these issues while working locally and while reviewing subsequent PRs. |
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.
* develop: (126 commits) refactor: improve blockquoteCompiler logic (#2624) docs: add DeployHQ deployment instructions (#2627) docs: fix broken link to issues in CONTRIBUTING.md (#2625) chore: bump rimraf from 5.0.7 to 6.1.0 (#2619) chore: bump @rollup/plugin-commonjs from 28.0.1 to 29.0.0 (#2618) chore: bump actions/setup-node from 5 to 6 (#2620) chore: bump actions/upload-artifact from 4 to 5 (#2621) chore: bump stefanzweifel/git-auto-commit-action from 6 to 7 (#2622) test: improve file embed & code fragment tests (#2617) test: add test for file embed and code fragments (#2616) feat: add fallback default language support (#2607) chore: bump actions/setup-node from 3 to 5 (#2609) chore: bump actions/checkout from 4 to 5 (#2608) docs: Update intro paragraph to help improve first impressions and broaden audience (#2602) feat: enhance embed handling for table cells (#2606) fix: enhance accessibility for sidebar toggle button (#2604) [release] 5.0.0-rc.3 [release] 5.0.0-rc.2 fix: normalize slugs to NFC and remove emoji variation selector (#2597) feat: GitHub style callouts (#2487) ...
|
I've updated this PR with the latest from The basic idea is: import {Docsify} from 'docsify'
// With type checking and intellisense, we can see the
// available Docsify options in our IDE.
new Docsify({
el: '#app',
// ...etc...
})Now, this is not a custom element yet, but it's a middle ground: using globals is bad and not suitable for a good ESM TypeScript experience, so this PR makes it possible to consume the |
|
Aaaand, I broke something. But we're almost there. Must be a tiny change somewhere. |
422f9b7 to
ec9a16d
Compare
…s with noImplicitAny disabled which we'll fix later
… a test that ensures types are properly exported and consumable in TS ESM projects.
ec9a16d to
affd65d
Compare
affd65d to
da6f92b
Compare
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? |

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 Docsify via ES Modules with type definitions.
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: