@storybook-astro/framework 1.3.0 → 1.4.0-canary.2
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/dist/{chunk-N3WTUD2A.js → chunk-A4DQ67HA.js} +53 -2
- package/dist/chunk-A4DQ67HA.js.map +1 -0
- package/dist/{chunk-2EABPTOY.js → chunk-BV6V2Z4X.js} +2 -2
- package/dist/{chunk-AYYMNFI6.js → chunk-VZXGPM6P.js} +218 -34
- package/dist/chunk-VZXGPM6P.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/middleware.js +10 -2
- package/dist/middleware.js.map +1 -1
- package/dist/node/index.d.ts +1 -1
- package/dist/preset.d.ts +1 -1
- package/dist/preset.js +39 -21
- package/dist/preset.js.map +1 -1
- package/dist/testing.js +3 -3
- package/dist/{types-BCpJLSTo.d.ts → types--SvYP5Ri.d.ts} +55 -0
- package/dist/{viteStorybookAstroMiddlewarePlugin-UB6ZLJ4B.js → viteStorybookAstroMiddlewarePlugin-246I5D3Y.js} +2 -2
- package/dist/vitest/global-setup.js +2 -2
- package/package.json +3 -2
- package/src/lib/resolve-aliased-island.test.ts +150 -0
- package/src/lib/resolve-aliased-island.ts +97 -0
- package/src/loadUserAstroConfig.ts +59 -0
- package/src/middleware.ts +15 -0
- package/src/productionRenderRuntime.ts +6 -2
- package/src/storySsrVite.ts +15 -2
- package/src/types.ts +9 -1
- package/src/vitePluginAstro.ts +10 -3
- package/src/vitePluginAstroBuildPrerender.ts +4 -1
- package/src/vitePluginAstroBuildShared.test.ts +25 -6
- package/src/vitePluginAstroBuildShared.ts +25 -12
- package/src/vitePluginAstroFonts.test.ts +153 -0
- package/src/vitePluginAstroFonts.ts +302 -0
- package/src/viteStorybookAstroMiddlewarePlugin.ts +20 -8
- package/dist/chunk-AYYMNFI6.js.map +0 -1
- package/dist/chunk-N3WTUD2A.js.map +0 -1
- package/src/vitePluginAstroFontsFallback.ts +0 -69
- /package/dist/{chunk-2EABPTOY.js.map → chunk-BV6V2Z4X.js.map} +0 -0
- /package/dist/{viteStorybookAstroMiddlewarePlugin-UB6ZLJ4B.js.map → viteStorybookAstroMiddlewarePlugin-246I5D3Y.js.map} +0 -0
package/dist/middleware.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createAstroRenderHandler,
|
|
3
|
-
ensureAstroPassthroughImageService
|
|
4
|
-
|
|
3
|
+
ensureAstroPassthroughImageService,
|
|
4
|
+
resolveAliasedIsland
|
|
5
|
+
} from "./chunk-A4DQ67HA.js";
|
|
5
6
|
import "./chunk-ZIDMHD4S.js";
|
|
6
7
|
import {
|
|
7
8
|
resolveStoryModuleMock
|
|
@@ -31,6 +32,13 @@ async function handlerFactory(_integrations, options) {
|
|
|
31
32
|
if (resolution) {
|
|
32
33
|
return resolution;
|
|
33
34
|
}
|
|
35
|
+
const aliasedIsland = await resolveAliasedIsland(
|
|
36
|
+
specifier,
|
|
37
|
+
options?.resolveFrom ?? process.cwd()
|
|
38
|
+
);
|
|
39
|
+
if (aliasedIsland) {
|
|
40
|
+
return `/@fs/${aliasedIsland}`;
|
|
41
|
+
}
|
|
34
42
|
return specifier;
|
|
35
43
|
}
|
|
36
44
|
});
|
package/dist/middleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/middleware.ts"],"sourcesContent":["/// <reference path=\"./virtual.d.ts\" />\n\nimport { pathToFileURL } from 'node:url';\nimport { experimental_AstroContainer as AstroContainer } from 'astro/container';\nimport { ensureAstroPassthroughImageService } from './astroImageService.ts';\nimport { createAstroRenderHandler, type HandlerProps } from './astroRenderHandler.ts';\nimport type { Integration } from './integrations/index.ts';\nimport type { SanitizationOptions } from './lib/sanitization.ts';\nimport { resolveStoryModuleMock } from './module-mocks.ts';\nimport { addRenderers, resolveClientModules } from 'virtual:astro-container-renderers';\n\ntype ResolveRulesConfigModule = () => unknown | Promise<unknown>;\n\ntype HandlerFactoryOptions = {\n sanitization?: SanitizationOptions;\n rulesConfigFilePath?: string;\n resolveRulesConfigModule?: ResolveRulesConfigModule;\n loadModule?: (id: string) => Promise<{ default: unknown }>;\n invalidateModuleGraph?: () => void;\n resolveModule?: (specifier: string) => string | undefined;\n};\n\nexport type { HandlerProps };\n\nexport async function handlerFactory(\n _integrations: Integration[],\n options?: HandlerFactoryOptions\n) {\n ensureAstroPassthroughImageService();\n\n const container = await AstroContainer.create({\n resolve: async (specifier) => {\n const mockedModule = resolveStoryModuleMock(specifier);\n\n if (mockedModule) {\n return mockedModule;\n }\n\n const customResolution = options?.resolveModule?.(specifier);\n\n if (customResolution) {\n return customResolution;\n }\n\n if (specifier.startsWith('astro:scripts')) {\n return `/@id/${specifier}`;\n }\n\n const resolution = resolveClientModules(specifier);\n\n if (resolution) {\n return resolution;\n }\n\n return specifier;\n }\n });\n\n addRenderers(container);\n\n const loadModule =\n options?.loadModule ??\n ((id: string) => {\n const normalizedId = /^[a-zA-Z]:[/\\\\]/.test(id) ? pathToFileURL(id).href : id;\n\n return import(/* @vite-ignore */ normalizedId);\n });\n\n return createAstroRenderHandler({\n container,\n sanitization: options?.sanitization,\n rulesConfigFilePath: options?.rulesConfigFilePath,\n resolveRulesConfigModule: options?.resolveRulesConfigModule,\n loadModule,\n invalidateModuleGraph: options?.invalidateModuleGraph\n });\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/middleware.ts"],"sourcesContent":["/// <reference path=\"./virtual.d.ts\" />\n\nimport { pathToFileURL } from 'node:url';\nimport { experimental_AstroContainer as AstroContainer } from 'astro/container';\nimport { ensureAstroPassthroughImageService } from './astroImageService.ts';\nimport { createAstroRenderHandler, type HandlerProps } from './astroRenderHandler.ts';\nimport type { Integration } from './integrations/index.ts';\nimport type { SanitizationOptions } from './lib/sanitization.ts';\nimport { resolveAliasedIsland } from './lib/resolve-aliased-island.ts';\nimport { resolveStoryModuleMock } from './module-mocks.ts';\nimport { addRenderers, resolveClientModules } from 'virtual:astro-container-renderers';\n\ntype ResolveRulesConfigModule = () => unknown | Promise<unknown>;\n\ntype HandlerFactoryOptions = {\n sanitization?: SanitizationOptions;\n rulesConfigFilePath?: string;\n resolveRulesConfigModule?: ResolveRulesConfigModule;\n loadModule?: (id: string) => Promise<{ default: unknown }>;\n invalidateModuleGraph?: () => void;\n resolveModule?: (specifier: string) => string | undefined;\n resolveFrom?: string;\n};\n\nexport type { HandlerProps };\n\nexport async function handlerFactory(\n _integrations: Integration[],\n options?: HandlerFactoryOptions\n) {\n ensureAstroPassthroughImageService();\n\n const container = await AstroContainer.create({\n resolve: async (specifier) => {\n const mockedModule = resolveStoryModuleMock(specifier);\n\n if (mockedModule) {\n return mockedModule;\n }\n\n const customResolution = options?.resolveModule?.(specifier);\n\n if (customResolution) {\n return customResolution;\n }\n\n if (specifier.startsWith('astro:scripts')) {\n return `/@id/${specifier}`;\n }\n\n const resolution = resolveClientModules(specifier);\n\n if (resolution) {\n return resolution;\n }\n\n // Last resort: an island imported via a tsconfig path alias (e.g. `@/...`)\n // has its raw aliased specifier baked into the island's component-url.\n // Resolve it to an on-disk file and hand back a `/@fs/` URL the dev Vite\n // server can serve so the island still hydrates.\n const aliasedIsland = await resolveAliasedIsland(\n specifier,\n options?.resolveFrom ?? process.cwd()\n );\n\n if (aliasedIsland) {\n return `/@fs/${aliasedIsland}`;\n }\n\n return specifier;\n }\n });\n\n addRenderers(container);\n\n const loadModule =\n options?.loadModule ??\n ((id: string) => {\n const normalizedId = /^[a-zA-Z]:[/\\\\]/.test(id) ? pathToFileURL(id).href : id;\n\n return import(/* @vite-ignore */ normalizedId);\n });\n\n return createAstroRenderHandler({\n container,\n sanitization: options?.sanitization,\n rulesConfigFilePath: options?.rulesConfigFilePath,\n resolveRulesConfigModule: options?.resolveRulesConfigModule,\n loadModule,\n invalidateModuleGraph: options?.invalidateModuleGraph\n });\n}\n"],"mappings":";;;;;;;;;;;;AAEA,SAAS,qBAAqB;AAC9B,SAAS,+BAA+B,sBAAsB;AAO9D,SAAS,cAAc,4BAA4B;AAgBnD,eAAsB,eACpB,eACA,SACA;AACA,qCAAmC;AAEnC,QAAM,YAAY,MAAM,eAAe,OAAO;AAAA,IAC5C,SAAS,OAAO,cAAc;AAC5B,YAAM,eAAe,uBAAuB,SAAS;AAErD,UAAI,cAAc;AAChB,eAAO;AAAA,MACT;AAEA,YAAM,mBAAmB,SAAS,gBAAgB,SAAS;AAE3D,UAAI,kBAAkB;AACpB,eAAO;AAAA,MACT;AAEA,UAAI,UAAU,WAAW,eAAe,GAAG;AACzC,eAAO,QAAQ,SAAS;AAAA,MAC1B;AAEA,YAAM,aAAa,qBAAqB,SAAS;AAEjD,UAAI,YAAY;AACd,eAAO;AAAA,MACT;AAMA,YAAM,gBAAgB,MAAM;AAAA,QAC1B;AAAA,QACA,SAAS,eAAe,QAAQ,IAAI;AAAA,MACtC;AAEA,UAAI,eAAe;AACjB,eAAO,QAAQ,aAAa;AAAA,MAC9B;AAEA,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AAED,eAAa,SAAS;AAEtB,QAAM,aACJ,SAAS,eACR,CAAC,OAAe;AACf,UAAM,eAAe,kBAAkB,KAAK,EAAE,IAAI,cAAc,EAAE,EAAE,OAAO;AAE3E,WAAO;AAAA;AAAA,MAA0B;AAAA;AAAA,EACnC;AAEF,SAAO,yBAAyB;AAAA,IAC9B;AAAA,IACA,cAAc,SAAS;AAAA,IACvB,qBAAqB,SAAS;AAAA,IAC9B,0BAA0B,SAAS;AAAA,IACnC;AAAA,IACA,uBAAuB,SAAS;AAAA,EAClC,CAAC;AACH;","names":[]}
|
package/dist/node/index.d.ts
CHANGED
package/dist/preset.d.ts
CHANGED
package/dist/preset.js
CHANGED
|
@@ -4,21 +4,23 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
createAstroRenderHandler,
|
|
6
6
|
ensureAstroPassthroughImageService,
|
|
7
|
+
resolveAliasedIsland,
|
|
7
8
|
resolveSanitizationOptions,
|
|
8
9
|
serializeSanitizationOptions
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-A4DQ67HA.js";
|
|
10
11
|
import {
|
|
11
12
|
createVirtualModule,
|
|
13
|
+
loadUserAstroIntegrations,
|
|
12
14
|
resolveRulesConfigFilePath,
|
|
13
15
|
ssrLoadModuleWithFsFallback,
|
|
14
16
|
viteAstroContainerRenderersPlugin,
|
|
15
|
-
|
|
17
|
+
vitePluginAstroFonts,
|
|
16
18
|
vitePluginAstroIntegrationOptsFallback,
|
|
17
19
|
vitePluginAstroRoutesFallback,
|
|
18
20
|
vitePluginAstroVueFallback,
|
|
19
21
|
vitePluginStoryModuleMocks,
|
|
20
22
|
vitePluginStorybookAstroMiddleware
|
|
21
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-VZXGPM6P.js";
|
|
22
24
|
import {
|
|
23
25
|
importAstroConfig
|
|
24
26
|
} from "./chunk-PUTCAN6X.js";
|
|
@@ -139,7 +141,10 @@ async function emitBuildEntrypoints(options) {
|
|
|
139
141
|
});
|
|
140
142
|
}
|
|
141
143
|
async function emitHydratedComponentEntriesFromAstroFile(options) {
|
|
142
|
-
const hydratedComponentPaths = await collectHydratedComponentPaths(
|
|
144
|
+
const hydratedComponentPaths = await collectHydratedComponentPaths(
|
|
145
|
+
options.astroFilePath,
|
|
146
|
+
options.resolveFrom
|
|
147
|
+
);
|
|
143
148
|
for (const resolvedImportPath of hydratedComponentPaths) {
|
|
144
149
|
if (options.componentEntrypointRefs.has(resolvedImportPath)) {
|
|
145
150
|
continue;
|
|
@@ -152,11 +157,11 @@ async function emitHydratedComponentEntriesFromAstroFile(options) {
|
|
|
152
157
|
options.componentEntrypointRefs.set(resolvedImportPath, fileReferenceId);
|
|
153
158
|
}
|
|
154
159
|
}
|
|
155
|
-
async function collectHydratedComponentPaths(astroFilePath) {
|
|
156
|
-
const
|
|
160
|
+
async function collectHydratedComponentPaths(astroFilePath, resolveFrom) {
|
|
161
|
+
const allImportSpecifiers = await readAllImportSpecifiers(astroFilePath);
|
|
157
162
|
const hydratedComponentPaths = [];
|
|
158
|
-
for (const specifier of
|
|
159
|
-
const resolvedImportPath = await resolveLocalImportPath(astroFilePath, specifier);
|
|
163
|
+
for (const specifier of allImportSpecifiers) {
|
|
164
|
+
const resolvedImportPath = specifier.startsWith(".") ? await resolveLocalImportPath(astroFilePath, specifier) : await resolveAliasedIsland(specifier, resolveFrom);
|
|
160
165
|
if (!resolvedImportPath) {
|
|
161
166
|
continue;
|
|
162
167
|
}
|
|
@@ -332,18 +337,19 @@ async function copyLocalRuntimeDependencies(sourcePath, options, copiedFiles) {
|
|
|
332
337
|
await copyLocalRuntimeDependencies(resolvedDependency, options, copiedFiles);
|
|
333
338
|
}
|
|
334
339
|
}
|
|
335
|
-
|
|
340
|
+
var IMPORT_RE = /(?:import|export)\s+(?:[^'"`]*?\s+from\s+)?['"`]([^'"`]+)['"`]|import\(\s*['"`]([^'"`]+)['"`]\s*\)/g;
|
|
341
|
+
async function readAllImportSpecifiers(filePath) {
|
|
336
342
|
if (!/\.(astro|[cm]?[jt]sx?|vue|svelte)$/.test(filePath)) {
|
|
337
343
|
return [];
|
|
338
344
|
}
|
|
339
345
|
const source = await readFile(filePath, "utf-8");
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
);
|
|
343
|
-
return Array.from(matches, (match) => match[1] ?? match[2]).filter(
|
|
344
|
-
(specifier) => Boolean(specifier) && specifier.startsWith(".")
|
|
346
|
+
return Array.from(source.matchAll(IMPORT_RE), (match) => match[1] ?? match[2]).filter(
|
|
347
|
+
(specifier) => Boolean(specifier)
|
|
345
348
|
);
|
|
346
349
|
}
|
|
350
|
+
async function readLocalImportSpecifiers(filePath) {
|
|
351
|
+
return (await readAllImportSpecifiers(filePath)).filter((s) => s.startsWith("."));
|
|
352
|
+
}
|
|
347
353
|
async function resolveLocalImportPath(importerPath, specifier) {
|
|
348
354
|
const basePath = resolve(dirname(importerPath), specifier);
|
|
349
355
|
const candidates = [
|
|
@@ -413,7 +419,7 @@ async function createStorySsrViteServer(options) {
|
|
|
413
419
|
},
|
|
414
420
|
plugins: [
|
|
415
421
|
createProjectAstroResolutionPlugin(options.resolveFrom),
|
|
416
|
-
|
|
422
|
+
vitePluginAstroFonts({ fonts: options.fonts, root: options.resolveFrom }),
|
|
417
423
|
vitePluginAstroIntegrationOptsFallback(),
|
|
418
424
|
vitePluginAstroVueFallback(),
|
|
419
425
|
vitePluginAstroRoutesFallback(),
|
|
@@ -471,6 +477,10 @@ async function createProductionAstroContainer(options) {
|
|
|
471
477
|
if (resolution) {
|
|
472
478
|
return resolution;
|
|
473
479
|
}
|
|
480
|
+
const abs = await resolveAliasedIsland(specifier, options.resolveFrom);
|
|
481
|
+
if (abs) {
|
|
482
|
+
return options.resolveClientModule(abs) ?? specifier;
|
|
483
|
+
}
|
|
474
484
|
return specifier;
|
|
475
485
|
}
|
|
476
486
|
});
|
|
@@ -558,7 +568,8 @@ async function createProductionRenderRuntime(options) {
|
|
|
558
568
|
const viteServer = await createStorySsrViteServer({
|
|
559
569
|
integrations: options.integrations,
|
|
560
570
|
trackedSpecifiers: options.trackedSpecifiers,
|
|
561
|
-
resolveFrom: options.resolveFrom
|
|
571
|
+
resolveFrom: options.resolveFrom,
|
|
572
|
+
fonts: options.fonts
|
|
562
573
|
});
|
|
563
574
|
try {
|
|
564
575
|
const rulesConfigModule = await loadRulesConfigModule(
|
|
@@ -572,7 +583,8 @@ async function createProductionRenderRuntime(options) {
|
|
|
572
583
|
const astroContainer = await createProductionAstroContainer({
|
|
573
584
|
integrations: options.integrations,
|
|
574
585
|
resolveClientModule,
|
|
575
|
-
viteServer
|
|
586
|
+
viteServer,
|
|
587
|
+
resolveFrom: options.resolveFrom
|
|
576
588
|
});
|
|
577
589
|
const loadModule = async (moduleId) => {
|
|
578
590
|
return await viteServer.ssrLoadModule(
|
|
@@ -708,13 +720,17 @@ var ASTRO_PLUGINS_THAT_ARE_SUPPOSEDLY_NOT_NEEDED_IN_STORYBOOK = [
|
|
|
708
720
|
async function mergeWithAstroConfig(config, integrations = [], resolveFrom = process.cwd(), mode = "development", command = "serve") {
|
|
709
721
|
const { getViteConfig } = await importAstroConfig(resolveFrom);
|
|
710
722
|
const safeIntegrations = integrations ?? [];
|
|
723
|
+
const frameworkIntegrations = await Promise.all(
|
|
724
|
+
safeIntegrations.map((integration) => integration.loadIntegration(resolveFrom))
|
|
725
|
+
);
|
|
726
|
+
const userIntegrations = await loadUserAstroIntegrations(resolveFrom);
|
|
727
|
+
const frameworkNames = new Set(frameworkIntegrations.map((i) => i.name));
|
|
728
|
+
const extraIntegrations = userIntegrations.filter((i) => !frameworkNames.has(i.name));
|
|
711
729
|
const astroConfig = await getViteConfig(
|
|
712
730
|
{},
|
|
713
731
|
{
|
|
714
732
|
configFile: false,
|
|
715
|
-
integrations:
|
|
716
|
-
safeIntegrations.map((integration) => integration.loadIntegration(resolveFrom))
|
|
717
|
-
)
|
|
733
|
+
integrations: [...frameworkIntegrations, ...extraIntegrations]
|
|
718
734
|
}
|
|
719
735
|
)({
|
|
720
736
|
mode,
|
|
@@ -966,6 +982,7 @@ function vitePluginAstroBuildPrerender(options) {
|
|
|
966
982
|
staticCssMap,
|
|
967
983
|
trackedSpecifiers,
|
|
968
984
|
resolveFrom,
|
|
985
|
+
fonts: options.fonts,
|
|
969
986
|
bundle
|
|
970
987
|
});
|
|
971
988
|
await writePrerenderedStoriesFile(outDir, prerenderedStories);
|
|
@@ -983,7 +1000,8 @@ async function prerenderAstroStories(options) {
|
|
|
983
1000
|
storyRulesConfigFilePath: options.storyRulesConfigFilePath,
|
|
984
1001
|
staticModuleMap: options.staticModuleMap,
|
|
985
1002
|
trackedSpecifiers: options.trackedSpecifiers,
|
|
986
|
-
resolveFrom: options.resolveFrom
|
|
1003
|
+
resolveFrom: options.resolveFrom,
|
|
1004
|
+
fonts: options.fonts
|
|
987
1005
|
});
|
|
988
1006
|
const assetPathMap = buildAssetPathMap(options.bundle);
|
|
989
1007
|
try {
|