Socket
Socket
Sign inDemoInstall

unplugin

Package Overview
Dependencies
Maintainers
1
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 0.3.3 to 0.4.0

14

dist/index.d.ts

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

import { SourceMap, Plugin, PluginContextMeta } from 'rollup';
import { SourceMap, EmittedAsset, Plugin, PluginContextMeta } from 'rollup';
export { Plugin as RollupPlugin } from 'rollup';

@@ -20,6 +20,11 @@ import { Compiler, WebpackPluginInstance } from 'webpack';

};
interface UnpluginBuildContext {
addWatchFile: (id: string) => void;
emitFile: (emittedFile: EmittedAsset) => void;
getWatchFiles: () => string[];
}
interface UnpluginOptions {
name: string;
enforce?: 'post' | 'pre' | undefined;
buildStart?: () => Promise<void> | void;
buildStart?: (this: UnpluginBuildContext) => Promise<void> | void;
buildEnd?: () => Promise<void> | void;

@@ -30,2 +35,5 @@ transformInclude?: (id: string) => boolean;

resolveId?: (id: string, importer?: string) => Thenable<string | ExternalIdResult | null | undefined>;
watchChange?: (id: string, change: {
event: 'create' | 'update' | 'delete';
}) => void;
rollup?: Partial<Plugin>;

@@ -71,2 +79,2 @@ webpack?: (compiler: Compiler) => void;

export { ExternalIdResult, ResolvedUnpluginOptions, Thenable, TransformResult, UnpluginContext, UnpluginContextMeta, UnpluginFactory, UnpluginInstance, UnpluginOptions, createUnplugin };
export { ExternalIdResult, ResolvedUnpluginOptions, Thenable, TransformResult, UnpluginBuildContext, UnpluginContext, UnpluginContextMeta, UnpluginFactory, UnpluginInstance, UnpluginOptions, createUnplugin };

@@ -52,3 +52,3 @@ var __create = Object.create;

// node_modules/.pnpm/tsup@5.11.11_typescript@4.5.4/node_modules/tsup/assets/cjs_shims.js
// node_modules/.pnpm/tsup@5.11.13_typescript@4.6.2/node_modules/tsup/assets/cjs_shims.js
var getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;

@@ -60,2 +60,3 @@ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();

var import_path2 = __toESM(require("path"));
var import_chokidar = __toESM(require("chokidar"));

@@ -65,145 +66,300 @@ // src/esbuild/utils.ts

// node_modules/.pnpm/@ampproject+remapping@1.0.2/node_modules/@ampproject/remapping/dist/remapping.mjs
var charToInteger = {};
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
for (i = 0; i < chars.length; i++) {
charToInteger[chars.charCodeAt(i)] = i;
// node_modules/.pnpm/@jridgewell+sourcemap-codec@1.4.11/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
var comma = ",".charCodeAt(0);
var semicolon = ";".charCodeAt(0);
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var intToChar = new Uint8Array(64);
var charToInteger = new Uint8Array(128);
for (let i = 0; i < chars.length; i++) {
const c = chars.charCodeAt(i);
charToInteger[c] = i;
intToChar[i] = c;
}
var i;
var td = typeof TextDecoder !== "undefined" ? new TextDecoder() : typeof Buffer !== "undefined" ? {
decode(buf) {
const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
return out.toString();
}
} : {
decode(buf) {
let out = "";
for (let i = 0; i < buf.length; i++) {
out += String.fromCharCode(buf[i]);
}
return out;
}
};
function decode(mappings) {
var decoded = [];
var line = [];
var segment = [
0,
0,
0,
0,
0
];
var j = 0;
for (var i = 0, shift = 0, value = 0; i < mappings.length; i++) {
var c = mappings.charCodeAt(i);
if (c === 44) {
segmentify(line, segment, j);
j = 0;
} else if (c === 59) {
segmentify(line, segment, j);
j = 0;
const state = new Int32Array(5);
const decoded = [];
let line = [];
let sorted = true;
let lastCol = 0;
for (let i = 0; i < mappings.length; ) {
const c = mappings.charCodeAt(i);
if (c === comma) {
i++;
} else if (c === semicolon) {
state[0] = lastCol = 0;
if (!sorted)
sort(line);
sorted = true;
decoded.push(line);
line = [];
segment[0] = 0;
i++;
} else {
var integer = charToInteger[c];
if (integer === void 0) {
throw new Error("Invalid character (" + String.fromCharCode(c) + ")");
i = decodeInteger(mappings, i, state, 0);
const col = state[0];
if (col < lastCol)
sorted = false;
lastCol = col;
if (!hasMoreSegments(mappings, i)) {
line.push([col]);
continue;
}
var hasContinuationBit = integer & 32;
integer &= 31;
value += integer << shift;
if (hasContinuationBit) {
shift += 5;
} else {
var shouldNegate = value & 1;
value >>>= 1;
if (shouldNegate) {
value = value === 0 ? -2147483648 : -value;
}
segment[j] += value;
j++;
value = shift = 0;
i = decodeInteger(mappings, i, state, 1);
i = decodeInteger(mappings, i, state, 2);
i = decodeInteger(mappings, i, state, 3);
if (!hasMoreSegments(mappings, i)) {
line.push([col, state[1], state[2], state[3]]);
continue;
}
i = decodeInteger(mappings, i, state, 4);
line.push([col, state[1], state[2], state[3], state[4]]);
}
}
segmentify(line, segment, j);
if (!sorted)
sort(line);
decoded.push(line);
return decoded;
}
function segmentify(line, segment, j) {
if (j === 4)
line.push([segment[0], segment[1], segment[2], segment[3]]);
else if (j === 5)
line.push([segment[0], segment[1], segment[2], segment[3], segment[4]]);
else if (j === 1)
line.push([segment[0]]);
function decodeInteger(mappings, pos, state, j) {
let value = 0;
let shift = 0;
let integer = 0;
do {
const c = mappings.charCodeAt(pos++);
integer = charToInteger[c];
value |= (integer & 31) << shift;
shift += 5;
} while (integer & 32);
const shouldNegate = value & 1;
value >>>= 1;
if (shouldNegate) {
value = -2147483648 | -value;
}
state[j] += value;
return pos;
}
function hasMoreSegments(mappings, i) {
if (i >= mappings.length)
return false;
const c = mappings.charCodeAt(i);
if (c === comma || c === semicolon)
return false;
return true;
}
function sort(line) {
line.sort(sortComparator);
}
function sortComparator(a, b) {
return a[0] - b[0];
}
function encode(decoded) {
var sourceFileIndex = 0;
var sourceCodeLine = 0;
var sourceCodeColumn = 0;
var nameIndex = 0;
var mappings = "";
for (var i = 0; i < decoded.length; i++) {
var line = decoded[i];
if (i > 0)
mappings += ";";
const state = new Int32Array(5);
let buf = new Uint8Array(1024);
let pos = 0;
for (let i = 0; i < decoded.length; i++) {
const line = decoded[i];
if (i > 0) {
buf = reserve(buf, pos, 1);
buf[pos++] = semicolon;
}
if (line.length === 0)
continue;
var generatedCodeColumn = 0;
var lineMappings = [];
for (var _i = 0, line_1 = line; _i < line_1.length; _i++) {
var segment = line_1[_i];
var segmentMappings = encodeInteger(segment[0] - generatedCodeColumn);
generatedCodeColumn = segment[0];
if (segment.length > 1) {
segmentMappings += encodeInteger(segment[1] - sourceFileIndex) + encodeInteger(segment[2] - sourceCodeLine) + encodeInteger(segment[3] - sourceCodeColumn);
sourceFileIndex = segment[1];
sourceCodeLine = segment[2];
sourceCodeColumn = segment[3];
}
if (segment.length === 5) {
segmentMappings += encodeInteger(segment[4] - nameIndex);
nameIndex = segment[4];
}
lineMappings.push(segmentMappings);
state[0] = 0;
for (let j = 0; j < line.length; j++) {
const segment = line[j];
buf = reserve(buf, pos, 36);
if (j > 0)
buf[pos++] = comma;
pos = encodeInteger(buf, pos, state, segment, 0);
if (segment.length === 1)
continue;
pos = encodeInteger(buf, pos, state, segment, 1);
pos = encodeInteger(buf, pos, state, segment, 2);
pos = encodeInteger(buf, pos, state, segment, 3);
if (segment.length === 4)
continue;
pos = encodeInteger(buf, pos, state, segment, 4);
}
mappings += lineMappings.join(",");
}
return mappings;
return td.decode(buf.subarray(0, pos));
}
function encodeInteger(num) {
var result = "";
function reserve(buf, pos, count) {
if (buf.length > pos + count)
return buf;
const swap = new Uint8Array(buf.length * 2);
swap.set(buf);
return swap;
}
function encodeInteger(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 {
var clamped = num & 31;
let clamped = num & 31;
num >>>= 5;
if (num > 0) {
if (num > 0)
clamped |= 32;
}
result += chars[clamped];
buf[pos++] = intToChar[clamped];
} while (num > 0);
return result;
return pos;
}
function defaults(target, source) {
return Object.assign(/* @__PURE__ */ Object.create(null), source, target);
// node_modules/.pnpm/@jridgewell+resolve-uri@3.0.5/node_modules/@jridgewell/resolve-uri/dist/resolve-uri.mjs
var schemeRegex = /^[\w+.-]+:\/\//;
var urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?/;
function isAbsoluteUrl(input) {
return schemeRegex.test(input);
}
function decodeSourceMap(map) {
if (typeof map === "string") {
map = JSON.parse(map);
function isSchemeRelativeUrl(input) {
return input.startsWith("//");
}
function isAbsolutePath(input) {
return input.startsWith("/");
}
function parseAbsoluteUrl(input) {
const match = urlRegex.exec(input);
return {
scheme: match[1],
user: match[2] || "",
host: match[3],
port: match[4] || "",
path: match[5] || "/",
relativePath: false
};
}
function parseUrl(input) {
if (isSchemeRelativeUrl(input)) {
const url = parseAbsoluteUrl("http:" + input);
url.scheme = "";
return url;
}
let { mappings } = map;
if (typeof mappings === "string") {
mappings = sortMappings(decode(mappings), true);
if (isAbsolutePath(input)) {
const url = parseAbsoluteUrl("http://foo.com" + input);
url.scheme = "";
url.host = "";
return url;
}
if (!isAbsoluteUrl(input)) {
const url = parseAbsoluteUrl("http://foo.com/" + input);
url.scheme = "";
url.host = "";
url.relativePath = true;
return url;
}
return parseAbsoluteUrl(input);
}
function stripPathFilename(path2) {
if (path2.endsWith("/.."))
return path2;
const index = path2.lastIndexOf("/");
return path2.slice(0, index + 1);
}
function mergePaths(url, base) {
if (!url.relativePath)
return;
normalizePath(base);
if (url.path === "/") {
url.path = base.path;
} else {
mappings = sortMappings(mappings, false);
url.path = stripPathFilename(base.path) + url.path;
}
return defaults({ mappings }, map);
url.relativePath = base.relativePath;
}
function firstUnsortedSegmentLine(mappings) {
for (let i = 0; i < mappings.length; i++) {
const segments = mappings[i];
for (let j = 1; j < segments.length; j++) {
if (segments[j][0] < segments[j - 1][0]) {
return i;
function normalizePath(url) {
const { relativePath } = url;
const pieces = url.path.split("/");
let pointer = 1;
let positive = 0;
let addTrailingSlash = false;
for (let i = 1; i < pieces.length; i++) {
const piece = pieces[i];
if (!piece) {
addTrailingSlash = true;
continue;
}
addTrailingSlash = false;
if (piece === ".")
continue;
if (piece === "..") {
if (positive) {
addTrailingSlash = true;
positive--;
pointer--;
} else if (relativePath) {
pieces[pointer++] = piece;
}
continue;
}
pieces[pointer++] = piece;
positive++;
}
return mappings.length;
let path2 = "";
for (let i = 1; i < pointer; i++) {
path2 += "/" + pieces[i];
}
if (!path2 || addTrailingSlash && !path2.endsWith("/..")) {
path2 += "/";
}
url.path = path2;
}
function sortMappings(mappings, owned) {
const unosrtedIndex = firstUnsortedSegmentLine(mappings);
if (unosrtedIndex === mappings.length)
function resolve(input, base) {
if (!input && !base)
return "";
const url = parseUrl(input);
if (base && !url.scheme) {
const baseUrl = parseUrl(base);
url.scheme = baseUrl.scheme;
if (!url.host || baseUrl.scheme === "file:") {
url.user = baseUrl.user;
url.host = baseUrl.host;
url.port = baseUrl.port;
}
mergePaths(url, baseUrl);
}
normalizePath(url);
if (url.relativePath) {
const path2 = url.path.slice(1);
if (!path2)
return ".";
const keepRelative = (base || input).startsWith(".");
return !keepRelative || path2.startsWith(".") ? path2 : "./" + path2;
}
if (!url.scheme && !url.host)
return url.path;
return `${url.scheme}//${url.user}${url.host}${url.port}${url.path}`;
}
// node_modules/.pnpm/@jridgewell+trace-mapping@0.3.4/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.mjs
function resolve2(input, base) {
if (base && !base.endsWith("/"))
base += "/";
return resolve(input, base);
}
function stripFilename(path2) {
if (!path2)
return "";
const index = path2.lastIndexOf("/");
return path2.slice(0, index + 1);
}
function maybeSort(mappings, owned) {
const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
if (unsortedIndex === mappings.length)
return mappings;
if (!owned)
mappings = mappings.slice();
for (let i = unosrtedIndex; i < mappings.length; i++) {
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
mappings[i] = sortSegments(mappings[i], owned);

@@ -213,96 +369,29 @@ }

}
function sortSegments(segments, owned) {
if (!owned)
segments = segments.slice();
return segments.sort(segmentComparator);
}
function segmentComparator(a, b) {
return a[0] - b[0];
}
var OriginalSource = class {
constructor(filename, content) {
this.filename = filename;
this.content = content;
function nextUnsortedSegmentLine(mappings, start) {
for (let i = start; i < mappings.length; i++) {
if (!isSorted(mappings[i]))
return i;
}
traceSegment(line, column, name) {
return { column, line, name, source: this };
}
};
var Url = typeof URL !== "undefined" ? URL : require("url").URL;
var parentRegex = /(^|\/)\.\.(?=\/|$)/g;
function isAbsoluteUrl(url) {
try {
return !!new Url(url);
} catch (e) {
return false;
}
return mappings.length;
}
function uniqInStr(str) {
let uniq = String(Math.random()).slice(2);
while (str.indexOf(uniq) > -1) {
uniq += uniq;
function isSorted(line) {
for (let j = 1; j < line.length; j++) {
if (line[j][0] < line[j - 1][0]) {
return false;
}
}
return uniq;
return true;
}
function stripPathFilename(path2) {
path2 = normalizePath(path2);
const index = path2.lastIndexOf("/");
return path2.slice(0, index + 1);
function sortSegments(line, owned) {
if (!owned)
line = line.slice();
return line.sort(sortComparator2);
}
function normalizeProtocolRelative(input, absoluteBase) {
const { href, protocol } = new Url(input, absoluteBase);
return href.slice(protocol.length);
function sortComparator2(a, b) {
return a[0] - b[0];
}
function normalizeSimplePath(input) {
const { href } = new Url(input, "https://foo.com/");
return href.slice("https://foo.com/".length);
}
function normalizePath(input) {
if (!parentRegex.test(input))
return normalizeSimplePath(input);
let total = 1;
while (parentRegex.test(input))
total++;
const uniqDirectory = `z${uniqInStr(input)}/`;
const search = new RegExp(`^(?:${uniqDirectory})*`);
const relative = normalizeSimplePath(uniqDirectory.repeat(total) + input);
return relative.replace(search, (all) => {
const leftover = all.length / uniqDirectory.length;
return "../".repeat(total - leftover);
});
}
function resolve(input, base) {
if (!base)
base = "";
if (isAbsoluteUrl(input))
return new Url(input).href;
if (base) {
if (isAbsoluteUrl(base))
return new Url(input, base).href;
if (base.startsWith("//"))
return normalizeProtocolRelative(input, `https:${base}`);
}
if (input.startsWith("//"))
return normalizeProtocolRelative(input, "https://foo.com/");
if (input.startsWith("/"))
return "/" + normalizeSimplePath(input);
const joined = stripPathFilename(base) + input;
if (base.startsWith("/"))
return "/" + normalizeSimplePath(joined);
const relative = normalizePath(joined);
if ((base || input).startsWith(".") && !relative.startsWith(".")) {
return "./" + relative;
}
return relative;
}
function resolve$1(input, base) {
if (base && !base.endsWith("/"))
base += "/";
return resolve(input, base);
}
function binarySearch(haystack, needle, comparator, low, high) {
low = Math.max(low, 0);
function binarySearch(haystack, needle, low, high) {
while (low <= high) {
const mid = low + (high - low >> 1);
const cmp = comparator(haystack[mid], needle);
const cmp = haystack[mid][0] - needle;
if (cmp === 0) {

@@ -317,4 +406,157 @@ return mid;

}
return ~low;
return low - 1;
}
function memoizedState() {
return {
lastKey: -1,
lastNeedle: -1,
lastIndex: -1
};
}
function memoizedBinarySearch(haystack, needle, state, key) {
const { lastKey, lastNeedle, lastIndex } = state;
let low = 0;
let high = haystack.length - 1;
if (key === lastKey) {
if (needle === lastNeedle) {
return lastIndex;
}
if (needle >= lastNeedle) {
low = Math.max(lastIndex, 0);
} else {
high = lastIndex;
}
}
state.lastKey = key;
state.lastNeedle = needle;
return state.lastIndex = binarySearch(haystack, needle, low, high);
}
var INVALID_MAPPING = Object.freeze({
source: null,
line: null,
column: null,
name: null
});
var encodedMappings;
var decodedMappings;
var traceSegment;
var originalPositionFor;
var eachMapping;
var presortedDecodedMap;
var TraceMap = class {
constructor(map, mapUrl) {
this._binarySearchMemo = memoizedState();
const isString = typeof map === "string";
const parsed = isString ? JSON.parse(map) : map;
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
this.version = version;
this.file = file;
this.names = names;
this.sourceRoot = sourceRoot;
this.sources = sources;
this.sourcesContent = sourcesContent;
if (sourceRoot || mapUrl) {
const from = resolve2(sourceRoot || "", stripFilename(mapUrl));
this.resolvedSources = sources.map((s) => resolve2(s || "", from));
} else {
this.resolvedSources = sources.map((s) => s || "");
}
const { mappings } = parsed;
if (typeof mappings === "string") {
this._encoded = mappings;
this._decoded = decode(mappings);
} else {
this._encoded = void 0;
this._decoded = maybeSort(mappings, isString);
}
}
};
(() => {
encodedMappings = (map) => {
var _a;
return (_a = map._encoded) !== null && _a !== void 0 ? _a : map._encoded = encode(map._decoded);
};
decodedMappings = (map) => {
return map._decoded;
};
traceSegment = (map, line, column) => {
const decoded = map._decoded;
if (line >= decoded.length)
return null;
const segments = decoded[line];
const index = memoizedBinarySearch(segments, column, map._binarySearchMemo, line);
if (index < 0)
return null;
return segments[index];
};
originalPositionFor = (map, { line, column }) => {
if (line < 1)
throw new Error("`line` must be greater than 0 (lines start at line 1)");
if (column < 0) {
throw new Error("`column` must be greater than or equal to 0 (columns start at column 0)");
}
const segment = traceSegment(map, line - 1, column);
if (segment == null)
return INVALID_MAPPING;
if (segment.length == 1)
return INVALID_MAPPING;
const { names, resolvedSources } = map;
return {
source: resolvedSources[segment[1]],
line: segment[2] + 1,
column: segment[3],
name: segment.length === 5 ? names[segment[4]] : null
};
};
eachMapping = (map, cb) => {
const decoded = map._decoded;
const { names, resolvedSources } = map;
for (let i = 0; i < decoded.length; i++) {
const line = decoded[i];
for (let j = 0; j < line.length; j++) {
const seg = line[j];
const generatedLine = i + 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
});
}
}
};
presortedDecodedMap = (map, mapUrl) => {
const clone = Object.assign({}, map);
clone.mappings = [];
const tracer = new TraceMap(clone, mapUrl);
tracer._decoded = map.mappings;
return tracer;
};
})();
// node_modules/.pnpm/@ampproject+remapping@2.1.2/node_modules/@ampproject/remapping/dist/remapping.mjs
var OriginalSource = class {
constructor(source, content) {
this.source = source;
this.content = content;
}
originalPositionFor(line, column, name) {
return { column, line, name, source: this.source, content: this.content };
}
};
var put;
var FastStringArray = class {

@@ -325,4 +567,6 @@ constructor() {

}
put(key) {
const { array, indexes } = this;
};
(() => {
put = (strarr, key) => {
const { array, indexes } = strarr;
let index = indexes[key];

@@ -334,4 +578,7 @@ if (index === void 0) {

return index;
}
};
};
})();
var INVALID_MAPPING2 = void 0;
var SOURCELESS_MAPPING = null;
var traceMappings;
var SourceMapTree = class {

@@ -341,7 +588,15 @@ constructor(map, sources) {

this.sources = sources;
this.lastLine = 0;
this.lastColumn = 0;
this.lastIndex = 0;
}
traceMappings() {
originalPositionFor(line, column, name) {
const segment = traceSegment(this.map, line, column);
if (segment == null)
return INVALID_MAPPING2;
if (segment.length === 1)
return SOURCELESS_MAPPING;
const source = this.sources[segment[1]];
return source.originalPositionFor(segment[2], segment[3], segment.length === 5 ? this.map.names[segment[4]] : name);
}
};
(() => {
traceMappings = (tree) => {
const mappings = [];

@@ -351,81 +606,56 @@ const names = new FastStringArray();

const sourcesContent = [];
const { mappings: rootMappings, names: rootNames } = this.map;
const { sources: rootSources, map } = tree;
const rootNames = map.names;
const rootMappings = decodedMappings(map);
let lastLineWithSegment = -1;
for (let i = 0; i < rootMappings.length; i++) {
const segments = rootMappings[i];
const tracedSegments = [];
let lastTraced = void 0;
let lastSourcesIndex = -1;
let lastSourceLine = -1;
let lastSourceColumn = -1;
for (let j = 0; j < segments.length; j++) {
const segment = segments[j];
if (segment.length === 1)
let traced = SOURCELESS_MAPPING;
if (segment.length !== 1) {
const source2 = rootSources[segment[1]];
traced = source2.originalPositionFor(segment[2], segment[3], segment.length === 5 ? rootNames[segment[4]] : "");
if (traced === INVALID_MAPPING2)
continue;
}
const genCol = segment[0];
if (traced === SOURCELESS_MAPPING) {
if (lastSourcesIndex === -1) {
continue;
}
lastSourcesIndex = lastSourceLine = lastSourceColumn = -1;
tracedSegments.push([genCol]);
continue;
const source = this.sources[segment[1]];
const traced = source.traceSegment(segment[2], segment[3], segment.length === 5 ? rootNames[segment[4]] : "");
if (!traced)
}
const { column, line, name, content, source } = traced;
const sourcesIndex = put(sources, source);
sourcesContent[sourcesIndex] = content;
if (lastSourcesIndex === sourcesIndex && lastSourceLine === line && lastSourceColumn === column) {
continue;
const { column, line, name } = traced;
const { content, filename } = traced.source;
const sourceIndex = sources.put(filename);
sourcesContent[sourceIndex] = content;
if (lastTraced && lastTraced[1] === sourceIndex && lastTraced[2] === line && lastTraced[3] === column) {
continue;
}
if (name) {
lastTraced = [segment[0], sourceIndex, line, column, names.put(name)];
} else {
lastTraced = [segment[0], sourceIndex, line, column];
}
tracedSegments.push(lastTraced);
lastLineWithSegment = i;
lastSourcesIndex = sourcesIndex;
lastSourceLine = line;
lastSourceColumn = column;
tracedSegments.push(name ? [genCol, sourcesIndex, line, column, put(names, name)] : [genCol, sourcesIndex, line, column]);
}
mappings.push(tracedSegments);
}
return defaults({
if (mappings.length > lastLineWithSegment + 1) {
mappings.length = lastLineWithSegment + 1;
}
return presortedDecodedMap(Object.assign({}, tree.map, {
mappings,
sourceRoot: void 0,
names: names.array,
sources: sources.array,
sourcesContent
}, this.map);
}
traceSegment(line, column, name) {
const { mappings, names } = this.map;
if (line >= mappings.length)
return null;
const segments = mappings[line];
if (segments.length === 0)
return null;
let low = 0;
let high = segments.length - 1;
if (line === this.lastLine) {
if (column >= this.lastColumn) {
low = this.lastIndex;
} else {
high = this.lastIndex;
}
}
let index = binarySearch(segments, column, segmentComparator$1, low, high);
this.lastLine = line;
this.lastColumn = column;
if (index === -1) {
this.lastIndex = index;
return null;
}
if (index < 0) {
index = ~index - 1;
}
this.lastIndex = index;
const segment = segments[index];
if (segment.length === 1)
return null;
const source = this.sources[segment[1]];
return source.traceSegment(segment[2], segment[3], segment.length === 5 ? names[segment[4]] : name);
}
};
function segmentComparator$1(segment, column) {
return segment[0] - column;
}
function stripFilename(path2) {
if (!path2)
return "";
const index = path2.lastIndexOf("/");
return path2.slice(0, index + 1);
}
}));
};
})();
function asArray(value) {

@@ -436,4 +666,4 @@ if (Array.isArray(value))

}
function buildSourceMapTree(input, loader, relativeRoot) {
const maps = asArray(input).map(decodeSourceMap);
function buildSourceMapTree(input, loader) {
const maps = asArray(input).map((m) => new TraceMap(m, ""));
const map = maps.pop();

@@ -446,13 +676,3 @@ for (let i = 0; i < maps.length; i++) {

}
const { sourceRoot, sources, sourcesContent } = map;
const children = sources.map((sourceFile, i) => {
const uri = resolve$1(sourceFile || "", resolve$1(sourceRoot || "", stripFilename(relativeRoot)));
const sourceMap = loader(uri);
if (!sourceMap) {
const sourceContent = sourcesContent ? sourcesContent[i] : null;
return new OriginalSource(uri, sourceContent);
}
return buildSourceMapTree(decodeSourceMap(sourceMap), loader, uri);
});
let tree = new SourceMapTree(map, children);
let tree = build(map, loader, "", 0);
for (let i = maps.length - 1; i >= 0; i--) {

@@ -463,9 +683,29 @@ tree = new SourceMapTree(maps[i], [tree]);

}
function build(map, loader, importer, importerDepth) {
const { resolvedSources, sourcesContent } = map;
const depth = importerDepth + 1;
const children = resolvedSources.map((sourceFile, i) => {
const ctx = {
importer,
depth,
source: sourceFile || "",
content: void 0
};
const sourceMap = loader(ctx.source, ctx);
const { source, content } = ctx;
if (!sourceMap) {
const sourceContent = content !== void 0 ? content : sourcesContent ? sourcesContent[i] : null;
return new OriginalSource(source, sourceContent);
}
return build(new TraceMap(sourceMap, source), loader, source, depth);
});
return new SourceMapTree(map, children);
}
var SourceMap = class {
constructor(map, options) {
this.version = 3;
if ("file" in map)
this.file = map.file;
this.mappings = options.decodedMappings ? map.mappings : encode(map.mappings);
this.file = map.file;
this.mappings = options.decodedMappings ? decodedMappings(map) : encodedMappings(map);
this.names = map.names;
this.sourceRoot = map.sourceRoot;
this.sources = map.sources;

@@ -482,6 +722,5 @@ if (!options.excludeContent && "sourcesContent" in map) {

const opts = typeof options === "object" ? options : { excludeContent: !!options, decodedMappings: false };
const graph = buildSourceMapTree(input, loader);
return new SourceMap(graph.traceMappings(), opts);
const tree = buildSourceMapTree(input, loader);
return new SourceMap(traceMappings(tree), opts);
}
var remapping_default = remapping;

@@ -543,5 +782,5 @@ // src/esbuild/utils.ts

if (useArrayInterface) {
map = remapping_default(sourcemapList, () => null, true);
map = remapping(sourcemapList, () => null, true);
} else {
map = remapping_default(sourcemapList[0], function loader(sourcefile) {
map = remapping(sourcemapList[0], function loader(sourcefile) {
if (sourcefile === filename && sourcemapList[mapIndex]) {

@@ -561,2 +800,4 @@ return sourcemapList[mapIndex++];

// src/esbuild/index.ts
var watchListRecord = {};
var watchList = /* @__PURE__ */ new Set();
function getEsbuildPlugin(factory) {

@@ -571,3 +812,3 @@ return (userOptions) => {

name: plugin.name,
setup: (_b = (_a = plugin.esbuild) == null ? void 0 : _a.setup) != null ? _b : function setup({ onStart, onEnd, onResolve, onLoad }) {
setup: (_b = (_a = plugin.esbuild) == null ? void 0 : _a.setup) != null ? _b : function setup({ onStart, onEnd, onResolve, onLoad, initialOptions, esbuild: { build: build2 } }) {
var _a2, _b2, _c, _d;

@@ -577,6 +818,48 @@ const onResolveFilter = (_b2 = (_a2 = plugin.esbuild) == null ? void 0 : _a2.onResolveFilter) != null ? _b2 : /.*/;

if (plugin.buildStart) {
onStart(plugin.buildStart);
onStart(() => plugin.buildStart.call({
addWatchFile(id) {
watchList.add(import_path2.default.resolve(id));
},
emitFile(emittedFile) {
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);
}
},
getWatchFiles() {
return Array.from(watchList);
}
}));
}
if (plugin.buildEnd) {
onEnd(plugin.buildEnd);
if (plugin.buildEnd || initialOptions.watch) {
const rebuild = () => build2(__spreadProps(__spreadValues({}, initialOptions), {
watch: false
}));
onEnd(() => {
var _a3;
(_a3 = plugin.buildEnd) == null ? void 0 : _a3.call(plugin);
if (initialOptions.watch) {
Object.keys(watchListRecord).forEach((id) => {
if (!watchList.has(id)) {
watchListRecord[id].close();
delete watchListRecord[id];
}
});
watchList.forEach((id) => {
if (!Object.keys(watchListRecord).includes(id)) {
watchListRecord[id] = import_chokidar.default.watch(id);
watchListRecord[id].on("change", () => {
var _a4;
(_a4 = plugin.watchChange) == null ? void 0 : _a4.call(plugin, id, { event: "update" });
rebuild();
});
watchListRecord[id].on("unlink", () => {
var _a4;
(_a4 = plugin.watchChange) == null ? void 0 : _a4.call(plugin, id, { event: "delete" });
rebuild();
});
}
});
}
});
}

@@ -730,3 +1013,2 @@ if (plugin.resolveId) {

apply(compiler) {
var _a;
const meta = {

@@ -830,3 +1112,35 @@ framework: "webpack",

}
(_a = plugin.buildStart) == null ? void 0 : _a.call(plugin);
compiler.hooks.thisCompilation.tap(plugin.name, (compilation) => {
var _a;
(_a = plugin.buildStart) == null ? void 0 : _a.call({
addWatchFile(id) {
var _a2;
((_a2 = compilation.fileDependencies) != null ? _a2 : compilation.compilationDependencies).add((0, import_path3.resolve)(process.cwd(), id));
},
emitFile(emittedFile) {
var _a2;
const outFileName = emittedFile.fileName || emittedFile.name;
if (emittedFile.source && outFileName) {
compilation.emitAsset(outFileName, ((_a2 = compiler.webpack) == null ? void 0 : _a2.sources) ? new compiler.webpack.sources.RawSource(typeof emittedFile.source === "string" ? emittedFile.source : Buffer.from(emittedFile.source)) : {
source: () => emittedFile.source,
size: () => emittedFile.source.length
});
}
},
getWatchFiles() {
var _a2;
return Array.from((_a2 = compilation.fileDependencies) != null ? _a2 : compilation.compilationDependencies);
}
});
});
if (plugin.watchChange) {
compiler.hooks.watchRun.tap(plugin.name, (compilation) => {
if (compilation.modifiedFiles) {
compilation.modifiedFiles.forEach((file) => plugin.watchChange(file, { event: "update" }));
}
if (compilation.removedFiles) {
compilation.removedFiles.forEach((file) => plugin.watchChange(file, { event: "delete" }));
}
});
}
if (plugin.buildEnd) {

@@ -833,0 +1147,0 @@ compiler.hooks.done.tapPromise(plugin.name, async () => {

{
"name": "unplugin",
"version": "0.3.3",
"version": "0.4.0",
"description": "Unified plugin system for build tools",

@@ -32,27 +32,28 @@ "repository": "unjs/unplugin",

"dependencies": {
"chokidar": "^3.5.3",
"webpack-virtual-modules": "^0.4.3"
},
"devDependencies": {
"@ampproject/remapping": "^1.0.2",
"@antfu/ni": "^0.12.0",
"@ampproject/remapping": "^2.1.2",
"@antfu/ni": "^0.13.2",
"@nuxtjs/eslint-config-typescript": "^8.0.0",
"@types/express": "^4.17.13",
"@types/fs-extra": "^9.0.13",
"@types/node": "^17.0.8",
"@types/node": "^17.0.21",
"bumpp": "^7.1.1",
"conventional-changelog-cli": "^2.2.2",
"enhanced-resolve": "^5.8.3",
"esbuild": "^0.14.11",
"eslint": "^8.6.0",
"fast-glob": "^3.2.10",
"fs-extra": "^10.0.0",
"jiti": "^1.12.9",
"magic-string": "^0.25.7",
"rollup": "^2.63.0",
"tsup": "^5.11.11",
"typescript": "^4.5.4",
"vite": "^2.7.10",
"vitest": "^0.0.141",
"webpack": "^5.66.0",
"webpack-cli": "^4.9.1"
"enhanced-resolve": "^5.9.2",
"esbuild": "^0.14.25",
"eslint": "^8.10.0",
"fast-glob": "^3.2.11",
"fs-extra": "^10.0.1",
"jiti": "^1.13.0",
"magic-string": "^0.26.1",
"rollup": "^2.70.0",
"tsup": "^5.11.13",
"typescript": "^4.6.2",
"vite": "^2.8.6",
"vitest": "^0.5.9",
"webpack": "^5.70.0",
"webpack-cli": "^4.9.2"
},

@@ -59,0 +60,0 @@ "peerDependencies": {

@@ -28,2 +28,3 @@ # unplugin

| [`load`](https://rollupjs.org/guide/en/#load) | ✅ | ✅ | ✅ | ✅ | ✅ <sup>3</sup> |
| [`watchChange`](https://rollupjs.org/guide/en/#watchchange) | ✅ | ✅ | ✅ | ✅ | ✅ |

@@ -34,2 +35,12 @@ 1. Webpack's id filter is outside of loader logic; an additional hook is needed for better perf on Webpack. In Rollup and Vite, this hook has been polyfilled to match the behaviors. See for following usage examples.

### [`buildStart`](https://rollupjs.org/guide/en/#buildstart) Context
###### Supported
| Hook | Rollup | Vite | Webpack 4 | Webpack 5 | esbuild |
| ---- | :----: | :--: | :-------: | :-------: | :-----: |
| [`this.addWatchFile`](https://rollupjs.org/guide/en/#thisaddwatchfile) | ✅ | ✅ | ✅ | ✅ | ✅ |
| [`this.emitFile`](https://rollupjs.org/guide/en/#thisemitfile) | ✅ | ✅ | ✅ | ✅ | ✅ |
| [`this.getWatchFiles`](https://rollupjs.org/guide/en/#thisgetwatchfiles) | ✅ | ✅ | ✅ | ✅ | ✅ |
## Usage

@@ -36,0 +47,0 @@

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