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

@storybook/react-docgen-typescript-plugin

Package Overview
Dependencies
Maintainers
30
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@storybook/react-docgen-typescript-plugin - npm Package Compare versions

Comparing version 1.0.2-canary.f7e28c0.0 to 1.0.6--canary.9.cd77847.0

dist/getIdentifier.d.ts

8

dist/dependency.d.ts
import * as webpack from "webpack";
import NullDependency from "webpack/lib/dependencies/NullDependency.js";
declare type Context = {
write: (a: string) => void;
read: () => string;
};
declare class DocGenDependency extends NullDependency {
codeBlock: string;
constructor(codeBlock: string);
get type(): string;
getModuleEvaluationSideEffectsState(): boolean;
updateHash: webpack.dependencies.NullDependency["updateHash"];
serialize(context: Context): void;
deserialize(context: Context): void;
}
export { DocGenDependency };
//# sourceMappingURL=dependency.d.ts.map

19

dist/dependency.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DocGenDependency = void 0;
const tslib_1 = require("tslib");

@@ -18,5 +19,19 @@ // eslint-disable-next-line

}
get type() {
return "docgen";
}
getModuleEvaluationSideEffectsState() {
return false;
}
serialize(context) {
const { write } = context;
write(this.codeBlock);
}
deserialize(context) {
const { read } = context;
this.codeBlock = read();
}
}
exports.DocGenDependency = DocGenDependency;
makeSerializable_js_1.default(DocGenDependency, "react-docgen-typescript-plugin/dist/dependency");
(0, makeSerializable_js_1.default)(DocGenDependency, "react-docgen-typescript-plugin/dist/dependency");
class DocGenTemplate extends NullDependency_js_1.default.Template {

@@ -36,4 +51,4 @@ constructor() {

// eslint-disable-next-line
// @ts-ignore TODO: How to type this correctly?
// @ts-expect-error TODO: How to type this correctly?
DocGenDependency.Template = DocGenTemplate;
//# sourceMappingURL=dependency.js.map

51

dist/generateDocgenCodeBlock.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateDocgenCodeBlock = void 0;
const tslib_1 = require("tslib");
const path_1 = tslib_1.__importDefault(require("path"));
const typescript_1 = tslib_1.__importDefault(require("typescript"));
const getIdentifier_1 = require("./getIdentifier");
/**

@@ -37,3 +39,3 @@ * Inserts a ts-ignore comment above the supplied statement.

function setDisplayName(d) {
return insertTsIgnoreBeforeStatement(typescript_1.default.createExpressionStatement(typescript_1.default.createBinary(typescript_1.default.createPropertyAccess(typescript_1.default.createIdentifier(d.displayName), typescript_1.default.createIdentifier("displayName")), typescript_1.default.SyntaxKind.EqualsToken, typescript_1.default.createLiteral(d.displayName))));
return insertTsIgnoreBeforeStatement(typescript_1.default.factory.createExpressionStatement(typescript_1.default.factory.createBinaryExpression(typescript_1.default.factory.createPropertyAccessExpression(typescript_1.default.factory.createIdentifier((0, getIdentifier_1.getIdentifier)(d)), typescript_1.default.factory.createIdentifier("displayName")), typescript_1.default.SyntaxKind.EqualsToken, typescript_1.default.factory.createStringLiteral(d.displayName))));
}

@@ -69,3 +71,3 @@ /**

*/
const setDefaultValue = (defaultValue) => typescript_1.default.createPropertyAssignment(typescript_1.default.createLiteral("defaultValue"),
const setDefaultValue = (defaultValue) => typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createStringLiteral("defaultValue"),
// Use a more extensive check on defaultValue. Sometimes the parser

@@ -80,8 +82,17 @@ // returns an empty object.

typeof defaultValue.value === "boolean")
? typescript_1.default.createObjectLiteral([
typescript_1.default.createPropertyAssignment(typescript_1.default.createIdentifier("value"), typescript_1.default.createLiteral(defaultValue.value)),
? typescript_1.default.factory.createObjectLiteralExpression([
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier("value"),
// eslint-disable-next-line no-nested-ternary
typeof defaultValue.value === "string"
? typescript_1.default.factory.createStringLiteral(defaultValue.value)
: // eslint-disable-next-line no-nested-ternary
typeof defaultValue.value === "number"
? typescript_1.default.factory.createNumericLiteral(defaultValue.value)
: defaultValue.value
? typescript_1.default.factory.createTrue()
: typescript_1.default.factory.createFalse()),
])
: typescript_1.default.createNull());
: typescript_1.default.factory.createNull());
/** Set a property with a string value */
const setStringLiteralField = (fieldName, fieldValue) => typescript_1.default.createPropertyAssignment(typescript_1.default.createLiteral(fieldName), typescript_1.default.createLiteral(fieldValue));
const setStringLiteralField = (fieldName, fieldValue) => typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createStringLiteral(fieldName), typescript_1.default.factory.createStringLiteral(fieldValue));
/**

@@ -107,3 +118,3 @@ * ```

*/
const setRequired = (required) => typescript_1.default.createPropertyAssignment(typescript_1.default.createLiteral("required"), required ? typescript_1.default.createTrue() : typescript_1.default.createFalse());
const setRequired = (required) => typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createStringLiteral("required"), required ? typescript_1.default.factory.createTrue() : typescript_1.default.factory.createFalse());
/**

@@ -120,3 +131,3 @@ * ```

typeValue.every((value) => typeof value.value === "string")
? typescript_1.default.createPropertyAssignment(typescript_1.default.createLiteral("value"), typescript_1.default.createArrayLiteral(typeValue.map((value) => typescript_1.default.createObjectLiteral([
? typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createStringLiteral("value"), typescript_1.default.factory.createArrayLiteralExpression(typeValue.map((value) => typescript_1.default.factory.createObjectLiteralExpression([
setStringLiteralField("value", value.value),

@@ -138,5 +149,5 @@ ]))))

}
return typescript_1.default.createPropertyAssignment(typescript_1.default.createLiteral(options.typePropName), typescript_1.default.createObjectLiteral(objectFields));
return typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createStringLiteral(options.typePropName), typescript_1.default.factory.createObjectLiteralExpression(objectFields));
};
return typescript_1.default.createPropertyAssignment(typescript_1.default.createLiteral(propName), typescript_1.default.createObjectLiteral([
return typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createStringLiteral(propName), typescript_1.default.factory.createObjectLiteralExpression([
setDefaultValue(prop.defaultValue),

@@ -167,6 +178,6 @@ setDescription(prop.description),

function insertDocgenIntoGlobalCollection(d, docgenCollectionName, relativeFilename) {
return insertTsIgnoreBeforeStatement(typescript_1.default.createIf(typescript_1.default.createBinary(typescript_1.default.createTypeOf(typescript_1.default.createIdentifier(docgenCollectionName)), typescript_1.default.SyntaxKind.ExclamationEqualsEqualsToken, typescript_1.default.createLiteral("undefined")), insertTsIgnoreBeforeStatement(typescript_1.default.createStatement(typescript_1.default.createBinary(typescript_1.default.createElementAccess(typescript_1.default.createIdentifier(docgenCollectionName), typescript_1.default.createLiteral(`${relativeFilename}#${d.displayName}`)), typescript_1.default.SyntaxKind.EqualsToken, typescript_1.default.createObjectLiteral([
typescript_1.default.createPropertyAssignment(typescript_1.default.createIdentifier("docgenInfo"), typescript_1.default.createPropertyAccess(typescript_1.default.createIdentifier(d.displayName), typescript_1.default.createIdentifier("__docgenInfo"))),
typescript_1.default.createPropertyAssignment(typescript_1.default.createIdentifier("name"), typescript_1.default.createLiteral(d.displayName)),
typescript_1.default.createPropertyAssignment(typescript_1.default.createIdentifier("path"), typescript_1.default.createLiteral(`${relativeFilename}#${d.displayName}`)),
return insertTsIgnoreBeforeStatement(typescript_1.default.factory.createIfStatement(typescript_1.default.factory.createBinaryExpression(typescript_1.default.factory.createTypeOfExpression(typescript_1.default.factory.createIdentifier(docgenCollectionName)), typescript_1.default.SyntaxKind.ExclamationEqualsEqualsToken, typescript_1.default.factory.createStringLiteral("undefined")), insertTsIgnoreBeforeStatement(typescript_1.default.factory.createExpressionStatement(typescript_1.default.factory.createBinaryExpression(typescript_1.default.factory.createElementAccessExpression(typescript_1.default.factory.createIdentifier(docgenCollectionName), typescript_1.default.factory.createStringLiteral(`${relativeFilename}#${d.displayName}`)), typescript_1.default.SyntaxKind.EqualsToken, typescript_1.default.factory.createObjectLiteralExpression([
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier("docgenInfo"), typescript_1.default.factory.createPropertyAccessExpression(typescript_1.default.factory.createIdentifier(d.displayName), typescript_1.default.factory.createIdentifier("__docgenInfo"))),
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier("name"), typescript_1.default.factory.createStringLiteral(d.displayName)),
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier("path"), typescript_1.default.factory.createStringLiteral(`${relativeFilename}#${d.displayName}`)),
]))))));

@@ -190,11 +201,11 @@ }

function setComponentDocGen(d, options) {
return insertTsIgnoreBeforeStatement(typescript_1.default.createStatement(typescript_1.default.createBinary(
return insertTsIgnoreBeforeStatement(typescript_1.default.factory.createExpressionStatement(typescript_1.default.factory.createBinaryExpression(
// SimpleComponent.__docgenInfo
typescript_1.default.createPropertyAccess(typescript_1.default.createIdentifier(d.displayName), typescript_1.default.createIdentifier("__docgenInfo")), typescript_1.default.SyntaxKind.EqualsToken, typescript_1.default.createObjectLiteral([
typescript_1.default.factory.createPropertyAccessExpression(typescript_1.default.factory.createIdentifier((0, getIdentifier_1.getIdentifier)(d)), typescript_1.default.factory.createIdentifier("__docgenInfo")), typescript_1.default.SyntaxKind.EqualsToken, typescript_1.default.factory.createObjectLiteralExpression([
// SimpleComponent.__docgenInfo.description
typescript_1.default.createPropertyAssignment(typescript_1.default.createLiteral("description"), typescript_1.default.createLiteral(d.description)),
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createStringLiteral("description"), typescript_1.default.factory.createStringLiteral(d.description)),
// SimpleComponent.__docgenInfo.displayName
typescript_1.default.createPropertyAssignment(typescript_1.default.createLiteral("displayName"), typescript_1.default.createLiteral(d.displayName)),
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createStringLiteral("displayName"), typescript_1.default.factory.createStringLiteral(d.displayName)),
// SimpleComponent.__docgenInfo.props
typescript_1.default.createPropertyAssignment(typescript_1.default.createLiteral("props"), typescript_1.default.createObjectLiteral(Object.entries(d.props).map(([propName, prop]) => createPropDefinition(propName, prop, options)))),
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createStringLiteral("props"), typescript_1.default.factory.createObjectLiteralExpression(Object.entries(d.props).map(([propName, prop]) => createPropDefinition(propName, prop, options)))),
]))));

@@ -207,3 +218,3 @@ }

.replace(/\\/g, "/");
const wrapInTryStatement = (statements) => typescript_1.default.createTry(typescript_1.default.createBlock(statements, true), typescript_1.default.createCatchClause(typescript_1.default.createVariableDeclaration(typescript_1.default.createIdentifier("__react_docgen_typescript_loader_error")), typescript_1.default.createBlock([])), undefined);
const wrapInTryStatement = (statements) => typescript_1.default.factory.createTryStatement(typescript_1.default.factory.createBlock(statements, true), typescript_1.default.factory.createCatchClause(typescript_1.default.factory.createVariableDeclaration(typescript_1.default.factory.createIdentifier("__react_docgen_typescript_loader_error")), typescript_1.default.factory.createBlock([])), undefined);
const codeBlocks = options.componentDocs.map((d) => wrapInTryStatement([

@@ -210,0 +221,0 @@ options.setDisplayName ? setDisplayName(d) : null,

"use strict";
/* eslint-disable */
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReactDocgenTypeScriptPlugin = void 0;
class EmptyPlugin {

@@ -5,0 +6,0 @@ constructor(_) { }

@@ -23,2 +23,7 @@ import ts from "typescript";

export default class DocgenPlugin implements webpack.WebpackPluginInstance {
static defaultOptions: {
setDisplayName: boolean;
typePropName: string;
docgenCollectionName: string;
};
private name;

@@ -25,0 +30,0 @@ private options;

@@ -13,4 +13,4 @@ "use strict";

const generateDocgenCodeBlock_1 = require("./generateDocgenCodeBlock");
const debugExclude = debug_1.default("docgen:exclude");
const debugInclude = debug_1.default("docgen:include");
const debugExclude = (0, debug_1.default)("docgen:exclude");
const debugInclude = (0, debug_1.default)("docgen:include");
/** Get the contents of the tsconfig in the system */

@@ -29,3 +29,3 @@ function getTSConfigFile(tsconfigPath) {

const matchGlob = (globs) => {
const matchers = (globs || []).map((g) => micromatch_1.matcher(g, { dot: true }));
const matchers = (globs || []).map((g) => (0, micromatch_1.matcher)(g, { dot: true }));
return (filename) => Boolean(filename && matchers.find((match) => match(filename)));

@@ -35,3 +35,3 @@ };

const cacheId = "ts-docgen";
const cacheDir = find_cache_dir_1.default({ name: cacheId });
const cacheDir = (0, find_cache_dir_1.default)({ name: cacheId });
const cache = flat_cache_1.default.load(cacheId, cacheDir);

@@ -55,3 +55,2 @@ /** Run the docgen parser and inject the result into the output */

// @ts-ignore
// eslint-disable-next-line
debugInclude(`Got cached docgen for "${webpackModule.request}"`);

@@ -71,3 +70,3 @@ // eslint-disable-next-line

}
const docs = generateDocgenCodeBlock_1.generateDocgenCodeBlock(Object.assign({ filename: userRequest, source: userRequest, componentDocs }, loaderOptions)).substring(userRequest.length);
const docs = (0, generateDocgenCodeBlock_1.generateDocgenCodeBlock)(Object.assign({ filename: userRequest, source: userRequest, componentDocs }, loaderOptions)).substring(userRequest.length);
// eslint-disable-next-line

@@ -129,2 +128,21 @@ // @ts-ignore: Webpack 4 type

const nameForCondition = module.nameForCondition() || "";
// Ignore modules that haven't been built yet for webpack 5
if (!compilation.builtModules.has(module)) {
debugExclude(`Ignoring un-built module: ${nameForCondition}`);
return;
}
// Ignore external modules
// eslint-disable-next-line
// @ts-ignore: Webpack 4 type
if (module.external) {
debugExclude(`Ignoring external module: ${nameForCondition}`);
return;
}
// Ignore raw requests
// eslint-disable-next-line
// @ts-ignore: Webpack 4 type
if (!module.rawRequest) {
debugExclude(`Ignoring module without "rawRequest": ${nameForCondition}`);
return;
}
if (isExcluded(nameForCondition)) {

@@ -153,3 +171,3 @@ debugExclude(`Module not matched in "exclude": ${nameForCondition}`);

// @ts-ignore: Webpack 4 type
new DocGenDependency(generateDocgenCodeBlock_1.generateDocgenCodeBlock(Object.assign({ filename: name, source: name, componentDocs: docGenParser.parseWithProgramProvider(name, () => tsProgram) }, generateOptions)).substring(name.length)));
new DocGenDependency((0, generateDocgenCodeBlock_1.generateDocgenCodeBlock)(Object.assign({ filename: name, source: name, componentDocs: docGenParser.parseWithProgramProvider(name, () => tsProgram) }, generateOptions)).substring(name.length)));
});

