From d15ddcc9258f38e265a225a3e841f07a827633b2 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 29 Jul 2022 22:02:46 +0800 Subject: [PATCH] fix: use inline `createFilter` --- packages/core/src/utils/basic.ts | 2 +- packages/transformer-attributify-jsx/package.json | 1 - packages/transformer-attributify-jsx/src/index.ts | 15 ++++++++++++++- pnpm-lock.yaml | 2 -- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/core/src/utils/basic.ts b/packages/core/src/utils/basic.ts index 211564bc1e..0cebf2d547 100644 --- a/packages/core/src/utils/basic.ts +++ b/packages/core/src/utils/basic.ts @@ -1,4 +1,4 @@ -export function toArray(value: T | T[] = []): T[] { +export function toArray(value: T | readonly T[] = []): T[] { return Array.isArray(value) ? value : [value] } diff --git a/packages/transformer-attributify-jsx/package.json b/packages/transformer-attributify-jsx/package.json index 04ee0212c2..c90cb3ab86 100644 --- a/packages/transformer-attributify-jsx/package.json +++ b/packages/transformer-attributify-jsx/package.json @@ -39,7 +39,6 @@ "@unocss/core": "workspace:*" }, "devDependencies": { - "@rollup/pluginutils": "^4.2.1", "magic-string": "^0.26.2" } } diff --git a/packages/transformer-attributify-jsx/src/index.ts b/packages/transformer-attributify-jsx/src/index.ts index 525fe821e7..fe6b3f50e4 100644 --- a/packages/transformer-attributify-jsx/src/index.ts +++ b/packages/transformer-attributify-jsx/src/index.ts @@ -1,8 +1,21 @@ import type { SourceCodeTransformer } from '@unocss/core' -import { createFilter } from '@rollup/pluginutils' +import { toArray } from '@unocss/core' export type FilterPattern = ReadonlyArray | string | RegExp | null +function createFilter( + include: FilterPattern, + exclude: FilterPattern, +): (id: string) => boolean { + const includePattern = toArray(include || []) + const excludePattern = toArray(exclude || []) + return (id: string) => { + if (excludePattern.some(p => id.match(p))) + return false + return includePattern.some(p => id.match(p)) + } +} + export interface TransformerAttributifyJsxOptions { /** * the list of attributes to ignore diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c99e1db2d7..44697d807b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -460,13 +460,11 @@ importers: packages/transformer-attributify-jsx: specifiers: - '@rollup/pluginutils': ^4.2.1 '@unocss/core': workspace:* magic-string: ^0.26.2 dependencies: '@unocss/core': link:../core devDependencies: - '@rollup/pluginutils': 4.2.1 magic-string: 0.26.2 packages/transformer-compile-class: