-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
[WIP] Next Major Release #39
base: main
Are you sure you want to change the base?
Conversation
drop tsdx in favor of custom build, due to lack of TS4 and limited ESM support
@ChristianMurphy would it be possible to get an alpha/canary release of this before the final version is ready? I would be willing to test the current state of this out on our projects. |
Welcome @karlhorky! 👋 To your implied question of when will this PR land? |
"husky": "^7.0.0", | ||
"katex": "^0.13.0", | ||
"pinst": "^2.0.0", | ||
"prettier": "^2.0.0", |
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.
Why not v3?
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.
Because this PR came before v3 was released 🙂
V3 would be good to include
"lint": "tsdx lint", | ||
"prepare": "tsdx build", | ||
"build": "tsc && type-coverage", | ||
"test": "node --loader ts-node/esm ./test/index.test.ts", |
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'd recommend to use lite https://github.com/privatenumber/tsx over ts-node
, types linting can be a seperate task via tsc
.
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 agree, though neither will be needed in the end.
The goal is:
migrate TypeScript files to JavaScript with JSDoc based Typescript
Ok, thanks for the response. Which files would be the minimum files to get converted to JSDoc Based TypeScript to get this working on a commit install? Just |
WorkaroundUntil this is published, I'm using this code for
import { ReactElement } from 'react';
import * as prod from 'react/jsx-runtime';
import rehypeReact, {
Components,
Options as RehypeReactOptions,
} from 'rehype-react';
import remarkGfm from 'remark-gfm';
import remarkParse, { Options as RemarkParseOptions } from 'remark-parse';
import remarkToRehype, { Options as RemarkRehypeOptions } from 'remark-rehype';
import { PluggableList, unified } from 'unified';
// Copied + modfied from:
// - https://github.com/remarkjs/react-remark/pull/39/files#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80R37
//
// Modifications:
// - Removed Omit<>/PartialBy<> used on rehypeReactOptions
// - Removed `?? true` from remarkToRehypeOptions
// - Fixed option values for rehypeReact
// - Used Partial<> with rehypeReactOptions
//
// TODO: Remove when PR #39 is merged or a new version is
// released, making react-remark compatible with the other
// plugins again
// - https://github.com/remarkjs/react-remark/pull/39
// - https://github.com/remarkjs/react-remark/issues/50#issuecomment-1123725393
// - https://github.com/remarkjs/react-remark/issues/54#issuecomment-1654923707
// - https://github.com/remarkjs/react-remark/issues/41
interface UseRemarkSyncOptions {
remarkParseOptions?: RemarkParseOptions;
remarkToRehypeOptions?: RemarkRehypeOptions;
rehypeReactOptions?: Partial<RehypeReactOptions>;
remarkPlugins?: PluggableList;
rehypePlugins?: PluggableList;
}
const useRemarkSync = (
source: string,
{
remarkParseOptions,
remarkToRehypeOptions,
rehypeReactOptions,
remarkPlugins = [],
rehypePlugins = [],
}: UseRemarkSyncOptions = {},
): ReactElement =>
unified()
.use(remarkParse, remarkParseOptions)
.use(remarkPlugins)
.use(remarkToRehype, remarkToRehypeOptions)
.use(rehypePlugins)
.use(rehypeReact, {
// @ts-expect-error: the react types are missing.
Fragment: prod.Fragment,
// @ts-expect-error: the react types are missing.
jsx: prod.jsx,
// @ts-expect-error: the react types are missing.
jsxs: prod.jsxs,
...rehypeReactOptions,
} as RehypeReactOptions)
.processSync(source).result as ReactElement;
// Copied code ends here
type Props = {
children: string;
components: Partial<Components>;
};
export default function Remark(props: Props) {
const reactContent = useRemarkSync(props.children, {
remarkPlugins: [remarkGfm],
rehypeReactOptions: {
components: {
...props.components,
},
},
});
return reactContent;
} |
drop tsdx in favor of custom build, due to lack of TS4 and limited ESM
support
Initial checklist
Description of changes
migrate tsdx text to uvu or jestnode:test
.d.ts
file rehypejs/rehype-react#30 and Fix to correctly compile intrinsic types rehypejs/rehype-react#31