From 0f2c5157aa30df4cb22325a5faf73c9392c445de Mon Sep 17 00:00:00 2001 From: Hugo ATTAL <4563971+hugoattal@users.noreply.github.com> Date: Tue, 10 Dec 2024 02:24:54 +0100 Subject: [PATCH] Update file path handling --- packages/histoire-shared/src/codegen/serialize-js.ts | 2 +- .../src/node/builtin-plugins/vanilla-support/collect.ts | 4 ---- packages/histoire/src/node/colors.ts | 4 ++-- packages/histoire/src/node/util/vendors.ts | 9 +++++++-- packages/histoire/src/node/vite.ts | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/histoire-shared/src/codegen/serialize-js.ts b/packages/histoire-shared/src/codegen/serialize-js.ts index c2b7c080..f3329824 100644 --- a/packages/histoire-shared/src/codegen/serialize-js.ts +++ b/packages/histoire-shared/src/codegen/serialize-js.ts @@ -1,4 +1,4 @@ -const KEY_ESCAPE_REG = /[\s-.:|#@$£*%]/ +const KEY_ESCAPE_REG = /[\s\-.:|#@$£*%]/ const MAX_SINGLE_LINE_ARRAY_LENGTH = 3 interface Line { diff --git a/packages/histoire/src/node/builtin-plugins/vanilla-support/collect.ts b/packages/histoire/src/node/builtin-plugins/vanilla-support/collect.ts index 5b401c9c..532dbfd9 100644 --- a/packages/histoire/src/node/builtin-plugins/vanilla-support/collect.ts +++ b/packages/histoire/src/node/builtin-plugins/vanilla-support/collect.ts @@ -2,10 +2,6 @@ import type { ServerRunPayload, ServerStory, ServerVariant } from '@histoire/sha import type { StoryOptions, VariantOptions } from './types' export async function run({ file, storyData }: ServerRunPayload) { - if (file.moduleId.toLowerCase().includes('tailwind')) { - return - } - const { default: Comp } = await import(/* @vite-ignore */ file.moduleId) const options = Comp as StoryOptions diff --git a/packages/histoire/src/node/colors.ts b/packages/histoire/src/node/colors.ts index 2084b9e8..00524e47 100644 --- a/packages/histoire/src/node/colors.ts +++ b/packages/histoire/src/node/colors.ts @@ -281,7 +281,7 @@ export const defaultColors = { } const HEX = /^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i -const SHORT_HEX = /^#([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i +const SHORT_HEX = /^#([a-f\d]){3,4}$/i const VALUE = `(?:\\d+|\\d*\\.\\d+)%?` const SEP = `(?:\\s*,\\s*|\\s+)` const ALPHA_SEP = `\\s*[,/]\\s*` @@ -289,7 +289,7 @@ const RGB = new RegExp( `^rgba?\\(\\s*(${VALUE})${SEP}(${VALUE})${SEP}(${VALUE})(?:${ALPHA_SEP}(${VALUE}))?\\s*\\)$`, ) const HSL = new RegExp( - `^hsla?\\(\\s*((?:${VALUE})(?:deg|rad|grad|turn)?)${SEP}(${VALUE})${SEP}(${VALUE})(?:${ALPHA_SEP}(${VALUE}))?\\s*\\)$`, + `^hsla?\\(\\s*(${VALUE}(?:deg|rad|grad|turn)?)${SEP}(${VALUE})${SEP}(${VALUE})(?:${ALPHA_SEP}(${VALUE}))?\\s*\\)$`, ) export function parseColor(value) { diff --git a/packages/histoire/src/node/util/vendors.ts b/packages/histoire/src/node/util/vendors.ts index fbb3bf0a..a4c04406 100644 --- a/packages/histoire/src/node/util/vendors.ts +++ b/packages/histoire/src/node/util/vendors.ts @@ -1,5 +1,5 @@ import path from 'node:path' -import { fileURLToPath } from 'node:url' +import { fileURLToPath, pathToFileURL } from 'node:url' // Resolve an absolute path to e.g. node_modules/.pnpm/histoire@0.11.7_vite@3.2.4/node_modules/histoire/dist/node/vendors/controls.js // https://github.com/histoire-dev/histoire/issues/282 @@ -18,5 +18,10 @@ export function getInjectedImport(request: string) { id = alias[id] } - return JSON.stringify(id) + if (path.isAbsolute(id)) { + return JSON.stringify(pathToFileURL(id).href) + } + else { + return JSON.stringify(id) + } } diff --git a/packages/histoire/src/node/vite.ts b/packages/histoire/src/node/vite.ts index 48624d91..2f75b6a8 100644 --- a/packages/histoire/src/node/vite.ts +++ b/packages/histoire/src/node/vite.ts @@ -91,7 +91,7 @@ export async function getViteConfigWithPlugins(isServer: boolean, ctx: Context): 'vue', ], alias: { - 'histoire-style': `file://${join(APP_PATH, process.env.HISTOIRE_DEV ? 'app/style/main.pcss' : 'style.css')}`, + 'histoire-style': join(APP_PATH, process.env.HISTOIRE_DEV ? 'app/style/main.pcss' : 'style.css'), }, ...(isServer ? {