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.1f3265d.0

index.cjs

53

dist/esm/analyze.js

@@ -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.js";
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.js";
{
"name": "@storybook/docs-mdx",
"version": "0.0.1-canary.1.9752632.0",
"version": "0.0.1-canary.1.1f3265d.0",
"description": "Storybook Docs MDX analyzer",

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

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

@@ -18,9 +20,8 @@ "types": "dist/ts/index.d.ts",

"*.js",
"*.d.ts"
"*.d.ts",
"index.cjs"
],
"scripts": {
"clean": "rimraf ./dist",
"buildBabel": "concurrently \"yarn buildBabel:cjs\" \"yarn buildBabel:esm\"",
"buildBabel:cjs": "babel ./src -d ./dist/cjs --extensions \".js,.jsx,.ts,.tsx\"",
"buildBabel:esm": "babel ./src -d ./dist/esm --env-name esm --extensions \".js,.jsx,.ts,.tsx\"",
"buildBabel": "babel ./src -d ./dist/esm --env-name dist --extensions \".js,.jsx,.ts,.tsx\"",
"buildTsc": "tsc --declaration --emitDeclarationOnly --outDir ./dist/ts",

@@ -45,5 +46,5 @@ "prebuild": "yarn clean",

"devDependencies": {
"@babel/parser": "^7.12.11",
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/parser": "^7.12.11",
"@babel/preset-env": "^7.12.1",

@@ -58,2 +59,3 @@ "@babel/preset-typescript": "^7.13.0",

"babel-loader": "^8.1.0",
"babel-plugin-add-import-extension": "^1.6.0",
"concurrently": "^7.0.0",

@@ -60,0 +62,0 @@ "husky": ">=6",

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