Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@windicss/plugin-utils

Package Overview
Dependencies
Maintainers
2
Versions
166
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@windicss/plugin-utils - npm Package Compare versions

Comparing version 0.10.4 to 0.11.0

19

dist/index.d.ts

@@ -1,2 +0,3 @@

import { FullConfig } from 'windicss/types/interfaces';
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';

@@ -21,4 +22,2 @@ import WindiCssProcessor from 'windicss';

declare const PugTransformer: Transformer<TransformerOptions>;
interface UserOptions {

@@ -223,2 +222,3 @@ /**

transformers: TransformerFunction[];
extractors: Extractor[];
};

@@ -266,3 +266,4 @@ preflightOptions: {

init: () => Promise<WindiCssProcessor>;
extractFile: (code: string, id?: string | undefined, applyGroupTransform?: boolean) => boolean;
extractFile: (code: string, id?: string | undefined, applyGroupTransform?: boolean) => Promise<boolean>;
applyExtractors: (code: string, id?: string | undefined) => Promise<windicss_types_interfaces.ExtractorResultDetailed>;
generateCSS: () => Promise<string>;

@@ -301,4 +302,10 @@ getFiles: () => Promise<string[]>;

declare function DefaultExtractor(code: string, id?: string): ExtractorResultDetailed;
declare function getDefaultExtractors(): Extractor[];
declare function applyExtractors(code: string, id?: string, extractors?: Extractor[], defaultExtract?: typeof DefaultExtractor): Promise<windicss_types_interfaces.ExtractorResultDetailed>;
declare function PugExtractor(code: string, id?: string): ExtractorResultDetailed;
declare function isResolvedOptions(options: UserOptions | ResolvedOptions): options is ResolvedOptions;
declare function getDefaultTransformers(): TransformerFunction[];
declare function resolveOptions(options?: UserOptions | ResolvedOptions, utilsOptions?: WindiPluginUtilsOptions, loadConfigFile?: boolean): Promise<ResolvedOptions>;

@@ -311,2 +318,2 @@ declare function loadConfiguration(options: UserOptions, utilsOptions: WindiPluginUtilsOptions): Promise<{

export { Arrayable, CompletionsResult, NestedArrayable, PugTransformer, ResolvedOptions, TagNames, Transformer, TransformerFunction, TransformerOptions, UserOptions, WindiPluginUtils, WindiPluginUtilsOptions, configureFiles, createUtils, defaultAlias, defineConfig, exclude, flattenArray, getDefaultTransformers, htmlTags, include, isResolvedOptions, kebabCase, loadConfiguration, mergeArrays, preflightTags, resolveOptions, slash, toArray, transformGroups, transformGroupsWithSourcemap };
export { Arrayable, CompletionsResult, DefaultExtractor, NestedArrayable, PugExtractor, ResolvedOptions, TagNames, Transformer, TransformerFunction, TransformerOptions, UserOptions, WindiPluginUtils, WindiPluginUtilsOptions, applyExtractors, configureFiles, createUtils, defaultAlias, defineConfig, exclude, flattenArray, getDefaultExtractors, htmlTags, include, isResolvedOptions, kebabCase, loadConfiguration, mergeArrays, preflightTags, resolveOptions, slash, toArray, transformGroups, transformGroupsWithSourcemap };

@@ -173,2 +173,10 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __defProp = Object.defineProperty;

// src/resolveOptions.ts
var _path = require('path');
// src/utils.ts
var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring);
// src/regexes.ts

@@ -189,9 +197,3 @@ var regexQuotedString = /(["'`])((?:\\\1|(?:(?!\1)|\n|\r).)*?)\1/mg;

// src/resolveOptions.ts
var _path = require('path');
// src/utils.ts
var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring);
function toArray(v) {

@@ -247,34 +249,2 @@ if (Array.isArray(v))

// src/transformers/pug.ts
var regexTemplate = /<template.*?lang=['"]pug['"][^>]*?>\n([\s\S]*?\n)<\/template>/gm;
var PugTransformer = ({
include: include2 = [/\.vue$/, /\.pug$/]
} = {}) => (code, id) => {
if (!include2.some((i) => id.match(i)))
return;
const Pug = require("pug");
const compile = (code2) => {
try {
return Pug.compile(code2, {filename: id})();
} catch (e2) {
}
};
if (id.match(/\.vue$/)) {
const matches = Array.from(code.matchAll(regexTemplate));
let tail = "";
for (const match of matches) {
if (match && match[1])
tail += `
${compile(match[1])}`;
}
if (tail)
return `${code}
${tail}`;
} else {
return compile(code);
}
};
// src/register.ts

@@ -311,15 +281,73 @@

// src/resolveOptions.ts
function isResolvedOptions(options) {
return options.__windi_resolved;
// src/extractors/helper.ts
// src/extractors/default.ts
function DefaultExtractor(code, id) {
const classes = Array.from(code.matchAll(regexQuotedString)).flatMap((m) => (m[2] || "").split(regexClassSplitter)).filter(validClassName);
const tags = Array.from(code.matchAll(regexHtmlTag)).map((i) => i[1]);
return {
classes,
tags
};
}
function getDefaultTransformers() {
const transformers = [];
// src/extractors/pug.ts
var regexTemplate = /<template.*?lang=['"]pug['"][^>]*?>\n([\s\S]*?\n)<\/template>/gm;
function PugExtractor(code, id) {
const Pug = require("pug");
const compile = (code2) => {
try {
return Pug.compile(code2, {filename: id})();
} catch (e2) {
}
};
let compiled;
if (id && id.match(/\.vue$/)) {
const matches = Array.from(code.matchAll(regexTemplate));
let tail = "";
for (const match of matches) {
if (match && match[1])
tail += `
${compile(match[1])}`;
}
if (tail)
compiled = `${code}
${tail}`;
} else {
compiled = compile(code);
}
return DefaultExtractor(compiled || code);
}
// src/extractors/helper.ts
function getDefaultExtractors() {
const extractors = [];
try {
require.resolve("pug");
transformers.push(PugTransformer());
extractors.push({
extractor: PugExtractor,
extensions: ["vue", "pug"]
});
} catch (e) {
}
return transformers;
return extractors;
}
async function applyExtractors(code, id, extractors = [], defaultExtract = DefaultExtractor) {
let ext = id ? _path.extname.call(void 0, id) : "*";
if (ext[0] === ".")
ext = ext.slice(1);
for (const {extractor, extensions} of extractors) {
if (extensions.includes(ext))
return extractor(code, id);
}
return defaultExtract(code, id);
}
// src/resolveOptions.ts
function isResolvedOptions(options) {
return options.__windi_resolved;
}
function buildGlobs(dirs, fileExtensions) {

@@ -332,3 +360,3 @@ dirs = toArray(dirs);

async function resolveOptions(options = {}, utilsOptions = {}, loadConfigFile = false) {
var _a, _b, _c;
var _a, _b, _c, _d;
if (isResolvedOptions(options))

@@ -362,6 +390,8 @@ return options;

runOnStartup: true,
transformers: getDefaultTransformers()
transformers: [],
extractors: []
}, typeof scan === "boolean" ? {} : scan);
scanOptions.exclude = mergeArrays((_a = config.extract) == null ? void 0 : _a.exclude, scanOptions.exclude);
scanOptions.include = mergeArrays((_b = config.extract) == null ? void 0 : _b.include, scanOptions.include, buildGlobs(scanOptions.dirs, scanOptions.fileExtensions));
scanOptions.extractors = mergeArrays(getDefaultExtractors(), (_c = config.extract) == null ? void 0 : _c.extractors);
const safelist = new Set(mergeArrays(config.safelist, options.safelist).flatMap((i) => i.split(" ")));

@@ -394,3 +424,3 @@ const blocklist = new Set(mergeArrays(config.blocklist, options.blocklist).flatMap((i) => i.split(" ")));

});
const modifiedOptions = await ((_c = resolvedOptions.onOptionsResolved) == null ? void 0 : _c.call(resolvedOptions, resolvedOptions));
const modifiedOptions = await ((_d = resolvedOptions.onOptionsResolved) == null ? void 0 : _d.call(resolvedOptions, resolvedOptions));
if (modifiedOptions != null && modifiedOptions !== resolvedOptions)

@@ -524,4 +554,3 @@ resolvedOptions = Object.assign(resolvedOptions, modifiedOptions);

const contents = await Promise.all(files.filter((id) => isDetectTarget(id)).map(async (id) => [await _fs.promises.readFile(id, "utf-8"), id]));
for (const [content, id] of contents)
extractFile(content, id, true);
await Promise.all(contents.map(([content, id]) => extractFile(content, id, true)));
scanned = true;

@@ -573,3 +602,6 @@ })();

}
function extractFile(code, id, applyGroupTransform = true) {
async function applyExtractors2(code, id) {
return await applyExtractors(code, id, options.scanOptions.extractors);
}
async function extractFile(code, id, applyGroupTransform = true) {
if (applyGroupTransform) {

@@ -587,6 +619,7 @@ if (options.transformGroups)

}
const {classes, tags} = await applyExtractors2(code, id);
let changed = false;
changed = addClasses(Array.from(code.matchAll(regexQuotedString)).flatMap((m) => (m[2] || "").split(regexClassSplitter)).filter(validClassName)) || changed;
changed = addClasses(classes || []) || changed;
if (options.enablePreflight || !options.preflightOptions.includeAll) {
changed = addTags(Array.from(code.matchAll(regexHtmlTag)).map((i) => i[1])) || changed;
changed = addTags(tags || []) || changed;
}

@@ -667,2 +700,3 @@ if (changed) {

extractFile,
applyExtractors: applyExtractors2,
generateCSS,

@@ -731,2 +765,4 @@ getFiles,

exports.PugTransformer = PugTransformer; exports.configureFiles = configureFiles; exports.createUtils = createUtils; exports.defaultAlias = defaultAlias; exports.defineConfig = defineConfig; exports.exclude = exclude; exports.flattenArray = flattenArray; exports.getDefaultTransformers = getDefaultTransformers; exports.htmlTags = htmlTags; exports.include = include; exports.isResolvedOptions = isResolvedOptions; exports.kebabCase = kebabCase; exports.loadConfiguration = loadConfiguration; exports.mergeArrays = mergeArrays; exports.preflightTags = preflightTags; exports.resolveOptions = resolveOptions; exports.slash = slash; exports.toArray = toArray; exports.transformGroups = transformGroups; exports.transformGroupsWithSourcemap = transformGroupsWithSourcemap;
exports.DefaultExtractor = DefaultExtractor; exports.PugExtractor = PugExtractor; exports.applyExtractors = applyExtractors; exports.configureFiles = configureFiles; exports.createUtils = createUtils; exports.defaultAlias = defaultAlias; exports.defineConfig = defineConfig; exports.exclude = exclude; exports.flattenArray = flattenArray; exports.getDefaultExtractors = getDefaultExtractors; exports.htmlTags = htmlTags; exports.include = include; exports.isResolvedOptions = isResolvedOptions; exports.kebabCase = kebabCase; exports.loadConfiguration = loadConfiguration; exports.mergeArrays = mergeArrays; exports.preflightTags = preflightTags; exports.resolveOptions = resolveOptions; exports.slash = slash; exports.toArray = toArray; exports.transformGroups = transformGroups; exports.transformGroupsWithSourcemap = transformGroupsWithSourcemap;
{
"name": "@windicss/plugin-utils",
"description": "Common utils for building integrations of Windi CSS",
"version": "0.10.4",
"version": "0.11.0",
"main": "dist/index.js",

@@ -36,3 +36,3 @@ "module": "dist/index.mjs",

"sucrase": "^3.17.1",
"windicss": "^2.5.7"
"windicss": "^2.5.8"
},

@@ -39,0 +39,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc