Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

vite-plugin-esi

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-esi - npm Package Compare versions

Comparing version
1.2.3
to
1.2.4
+103
dist/index.cjs
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// src/index.ts
var src_exports = {};
__export(src_exports, {
default: () => esiPlugin
});
module.exports = __toCommonJS(src_exports);
// src/transform.ts
var import_nodesi = __toESM(require("nodesi"), 1);
// src/errors.ts
var TagsNotFoundError = class extends Error {
constructor(message) {
super(message);
this.name = "TagsNotFoundError";
}
};
// src/transform.ts
function transformHtml(html, options) {
const regex = new RegExp('<!--*\\s*vite-plugin-esi\\s(name="(?<name>[a-zA-Z0-9]+)").*->', "g");
return html.replace(regex, (_match, _, __, ___, ____, groups) => {
const tags = options[groups.name];
if (!tags) {
throw new TagsNotFoundError(`no tags found for ${groups.name}`);
}
return tags.map((tag) => {
const { src, type = "include", onError = "abort" } = tag;
return `<esi:${type} src="${src}" onerror="${onError}" />`;
}).join("\n");
});
}
function resolveESI(html, options) {
return __async(this, null, function* () {
const esi = new import_nodesi.default(options);
const resolvedHtml = yield esi.process(html);
return resolvedHtml;
});
}
// src/index.ts
function esiPlugin(options) {
var _a;
const shouldResolveESI = (_a = options.resolveESI) != null ? _a : true;
return {
name: "vite-plugin-esi",
transformIndexHtml(inputHtml) {
const html = transformHtml(inputHtml, options.esi);
if (shouldResolveESI) {
return resolveESI(html);
}
}
};
}
import { Plugin } from 'vite';
type Tag = {
src: string;
type?: 'include' | 'remove';
onError?: 'continue' | 'abort';
};
type NodeEsiOptions = {
onError: (src: string, err: Error) => string;
allowedHosts: string[];
baseUrl: string;
};
type EsiOptions = {
[name: string]: Tag[];
};
type Options = {
esiOptions?: NodeEsiOptions;
esi: EsiOptions;
resolveESI?: boolean;
};
declare function esiPlugin(options: Options): Plugin;
export { esiPlugin as default };
+24
-3

@@ -1,3 +0,24 @@

import type { Plugin } from 'vite';
import type { Options } from './types';
export default function esiPlugin(options: Options): Plugin;
import { Plugin } from 'vite';
type Tag = {
src: string;
type?: 'include' | 'remove';
onError?: 'continue' | 'abort';
};
type NodeEsiOptions = {
onError: (src: string, err: Error) => string;
allowedHosts: string[];
baseUrl: string;
};
type EsiOptions = {
[name: string]: Tag[];
};
type Options = {
esiOptions?: NodeEsiOptions;
esi: EsiOptions;
resolveESI?: boolean;
};
declare function esiPlugin(options: Options): Plugin;
export { esiPlugin as default };

@@ -1,17 +0,71 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const transform_1 = require("./transform");
function esiPlugin(options) {
var _a;
const shouldResolveESI = (_a = options.resolveESI) !== null && _a !== void 0 ? _a : true;
return {
name: 'vite-plugin-esi',
transformIndexHtml(inputHtml) {
const html = (0, transform_1.transformHtml)(inputHtml, options.esi);
if (shouldResolveESI) {
return (0, transform_1.resolveESI)(html);
}
},
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// src/transform.ts
import ESI from "nodesi";
// src/errors.ts
var TagsNotFoundError = class extends Error {
constructor(message) {
super(message);
this.name = "TagsNotFoundError";
}
};
// src/transform.ts
function transformHtml(html, options) {
const regex = new RegExp('<!--*\\s*vite-plugin-esi\\s(name="(?<name>[a-zA-Z0-9]+)").*->', "g");
return html.replace(regex, (_match, _, __, ___, ____, groups) => {
const tags = options[groups.name];
if (!tags) {
throw new TagsNotFoundError(`no tags found for ${groups.name}`);
}
return tags.map((tag) => {
const { src, type = "include", onError = "abort" } = tag;
return `<esi:${type} src="${src}" onerror="${onError}" />`;
}).join("\n");
});
}
exports.default = esiPlugin;
function resolveESI(html, options) {
return __async(this, null, function* () {
const esi = new ESI(options);
const resolvedHtml = yield esi.process(html);
return resolvedHtml;
});
}
// src/index.ts
function esiPlugin(options) {
var _a;
const shouldResolveESI = (_a = options.resolveESI) != null ? _a : true;
return {
name: "vite-plugin-esi",
transformIndexHtml(inputHtml) {
const html = transformHtml(inputHtml, options.esi);
if (shouldResolveESI) {
return resolveESI(html);
}
}
};
}
export {
esiPlugin as default
};
+1
-1
{
"name": "vite-plugin-esi",
"version": "1.2.3",
"version": "1.2.4",
"description": "",

@@ -5,0 +5,0 @@ "type": "module",

export declare class TagsNotFoundError extends Error {
constructor(message: string);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TagsNotFoundError = void 0;
class TagsNotFoundError extends Error {
constructor(message) {
super(message);
this.name = 'TagsNotFoundError';
}
}
exports.TagsNotFoundError = TagsNotFoundError;
/// <reference path="../src/nodesi.d.ts" />
import { type NodeEsiOptions } from 'nodesi';
import type { EsiOptions } from './types';
export declare function transformHtml(html: string, options: EsiOptions): string;
export declare function resolveESI(html: string, options?: NodeEsiOptions): Promise<string>;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveESI = exports.transformHtml = void 0;
const nodesi_1 = __importDefault(require("nodesi"));
const errors_1 = require("./errors");
// Will transform the html by replacing the special comments with the esi tags
function transformHtml(html, options) {
const regex = /<!--*\s*vite-plugin-esi\s(name="(?<name>[a-zA-Z0-9]+)").*->/g; // example <!-- vite-plugin-esi name="header" -->
return html.replace(regex, (_match, _, __, ___, ____, groups) => {
const tags = options[groups.name];
if (!tags) {
throw new errors_1.TagsNotFoundError(`no tags found for ${groups.name}`);
}
return tags
.map((tag) => {
const { src, type = 'include', onError = 'abort' } = tag;
return `<esi:${type} src="${src}" onerror="${onError}" />`;
})
.join('\n');
});
}
exports.transformHtml = transformHtml;
function resolveESI(html, options) {
return __awaiter(this, void 0, void 0, function* () {
const esi = new nodesi_1.default(options);
const resolvedHtml = yield esi.process(html);
return resolvedHtml;
});
}
exports.resolveESI = resolveESI;
export type Tag = {
src: string;
type?: 'include' | 'remove';
onError?: 'continue' | 'abort';
};
export type NodeEsiOptions = {
onError: (src: string, err: Error) => string;
allowedHosts: string[];
baseUrl: string;
};
export type EsiOptions = {
[name: string]: Tag[];
};
export type Options = {
esiOptions?: NodeEsiOptions;
esi: EsiOptions;
resolveESI?: boolean;
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });