@11ty/eleventy
Advanced tools
Comparing version 3.0.0-alpha.9 to 3.0.0-alpha.10
{ | ||
"name": "@11ty/eleventy", | ||
"version": "3.0.0-alpha.9", | ||
"version": "3.0.0-alpha.10", | ||
"description": "A simpler static site generator.", | ||
@@ -79,3 +79,3 @@ "publishConfig": { | ||
"@iarna/toml": "^2.2.5", | ||
"@vue/server-renderer": "^3.4.21", | ||
"@vue/server-renderer": "^3.4.26", | ||
"@zachleat/noop": "^1.0.3", | ||
@@ -91,10 +91,10 @@ "ava": "^6.1.2", | ||
"markdown-it-emoji": "^3.0.0", | ||
"marked": "^12.0.1", | ||
"marked": "^12.0.2", | ||
"prettier": "^3.2.5", | ||
"pretty": "^2.0.0", | ||
"rimraf": "^5.0.5", | ||
"sass": "^1.74.1", | ||
"vue": "^3.4.21", | ||
"zod": "^3.22.4", | ||
"zod-validation-error": "^3.1.0" | ||
"sass": "^1.76.0", | ||
"vue": "^3.4.26", | ||
"zod": "^3.23.5", | ||
"zod-validation-error": "^3.2.0" | ||
}, | ||
@@ -105,2 +105,3 @@ "dependencies": { | ||
"@11ty/eleventy-dev-server": "^2.0.0", | ||
"@11ty/eleventy-plugin-bundle": "^2.0.2", | ||
"@11ty/eleventy-utils": "^1.0.2", | ||
@@ -121,3 +122,3 @@ "@11ty/lodash-custom": "^4.17.21", | ||
"kleur": "^4.1.5", | ||
"liquidjs": "^10.11.1", | ||
"liquidjs": "^10.12.0", | ||
"luxon": "^3.4.4", | ||
@@ -124,0 +125,0 @@ "markdown-it": "^14.1.0", |
@@ -0,1 +1,3 @@ | ||
import bundlePlugin from "@11ty/eleventy-plugin-bundle"; | ||
import urlFilter from "./Filters/Url.js"; | ||
@@ -58,2 +60,7 @@ import slugFilter from "./Filters/Slug.js"; | ||
config.addPlugin(bundlePlugin, { | ||
bundles: false, // no default bundles included—must be opt-in. | ||
immediate: true, | ||
}); | ||
config.addFilter("slug", slugFilter); | ||
@@ -60,0 +67,0 @@ config.addFilter("slugify", slugifyFilter); |
import { performance } from "node:perf_hooks"; | ||
import { TemplatePath } from "@11ty/eleventy-utils"; | ||
import BundlePlugin from "@11ty/eleventy-plugin-bundle"; | ||
import debugUtil from "debug"; | ||
@@ -30,2 +31,3 @@ | ||
import ProjectTemplateFormats from "./Util/ProjectTemplateFormats.js"; | ||
import EventBusUtil from "./Util/EventBusUtil.js"; | ||
@@ -53,6 +55,6 @@ const pkg = getEleventyPackageJson(); | ||
/** @member {String} - Holds the path to the input (might be a file or folder) */ | ||
this.rawInput = input; | ||
this.rawInput = input || undefined; | ||
/** @member {String} - Holds the path to the output directory */ | ||
this.rawOutput = output; | ||
this.rawOutput = output || undefined; | ||
@@ -764,2 +766,4 @@ /** @member {module:11ty/eleventy/TemplateConfig} - Override the config instance (for centralized config re-use) */ | ||
} | ||
EventBusUtil.resetForConfig(); | ||
} | ||
@@ -785,3 +789,5 @@ | ||
// Note: this is a sync event! | ||
// Note: these are sync events! | ||
// `templateModified` is an alias for resourceModified but all listeners for this are cleared out when the config is reset. | ||
eventBus.emit("eleventy.templateModified", changedFilePath, usedByDependants); | ||
eventBus.emit("eleventy.resourceModified", changedFilePath, usedByDependants, { | ||
@@ -1330,3 +1336,3 @@ viaConfigReset: isResetConfig, | ||
*/ | ||
RenderPlugin as EleventyRenderPlugin, | ||
RenderPlugin as EleventyRenderPlugin, // legacy name | ||
/** | ||
@@ -1340,3 +1346,3 @@ * @type {module:11ty/eleventy/Plugins/RenderPlugin} | ||
*/ | ||
I18nPlugin as EleventyI18nPlugin, | ||
I18nPlugin as EleventyI18nPlugin, // legacy name | ||
/** | ||
@@ -1350,3 +1356,3 @@ * @type {module:11ty/eleventy/Plugins/I18nPlugin} | ||
*/ | ||
HtmlBasePlugin as EleventyHtmlBasePlugin, | ||
HtmlBasePlugin as EleventyHtmlBasePlugin, // legacy name | ||
/** | ||
@@ -1361,2 +1367,7 @@ * @type {module:11ty/eleventy/Plugins/HtmlBasePlugin} | ||
InputPathToUrlTransformPlugin, | ||
/** | ||
* @type {module:11ty/eleventy-plugin-bundle} | ||
*/ | ||
BundlePlugin, | ||
}; |
@@ -281,4 +281,8 @@ import fs from "node:fs"; | ||
// ignore output dir unless that would exclude all input | ||
if (!TemplatePath.startsWithSubPath(this.inputDir, this.outputDir)) { | ||
// ignore output dir (unless this excludes all input) | ||
// input: . and output: . (skip) | ||
// input: ./content and output . (skip) | ||
// input: . and output: ./_site (add) | ||
if (!this.inputDir.startsWith(this.outputDir)) { | ||
// both are already normalized in 3.0 | ||
files.add(TemplateGlob.map(this.outputDir + "/**")); | ||
@@ -285,0 +289,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { TemplatePath } from "@11ty/eleventy-utils"; | ||
import { TemplatePath, isPlainObject } from "@11ty/eleventy-utils"; | ||
@@ -15,9 +15,8 @@ import TemplateEngine from "./TemplateEngine.js"; | ||
constructor(name, eleventyConfig) { | ||
super(name, eleventyConfig); | ||
constructor(name, templateConfig) { | ||
super(name, templateConfig); | ||
this.instances = {}; | ||
this.cacheable = false; | ||
EventBusUtil.soloOn("eleventy.resourceModified", (inputPath, usedByDependants = []) => { | ||
EventBusUtil.soloOn("eleventy.templateModified", (inputPath, usedByDependants = []) => { | ||
// Remove from cached instances when modified | ||
@@ -131,2 +130,41 @@ let instancesToDelete = [TemplatePath.addLeadingDotSlash(inputPath), ...usedByDependants]; | ||
addExportsToBundles(inst, url) { | ||
let cfg = this.eleventyConfig.userConfig; | ||
if (!("getBundleManagers" in cfg)) { | ||
return; | ||
} | ||
let managers = cfg.getBundleManagers(); | ||
for (let name in managers) { | ||
let mgr = managers[name]; | ||
let key = mgr.getBundleExportKey(); | ||
if (!key) { | ||
continue; | ||
} | ||
if (typeof inst[key] === "string") { | ||
// export const css = ``; | ||
mgr.addToPage(url, inst[key]); | ||
} else if (isPlainObject(inst[key])) { | ||
if (typeof inst[key][name] === "string") { | ||
// Object with bundle names: | ||
// export const bundle = { | ||
// css: `` | ||
// }; | ||
mgr.addToPage(url, inst[key][name]); | ||
} else if (isPlainObject(inst[key][name])) { | ||
// Object with bucket names: | ||
// export const bundle = { | ||
// css: { | ||
// default: `` | ||
// } | ||
// }; | ||
for (let bucketName in inst[key][name]) { | ||
mgr.addToPage(url, inst[key][name][bucketName], bucketName); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
async compile(str, inputPath) { | ||
@@ -147,2 +185,7 @@ let inst; | ||
// Map exports to bundles | ||
if (data.page?.url) { | ||
this.addExportsToBundles(inst, data.page.url); | ||
} | ||
for (let key of JavaScript.DATA_KEYS_TO_BIND) { | ||
@@ -149,0 +192,0 @@ if (!inst[key] && data[key]) { |
@@ -69,3 +69,3 @@ import NunjucksLib from "nunjucks"; | ||
// resolution from paths isn't straightforward. | ||
EventBusUtil.soloOn("eleventy.resourceModified", (/*path*/) => { | ||
EventBusUtil.soloOn("eleventy.templateModified", (/*path*/) => { | ||
this.njkEnv.invalidateCache(); | ||
@@ -72,0 +72,0 @@ }); |
@@ -0,4 +1,7 @@ | ||
import debugUtil from "debug"; | ||
import EleventyBaseError from "../Errors/EleventyBaseError.js"; | ||
import { EleventyImportFromEleventy } from "../Util/Require.js"; | ||
const debug = debugUtil("Eleventy:TemplateEngineManager"); | ||
class TemplateEngineManagerConfigError extends EleventyBaseError {} | ||
@@ -14,2 +17,3 @@ | ||
this.engineCache = {}; | ||
this.importCache = {}; | ||
} | ||
@@ -83,16 +87,26 @@ | ||
async getEngineClassByExtension(extension) { | ||
if (this.importCache[extension]) { | ||
return this.importCache[extension]; | ||
} | ||
let promise; | ||
// We include these as raw strings (and not more readable variables) so they’re parsed by a bundler. | ||
if (extension === "md") { | ||
return EleventyImportFromEleventy("./src/Engines/Markdown.js"); | ||
promise = EleventyImportFromEleventy("./src/Engines/Markdown.js"); | ||
} else if (extension === "html") { | ||
return EleventyImportFromEleventy("./src/Engines/Html.js"); | ||
promise = EleventyImportFromEleventy("./src/Engines/Html.js"); | ||
} else if (extension === "njk") { | ||
return EleventyImportFromEleventy("./src/Engines/Nunjucks.js"); | ||
promise = EleventyImportFromEleventy("./src/Engines/Nunjucks.js"); | ||
} else if (extension === "liquid") { | ||
return EleventyImportFromEleventy("./src/Engines/Liquid.js"); | ||
promise = EleventyImportFromEleventy("./src/Engines/Liquid.js"); | ||
} else if (extension === "11ty.js") { | ||
return EleventyImportFromEleventy("./src/Engines/JavaScript.js"); | ||
promise = EleventyImportFromEleventy("./src/Engines/JavaScript.js"); | ||
} else { | ||
return this.getCustomEngineClass(); | ||
promise = this.getCustomEngineClass(); | ||
} | ||
this.importCache[extension] = promise; | ||
return promise; | ||
} | ||
@@ -122,31 +136,34 @@ | ||
// "Double override (not aliases) throws an error" test in TemplateRenderCustomTest.js | ||
if (this.engineCache[name]) { | ||
return this.engineCache[name]; | ||
} | ||
if (!this.engineCache[name]) { | ||
debug("Engine cache miss %o (should only happen once per type)", name); | ||
let cls = await this.getEngineClassByExtension(name); | ||
let instance = new cls(name, this.eleventyConfig); | ||
instance.extensionMap = extensionMap; | ||
instance.engineManager = this; | ||
// Make sure cache key is based on name and not path | ||
// Custom class is used for all plugins, cache once per plugin | ||
this.engineCache[name] = new Promise(async (resolve) => { | ||
let cls = await this.getEngineClassByExtension(name); | ||
let instance = new cls(name, this.eleventyConfig); | ||
instance.extensionMap = extensionMap; | ||
instance.engineManager = this; | ||
// If provided a "Custom" engine using addExtension, | ||
// But that engine's instance is *not* custom, | ||
// The user must be overriding an existing engine | ||
// i.e. addExtension('md', { ...overrideBehavior }) | ||
if ( | ||
this.getClassNameFromTemplateKey(name) === "Custom" && | ||
instance.constructor.name !== "CustomEngine" | ||
) { | ||
let CustomEngine = await this.getCustomEngineClass(); | ||
let overrideCustomEngine = new CustomEngine(name, this.eleventyConfig); | ||
// Keep track of the "default" engine 11ty would normally use | ||
// This allows the user to access the default engine in their override | ||
overrideCustomEngine.setDefaultEngine(instance); | ||
instance = overrideCustomEngine; | ||
// If provided a "Custom" engine using addExtension, | ||
// But that engine's instance is *not* custom, | ||
// The user must be overriding an existing engine | ||
// i.e. addExtension('md', { ...overrideBehavior }) | ||
if ( | ||
this.getClassNameFromTemplateKey(name) === "Custom" && | ||
instance.constructor.name !== "CustomEngine" | ||
) { | ||
let CustomEngine = await this.getCustomEngineClass(); | ||
let overrideCustomEngine = new CustomEngine(name, this.eleventyConfig); | ||
// Keep track of the "default" engine 11ty would normally use | ||
// This allows the user to access the default engine in their override | ||
overrideCustomEngine.setDefaultEngine(instance); | ||
instance = overrideCustomEngine; | ||
} | ||
resolve(instance); | ||
}); | ||
} | ||
// Make sure cache key is based on name and not path | ||
// Custom class is used for all plugins, cache once per plugin | ||
this.engineCache[name] = instance; | ||
return instance; | ||
return this.engineCache[name]; | ||
} | ||
@@ -153,0 +170,0 @@ } |
@@ -21,2 +21,4 @@ import debugUtil from "debug"; | ||
debug("EventBus max listener count: %o", bus.getMaxListeners()); | ||
export default bus; |
import eventBus from "../EventBus.js"; | ||
import debugUtil from "debug"; | ||
const debug = debugUtil("Eleventy:EventBus"); | ||
class EventBusUtil { | ||
@@ -9,4 +12,16 @@ // Used for non-global subscriptions that will blow away the previous listener | ||
} | ||
static resetForConfig() { | ||
this.debug(); | ||
debug("Config reset (removing eleventy.templateModified listeners)."); | ||
eventBus.removeAllListeners("eleventy.templateModified"); | ||
} | ||
static debug() { | ||
for (let name of eventBus.eventNames()) { | ||
debug("Listeners for %o: %o", name, eventBus.listenerCount(name)); | ||
} | ||
} | ||
} | ||
export default EventBusUtil; |
@@ -28,3 +28,3 @@ import debugUtil from "debug"; | ||
if (Array.isArray(formats)) { | ||
return formats.map((entry) => entry.trim()); | ||
formats = "" + formats.join(","); | ||
} | ||
@@ -31,0 +31,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
446511
13534
34
+ Added@11ty/eleventy-plugin-bundle@2.0.2(transitive)
Updatedliquidjs@^10.12.0