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.a764a50.0 to 0.0.1-canary.1.b140761.0

index.cjs

91

dist/esm/analyze.js

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

"use strict";
import * as t from '@babel/types';
import toBabel from 'estree-to-babel';
import * as babelTraverse 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) => {

@@ -83,3 +70,3 @@ const attr = elt.attributes.find(n => n.name.name === what);

}
} else if (t.isJSXExpressionContainer(child) && t.isStringLiteral(child.expression)) {// Skip string literals
} else if (t.isJSXExpressionContainer(child)) {// Skip string literals & other JSX expressions
} else {

@@ -93,6 +80,42 @@ throw new Error(`Unexpected JSX child: ${child.type}`);

};
/**
* This is a hack to get around inconsistencies between
* Babel's own weird interop code AND the typescript types (definitelyTyped)
* and the fact that we're using `type: "module"` in this package
* which has some weird behaviors
*/
const extractImports = root => {
const getTraverse = input => {
switch (true) {
case typeof input === 'function':
{
return input;
}
case typeof input.traverse === 'function':
{
return input.traverse;
}
case typeof input.default === 'function':
{
return input.default;
}
case typeof input.default.default === 'function':
{
return input.default.default;
}
default:
{
throw new Error(`Unable to get traverse function from ${input}`);
}
}
};
export const extractImports = root => {
const varToImport = {};
(0, _traverse.default)(root, {
getTraverse(babelTraverse)(root, {
ImportDeclaration: {

@@ -120,6 +143,3 @@ enter({

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

@@ -129,3 +149,3 @@ let varToImport = {};

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

@@ -137,3 +157,3 @@

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

@@ -148,14 +168,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 = {

@@ -180,4 +189,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,3 +29,3 @@

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

@@ -47,7 +35,7 @@ "imports": Array [],

"title": "foobar",
}
}
`);
});
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,8 +111,8 @@ "imports": Array [],

it('Bad MDX formatting', () => {
const input = (0, _tsDedent.dedent)`
import meta, { Basic } from './Button.stories';
const input = dedent`
import meta, { Basic } from './Button.stories';
<Meta of={meta} />/>
`;
expect((0, _analyze.analyze)(input)).toMatchInlineSnapshot(`
<Meta of={meta} />/>
`;
expect(analyze(input)).toMatchInlineSnapshot(`
Object {

@@ -139,3 +127,21 @@ "imports": Array [

});
it('MDX comments', () => {
const input = dedent`
import meta, { Basic } from './Button.stories';
<Meta of={meta} />
{/* whatever */}
`;
expect(analyze(input)).toMatchInlineSnapshot(`
Object {
"imports": Array [
"./Button.stories",
],
"of": "./Button.stories",
"title": undefined,
}
`);
});
});
});

@@ -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.a764a50.0",
"version": "0.0.1-canary.1.b140761.0",
"description": "Storybook Docs MDX analyzer",

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

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

@@ -19,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",

@@ -46,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",

@@ -59,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",

@@ -61,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