Skip to content

Commit

Permalink
Update file path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoattal committed Dec 10, 2024
1 parent dde4f7a commit 0f2c515
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/histoire-shared/src/codegen/serialize-js.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const KEY_ESCAPE_REG = /[\s-.:|#@$£*%]/
const KEY_ESCAPE_REG = /[\s\-.:|#@$£*%]/
const MAX_SINGLE_LINE_ARRAY_LENGTH = 3

interface Line {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/histoire/src/node/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ 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*`
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) {
Expand Down
9 changes: 7 additions & 2 deletions packages/histoire/src/node/util/vendors.ts
Original file line number Diff line number Diff line change
@@ -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/[email protected][email protected]/node_modules/histoire/dist/node/vendors/controls.js
// https://github.com/histoire-dev/histoire/issues/282
Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion packages/histoire/src/node/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
? {
Expand Down

0 comments on commit 0f2c515

Please sign in to comment.