Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@11ty/eleventy-dev-server

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@11ty/eleventy-dev-server - npm Package Compare versions

Comparing version 1.0.0-canary.1 to 1.0.0-canary.2

27

client/reload-client.js

@@ -27,2 +27,23 @@ class Util {

}
static matchRootAttributes(htmlContent) {
// Workaround for morphdom bug with attributes on <html> https://github.com/11ty/eleventy-dev-server/issues/6
// Note also `childrenOnly: true` above
const parser = new DOMParser();
let parsed = parser.parseFromString(htmlContent, "text/html");
let parsedDoc = parsed.documentElement;
let newAttrs = parsedDoc.getAttributeNames();
let docEl = document.documentElement;
// Remove old
let removedAttrs = docEl.getAttributeNames().filter(name => !newAttrs.includes(name));
for(let attr of removedAttrs) {
docEl.removeAttribute(attr);
}
// Add new
for(let attr of newAttrs) {
docEl.setAttribute(attr, parsedDoc.getAttribute(attr));
}
}
}

@@ -61,3 +82,5 @@

morphed = true;
morphdom(document.documentElement, template.content, {
childrenOnly: true,
// Speed-up trick from morphdom docs

@@ -72,3 +95,5 @@ onBeforeElUpdated: function (fromEl, toEl) {

});
Util.matchRootAttributes(template.content);
Util.log(`HTML delta applied without page reload.`);

@@ -75,0 +100,0 @@ }

2

package.json
{
"name": "@11ty/eleventy-dev-server",
"version": "1.0.0-canary.1",
"version": "1.0.0-canary.2",
"description": "A minimal, modern, generic, hot-reloading local web server to help web developers.",

@@ -5,0 +5,0 @@ "main": "server.js",

@@ -19,2 +19,6 @@ <p align="center"><img src="https://www.11ty.dev/img/logo-github.png" alt="eleventy Logo"></p>

This is bundled with @11ty/eleventy starting with Eleventy v2.0.0.
That said, you can use it standalone! A CLI is also rumored, if you pester the author about it enough.
```

@@ -21,0 +25,0 @@ npm install @11ty/eleventy-dev-server

@@ -10,3 +10,3 @@ const path = require("path");

const debug = require("debug")("EleventyServeAdapter");
const debug = require("debug")("EleventyDevServer");

@@ -33,8 +33,9 @@ const wrapResponse = require("./server/wrapResponse.js");

class EleventyServeAdapter {
class EleventyDevServer {
static getServer(...args) {
let [name] = args;
// TODO what if previously cached server has new/different dir or options
if (!serverCache[name]) {
serverCache[name] = new EleventyServeAdapter(...args);
serverCache[name] = new EleventyDevServer(...args);
}

@@ -49,3 +50,2 @@

this.fileCache = {};
// Directory to serve

@@ -63,7 +63,7 @@ if(!dir) {

// avoid trailing slash for filepath/.html requests
let entry = path.join(this.dir, filepath);
if(entry.endsWith(path.sep)) {
entry = entry.substring(0, entry.length - path.sep.length);
let prefix = path.join(this.dir, filepath);
if(prefix.endsWith(path.sep)) {
prefix = prefix.substring(0, prefix.length - path.sep.length);
}
computedPath = entry + filename;
computedPath = prefix + filename;
} else {

@@ -164,3 +164,3 @@ computedPath = path.join(this.dir, filepath, filename);

_getFileContents(localpath, useCache = true) {
_getFileContents(localpath, rootDir, useCache = true) {
if(this.fileCache[localpath]) {

@@ -171,5 +171,14 @@ return this.fileCache[localpath];

let filepath = TemplatePath.absolutePath(
__dirname,
rootDir || __dirname,
localpath
);
// fallback for file:../ installations
if(rootDir && !fs.existsSync(filepath)) {
filepath = TemplatePath.absolutePath(
__dirname,
localpath
);
}
let contents = fs.readFileSync(filepath, {

@@ -246,3 +255,3 @@ encoding: "utf8",

res.setHeader("Content-Type", mime.getType("js"));
return res.end(this._getFileContents("./node_modules/morphdom/dist/morphdom-esm.js"));
return res.end(this._getFileContents("./node_modules/morphdom/dist/morphdom-esm.js", path.resolve(".")));
}

@@ -298,2 +307,3 @@

}
return content;

@@ -303,15 +313,23 @@ });

let middlewares = this.options.middleware || [];
if(middlewares.length) {
let nexts = [];
// Iterate over those middlewares
middlewares.forEach((ware, index) => {
let nextWare = middlewares[index + 1] || this.requestMiddleware.bind(this, req, res);
nexts.push(ware.bind(null, req, res, nextWare));
});
for(let ware of nexts) {
await ware();
middlewares = middlewares.slice();
middlewares.push(this.requestMiddleware);
middlewares.reverse();
let bound = [];
let next;
for(let ware of middlewares) {
let fn;
if(next) {
fn = ware.bind(this, req, res, next);
} else {
fn = ware.bind(this, req, res);
}
} else {
this.requestMiddleware(req, res)
bound.push(fn);
next = fn;
}
bound.reverse();
let [first] = bound;
await first();
}

@@ -391,2 +409,11 @@

async getPort() {
return new Promise(resolve => {
this.server.on("listening", (e) => {
let { port } = this._server.address();
resolve(port);
});
})
}
serve(port) {

@@ -474,2 +501,2 @@ this._serverListen(port);

module.exports = EleventyServeAdapter;
module.exports = EleventyDevServer;

@@ -95,4 +95,2 @@ function getContentType(headers) {

}
return this;
}

@@ -99,0 +97,0 @@

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