🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

unplugin

Package Overview
Dependencies
Maintainers
2
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unplugin - npm Package Compare versions

Comparing version

to
2.2.0

dist/context-BIfGOl2h.js

40

dist/index.d.ts
import { CompilationContext, JsPlugin } from '@farmfe/core';
import { Compiler as Compiler$1, Compilation as Compilation$1, LoaderContext as LoaderContext$1, RspackPluginInstance } from '@rspack/core';
export { Compiler as RspackCompiler, RspackPluginInstance } from '@rspack/core';
import { PluginBuild, OnLoadResult, Loader, BuildOptions, Plugin as Plugin$3 } from 'esbuild';
import { PluginBuild, Loader, BuildOptions, Plugin as Plugin$4 } from 'esbuild';
export { Plugin as EsbuildPlugin } from 'esbuild';
import { Plugin as Plugin$2 } from 'rolldown';
import { Plugin as Plugin$3 } from 'rolldown';
export { Plugin as RolldownPlugin } from 'rolldown';
import { SourceMapInput, EmittedAsset, AstNode, Plugin, PluginContextMeta } from 'rollup';
import { PluginContextMeta, EmittedAsset, AstNode, SourceMapInput, Plugin } from 'rollup';
export { Plugin as RollupPlugin } from 'rollup';
import { Plugin as Plugin$2 } from 'unloader';
export { Plugin as UnloaderPlugin } from 'unloader';
import { Plugin as Plugin$1 } from 'vite';

@@ -16,19 +18,2 @@ export { Plugin as VitePlugin } from 'vite';

interface OnTransformOptions {
filter: RegExp;
namespace?: string;
}
interface OnTransformArgs {
getContents: () => Promise<string>;
path: string;
namespace: string;
suffix: string;
pluginData: any;
with: Record<string, string>;
}
type OnTransformCallback = (args: OnTransformArgs) => (OnLoadResult | null | undefined | Promise<OnLoadResult | null | undefined>);
interface EsbuildPluginBuild extends PluginBuild {
onTransform: (options: OnTransformOptions, callback: OnTransformCallback) => void;
}
type Thenable<T> = T | Promise<T>;

