Socket
Socket
Sign inDemoInstall

@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.954724c.0

43

dist/esm/analyze.js

@@ -1,20 +0,5 @@

"use strict";
import * as t from '@babel/types';
import toBabel from 'estree-to-babel';
import traverse from '@babel/traverse';
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 +78,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 +104,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 +110,3 @@ let varToImport = {};

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

@@ -136,3 +118,3 @@

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

@@ -147,6 +129,3 @@ title,

};
exports.plugin = plugin;
const analyze = code => {
export const analyze = code => {
const {

@@ -179,4 +158,2 @@ compileSync

};
};
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,3 +29,3 @@

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

@@ -51,3 +39,3 @@ "imports": Array [],

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

@@ -57,6 +45,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" />

@@ -66,3 +54,3 @@

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

@@ -72,3 +60,3 @@ });

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

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

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

@@ -92,9 +80,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';

@@ -104,3 +92,3 @@

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

@@ -110,6 +98,6 @@ });

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

@@ -123,3 +111,3 @@ "imports": Array [],

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

@@ -129,3 +117,3 @@

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

@@ -132,0 +120,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.954724c.0",
"description": "Storybook Docs MDX analyzer",

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

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

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

"*.js",
"*.d.ts"
"*.d.ts",
"analyzer.js"
],

@@ -21,0 +24,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