@storybook/csf-plugin
Advanced tools
Comparing version
@@ -6,5 +6,7 @@ import * as _vite from 'vite'; | ||
import * as _unplugin from 'unplugin'; | ||
import { UnpluginFactory } from 'unplugin'; | ||
import { EnrichCsfOptions } from 'storybook/internal/csf-tools'; | ||
type CsfPluginOptions = EnrichCsfOptions; | ||
declare const unpluginFactory: UnpluginFactory<EnrichCsfOptions>; | ||
declare const unplugin: _unplugin.UnpluginInstance<EnrichCsfOptions, boolean>; | ||
@@ -16,2 +18,2 @@ declare const esbuild: (options: EnrichCsfOptions) => _esbuild.Plugin; | ||
export { CsfPluginOptions, esbuild, rollup, unplugin, vite, webpack }; | ||
export { type CsfPluginOptions, esbuild, rollup, unplugin, unpluginFactory, vite, webpack }; |
@@ -1,1 +0,100 @@ | ||
"use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var index_exports={};__export(index_exports,{esbuild:()=>esbuild,rollup:()=>rollup,unplugin:()=>unplugin,vite:()=>vite,webpack:()=>webpack});module.exports=__toCommonJS(index_exports);var import_unplugin=require("unplugin");var STORIES_REGEX=/(?<!node_modules.*)\.(story|stories)\.[tj]sx?$/;var import_promises=require("fs/promises"),import_csf_tools=require("storybook/internal/csf-tools"),import_node_logger=require("storybook/internal/node-logger");function rollupBasedPlugin(options){return{name:"plugin-csf",async transform(code,id){if(!STORIES_REGEX.test(id))return;let sourceCode=await(0,import_promises.readFile)(id,"utf-8");try{let makeTitle=userTitle=>userTitle||"default",csf=(0,import_csf_tools.loadCsf)(code,{makeTitle}).parse(),csfSource=(0,import_csf_tools.loadCsf)(sourceCode,{makeTitle}).parse();(0,import_csf_tools.enrichCsf)(csf,csfSource,options);let inputSourceMap=this.getCombinedSourcemap();return(0,import_csf_tools.formatCsf)(csf,{sourceMaps:!0,inputSourceMap},code)}catch(err){return err.message?.startsWith("CSF:")||import_node_logger.logger.warn(err.message),code}}}}var unplugin=(0,import_unplugin.createUnplugin)(options=>({name:"unplugin-csf",rollup:{...rollupBasedPlugin(options)},vite:{enforce:"pre",...rollupBasedPlugin(options)},webpack(compiler){compiler.options.module.rules.unshift({test:STORIES_REGEX,enforce:"post",use:{options,loader:require.resolve("@storybook/csf-plugin/dist/webpack-loader")}})},rspack(compiler){compiler.options.module.rules.unshift({test:STORIES_REGEX,enforce:"post",use:{options,loader:require.resolve("@storybook/csf-plugin/dist/webpack-loader")}})}})),{esbuild}=unplugin,{webpack}=unplugin,{rollup}=unplugin,{vite}=unplugin;0&&(module.exports={esbuild,rollup,unplugin,vite,webpack}); | ||
import CJS_COMPAT_NODE_URL_o5nb1b36uth from 'node:url'; | ||
import CJS_COMPAT_NODE_PATH_o5nb1b36uth from 'node:path'; | ||
import CJS_COMPAT_NODE_MODULE_o5nb1b36uth from "node:module"; | ||
var __filename = CJS_COMPAT_NODE_URL_o5nb1b36uth.fileURLToPath(import.meta.url); | ||
var __dirname = CJS_COMPAT_NODE_PATH_o5nb1b36uth.dirname(__filename); | ||
var require = CJS_COMPAT_NODE_MODULE_o5nb1b36uth.createRequire(import.meta.url); | ||
// ------------------------------------------------------------ | ||
// end of CJS compatibility banner, injected by Storybook's esbuild configuration | ||
// ------------------------------------------------------------ | ||
import { | ||
__name | ||
} from "./_node-chunks/chunk-PINAZRXF.js"; | ||
// src/index.ts | ||
import { fileURLToPath } from "node:url"; | ||
import { createUnplugin } from "unplugin"; | ||
// src/constants.ts | ||
var STORIES_REGEX = /(?<!node_modules.*)\.(story|stories)\.[tj]sx?$/; | ||
// src/rollup-based-plugin.ts | ||
import { readFile } from "node:fs/promises"; | ||
import { enrichCsf, formatCsf, loadCsf } from "storybook/internal/csf-tools"; | ||
import { logger } from "storybook/internal/node-logger"; | ||
function rollupBasedPlugin(options) { | ||
return { | ||
name: "plugin-csf", | ||
async transform(code, id) { | ||
if (!STORIES_REGEX.test(id)) { | ||
return; | ||
} | ||
const sourceCode = await readFile(id, "utf-8"); | ||
try { | ||
const makeTitle = /* @__PURE__ */ __name((userTitle) => userTitle || "default", "makeTitle"); | ||
const csf = loadCsf(code, { makeTitle }).parse(); | ||
const csfSource = loadCsf(sourceCode, { | ||
makeTitle | ||
}).parse(); | ||
enrichCsf(csf, csfSource, options); | ||
const inputSourceMap = this.getCombinedSourcemap(); | ||
return formatCsf(csf, { sourceMaps: true, inputSourceMap }, code); | ||
} catch (err) { | ||
if (!err.message?.startsWith("CSF:")) { | ||
logger.warn(err.message); | ||
} | ||
return code; | ||
} | ||
} | ||
}; | ||
} | ||
__name(rollupBasedPlugin, "rollupBasedPlugin"); | ||
// src/index.ts | ||
var unpluginFactory = /* @__PURE__ */ __name((options) => { | ||
return { | ||
name: "unplugin-csf", | ||
rollup: { | ||
...rollupBasedPlugin(options) | ||
}, | ||
vite: { | ||
enforce: "pre", | ||
...rollupBasedPlugin(options) | ||
}, | ||
webpack(compiler) { | ||
compiler.options.module.rules.unshift({ | ||
test: STORIES_REGEX, | ||
enforce: "post", | ||
use: { | ||
options, | ||
loader: fileURLToPath(import.meta.resolve("@storybook/csf-plugin/webpack-loader")) | ||
} | ||
}); | ||
}, | ||
rspack(compiler) { | ||
compiler.options.module.rules.unshift({ | ||
test: STORIES_REGEX, | ||
enforce: "post", | ||
use: { | ||
options, | ||
loader: fileURLToPath(import.meta.resolve("@storybook/csf-plugin/webpack-loader")) | ||
} | ||
}); | ||
} | ||
}; | ||
}, "unpluginFactory"); | ||
var unplugin = createUnplugin(unpluginFactory); | ||
var { esbuild } = unplugin; | ||
var { webpack } = unplugin; | ||
var { rollup } = unplugin; | ||
var { vite } = unplugin; | ||
export { | ||
esbuild, | ||
rollup, | ||
unplugin, | ||
unpluginFactory, | ||
vite, | ||
webpack | ||
}; |
@@ -1,1 +0,49 @@ | ||
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var webpack_loader_exports={};__export(webpack_loader_exports,{default:()=>webpack_loader_default});module.exports=__toCommonJS(webpack_loader_exports);var import_promises=require("fs/promises"),import_csf_tools=require("storybook/internal/csf-tools");async function loader(content,map){let callback=this.async(),options=this.getOptions(),id=this.resourcePath,sourceCode=await(0,import_promises.readFile)(id,"utf-8");try{let makeTitle=userTitle=>userTitle||"default",csf=(0,import_csf_tools.loadCsf)(content,{makeTitle}).parse(),csfSource=(0,import_csf_tools.loadCsf)(sourceCode,{makeTitle}).parse();(0,import_csf_tools.enrichCsf)(csf,csfSource,options);let formattedCsf=(0,import_csf_tools.formatCsf)(csf,{sourceMaps:!0,inputSourceMap:map,sourceFileName:id},content);if(typeof formattedCsf=="string")return callback(null,formattedCsf,map);callback(null,formattedCsf.code,formattedCsf.map)}catch(err){err.message?.startsWith("CSF:")||console.warn(err.message),callback(null,content,map)}}var webpack_loader_default=loader; | ||
import CJS_COMPAT_NODE_URL_o5nb1b36uth from 'node:url'; | ||
import CJS_COMPAT_NODE_PATH_o5nb1b36uth from 'node:path'; | ||
import CJS_COMPAT_NODE_MODULE_o5nb1b36uth from "node:module"; | ||
var __filename = CJS_COMPAT_NODE_URL_o5nb1b36uth.fileURLToPath(import.meta.url); | ||
var __dirname = CJS_COMPAT_NODE_PATH_o5nb1b36uth.dirname(__filename); | ||
var require = CJS_COMPAT_NODE_MODULE_o5nb1b36uth.createRequire(import.meta.url); | ||
// ------------------------------------------------------------ | ||
// end of CJS compatibility banner, injected by Storybook's esbuild configuration | ||
// ------------------------------------------------------------ | ||
import { | ||
__name | ||
} from "./_node-chunks/chunk-PINAZRXF.js"; | ||
// src/webpack-loader.ts | ||
import { readFile } from "node:fs/promises"; | ||
import { enrichCsf, formatCsf, loadCsf } from "storybook/internal/csf-tools"; | ||
async function loader(content, map) { | ||
const callback = this.async(); | ||
const options = this.getOptions(); | ||
const id = this.resourcePath; | ||
const sourceCode = await readFile(id, "utf-8"); | ||
try { | ||
const makeTitle = /* @__PURE__ */ __name((userTitle) => userTitle || "default", "makeTitle"); | ||
const csf = loadCsf(content, { makeTitle }).parse(); | ||
const csfSource = loadCsf(sourceCode, { makeTitle }).parse(); | ||
enrichCsf(csf, csfSource, options); | ||
const formattedCsf = formatCsf( | ||
csf, | ||
{ sourceMaps: true, inputSourceMap: map, sourceFileName: id }, | ||
content | ||
); | ||
if (typeof formattedCsf === "string") { | ||
return callback(null, formattedCsf, map); | ||
} | ||
callback(null, formattedCsf.code, formattedCsf.map); | ||
} catch (err) { | ||
if (!err.message?.startsWith("CSF:")) { | ||
console.warn(err.message); | ||
} | ||
callback(null, content, map); | ||
} | ||
} | ||
__name(loader, "loader"); | ||
var webpack_loader_default = loader; | ||
export { | ||
webpack_loader_default as default | ||
}; |
{ | ||
"name": "@storybook/csf-plugin", | ||
"version": "9.2.0-alpha.3", | ||
"version": "10.0.0-beta.0", | ||
"description": "Enrich CSF files via static analysis", | ||
@@ -23,20 +23,11 @@ "keywords": [ | ||
"sideEffects": false, | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"node": "./dist/index.js", | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.js" | ||
"default": "./dist/index.js" | ||
}, | ||
"./dist/webpack-loader": { | ||
"types": "./dist/webpack-loader.d.ts", | ||
"node": "./dist/webpack-loader.js", | ||
"import": "./dist/webpack-loader.mjs", | ||
"require": "./dist/webpack-loader.js" | ||
}, | ||
"./package.json": "./package.json" | ||
"./package.json": "./package.json", | ||
"./webpack-loader": "./dist/webpack-loader.js" | ||
}, | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
@@ -50,7 +41,7 @@ "dist/**/*", | ||
"scripts": { | ||
"check": "jiti ../../../scripts/prepare/check.ts", | ||
"prep": "jiti ../../../scripts/prepare/bundle.ts" | ||
"check": "jiti ../../../scripts/check/check-package.ts", | ||
"prep": "jiti ../../../scripts/build/build-package.ts" | ||
}, | ||
"dependencies": { | ||
"unplugin": "^1.3.1" | ||
"unplugin": "^2.3.5" | ||
}, | ||
@@ -61,21 +52,26 @@ "devDependencies": { | ||
"peerDependencies": { | ||
"storybook": "^9.2.0-alpha.3" | ||
"esbuild": "*", | ||
"rollup": "*", | ||
"storybook": "^10.0.0-beta.0", | ||
"vite": "*", | ||
"webpack": "*" | ||
}, | ||
"peerDependenciesMeta": { | ||
"esbuild": { | ||
"optional": true | ||
}, | ||
"rollup": { | ||
"optional": true | ||
}, | ||
"vite": { | ||
"optional": true | ||
}, | ||
"webpack": { | ||
"optional": true | ||
} | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"bundler": { | ||
"entries": [ | ||
"./src/index.ts", | ||
"./src/webpack-loader.ts" | ||
], | ||
"externals": [ | ||
"webpack", | ||
"vite", | ||
"rollup", | ||
"esbuild" | ||
], | ||
"platform": "node" | ||
}, | ||
"gitHead": "ce6a1e4a8d5ad69c699021a0b183df89cfc7b684" | ||
"gitHead": "a8e7fd8a655c69780bc20b9749d2699e45beae16" | ||
} |
@@ -27,1 +27,3 @@ # CSF Plugin | ||
This allows `@storybook/addon-docs` to display the static source snippet. | ||
Learn more about Storybook at [storybook.js.org](https://storybook.js.org/?ref=readme). |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
169
186.44%1
-66.67%29
7.41%0
-100%Yes
NaN8843
-16.35%6
200%6
-33.33%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
Updated