-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
chore: output type definitions #2392
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 Git ↗︎
|
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.
"target": "ESNext", | ||
"lib": ["DOM", "ESNext"], | ||
"declaration": true, | ||
"emitDeclarationOnly": true, |
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.
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.
The screenshot shows .d.ts
declaration files, which is the expected result. That's what makes the types available in the demo:
https://github.com/docsifyjs/docsify-template-plain-js-type-checked/blob/main/index.js
however the demo has docsify locally symlinked, which includes the src code. The lib otherwise doesn't export anything from the index file.
I converted the PR into a draft. Perhaps first we should export Docsify
and allow it to accept options with new Docsify({...})
and deprecate global $docsify
as a way to move towards a componentization, non-globals, and ESM, and then having the type defs will make a lot more sense.
fails our tests and automated checks
Our tests didn't fail (the PR went green (EDIT: it was green in this commit, but my new commit failed something)). However GitHub seems to have some feature that is automatically showing us type errors in the Files changed
tab now (?), but this is not failing our own checks. I recommend we disable it if that's possible, or just ignore it, then fix errors as we go rather than refactoring code all in one PR.
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.
Ok here's what I'll do:
- I'll make the deprecation note for
$docsify
in the same PR - and expose the new non-global API (
new Docsify
, along with type support as above).
Let me know if you prefer the change to be separate (it won't be a big additional change, you'll be able to take a look at the specific commit).
… package for people to start importing `Docsify` and passing in non-global configs
IMO,for current propose to replace |
Let's chat about the concept, let me know what you think of this path. In the last commit I marked I updated the demo repository so that each of the following files show how the
The template repo is WIP, it can't run because there's no build and the Another approach would be to go straight for components with solid/react/vue/etc, or even better: custom elements that work in any framework. A "legacy" script could mount a component at the target Hmm, this sounds better. f.e. <!-- legacy -->
<script src="path/to/docsify/lib/docsify.min.js"></script>
<div id="app"><!-- the element gets mounted here --></div> vs <!-- modern (HTML file) -->
<script type="module">
import 'path/to/docsify/dist/docsify.js'
</script>
<docsify-app execute-script homepage="index.md" etc></docsify-app> or // modern (JS component)
import 'path/to/docsify/dist/docsify.js'
export function MyComponent() {
return <docsify-app execute-script homepage="index.md" etc></docsify-app>
} etc Gonna think about this some more... |
The |
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 => Encapsulating Docsify #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. |
Hey guys, no offense taken at all! I usually propose ideas in the form of code changes. This could be a prototype to help discuss how type checking (without writing TS, only JS with JSDoc comments) can be implemented. I'm currently experimenting with Astro, and will get a custom element setup with SSR/SSG working in Astro with Lume Element (not Docsify related, just Astro + Lume Element only, to learn about the approach). One thing that would be nice for when we eventually get Docsify converted into a Custom Element with SSR/SSG working, is to have type checking. In Astro, for example, all markup is type checked. So for example, it will be possible for a user to write the following in Astro, React JSX, Solid JSX, etc, and they will get type checking. For example, the current function MyReactComponent() {
return <docsify-app max-level={3} />
} but if they were to write this: function MyReactComponent() {
return <docsify-app max-level={"foo"} />
} they will get a type error in their editor (f.e. VS Code) because So basically with this PR I'm just starting to get things in place for this future, but it may not be in the ideal final format yet. Let's use this as a discussion point so we can ideate. In the meantime I'm in Astro land (https://astro.build/chat) doing some research. If you go there 🚀 let me know! |
@jhildenbiddle yeah please feel free to make issues as needed. I have to admit I will not be too active over here while I'm in Astro land. But I'll be back with some info on what I find. (I'm imagining it as if I'm traveling across the galaxy lol. May as well have some fun 🚀 😄 ) |
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 will start to use ES Modules will get 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
This outputs types to a new
dist/
folder. I figured I'd output here because the intent we have is to output to move all outputs todist/
so I figured I'd get started. We could output types somewhere else liketypes/
, but I figured why do that and then move it later, when we can put it where we know we'll want it.This new (WIP) template shows that type definitions are picked up:
https://github.com/docsifyjs/docsify-template-plain-js-type-checked
Note that the template is not complete yet, as
prismjs
is in CommonJS format hence native JS modules are not working there yet. To test out the template,npm install
within the template repo,npm link
within the docsify repo,npm link docsify
within the template repo to symlink a local copy of docsify into the template repoindex.js
in VS Code and see that running Go To Definition onDocsify
will take you to the type definition, confirming that type definitions are available in consumers. (A consumer with a build step would not have to worry about the native JS module issue).