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

[WIP] Next Major Release #39

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

[WIP] Next Major Release #39

wants to merge 2 commits into from

Conversation

ChristianMurphy
Copy link
Member

@ChristianMurphy ChristianMurphy commented Aug 26, 2021

drop tsdx in favor of custom build, due to lack of TS4 and limited ESM
support

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

@ChristianMurphy ChristianMurphy added ☂️ area/types This affects typings 🏗 area/tools This affects tooling 📚 area/docs This affects documentation 📦 area/deps This affects dependencies 🕸️ area/tests This affects tests 🗄 area/interface This affects the public interface 🧑 semver/major This is a change 🛠 blocked/wip This cannot progress yet, it’s being worked on labels Aug 26, 2021
@ChristianMurphy ChristianMurphy mentioned this pull request May 11, 2022
4 tasks
@mrienstra mrienstra mentioned this pull request Jul 28, 2023
4 tasks
@karlhorky
Copy link

@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.

@ChristianMurphy
Copy link
Member Author

Welcome @karlhorky! 👋
Generally we don't publish alpha releases.
But once migrate TypeScript files to JavaScript with JSDoc based Typescript is complete
npm install remarkjs/react-remark#commit will work.

To your implied question of when will this PR land?
Not soon, my focus is elsewhere (both on professional projects and other volunteer unified initiatives) for at least the next month or so, and as far as I'm aware the same goes for most of the other remark maintainers as well.
This is still on the roadmap though.
If you'd like to contribute to moving this forward through PRs, you are welcome to!

"husky": "^7.0.0",
"katex": "^0.13.0",
"pinst": "^2.0.0",
"prettier": "^2.0.0",
Copy link
Member

Choose a reason for hiding this comment

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

Why not v3?

Copy link
Member Author

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",
Copy link
Member

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.

Copy link
Member Author

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

@karlhorky
Copy link

karlhorky commented Feb 19, 2024

Generally we don't publish alpha releases.
But once migrate TypeScript files to JavaScript with JSDoc based Typescript is complete
npm install remarkjs/react-remark#commit will work.

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 src/index.ts -> src/index.js?

@karlhorky
Copy link

karlhorky commented Feb 19, 2024

Workaround

Until this is published, I'm using this code for useRemarkSync (Next.js App Router / RSC / SSR), in case useful for anyone:

Remark.tsx

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 area/deps This affects dependencies 📚 area/docs This affects documentation 🗄 area/interface This affects the public interface 🕸️ area/tests This affects tests 🏗 area/tools This affects tooling ☂️ area/types This affects typings 🛠 blocked/wip This cannot progress yet, it’s being worked on 🧑 semver/major This is a change
Development

Successfully merging this pull request may close these issues.

4 participants