@modern-js/storybook-builder 0.0.0-next-20230913035856
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/.eslintrc.js +7 -0
- package/.turbo/turbo-build.log +6 -0
- package/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/dist/cjs/addons/components/modern.js +65 -0
- package/dist/cjs/addons/constants.js +11 -0
- package/dist/cjs/addons/index.js +20 -0
- package/dist/cjs/addons/preset/preview.js +14 -0
- package/dist/cjs/addons/type.js +4 -0
- package/dist/cjs/addons/withPluginRuntime.js +20 -0
- package/dist/cjs/build.js +109 -0
- package/dist/cjs/core.js +40 -0
- package/dist/cjs/docgen/actualNameHandler.js +34 -0
- package/dist/cjs/docgen/index.js +74 -0
- package/dist/cjs/docgen/loader.js +37 -0
- package/dist/cjs/docgen/process.js +39 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/plugin-storybook.js +316 -0
- package/dist/cjs/preset.js +61 -0
- package/dist/cjs/types.js +11 -0
- package/dist/cjs/utils.js +142 -0
- package/dist/esm/addons/components/modern.js +44 -0
- package/dist/esm/addons/constants.js +1 -0
- package/dist/esm/addons/index.js +5 -0
- package/dist/esm/addons/preset/preview.js +4 -0
- package/dist/esm/addons/type.js +1 -0
- package/dist/esm/addons/withPluginRuntime.js +10 -0
- package/dist/esm/build.js +83 -0
- package/dist/esm/core.js +30 -0
- package/dist/esm/docgen/actualNameHandler.js +24 -0
- package/dist/esm/docgen/index.js +54 -0
- package/dist/esm/docgen/loader.js +26 -0
- package/dist/esm/docgen/process.js +28 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/plugin-storybook.js +296 -0
- package/dist/esm/preset.js +36 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils.js +95 -0
- package/dist/types/addons/components/modern.d.ts +5 -0
- package/dist/types/addons/constants.d.ts +1 -0
- package/dist/types/addons/index.d.ts +2 -0
- package/dist/types/addons/preset/preview.d.ts +1 -0
- package/dist/types/addons/type.d.ts +4 -0
- package/dist/types/addons/withPluginRuntime.d.ts +2 -0
- package/dist/types/build.d.ts +7 -0
- package/dist/types/core.d.ts +4 -0
- package/dist/types/docgen/actualNameHandler.d.ts +14 -0
- package/dist/types/docgen/index.d.ts +9 -0
- package/dist/types/docgen/loader.d.ts +2 -0
- package/dist/types/docgen/process.d.ts +10 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/plugin-storybook.d.ts +6 -0
- package/dist/types/preset.d.ts +6 -0
- package/dist/types/types.d.ts +15 -0
- package/dist/types/utils.d.ts +12 -0
- package/index.js +24 -0
- package/modern.config.js +5 -0
- package/package.json +96 -0
- package/src/addons/components/modern.tsx +52 -0
- package/src/addons/constants.ts +1 -0
- package/src/addons/index.ts +8 -0
- package/src/addons/preset/preview.ts +3 -0
- package/src/addons/type.ts +4 -0
- package/src/addons/withPluginRuntime.ts +18 -0
- package/src/build.ts +119 -0
- package/src/core.ts +51 -0
- package/src/docgen/actualNameHandler.ts +57 -0
- package/src/docgen/index.ts +100 -0
- package/src/docgen/loader.ts +34 -0
- package/src/docgen/process.ts +44 -0
- package/src/index.ts +7 -0
- package/src/plugin-storybook.ts +462 -0
- package/src/preset.ts +59 -0
- package/src/types.ts +21 -0
- package/src/utils.ts +131 -0
- package/templates/preview.ejs +54 -0
- package/templates/virtualModuleModernEntry.js.handlebars +43 -0
- package/tsconfig.json +16 -0
package/.eslintrc.js
ADDED
package/CHANGELOG.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# @modern-js/storybook-builder
|
2
|
+
|
3
|
+
## 0.0.0-next-20230913035856
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- aec9975f8: feat: add storybook-framework
|
8
|
+
feat: 支持 storybook-framework
|
9
|
+
- Updated dependencies [e2def6e3d]
|
10
|
+
- Updated dependencies [8ed713c05]
|
11
|
+
- Updated dependencies [225f065f4]
|
12
|
+
- Updated dependencies [0300daf88]
|
13
|
+
- Updated dependencies [15b834f65]
|
14
|
+
- Updated dependencies [28128ca6e]
|
15
|
+
- Updated dependencies [d87a42600]
|
16
|
+
- Updated dependencies [4027a6aba]
|
17
|
+
- Updated dependencies [3d93e8114]
|
18
|
+
- @modern-js/builder-rspack-provider@0.0.0-next-20230913035856
|
19
|
+
- @modern-js/builder@0.0.0-next-20230913035856
|
20
|
+
- @modern-js/builder-shared@0.0.0-next-20230913035856
|
21
|
+
- @modern-js/utils@0.0.0-next-20230913035856
|
22
|
+
- @modern-js/core@0.0.0-next-20230913035856
|
23
|
+
- @modern-js/builder-webpack-provider@0.0.0-next-20230913035856
|
24
|
+
- @modern-js/runtime@0.0.0-next-20230913035856
|
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021-present Modern.js
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
6
|
+
for (var name in all)
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
13
|
+
WrapProviders: function() {
|
14
|
+
return WrapProviders;
|
15
|
+
},
|
16
|
+
resolvePlugins: function() {
|
17
|
+
return resolvePlugins;
|
18
|
+
}
|
19
|
+
});
|
20
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
21
|
+
const _jsxruntime = require("react/jsx-runtime");
|
22
|
+
const _react = /* @__PURE__ */ _interop_require_default._(require("react"));
|
23
|
+
const _runtime = require("@modern-js/runtime");
|
24
|
+
const _router = /* @__PURE__ */ _interop_require_default._(require("@modern-js/runtime/router"));
|
25
|
+
const _model = /* @__PURE__ */ _interop_require_default._(require("@modern-js/runtime/model"));
|
26
|
+
const WrapProviders = (storyFn, config) => {
|
27
|
+
const App = (0, _runtime.createApp)({
|
28
|
+
plugins: resolvePlugins(config.modernConfigRuntime)
|
29
|
+
})(storyFn);
|
30
|
+
return /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {});
|
31
|
+
};
|
32
|
+
const allowedRuntimeAPI = {
|
33
|
+
router: "router",
|
34
|
+
state: "state"
|
35
|
+
};
|
36
|
+
const allowedRuntimeAPIValues = Object.values(allowedRuntimeAPI);
|
37
|
+
const resolvePlugins = (runtime) => {
|
38
|
+
const plugins = [];
|
39
|
+
if (!runtime) {
|
40
|
+
return plugins;
|
41
|
+
}
|
42
|
+
Object.keys(runtime).forEach((api) => {
|
43
|
+
if (allowedRuntimeAPIValues.includes(api)) {
|
44
|
+
if (api === allowedRuntimeAPI.state) {
|
45
|
+
if (typeof runtime.state === "boolean") {
|
46
|
+
if (runtime.state) {
|
47
|
+
plugins.push((0, _model.default)({}));
|
48
|
+
}
|
49
|
+
} else if (typeof runtime.state === "object") {
|
50
|
+
plugins.push((0, _model.default)(runtime.state));
|
51
|
+
}
|
52
|
+
} else if (api === allowedRuntimeAPI.router) {
|
53
|
+
plugins.push((0, _router.default)({
|
54
|
+
...{
|
55
|
+
serverBase: [
|
56
|
+
"/"
|
57
|
+
]
|
58
|
+
},
|
59
|
+
...runtime.router
|
60
|
+
}));
|
61
|
+
}
|
62
|
+
}
|
63
|
+
});
|
64
|
+
return plugins;
|
65
|
+
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(
|
6
|
+
exports,
|
7
|
+
// make it work with --isolatedModules
|
8
|
+
"default",
|
9
|
+
{
|
10
|
+
enumerable: true,
|
11
|
+
get: function() {
|
12
|
+
return _default;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
);
|
16
|
+
var _module_hot, _module;
|
17
|
+
if ((_module = module) === null || _module === void 0 ? void 0 : (_module_hot = _module.hot) === null || _module_hot === void 0 ? void 0 : _module_hot.decline) {
|
18
|
+
module.hot.decline();
|
19
|
+
}
|
20
|
+
const _default = {};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "decorators", {
|
6
|
+
enumerable: true,
|
7
|
+
get: function() {
|
8
|
+
return decorators;
|
9
|
+
}
|
10
|
+
});
|
11
|
+
const _withPluginRuntime = require("../withPluginRuntime");
|
12
|
+
const decorators = [
|
13
|
+
_withPluginRuntime.withPluginRuntime
|
14
|
+
];
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "withPluginRuntime", {
|
6
|
+
enumerable: true,
|
7
|
+
get: function() {
|
8
|
+
return withPluginRuntime;
|
9
|
+
}
|
10
|
+
});
|
11
|
+
const _previewapi = require("@storybook/preview-api");
|
12
|
+
const _modern = require("./components/modern");
|
13
|
+
const withPluginRuntime = (storyFn) => {
|
14
|
+
const modernConfigRuntime = (0, _previewapi.useParameter)("modernConfigRuntime");
|
15
|
+
const modernConfigDesignToken = (0, _previewapi.useParameter)("modernConfigDesignToken");
|
16
|
+
return (0, _modern.WrapProviders)(storyFn, {
|
17
|
+
modernConfigRuntime: modernConfigRuntime || {},
|
18
|
+
modernConfigDesignToken
|
19
|
+
});
|
20
|
+
};
|
@@ -0,0 +1,109 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
6
|
+
for (var name in all)
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
13
|
+
getConfig: function() {
|
14
|
+
return getConfig;
|
15
|
+
},
|
16
|
+
build: function() {
|
17
|
+
return build;
|
18
|
+
},
|
19
|
+
start: function() {
|
20
|
+
return start;
|
21
|
+
},
|
22
|
+
bail: function() {
|
23
|
+
return bail;
|
24
|
+
}
|
25
|
+
});
|
26
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
27
|
+
const _path = require("path");
|
28
|
+
const _webpackdevmiddleware = /* @__PURE__ */ _interop_require_default._(require("@modern-js/utils/webpack-dev-middleware"));
|
29
|
+
const _webpackhotmiddleware = /* @__PURE__ */ _interop_require_default._(require("webpack-hot-middleware"));
|
30
|
+
const _servestatic = /* @__PURE__ */ _interop_require_default._(require("serve-static"));
|
31
|
+
const _utils = require("@modern-js/utils");
|
32
|
+
const _core = require("./core");
|
33
|
+
const _pluginstorybook = require("./plugin-storybook");
|
34
|
+
const getConfig = async (options) => {
|
35
|
+
var _frameworkOptions;
|
36
|
+
const { presets } = options;
|
37
|
+
const frameworkOptions = await presets.apply("frameworkOptions");
|
38
|
+
return ((_frameworkOptions = frameworkOptions) === null || _frameworkOptions === void 0 ? void 0 : _frameworkOptions.options) || {};
|
39
|
+
};
|
40
|
+
const build = async ({ options }) => {
|
41
|
+
const config = await getConfig(options);
|
42
|
+
const compiler = await (0, _core.getCompiler)(process.cwd(), config, options);
|
43
|
+
const previewResolvedDir = (0, _path.dirname)(require.resolve("@storybook/preview/package.json"));
|
44
|
+
const previewDirOrigin = (0, _path.join)(previewResolvedDir, "dist");
|
45
|
+
const previewDirTarget = (0, _path.join)(options.outputDir || "", `sb-preview`);
|
46
|
+
const previewFiles = _utils.fs.copy(previewDirOrigin, previewDirTarget, {
|
47
|
+
filter: (src) => {
|
48
|
+
const { ext } = (0, _path.parse)(src);
|
49
|
+
if (ext) {
|
50
|
+
return ext === ".js";
|
51
|
+
}
|
52
|
+
return true;
|
53
|
+
}
|
54
|
+
});
|
55
|
+
const compilation = new Promise((resolve, reject) => {
|
56
|
+
compiler.run((err, stats2) => {
|
57
|
+
if (err) {
|
58
|
+
reject(err);
|
59
|
+
} else {
|
60
|
+
resolve(stats2);
|
61
|
+
}
|
62
|
+
});
|
63
|
+
});
|
64
|
+
const [stats] = await Promise.all([
|
65
|
+
compilation,
|
66
|
+
previewFiles
|
67
|
+
]);
|
68
|
+
return stats;
|
69
|
+
};
|
70
|
+
const start = async ({ options, router, startTime }) => {
|
71
|
+
var _config_builderConfig_tools_devServer_devMiddleware, _config_builderConfig_tools_devServer, _config_builderConfig_tools, _config_builderConfig;
|
72
|
+
const previewResolvedDir = (0, _path.dirname)(require.resolve("@storybook/preview/package.json"));
|
73
|
+
const previewDirOrigin = (0, _path.join)(previewResolvedDir, "dist");
|
74
|
+
router.use(`/sb-preview`, (0, _servestatic.default)(previewDirOrigin, {
|
75
|
+
immutable: true,
|
76
|
+
maxAge: "5m"
|
77
|
+
}));
|
78
|
+
const config = await getConfig(options);
|
79
|
+
const compiler = await (0, _core.getCompiler)(process.cwd(), config, options);
|
80
|
+
const middleware = (0, _webpackdevmiddleware.default)(compiler, {
|
81
|
+
writeToDisk: ((_config_builderConfig = config.builderConfig) === null || _config_builderConfig === void 0 ? void 0 : (_config_builderConfig_tools = _config_builderConfig.tools) === null || _config_builderConfig_tools === void 0 ? void 0 : (_config_builderConfig_tools_devServer = _config_builderConfig_tools.devServer) === null || _config_builderConfig_tools_devServer === void 0 ? void 0 : (_config_builderConfig_tools_devServer_devMiddleware = _config_builderConfig_tools_devServer.devMiddleware) === null || _config_builderConfig_tools_devServer_devMiddleware === void 0 ? void 0 : _config_builderConfig_tools_devServer_devMiddleware.writeToDisk) || true,
|
82
|
+
// builder can log errors, so not using dev-middleware logs
|
83
|
+
stats: false
|
84
|
+
});
|
85
|
+
router.use(middleware);
|
86
|
+
router.use((0, _webpackhotmiddleware.default)(compiler, {
|
87
|
+
log: false
|
88
|
+
}));
|
89
|
+
const stats = await new Promise((resolve) => {
|
90
|
+
middleware.waitUntilValid((stats2) => {
|
91
|
+
resolve(stats2);
|
92
|
+
});
|
93
|
+
});
|
94
|
+
if (!stats) {
|
95
|
+
throw new Error("build failed");
|
96
|
+
}
|
97
|
+
const statsJson = stats.toJson();
|
98
|
+
if (statsJson.errors.length > 1) {
|
99
|
+
throw stats;
|
100
|
+
}
|
101
|
+
return {
|
102
|
+
bail,
|
103
|
+
stats,
|
104
|
+
totalTime: process.hrtime(startTime)
|
105
|
+
};
|
106
|
+
};
|
107
|
+
const bail = async () => {
|
108
|
+
await (0, _pluginstorybook.finalize)();
|
109
|
+
};
|
package/dist/cjs/core.js
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "getCompiler", {
|
6
|
+
enumerable: true,
|
7
|
+
get: function() {
|
8
|
+
return getCompiler;
|
9
|
+
}
|
10
|
+
});
|
11
|
+
const _builder = require("@modern-js/builder");
|
12
|
+
const _core = require("@modern-js/core");
|
13
|
+
const _utils = require("./utils");
|
14
|
+
const _pluginstorybook = require("./plugin-storybook");
|
15
|
+
async function getCompiler(cwd, frameworkConfig, options) {
|
16
|
+
const bundler = frameworkConfig.bundler || "webpack";
|
17
|
+
const { presets } = options;
|
18
|
+
const entries = await presets.apply("entries", []);
|
19
|
+
const res = await (0, _utils.runWithErrorMsg)(() => (0, _core.loadConfig)(cwd, frameworkConfig.configPath || "modern.config.ts"), "Failed to load config");
|
20
|
+
const loadedConfig = res ? res.config : {};
|
21
|
+
const otherBuilderConfig = await presets.apply("modern", loadedConfig) || {};
|
22
|
+
const builderConfig = (0, _builder.mergeBuilderConfig)(otherBuilderConfig, loadedConfig);
|
23
|
+
const provider = await (0, _utils.getProvider)(bundler, builderConfig);
|
24
|
+
if (!provider) {
|
25
|
+
throw new Error(`@modern-js/builder-${bundler}-provider not found `);
|
26
|
+
}
|
27
|
+
const builder = await (0, _builder.createBuilder)(provider, {
|
28
|
+
cwd,
|
29
|
+
target: "web",
|
30
|
+
framework: "modern.js storybook",
|
31
|
+
entry: {
|
32
|
+
main: entries
|
33
|
+
}
|
34
|
+
});
|
35
|
+
builder.addPlugins([
|
36
|
+
(0, _pluginstorybook.pluginStorybook)(cwd, options),
|
37
|
+
...loadedConfig.builderPlugins || []
|
38
|
+
]);
|
39
|
+
return builder.createCompiler();
|
40
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "default", {
|
6
|
+
enumerable: true,
|
7
|
+
get: function() {
|
8
|
+
return actualNameHandler;
|
9
|
+
}
|
10
|
+
});
|
11
|
+
const _asttypes = require("ast-types");
|
12
|
+
const _utils = require("react-docgen/dist/utils");
|
13
|
+
function actualNameHandler(documentation, path, importer) {
|
14
|
+
if (_asttypes.namedTypes.ClassDeclaration.check(path.node) || _asttypes.namedTypes.FunctionDeclaration.check(path.node)) {
|
15
|
+
documentation.set("actualName", (0, _utils.getNameOrValue)(path.get("id")));
|
16
|
+
} else if (_asttypes.namedTypes.ArrowFunctionExpression.check(path.node) || _asttypes.namedTypes.FunctionExpression.check(path.node) || (0, _utils.isReactForwardRefCall)(path, importer)) {
|
17
|
+
let currentPath = path;
|
18
|
+
while (currentPath.parent) {
|
19
|
+
if (_asttypes.namedTypes.VariableDeclarator.check(currentPath.parent.node)) {
|
20
|
+
documentation.set("actualName", (0, _utils.getNameOrValue)(currentPath.parent.get("id")));
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
if (_asttypes.namedTypes.AssignmentExpression.check(currentPath.parent.node)) {
|
24
|
+
const leftPath = currentPath.parent.get("left");
|
25
|
+
if (_asttypes.namedTypes.Identifier.check(leftPath.node) || _asttypes.namedTypes.Literal.check(leftPath.node)) {
|
26
|
+
documentation.set("actualName", (0, _utils.getNameOrValue)(leftPath));
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
currentPath = currentPath.parent;
|
31
|
+
}
|
32
|
+
documentation.set("actualName", "");
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
6
|
+
for (var name in all)
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
13
|
+
applyDocgenWebpack: function() {
|
14
|
+
return applyDocgenWebpack;
|
15
|
+
},
|
16
|
+
applyDocgenRspack: function() {
|
17
|
+
return applyDocgenRspack;
|
18
|
+
}
|
19
|
+
});
|
20
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
21
|
+
const _utils = require("@modern-js/utils");
|
22
|
+
async function applyDocgenWebpack(chain, options) {
|
23
|
+
const typescriptOptions = await options.presets.apply("typescript", {});
|
24
|
+
const { reactDocgen, reactDocgenTypescriptOptions } = typescriptOptions || {};
|
25
|
+
if (typeof reactDocgen !== "string") {
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
if (reactDocgen === "react-docgen-typescript") {
|
29
|
+
const { ReactDocgenTypeScriptPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@storybook/react-docgen-typescript-plugin")));
|
30
|
+
chain.plugin("Storybook-docgen").use(ReactDocgenTypeScriptPlugin, [
|
31
|
+
{
|
32
|
+
...reactDocgenTypescriptOptions,
|
33
|
+
savePropValueAsString: true
|
34
|
+
}
|
35
|
+
]);
|
36
|
+
} else if (reactDocgen === "react-docgen") {
|
37
|
+
const loader = require.resolve("./loader");
|
38
|
+
const resolveOptions = chain.toConfig().resolve;
|
39
|
+
chain.module.rule(_utils.CHAIN_ID.RULE.JS).use(_utils.CHAIN_ID.USE.REACT_DOCGEN).loader(loader).options({
|
40
|
+
resolveOptions
|
41
|
+
}).after(_utils.CHAIN_ID.USE.BABEL).after(_utils.CHAIN_ID.USE.ESBUILD).after(_utils.CHAIN_ID.USE.SWC).end();
|
42
|
+
const tsRuls = chain.module.rule(_utils.CHAIN_ID.RULE.TS);
|
43
|
+
if (tsRuls.uses.values().length !== 0) {
|
44
|
+
tsRuls.use(_utils.CHAIN_ID.USE.REACT_DOCGEN).loader(loader).options({
|
45
|
+
resolveOptions
|
46
|
+
}).after(_utils.CHAIN_ID.USE.TS).after(_utils.CHAIN_ID.USE.ESBUILD).after(_utils.CHAIN_ID.USE.SWC).end();
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
async function applyDocgenRspack(config, options) {
|
51
|
+
var _config, _config_module;
|
52
|
+
const typescriptOptions = await options.presets.apply("typescript", {});
|
53
|
+
const { reactDocgen } = typescriptOptions || {};
|
54
|
+
if (reactDocgen !== "react-docgen") {
|
55
|
+
if (reactDocgen !== false && reactDocgen !== void 0) {
|
56
|
+
_utils.logger.warn(`Rspack currently only support 'typescript.reactDocgen: react-docgen' for auto docs generation, but you specified ${reactDocgen}`);
|
57
|
+
}
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
var _module;
|
61
|
+
(_module = (_config = config).module) !== null && _module !== void 0 ? _module : _config.module = {};
|
62
|
+
var _rules;
|
63
|
+
(_rules = (_config_module = config.module).rules) !== null && _rules !== void 0 ? _rules : _config_module.rules = [];
|
64
|
+
config.module.rules.push({
|
65
|
+
test: /\.(tsx?|jsx?)$/,
|
66
|
+
exclude: /node_modules/,
|
67
|
+
use: {
|
68
|
+
loader: require.resolve("./loader"),
|
69
|
+
options: {
|
70
|
+
resolveOptions: config.resolve
|
71
|
+
}
|
72
|
+
}
|
73
|
+
});
|
74
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "default", {
|
6
|
+
enumerable: true,
|
7
|
+
get: function() {
|
8
|
+
return _default;
|
9
|
+
}
|
10
|
+
});
|
11
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
12
|
+
let tinyPoolPromise = null;
|
13
|
+
async function docLoader(source, map, data) {
|
14
|
+
const callback = this.async();
|
15
|
+
if (!tinyPoolPromise) {
|
16
|
+
tinyPoolPromise = Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("tinypool"))).then(({ Tinypool }) => {
|
17
|
+
return new Tinypool({
|
18
|
+
filename: require.resolve("./process")
|
19
|
+
});
|
20
|
+
});
|
21
|
+
}
|
22
|
+
const tinyPool = await tinyPoolPromise;
|
23
|
+
const result = await tinyPool.run({
|
24
|
+
source,
|
25
|
+
map,
|
26
|
+
filename: this.resourcePath,
|
27
|
+
data
|
28
|
+
});
|
29
|
+
if (result) {
|
30
|
+
const [docgen, outputMap] = result;
|
31
|
+
callback(null, `${source}
|
32
|
+
${docgen}`, outputMap, data);
|
33
|
+
} else {
|
34
|
+
callback(null, source, map, data);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
const _default = docLoader;
|
@@ -0,0 +1,39 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "default", {
|
6
|
+
enumerable: true,
|
7
|
+
get: function() {
|
8
|
+
return _default;
|
9
|
+
}
|
10
|
+
});
|
11
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
12
|
+
const _reactdocgen = require("react-docgen");
|
13
|
+
const _actualNameHandler = /* @__PURE__ */ _interop_require_default._(require("./actualNameHandler"));
|
14
|
+
const defaultHandlers = Object.values(_reactdocgen.handlers).map((handler) => handler);
|
15
|
+
const importer = _reactdocgen.importers.makeFsImporter();
|
16
|
+
const _default = ({ source, map, filename }) => {
|
17
|
+
try {
|
18
|
+
const results = (0, _reactdocgen.parse)(source, _reactdocgen.resolver.findAllExportedComponentDefinitions, [
|
19
|
+
...defaultHandlers,
|
20
|
+
_actualNameHandler.default
|
21
|
+
], {
|
22
|
+
filename,
|
23
|
+
importer
|
24
|
+
});
|
25
|
+
const docgen = results.map((result) => {
|
26
|
+
const { actualName, ...docgenInfo } = result;
|
27
|
+
if (actualName) {
|
28
|
+
return `${actualName}.__docgenInfo=${JSON.stringify(docgenInfo)}`;
|
29
|
+
}
|
30
|
+
return "";
|
31
|
+
}).filter(Boolean).join(";");
|
32
|
+
return [
|
33
|
+
docgen,
|
34
|
+
map
|
35
|
+
];
|
36
|
+
} catch (e) {
|
37
|
+
return null;
|
38
|
+
}
|
39
|
+
};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
6
|
+
for (var name in all)
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
13
|
+
start: function() {
|
14
|
+
return _build.start;
|
15
|
+
},
|
16
|
+
build: function() {
|
17
|
+
return _build.build;
|
18
|
+
},
|
19
|
+
bail: function() {
|
20
|
+
return _build.bail;
|
21
|
+
},
|
22
|
+
getConfig: function() {
|
23
|
+
return _build.getConfig;
|
24
|
+
},
|
25
|
+
corePresets: function() {
|
26
|
+
return corePresets;
|
27
|
+
}
|
28
|
+
});
|
29
|
+
const _export_star = require("@swc/helpers/_/_export_star");
|
30
|
+
const _path = require("path");
|
31
|
+
const _build = require("./build");
|
32
|
+
_export_star._(require("./types"), exports);
|
33
|
+
const corePresets = [
|
34
|
+
(0, _path.join)(__dirname, "./preset.js")
|
35
|
+
];
|