@@ -69,3 +54,3 @@ /**

framework: 'esbuild';
build: EsbuildPluginBuild;
build: PluginBuild;
} | {

@@ -115,3 +100,4 @@ framework: 'rspack';

vite?: Partial<Plugin$1>;
rolldown?: Partial<Plugin$2>;
unloader?: Partial<Plugin$2>;
rolldown?: Partial<Plugin$3>;
esbuild?: {

@@ -136,6 +122,7 @@ onResolveFilter?: RegExp;

vite: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<Plugin$1> : Plugin$1>;
rolldown: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<Plugin$2> : Plugin$2>;
rolldown: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<Plugin$3> : Plugin$3>;
webpack: UnpluginFactoryOutput<UserOptions, WebpackPluginInstance>;
rspack: UnpluginFactoryOutput<UserOptions, RspackPluginInstance>;
esbuild: UnpluginFactoryOutput<UserOptions, Plugin$3>;
esbuild: UnpluginFactoryOutput<UserOptions, Plugin$4>;
unloader: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<Plugin$2> : Plugin$2>;
farm: UnpluginFactoryOutput<UserOptions, JsPlugin>;

@@ -145,3 +132,3 @@ raw: UnpluginFactory<UserOptions, Nested>;

type UnpluginContextMeta = Partial<PluginContextMeta> & ({
framework: 'rollup' | 'vite' | 'rolldown' | 'farm';
framework: 'rollup' | 'vite' | 'rolldown' | 'farm' | 'unloader';
} | {

@@ -191,3 +178,4 @@ framework: 'webpack';

declare function createFarmPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>['farm'];
declare function createUnloaderPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>['unloader'];
export { type Arrayable, type ExternalIdResult, type NativeBuildContext, type Nullable, type ResolvedUnpluginOptions, type SourceMapCompact, type Thenable, type TransformResult, type UnpluginBuildContext, type UnpluginContext, type UnpluginContextMeta, type UnpluginFactory, type UnpluginFactoryOutput, type UnpluginInstance, type UnpluginMessage, type UnpluginOptions, createEsbuildPlugin, createFarmPlugin, createRolldownPlugin, createRollupPlugin, createRspackPlugin, createUnplugin, createVitePlugin, createWebpackPlugin };
export { type Arrayable, type ExternalIdResult, type NativeBuildContext, type Nullable, type ResolvedUnpluginOptions, type SourceMapCompact, type Thenable, type TransformResult, type UnpluginBuildContext, type UnpluginContext, type UnpluginContextMeta, type UnpluginFactory, type UnpluginFactoryOutput, type UnpluginInstance, type UnpluginMessage, type UnpluginOptions, createEsbuildPlugin, createFarmPlugin, createRolldownPlugin, createRollupPlugin, createRspackPlugin, createUnloaderPlugin, createUnplugin, createVitePlugin, createWebpackPlugin };
import { parse } from "./context-CyqyI0ug.js";
import { normalizeAbsolutePath, transformUse } from "./webpack-like-D2Xnrc0I.js";
import { createBuildContext$1 as createBuildContext, normalizeMessage$1 as normalizeMessage } from "./context-B_3zWGEx.js";
import { FakeVirtualModulesPlugin, decodeVirtualModuleId, encodeVirtualModuleId, isVirtualModuleId } from "./utils-B98x5nrp.js";
import { contextOptionsFromCompilation, createBuildContext as createBuildContext$1, normalizeMessage as normalizeMessage$1 } from "./context-DvA_cJ4P.js";
import fs, { existsSync, default as fs$1, default as fs$2, default as fs$3 } from "node:fs";
import path, { extname, resolve, default as path$1, default as path$2, default as path$3, default as path$4 } from "node:path";
import { normalizeAbsolutePath, transformUse } from "./webpack-like-CfLIv0IN.js";
import { createBuildContext, normalizeMessage } from "./context-BIfGOl2h.js";
import { FakeVirtualModulesPlugin, decodeVirtualModuleId, encodeVirtualModuleId, isVirtualModuleId } from "./utils-BrnUOYYS.js";
import { contextOptionsFromCompilation, createBuildContext$1, normalizeMessage$1 } from "./context-Cvtxr8zI.js";
import fs, { existsSync } from "node:fs";
import path, { extname, resolve } from "node:path";
import { Buffer as Buffer$1 } from "node:buffer";

@@ -63,3 +63,3 @@ import * as querystring from "node:querystring";

}
const bufLength = 16384;
const bufLength = 1024 * 16;
const td = typeof TextDecoder !== "undefined" ? /* #__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? { decode(buf) {

@@ -235,6 +235,6 @@ const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);

const match = fileRegex.exec(input);
const path$5 = match[2];
return makeUrl("file:", "", match[1] || "", "", isAbsolutePath(path$5) ? path$5 : "/" + path$5, match[3] || "", match[4] || "");
const path$1 = match[2];
return makeUrl("file:", "", match[1] || "", "", isAbsolutePath(path$1) ? path$1 : "/" + path$1, match[3] || "", match[4] || "");
}
function makeUrl(scheme, user, host, port, path$5, query, hash) {
function makeUrl(scheme, user, host, port, path$1, query, hash) {
return {

@@ -245,3 +245,3 @@ scheme,

port,
path: path$5,
path: path$1,
query,

@@ -274,6 +274,6 @@ hash,

}
function stripPathFilename(path$5) {
if (path$5.endsWith("/..")) return path$5;
const index = path$5.lastIndexOf("/");
return path$5.slice(0, index + 1);
function stripPathFilename(path$1) {
if (path$1.endsWith("/..")) return path$1;
const index = path$1.lastIndexOf("/");
return path$1.slice(0, index + 1);
}

@@ -283,3 +283,3 @@ function mergePaths(url, base) {

if (url.path === "/") url.path = base.path;
else url.path = stripPathFilename(base.path) + url.path;
else url.path = stripPathFilename(base.path) + url.path;
}

@@ -315,6 +315,6 @@ /**

}
let path$5 = "";
for (let i = 1; i < pointer; i++) path$5 += "/" + pieces[i];
if (!path$5 || addTrailingSlash && !path$5.endsWith("/..")) path$5 += "/";
url.path = path$5;
let path$1 = "";
for (let i = 1; i < pointer; i++) path$1 += "/" + pieces[i];
if (!path$1 || addTrailingSlash && !path$1.endsWith("/..")) path$1 += "/";
url.path = path$1;
}

@@ -350,6 +350,6 @@ /**

case 4: {
const path$5 = url.path.slice(1);
if (!path$5) return queryHash || ".";
if (isRelative(base || input) && !isRelative(path$5)) return "./" + path$5 + queryHash;
return path$5 + queryHash;
const path$1 = url.path.slice(1);
if (!path$1) return queryHash || ".";
if (isRelative(base || input) && !isRelative(path$1)) return "./" + path$1 + queryHash;
return path$1 + queryHash;
}

@@ -370,6 +370,6 @@ case 5: return url.path + queryHash;

*/
function stripFilename(path$5) {
if (!path$5) return "";
const index = path$5.lastIndexOf("/");
return path$5.slice(0, index + 1);
function stripFilename(path$1) {
if (!path$1) return "";
const index = path$1.lastIndexOf("/");
return path$1.slice(0, index + 1);
}

@@ -425,3 +425,3 @@ const COLUMN$1 = 0;

if (cmp < 0) low = mid + 1;
else high = mid - 1;
else high = mid - 1;
}

