Git Product home page Git Product logo

mdx1-csf's Introduction

@storybook/mdx1-csf

Storybook's mdx1-csf is a compiler that turns MDXv1 input into CSF output.

For example, the following input:

import { Meta, Story } from '@storybook/addon-docs';

<Meta title="atoms/Button" />

<Story name="Bar">
  <Button>hello</Button>
</Story>

Might be transformed into the following CSF (over-simplified):

export default {
  title: 'atoms/Button',
};

export const Bar = () => <Button>hello</Button>;

API

This library exports three functions to compile MDX: compile, compileSync, and createCompiler.

compile

Asynchronously compile a string:

import { compile } from '@storybook/mdx1-csf';

const code = '# hello\n\nworld';
const output = await compile(code);

compileSync

Synchronously compile a string:

import { compileSync } from '@storybook/mdx1-csf';

const code = '# hello\n\nworld';
const output = compileSync(code);

createCompiler

Create a compiler plugin for for MDXv1:

import mdx from '@mdx-js/mdx';
import { createCompiler } from '@storybook/mdx1-csf';

const code = '# hello\n\nworld';
mdx.sync(code, { compilers: [createCompiler()] });

Loader

In addition, this library supports a simple Webpack loader that mirrors MDXv1's loader, but adds Webpack5 support.

module.exports = {
  module: {
    rules: [
      {
        test: /\.(stories|story)\.mdx$/,
        use: [
          {
            loader: require.resolve('@storybook/mdx1-csf/loader'),
            options: {},
          },
        ],
      },
    ],
  },
};

Contributing

We welcome contributions to Storybook!

  • 📥 Pull requests and 🌟 Stars are always welcome.
  • Read our contributing guide to get started, or find us on Discord, we will take the time to guide you

License

MIT

mdx1-csf's People

Contributors

iarmbears avatar joshwooding avatar jreinhold avatar ndelangen avatar shilman avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mdx1-csf's Issues

ModuleBuildError: Module build failed: UnhandledSchemeError

Describe the bug
When using the package on storybook 7, on windows with legacyMdx1 enabled it will through the error

ModuleBuildError: Module build failed: UnhandledSchemeError: Reading from "C:ProjectsCodeemergnids-corecore      
ode_modules@storybookmdx1-csf
eact" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.

To Reproduce
Steps to reproduce the behavior:

Install storybook 7, add the package to support mdx1

Expected behavior
Simply work

Upgrade the dependencies '@mdx-js/mdx' to V2

Is your feature request related to a problem? Please describe.
When I install this package, I will get a warn:
image
I found the reference chain is:
'@mdx-js/[email protected]' -> '[email protected]' -> '@babel/[email protected]'.

Describe the solution you'd like
I hope mdx1-csf can upgrade the version of '@mdx-js/mdx' to v2.
I found mdx2-csf depend on v2.https://github.com/storybookjs/mdx2-csf/blob/next/package.json#L43
Would it be better if they used the same version?

Thanks for reading my request.

Unnecessary @types/lodash on dependency

Describe the bug

@types/lodash is currently declared as a dependency. This is unnecessary since @types/lodash is a build time dependency, so it should be moved to devDependency instead.

To Reproduce
Steps to reproduce the behavior:

  1. Initialize a new package and install mdx1-csf
  2. Verify @types/lodash is installed

Expected behavior

@types/lodash is not installed.

Additional context

I hit this issue because of a conflicting type with underscore.

Upgrade @mdx-js/mdx to v2 [critical security issue]

Describe the bug
This project has a critical security issue.

It is currently using @mdx-js/mdx in version 1.x which uses remark-parse which uses an insecure trim version. E.g. updating to @mdx-js/mdx version 2.x will fix that security issue.

To Reproduce
Steps to reproduce the behavior:

  1. create new Project with npm init
  2. Add the package npm install --save @storybook/mdx1-csf
  3. Check for security issues npm audit
  4. See high security issue

Expected behavior
No security issues in @storybook/mdx1-csf

Screenshots
issue

[Bug] vulnerability related to trim

Describe the bug

Test-runner has a dep vulnerability related to trim 0.0.1
Force to use trim 0.0.3 breaks the storybook build on my side.

trim  <0.0.3
Severity: high
Regular Expression Denial of Service in trim - https://github.com/advisories/GHSA-w5p7-h5w8-2hfq
fix available via `npm audit fix --force`
Will install @storybook/[email protected], which is a breaking change
node_modules/trim
  remark-parse  <=8.0.3
  Depends on vulnerable versions of trim
  node_modules/remark-parse
    @mdx-js/mdx  <=1.6.22
    Depends on vulnerable versions of remark-mdx
    Depends on vulnerable versions of remark-parse
    node_modules/@mdx-js/mdx
      @storybook/mdx1-csf  *
      Depends on vulnerable versions of @mdx-js/mdx
      node_modules/@storybook/mdx1-csf
        @storybook/csf-tools  6.5.0-alpha.1 - 6.5.17-alpha.0
        Depends on vulnerable versions of @storybook/mdx1-csf
        node_modules/@storybook/csf-tools
          @storybook/test-runner  >=0.0.9--canary.107.1b41303.0
          Depends on vulnerable versions of @storybook/csf-tools
          node_modules/@storybook/test-runner

Environment

  • OS: iOS
  • Node.js version: 16.13.0
  • NPM version: 8.1.0

Additional context

I'm using

"@storybook/vue": "6.5.16",
"@storybook/test-runner": "0.9.4"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.