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

react-docgen-typescript-plugin

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-docgen-typescript-plugin - npm Package Compare versions

Comparing version 0.7.1-canary.29e1a62.0 to 0.7.1

16

CHANGELOG.md

@@ -0,1 +1,17 @@

# v0.7.1 (Tue May 11 2021)
:tada: This release contains work from a new contributor! :tada:
Thank you, Kyle Herock ([@kherock](https://github.com/kherock)), for all your work!
#### 🐛 Bug Fix
- Include dotfiles in micromatch globs [#34](https://github.com/hipstersmoothie/react-docgen-typescript-plugin/pull/34) ([@kherock](https://github.com/kherock))
#### Authors: 1
- Kyle Herock ([@kherock](https://github.com/kherock))
---
# v0.7.0 (Fri Dec 04 2020)

@@ -2,0 +18,0 @@

3

dist/index.d.ts

@@ -1,6 +0,5 @@

import type { DocgenPluginType } from "./plugin";
import type { DocgenPluginType } from './plugin';
declare let plugin: DocgenPluginType;
export { PluginOptions } from "./plugin";
export { plugin as ReactDocgenTypeScriptPlugin };
export default plugin;
//# sourceMappingURL=index.d.ts.map

@@ -9,11 +9,10 @@ "use strict";

let plugin;
exports.ReactDocgenTypeScriptPlugin = plugin;
try {
require.resolve("typescript");
exports.ReactDocgenTypeScriptPlugin = plugin = require("./plugin").default;
plugin = require('./plugin').default;
}
catch (error) {
exports.ReactDocgenTypeScriptPlugin = plugin = EmptyPlugin;
plugin = EmptyPlugin;
}
exports.default = plugin;
//# sourceMappingURL=index.js.map

@@ -1,6 +0,4 @@

import { Compiler, WebpackPluginInstance } from "webpack";
import * as webpack from "webpack";
import ts from "typescript";
import * as docGen from "react-docgen-typescript";
import { LoaderOptions } from "./types";
import { GeneratorOptions } from "./generateDocgenCodeBlock";
interface TypescriptOptions {

@@ -15,2 +13,34 @@ /**

}
interface LoaderOptions {
/**
* Specify the docgen collection name to use. All docgen information will
* be collected into this global object. Set to null to disable.
*
* @default STORYBOOK_REACT_CLASSES
* @see https://github.com/gongreg/react-storybook-addon-docgen
**/
docgenCollectionName?: string | null;
/**
* Automatically set the component's display name. If you want to set display
* names yourself or are using another plugin to do this, you should disable
* this option.
*
* ```
* class MyComponent extends React.Component {
* ...
* }
*
* MyComponent.displayName = "MyComponent";
* ```
*
* @default true
*/
setDisplayName?: boolean;
/**
* Specify the name of the property for docgen info prop type.
*
* @default "type"
*/
typePropName?: string;
}
export declare type PluginOptions = docGen.ParserOptions & LoaderOptions & TypescriptOptions & {

@@ -23,16 +53,7 @@ /** Glob patterns to ignore */

/** Inject typescript docgen information into modules at the end of a build */
export default class DocgenPlugin implements WebpackPluginInstance {
export default class DocgenPlugin {
private name;
private options;
constructor(options?: PluginOptions);
apply(compiler: Compiler): void;
getOptions(): {
docgenOptions: docGen.ParserOptions;
generateOptions: {
docgenCollectionName: GeneratorOptions["docgenCollectionName"];
setDisplayName: GeneratorOptions["setDisplayName"];
typePropName: GeneratorOptions["typePropName"];
};
compilerOptions: ts.CompilerOptions;
};
apply(compiler: webpack.Compiler): void;
}

@@ -39,0 +60,0 @@ export declare type DocgenPluginType = typeof DocgenPlugin;

@@ -10,5 +10,38 @@ "use strict";

const micromatch_1 = require("micromatch");
const dependency_1 = tslib_1.__importDefault(require("./dependency"));
const find_cache_dir_1 = tslib_1.__importDefault(require("find-cache-dir"));
const flat_cache_1 = tslib_1.__importDefault(require("flat-cache"));
const crypto_1 = tslib_1.__importDefault(require("crypto"));
const generateDocgenCodeBlock_1 = require("./generateDocgenCodeBlock");
const debugExclude = debug_1.default("docgen:exclude");
const debugInclude = debug_1.default("docgen:include");
const debugDocs = debug_1.default("docgen:docs");
const cacheId = "ts-docgen";
const cacheDir = find_cache_dir_1.default({ name: cacheId });
const cache = flat_cache_1.default.load(cacheId, cacheDir);
/** Run the docgen parser and inject the result into the output */
function processModule(parser, webpackModule, tsProgram, loaderOptions) {
if (!webpackModule) {
return;
}
const hash = crypto_1.default
.createHash("sha1")
.update(webpackModule._source._value)
.digest("hex");
const cached = cache.getKey(hash);
if (cached) {
debugInclude(`Got cached docgen for "${webpackModule.request}"`);
webpackModule._source._value = cached;
return;
}
const componentDocs = parser.parseWithProgramProvider(webpackModule.userRequest, () => tsProgram);
if (!componentDocs.length) {
return;
}
const docs = generateDocgenCodeBlock_1.generateDocgenCodeBlock(Object.assign({ filename: webpackModule.userRequest, source: webpackModule.userRequest, componentDocs }, loaderOptions)).substring(webpackModule.userRequest.length);
debugDocs(docs);
let sourceWithDocs = webpackModule._source._value;
sourceWithDocs += `\n${docs}\n`;
webpackModule._source._value = sourceWithDocs;
cache.setKey(hash, sourceWithDocs);
}
/** Get the contents of the tsconfig in the system */

@@ -27,3 +60,3 @@ function getTSConfigFile(tsconfigPath) {

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

@@ -38,44 +71,5 @@ };

apply(compiler) {
const pluginName = "DocGenPlugin";
const { docgenOptions, compilerOptions, generateOptions, } = this.getOptions();
const docGenParser = docGen.withCompilerOptions(compilerOptions, docgenOptions);
const { exclude = [], include = ["**/**.tsx"] } = this.options;
const _a = this.options, { tsconfigPath = "./tsconfig.json", docgenCollectionName = "STORYBOOK_REACT_CLASSES", setDisplayName = true, typePropName = "type", compilerOptions: userCompilerOptions, exclude = [], include = ["**/**.tsx"] } = _a, docgenOptions = tslib_1.__rest(_a, ["tsconfigPath", "docgenCollectionName", "setDisplayName", "typePropName", "compilerOptions", "exclude", "include"]);
const isExcluded = matchGlob(exclude);
const isIncluded = matchGlob(include);
compiler.hooks.compilation.tap(pluginName, (compilation, { normalModuleFactory }) => {
compilation.dependencyTemplates.set(
// eslint-disable-next-line
// @ts-ignore TODO: Figure out why this isn't allowed
dependency_1.default, new dependency_1.default.Template());
const handler = (parser) => {
parser.hooks.program.tap(pluginName, () => {
// eslint-disable-next-line
// @ts-ignore
const { module } = parser.state;
const nameForCondition = module.nameForCondition();
if (isExcluded(nameForCondition)) {
debugExclude(`Module not matched in "exclude": ${nameForCondition}`);
return;
}
if (!isIncluded(nameForCondition)) {
debugExclude(`Module not matched in "include": ${nameForCondition}`);
return;
}
const componentDocs = docGenParser.parse(nameForCondition);
module.addDependency(new dependency_1.default(module.request, generateDocgenCodeBlock_1.generateDocgenCodeBlock(Object.assign({ filename: nameForCondition, source: nameForCondition, componentDocs }, generateOptions)).substring(module.userRequest.length)));
});
};
normalModuleFactory.hooks.parser
.for("javascript/auto")
.tap(pluginName, handler);
normalModuleFactory.hooks.parser
.for("javascript/dynamic")
.tap(pluginName, handler);
normalModuleFactory.hooks.parser
.for("javascript/esm")
.tap(pluginName, handler);
});
}
getOptions() {
const _a = this.options, { tsconfigPath = "./tsconfig.json", compilerOptions: userCompilerOptions, docgenCollectionName, setDisplayName, typePropName } = _a, docgenOptions = tslib_1.__rest(_a, ["tsconfigPath", "compilerOptions", "docgenCollectionName", "setDisplayName", "typePropName"]);
let compilerOptions = {

@@ -90,14 +84,42 @@ jsx: typescript_1.default.JsxEmit.React,

else {
const { options: tsOptions } = getTSConfigFile(tsconfigPath);
compilerOptions = Object.assign(Object.assign({}, compilerOptions), tsOptions);
const { options } = getTSConfigFile(tsconfigPath);
compilerOptions = Object.assign(Object.assign({}, compilerOptions), options);
}
return {
docgenOptions,
generateOptions: {
docgenCollectionName: docgenCollectionName || "STORYBOOK_REACT_CLASSES",
setDisplayName: setDisplayName || true,
typePropName: typePropName || "type",
},
compilerOptions,
};
const parser = docGen.withCompilerOptions(compilerOptions, docgenOptions);
compiler.hooks.make.tap(this.name, (compilation) => {
compilation.hooks.seal.tap(this.name, () => {
const modulesToProcess = [];
compilation.modules.forEach((module) => {
if (!module.built) {
debugExclude(`Ignoring un-built module: ${module.userRequest}`);
return;
}
if (module.external) {
debugExclude(`Ignoring external module: ${module.userRequest}`);
return;
}
if (!module.rawRequest) {
debugExclude(`Ignoring module without "rawRequest": ${module.userRequest}`);
return;
}
if (isExcluded(module.userRequest)) {
debugExclude(`Module not matched in "exclude": ${module.userRequest}`);
return;
}
if (!isIncluded(module.userRequest)) {
debugExclude(`Module not matched in "include": ${module.userRequest}`);
return;
}
debugInclude(module.userRequest);
modulesToProcess.push(module);
});
const tsProgram = typescript_1.default.createProgram(modulesToProcess.map((v) => v.userRequest), compilerOptions);
modulesToProcess.forEach((m) => processModule(parser, m, tsProgram, {
docgenCollectionName,
setDisplayName,
typePropName,
}));
cache.save();
});
});
}

@@ -104,0 +126,0 @@ }

{
"name": "react-docgen-typescript-plugin",
"version": "0.7.1-canary.29e1a62.0",
"version": "0.7.1",
"description": "A webpack plugin to inject react typescript docgen information.",

@@ -9,8 +9,3 @@ "license": "MIT",

"main": "dist/index.js",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
},
"scripts": {
"build:example": "npm run build && webpack",
"build": "tsc -p tsconfig.build.json",

@@ -35,6 +30,7 @@ "start": "yarn build --watch",

"endent": "^2.0.1",
"find-cache-dir": "^3.3.1",
"flat-cache": "^3.0.4",
"micromatch": "^4.0.2",
"react-docgen-typescript": "^1.22.0",
"tslib": "^2.0.0",
"webpack-sources": "^2.2.0"
"react-docgen-typescript": "^1.20.5",
"tslib": "^2.0.0"
},

@@ -45,7 +41,7 @@ "devDependencies": {

"@types/flat-cache": "^2.0.0",
"@types/jest": "^26.0.23",
"@types/jest": "^26.0.16",
"@types/micromatch": "^4.0.1",
"@types/node": "^14.0.12",
"@types/react": "^17.0.0",
"@types/webpack-sources": "^2.1.0",
"@types/webpack": "^4.41.17",
"@typescript-eslint/eslint-plugin": "^4.9.0",

@@ -65,14 +61,9 @@ "@typescript-eslint/parser": "^4.9.0",

"jest": "^26.6.3",
"memfs": "^3.2.2",
"prettier": "^2.0.5",
"react": "^17.0.1",
"ts-jest": "^26.5.6",
"ts-loader": "^9.1.2",
"typescript": "3.8.3",
"webpack": "^5.36.2",
"webpack-cli": "^4.7.0"
"ts-jest": "^26.4.4",
"typescript": "3.8.3"
},
"peerDependencies": {
"typescript": ">= 3.x",
"webpack": ">= 5"
"typescript": ">= 3.x"
},

@@ -79,0 +70,0 @@ "lint-staged": {

@@ -83,2 +83,3 @@ <div align="center">

<td align="center"><a href="http://shilman.net/"><img src="https://avatars2.githubusercontent.com/u/488689?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Michael Shilman</b></sub></a><br /><a href="https://github.com/hipstersmoothie/react-docgen-typescript-plugin/commits?author=shilman" title="Code">💻</a></td>
<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>
</tr>

@@ -85,0 +86,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

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