@rolldown/pluginutils
Advanced tools
| type StringOrRegExp = string | RegExp; | ||
| type PluginModuleType = 'js' | 'jsx' | 'ts' | 'tsx' | 'json' | 'text' | 'base64' | 'dataurl' | 'binary' | 'empty' | (string & {}); | ||
| export type FilterExpressionKind = FilterExpression['kind']; | ||
| export type FilterExpression = And | Or | Not | Id | ModuleType | Code | Include | Exclude; | ||
| export type TopLevelFilterExpression = Include | Exclude; | ||
| export declare class And { | ||
| kind: 'and'; | ||
| args: FilterExpression[]; | ||
| constructor(...args: FilterExpression[]); | ||
| } | ||
| declare class Or { | ||
| kind: 'or'; | ||
| args: FilterExpression[]; | ||
| constructor(...args: FilterExpression[]); | ||
| } | ||
| declare class Not { | ||
| kind: 'not'; | ||
| expr: FilterExpression; | ||
| constructor(expr: FilterExpression); | ||
| } | ||
| declare class Id { | ||
| kind: 'id'; | ||
| pattern: StringOrRegExp; | ||
| constructor(pattern: StringOrRegExp); | ||
| } | ||
| declare class ModuleType { | ||
| kind: 'moduleType'; | ||
| pattern: PluginModuleType; | ||
| constructor(pattern: PluginModuleType); | ||
| } | ||
| declare class Code { | ||
| kind: 'code'; | ||
| pattern: StringOrRegExp; | ||
| constructor(expr: StringOrRegExp); | ||
| } | ||
| declare class Include { | ||
| kind: 'include'; | ||
| expr: FilterExpression; | ||
| constructor(expr: FilterExpression); | ||
| } | ||
| declare class Exclude { | ||
| kind: 'exclude'; | ||
| expr: FilterExpression; | ||
| constructor(expr: FilterExpression); | ||
| } | ||
| export declare function and(...args: FilterExpression[]): And; | ||
| export declare function or(...args: FilterExpression[]): Or; | ||
| export declare function not(expr: FilterExpression): Not; | ||
| export declare function id(pattern: StringOrRegExp): Id; | ||
| export declare function moduleType(pattern: PluginModuleType): ModuleType; | ||
| export declare function code(pattern: StringOrRegExp): Code; | ||
| export declare function include(expr: FilterExpression): Include; | ||
| export declare function exclude(expr: FilterExpression): Exclude; | ||
| export declare function interpreter(exprs: TopLevelFilterExpression | TopLevelFilterExpression[], code?: string, id?: string, moduleType?: PluginModuleType): boolean; | ||
| export declare function interpreterImpl(expr: TopLevelFilterExpression[], code?: string, id?: string, moduleType?: PluginModuleType): boolean; | ||
| export declare function exprInterpreter(expr: FilterExpression, code?: string, id?: string, moduleType?: PluginModuleType): boolean; | ||
| export {}; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.And = void 0; | ||
| exports.and = and; | ||
| exports.or = or; | ||
| exports.not = not; | ||
| exports.id = id; | ||
| exports.moduleType = moduleType; | ||
| exports.code = code; | ||
| exports.include = include; | ||
| exports.exclude = exclude; | ||
| exports.interpreter = interpreter; | ||
| exports.interpreterImpl = interpreterImpl; | ||
| exports.exprInterpreter = exprInterpreter; | ||
| class And { | ||
| kind; | ||
| args; | ||
| constructor(...args) { | ||
| if (args.length === 0) { | ||
| throw new Error('`And` expects at least one operand'); | ||
| } | ||
| this.args = args; | ||
| this.kind = 'and'; | ||
| } | ||
| } | ||
| exports.And = And; | ||
| class Or { | ||
| kind; | ||
| args; | ||
| constructor(...args) { | ||
| if (args.length === 0) { | ||
| throw new Error('`Or` expects at least one operand'); | ||
| } | ||
| this.args = args; | ||
| this.kind = 'or'; | ||
| } | ||
| } | ||
| class Not { | ||
| kind; | ||
| expr; | ||
| constructor(expr) { | ||
| this.expr = expr; | ||
| this.kind = 'not'; | ||
| } | ||
| } | ||
| class Id { | ||
| kind; | ||
| pattern; | ||
| constructor(pattern) { | ||
| this.pattern = pattern; | ||
| this.kind = 'id'; | ||
| } | ||
| } | ||
| class ModuleType { | ||
| kind; | ||
| pattern; | ||
| constructor(pattern) { | ||
| this.pattern = pattern; | ||
| this.kind = 'moduleType'; | ||
| } | ||
| } | ||
| class Code { | ||
| kind; | ||
| pattern; | ||
| constructor(expr) { | ||
| this.pattern = expr; | ||
| this.kind = 'code'; | ||
| } | ||
| } | ||
| class Include { | ||
| kind; | ||
| expr; | ||
| constructor(expr) { | ||
| this.expr = expr; | ||
| this.kind = 'include'; | ||
| } | ||
| } | ||
| class Exclude { | ||
| kind; | ||
| expr; | ||
| constructor(expr) { | ||
| this.expr = expr; | ||
| this.kind = 'exclude'; | ||
| } | ||
| } | ||
| function and(...args) { | ||
| return new And(...args); | ||
| } | ||
| function or(...args) { | ||
| return new Or(...args); | ||
| } | ||
| function not(expr) { | ||
| return new Not(expr); | ||
| } | ||
| function id(pattern) { | ||
| return new Id(pattern); | ||
| } | ||
| function moduleType(pattern) { | ||
| return new ModuleType(pattern); | ||
| } | ||
| function code(pattern) { | ||
| return new Code(pattern); | ||
| } | ||
| function include(expr) { | ||
| return new Include(expr); | ||
| } | ||
| function exclude(expr) { | ||
| return new Exclude(expr); | ||
| } | ||
| function interpreter(exprs, code, id, moduleType) { | ||
| let arr = []; | ||
| if (Array.isArray(exprs)) { | ||
| arr = exprs; | ||
| } | ||
| else { | ||
| arr = [exprs]; | ||
| } | ||
| return interpreterImpl(arr, code, id, moduleType); | ||
| } | ||
| function interpreterImpl(expr, code, id, moduleType) { | ||
| let hasInclude = false; | ||
| for (const e of expr) { | ||
| switch (e.kind) { | ||
| case 'include': { | ||
| hasInclude = true; | ||
| if (exprInterpreter(e.expr, code, id, moduleType)) { | ||
| return true; | ||
| } | ||
| break; | ||
| } | ||
| case 'exclude': { | ||
| if (exprInterpreter(e.expr, code, id, moduleType)) { | ||
| return false; | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| return !hasInclude; | ||
| } | ||
| function exprInterpreter(expr, code, id, moduleType) { | ||
| switch (expr.kind) { | ||
| case 'and': { | ||
| return expr.args.every((e) => exprInterpreter(e, code, id, moduleType)); | ||
| } | ||
| case 'or': { | ||
| return expr.args.some((e) => exprInterpreter(e, code, id, moduleType)); | ||
| } | ||
| case 'not': { | ||
| return !exprInterpreter(expr.expr, code, id, moduleType); | ||
| } | ||
| case 'id': { | ||
| if (id === undefined) { | ||
| throw new Error('`id` is required for `id` expression'); | ||
| } | ||
| return typeof expr.pattern === 'string' | ||
| ? id === expr.pattern | ||
| : expr.pattern.test(id); | ||
| } | ||
| case 'moduleType': { | ||
| if (moduleType === undefined) { | ||
| throw new Error('`moduleType` is required for `moduleType` expression'); | ||
| } | ||
| return moduleType === expr.pattern; | ||
| } | ||
| case 'code': { | ||
| if (code === undefined) { | ||
| throw new Error('`code` is required for `code` expression'); | ||
| } | ||
| return typeof expr.pattern === 'string' | ||
| ? code.includes(expr.pattern) | ||
| : expr.pattern.test(code); | ||
| } | ||
| default: { | ||
| throw new Error(`Expression kind ${expr.kind} is not expected.`); | ||
| } | ||
| } | ||
| } |
| export * from './composable-filters.js'; | ||
| export * from './simple-filters.js'; |
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| __exportStar(require("./composable-filters.js"), exports); | ||
| __exportStar(require("./simple-filters.js"), exports); |
| { | ||
| "type": "commonjs" | ||
| } |
| /** | ||
| * Constructs a RegExp that matches the exact string specified. | ||
| * | ||
| * This is useful for plugin hook filters. | ||
| * | ||
| * @param str the string to match. | ||
| * @param flags flags for the RegExp. | ||
| */ | ||
| export declare function exactRegex(str: string, flags?: string): RegExp; | ||
| /** | ||
| * Constructs a RegExp that matches a value that has the specified prefix. | ||
| * | ||
| * This is useful for plugin hook filters. | ||
| * | ||
| * @param str the string to match. | ||
| * @param flags flags for the RegExp. | ||
| */ | ||
| export declare function prefixRegex(str: string, flags?: string): RegExp; | ||
| type WidenString<T> = T extends string ? string : T; | ||
| /** | ||
| * Converts a id filter to match with an id with a query. | ||
| * | ||
| * @param input the id filters to convert. | ||
| */ | ||
| export declare function makeIdFiltersToMatchWithQuery<T extends string | RegExp>(input: T): WidenString<T>; | ||
| export declare function makeIdFiltersToMatchWithQuery<T extends string | RegExp>(input: readonly T[]): WidenString<T>[]; | ||
| export declare function makeIdFiltersToMatchWithQuery(input: string | RegExp | readonly (string | RegExp)[]): string | RegExp | (string | RegExp)[]; | ||
| export {}; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.exactRegex = exactRegex; | ||
| exports.prefixRegex = prefixRegex; | ||
| exports.makeIdFiltersToMatchWithQuery = makeIdFiltersToMatchWithQuery; | ||
| /** | ||
| * Constructs a RegExp that matches the exact string specified. | ||
| * | ||
| * This is useful for plugin hook filters. | ||
| * | ||
| * @param str the string to match. | ||
| * @param flags flags for the RegExp. | ||
| */ | ||
| function exactRegex(str, flags) { | ||
| return new RegExp(`^${escapeRegex(str)}$`, flags); | ||
| } | ||
| /** | ||
| * Constructs a RegExp that matches a value that has the specified prefix. | ||
| * | ||
| * This is useful for plugin hook filters. | ||
| * | ||
| * @param str the string to match. | ||
| * @param flags flags for the RegExp. | ||
| */ | ||
| function prefixRegex(str, flags) { | ||
| return new RegExp(`^${escapeRegex(str)}`, flags); | ||
| } | ||
| const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g; | ||
| function escapeRegex(str) { | ||
| return str.replace(escapeRegexRE, '\\$&'); | ||
| } | ||
| function makeIdFiltersToMatchWithQuery(input) { | ||
| if (!Array.isArray(input)) { | ||
| return makeIdFilterToMatchWithQuery( | ||
| // Array.isArray cannot narrow the type | ||
| // https://github.com/microsoft/TypeScript/issues/17002 | ||
| input); | ||
| } | ||
| return input.map((i) => makeIdFilterToMatchWithQuery(i)); | ||
| } | ||
| function makeIdFilterToMatchWithQuery(input) { | ||
| if (typeof input === 'string') { | ||
| return `${input}{?*,}`; | ||
| } | ||
| return makeRegexIdFilterToMatchWithQuery(input); | ||
| } | ||
| function makeRegexIdFilterToMatchWithQuery(input) { | ||
| return new RegExp( | ||
| // replace `$` with `(?:\?.*)?$` (ignore `\$`) | ||
| input.source.replace(/(?<!\\)\$/g, '(?:\\?.*)?$'), input.flags); | ||
| } |
| type StringOrRegExp = string | RegExp; | ||
| type PluginModuleType = 'js' | 'jsx' | 'ts' | 'tsx' | 'json' | 'text' | 'base64' | 'dataurl' | 'binary' | 'empty' | (string & {}); | ||
| export type FilterExpressionKind = FilterExpression['kind']; | ||
| export type FilterExpression = And | Or | Not | Id | ModuleType | Code | Include | Exclude; | ||
| export type TopLevelFilterExpression = Include | Exclude; | ||
| export declare class And { | ||
| kind: 'and'; | ||
| args: FilterExpression[]; | ||
| constructor(...args: FilterExpression[]); | ||
| } | ||
| declare class Or { | ||
| kind: 'or'; | ||
| args: FilterExpression[]; | ||
| constructor(...args: FilterExpression[]); | ||
| } | ||
| declare class Not { | ||
| kind: 'not'; | ||
| expr: FilterExpression; | ||
| constructor(expr: FilterExpression); | ||
| } | ||
| declare class Id { | ||
| kind: 'id'; | ||
| pattern: StringOrRegExp; | ||
| constructor(pattern: StringOrRegExp); | ||
| } | ||
| declare class ModuleType { | ||
| kind: 'moduleType'; | ||
| pattern: PluginModuleType; | ||
| constructor(pattern: PluginModuleType); | ||
| } | ||
| declare class Code { | ||
| kind: 'code'; | ||
| pattern: StringOrRegExp; | ||
| constructor(expr: StringOrRegExp); | ||
| } | ||
| declare class Include { | ||
| kind: 'include'; | ||
| expr: FilterExpression; | ||
| constructor(expr: FilterExpression); | ||
| } | ||
| declare class Exclude { | ||
| kind: 'exclude'; | ||
| expr: FilterExpression; | ||
| constructor(expr: FilterExpression); | ||
| } | ||
| export declare function and(...args: FilterExpression[]): And; | ||
| export declare function or(...args: FilterExpression[]): Or; | ||
| export declare function not(expr: FilterExpression): Not; | ||
| export declare function id(pattern: StringOrRegExp): Id; | ||
| export declare function moduleType(pattern: PluginModuleType): ModuleType; | ||
| export declare function code(pattern: StringOrRegExp): Code; | ||
| export declare function include(expr: FilterExpression): Include; | ||
| export declare function exclude(expr: FilterExpression): Exclude; | ||
| export declare function interpreter(exprs: TopLevelFilterExpression | TopLevelFilterExpression[], code?: string, id?: string, moduleType?: PluginModuleType): boolean; | ||
| export declare function interpreterImpl(expr: TopLevelFilterExpression[], code?: string, id?: string, moduleType?: PluginModuleType): boolean; | ||
| export declare function exprInterpreter(expr: FilterExpression, code?: string, id?: string, moduleType?: PluginModuleType): boolean; | ||
| export {}; |
| export class And { | ||
| kind; | ||
| args; | ||
| constructor(...args) { | ||
| if (args.length === 0) { | ||
| throw new Error('`And` expects at least one operand'); | ||
| } | ||
| this.args = args; | ||
| this.kind = 'and'; | ||
| } | ||
| } | ||
| class Or { | ||
| kind; | ||
| args; | ||
| constructor(...args) { | ||
| if (args.length === 0) { | ||
| throw new Error('`Or` expects at least one operand'); | ||
| } | ||
| this.args = args; | ||
| this.kind = 'or'; | ||
| } | ||
| } | ||
| class Not { | ||
| kind; | ||
| expr; | ||
| constructor(expr) { | ||
| this.expr = expr; | ||
| this.kind = 'not'; | ||
| } | ||
| } | ||
| class Id { | ||
| kind; | ||
| pattern; | ||
| constructor(pattern) { | ||
| this.pattern = pattern; | ||
| this.kind = 'id'; | ||
| } | ||
| } | ||
| class ModuleType { | ||
| kind; | ||
| pattern; | ||
| constructor(pattern) { | ||
| this.pattern = pattern; | ||
| this.kind = 'moduleType'; | ||
| } | ||
| } | ||
| class Code { | ||
| kind; | ||
| pattern; | ||
| constructor(expr) { | ||
| this.pattern = expr; | ||
| this.kind = 'code'; | ||
| } | ||
| } | ||
| class Include { | ||
| kind; | ||
| expr; | ||
| constructor(expr) { | ||
| this.expr = expr; | ||
| this.kind = 'include'; | ||
| } | ||
| } | ||
| class Exclude { | ||
| kind; | ||
| expr; | ||
| constructor(expr) { | ||
| this.expr = expr; | ||
| this.kind = 'exclude'; | ||
| } | ||
| } | ||
| export function and(...args) { | ||
| return new And(...args); | ||
| } | ||
| export function or(...args) { | ||
| return new Or(...args); | ||
| } | ||
| export function not(expr) { | ||
| return new Not(expr); | ||
| } | ||
| export function id(pattern) { | ||
| return new Id(pattern); | ||
| } | ||
| export function moduleType(pattern) { | ||
| return new ModuleType(pattern); | ||
| } | ||
| export function code(pattern) { | ||
| return new Code(pattern); | ||
| } | ||
| export function include(expr) { | ||
| return new Include(expr); | ||
| } | ||
| export function exclude(expr) { | ||
| return new Exclude(expr); | ||
| } | ||
| export function interpreter(exprs, code, id, moduleType) { | ||
| let arr = []; | ||
| if (Array.isArray(exprs)) { | ||
| arr = exprs; | ||
| } | ||
| else { | ||
| arr = [exprs]; | ||
| } | ||
| return interpreterImpl(arr, code, id, moduleType); | ||
| } | ||
| export function interpreterImpl(expr, code, id, moduleType) { | ||
| let hasInclude = false; | ||
| for (const e of expr) { | ||
| switch (e.kind) { | ||
| case 'include': { | ||
| hasInclude = true; | ||
| if (exprInterpreter(e.expr, code, id, moduleType)) { | ||
| return true; | ||
| } | ||
| break; | ||
| } | ||
| case 'exclude': { | ||
| if (exprInterpreter(e.expr, code, id, moduleType)) { | ||
| return false; | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| return !hasInclude; | ||
| } | ||
| export function exprInterpreter(expr, code, id, moduleType) { | ||
| switch (expr.kind) { | ||
| case 'and': { | ||
| return expr.args.every((e) => exprInterpreter(e, code, id, moduleType)); | ||
| } | ||
| case 'or': { | ||
| return expr.args.some((e) => exprInterpreter(e, code, id, moduleType)); | ||
| } | ||
| case 'not': { | ||
| return !exprInterpreter(expr.expr, code, id, moduleType); | ||
| } | ||
| case 'id': { | ||
| if (id === undefined) { | ||
| throw new Error('`id` is required for `id` expression'); | ||
| } | ||
| return typeof expr.pattern === 'string' | ||
| ? id === expr.pattern | ||
| : expr.pattern.test(id); | ||
| } | ||
| case 'moduleType': { | ||
| if (moduleType === undefined) { | ||
| throw new Error('`moduleType` is required for `moduleType` expression'); | ||
| } | ||
| return moduleType === expr.pattern; | ||
| } | ||
| case 'code': { | ||
| if (code === undefined) { | ||
| throw new Error('`code` is required for `code` expression'); | ||
| } | ||
| return typeof expr.pattern === 'string' | ||
| ? code.includes(expr.pattern) | ||
| : expr.pattern.test(code); | ||
| } | ||
| default: { | ||
| throw new Error(`Expression kind ${expr.kind} is not expected.`); | ||
| } | ||
| } | ||
| } |
| export * from './composable-filters.js'; | ||
| export * from './simple-filters.js'; |
| export * from './composable-filters.js'; | ||
| export * from './simple-filters.js'; |
| /** | ||
| * Constructs a RegExp that matches the exact string specified. | ||
| * | ||
| * This is useful for plugin hook filters. | ||
| * | ||
| * @param str the string to match. | ||
| * @param flags flags for the RegExp. | ||
| */ | ||
| export declare function exactRegex(str: string, flags?: string): RegExp; | ||
| /** | ||
| * Constructs a RegExp that matches a value that has the specified prefix. | ||
| * | ||
| * This is useful for plugin hook filters. | ||
| * | ||
| * @param str the string to match. | ||
| * @param flags flags for the RegExp. | ||
| */ | ||
| export declare function prefixRegex(str: string, flags?: string): RegExp; | ||
| type WidenString<T> = T extends string ? string : T; | ||
| /** | ||
| * Converts a id filter to match with an id with a query. | ||
| * | ||
| * @param input the id filters to convert. | ||
| */ | ||
| export declare function makeIdFiltersToMatchWithQuery<T extends string | RegExp>(input: T): WidenString<T>; | ||
| export declare function makeIdFiltersToMatchWithQuery<T extends string | RegExp>(input: readonly T[]): WidenString<T>[]; | ||
| export declare function makeIdFiltersToMatchWithQuery(input: string | RegExp | readonly (string | RegExp)[]): string | RegExp | (string | RegExp)[]; | ||
| export {}; |
| /** | ||
| * Constructs a RegExp that matches the exact string specified. | ||
| * | ||
| * This is useful for plugin hook filters. | ||
| * | ||
| * @param str the string to match. | ||
| * @param flags flags for the RegExp. | ||
| */ | ||
| export function exactRegex(str, flags) { | ||
| return new RegExp(`^${escapeRegex(str)}$`, flags); | ||
| } | ||
| /** | ||
| * Constructs a RegExp that matches a value that has the specified prefix. | ||
| * | ||
| * This is useful for plugin hook filters. | ||
| * | ||
| * @param str the string to match. | ||
| * @param flags flags for the RegExp. | ||
| */ | ||
| export function prefixRegex(str, flags) { | ||
| return new RegExp(`^${escapeRegex(str)}`, flags); | ||
| } | ||
| const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g; | ||
| function escapeRegex(str) { | ||
| return str.replace(escapeRegexRE, '\\$&'); | ||
| } | ||
| export function makeIdFiltersToMatchWithQuery(input) { | ||
| if (!Array.isArray(input)) { | ||
| return makeIdFilterToMatchWithQuery( | ||
| // Array.isArray cannot narrow the type | ||
| // https://github.com/microsoft/TypeScript/issues/17002 | ||
| input); | ||
| } | ||
| return input.map((i) => makeIdFilterToMatchWithQuery(i)); | ||
| } | ||
| function makeIdFilterToMatchWithQuery(input) { | ||
| if (typeof input === 'string') { | ||
| return `${input}{?*,}`; | ||
| } | ||
| return makeRegexIdFilterToMatchWithQuery(input); | ||
| } | ||
| function makeRegexIdFilterToMatchWithQuery(input) { | ||
| return new RegExp( | ||
| // replace `$` with `(?:\?.*)?$` (ignore `\$`) | ||
| input.source.replace(/(?<!\\)\$/g, '(?:\\?.*)?$'), input.flags); | ||
| } |
+1
-1
| { | ||
| "name": "@rolldown/pluginutils", | ||
| "version": "1.0.0-beta.8-commit.56abf23", | ||
| "version": "1.0.0-beta.8-commit.f97bbba", | ||
| "license": "MIT", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
21215
888.58%15
650%632
Infinity%