@@ -232,2 +250,3 @@ });

const _a = this.options, { tsconfigPath = "./tsconfig.json", compilerOptions: userCompilerOptions, docgenCollectionName, setDisplayName, typePropName } = _a, docgenOptions = tslib_1.__rest(_a, ["tsconfigPath", "compilerOptions", "docgenCollectionName", "setDisplayName", "typePropName"]);
const { defaultOptions } = DocgenPlugin;
let compilerOptions = {

@@ -246,7 +265,9 @@ jsx: typescript_1.default.JsxEmit.React,

return {
docgenOptions,
docgenOptions: Object.assign({ shouldIncludeExpression: true }, docgenOptions),
generateOptions: {
docgenCollectionName: docgenCollectionName || "STORYBOOK_REACT_CLASSES",
setDisplayName: setDisplayName || true,
typePropName: typePropName || "type",
docgenCollectionName: docgenCollectionName === undefined
? defaultOptions.docgenCollectionName
: docgenCollectionName,
setDisplayName: setDisplayName !== null && setDisplayName !== void 0 ? setDisplayName : defaultOptions.setDisplayName,
typePropName: typePropName !== null && typePropName !== void 0 ? typePropName : defaultOptions.typePropName,
},

@@ -258,2 +279,7 @@ compilerOptions,

exports.default = DocgenPlugin;
DocgenPlugin.defaultOptions = {
setDisplayName: true,
typePropName: "type",
docgenCollectionName: "STORYBOOK_REACT_CLASSES",
};
//# sourceMappingURL=plugin.js.map
{
"name": "@storybook/react-docgen-typescript-plugin",
"version": "1.0.2-canary.f7e28c0.0",
"version": "1.0.6--canary.9.cd77847.0",
"description": "A webpack plugin to inject react typescript docgen information.",

@@ -41,3 +41,3 @@ "license": "MIT",

"micromatch": "^4.0.2",
"react-docgen-typescript": "^1.22.0",
"react-docgen-typescript": "^2.2.2",
"tslib": "^2.0.0"

@@ -55,4 +55,3 @@ },

"@typescript-eslint/parser": "^4.9.0",
"auto": "^10.2.3",
"auto-config-hipstersmoothie": "^4.0.0",
"auto": "^10.43.0",
"eslint": "^7.14.0",

@@ -74,3 +73,3 @@ "eslint-config-airbnb-base": "^14.2.1",

"ts-loader": "^9.1.2",
"typescript": "3.8.3",
"typescript": "4.8.3",
"webpack": "^5.36.2",

@@ -81,3 +80,3 @@ "webpack-cli": "^4.7.0",

"peerDependencies": {
"typescript": ">= 3.x",
"typescript": ">= 4.x",
"webpack": ">= 4"

@@ -90,6 +89,3 @@ },

]
},
"auto": {
"extends": "hipstersmoothie"
}
}

@@ -84,3 +84,6 @@ <div align="center">

<td align="center"><a href="https://github.com/kherock"><img src="https://avatars.githubusercontent.com/u/4993980?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kyle Herock</b></sub></a><br /><a href="https://github.com/hipstersmoothie/react-docgen-typescript-plugin/commits?author=kherock" title="Code">💻</a></td>
<td align="center"><a href="https://survivejs.com/"><img src="https://avatars.githubusercontent.com/u/166921?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Juho Vepsäläinen</b></sub></a><br /><a href="#infra-bebraw" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/hipstersmoothie/react-docgen-typescript-plugin/commits?author=bebraw" title="Tests">⚠️</a> <a href="https://github.com/hipstersmoothie/react-docgen-typescript-plugin/commits?author=bebraw" title="Code">💻</a></td>
<td align="center"><a href="https://survivejs.com/"><img src="https://avatars.githubusercontent.com/u/166921?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Juho Vepsäläinen</b></sub></a><br /><a href="#infra-bebraw" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/hipstersmoothie/react-docgen-typescript-plugin/commits?author=bebraw" title="Tests">⚠️</a> <a href="https://github.com/hipstersmoothie/react-docgen-typescript-plugin/commits?author=bebraw" title="Code">💻</a> <a href="https://github.com/hipstersmoothie/react-docgen-typescript-plugin/commits?author=bebraw" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/zhzz"><img src="https://avatars.githubusercontent.com/u/4607770?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Egor Pogadaev</b></sub></a><br /><a href="https://github.com/hipstersmoothie/react-docgen-typescript-plugin/commits?author=zhzz" title="Tests">⚠️</a> <a href="https://github.com/hipstersmoothie/react-docgen-typescript-plugin/commits?author=zhzz" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/sairus2k"><img src="https://avatars.githubusercontent.com/u/1106887?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Anton Savoskin</b></sub></a><br /><a href="https://github.com/hipstersmoothie/react-docgen-typescript-plugin/commits?author=sairus2k" title="Code">💻</a></td>
<td align="center"><a href="http://trevorburnham.com/"><img src="https://avatars.githubusercontent.com/u/224895?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Trevor Burnham</b></sub></a><br /><a href="https://github.com/hipstersmoothie/react-docgen-typescript-plugin/commits?author=TrevorBurnham" title="Tests">⚠️</a> <a href="https://github.com/hipstersmoothie/react-docgen-typescript-plugin/commits?author=TrevorBurnham" title="Code">💻</a></td>
</tr>

@@ -87,0 +90,0 @@ </table>

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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