Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@storybook/docs-mdx

Package Overview
Dependencies
Maintainers
29
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@storybook/docs-mdx - npm Package Compare versions

Comparing version 0.0.1-canary.1.9752632.0 to 0.0.1-canary.1.84e0610.0

index.cjs

16

dist/cjs/analyze.js

@@ -14,2 +14,6 @@ "use strict";

var _mdx = require("@mdx-js/mdx");
var _hastUtilToEstree = require("hast-util-to-estree");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -148,10 +152,2 @@

const analyze = code => {
const {
compileSync
} = require('@mdx-js/mdx');
const {
toEstree
} = require('hast-util-to-estree');
const store = {

@@ -161,5 +157,5 @@ title: undefined,

imports: undefined,
toEstree
toEstree: _hastUtilToEstree.toEstree
};
compileSync(code, {
(0, _mdx.compileSync)(code, {
rehypePlugins: [[plugin, store]]

@@ -166,0 +162,0 @@ });

@@ -41,8 +41,8 @@ "use strict";

expect((0, _analyze.analyze)(input)).toMatchInlineSnapshot(`
Object {
"imports": Array [],
"of": undefined,
"title": "foobar",
}
`);
Object {
"imports": Array [],
"of": undefined,
"title": "foobar",
}
`);
});

@@ -49,0 +49,0 @@ it('template literal title', () => {

@@ -1,20 +0,7 @@

"use strict";
import * as t from '@babel/types';
import toBabel from 'estree-to-babel';
import traverse from '@babel/traverse';
import { compileSync } from '@mdx-js/mdx';
import { toEstree } from 'hast-util-to-estree';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.plugin = exports.extractImports = exports.analyze = void 0;
var t = _interopRequireWildcard(require("@babel/types"));
var _estreeToBabel = _interopRequireDefault(require("estree-to-babel"));
var _traverse = _interopRequireDefault(require("@babel/traverse"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const getAttr = (elt, what) => {

@@ -93,5 +80,5 @@ const attr = elt.attributes.find(n => n.name.name === what);

const extractImports = root => {
export const extractImports = root => {
const varToImport = {};
(0, _traverse.default)(root, {
traverse(root, {
ImportDeclaration: {

@@ -119,6 +106,3 @@ enter({

};
exports.extractImports = extractImports;
const plugin = store => root => {
export const plugin = store => root => {
const imports = root.children.find(child => child.type === 'mdxjsEsm');

@@ -128,3 +112,3 @@ let varToImport = {};

if (imports) {
varToImport = extractImports((0, _estreeToBabel.default)(imports.data.estree));
varToImport = extractImports(toBabel(imports.data.estree));
}

@@ -136,3 +120,3 @@

const babel = (0, _estreeToBabel.default)(estree);
const babel = toBabel(estree);
const {

@@ -147,14 +131,3 @@ title,

};
exports.plugin = plugin;
const analyze = code => {
const {
compileSync
} = require('@mdx-js/mdx');
const {
toEstree
} = require('hast-util-to-estree');
export const analyze = code => {
const store = {

@@ -179,4 +152,2 @@ title: undefined,

};
};
exports.analyze = analyze;
};

@@ -1,25 +0,13 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.babelParse = void 0;
var _tsDedent = require("ts-dedent");
var _analyze = require("./analyze");
var _parser = require("@babel/parser");
const babelParse = code => (0, _parser.parse)(code, {
import { dedent } from 'ts-dedent';
import { analyze, extractImports } from './analyze';
import { parse } from '@babel/parser';
export const babelParse = code => parse(code, {
sourceType: 'module'
});
exports.babelParse = babelParse;
describe('extractImports', () => {
const ast = babelParse((0, _tsDedent.dedent)`
const ast = babelParse(dedent`
import { Meta } from '@storybook/blocks';
import meta, { Basic } from './Button.stories';
`);
expect((0, _analyze.extractImports)(ast)).toMatchInlineSnapshot(`
expect(extractImports(ast)).toMatchInlineSnapshot(`
Object {

@@ -35,3 +23,3 @@ "Basic": "./Button.stories",

it('string literal title', () => {
const input = (0, _tsDedent.dedent)`
const input = dedent`
# hello

@@ -41,12 +29,12 @@

`;
expect((0, _analyze.analyze)(input)).toMatchInlineSnapshot(`
Object {
"imports": Array [],
"of": undefined,
"title": "foobar",
}
`);
expect(analyze(input)).toMatchInlineSnapshot(`
Object {
"imports": Array [],
"of": undefined,
"title": "foobar",
}
`);
});
it('template literal title', () => {
const input = (0, _tsDedent.dedent)`
const input = dedent`
# hello

@@ -56,6 +44,6 @@

`;
expect(() => (0, _analyze.analyze)(input)).toThrowErrorMatchingInlineSnapshot(`"Expected string literal title, received JSXExpressionContainer"`);
expect(() => analyze(input)).toThrowErrorMatchingInlineSnapshot(`"Expected string literal title, received JSXExpressionContainer"`);
});
it('duplicate titles', () => {
const input = (0, _tsDedent.dedent)`
const input = dedent`
<Meta title="foobar" />

@@ -65,3 +53,3 @@

`;
expect(() => (0, _analyze.analyze)(input)).toThrowErrorMatchingInlineSnapshot(`"Meta can only be declared once"`);
expect(() => analyze(input)).toThrowErrorMatchingInlineSnapshot(`"Meta can only be declared once"`);
});

@@ -71,3 +59,3 @@ });

it('basic', () => {
const input = (0, _tsDedent.dedent)`
const input = dedent`
import { Meta } from '@storybook/blocks';

@@ -78,3 +66,3 @@ import meta, { Basic } from './Button.stories';

`;
expect((0, _analyze.analyze)(input)).toMatchInlineSnapshot(`
expect(analyze(input)).toMatchInlineSnapshot(`
Object {

@@ -91,9 +79,9 @@ "imports": Array [

it('missing variable', () => {
const input = (0, _tsDedent.dedent)`
const input = dedent`
<Meta of={meta} />
`;
expect(() => (0, _analyze.analyze)(input)).toThrowErrorMatchingInlineSnapshot(`"Unknown identifier meta"`);
expect(() => analyze(input)).toThrowErrorMatchingInlineSnapshot(`"Unknown identifier meta"`);
});
it('string literal', () => {
const input = (0, _tsDedent.dedent)`
const input = dedent`
import meta, { Basic } from './Button.stories';

@@ -103,3 +91,3 @@

`;
expect(() => (0, _analyze.analyze)(input)).toThrowErrorMatchingInlineSnapshot(`"Expected JSX expression, received StringLiteral"`);
expect(() => analyze(input)).toThrowErrorMatchingInlineSnapshot(`"Expected JSX expression, received StringLiteral"`);
});

@@ -109,6 +97,6 @@ });

it('no title', () => {
const input = (0, _tsDedent.dedent)`
const input = dedent`
# hello
`;
expect((0, _analyze.analyze)(input)).toMatchInlineSnapshot(`
expect(analyze(input)).toMatchInlineSnapshot(`
Object {

@@ -122,3 +110,3 @@ "imports": Array [],

it('Bad MDX formatting', () => {
const input = (0, _tsDedent.dedent)`
const input = dedent`
import meta, { Basic } from './Button.stories';

@@ -128,3 +116,3 @@

`;
expect((0, _analyze.analyze)(input)).toMatchInlineSnapshot(`
expect(analyze(input)).toMatchInlineSnapshot(`
Object {

@@ -131,0 +119,0 @@ "imports": Array [

@@ -1,18 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _analyze = require("./analyze");
Object.keys(_analyze).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _analyze[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _analyze[key];
}
});
});
export * from './analyze';
{
"name": "@storybook/docs-mdx",
"version": "0.0.1-canary.1.9752632.0",
"version": "0.0.1-canary.1.84e0610.0",
"description": "Storybook Docs MDX analyzer",

@@ -11,2 +11,3 @@ "repository": {

"license": "MIT",
"main": "index.cjs",
"module": "dist/esm/index.js",

@@ -18,3 +19,4 @@ "types": "dist/ts/index.d.ts",

"*.js",
"*.d.ts"
"*.d.ts",
"index.cjs"
],

@@ -21,0 +23,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc