@storybook/csf-plugin 9.2.0-alpha.2 → 10.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/_node-chunks/chunk-PINAZRXF.js +17 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +100 -1
- package/dist/webpack-loader.js +49 -1
- package/package.json +28 -32
- package/dist/chunk-MXFP7CYD.mjs +0 -3
- package/dist/index.mjs +0 -9
- package/dist/webpack-loader.d.ts +0 -10
- package/dist/webpack-loader.mjs +0 -7
package/README.md
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import CJS_COMPAT_NODE_URL_o5nb1b36uth from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_o5nb1b36uth from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_o5nb1b36uth from "node:module";
|
|
4
|
+
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_o5nb1b36uth.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_o5nb1b36uth.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_o5nb1b36uth.createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// ------------------------------------------------------------
|
|
10
|
+
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
+
// ------------------------------------------------------------
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
__name
|
|
17
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,13 +3,15 @@ import * as _rollup from 'rollup';
|
|
|
3
3
|
import * as _webpack from 'webpack';
|
|
4
4
|
import * as _esbuild from 'esbuild';
|
|
5
5
|
import * as _unplugin from 'unplugin';
|
|
6
|
+
import { UnpluginFactory } from 'unplugin';
|
|
6
7
|
import { EnrichCsfOptions } from 'storybook/internal/csf-tools';
|
|
7
8
|
|
|
8
9
|
type CsfPluginOptions = EnrichCsfOptions;
|
|
10
|
+
declare const unpluginFactory: UnpluginFactory<EnrichCsfOptions>;
|
|
9
11
|
declare const unplugin: _unplugin.UnpluginInstance<EnrichCsfOptions, boolean>;
|
|
10
12
|
declare const esbuild: (options: EnrichCsfOptions) => _esbuild.Plugin;
|
|
11
13
|
declare const webpack: (options: EnrichCsfOptions) => _webpack.WebpackPluginInstance;
|
|
12
14
|
declare const rollup: (options: EnrichCsfOptions) => _rollup.Plugin<any> | _rollup.Plugin<any>[];
|
|
13
15
|
declare const vite: (options: EnrichCsfOptions) => _vite.Plugin<any> | _vite.Plugin<any>[];
|
|
14
16
|
|
|
15
|
-
export { CsfPluginOptions, esbuild, rollup, unplugin, vite, webpack };
|
|
17
|
+
export { type CsfPluginOptions, esbuild, rollup, unplugin, unpluginFactory, vite, webpack };
|
package/dist/index.js
CHANGED
|
@@ -1 +1,100 @@
|
|
|
1
|
-
|
|
1
|
+
import CJS_COMPAT_NODE_URL_o5nb1b36uth from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_o5nb1b36uth from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_o5nb1b36uth from "node:module";
|
|
4
|
+
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_o5nb1b36uth.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_o5nb1b36uth.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_o5nb1b36uth.createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// ------------------------------------------------------------
|
|
10
|
+
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
+
// ------------------------------------------------------------
|
|
12
|
+
import {
|
|
13
|
+
__name
|
|
14
|
+
} from "./_node-chunks/chunk-PINAZRXF.js";
|
|
15
|
+
|
|
16
|
+
// src/index.ts
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
import { createUnplugin } from "unplugin";
|
|
19
|
+
|
|
20
|
+
// src/constants.ts
|
|
21
|
+
var STORIES_REGEX = /(?<!node_modules.*)\.(story|stories)\.[tj]sx?$/;
|
|
22
|
+
|
|
23
|
+
// src/rollup-based-plugin.ts
|
|
24
|
+
import { readFile } from "node:fs/promises";
|
|
25
|
+
import { enrichCsf, formatCsf, loadCsf } from "storybook/internal/csf-tools";
|
|
26
|
+
import { logger } from "storybook/internal/node-logger";
|
|
27
|
+
function rollupBasedPlugin(options) {
|
|
28
|
+
return {
|
|
29
|
+
name: "plugin-csf",
|
|
30
|
+
async transform(code, id) {
|
|
31
|
+
if (!STORIES_REGEX.test(id)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const sourceCode = await readFile(id, "utf-8");
|
|
35
|
+
try {
|
|
36
|
+
const makeTitle = /* @__PURE__ */ __name((userTitle) => userTitle || "default", "makeTitle");
|
|
37
|
+
const csf = loadCsf(code, { makeTitle }).parse();
|
|
38
|
+
const csfSource = loadCsf(sourceCode, {
|
|
39
|
+
makeTitle
|
|
40
|
+
}).parse();
|
|
41
|
+
enrichCsf(csf, csfSource, options);
|
|
42
|
+
const inputSourceMap = this.getCombinedSourcemap();
|
|
43
|
+
return formatCsf(csf, { sourceMaps: true, inputSourceMap }, code);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
if (!err.message?.startsWith("CSF:")) {
|
|
46
|
+
logger.warn(err.message);
|
|
47
|
+
}
|
|
48
|
+
return code;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
__name(rollupBasedPlugin, "rollupBasedPlugin");
|
|
54
|
+
|
|
55
|
+
// src/index.ts
|
|
56
|
+
var unpluginFactory = /* @__PURE__ */ __name((options) => {
|
|
57
|
+
return {
|
|
58
|
+
name: "unplugin-csf",
|
|
59
|
+
rollup: {
|
|
60
|
+
...rollupBasedPlugin(options)
|
|
61
|
+
},
|
|
62
|
+
vite: {
|
|
63
|
+
enforce: "pre",
|
|
64
|
+
...rollupBasedPlugin(options)
|
|
65
|
+
},
|
|
66
|
+
webpack(compiler) {
|
|
67
|
+
compiler.options.module.rules.unshift({
|
|
68
|
+
test: STORIES_REGEX,
|
|
69
|
+
enforce: "post",
|
|
70
|
+
use: {
|
|
71
|
+
options,
|
|
72
|
+
loader: fileURLToPath(import.meta.resolve("@storybook/csf-plugin/webpack-loader"))
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
rspack(compiler) {
|
|
77
|
+
compiler.options.module.rules.unshift({
|
|
78
|
+
test: STORIES_REGEX,
|
|
79
|
+
enforce: "post",
|
|
80
|
+
use: {
|
|
81
|
+
options,
|
|
82
|
+
loader: fileURLToPath(import.meta.resolve("@storybook/csf-plugin/webpack-loader"))
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}, "unpluginFactory");
|
|
88
|
+
var unplugin = createUnplugin(unpluginFactory);
|
|
89
|
+
var { esbuild } = unplugin;
|
|
90
|
+
var { webpack } = unplugin;
|
|
91
|
+
var { rollup } = unplugin;
|
|
92
|
+
var { vite } = unplugin;
|
|
93
|
+
export {
|
|
94
|
+
esbuild,
|
|
95
|
+
rollup,
|
|
96
|
+
unplugin,
|
|
97
|
+
unpluginFactory,
|
|
98
|
+
vite,
|
|
99
|
+
webpack
|
|
100
|
+
};
|
package/dist/webpack-loader.js
CHANGED
|
@@ -1 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
import CJS_COMPAT_NODE_URL_o5nb1b36uth from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_o5nb1b36uth from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_o5nb1b36uth from "node:module";
|
|
4
|
+
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_o5nb1b36uth.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_o5nb1b36uth.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_o5nb1b36uth.createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// ------------------------------------------------------------
|
|
10
|
+
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
+
// ------------------------------------------------------------
|
|
12
|
+
import {
|
|
13
|
+
__name
|
|
14
|
+
} from "./_node-chunks/chunk-PINAZRXF.js";
|
|
15
|
+
|
|
16
|
+
// src/webpack-loader.ts
|
|
17
|
+
import { readFile } from "node:fs/promises";
|
|
18
|
+
import { enrichCsf, formatCsf, loadCsf } from "storybook/internal/csf-tools";
|
|
19
|
+
async function loader(content, map) {
|
|
20
|
+
const callback = this.async();
|
|
21
|
+
const options = this.getOptions();
|
|
22
|
+
const id = this.resourcePath;
|
|
23
|
+
const sourceCode = await readFile(id, "utf-8");
|
|
24
|
+
try {
|
|
25
|
+
const makeTitle = /* @__PURE__ */ __name((userTitle) => userTitle || "default", "makeTitle");
|
|
26
|
+
const csf = loadCsf(content, { makeTitle }).parse();
|
|
27
|
+
const csfSource = loadCsf(sourceCode, { makeTitle }).parse();
|
|
28
|
+
enrichCsf(csf, csfSource, options);
|
|
29
|
+
const formattedCsf = formatCsf(
|
|
30
|
+
csf,
|
|
31
|
+
{ sourceMaps: true, inputSourceMap: map, sourceFileName: id },
|
|
32
|
+
content
|
|
33
|
+
);
|
|
34
|
+
if (typeof formattedCsf === "string") {
|
|
35
|
+
return callback(null, formattedCsf, map);
|
|
36
|
+
}
|
|
37
|
+
callback(null, formattedCsf.code, formattedCsf.map);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
if (!err.message?.startsWith("CSF:")) {
|
|
40
|
+
console.warn(err.message);
|
|
41
|
+
}
|
|
42
|
+
callback(null, content, map);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
__name(loader, "loader");
|
|
46
|
+
var webpack_loader_default = loader;
|
|
47
|
+
export {
|
|
48
|
+
webpack_loader_default as default
|
|
49
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/csf-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0-beta.0",
|
|
4
4
|
"description": "Enrich CSF files via static analysis",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook"
|
|
@@ -20,24 +20,15 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"sideEffects": false,
|
|
23
|
+
"type": "module",
|
|
23
24
|
"exports": {
|
|
24
25
|
".": {
|
|
25
26
|
"types": "./dist/index.d.ts",
|
|
26
|
-
"
|
|
27
|
-
"import": "./dist/index.mjs",
|
|
28
|
-
"require": "./dist/index.js"
|
|
27
|
+
"default": "./dist/index.js"
|
|
29
28
|
},
|
|
30
|
-
"./
|
|
31
|
-
|
|
32
|
-
"node": "./dist/webpack-loader.js",
|
|
33
|
-
"import": "./dist/webpack-loader.mjs",
|
|
34
|
-
"require": "./dist/webpack-loader.js"
|
|
35
|
-
},
|
|
36
|
-
"./package.json": "./package.json"
|
|
29
|
+
"./package.json": "./package.json",
|
|
30
|
+
"./webpack-loader": "./dist/webpack-loader.js"
|
|
37
31
|
},
|
|
38
|
-
"main": "dist/index.js",
|
|
39
|
-
"module": "dist/index.mjs",
|
|
40
|
-
"types": "dist/index.d.ts",
|
|
41
32
|
"files": [
|
|
42
33
|
"dist/**/*",
|
|
43
34
|
"README.md",
|
|
@@ -46,33 +37,38 @@
|
|
|
46
37
|
"!src/**/*"
|
|
47
38
|
],
|
|
48
39
|
"scripts": {
|
|
49
|
-
"check": "jiti ../../../scripts/
|
|
50
|
-
"prep": "jiti ../../../scripts/
|
|
40
|
+
"check": "jiti ../../../scripts/check/check-package.ts",
|
|
41
|
+
"prep": "jiti ../../../scripts/build/build-package.ts"
|
|
51
42
|
},
|
|
52
43
|
"dependencies": {
|
|
53
|
-
"unplugin": "^
|
|
44
|
+
"unplugin": "^2.3.5"
|
|
54
45
|
},
|
|
55
46
|
"devDependencies": {
|
|
56
47
|
"typescript": "^5.8.3"
|
|
57
48
|
},
|
|
58
49
|
"peerDependencies": {
|
|
59
|
-
"
|
|
50
|
+
"esbuild": "*",
|
|
51
|
+
"rollup": "*",
|
|
52
|
+
"storybook": "^10.0.0-beta.0",
|
|
53
|
+
"vite": "*",
|
|
54
|
+
"webpack": "*"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"esbuild": {
|
|
58
|
+
"optional": true
|
|
59
|
+
},
|
|
60
|
+
"rollup": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"vite": {
|
|
64
|
+
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"webpack": {
|
|
67
|
+
"optional": true
|
|
68
|
+
}
|
|
60
69
|
},
|
|
61
70
|
"publishConfig": {
|
|
62
71
|
"access": "public"
|
|
63
72
|
},
|
|
64
|
-
"
|
|
65
|
-
"entries": [
|
|
66
|
-
"./src/index.ts",
|
|
67
|
-
"./src/webpack-loader.ts"
|
|
68
|
-
],
|
|
69
|
-
"externals": [
|
|
70
|
-
"webpack",
|
|
71
|
-
"vite",
|
|
72
|
-
"rollup",
|
|
73
|
-
"esbuild"
|
|
74
|
-
],
|
|
75
|
-
"platform": "node"
|
|
76
|
-
},
|
|
77
|
-
"gitHead": "e6a7fd8a655c69780bc20b9749c2699e44beae16"
|
|
73
|
+
"gitHead": "a8e7fd8a655c69780bc20b9749d2699e45beae16"
|
|
78
74
|
}
|
package/dist/chunk-MXFP7CYD.mjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
var __require=(x=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(x,{get:(a,b)=>(typeof require<"u"?require:a)[b]}):x)(function(x){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+x+'" is not supported')});
|
|
2
|
-
|
|
3
|
-
export { __require };
|
package/dist/index.mjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { __require } from './chunk-MXFP7CYD.mjs';
|
|
2
|
-
import { createUnplugin } from 'unplugin';
|
|
3
|
-
import { readFile } from 'node:fs/promises';
|
|
4
|
-
import { loadCsf, enrichCsf, formatCsf } from 'storybook/internal/csf-tools';
|
|
5
|
-
import { logger } from 'storybook/internal/node-logger';
|
|
6
|
-
|
|
7
|
-
var STORIES_REGEX=/(?<!node_modules.*)\.(story|stories)\.[tj]sx?$/;function rollupBasedPlugin(options){return {name:"plugin-csf",async transform(code,id){if(!STORIES_REGEX.test(id))return;let sourceCode=await readFile(id,"utf-8");try{let makeTitle=userTitle=>userTitle||"default",csf=loadCsf(code,{makeTitle}).parse(),csfSource=loadCsf(sourceCode,{makeTitle}).parse();enrichCsf(csf,csfSource,options);let inputSourceMap=this.getCombinedSourcemap();return formatCsf(csf,{sourceMaps:!0,inputSourceMap},code)}catch(err){return err.message?.startsWith("CSF:")||logger.warn(err.message),code}}}}var 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;
|
|
8
|
-
|
|
9
|
-
export { esbuild, rollup, unplugin, vite, webpack };
|
package/dist/webpack-loader.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { EnrichCsfOptions } from 'storybook/internal/csf-tools';
|
|
2
|
-
|
|
3
|
-
interface LoaderContext {
|
|
4
|
-
async: () => (err: Error | null, result?: string, map?: any) => void;
|
|
5
|
-
getOptions: () => EnrichCsfOptions;
|
|
6
|
-
resourcePath: string;
|
|
7
|
-
}
|
|
8
|
-
declare function loader(this: LoaderContext, content: string, map: any): Promise<void>;
|
|
9
|
-
|
|
10
|
-
export { loader as default };
|
package/dist/webpack-loader.mjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import './chunk-MXFP7CYD.mjs';
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
3
|
-
import { loadCsf, enrichCsf, formatCsf } from 'storybook/internal/csf-tools';
|
|
4
|
-
|
|
5
|
-
async function loader(content,map){let callback=this.async(),options=this.getOptions(),id=this.resourcePath,sourceCode=await readFile(id,"utf-8");try{let makeTitle=userTitle=>userTitle||"default",csf=loadCsf(content,{makeTitle}).parse(),csfSource=loadCsf(sourceCode,{makeTitle}).parse();enrichCsf(csf,csfSource,options);let formattedCsf=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;
|
|
6
|
-
|
|
7
|
-
export { webpack_loader_default as default };
|