@@ -460,3 +460,3 @@ found = false;

if (needle >= lastNeedle) low = lastIndex === -1 ? 0 : lastIndex;
else high = lastIndex;
else high = lastIndex;
}

@@ -525,3 +525,3 @@ state.lastKey = key;

if (found) index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
else if (bias === LEAST_UPPER_BOUND) index++;
else if (bias === LEAST_UPPER_BOUND) index++;
if (index === -1 || index === segments.length) return -1;

@@ -626,3 +626,3 @@ return index;

if (ignore) put(ignoreList, index);
else remove(ignoreList, index);
else remove(ignoreList, index);
}

@@ -893,3 +893,3 @@ /**

function guessLoader(code, id) {
return ExtToLoader$1[path$4.extname(id).toLowerCase()] || "js";
return ExtToLoader$1[path.extname(id).toLowerCase()] || "js";
}

@@ -928,5 +928,5 @@ function unwrapLoader(loader, code, id) {

if (useArrayInterface) map = remapping(sourcemapList, () => null, true);
else map = remapping(sourcemapList[0], (sourcefile) => {
else map = remapping(sourcemapList[0], (sourcefile) => {
if (sourcefile === filename && sourcemapList[mapIndex]) return sourcemapList[mapIndex++];
else return { ...nullSourceMap };
else return { ...nullSourceMap };
}, true);

@@ -947,6 +947,6 @@ if (!map.file) delete map.file;

if (initialOptions.outdir && emittedFile.source && outFileName) {
const outPath = path$4.resolve(initialOptions.outdir, outFileName);
const outDir = path$4.dirname(outPath);
if (!fs$3.existsSync(outDir)) fs$3.mkdirSync(outDir, { recursive: true });
fs$3.writeFileSync(outPath, emittedFile.source);
const outPath = path.resolve(initialOptions.outdir, outFileName);
const outDir = path.dirname(outPath);
if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true });
fs.writeFileSync(outPath, emittedFile.source);
}

@@ -1057,3 +1057,3 @@ },

if (fsContentsCache) return fsContentsCache;
return fsContentsCache = await fs$2.promises.readFile(args.path, "utf8");
return fsContentsCache = await fs.promises.readFile(args.path, "utf8");
}

@@ -1077,3 +1077,3 @@ };

return (build$1, rawBuild) => {
const context = createBuildContext$2(build$1);
const context = createBuildContext$2(rawBuild);
const { onStart, onEnd, onResolve, onLoad, onTransform, initialOptions } = build$1;

@@ -1110,3 +1110,3 @@ const onResolveFilter = plugin.esbuild?.onResolveFilter ?? /.*/;

};
else if (typeof result === "object" && result !== null) return {
else if (typeof result === "object" && result !== null) return {
path: result.id,

@@ -1123,3 +1123,3 @@ external: result.external,

const { errors, warnings, mixedContext } = createPluginContext(context);
const resolveDir = path$3.dirname(args.path);
const resolveDir = path.dirname(args.path);
let code, map;

@@ -1129,3 +1129,3 @@ if (plugin.load && (!plugin.loadInclude || plugin.loadInclude(id))) {

if (typeof result === "string") code = result;
else if (typeof result === "object" && result !== null) {
else if (typeof result === "object" && result !== null) {
code = result.code;

@@ -1150,3 +1150,3 @@ map = result.map;

const { mixedContext, errors, warnings } = createPluginContext(context);
const resolveDir = path$3.dirname(args.path);
const resolveDir = path.dirname(args.path);
let code = await args.getContents();

@@ -1156,7 +1156,7 @@ let map;

if (typeof result === "string") code = result;
else if (typeof result === "object" && result !== null) {
else if (typeof result === "object" && result !== null) {
code = result.code;
if (map && result.map) map = combineSourcemaps(args.path, [result.map === "string" ? JSON.parse(result.map) : result.map, map]);
else if (typeof result.map === "string") map = JSON.parse(result.map);
else map = result.map;
else if (typeof result.map === "string") map = JSON.parse(result.map);
else map = result.map;
}

@@ -1234,3 +1234,3 @@ if (code) {

function guessIdLoader(id) {
return ExtToLoader[path$2.extname(id).toLowerCase()] || "js";
return ExtToLoader[path.extname(id).toLowerCase()] || "js";
}

@@ -1282,3 +1282,3 @@ function convertEnforceToPriority(value) {

}
return path$2.posix.normalize(result.join(""));
return path.posix.normalize(result.join(""));
}

@@ -1298,3 +1298,3 @@ function decodeStr(str) {

} else result[pos++] = str[i++];
return path$2.posix.normalize(result.join(""));
return path.posix.normalize(result.join(""));
}

@@ -1323,4 +1323,4 @@ function getContentValue(content) {

const queryIndex = pathe.indexOf("?");
if (queryIndex !== -1) return path$2.posix.normalize(pathe.slice(0, queryIndex));
return path$2.posix.normalize(pathe);
if (queryIndex !== -1) return path.posix.normalize(pathe.slice(0, queryIndex));
return path.posix.normalize(pathe);
}

@@ -1380,3 +1380,3 @@ function isStartsWithSlash(str) {

async executor(params, context) {
const resolvedIdPath = path$1.resolve(process.cwd(), params.importer ?? "");
const resolvedIdPath = path.resolve(process.cwd(), params.importer ?? "");
let isEntry = false;

@@ -1404,3 +1404,3 @@ if (isObject(params.kind) && "entry" in params.kind) {

if (!isStartsWithSlash(params.source)) return null;
const rootAbsolutePath = path$1.resolve(params.source);
const rootAbsolutePath = path.resolve(params.source);
if (existsSync(rootAbsolutePath)) return {

@@ -1531,3 +1531,3 @@ resolvedPath: removeQuery(encodeStr(rootAbsolutePath)),

//#endregion
//#region node_modules/.pnpm/tsdown@0.5.2_@babel+runtime@7.26.0_typescript@5.6.3/node_modules/tsdown/esm-shims.js
//#region node_modules/.pnpm/tsdown@0.5.9_@babel+runtime@7.26.7_typescript@5.7.3/node_modules/tsdown/esm-shims.js
const getFilename = () => fileURLToPath(import.meta.url);

@@ -1573,3 +1573,3 @@ const getDirname = () => path.dirname(getFilename());

if (error == null) error = normalizeMessage(msg);
else console.error(`unplugin/rspack: multiple errors returned from resolveId hook: ${msg}`);
else console.error(`unplugin/rspack: multiple errors returned from resolveId hook: ${msg}`);
},

@@ -1589,3 +1589,3 @@ warn(msg) {

if (isExternal) externalModules.add(resolved);
if (!fs$1.existsSync(resolved)) {
if (!fs.existsSync(resolved)) {
if (!plugin.__vfsModules.has(resolved)) {

@@ -1643,2 +1643,17 @@ plugin.__vfsModules.add(resolved);

//#endregion
//#region src/unloader/index.ts
function getUnloaderPlugin(factory) {
return (userOptions) => {
const meta = { framework: "unloader" };
const rawPlugins = toArray(factory(userOptions, meta));
const plugins = rawPlugins.map((rawPlugin) => {
const plugin = toRollupPlugin(rawPlugin, false);
if (rawPlugin.unloader) Object.assign(plugin, rawPlugin.unloader);
return plugin;
});
return plugins.length === 1 ? plugins[0] : plugins;
};
}
//#endregion
//#region src/vite/index.ts

@@ -1709,3 +1724,3 @@ function getVitePlugin(factory) {

if (error == null) error = normalizeMessage$1(msg);
else console.error(`unplugin/webpack: multiple errors returned from resolveId hook: ${msg}`);
else console.error(`unplugin/webpack: multiple errors returned from resolveId hook: ${msg}`);
},

@@ -1811,2 +1826,5 @@ warn(msg) {

},
get unloader() {
return getUnloaderPlugin(factory);
},
get raw() {

@@ -1838,4 +1856,7 @@ return factory;

}
function createUnloaderPlugin(factory) {
return getUnloaderPlugin(factory);
}
//#endregion
export { createEsbuildPlugin, createFarmPlugin, createRolldownPlugin, createRollupPlugin, createRspackPlugin, createUnplugin, createVitePlugin, createWebpackPlugin };
export { createEsbuildPlugin, createFarmPlugin, createRolldownPlugin, createRollupPlugin, createRspackPlugin, createUnloaderPlugin, createUnplugin, createVitePlugin, createWebpackPlugin };
import "../../context-CyqyI0ug.js";
import { normalizeAbsolutePath } from "../../webpack-like-D2Xnrc0I.js";
import { createBuildContext$1 as createBuildContext, createContext$1 as createContext } from "../../context-B_3zWGEx.js";
import { decodeVirtualModuleId, isVirtualModuleId } from "../../utils-B98x5nrp.js";
import { normalizeAbsolutePath } from "../../webpack-like-CfLIv0IN.js";
import { createBuildContext, createContext } from "../../context-BIfGOl2h.js";
import { decodeVirtualModuleId, isVirtualModuleId } from "../../utils-BrnUOYYS.js";

@@ -16,4 +16,4 @@ //#region src/rspack/loaders/load.ts

if (res == null) callback(null, source, map);
else if (typeof res !== "string") callback(null, res.code, res.map ?? map);
else callback(null, res, map);
else if (typeof res !== "string") callback(null, res.code, res.map ?? map);
else callback(null, res, map);
}

@@ -20,0 +20,0 @@

import "../../context-CyqyI0ug.js";
import { createBuildContext$1 as createBuildContext, createContext$1 as createContext } from "../../context-B_3zWGEx.js";
import { createBuildContext, createContext } from "../../context-BIfGOl2h.js";

@@ -13,4 +13,4 @@ //#region src/rspack/loaders/transform.ts

if (res == null) callback(null, source, map);
else if (typeof res !== "string") callback(null, res.code, map == null ? map : res.map || map);
else callback(null, res, map);
else if (typeof res !== "string") callback(null, res.code, map == null ? map : res.map || map);
else callback(null, res, map);
}

@@ -17,0 +17,0 @@

import "../../context-CyqyI0ug.js";
import { normalizeAbsolutePath } from "../../webpack-like-D2Xnrc0I.js";
import { createBuildContext, createContext } from "../../context-DvA_cJ4P.js";
import { normalizeAbsolutePath } from "../../webpack-like-CfLIv0IN.js";
import { createBuildContext$1 as createBuildContext, createContext$1 as createContext } from "../../context-Cvtxr8zI.js";

@@ -22,4 +22,4 @@ //#region src/webpack/loaders/load.ts

if (res == null) callback(null, source, map);
else if (typeof res !== "string") callback(null, res.code, res.map ?? map);
else callback(null, res, map);
else if (typeof res !== "string") callback(null, res.code, res.map ?? map);
else callback(null, res, map);
}

@@ -26,0 +26,0 @@

import "../../context-CyqyI0ug.js";
import { createBuildContext, createContext } from "../../context-DvA_cJ4P.js";
import { createBuildContext$1 as createBuildContext, createContext$1 as createContext } from "../../context-Cvtxr8zI.js";

@@ -19,4 +19,4 @@ //#region src/webpack/loaders/transform.ts

if (res == null) callback(null, source, map);
else if (typeof res !== "string") callback(null, res.code, map == null ? map : res.map || map);
else callback(null, res, map);
else if (typeof res !== "string") callback(null, res.code, map == null ? map : res.map || map);
else callback(null, res, map);
}

@@ -23,0 +23,0 @@

{
"name": "unplugin",
"type": "module",
"version": "2.1.2",
"packageManager": "pnpm@9.15.1",
"version": "2.2.0",
"packageManager": "pnpm@10.3.0",
"description": "Unified plugin system for build tools",

@@ -50,35 +50,34 @@ "license": "MIT",

"@ampproject/remapping": "^2.3.0",
"@antfu/eslint-config": "^3.12.1",
"@antfu/ni": "^0.23.2",
"@antfu/eslint-config": "^4.2.0",
"@antfu/ni": "^23.3.1",
"@farmfe/cli": "^1.0.4",
"@farmfe/core": "^1.5.0",
"@rspack/cli": "^1.1.6",
"@rspack/core": "^1.1.6",
"@farmfe/core": "^1.6.6",
"@rspack/cli": "^1.2.2",
"@rspack/core": "^1.2.2",
"@types/fs-extra": "^11.0.4",
"@types/node": "^22.10.2",
"bumpp": "^9.9.2",
"esbuild": "^0.24.2",
"@types/node": "^22.13.1",
"ansis": "^3.12.0",
"bumpp": "^10.0.3",
"esbuild": "^0.25.0",
"esbuild-plugin-copy": "^2.1.1",
"eslint": "^9.17.0",
"fast-glob": "^3.3.2",
"fs-extra": "^11.2.0",
"eslint": "^9.20.0",
"fast-glob": "^3.3.3",
"fs-extra": "^11.3.0",
"jiti": "^2.4.2",
"lint-staged": "^15.2.11",
"lint-staged": "^15.4.3",
"magic-string": "^0.30.17",
"picocolors": "^1.1.1",
"rolldown": "^0.15.1",
"rollup": "^4.29.1",
"rolldown": "^1.0.0-beta.3",
"rollup": "^4.34.6",
"simple-git-hooks": "^2.11.1",
"tsdown": "^0.5.2",
"typescript": "~5.6.3",
"tsdown": "^0.5.9",
"typescript": "~5.7.3",
"unloader": "^0.2.2",
"unplugin": "workspace:*",
"vite": "^6.0.5",
"vitest": "^2.1.8",
"vite": "^6.1.0",
"vitest": "^3.0.5",
"webpack": "^5.97.1",
"webpack-cli": "^6.0.1"
},
"pnpm": {
"overrides": {
"typescript": "~5.6.3"
}
"resolutions": {
"esbuild": "^0.25.0"
},

@@ -85,0 +84,0 @@ "simple-git-hooks": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet