@storybook/builder-vite 10.4.0-alpha.9 → 10.4.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.
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_mnw6l1lqcif from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_mnw6l1lqcif from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_mnw6l1lqcif from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_mnw6l1lqcif.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_mnw6l1lqcif.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_mnw6l1lqcif.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
package/dist/index.d.ts
CHANGED
|
@@ -24,9 +24,14 @@ declare const withoutVitePlugins: <TPlugin>(plugins: TPlugin[] | undefined, name
|
|
|
24
24
|
declare function hasVitePlugins(plugins: PluginOption[], names: string[]): Promise<boolean>;
|
|
25
25
|
|
|
26
26
|
declare function bail(): Promise<void>;
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Returns a {@link ChangeDetectionAdapter} bound to the Vite dev server created by `start()`.
|
|
29
|
+
*
|
|
30
|
+
* Throws if called before `start()` has resolved (i.e. before the Vite dev server exists).
|
|
31
|
+
*/
|
|
32
|
+
declare const changeDetectionAdapter: NonNullable<Builder<Options>['changeDetectionAdapter']>;
|
|
28
33
|
declare const start: ViteBuilder['start'];
|
|
29
34
|
declare const build: ViteBuilder['build'];
|
|
30
35
|
declare const corePresets: string[];
|
|
31
36
|
|
|
32
|
-
export { type BuilderOptions, type StorybookConfigVite, type ViteBuilder, type ViteFinal, bail, build, corePresets, hasVitePlugins,
|
|
37
|
+
export { type BuilderOptions, type StorybookConfigVite, type ViteBuilder, type ViteFinal, bail, build, changeDetectionAdapter, corePresets, hasVitePlugins, start, withoutVitePlugins };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_mnw6l1lqcif from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_mnw6l1lqcif from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_mnw6l1lqcif from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_mnw6l1lqcif.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_mnw6l1lqcif.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_mnw6l1lqcif.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
normalize,
|
|
25
25
|
relative,
|
|
26
26
|
viteCorePlugins
|
|
27
|
-
} from "./_node-chunks/chunk-
|
|
27
|
+
} from "./_node-chunks/chunk-RPKZLEOZ.js";
|
|
28
28
|
|
|
29
29
|
// ../../../node_modules/picocolors/picocolors.js
|
|
30
30
|
var require_picocolors = __commonJS({
|
|
@@ -93,7 +93,6 @@ var require_picocolors = __commonJS({
|
|
|
93
93
|
// src/index.ts
|
|
94
94
|
import { readFile } from "node:fs/promises";
|
|
95
95
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
96
|
-
import { logger as logger3 } from "storybook/internal/node-logger";
|
|
97
96
|
import { NoStatsForViteDevError } from "storybook/internal/server-errors";
|
|
98
97
|
|
|
99
98
|
// src/build.ts
|
|
@@ -1520,6 +1519,41 @@ async function build(options) {
|
|
|
1520
1519
|
)?.storybookGetStats();
|
|
1521
1520
|
}
|
|
1522
1521
|
|
|
1522
|
+
// src/change-detection-adapter/index.ts
|
|
1523
|
+
import { logger as logger3 } from "storybook/internal/node-logger";
|
|
1524
|
+
function createViteChangeDetectionAdapter(server2) {
|
|
1525
|
+
return {
|
|
1526
|
+
/**
|
|
1527
|
+
* Snapshots the Vite resolver configuration (aliases, conditions, root) once at
|
|
1528
|
+
* adapter creation time. If `vite.config.ts` is modified while Storybook is
|
|
1529
|
+
* running, this snapshot becomes stale and Storybook must be restarted to pick
|
|
1530
|
+
* up the updated aliases.
|
|
1531
|
+
*
|
|
1532
|
+
* A future improvement would subscribe to Vite's HMR config-reload event and
|
|
1533
|
+
* invalidate the resolver cache on config change.
|
|
1534
|
+
*/
|
|
1535
|
+
async getResolveConfig() {
|
|
1536
|
+
logger3.debug(
|
|
1537
|
+
"Change detection: snapshotting Vite resolve config (restart required if vite.config.ts changes)"
|
|
1538
|
+
);
|
|
1539
|
+
let resolveOpts = server2.config.resolve, alias = resolveOpts?.alias, conditions = resolveOpts?.conditions;
|
|
1540
|
+
return {
|
|
1541
|
+
projectRoot: server2.config.root,
|
|
1542
|
+
alias,
|
|
1543
|
+
conditions
|
|
1544
|
+
};
|
|
1545
|
+
},
|
|
1546
|
+
onFileChange(handler) {
|
|
1547
|
+
let FORWARDED_EVENTS = /* @__PURE__ */ new Set(["add", "change", "unlink"]), isForwardedEvent = (name) => FORWARDED_EVENTS.has(name), onAll = (eventName, path) => {
|
|
1548
|
+
isForwardedEvent(eventName) && handler({ kind: eventName, path: normalize(path) });
|
|
1549
|
+
};
|
|
1550
|
+
return server2.watcher.on("all", onAll), () => {
|
|
1551
|
+
server2.watcher.off("all", onAll);
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
};
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1523
1557
|
// src/vite-server.ts
|
|
1524
1558
|
async function createViteServer(options, devServer) {
|
|
1525
1559
|
let { presets } = options, commonCfg = await commonConfig(options, "development"), { allowedHosts } = await presets.apply("core", {}), config = {
|
|
@@ -1542,43 +1576,6 @@ async function createViteServer(options, devServer) {
|
|
|
1542
1576
|
return finalConfig.customLogger ??= await createViteLogger(), createServer(finalConfig);
|
|
1543
1577
|
}
|
|
1544
1578
|
|
|
1545
|
-
// src/utils/build-module-graph.ts
|
|
1546
|
-
function buildModuleGraph(fileToModulesMap) {
|
|
1547
|
-
let moduleGraph = /* @__PURE__ */ new Map(), moduleNodeMap = /* @__PURE__ */ new WeakMap(), getModuleFileFromMap = (viteModuleNode) => {
|
|
1548
|
-
for (let [filePath, viteModuleSet] of fileToModulesMap.entries())
|
|
1549
|
-
if (viteModuleSet.has(viteModuleNode))
|
|
1550
|
-
return filePath;
|
|
1551
|
-
}, getOrCreateModuleNode = (viteModuleNode, fallbackFile) => {
|
|
1552
|
-
let file = viteModuleNode.file ?? fallbackFile;
|
|
1553
|
-
if (!file)
|
|
1554
|
-
return;
|
|
1555
|
-
let existingNode = moduleNodeMap.get(viteModuleNode);
|
|
1556
|
-
if (existingNode)
|
|
1557
|
-
return existingNode;
|
|
1558
|
-
let moduleNode = {
|
|
1559
|
-
file,
|
|
1560
|
-
type: viteModuleNode.type,
|
|
1561
|
-
importers: /* @__PURE__ */ new Set(),
|
|
1562
|
-
importedModules: /* @__PURE__ */ new Set()
|
|
1563
|
-
};
|
|
1564
|
-
moduleNodeMap.set(viteModuleNode, moduleNode);
|
|
1565
|
-
let moduleSet = moduleGraph.get(file) ?? /* @__PURE__ */ new Set();
|
|
1566
|
-
return moduleSet.add(moduleNode), moduleGraph.set(file, moduleSet), moduleNode;
|
|
1567
|
-
};
|
|
1568
|
-
return fileToModulesMap.forEach((viteModuleSet, filePath) => {
|
|
1569
|
-
viteModuleSet.forEach((viteModuleNode) => {
|
|
1570
|
-
let moduleNode = getOrCreateModuleNode(viteModuleNode, filePath);
|
|
1571
|
-
moduleNode && (viteModuleNode.importers.forEach((importer) => {
|
|
1572
|
-
let importerNode = getOrCreateModuleNode(importer) ?? getOrCreateModuleNode(importer, getModuleFileFromMap(importer));
|
|
1573
|
-
importerNode && moduleNode.importers.add(importerNode);
|
|
1574
|
-
}), viteModuleNode.importedModules.forEach((importedModule) => {
|
|
1575
|
-
let importedModuleNode = getOrCreateModuleNode(importedModule) ?? getOrCreateModuleNode(importedModule, getModuleFileFromMap(importedModule));
|
|
1576
|
-
importedModuleNode && moduleNode.importedModules.add(importedModuleNode);
|
|
1577
|
-
}));
|
|
1578
|
-
});
|
|
1579
|
-
}), moduleGraph;
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1582
1579
|
// src/index.ts
|
|
1583
1580
|
function iframeHandler(options, server2) {
|
|
1584
1581
|
return async (req, res) => {
|
|
@@ -1591,77 +1588,22 @@ function iframeHandler(options, server2) {
|
|
|
1591
1588
|
res.setHeader("Content-Type", "text/html"), res.statusCode = 200, res.write(transformed), res.end();
|
|
1592
1589
|
};
|
|
1593
1590
|
}
|
|
1594
|
-
var server
|
|
1595
|
-
function clearModuleGraphPolling() {
|
|
1596
|
-
waitForModuleGraph && (clearInterval(waitForModuleGraph), waitForModuleGraph = void 0);
|
|
1597
|
-
}
|
|
1598
|
-
function notifyListeners(moduleGraph) {
|
|
1599
|
-
listeners.forEach((listener) => {
|
|
1600
|
-
listener({ type: "moduleGraph", moduleGraph });
|
|
1601
|
-
});
|
|
1602
|
-
}
|
|
1603
|
-
function notifyListenersOfStartupFailure(event) {
|
|
1604
|
-
listeners.forEach((listener) => {
|
|
1605
|
-
listener(event);
|
|
1606
|
-
});
|
|
1607
|
-
}
|
|
1591
|
+
var server;
|
|
1608
1592
|
async function bail() {
|
|
1609
|
-
return
|
|
1610
|
-
}
|
|
1611
|
-
function startModuleGraphTracking() {
|
|
1612
|
-
moduleGraphTrackingStarted || listeners.size === 0 || !server || !lastBuilderOptions || (moduleGraphTrackingStarted = !0, watcherChangeHandler = () => {
|
|
1613
|
-
clearTimeout(debounce), debounce = setTimeout(() => {
|
|
1614
|
-
notifyListeners(buildModuleGraph(server.moduleGraph.fileToModulesMap));
|
|
1615
|
-
}, 100);
|
|
1616
|
-
}, startChangeDetection(lastBuilderOptions).catch((error) => {
|
|
1617
|
-
clearModuleGraphPolling(), logger3.error("Failed to initialize Vite change detection"), logger3.error(error instanceof Error ? error : String(error)), notifyListenersOfStartupFailure({
|
|
1618
|
-
type: "error",
|
|
1619
|
-
error: error instanceof Error ? error : new Error(String(error))
|
|
1620
|
-
});
|
|
1621
|
-
}));
|
|
1593
|
+
return server?.close();
|
|
1622
1594
|
}
|
|
1623
|
-
var
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
try {
|
|
1630
|
-
if (!watcherChangeHandler) {
|
|
1631
|
-
clearModuleGraphPolling();
|
|
1632
|
-
return;
|
|
1633
|
-
}
|
|
1634
|
-
if (process.hrtime(startTime)[0] > 30) {
|
|
1635
|
-
clearModuleGraphPolling();
|
|
1636
|
-
let error = new Error(
|
|
1637
|
-
"Timed out while waiting for the Vite module graph to initialize"
|
|
1638
|
-
);
|
|
1639
|
-
logger3.error("Failed to complete Vite change detection startup"), logger3.error(error), notifyListenersOfStartupFailure({
|
|
1640
|
-
type: "unavailable",
|
|
1641
|
-
reason: error.message,
|
|
1642
|
-
error
|
|
1643
|
-
});
|
|
1644
|
-
return;
|
|
1645
|
-
}
|
|
1646
|
-
if (server.moduleGraph.fileToModulesMap.size > 0) {
|
|
1647
|
-
if (clearModuleGraphPolling(), await server.waitForRequestsIdle(), !watcherChangeHandler)
|
|
1648
|
-
return;
|
|
1649
|
-
server.watcher.on("all", watcherChangeHandler), watcherChangeHandler();
|
|
1650
|
-
}
|
|
1651
|
-
} catch (error) {
|
|
1652
|
-
clearModuleGraphPolling(), logger3.error("Failed to complete Vite change detection startup"), logger3.error(error instanceof Error ? error : String(error)), notifyListenersOfStartupFailure({
|
|
1653
|
-
type: "error",
|
|
1654
|
-
error: error instanceof Error ? error : new Error(String(error))
|
|
1655
|
-
});
|
|
1656
|
-
}
|
|
1657
|
-
})();
|
|
1658
|
-
}, 1e3);
|
|
1595
|
+
var changeDetectionAdapter = () => {
|
|
1596
|
+
if (!server)
|
|
1597
|
+
throw new Error(
|
|
1598
|
+
"builder-vite: changeDetectionAdapter() called before start(); the Vite dev server is not ready yet."
|
|
1599
|
+
);
|
|
1600
|
+
return createViteChangeDetectionAdapter(server);
|
|
1659
1601
|
}, start = async ({
|
|
1660
1602
|
startTime,
|
|
1661
1603
|
options,
|
|
1662
1604
|
router,
|
|
1663
1605
|
server: devServer
|
|
1664
|
-
}) => (
|
|
1606
|
+
}) => (server = await createViteServer(options, devServer), router.get("/iframe.html", iframeHandler(options, server)), router.use(server.middlewares), {
|
|
1665
1607
|
bail,
|
|
1666
1608
|
stats: {
|
|
1667
1609
|
toJson: () => {
|
|
@@ -1673,9 +1615,9 @@ var onModuleGraphChange = (cb) => (listeners.add(cb), startModuleGraphTracking()
|
|
|
1673
1615
|
export {
|
|
1674
1616
|
bail,
|
|
1675
1617
|
build2 as build,
|
|
1618
|
+
changeDetectionAdapter,
|
|
1676
1619
|
corePresets,
|
|
1677
1620
|
hasVitePlugins,
|
|
1678
|
-
onModuleGraphChange,
|
|
1679
1621
|
start,
|
|
1680
1622
|
withoutVitePlugins
|
|
1681
1623
|
};
|
package/dist/preset.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_mnw6l1lqcif from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_mnw6l1lqcif from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_mnw6l1lqcif from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_mnw6l1lqcif.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_mnw6l1lqcif.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_mnw6l1lqcif.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -12,7 +12,7 @@ var require = CJS_COMPAT_NODE_MODULE_4bsf84d8msn.createRequire(import.meta.url);
|
|
|
12
12
|
import {
|
|
13
13
|
optimizeViteDeps,
|
|
14
14
|
viteCorePlugins
|
|
15
|
-
} from "./_node-chunks/chunk-
|
|
15
|
+
} from "./_node-chunks/chunk-RPKZLEOZ.js";
|
|
16
16
|
export {
|
|
17
17
|
optimizeViteDeps,
|
|
18
18
|
viteCorePlugins
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/builder-vite",
|
|
3
|
-
"version": "10.4.0
|
|
3
|
+
"version": "10.4.0",
|
|
4
4
|
"description": "A Storybook builder to dev and build with Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"!src/**/*"
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@storybook/csf-plugin": "10.4.0
|
|
50
|
+
"@storybook/csf-plugin": "10.4.0",
|
|
51
51
|
"ts-dedent": "^2.0.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"vite": "^7.0.4"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"storybook": "^10.4.0
|
|
65
|
+
"storybook": "^10.4.0",
|
|
66
66
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
67
67
|
},
|
|
68
68
|
"publishConfig": {
|