slidevjs/slidev

Type mismatch for UnoCSS setup configuration

openscript opened this issue · 0 comments

deepMerge setup configurations don't cover the case, where shortcuts aren't an array, even though the UnoCSS typing is allowing for such:

if (isObject(a[key]))
a[key] = deepMerge(a[key], b[key], rootPath ? `${rootPath}.${key}` : key)
else if (Array.isArray(a[key]))
a[key] = [...a[key], ...b[key]]
else
a[key] = b[key]

UserShortcuts:
https://github.com/unocss/unocss/blob/62abf05fb29156b13456d02b0ae6ddca5916c356/packages/core/src/types.ts#L201

With a configuration like

import { defineUnoSetup } from '@slidev/types'

export default defineUnoSetup(() => ({
  shortcuts: {
    'bg-main': 'bg-white text-[#181818] dark:bg-[#121212] dark:text-[#ddd]',
  },
}))

this leads to:

/workspaces/slidev-theme/node_modules/@slidev/cli/dist/chunk-KKGXM3XL.js:12
      a[key] = [...a[key], ...b[key]];
                               ^

TypeError: b[key] is not iterable
    at /workspaces/slidev-theme/node_modules/@slidev/cli/dist/chunk-KKGXM3XL.js:12:32
    at Array.forEach (<anonymous>)
    at deepMerge (/workspaces/slidev-theme/node_modules/@slidev/cli/dist/chunk-KKGXM3XL.js:8:18)
    at loadSetups (/workspaces/slidev-theme/node_modules/@slidev/cli/dist/chunk-KKGXM3XL.js:26:27)
    at async Object.createUnocssPlugin (/workspaces/slidev-theme/node_modules/@slidev/cli/dist/unocss-2DU67QXG.js:31:12)
    at async Promise.all (index 14)
    at async ViteSlidevPlugin (/workspaces/slidev-theme/node_modules/@slidev/cli/dist/chunk-SEZW5DVB.js:1694:11)
    at async createServer (/workspaces/slidev-theme/node_modules/@slidev/cli/dist/chunk-EFLHY5RE.js:2509:11)
    at async initServer (/workspaces/slidev-theme/node_modules/@slidev/cli/dist/cli.js:120:16)

Node.js v20.5.0

Reproduction

  1. Clone openscript-ch/slidev-theme@cfce5da
  2. Open in devcontainer (optional)
  3. Install dependencies with yarn install
  4. Run yarn dev

Workaround

Define the configuration as an array:

import { defineUnoSetup } from '@slidev/types'

export default defineUnoSetup(() => ({
  shortcuts: [
    {'bg-main': 'bg-white text-[#181818] dark:bg-[#121212] dark:text-[#ddd]'}
  ]
}))