Socket
Socket
Sign inDemoInstall

unplugin

Package Overview
Dependencies
Maintainers
2
Versions
87
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 1.7.1 to 1.8.0

23

dist/index.d.ts

@@ -12,3 +12,3 @@ import * as _rspack_core_dist_config_zod from '@rspack/core/dist/config/zod';

import * as esbuild from 'esbuild';
import { Plugin as Plugin$2, Loader, BuildOptions, PluginBuild } from 'esbuild';
import { PluginBuild, OnLoadResult, Loader, BuildOptions, Plugin as Plugin$2 } from 'esbuild';
export { Plugin as EsbuildPlugin } from 'esbuild';

@@ -19,2 +19,19 @@ import { Compiler as Compiler$1, RspackPluginInstance } from '@rspack/core';

interface OnTransformOptions {
filter: RegExp;
namespace?: string;
}
interface OnTransformArgs {
contents: 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>;

@@ -75,3 +92,3 @@ interface SourceMapCompact {

onLoadFilter?: RegExp;
setup?: Plugin$2['setup'];
setup?: (build: EsbuildPluginBuild) => void | Promise<void>;
loader?: Loader | ((code: string, id: string) => Loader);

@@ -105,3 +122,3 @@ config?: (options: BuildOptions) => void;

framework: 'esbuild';
build?: PluginBuild;
build?: EsbuildPluginBuild;
/** Set the host plugin name of esbuild when returning multiple plugins */

@@ -108,0 +125,0 @@ esbuildHostName?: string;

862

dist/index.js

@@ -51,3 +51,3 @@ "use strict";

// node_modules/.pnpm/@jridgewell+sourcemap-codec@1.4.14/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
// node_modules/.pnpm/@jridgewell+sourcemap-codec@1.4.15/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
var comma = ",".charCodeAt(0);

@@ -58,6 +58,6 @@ var semicolon = ";".charCodeAt(0);

var charToInt = new Uint8Array(128);
for (let i2 = 0; i2 < chars.length; i2++) {
const c = chars.charCodeAt(i2);
intToChar[i2] = c;
charToInt[c] = i2;
for (let i = 0; i < chars.length; i++) {
const c = chars.charCodeAt(i);
intToChar[i] = c;
charToInt[c] = i;
}

@@ -72,4 +72,4 @@ var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {

let out = "";
for (let i2 = 0; i2 < buf.length; i2++) {
out += String.fromCharCode(buf[i2]);
for (let i = 0; i < buf.length; i++) {
out += String.fromCharCode(buf[i]);
}

@@ -89,5 +89,5 @@ return out;

state[0] = 0;
for (let i2 = index; i2 < semi; i2++) {
for (let i = index; i < semi; i++) {
let seg;
i2 = decodeInteger(mappings, i2, state, 0);
i = decodeInteger(mappings, i, state, 0);
const col = state[0];

@@ -97,8 +97,8 @@ if (col < lastCol)

lastCol = col;
if (hasMoreVlq(mappings, i2, semi)) {
i2 = decodeInteger(mappings, i2, state, 1);
i2 = decodeInteger(mappings, i2, state, 2);
i2 = decodeInteger(mappings, i2, state, 3);
if (hasMoreVlq(mappings, i2, semi)) {
i2 = decodeInteger(mappings, i2, state, 4);
if (hasMoreVlq(mappings, i, semi)) {
i = decodeInteger(mappings, i, state, 1);
i = decodeInteger(mappings, i, state, 2);
i = decodeInteger(mappings, i, state, 3);
if (hasMoreVlq(mappings, i, semi)) {
i = decodeInteger(mappings, i, state, 4);
seg = [col, state[1], state[2], state[3], state[4]];

@@ -142,6 +142,6 @@ } else {

}
function hasMoreVlq(mappings, i2, length) {
if (i2 >= length)
function hasMoreVlq(mappings, i, length) {
if (i >= length)
return false;
return mappings.charCodeAt(i2) !== comma;
return mappings.charCodeAt(i) !== comma;
}

@@ -162,5 +162,5 @@ function sort(line) {

let out = "";
for (let i2 = 0; i2 < decoded.length; i2++) {
const line = decoded[i2];
if (i2 > 0) {
for (let i = 0; i < decoded.length; i++) {
const line = decoded[i];
if (i > 0) {
if (pos === bufLength) {

@@ -212,16 +212,6 @@ out += td.decode(buf);

// node_modules/.pnpm/@jridgewell+resolve-uri@3.1.0/node_modules/@jridgewell/resolve-uri/dist/resolve-uri.mjs
// node_modules/.pnpm/@jridgewell+resolve-uri@3.1.2/node_modules/@jridgewell/resolve-uri/dist/resolve-uri.mjs
var schemeRegex = /^[\w+.-]+:\/\//;
var urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
var fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
var UrlType;
(function(UrlType2) {
UrlType2[UrlType2["Empty"] = 1] = "Empty";
UrlType2[UrlType2["Hash"] = 2] = "Hash";
UrlType2[UrlType2["Query"] = 3] = "Query";
UrlType2[UrlType2["RelativePath"] = 4] = "RelativePath";
UrlType2[UrlType2["AbsolutePath"] = 5] = "AbsolutePath";
UrlType2[UrlType2["SchemeRelative"] = 6] = "SchemeRelative";
UrlType2[UrlType2["Absolute"] = 7] = "Absolute";
})(UrlType || (UrlType = {}));
function isAbsoluteUrl(input) {

@@ -260,3 +250,3 @@ return schemeRegex.test(input);

hash,
type: UrlType.Absolute
type: 7
};

@@ -268,3 +258,3 @@ }

url2.scheme = "";
url2.type = UrlType.SchemeRelative;
url2.type = 6;
return url2;

@@ -276,3 +266,3 @@ }

url2.host = "";
url2.type = UrlType.AbsolutePath;
url2.type = 5;
return url2;

@@ -287,3 +277,3 @@ }

url.host = "";
url.type = input ? input.startsWith("?") ? UrlType.Query : input.startsWith("#") ? UrlType.Hash : UrlType.RelativePath : UrlType.Empty;
url.type = input ? input.startsWith("?") ? 3 : input.startsWith("#") ? 2 : 4 : 1;
return url;

@@ -306,3 +296,3 @@ }

function normalizePath(url, type) {
const rel = type <= UrlType.RelativePath;
const rel = type <= 4;
const pieces = url.path.split("/");

@@ -312,4 +302,4 @@ let pointer = 1;

let addTrailingSlash = false;
for (let i2 = 1; i2 < pieces.length; i2++) {
const piece = pieces[i2];
for (let i = 1; i < pieces.length; i++) {
const piece = pieces[i];
if (!piece) {

@@ -336,4 +326,4 @@ addTrailingSlash = true;

let path3 = "";
for (let i2 = 1; i2 < pointer; i2++) {
path3 += "/" + pieces[i2];
for (let i = 1; i < pointer; i++) {
path3 += "/" + pieces[i];
}

@@ -350,18 +340,18 @@ if (!path3 || addTrailingSlash && !path3.endsWith("/..")) {

let inputType = url.type;
if (base && inputType !== UrlType.Absolute) {
if (base && inputType !== 7) {
const baseUrl = parseUrl(base);
const baseType = baseUrl.type;
switch (inputType) {
case UrlType.Empty:
case 1:
url.hash = baseUrl.hash;
case UrlType.Hash:
case 2:
url.query = baseUrl.query;
case UrlType.Query:
case UrlType.RelativePath:
case 3:
case 4:
mergePaths(url, baseUrl);
case UrlType.AbsolutePath:
case 5:
url.user = baseUrl.user;
url.host = baseUrl.host;
url.port = baseUrl.port;
case UrlType.SchemeRelative:
case 6:
url.scheme = baseUrl.scheme;

@@ -375,6 +365,6 @@ }

switch (inputType) {
case UrlType.Hash:
case UrlType.Query:
case 2:
case 3:
return queryHash;
case UrlType.RelativePath: {
case 4: {
const path3 = url.path.slice(1);

@@ -388,3 +378,3 @@ if (!path3)

}
case UrlType.AbsolutePath:
case 5:
return url.path + queryHash;

@@ -396,3 +386,3 @@ default:

// node_modules/.pnpm/@jridgewell+trace-mapping@0.3.17/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.mjs
// node_modules/.pnpm/@jridgewell+trace-mapping@0.3.25/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.mjs
function resolve2(input, base) {

@@ -410,8 +400,2 @@ if (base && !base.endsWith("/"))

var COLUMN = 0;
var SOURCES_INDEX = 1;
var SOURCE_LINE = 2;
var SOURCE_COLUMN = 3;
var NAMES_INDEX = 4;
var REV_GENERATED_LINE = 1;
var REV_GENERATED_COLUMN = 2;
function maybeSort(mappings, owned) {

@@ -423,4 +407,4 @@ const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);

mappings = mappings.slice();
for (let i2 = unsortedIndex; i2 < mappings.length; i2 = nextUnsortedSegmentLine(mappings, i2 + 1)) {
mappings[i2] = sortSegments(mappings[i2], owned);
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
mappings[i] = sortSegments(mappings[i], owned);
}

@@ -430,5 +414,5 @@ return mappings;

function nextUnsortedSegmentLine(mappings, start) {
for (let i2 = start; i2 < mappings.length; i2++) {
if (!isSorted(mappings[i2]))
return i2;
for (let i = start; i < mappings.length; i++) {
if (!isSorted(mappings[i]))
return i;
}

@@ -472,4 +456,4 @@ return mappings.length;

function upperBound(haystack, needle, index) {
for (let i2 = index + 1; i2 < haystack.length; index = i2++) {
if (haystack[i2][COLUMN] !== needle)
for (let i = index + 1; i < haystack.length; index = i++) {
if (haystack[i][COLUMN] !== needle)
break;

@@ -480,4 +464,4 @@ }

function lowerBound(haystack, needle, index) {
for (let i2 = index - 1; i2 >= 0; index = i2--) {
if (haystack[i2][COLUMN] !== needle)
for (let i = index - 1; i >= 0; index = i--) {
if (haystack[i][COLUMN] !== needle)
break;

@@ -513,46 +497,4 @@ }

}
function buildBySources(decoded, memos) {
const sources3 = memos.map(buildNullArray);
for (let i2 = 0; i2 < decoded.length; i2++) {
const line = decoded[i2];
for (let j = 0; j < line.length; j++) {
const seg = line[j];
if (seg.length === 1)
continue;
const sourceIndex = seg[SOURCES_INDEX];
const sourceLine = seg[SOURCE_LINE];
const sourceColumn = seg[SOURCE_COLUMN];
const originalSource = sources3[sourceIndex];
const originalLine = originalSource[sourceLine] || (originalSource[sourceLine] = []);
const memo = memos[sourceIndex];
const index = upperBound(originalLine, sourceColumn, memoizedBinarySearch(originalLine, sourceColumn, memo, sourceLine));
insert(originalLine, memo.lastIndex = index + 1, [sourceColumn, i2, seg[COLUMN]]);
}
}
return sources3;
}
function insert(array, index, value) {
for (let i2 = array.length; i2 > index; i2--) {
array[i2] = array[i2 - 1];
}
array[index] = value;
}
function buildNullArray() {
return { __proto__: null };
}
var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
var LEAST_UPPER_BOUND = -1;
var GREATEST_LOWER_BOUND = 1;
var encodedMappings;
var decodedMappings;
var traceSegment;
var originalPositionFor;
var generatedPositionFor;
var allGeneratedPositionsFor;
var eachMapping;
var sourceContentFor;
var presortedDecodedMap;
var decodedMap;
var encodedMap;
var TraceMap = class {

@@ -567,6 +509,7 @@ constructor(map, mapUrl) {

this.file = file;
this.names = names;
this.names = names || [];
this.sourceRoot = sourceRoot;
this.sources = sources3;
this.sourcesContent = sourcesContent;
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
const from = resolve2(sourceRoot || "", stripFilename(mapUrl));

@@ -587,136 +530,16 @@ this.resolvedSources = sources3.map((s) => resolve2(s || "", from));

};
(() => {
encodedMappings = (map) => {
var _a;
return (_a = map._encoded) !== null && _a !== void 0 ? _a : map._encoded = encode(map._decoded);
};
decodedMappings = (map) => {
return map._decoded || (map._decoded = decode(map._encoded));
};
traceSegment = (map, line, column) => {
const decoded = decodedMappings(map);
if (line >= decoded.length)
return null;
const segments = decoded[line];
const index = traceSegmentInternal(segments, map._decodedMemo, line, column, GREATEST_LOWER_BOUND);
return index === -1 ? null : segments[index];
};
originalPositionFor = (map, { line, column, bias }) => {
line--;
if (line < 0)
throw new Error(LINE_GTR_ZERO);
if (column < 0)
throw new Error(COL_GTR_EQ_ZERO);
const decoded = decodedMappings(map);
if (line >= decoded.length)
return OMapping(null, null, null, null);
const segments = decoded[line];
const index = traceSegmentInternal(segments, map._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
if (index === -1)
return OMapping(null, null, null, null);
const segment = segments[index];
if (segment.length === 1)
return OMapping(null, null, null, null);
const { names, resolvedSources } = map;
return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
};
allGeneratedPositionsFor = (map, { source, line, column, bias }) => {
return generatedPosition(map, source, line, column, bias || LEAST_UPPER_BOUND, true);
};
generatedPositionFor = (map, { source, line, column, bias }) => {
return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false);
};
eachMapping = (map, cb) => {
const decoded = decodedMappings(map);
const { names, resolvedSources } = map;
for (let i2 = 0; i2 < decoded.length; i2++) {
const line = decoded[i2];
for (let j = 0; j < line.length; j++) {
const seg = line[j];
const generatedLine = i2 + 1;
const generatedColumn = seg[0];
let source = null;
let originalLine = null;
let originalColumn = null;
let name = null;
if (seg.length !== 1) {
source = resolvedSources[seg[1]];
originalLine = seg[2] + 1;
originalColumn = seg[3];
}
if (seg.length === 5)
name = names[seg[4]];
cb({
generatedLine,
generatedColumn,
source,
originalLine,
originalColumn,
name
});
}
}
};
sourceContentFor = (map, source) => {
const { sources: sources3, resolvedSources, sourcesContent } = map;
if (sourcesContent == null)
return null;
let index = sources3.indexOf(source);
if (index === -1)
index = resolvedSources.indexOf(source);
return index === -1 ? null : sourcesContent[index];
};
presortedDecodedMap = (map, mapUrl) => {
const tracer = new TraceMap(clone(map, []), mapUrl);
tracer._decoded = map.mappings;
return tracer;
};
decodedMap = (map) => {
return clone(map, decodedMappings(map));
};
encodedMap = (map) => {
return clone(map, encodedMappings(map));
};
function generatedPosition(map, source, line, column, bias, all) {
line--;
if (line < 0)
throw new Error(LINE_GTR_ZERO);
if (column < 0)
throw new Error(COL_GTR_EQ_ZERO);
const { sources: sources3, resolvedSources } = map;
let sourceIndex = sources3.indexOf(source);
if (sourceIndex === -1)
sourceIndex = resolvedSources.indexOf(source);
if (sourceIndex === -1)
return all ? [] : GMapping(null, null);
const generated = map._bySources || (map._bySources = buildBySources(decodedMappings(map), map._bySourceMemos = sources3.map(memoizedState)));
const segments = generated[sourceIndex][line];
if (segments == null)
return all ? [] : GMapping(null, null);
const memo = map._bySourceMemos[sourceIndex];
if (all)
return sliceGeneratedPositions(segments, memo, line, column, bias);
const index = traceSegmentInternal(segments, memo, line, column, bias);
if (index === -1)
return GMapping(null, null);
const segment = segments[index];
return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
}
})();
function clone(map, mappings) {
return {
version: map.version,
file: map.file,
names: map.names,
sourceRoot: map.sourceRoot,
sources: map.sources,
sourcesContent: map.sourcesContent,
mappings
};
function cast(map) {
return map;
}
function OMapping(source, line, column, name) {
return { source, line, column, name };
function decodedMappings(map) {
var _a;
return (_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded));
}
function GMapping(line, column) {
return { line, column };
function traceSegment(map, line, column) {
const decoded = decodedMappings(map);
if (line >= decoded.length)
return null;
const segments = decoded[line];
const index = traceSegmentInternal(segments, cast(map)._decodedMemo, line, column, GREATEST_LOWER_BOUND);
return index === -1 ? null : segments[index];
}

@@ -733,24 +556,4 @@ function traceSegmentInternal(segments, memo, line, column, bias) {

}
function sliceGeneratedPositions(segments, memo, line, column, bias) {
let min = traceSegmentInternal(segments, memo, line, column, GREATEST_LOWER_BOUND);
if (!found && bias === LEAST_UPPER_BOUND)
min++;
if (min === -1 || min === segments.length)
return [];
const matchedColumn = found ? column : segments[min][COLUMN];
if (!found)
min = lowerBound(segments, matchedColumn, min);
const max = upperBound(segments, matchedColumn, min);
const result = [];
for (; min <= max; min++) {
const segment = segments[min];
result.push(GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]));
}
return result;
}
// node_modules/.pnpm/@jridgewell+set-array@1.1.2/node_modules/@jridgewell/set-array/dist/set-array.mjs
var get;
var put;
var pop;
// node_modules/.pnpm/@jridgewell+set-array@1.2.1/node_modules/@jridgewell/set-array/dist/set-array.mjs
var SetArray = class {

@@ -762,119 +565,37 @@ constructor() {

};
(() => {
get = (strarr, key) => strarr._indexes[key];
put = (strarr, key) => {
const index = get(strarr, key);
if (index !== void 0)
return index;
const { array, _indexes: indexes } = strarr;
return indexes[key] = array.push(key) - 1;
};
pop = (strarr) => {
const { array, _indexes: indexes } = strarr;
if (array.length === 0)
return;
const last = array.pop();
indexes[last] = void 0;
};
})();
// node_modules/.pnpm/@jridgewell+sourcemap-codec@1.4.15/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
var comma2 = ",".charCodeAt(0);
var semicolon2 = ";".charCodeAt(0);
var chars2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var intToChar2 = new Uint8Array(64);
var charToInt2 = new Uint8Array(128);
for (let i2 = 0; i2 < chars2.length; i2++) {
const c = chars2.charCodeAt(i2);
intToChar2[i2] = c;
charToInt2[c] = i2;
function cast2(set) {
return set;
}
var td2 = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
decode(buf) {
const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
return out.toString();
function get(setarr, key) {
return cast2(setarr)._indexes[key];
}
function put(setarr, key) {
const index = get(setarr, key);
if (index !== void 0)
return index;
const { array, _indexes: indexes } = cast2(setarr);
const length = array.push(key);
return indexes[key] = length - 1;
}
function remove(setarr, key) {
const index = get(setarr, key);
if (index === void 0)
return;
const { array, _indexes: indexes } = cast2(setarr);
for (let i = index + 1; i < array.length; i++) {
const k = array[i];
array[i - 1] = k;
indexes[k]--;
}
} : {
decode(buf) {
let out = "";
for (let i2 = 0; i2 < buf.length; i2++) {
out += String.fromCharCode(buf[i2]);
}
return out;
}
};
function encode2(decoded) {
const state = new Int32Array(5);
const bufLength = 1024 * 16;
const subLength = bufLength - 36;
const buf = new Uint8Array(bufLength);
const sub = buf.subarray(0, subLength);
let pos = 0;
let out = "";
for (let i2 = 0; i2 < decoded.length; i2++) {
const line = decoded[i2];
if (i2 > 0) {
if (pos === bufLength) {
out += td2.decode(buf);
pos = 0;
}
buf[pos++] = semicolon2;
}
if (line.length === 0)
continue;
state[0] = 0;
for (let j = 0; j < line.length; j++) {
const segment = line[j];
if (pos > subLength) {
out += td2.decode(sub);
buf.copyWithin(0, subLength, pos);
pos -= subLength;
}
if (j > 0)
buf[pos++] = comma2;
pos = encodeInteger2(buf, pos, state, segment, 0);
if (segment.length === 1)
continue;
pos = encodeInteger2(buf, pos, state, segment, 1);
pos = encodeInteger2(buf, pos, state, segment, 2);
pos = encodeInteger2(buf, pos, state, segment, 3);
if (segment.length === 4)
continue;
pos = encodeInteger2(buf, pos, state, segment, 4);
}
}
return out + td2.decode(buf.subarray(0, pos));
indexes[key] = void 0;
array.pop();
}
function encodeInteger2(buf, pos, state, segment, j) {
const next = segment[j];
let num = next - state[j];
state[j] = next;
num = num < 0 ? -num << 1 | 1 : num << 1;
do {
let clamped = num & 31;
num >>>= 5;
if (num > 0)
clamped |= 32;
buf[pos++] = intToChar2[clamped];
} while (num > 0);
return pos;
}
// node_modules/.pnpm/@jridgewell+gen-mapping@0.3.2/node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs
// node_modules/.pnpm/@jridgewell+gen-mapping@0.3.5/node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs
var COLUMN2 = 0;
var SOURCES_INDEX2 = 1;
var SOURCE_LINE2 = 2;
var SOURCE_COLUMN2 = 3;
var NAMES_INDEX2 = 4;
var SOURCES_INDEX = 1;
var SOURCE_LINE = 2;
var SOURCE_COLUMN = 3;
var NAMES_INDEX = 4;
var NO_NAME = -1;
var addSegment;
var addMapping;
var maybeAddSegment;
var maybeAddMapping;
var setSourceContent;
var toDecodedMap;
var toEncodedMap;
var fromMap;
var allMappings;
var addSegmentInternal;
var GenMapping = class {

@@ -888,91 +609,65 @@ constructor({ file, sourceRoot } = {}) {

this.sourceRoot = sourceRoot;
this._ignoreList = new SetArray();
}
};
(() => {
addSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
return addSegmentInternal(false, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content);
function cast3(map) {
return map;
}
var maybeAddSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
return addSegmentInternal(true, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content);
};
function setSourceContent(map, source, content) {
const { _sources: sources3, _sourcesContent: sourcesContent } = cast3(map);
const index = put(sources3, source);
sourcesContent[index] = content;
}
function setIgnore(map, source, ignore = true) {
const { _sources: sources3, _sourcesContent: sourcesContent, _ignoreList: ignoreList } = cast3(map);
const index = put(sources3, source);
if (index === sourcesContent.length)
sourcesContent[index] = null;
if (ignore)
put(ignoreList, index);
else
remove(ignoreList, index);
}
function toDecodedMap(map) {
const { _mappings: mappings, _sources: sources3, _sourcesContent: sourcesContent, _names: names, _ignoreList: ignoreList } = cast3(map);
removeEmptyFinalLines(mappings);
return {
version: 3,
file: map.file || void 0,
names: names.array,
sourceRoot: map.sourceRoot || void 0,
sources: sources3.array,
sourcesContent,
mappings,
ignoreList: ignoreList.array
};
maybeAddSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
return addSegmentInternal(true, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content);
};
addMapping = (map, mapping) => {
return addMappingInternal(false, map, mapping);
};
maybeAddMapping = (map, mapping) => {
return addMappingInternal(true, map, mapping);
};
setSourceContent = (map, source, content) => {
const { _sources: sources3, _sourcesContent: sourcesContent } = map;
sourcesContent[put(sources3, source)] = content;
};
toDecodedMap = (map) => {
const { file, sourceRoot, _mappings: mappings, _sources: sources3, _sourcesContent: sourcesContent, _names: names } = map;
removeEmptyFinalLines(mappings);
return {
version: 3,
file: file || void 0,
names: names.array,
sourceRoot: sourceRoot || void 0,
sources: sources3.array,
sourcesContent,
mappings
};
};
toEncodedMap = (map) => {
const decoded = toDecodedMap(map);
return Object.assign(Object.assign({}, decoded), { mappings: encode2(decoded.mappings) });
};
allMappings = (map) => {
const out = [];
const { _mappings: mappings, _sources: sources3, _names: names } = map;
for (let i2 = 0; i2 < mappings.length; i2++) {
const line = mappings[i2];
for (let j = 0; j < line.length; j++) {
const seg = line[j];
const generated = { line: i2 + 1, column: seg[COLUMN2] };
let source = void 0;
let original = void 0;
let name = void 0;
if (seg.length !== 1) {
source = sources3.array[seg[SOURCES_INDEX2]];
original = { line: seg[SOURCE_LINE2] + 1, column: seg[SOURCE_COLUMN2] };
if (seg.length === 5)
name = names.array[seg[NAMES_INDEX2]];
}
out.push({ generated, source, original, name });
}
}
return out;
};
fromMap = (input) => {
const map = new TraceMap(input);
const gen = new GenMapping({ file: map.file, sourceRoot: map.sourceRoot });
putAll(gen._names, map.names);
putAll(gen._sources, map.sources);
gen._sourcesContent = map.sourcesContent || map.sources.map(() => null);
gen._mappings = decodedMappings(map);
return gen;
};
addSegmentInternal = (skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
const { _mappings: mappings, _sources: sources3, _sourcesContent: sourcesContent, _names: names } = map;
const line = getLine(mappings, genLine);
const index = getColumnIndex(line, genColumn);
if (!source) {
if (skipable && skipSourceless(line, index))
return;
return insert2(line, index, [genColumn]);
}
const sourcesIndex = put(sources3, source);
const namesIndex = name ? put(names, name) : NO_NAME;
if (sourcesIndex === sourcesContent.length)
sourcesContent[sourcesIndex] = content !== null && content !== void 0 ? content : null;
if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) {
}
function toEncodedMap(map) {
const decoded = toDecodedMap(map);
return Object.assign(Object.assign({}, decoded), { mappings: encode(decoded.mappings) });
}
function addSegmentInternal(skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
const { _mappings: mappings, _sources: sources3, _sourcesContent: sourcesContent, _names: names } = cast3(map);
const line = getLine(mappings, genLine);
const index = getColumnIndex(line, genColumn);
if (!source) {
if (skipable && skipSourceless(line, index))
return;
}
return insert2(line, index, name ? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex] : [genColumn, sourcesIndex, sourceLine, sourceColumn]);
};
})();
return insert(line, index, [genColumn]);
}
const sourcesIndex = put(sources3, source);
const namesIndex = name ? put(names, name) : NO_NAME;
if (sourcesIndex === sourcesContent.length)
sourcesContent[sourcesIndex] = content !== null && content !== void 0 ? content : null;
if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) {
return;
}
return insert(line, index, name ? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex] : [genColumn, sourcesIndex, sourceLine, sourceColumn]);
}
function getLine(mappings, index) {
for (let i2 = mappings.length; i2 <= index; i2++) {
mappings[i2] = [];
for (let i = mappings.length; i <= index; i++) {
mappings[i] = [];
}

@@ -983,4 +678,4 @@ return mappings[index];

let index = line.length;
for (let i2 = index - 1; i2 >= 0; index = i2--) {
const current = line[i2];
for (let i = index - 1; i >= 0; index = i--) {
const current = line[i];
if (genColumn >= current[COLUMN2])

@@ -991,5 +686,5 @@ break;

}
function insert2(array, index, value) {
for (let i2 = array.length; i2 > index; i2--) {
array[i2] = array[i2 - 1];
function insert(array, index, value) {
for (let i = array.length; i > index; i--) {
array[i] = array[i - 1];
}

@@ -1001,4 +696,4 @@ array[index] = value;

let len = length;
for (let i2 = len - 1; i2 >= 0; len = i2, i2--) {
if (mappings[i2].length > 0)
for (let i = len - 1; i >= 0; len = i, i--) {
if (mappings[i].length > 0)
break;

@@ -1009,6 +704,2 @@ }

}
function putAll(strarr, array) {
for (let i2 = 0; i2 < array.length; i2++)
put(strarr, array[i2]);
}
function skipSourceless(line, index) {

@@ -1026,20 +717,12 @@ if (index === 0)

return false;
return sourcesIndex === prev[SOURCES_INDEX2] && sourceLine === prev[SOURCE_LINE2] && sourceColumn === prev[SOURCE_COLUMN2] && namesIndex === (prev.length === 5 ? prev[NAMES_INDEX2] : NO_NAME);
return sourcesIndex === prev[SOURCES_INDEX] && sourceLine === prev[SOURCE_LINE] && sourceColumn === prev[SOURCE_COLUMN] && namesIndex === (prev.length === 5 ? prev[NAMES_INDEX] : NO_NAME);
}
function addMappingInternal(skipable, map, mapping) {
const { generated, source, original, name, content } = mapping;
if (!source) {
return addSegmentInternal(skipable, map, generated.line - 1, generated.column, null, null, null, null, null);
}
const s = source;
return addSegmentInternal(skipable, map, generated.line - 1, generated.column, s, original.line - 1, original.column, name, content);
}
// node_modules/.pnpm/@ampproject+remapping@2.2.1/node_modules/@ampproject/remapping/dist/remapping.mjs
var SOURCELESS_MAPPING = /* @__PURE__ */ SegmentObject("", -1, -1, "", null);
// node_modules/.pnpm/@ampproject+remapping@2.3.0/node_modules/@ampproject/remapping/dist/remapping.mjs
var SOURCELESS_MAPPING = /* @__PURE__ */ SegmentObject("", -1, -1, "", null, false);
var EMPTY_SOURCES = [];
function SegmentObject(source, line, column, name, content) {
return { source, line, column, name, content };
function SegmentObject(source, line, column, name, content, ignore) {
return { source, line, column, name, content, ignore };
}
function Source(map, sources3, source, content) {
function Source(map, sources3, source, content, ignore) {
return {

@@ -1049,10 +732,11 @@ map,

source,
content
content,
ignore
};
}
function MapSource(map, sources3) {
return Source(map, sources3, "", null);
return Source(map, sources3, "", null, false);
}
function OriginalSource(source, content) {
return Source(null, EMPTY_SOURCES, source, content);
function OriginalSource(source, content, ignore) {
return Source(null, EMPTY_SOURCES, source, content, ignore);
}

@@ -1064,4 +748,4 @@ function traceMappings(tree) {

const rootMappings = decodedMappings(map);
for (let i2 = 0; i2 < rootMappings.length; i2++) {
const segments = rootMappings[i2];
for (let i = 0; i < rootMappings.length; i++) {
const segments = rootMappings[i];
for (let j = 0; j < segments.length; j++) {

@@ -1073,10 +757,12 @@ const segment = segments[j];

const source2 = rootSources[segment[1]];
traced = originalPositionFor2(source2, segment[2], segment[3], segment.length === 5 ? rootNames[segment[4]] : "");
traced = originalPositionFor(source2, segment[2], segment[3], segment.length === 5 ? rootNames[segment[4]] : "");
if (traced == null)
continue;
}
const { column, line, name, content, source } = traced;
maybeAddSegment(gen, i2, genCol, source, line, column, name);
const { column, line, name, content, source, ignore } = traced;
maybeAddSegment(gen, i, genCol, source, line, column, name);
if (source && content != null)
setSourceContent(gen, source, content);
if (ignore)
setIgnore(gen, source, true);
}

@@ -1086,5 +772,5 @@ }

}
function originalPositionFor2(source, line, column, name) {
function originalPositionFor(source, line, column, name) {
if (!source.map) {
return SegmentObject(source.source, line, column, name, source.content);
return SegmentObject(source.source, line, column, name, source.content, source.ignore);
}

@@ -1096,3 +782,3 @@ const segment = traceSegment(source.map, line, column);

return SOURCELESS_MAPPING;
return originalPositionFor2(source.sources[segment[1]], segment[2], segment[3], segment.length === 5 ? source.map.names[segment[4]] : name);
return originalPositionFor(source.sources[segment[1]], segment[2], segment[3], segment.length === 5 ? source.map.names[segment[4]] : name);
}

@@ -1107,5 +793,5 @@ function asArray(value) {

const map = maps.pop();
for (let i2 = 0; i2 < maps.length; i2++) {
if (maps[i2].sources.length > 1) {
throw new Error(`Transformation map ${i2} must have exactly one source file.
for (let i = 0; i < maps.length; i++) {
if (maps[i].sources.length > 1) {
throw new Error(`Transformation map ${i} must have exactly one source file.
Did you specify these with the most recent transformation maps first?`);

@@ -1115,4 +801,4 @@ }

let tree = build(map, loader, "", 0);
for (let i2 = maps.length - 1; i2 >= 0; i2--) {
tree = MapSource(maps[i2], [tree]);
for (let i = maps.length - 1; i >= 0; i--) {
tree = MapSource(maps[i], [tree]);
}

@@ -1122,5 +808,5 @@ return tree;

function build(map, loader, importer, importerDepth) {
const { resolvedSources, sourcesContent } = map;
const { resolvedSources, sourcesContent, ignoreList } = map;
const depth = importerDepth + 1;
const children = resolvedSources.map((sourceFile, i2) => {
const children = resolvedSources.map((sourceFile, i) => {
const ctx = {

@@ -1130,10 +816,12 @@ importer,

source: sourceFile || "",
content: void 0
content: void 0,
ignore: void 0
};
const sourceMap = loader(ctx.source, ctx);
const { source, content } = ctx;
const { source, content, ignore } = ctx;
if (sourceMap)
return build(new TraceMap(sourceMap, source), loader, source, depth);
const sourceContent = content !== void 0 ? content : sourcesContent ? sourcesContent[i2] : null;
return OriginalSource(source, sourceContent);
const sourceContent = content !== void 0 ? content : sourcesContent ? sourcesContent[i] : null;
const ignored = ignore !== void 0 ? ignore : ignoreList ? ignoreList.includes(i) : false;
return OriginalSource(source, sourceContent, ignored);
});

@@ -1149,2 +837,3 @@ return MapSource(map, children);

this.names = out.names;
this.ignoreList = out.ignoreList;
this.sourceRoot = out.sourceRoot;

@@ -1293,7 +982,10 @@ this.sources = out.sources;

emitFile(emittedFile) {
if (initialOptions.outdir && !import_fs.default.existsSync(initialOptions.outdir))
import_fs.default.mkdirSync(initialOptions.outdir, { recursive: true });
const outFileName = emittedFile.fileName || emittedFile.name;
if (initialOptions.outdir && emittedFile.source && outFileName)
import_fs.default.writeFileSync(import_path2.default.resolve(initialOptions.outdir, outFileName), emittedFile.source);
if (initialOptions.outdir && emittedFile.source && outFileName) {
const outPath = import_path2.default.resolve(initialOptions.outdir, outFileName);
const outDir = import_path2.default.dirname(outPath);
if (!import_fs.default.existsSync(outDir))
import_fs.default.mkdirSync(outDir, { recursive: true });
import_fs.default.writeFileSync(outPath, emittedFile.source);
}
},

@@ -1357,3 +1049,2 @@ getWatchFiles() {

// src/esbuild/index.ts
var i = 0;
function getEsbuildPlugin(factory) {

@@ -1365,5 +1056,67 @@ return (userOptions) => {

const plugins = toArray(factory(userOptions, meta));
const setup = (plugin) => plugin.esbuild?.setup ?? ((build2) => {
const setupPlugins = async (build2) => {
const setup = buildSetup(meta);
const loaders = [];
for (const plugin of plugins) {
const loader = {};
await setup(plugin)({
...build2,
onLoad(_options, callback) {
loader.options = _options;
loader.onLoadCb = callback;
},
onTransform(_options, callback) {
loader.options ||= _options;
loader.onTransformCb = callback;
}
});
if (loader.onLoadCb || loader.onTransformCb)
loaders.push(loader);
}
if (loaders.length) {
build2.onLoad(loaders.length === 1 ? loaders[0].options : { filter: /.*/ }, async (args) => {
function checkFilter(options) {
return loaders.length === 1 || !options?.filter || options.filter.test(args.path);
}
let result;
for (const { options, onLoadCb } of loaders) {
if (!checkFilter(options))
continue;
if (onLoadCb)
result = await onLoadCb(args);
if (result && result.contents)
break;
}
result ||= {};
for (const { options, onTransformCb } of loaders) {
if (!checkFilter(options))
continue;
if (onTransformCb) {
result.contents ||= await import_fs2.default.promises.readFile(args.path, "utf8");
const _result = await onTransformCb({
...result,
...args,
contents: result.contents
});
if (_result && _result.contents)
result = _result;
}
}
return result;
});
}
};
return {
name: (plugins.length === 1 ? plugins[0].name : meta.esbuildHostName) ?? `unplugin-host:${plugins.map((p) => p.name).join(":")}`,
setup: setupPlugins
};
};
}
function buildSetup(meta) {
return (plugin) => {
if (plugin.esbuild?.setup)
return plugin.esbuild.setup;
return (build2) => {
meta.build = build2;
const { onStart, onEnd, onResolve, onLoad, initialOptions } = build2;
const { onStart, onEnd, onResolve, onLoad, onTransform, initialOptions } = build2;
const onResolveFilter = plugin.esbuild?.onResolveFilter ?? /.*/;

@@ -1395,4 +1148,6 @@ const onLoadFilter = plugin.esbuild?.onLoadFilter ?? /.*/;

args.path,
// We explicitly have this if statement here for consistency with the integration of other bundlers.
// Here, `args.importer` is just an empty string on entry files whereas the equivalent on other bundlers is `undefined.`
// We explicitly have this if statement here for consistency with
// the integration of other bundlers.
// Here, `args.importer` is just an empty string on entry files
// whereas the equivalent on other bundlers is`undefined.`
isEntry ? void 0 : args.importer,

@@ -1421,3 +1176,3 @@ { isEntry }

}
if (plugin.load || plugin.transform) {
if (plugin.load) {
onLoad({ filter: onLoadFilter }, async (args) => {

@@ -1437,34 +1192,38 @@ const id = args.path + args.suffix;

}
if (!plugin.transform) {
if (code === void 0)
return null;
if (map)
code = processCodeWithSourceMap(map, code);
return {
contents: code,
errors,
warnings,
watchFiles: mixedContext.getWatchFiles(),
loader: unwrapLoader(loader, code, args.path),
resolveDir
};
}
if (!plugin.transformInclude || plugin.transformInclude(id)) {
if (!code) {
code = await import_fs2.default.promises.readFile(args.path, "utf8");
if (code === void 0)
return null;
if (map)
code = processCodeWithSourceMap(map, code);
return {
contents: code,
errors,
warnings,
watchFiles: mixedContext.getWatchFiles(),
loader: unwrapLoader(loader, code, args.path),
resolveDir
};
});
}
if (plugin.transform) {
onTransform({ filter: onLoadFilter }, async (args) => {
const id = args.path + args.suffix;
if (plugin.transformInclude && !plugin.transformInclude(id))
return;
const { mixedContext, errors, warnings } = createPluginContext(context);
const resolveDir = import_path3.default.dirname(args.path);
let code = args.contents;
let map;
const result = await plugin.transform.call(mixedContext, code, id);
if (typeof result === "string") {
code = result;
} else if (typeof result === "object" && result !== null) {
code = result.code;
if (map && result.map) {
map = combineSourcemaps(args.path, [
result.map,
map
]);
} else {
map = result.map;
}
const result = await plugin.transform.call(mixedContext, code, id);
if (typeof result === "string") {
code = result;
} else if (typeof result === "object" && result !== null) {
code = result.code;
if (map && result.map) {
map = combineSourcemaps(args.path, [
result.map,
map
]);
} else {
map = result.map;
}
}
}

@@ -1485,8 +1244,3 @@ if (code) {

}
});
const setupMultiplePlugins = () => (build2) => {
for (const plugin of plugins)
setup(plugin)(build2);
};
return plugins.length === 1 ? { name: plugins[0].name, setup: setup(plugins[0]) } : { name: meta.esbuildHostName ?? `unplugin-host-${i++}`, setup: setupMultiplePlugins() };
};

@@ -1773,3 +1527,3 @@ }

if (plugin.resolveId) {
let vfs = compiler.options.plugins.find((i2) => i2 instanceof import_webpack_virtual_modules.default);
let vfs = compiler.options.plugins.find((i) => i instanceof import_webpack_virtual_modules.default);
if (!vfs) {

@@ -1776,0 +1530,0 @@ vfs = new import_webpack_virtual_modules.default();

{
"name": "unplugin",
"version": "1.7.1",
"version": "1.8.0",
"packageManager": "pnpm@8.15.1",

@@ -32,5 +32,6 @@ "description": "Unified plugin system for build tools",

"lint:fix": "nr lint --fix",
"typecheck": "tsc --noEmit",
"prepublishOnly": "nr build",
"release": "bumpp --all -x 'npx conventional-changelog -p angular -i CHANGELOG.md -s' && npm publish",
"test": "nr lint && nr test:build && vitest run --pool=forks",
"test": "nr test:build && vitest run --pool=forks",
"test:build": "jiti scripts/buildFixtures.ts"

@@ -40,3 +41,3 @@ },

"acorn": "^8.11.3",
"chokidar": "^3.5.3",
"chokidar": "^3.6.0",
"webpack-sources": "^3.2.3",

@@ -46,27 +47,27 @@ "webpack-virtual-modules": "^0.6.1"

"devDependencies": {
"@ampproject/remapping": "^2.2.1",
"@antfu/eslint-config": "^2.6.4",
"@ampproject/remapping": "^2.3.0",
"@antfu/eslint-config": "^2.7.0",
"@antfu/ni": "^0.21.12",
"@rspack/cli": "^0.5.3",
"@rspack/core": "^0.5.3",
"@rspack/cli": "^0.5.5",
"@rspack/core": "^0.5.5",
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.11.15",
"@types/node": "^20.11.24",
"@types/webpack-sources": "^3.2.3",
"bumpp": "^9.3.0",
"conventional-changelog-cli": "^4.1.0",
"esbuild": "^0.20.0",
"eslint": "^8.56.0",
"esbuild": "^0.20.1",
"eslint": "^8.57.0",
"fast-glob": "^3.3.2",
"fs-extra": "^11.2.0",
"jiti": "^1.21.0",
"lint-staged": "^15.2.1",
"magic-string": "^0.30.6",
"lint-staged": "^15.2.2",
"magic-string": "^0.30.7",
"picocolors": "^1.0.0",
"rollup": "^4.9.6",
"simple-git-hooks": "^2.9.0",
"tsup": "^8.0.1",
"rollup": "^4.12.0",
"simple-git-hooks": "^2.10.0",
"tsup": "^8.0.2",
"typescript": "^5.3.3",
"vite": "^5.0.12",
"vitest": "^1.2.2",
"webpack": "^5.90.0",
"vite": "^5.1.4",
"vitest": "^1.3.1",
"webpack": "^5.90.3",
"webpack-cli": "4.10.0"

@@ -73,0 +74,0 @@ },

Sorry, the diff of this file is not supported yet

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