@11ty/eleventy
Advanced tools
Comparing version 2.0.0-canary.33 to 2.0.0-canary.34
@@ -66,2 +66,3 @@ #!/usr/bin/env node | ||
pathPrefix: argv.pathprefix, | ||
runMode: argv.serve ? "serve" : argv.watch ? "watch" : "build", | ||
}); | ||
@@ -82,8 +83,2 @@ | ||
if (argv.serve) { | ||
elev.setRunMode("serve"); | ||
} else if (argv.watch) { | ||
elev.setRunMode("watch"); | ||
} | ||
// careful, we can’t use async/await here to error properly | ||
@@ -90,0 +85,0 @@ // with old node versions in `please-upgrade-node` above. |
{ | ||
"name": "@11ty/eleventy", | ||
"version": "2.0.0-canary.33", | ||
"version": "2.0.0-canary.34", | ||
"description": "Transform a directory of templates into HTML.", | ||
@@ -99,3 +99,3 @@ "publishConfig": { | ||
"@11ty/dependency-tree": "^2.0.1", | ||
"@11ty/eleventy-dev-server": "^1.0.1", | ||
"@11ty/eleventy-dev-server": "^1.0.3", | ||
"@11ty/eleventy-utils": "^1.0.1", | ||
@@ -102,0 +102,0 @@ "@iarna/toml": "^2.2.5", |
@@ -20,3 +20,2 @@ const { TemplatePath } = require("@11ty/eleventy-utils"); | ||
const simplePlural = require("./Util/Pluralize"); | ||
const deleteRequireCache = require("./Util/DeleteRequireCache"); | ||
const checkPassthroughCopyBehavior = require("./Util/PassthroughCopyBehaviorCheck"); | ||
@@ -82,4 +81,2 @@ const debug = require("debug")("Eleventy"); | ||
*/ | ||
// This needs to happen before `getEnvironmentVariableValues` below. | ||
if ("isServerless" in options) { | ||
@@ -92,5 +89,12 @@ this.isServerless = !!options.isServerless; | ||
/** | ||
* @member {String} - One of build, serve, or watch | ||
* @default "build" | ||
*/ | ||
this.runMode = options.runMode || "build"; | ||
/** | ||
* @member {Object} - Initialize Eleventy environment variables | ||
* @default null | ||
*/ | ||
// both this.isServerless and this.runMode need to be set before this | ||
this.env = this.getEnvironmentVariableValues(); | ||
@@ -116,8 +120,2 @@ this.initializeEnvironmentVariables(this.env); | ||
/** | ||
* @member {String} - One of build, serve, or watch | ||
* @default "build" | ||
*/ | ||
this.runMode = "build"; | ||
/** | ||
* @member {Boolean} - Is Eleventy running in verbose mode? | ||
@@ -294,8 +292,2 @@ * @default true | ||
this.extensionMap.reset(); | ||
// reload package.json values (if applicable) | ||
// TODO only reset this if it changed | ||
deleteRequireCache("package.json"); | ||
await this.init(); | ||
} | ||
@@ -383,3 +375,5 @@ | ||
*/ | ||
async init() { | ||
async init(options = {}) { | ||
options = Object.assign({ viaConfigReset: false }, options); | ||
await this.config.events.emit("eleventy.config", this.eleventyConfig); | ||
@@ -437,4 +431,7 @@ | ||
); | ||
this._cache("TemplateWriter", this.writer); | ||
if (!options.viaConfigReset) { | ||
this._cache("TemplateWriter", this.writer); | ||
} | ||
this.writer.setInput(this.inputDir, this.input); | ||
@@ -478,2 +475,3 @@ this.writer.logger = this.logger; | ||
source: this.source, | ||
runMode: this.runMode, | ||
}; | ||
@@ -506,2 +504,3 @@ let configPath = this.eleventyConfig.getLocalProjectConfigFile(); | ||
process.env.ELEVENTY_SOURCE = env.source; | ||
process.env.ELEVENTY_RUN_MODE = env.runMode; | ||
@@ -755,4 +754,2 @@ // https://github.com/11ty/eleventy/issues/1957 | ||
let returnValue = false; | ||
for (const configFilePath of configFilePaths) { | ||
@@ -764,6 +761,3 @@ // Any dependencies of the config file changed | ||
if (this.watchManager.hasQueuedFile(dep)) { | ||
// Delete from require cache so that updates to the module are re-required | ||
deleteRequireCache(dep); | ||
returnValue = true; | ||
return true; | ||
} | ||
@@ -773,3 +767,3 @@ } | ||
return returnValue; | ||
return false; | ||
} | ||
@@ -794,4 +788,8 @@ | ||
// reset and reload global configuration :O | ||
if (this._shouldResetConfig()) { | ||
// Clear `require` cache for all files that triggered the rebuild | ||
this.watchTargets.clearRequireCacheFor(queue); | ||
// reset and reload global configuration | ||
let isResetConfig = this._shouldResetConfig(); | ||
if (isResetConfig) { | ||
this.resetConfig(); | ||
@@ -801,5 +799,4 @@ } | ||
await this.restart(); | ||
await this.init({ viaConfigReset: isResetConfig }); | ||
this.watchTargets.clearDependencyRequireCache(); | ||
let incrementalFile = this.watchManager.getIncrementalFile(); | ||
@@ -892,2 +889,3 @@ if (incrementalFile) { | ||
this.watchTargets.add(["./package.json"]); | ||
this.watchTargets.add(this.eleventyFiles.getGlobWatcherFiles()); | ||
@@ -894,0 +892,0 @@ this.watchTargets.add(this.eleventyFiles.getIgnoreFiles()); |
@@ -122,5 +122,12 @@ const { TemplatePath } = require("@11ty/eleventy-utils"); | ||
clearDependencyRequireCache() { | ||
for (let path of this.dependencies) { | ||
deleteRequireCache(path); | ||
clearRequireCacheFor(filePathArray) { | ||
for (const filePath of filePathArray) { | ||
deleteRequireCache(filePath); | ||
// Any dependencies of the config file changed | ||
let fileDeps = this.getDependenciesOf(filePath); | ||
for (let dep of fileDeps) { | ||
// Delete from require cache so that updates to the module are re-required | ||
deleteRequireCache(dep); | ||
} | ||
} | ||
@@ -127,0 +134,0 @@ } |
@@ -5,4 +5,4 @@ const { TemplatePath } = require("@11ty/eleventy-utils"); | ||
const EleventyBaseError = require("../EleventyBaseError"); | ||
const deleteRequireCache = require("../Util/DeleteRequireCache"); | ||
const getJavaScriptData = require("../Util/GetJavaScriptData"); | ||
const eventBus = require("../EventBus"); | ||
@@ -17,2 +17,11 @@ class JavaScriptTemplateNotDefined extends EleventyBaseError {} | ||
this.cacheable = false; | ||
eventBus.on("eleventy.resourceModified", (inputPath) => { | ||
inputPath = TemplatePath.addLeadingDotSlash(inputPath); | ||
// Remove from cached instances when modified | ||
if (inputPath in this.instances) { | ||
delete this.instances[inputPath]; | ||
} | ||
}); | ||
} | ||
@@ -39,6 +48,3 @@ | ||
} else if (typeof mod === "function") { | ||
if ( | ||
mod.prototype && | ||
("data" in mod.prototype || "render" in mod.prototype) | ||
) { | ||
if (mod.prototype && ("data" in mod.prototype || "render" in mod.prototype)) { | ||
if (!("render" in mod.prototype)) { | ||
@@ -64,3 +70,3 @@ mod.prototype.render = noop; | ||
const mod = this._getRequire(inputPath); | ||
const mod = require(TemplatePath.absolutePath(inputPath)); | ||
let inst = this._getInstance(mod); | ||
@@ -78,7 +84,2 @@ | ||
_getRequire(inputPath) { | ||
let requirePath = TemplatePath.absolutePath(inputPath); | ||
return require(requirePath); | ||
} | ||
/** | ||
@@ -93,11 +94,2 @@ * JavaScript files defer to the module loader rather than read the files to strings | ||
// only remove from cache once on startup (if it already exists) | ||
initRequireCache(inputPath) { | ||
deleteRequireCache(inputPath); | ||
if (inputPath in this.instances) { | ||
delete this.instances[inputPath]; | ||
} | ||
} | ||
async getExtraDataFromFile(inputPath) { | ||
@@ -146,4 +138,8 @@ let inst = this.getInstanceFromInputPath(inputPath); | ||
} | ||
if (inst && "render" in inst) { | ||
return function (data) { | ||
// TODO does this do anything meaningful for non-classes? | ||
// `inst` should have a normalized `render` function from _getInstance | ||
// only blow away existing inst.page if it has a page.url | ||
@@ -150,0 +146,0 @@ if (!inst.page || inst.page.url) { |
@@ -208,6 +208,2 @@ const fs = require("fs"); | ||
initRequireCache() { | ||
// do nothing | ||
} | ||
getCompileCacheKey(str, inputPath) { | ||
@@ -214,0 +210,0 @@ // Changing to use inputPath and contents, using only file contents (`str`) caused issues when two |
@@ -35,2 +35,3 @@ const fastglob = require("fast-glob"); | ||
options.ignore = options.ignore.map((entry) => TemplatePath.stripLeadingDotSlash(entry)); | ||
debug("Glob search (%o) ignoring: %o", key, options.ignore); | ||
} | ||
@@ -37,0 +38,0 @@ |
@@ -13,2 +13,3 @@ const fs = require("fs"); | ||
const JavaScriptDependencies = require("../Util/JavaScriptDependencies"); | ||
const deleteRequireCache = require("../Util/DeleteRequireCache"); | ||
const debug = require("debug")("Eleventy:Serverless"); | ||
@@ -171,2 +172,4 @@ | ||
return async function EleventyServerlessMiddleware(req, res, next) { | ||
deleteRequireCache(serverlessFilePath); | ||
let serverlessFunction = EleventyRequire(serverlessFilepath); | ||
@@ -173,0 +176,0 @@ let url = new URL(req.url, "http://localhost/"); // any domain will do here, we just want the searchParams |
@@ -7,4 +7,4 @@ const path = require("path"); | ||
const Eleventy = require("./Eleventy"); | ||
const { EleventyRequireAbsolute } = require("./Util/Require"); | ||
const normalizeServerlessUrl = require("./Util/NormalizeServerlessUrl"); | ||
const deleteRequireCache = require("./Util/DeleteRequireCache"); | ||
const debug = require("debug")("Eleventy:Serverless"); | ||
@@ -104,3 +104,5 @@ | ||
// TODO dedicated reset method, don’t delete this every time | ||
return EleventyRequireAbsolute(fullPath); | ||
deleteRequireCache(fullPath); | ||
return require(fullPath); | ||
} | ||
@@ -113,3 +115,5 @@ | ||
// TODO dedicated reset method, don’t delete this every time | ||
return EleventyRequireAbsolute(fullPath); | ||
deleteRequireCache(fullPath); | ||
return require(fullPath); | ||
} | ||
@@ -116,0 +120,0 @@ |
@@ -9,3 +9,2 @@ const fs = require("fs"); | ||
const unique = require("./Util/Unique"); | ||
const TemplateRender = require("./TemplateRender"); | ||
const TemplateGlob = require("./TemplateGlob"); | ||
@@ -12,0 +11,0 @@ const EleventyExtensionMap = require("./EleventyExtensionMap"); |
@@ -16,5 +16,3 @@ const { TemplatePath } = require("@11ty/eleventy-utils"); | ||
if (!tmplPath) { | ||
throw new Error( | ||
`TemplateRender requires a tmplPath argument, instead of ${tmplPath}` | ||
); | ||
throw new Error(`TemplateRender requires a tmplPath argument, instead of ${tmplPath}`); | ||
} | ||
@@ -32,6 +30,3 @@ if (!config) { | ||
this.inputDir = inputDir ? inputDir : this.config.dir.input; | ||
this.includesDir = TemplatePath.join( | ||
this.inputDir, | ||
this.config.dir.includes | ||
); | ||
this.includesDir = TemplatePath.join(this.inputDir, this.config.dir.includes); | ||
@@ -65,7 +60,3 @@ this.parseMarkdownWith = this.config.markdownTemplateEngine; | ||
getEngineByName(name) { | ||
let engine = this.extensionMap.engineManager.getEngine( | ||
name, | ||
this.getDirs(), | ||
this.extensionMap | ||
); | ||
let engine = this.extensionMap.engineManager.getEngine(name, this.getDirs(), this.extensionMap); | ||
engine.config = this.config; | ||
@@ -87,3 +78,2 @@ | ||
this._engine = this.getEngineByName(this._engineName); | ||
this._engine.initRequireCache(engineNameOrPath); | ||
@@ -111,6 +101,3 @@ if (this.useMarkdown === undefined) { | ||
if (typeof (engineName || "") !== "string") { | ||
throw new Error( | ||
"Expected String passed to parseEngineOverrides. Received: " + | ||
engineName | ||
); | ||
throw new Error("Expected String passed to parseEngineOverrides. Received: " + engineName); | ||
} | ||
@@ -163,5 +150,3 @@ | ||
getReadableEnginesList() { | ||
return ( | ||
this.getReadableEnginesListDifferingFromFileExtension() || this.engineName | ||
); | ||
return this.getReadableEnginesListDifferingFromFileExtension() || this.engineName; | ||
} | ||
@@ -184,7 +169,3 @@ | ||
if ( | ||
this.engineName === "md" && | ||
this.useMarkdown && | ||
this.parseMarkdownWith | ||
) { | ||
if (this.engineName === "md" && this.useMarkdown && this.parseMarkdownWith) { | ||
return this.parseMarkdownWith; | ||
@@ -216,12 +197,7 @@ } | ||
if (engineOverride) { | ||
let engines = | ||
TemplateRender.parseEngineOverrides(engineOverride).reverse(); | ||
let engines = TemplateRender.parseEngineOverrides(engineOverride).reverse(); | ||
return engines.join(","); | ||
} | ||
if ( | ||
this.engineName === "md" && | ||
this.useMarkdown && | ||
this.parseMarkdownWith | ||
) { | ||
if (this.engineName === "md" && this.useMarkdown && this.parseMarkdownWith) { | ||
return `${this.parseMarkdownWith},md`; | ||
@@ -308,7 +284,3 @@ } | ||
} else if (this.engineName === "html") { | ||
return this.engine.compile( | ||
str, | ||
this.engineNameOrPath, | ||
this.parseHtmlWith | ||
); | ||
return this.engine.compile(str, this.engineNameOrPath, this.parseHtmlWith); | ||
} else { | ||
@@ -315,0 +287,0 @@ return this.engine.compile(str, this.engineNameOrPath); |
const chalk = require("kleur"); | ||
const semver = require("semver"); | ||
const { DateTime } = require("luxon"); | ||
const EventEmitter = require("./Util/AsyncEventEmitter"); | ||
const EleventyCompatibility = require("./Util/Compatibility"); | ||
const EleventyBaseError = require("./EleventyBaseError"); | ||
const BenchmarkManager = require("./BenchmarkManager"); | ||
const merge = require("./Util/Merge"); | ||
const debug = require("debug")("Eleventy:UserConfig"); | ||
const pkg = require("../package.json"); | ||
@@ -109,11 +110,8 @@ class UserConfigError extends EleventyBaseError {} | ||
versionCheck(expected) { | ||
if ( | ||
!semver.satisfies(pkg.version, expected, { | ||
includePrerelease: true, | ||
}) | ||
) { | ||
throw new UserConfigError( | ||
`This project requires the Eleventy version to match '${expected}' but found ${pkg.version}. Use \`npm update @11ty/eleventy -g\` to upgrade the eleventy global or \`npm update @11ty/eleventy --save\` to upgrade your local project version.` | ||
); | ||
// compatibleRange is optional in 2.0.0-beta.2 | ||
versionCheck(compatibleRange) { | ||
let compat = new EleventyCompatibility(compatibleRange); | ||
if (!compat.isCompatible()) { | ||
throw new UserConfigError(compat.getErrorMessage()); | ||
} | ||
@@ -120,0 +118,0 @@ } |
const path = require("path"); | ||
const { TemplatePath } = require("@11ty/eleventy-utils"); | ||
const debug = require("debug")("Eleventy:DeleteRequireCache"); | ||
@@ -11,2 +12,3 @@ /** | ||
const normalizedPath = path.normalize(absolutePath); | ||
debug("Deleting %o from `require` cache.", normalizedPath); | ||
delete require.cache[normalizedPath]; | ||
@@ -20,3 +22,5 @@ } | ||
module.exports = deleteRequireCache; // local paths | ||
module.exports = deleteRequireCache; // will transform local paths to absolute | ||
// Export for testing only | ||
module.exports.deleteRequireCacheAbsolute = deleteRequireCacheAbsolute; |
const { TemplatePath } = require("@11ty/eleventy-utils"); | ||
const { deleteRequireCacheAbsolute } = require("./DeleteRequireCache"); | ||
@@ -7,9 +6,2 @@ function requireLocal(localPath) { | ||
return requireAbsolute(absolutePath); | ||
} | ||
function requireAbsolute(absolutePath) { | ||
// remove from require cache so it will grab a fresh copy | ||
deleteRequireCacheAbsolute(absolutePath); | ||
return require(absolutePath); | ||
@@ -19,2 +11,1 @@ } | ||
module.exports.EleventyRequire = requireLocal; | ||
module.exports.EleventyRequireAbsolute = requireAbsolute; |
Sorry, the diff of this file is not supported yet
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
476080
105
13679
40