@windicss/plugin-utils
Advanced tools
Comparing version 0.3.14 to 0.4.0
import { Config } from 'windicss/types/interfaces'; | ||
export { Config as WindiCssOptions } from 'windicss/types/interfaces'; | ||
declare const configureFiles: string[]; | ||
declare const defaultAlias: Record<string, TagNames>; | ||
@@ -8,3 +10,3 @@ declare const preflightTags: string[]; | ||
interface WindiPluginUtilsOptions { | ||
interface UserOptions { | ||
/** | ||
@@ -14,3 +16,3 @@ * Options for windicss/tailwindcss. | ||
* | ||
* @default 'tailwind.config.js' | ||
* @default auto searching for `windi.config.ts` / `tailwind.config.js` | ||
*/ | ||
@@ -108,2 +110,4 @@ config?: Config | string; | ||
sortUtilities?: boolean; | ||
} | ||
interface WindiPluginUtilsOptions { | ||
/** | ||
@@ -115,56 +119,49 @@ * Name for debug | ||
*/ | ||
_pluginName?: string; | ||
name?: string; | ||
/** | ||
* CWD | ||
* CWD | ||
* | ||
* @default process.cwd | ||
* @internal | ||
*/ | ||
root?: string; | ||
/** | ||
* Use esbuild-register to load configs in TypeScript | ||
* | ||
* @default process.cwd | ||
* @internal | ||
* @default true | ||
*/ | ||
_projectRoot?: string; | ||
enabledTypeScriptConfig?: boolean; | ||
} | ||
declare type UserOptions = Omit<WindiPluginUtilsOptions, '_pluginName' | '_projectRoot'>; | ||
interface ResolvedOptions { | ||
config: string | Config | undefined; | ||
scan: boolean; | ||
scanOptions: { | ||
fileExtensions: string[]; | ||
dirs: string[]; | ||
exclude: string[]; | ||
include: string[]; | ||
runOnStartup: boolean; | ||
}; | ||
preflight: boolean; | ||
preflightOptions: { | ||
includeBase: boolean; | ||
includeGlobal: boolean; | ||
includePlugin: boolean; | ||
enableAll: boolean; | ||
safelist: string[]; | ||
alias: Record<string, TagNames>; | ||
}; | ||
transformCSS: boolean; | ||
transformGroups: boolean; | ||
sortUtilities: boolean; | ||
safelist: Set<string>; | ||
} | ||
declare function resolveOptions(options?: UserOptions | ResolvedOptions): ResolvedOptions; | ||
declare function defineConfig(config: Config): Config; | ||
declare function transfromGroups(str: string): string; | ||
declare type WindiPluginUtils = ReturnType<typeof createUtils>; | ||
declare function createUtils(_options?: WindiPluginUtilsOptions): { | ||
options: { | ||
_projectRoot: string; | ||
_pluginName: string; | ||
config: string | Config; | ||
scan: boolean; | ||
scanOptions: { | ||
fileExtensions: string[]; | ||
dirs: string[]; | ||
exclude: string[]; | ||
include: string[]; | ||
runOnStartup: boolean; | ||
} & { | ||
runOnStartup?: boolean | undefined; | ||
dirs?: string[] | undefined; | ||
fileExtensions?: string[] | undefined; | ||
exclude?: string[] | undefined; | ||
include?: string[] | undefined; | ||
}; | ||
preflight: boolean; | ||
preflightOptions: { | ||
includeBase: boolean; | ||
includeGlobal: boolean; | ||
includePlugin: boolean; | ||
enableAll: boolean; | ||
alias: {}; | ||
} & { | ||
enableAll?: boolean | undefined; | ||
safelist?: string | string[] | undefined; | ||
alias?: Record<string, "object" | "html" | "body" | "div" | "a" | "abbr" | "address" | "area" | "article" | "aside" | "audio" | "base" | "basefont" | "bdo" | "blink" | "blockquote" | "br" | "button" | "canvas" | "caption" | "center" | "col" | "colgroup" | "command" | "comment" | "datalist" | "dd" | "del" | "details" | "dir" | "dl" | "dt" | "embed" | "fieldset" | "figure" | "b" | "big" | "i" | "small" | "tt" | "font" | "footer" | "form" | "frame" | "frameset" | "head" | "header" | "hgroup" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "hr" | "isindex" | "iframe" | "ilayer" | "img" | "input" | "ins" | "keygen" | "label" | "layer" | "legend" | "li" | "link" | "map" | "mark" | "marquee" | "menu" | "meta" | "meter" | "multicol" | "nav" | "nobr" | "noembed" | "noframes" | "noscript" | "ol" | "optgroup" | "option" | "output" | "p" | "param" | "cite" | "code" | "dfn" | "em" | "kbd" | "samp" | "strong" | "var" | "plaintext" | "pre" | "progress" | "q" | "ruby" | "script" | "section" | "select" | "spacer" | "span" | "s" | "strike" | "style" | "sub" | "sup" | "svg" | "table" | "tbody" | "td" | "textarea" | "tfoot" | "th" | "thead" | "time" | "title" | "tr" | "u" | "ul" | "video" | "wbr" | "xmp"> | undefined; | ||
includeBase?: boolean | undefined; | ||
includeGlobal?: boolean | undefined; | ||
includePlugin?: boolean | undefined; | ||
}; | ||
transformCSS: boolean; | ||
transformGroups: boolean; | ||
sortUtilities: boolean; | ||
safelist: Set<string>; | ||
}; | ||
declare function createUtils(userOptions?: UserOptions | ResolvedOptions, utilsOptions?: WindiPluginUtilsOptions): { | ||
options: ResolvedOptions; | ||
init: () => void; | ||
@@ -191,3 +188,4 @@ extractFile: (code: string, applyTransform?: boolean) => boolean; | ||
}; | ||
declare type WindiPluginUtils = ReturnType<typeof createUtils>; | ||
export { TagNames, UserOptions, WindiPluginUtils, WindiPluginUtilsOptions, createUtils, defaultAlias, htmlTags, preflightTags }; | ||
export { ResolvedOptions, TagNames, UserOptions, WindiPluginUtils, WindiPluginUtilsOptions, configureFiles, createUtils, defaultAlias, defineConfig, htmlTags, preflightTags, resolveOptions }; |
@@ -747,18 +747,9 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __create = Object.create; | ||
// src/index.ts | ||
var import_debug = __toModule(require_src()); | ||
var _fs = require('fs'); | ||
var _path = require('path'); | ||
var _windicss = require('windicss'); var _windicss2 = _interopRequireDefault(_windicss); | ||
var _style = require('windicss/utils/style'); | ||
var _parser = require('windicss/utils/parser'); | ||
var _fastglob = require('fast-glob'); var _fastglob2 = _interopRequireDefault(_fastglob); | ||
var _micromatch = require('micromatch'); var _micromatch2 = _interopRequireDefault(_micromatch); | ||
// src/constants.ts | ||
var regexQuotedString = /(["'`])((?:\\\1|(?:(?!\1)|\n).)*?)\1/mg; | ||
var regexClassCheck = /^[a-z.-]+[\w:/\\.$-]*\w$/; | ||
var regexHtmlTag = /<(\w[\w-]*)/g; | ||
var regexClassSplitter = /[\s'"`{}]/g; | ||
var regexClassGroup = /(\w[\w:_/-]*?):\(([\w\s/-]*?)\)/gm; | ||
var configureFiles = [ | ||
"windi.config.ts", | ||
"windi.config.js", | ||
"tailwind.config.ts", | ||
"tailwind.config.js" | ||
]; | ||
var defaultAlias = { | ||
@@ -897,2 +888,24 @@ "router-link": "a" | ||
// src/defineConfig.ts | ||
function defineConfig(config) { | ||
return config; | ||
} | ||
// src/createUtils.ts | ||
var import_debug = __toModule(require_src()); | ||
var _fs = require('fs'); | ||
var _path = require('path'); | ||
var _windicss = require('windicss'); var _windicss2 = _interopRequireDefault(_windicss); | ||
var _style = require('windicss/utils/style'); | ||
var _parser = require('windicss/utils/parser'); | ||
var _fastglob = require('fast-glob'); var _fastglob2 = _interopRequireDefault(_fastglob); | ||
var _micromatch = require('micromatch'); var _micromatch2 = _interopRequireDefault(_micromatch); | ||
// src/regexes.ts | ||
var regexQuotedString = /(["'`])((?:\\\1|(?:(?!\1)|\n).)*?)\1/mg; | ||
var regexClassCheck = /^[a-z.-]+[\w:/\\.$-]*\w$/; | ||
var regexHtmlTag = /<(\w[\w-]*)/g; | ||
var regexClassSplitter = /[\s'"`{}]/g; | ||
var regexClassGroup = /(\w[\w:_/-]*?):\(([\w\s/-]*?)\)/gm; | ||
// src/utils.ts | ||
@@ -923,5 +936,9 @@ function toArray(v) { | ||
// src/options.ts | ||
function resolveOptions(options) { | ||
function isResolvedOptions(options) { | ||
return options.__windi_resolved; | ||
} | ||
function resolveOptions(options = {}) { | ||
if (isResolvedOptions(options)) | ||
return options; | ||
const { | ||
config = "tailwind.config.js", | ||
scan = true, | ||
@@ -931,5 +948,3 @@ preflight = true, | ||
transformGroups = true, | ||
sortUtilities = true, | ||
_projectRoot = process.cwd(), | ||
_pluginName = "windi-plugin-utils" | ||
sortUtilities = true | ||
} = options; | ||
@@ -941,2 +956,3 @@ const preflightOptions = Object.assign({ | ||
enableAll: false, | ||
safelist: [], | ||
alias: {} | ||
@@ -954,5 +970,2 @@ }, typeof preflight === "boolean" ? {} : preflight); | ||
return __assign(__assign({}, options), { | ||
_projectRoot, | ||
_pluginName, | ||
config, | ||
scan: Boolean(scan), | ||
@@ -965,9 +978,10 @@ scanOptions, | ||
sortUtilities, | ||
safelist | ||
safelist, | ||
__windi_resolved: true | ||
}); | ||
} | ||
// src/index.ts | ||
function createUtils(_options = {}) { | ||
const options = resolveOptions(_options); | ||
// src/createUtils.ts | ||
function createUtils(userOptions = {}, utilsOptions = {}) { | ||
const options = resolveOptions(userOptions); | ||
const { | ||
@@ -982,6 +996,9 @@ config, | ||
sortUtilities, | ||
safelist, | ||
_pluginName: name, | ||
_projectRoot: root | ||
safelist | ||
} = options; | ||
const { | ||
name = "windicss-plugin-utils", | ||
root = process.cwd(), | ||
enabledTypeScriptConfig = true | ||
} = utilsOptions; | ||
const debug = { | ||
@@ -1009,10 +1026,29 @@ config: import_debug.default(`${name}:config`), | ||
let resolved = {}; | ||
if (typeof config === "string") { | ||
const path = _path.resolve.call(void 0, root, config); | ||
if (!_fs.existsSync.call(void 0, path)) { | ||
console.warn(`[${name}] config file "${config}" not found, ignored`); | ||
if (typeof config === "string" || !config) { | ||
let path = ""; | ||
if (!config) { | ||
for (const name2 of configureFiles) { | ||
const tryPath = _path.resolve.call(void 0, root, name2); | ||
if (_fs.existsSync.call(void 0, tryPath)) { | ||
path = tryPath; | ||
break; | ||
} | ||
} | ||
} else { | ||
path = _path.resolve.call(void 0, root, config); | ||
if (!_fs.existsSync.call(void 0, path)) { | ||
console.warn(`[${name}] config file "${config}" not found, ignored`); | ||
path = ""; | ||
} | ||
} | ||
if (path) { | ||
try { | ||
debug.config("loading from ", path); | ||
if (enabledTypeScriptConfig && path.endsWith(".ts")) { | ||
require("esbuild-register"); | ||
} | ||
delete require.cache[require.resolve(path)]; | ||
resolved = require(path); | ||
if (resolved.default) | ||
resolved = resolved.default; | ||
configFilePath = path; | ||
@@ -1022,5 +1058,5 @@ configSafelist.clear(); | ||
} catch (e) { | ||
console.error(`[${name}] failed to load config "${config}"`); | ||
console.error(`[${name}] failed to load config "${path}"`); | ||
console.error(`[${name}] ${e.toString()}`); | ||
process.exit(1); | ||
setTimeout(() => process.exit(1)); | ||
} | ||
@@ -1160,3 +1196,3 @@ } | ||
_cssCache = void 0; | ||
const preflightSafelist = toArray((preflightOptions == null ? void 0 : preflightOptions.safelist) || []).flatMap((i) => i.split(" ")); | ||
const preflightSafelist = toArray(preflightOptions.safelist).flatMap((i) => i.split(" ")); | ||
include(classesPending, configSafelist); | ||
@@ -1213,2 +1249,5 @@ include(classesPending, safelist); | ||
exports.createUtils = createUtils; exports.defaultAlias = defaultAlias; exports.htmlTags = htmlTags; exports.preflightTags = preflightTags; | ||
exports.configureFiles = configureFiles; exports.createUtils = createUtils; exports.defaultAlias = defaultAlias; exports.defineConfig = defineConfig; exports.htmlTags = htmlTags; exports.preflightTags = preflightTags; exports.resolveOptions = resolveOptions; |
{ | ||
"name": "@windicss/plugin-utils", | ||
"description": "Common utils for building integrations of Windi CSS", | ||
"version": "0.3.14", | ||
"version": "0.4.0", | ||
"main": "dist/index.js", | ||
@@ -30,4 +30,6 @@ "module": "dist/index.mjs", | ||
"dependencies": { | ||
"esbuild": "^0.8.49", | ||
"fast-glob": "^3.2.5", | ||
"micromatch": "^4.0.2", | ||
"esbuild-register": "^2.0.0", | ||
"windicss": "^2.1.14" | ||
@@ -34,0 +36,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75272
2633
5
+ Addedesbuild@^0.8.49
+ Addedesbuild-register@^2.0.0
+ Addedesbuild@0.12.290.8.57(transitive)
+ Addedesbuild-register@2.6.0(transitive)
+ Addedjsonc-parser@3.3.1(transitive)