storybook
Version:
Storybook: Develop, document, and test UI components in isolation
77 lines (73 loc) • 3.15 kB
JavaScript
import CJS_COMPAT_NODE_URL_paa39lqmhk from 'node:url';
import CJS_COMPAT_NODE_PATH_paa39lqmhk from 'node:path';
import CJS_COMPAT_NODE_MODULE_paa39lqmhk from "node:module";
var __filename = CJS_COMPAT_NODE_URL_paa39lqmhk.fileURLToPath(import.meta.url);
var __dirname = CJS_COMPAT_NODE_PATH_paa39lqmhk.dirname(__filename);
var require = CJS_COMPAT_NODE_MODULE_paa39lqmhk.createRequire(import.meta.url);
// ------------------------------------------------------------
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
// ------------------------------------------------------------
import {
resolveStorybookConfigDir
} from "./chunk-L5SYMBIZ.js";
import {
ToolsRuntimeError,
projectPathsEqual
} from "./chunk-E7OKDKKL.js";
import {
clearToolsetRegistry,
getRegisteredToolsets
} from "./chunk-7LP4DGGS.js";
import "./chunk-LMVESVEK.js";
import {
clearRegistry
} from "./chunk-A5QK6FVS.js";
import "./chunk-GZENSKDV.js";
import "./chunk-RS3OANVC.js";
import "./chunk-VEG5VN5A.js";
import "./chunk-MW37V742.js";
import "./chunk-MJJYZGM3.js";
import "./chunk-IN455KZR.js";
// src/cli/tools/sdk/local-runtime.ts
import { resolve } from "node:path";
import {
ChangeDetectionService,
experimental_getStatusStore,
experimental_loadStorybook,
experimental_resetChangeDetectionReadiness,
experimental_resetServicesPresetOnce,
experimental_setChangeDetectionHost,
getService,
prepareHeadlessUniversalStores
} from "storybook/internal/core-server";
import { CHANGE_DETECTION_STATUS_TYPE_ID } from "storybook/internal/types";
async function bootstrapToolsRuntime(target, deps = {}) {
let cwd = resolve(target.cwd ?? process.cwd());
if (!projectPathsEqual(cwd, process.cwd()))
throw new ToolsRuntimeError({
reason: "mode-unavailable",
message: `Local tools bootstrap requires process.cwd() to be the target project (${cwd}), not ${process.cwd()}.`
});
let configDir = resolveStorybookConfigDir({ cwd, configDir: target.configDir }), channel = prepareHeadlessUniversalStores(), options = await experimental_loadStorybook({ configDir, channel }), setChangeDetectionHost = deps.setChangeDetectionHost ?? experimental_setChangeDetectionHost;
setChangeDetectionHost(() => startChangeDetectionInProcess(options));
let closed = !1, close = async () => {
closed || (closed = !0, clearRegistry(), clearToolsetRegistry(), experimental_resetServicesPresetOnce(), setChangeDetectionHost(void 0), experimental_resetChangeDetectionReadiness());
};
return {
configDir,
toolsets: getRegisteredToolsets(),
getService: (serviceId, serviceOptions) => getService(serviceId, serviceOptions),
close
};
}
async function startChangeDetectionInProcess(options) {
let changeDetectionService = new ChangeDetectionService({
storyIndexGeneratorPromise: options.presets.apply("storyIndexGenerator"),
statusStore: experimental_getStatusStore(CHANGE_DETECTION_STATUS_TYPE_ID),
workingDir: process.cwd()
}), features = await options.presets.apply("features");
changeDetectionService.start(features?.changeDetection !== !1);
}
export {
bootstrapToolsRuntime
};