Socket
Socket
Sign inDemoInstall

@11ty/eleventy

Package Overview
Dependencies
Maintainers
1
Versions
187
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@11ty/eleventy - npm Package Compare versions

Comparing version 3.0.0-alpha.3 to 3.0.0-alpha.4

src/Util/ExistsCache.js

12

package.json
{
"name": "@11ty/eleventy",
"version": "3.0.0-alpha.3",
"version": "3.0.0-alpha.4",
"description": "A simpler static site generator.",

@@ -82,3 +82,3 @@ "publishConfig": {

"@iarna/toml": "^2.2.5",
"@vue/server-renderer": "^3.3.12",
"@vue/server-renderer": "^3.4.3",
"@zachleat/noop": "^1.0.3",

@@ -94,8 +94,8 @@ "ava": "^6.0.1",

"markdown-it-emoji": "^3.0.0",
"marked": "^11.1.0",
"marked": "^11.1.1",
"prettier": "^3.1.1",
"pretty": "^2.0.0",
"rimraf": "^5.0.5",
"sass": "^1.69.5",
"vue": "^3.3.12"
"sass": "^1.69.7",
"vue": "^3.4.3"
},

@@ -120,3 +120,3 @@ "dependencies": {

"kleur": "^4.1.5",
"liquidjs": "^10.9.4",
"liquidjs": "^10.10.0",
"luxon": "^3.4.4",

@@ -123,0 +123,0 @@ "markdown-it": "^14.0.0",

@@ -114,5 +114,4 @@ import debugUtil from "debug";

if (
totalForBenchmark.toFixed(0) > 1 || // more than 1ms
callCount > 2 || // more than 2×
percent > 1 // more than 1%
callCount > 1 || // called more than once
totalForBenchmark.toFixed(0) > 0 // more than 0ms
) {

@@ -119,0 +118,0 @@ debugBenchmark(str);

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

import { fileURLToPath } from "node:url";
import { DepGraph } from "dependency-graph";
import { TemplatePath } from "@11ty/eleventy-utils";
import debugUtil from "debug";

@@ -94,7 +91,2 @@

// Fix file:///Users/ or file:///C:/ paths passed in
if (node.startsWith("file://")) {
node = fileURLToPath(node);
}
if (typeof node !== "string") {

@@ -104,8 +96,3 @@ throw new Error("`addDependencies` files must be strings. Received:" + node);

// Paths should not be absolute (we convert absolute paths to relative)
// Paths should not have a leading dot slash
// Paths should always be `/` independent of OS path separator
return TemplatePath.stripLeadingDotSlash(
PathNormalizer.normalizeSeperator(TemplatePath.relativePath(node)),
);
return PathNormalizer.fullNormalization(node);
}

@@ -112,0 +99,0 @@

@@ -70,33 +70,2 @@ import { bcp47Normalize } from "bcp-47-normalize";

}
// Search for same input path files with only differing locale folders
// matches /en/about.html and /es/about.html
// Folders can exist anywhere in the hierarchy!
// matches /testing/en/about.html and /testing/es/about.html
// Returns an array of the first matched language codes in the path
// [inputPathLangCode, inputPath2LangCode]
static matchLanguageFolder(inputPath, inputPath2) {
if (inputPath === inputPath2) {
return false;
}
let langCodes = [];
let s1 = inputPath.split("/");
let s2 = inputPath2.split("/");
for (let j = 0, k = s1.length; j < k; j++) {
if (Comparator.isLangCode(s1[j]) && Comparator.isLangCode(s2[j])) {
// Return the first match only
if (langCodes.length === 0) {
langCodes = [s1[j], s2[j]];
}
continue;
}
if (s1[j] !== s2[j]) {
return false;
}
}
return langCodes;
}
}

@@ -209,4 +178,2 @@

let benchmarkManager = eleventyConfig.benchmarkManager.get("Aggregate");
let extensionMap;

@@ -217,6 +184,7 @@ eleventyConfig.on("eleventy.extensionmap", (map) => {

let bench = eleventyConfig.benchmarkManager.get("Aggregate");
let contentMaps = {};
eleventyConfig.on("eleventy.contentMap", function ({ urlToInputPath, inputPathToUrl }) {
let bench = benchmarkManager.get("(i18n Plugin) Setting up content map.");
bench.before();
let b = bench.get("(i18n Plugin) Setting up content map.");
b.before();
contentMaps.inputPathToUrl = inputPathToUrl;

@@ -226,3 +194,3 @@ contentMaps.urlToInputPath = urlToInputPath;

contentMaps.localeUrlsMap = getLocaleUrlsMap(urlToInputPath, extensionMap, options);
bench.after();
b.after();
});

@@ -229,0 +197,0 @@

@@ -336,3 +336,6 @@ import { isPlainObject } from "@11ty/eleventy-utils";

// Do *not* deep merge pagination data! See https://github.com/11ty/eleventy/issues/147#issuecomment-440802454
let clonedData = ProxyWrap(paginationData, parentData);
let clonedData = ProxyWrap(paginationData, parentData, {
benchmarkManager: this.config.benchmarkManager,
});
// Previous method:

@@ -339,0 +342,0 @@ // let clonedData = DeepCopy(paginationData, parentData);

@@ -29,3 +29,2 @@ import util from "node:util";

const writeFile = util.promisify(fs.writeFile);
const mkdir = util.promisify(fs.mkdir);
const fsStat = util.promisify(fs.stat);

@@ -82,2 +81,6 @@

get existsCache() {
return this.eleventyConfig.existsCache;
}
get logger() {

@@ -729,10 +732,12 @@ if (!this._logger) {

let templateBenchmark = this.bench.get("Template Write");
templateBenchmark.before();
let templateBenchmarkDir = this.bench.get("Template make parent directory");
templateBenchmarkDir.before();
// TODO(@zachleat) add a cache to check if this was already created
let templateOutputDir = path.parse(outputPath).dir;
if (templateOutputDir) {
await mkdir(templateOutputDir, { recursive: true });
if (!this.existsCache.exists(templateOutputDir)) {
fs.mkdirSync(templateOutputDir, { recursive: true });
}
}
templateBenchmarkDir.after();

@@ -745,2 +750,5 @@ if (!Buffer.isBuffer(finalContent) && typeof finalContent !== "string") {

let templateBenchmark = this.bench.get("Template Write");
templateBenchmark.before();
await writeFile(outputPath, finalContent);

@@ -747,0 +755,0 @@

@@ -10,2 +10,3 @@ import fs from "node:fs";

import GlobalDependencyMap from "./GlobalDependencyMap.js";
import ExistsCache from "./Util/ExistsCache.js";
import merge from "./Util/Merge.js";

@@ -393,3 +394,7 @@ import unique from "./Util/Unique.js";

let benchmarkManager = this.userConfig.benchmarkManager.get("Aggregate");
let pluginsBench = benchmarkManager.get("Processing plugins in config");
pluginsBench.before();
await this.processPlugins(mergedConfig);
pluginsBench.after();

@@ -449,4 +454,12 @@ delete mergedConfig.templateFormats;

}
get existsCache() {
if (!this._existsCache) {
this._existsCache = new ExistsCache();
this._existsCache.setDirectoryCheck(true);
}
return this._existsCache;
}
}
export default TemplateConfig;

@@ -17,4 +17,3 @@ import util from "node:util";

const fsExists = util.promisify(fs.exists);
const fsStat = util.promisify(fs.stat);
const fsStatAsync = util.promisify(fs.stat);
const { set: lodashSet, get: lodashGet } = lodash;

@@ -25,22 +24,2 @@ const debugWarn = debugUtil("Eleventy:Warnings");

class FSExistsCache {
constructor() {
this._cache = new Map();
}
has(path) {
return this._cache.has(path);
}
async exists(path) {
let exists = this._cache.get(path);
if (!this.has(path)) {
exists = await fsExists(path);
this._cache.set(path, exists);
}
return exists;
}
markExists(path, value = true) {
this._cache.set(path, !!value);
}
}
class TemplateDataConfigError extends EleventyBaseError {}

@@ -69,7 +48,9 @@ class TemplateDataParseError extends EleventyBaseError {}

this.initialGlobalData = new TemplateDataInitialGlobalData(this.eleventyConfig);
}
get _fsExistsCache() {
// It's common for data files not to exist, so we avoid going to the FS to
// re-check if they do via a quick-and-dirty cache.
this._fsExistsCache = new FSExistsCache();
this.initialGlobalData = new TemplateDataInitialGlobalData(this.eleventyConfig);
return this.eleventyConfig.existsCache;
}

@@ -153,3 +134,3 @@

if (this.inputDirNeedsCheck) {
let globalPathStat = await fsStat(this.inputDir);
let globalPathStat = await fsStatAsync(this.inputDir);

@@ -406,8 +387,8 @@ if (!globalPathStat.isDirectory()) {

const dataPaths = await Promise.all(
localDataPaths.map((path) =>
this._fsExistsCache.exists(path).then((exists) => {
if (exists) return path;
return false;
}),
),
localDataPaths.map((path) => {
if (this._fsExistsCache.exists(path)) {
return path;
}
return false;
}),
);

@@ -519,3 +500,3 @@

let localPath = TemplatePath.absolutePath(path);
let exists = await this._fsExistsCache.exists(localPath);
let exists = this._fsExistsCache.exists(localPath);
// Make sure that relative lookups benefit from cache

@@ -522,0 +503,0 @@ this._fsExistsCache.markExists(path, exists);

import path from "node:path";
import { fileURLToPath } from "node:url";
import { TemplatePath } from "@11ty/eleventy-utils";
class PathNormalizer {
static getParts(inputPath) {
if (!inputPath) {
return [];
}
let separator = "/";
if (inputPath.includes(path.sep)) {
separator = path.sep;
}
return inputPath.split(separator).filter((entry) => entry !== ".");
}
// order is important here: the top-most directory returns first
// array of file and all parent directories
static getAllPaths(inputPath) {
let parts = this.getParts(inputPath);
let allPaths = [];
let fullpath = "";
for (let part of parts) {
fullpath += (fullpath.length > 0 ? "/" : "") + part;
allPaths.push(fullpath);
}
return allPaths;
}
static normalizeSeperator(inputPath) {

@@ -10,4 +40,22 @@ if (!inputPath) {

}
static fullNormalization(inputPath) {
if (typeof inputPath !== "string") {
return inputPath;
}
// Fix file:///Users/ or file:///C:/ paths passed in
if (inputPath.startsWith("file://")) {
inputPath = fileURLToPath(inputPath);
}
// Paths should not be absolute (we convert absolute paths to relative)
// Paths should not have a leading dot slash
// Paths should always be `/` independent of OS path separator
return TemplatePath.stripLeadingDotSlash(
this.normalizeSeperator(TemplatePath.relativePath(inputPath)),
);
}
}
export default PathNormalizer;

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

import types from "node:util/types";
import debugUtil from "debug";

@@ -9,16 +10,13 @@ import { isPlainObject } from "@11ty/eleventy-utils";

getOwnPropertyDescriptor(target, prop) {
let ret;
if (Reflect.has(target, prop)) {
return Reflect.getOwnPropertyDescriptor(target, prop);
ret = Reflect.getOwnPropertyDescriptor(target, prop);
} else if (Reflect.has(fallback, prop)) {
ret = Reflect.getOwnPropertyDescriptor(fallback, prop);
}
// assume fallback is frozen
return {
value: undefined,
writable: true,
enumerable: true,
configurable: true,
};
return ret;
},
has(target, prop) {
// debug( "handler:has", prop, Reflect.has(target, prop), Reflect.has(fallback, prop));
if (Reflect.has(target, prop)) {

@@ -46,11 +44,16 @@ return true;

let value = Reflect.get(target, prop);
if (Reflect.has(target, prop)) {
// debug( "handler:get", prop, { isProxy: util.types.isProxy(value), hasFallback: Reflect.has(fallback, prop) } );
// Already proxied
if (types.isProxy(value)) {
return value;
}
if (isPlainObject(value) && Reflect.has(fallback, prop)) {
let ret = wrapObject(value, Reflect.get(fallback, prop));
debug(" handler:get (object)", prop, "found on primary ****", ret);
debug("handler:get (primary, object)", prop);
return ret;
}
debug(" handler:get (not object)", prop, "found on primary ****");
debug("handler:get (primary)", prop);
return value;

@@ -65,10 +68,11 @@ }

if (isPlainObject(fallbackValue)) {
debug(" > proxying (fallback has prop)", { fallback, prop, fallbackValue });
debug("handler:get (fallback, object)", prop);
// set empty object on primary
Reflect.set(target, prop, {});
let emptyObject = {};
Reflect.set(target, prop, emptyObject);
return wrapObject(Reflect.get(target, prop), fallbackValue);
return wrapObject(emptyObject, fallbackValue);
}
debug(" > returning (fallback has prop, not object)", { prop, fallbackValue });
debug("handler:get (fallback)", prop);
return fallbackValue;

@@ -78,7 +82,9 @@ }

// primary *and* fallback do _not_ have prop
debug(" > returning (primary and fallback missing prop)", { prop, value });
debug("handler:get (not on primary or fallback)", prop);
return value;
},
set(target, prop, value) {
debug("handler:set", { target, prop, value });
debug("handler:set", prop);
return Reflect.set(target, prop, value);

@@ -89,10 +95,10 @@ },

function ProxyWrap(target, fallback) {
function ProxyWrap(target, fallback, options) {
if (!isPlainObject(target) || !isPlainObject(fallback)) {
throw new Error("ProxyWrap expects objects for both the target and fallback");
}
let wrapped = wrapObject(target, fallback);
return wrapped;
return wrapObject(target, fallback, options);
}
export { ProxyWrap };
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