@windicss/plugin-utils
Advanced tools
Comparing version 0.16.0-beta.16 to 0.16.0-beta.17
import * as windicss_types_interfaces from 'windicss/types/interfaces'; | ||
import { FullConfig, Extractor, ExtractorResultDetailed } from 'windicss/types/interfaces'; | ||
export { FullConfig as WindiCssOptions } from 'windicss/types/interfaces'; | ||
import * as _antfu_utils from '@antfu/utils'; | ||
export { Arrayable, partition, slash, toArray } from '@antfu/utils'; | ||
import * as magic_string from 'magic-string'; | ||
@@ -312,3 +314,3 @@ import { generateCompletions } from 'windicss/utils'; | ||
isExcluded: (id: string) => boolean; | ||
scan: () => Promise<void>; | ||
scan: _antfu_utils.SingletonPromiseReturn<void>; | ||
classesGenerated: Set<string>; | ||
@@ -345,10 +347,6 @@ classesPending: Set<string>; | ||
declare type Arrayable<T> = T | T[]; | ||
declare type NestedArrayable<T> = T | (T | T[])[]; | ||
declare function toArray<T>(v: Arrayable<T>): T[]; | ||
declare function flattenArray<T>(v: NestedArrayable<T>): T[]; | ||
declare function mergeArrays<T>(...args: (NestedArrayable<T> | undefined)[]): T[]; | ||
declare function slash(str: string): string; | ||
declare function kebabCase(str: string): string; | ||
declare function partition<T>(array: T[], filter: (i: T, idx: number, arr: T[]) => any): T[][]; | ||
declare function include<T>(set: Set<T>, v: T[] | Set<T>): void; | ||
@@ -368,2 +366,2 @@ declare function exclude<T>(set: Set<T>, v: T[] | Set<T>): void; | ||
export { Arrayable, CompletionsResult, DefaultExtractor, LayerMeta, LayerName, LoadConfigurationOptions, NestedArrayable, PugExtractor, ResolvedOptions, SupportedLayers, TagNames, Transformer, TransformerFunction, TransformerOptions, UserOptions, WindiPluginUtils, WindiPluginUtilsOptions, applyExtractors, buildAliasTransformer, createUtils, defaultAlias, defaultConfigureFiles, defineConfig, escapeRegExp, exclude, flattenArray, getDefaultExtractors, htmlTags, include, isResolvedOptions, kebabCase, loadConfiguration, mergeArrays, mergeWindicssConfig, partition, preflightTags, resolveOptions, slash, toArray, transformGroups }; | ||
export { CompletionsResult, DefaultExtractor, LayerMeta, LayerName, LoadConfigurationOptions, NestedArrayable, PugExtractor, ResolvedOptions, SupportedLayers, TagNames, Transformer, TransformerFunction, TransformerOptions, UserOptions, WindiPluginUtils, WindiPluginUtilsOptions, applyExtractors, buildAliasTransformer, createUtils, defaultAlias, defaultConfigureFiles, defineConfig, escapeRegExp, exclude, flattenArray, getDefaultExtractors, htmlTags, include, isResolvedOptions, kebabCase, loadConfiguration, mergeArrays, mergeWindicssConfig, preflightTags, resolveOptions, transformGroups }; |
@@ -44,2 +44,3 @@ var __create = Object.create; | ||
__export(exports, { | ||
Arrayable: () => import_utils2.Arrayable, | ||
DefaultExtractor: () => DefaultExtractor, | ||
@@ -65,7 +66,7 @@ PugExtractor: () => PugExtractor, | ||
mergeWindicssConfig: () => mergeWindicssConfig, | ||
partition: () => partition, | ||
partition: () => import_utils2.partition, | ||
preflightTags: () => preflightTags, | ||
resolveOptions: () => resolveOptions, | ||
slash: () => slash, | ||
toArray: () => toArray, | ||
slash: () => import_utils2.slash, | ||
toArray: () => import_utils2.toArray, | ||
transformGroups: () => transformGroups | ||
@@ -231,3 +232,4 @@ }); | ||
var import_parser = __toModule(require("windicss/utils/parser")); | ||
var import_utils3 = __toModule(require("windicss/utils")); | ||
var import_utils5 = __toModule(require("windicss/utils")); | ||
var import_utils6 = __toModule(require("@antfu/utils")); | ||
var import_fast_glob = __toModule(require("fast-glob")); | ||
@@ -245,9 +247,6 @@ var import_debug2 = __toModule(require("debug")); | ||
// src/utils.ts | ||
function toArray(v) { | ||
if (Array.isArray(v)) | ||
return v; | ||
return [v]; | ||
} | ||
var import_utils = __toModule(require("@antfu/utils")); | ||
var import_utils2 = __toModule(require("@antfu/utils")); | ||
function flattenArray(v) { | ||
return toArray(v).flat(); | ||
return (0, import_utils.toArray)(v).flat(); | ||
} | ||
@@ -257,14 +256,5 @@ function mergeArrays(...args) { | ||
} | ||
function slash(str) { | ||
return str.replace(/\\/g, "/"); | ||
} | ||
function kebabCase(str) { | ||
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(); | ||
} | ||
function partition(array, filter) { | ||
const pass = []; | ||
const fail = []; | ||
array.forEach((e, idx, arr) => (filter(e, idx, arr) ? pass : fail).push(e)); | ||
return [pass, fail]; | ||
} | ||
function include(set, v) { | ||
@@ -399,4 +389,4 @@ for (const i of v) | ||
function buildGlobs(dirs, fileExtensions) { | ||
dirs = toArray(dirs); | ||
const exts = toArray(fileExtensions); | ||
dirs = (0, import_utils2.toArray)(dirs); | ||
const exts = (0, import_utils2.toArray)(fileExtensions); | ||
const globs = exts.length ? dirs.map((i) => import_path2.posix.join(i, exts.length > 1 ? `**/*.{${exts.join(",")}}` : `**/*.${exts[0]}`)) : []; | ||
@@ -450,4 +440,4 @@ globs.push("index.html"); | ||
}, typeof scan === "boolean" ? {} : scan); | ||
scanOptions.exclude = mergeArrays((_b = config.extract) == null ? void 0 : _b.exclude, scanOptions.exclude, ((_c = config.extract) == null ? void 0 : _c.exclude) ? [] : ["node_modules", ".git"]).map((i) => slash((0, import_path2.resolve)(root, i))); | ||
scanOptions.include = mergeArrays((_d = config.extract) == null ? void 0 : _d.include, scanOptions.include, ((_e = config.extract) == null ? void 0 : _e.include) ? [] : buildGlobs(scanOptions.dirs, scanOptions.fileExtensions)).map((i) => slash((0, import_path2.resolve)(root, i))); | ||
scanOptions.exclude = mergeArrays((_b = config.extract) == null ? void 0 : _b.exclude, scanOptions.exclude, ((_c = config.extract) == null ? void 0 : _c.exclude) ? [] : ["node_modules", ".git"]).map((i) => (0, import_utils2.slash)((0, import_path2.resolve)(root, i))); | ||
scanOptions.include = mergeArrays((_d = config.extract) == null ? void 0 : _d.include, scanOptions.include, ((_e = config.extract) == null ? void 0 : _e.include) ? [] : buildGlobs(scanOptions.dirs, scanOptions.fileExtensions)).map((i) => (0, import_utils2.slash)((0, import_path2.resolve)(root, i))); | ||
scanOptions.extractors = mergeArrays(getDefaultExtractors(), (_f = config.extract) == null ? void 0 : _f.extractors); | ||
@@ -622,3 +612,3 @@ const safelist = new Set(mergeArrays(config.safelist, options.safelist).flatMap((i) => i.split(" "))); | ||
if (!completions) | ||
completions = (0, import_utils3.generateCompletions)(processor); | ||
completions = (0, import_utils5.generateCompletions)(processor); | ||
return completions; | ||
@@ -641,27 +631,21 @@ } | ||
let scanned = false; | ||
let _searching; | ||
async function scan() { | ||
const scan = (0, import_utils6.createSingletonPromise)(async () => { | ||
await ensureInit(); | ||
if (!_searching) { | ||
_searching = (async () => { | ||
debug.scan("started"); | ||
files.push(...await getFiles()); | ||
const contents = await Promise.all(files.filter((id) => isDetectTarget(id)).map(async (id) => [await import_fs2.promises.readFile(id, "utf-8"), id])); | ||
await Promise.all(contents.map(async ([content, id]) => { | ||
if (isCssTransformTarget(id)) | ||
return transformCSS(content, id); | ||
else | ||
return extractFile(content, id, true); | ||
})); | ||
scanned = true; | ||
debug.scan("finished"); | ||
})(); | ||
} | ||
return _searching; | ||
} | ||
debug.scan("started"); | ||
files.push(...await getFiles()); | ||
const contents = await Promise.all(files.filter((id) => isDetectTarget(id)).map(async (id) => [await import_fs2.promises.readFile(id, "utf-8"), id])); | ||
await Promise.all(contents.map(async ([content, id]) => { | ||
if (isCssTransformTarget(id)) | ||
return transformCSS(content, id); | ||
else | ||
return extractFile(content, id, true); | ||
})); | ||
scanned = true; | ||
debug.scan("finished"); | ||
}); | ||
function isExcluded(id) { | ||
return import_micromatch.default.contains(slash(id), options.scanOptions.exclude, {dot: true}); | ||
return import_micromatch.default.contains((0, import_utils2.slash)(id), options.scanOptions.exclude, {dot: true}); | ||
} | ||
function isIncluded(id) { | ||
return import_micromatch.default.isMatch(slash(id), options.scanOptions.include); | ||
return import_micromatch.default.isMatch((0, import_utils2.slash)(id), options.scanOptions.include); | ||
} | ||
@@ -671,3 +655,3 @@ function isDetectTarget(id) { | ||
return true; | ||
id = slash(id); | ||
id = (0, import_utils2.slash)(id); | ||
return isIncluded(id) && !isExcluded(id); | ||
@@ -755,3 +739,3 @@ } | ||
const style = new import_parser.CSSParser(css, processor).parse(); | ||
const [layerBlocks, blocks] = partition(style.children, (i) => i.meta.group === "layer-block" && SupportedLayers.includes(i.meta.type)); | ||
const [layerBlocks, blocks] = (0, import_utils2.partition)(style.children, (i) => i.meta.group === "layer-block" && SupportedLayers.includes(i.meta.type)); | ||
if (layerBlocks.length) { | ||
@@ -980,2 +964,3 @@ updateLayers(layerBlocks, id); | ||
0 && (module.exports = { | ||
Arrayable, | ||
DefaultExtractor, | ||
@@ -982,0 +967,0 @@ PugExtractor, |
{ | ||
"name": "@windicss/plugin-utils", | ||
"version": "0.16.0-beta.16", | ||
"version": "0.16.0-beta.17", | ||
"description": "Common utils for building integrations of Windi CSS", | ||
@@ -25,2 +25,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@antfu/utils": "^0.1.5", | ||
"debug": "^4.3.2", | ||
@@ -27,0 +28,0 @@ "fast-glob": "^3.2.5", |
Sorry, the diff of this file is not supported yet
74351
7
2232
+ Added@antfu/utils@^0.1.5
+ Added@antfu/utils@0.1.7(transitive)