Skip to content

Commit

Permalink
Adds upgrade helper for 11ty/eleventy#3302
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jul 23, 2024
1 parent d583b70 commit c9530ca
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
1 change: 1 addition & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(require("./src/node-version.js"));
eleventyConfig.addPlugin(require("./src/explicit-config-file.js"));
eleventyConfig.addPlugin(require("./src/html-output-suffix.js"));
eleventyConfig.addPlugin(require("./src/alias-template-formats.js"));

eleventyConfig.on("eleventy.after", () => {
console.log(chalk.blue(`[${pkg.name}] This plugin is intended for temporary use: once you’re satisfied please remove this plugin from your project!`));
Expand Down
22 changes: 22 additions & 0 deletions src/alias-template-formats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const chalk = require("kleur");
const pkg = require("../package.json");

module.exports = function(eleventyConfig) {
eleventyConfig.on("eleventy.config", templateConfig => {
let templateFormatsActive = templateConfig.templateFormats.getTemplateFormats();

if(eleventyConfig.extensionMap.size === 0) {
console.log(chalk.green(`[${pkg.name}] PASSED`), `No aliases were added via \`eleventyConfig.addExtension()\`. If you had added an alias, it would need to be also added to your active template formats. Learn more about template formats: https://www.11ty.dev/docs/config/#template-formats or about this change: https://github.com/11ty/eleventy/issues/3302`);
} else {
for(let { key, extension, aliasKey } of eleventyConfig.extensionMap) {
if(!templateFormatsActive.includes(extension)) {
console.log(chalk.red(`[${pkg.name}] ERROR`), `Aliases added via \`eleventyConfig.addExtension()\` must be added to your active template formats, via \`--formats=${extension}\` on the command line, the \`templateFormats: "${extension}"\` configuration object property, \`eleventyConfig.setTemplateFormats("${extension}")\`, or \`eleventyConfig.addTemplateFormats("${extension}")\` (additive). This *might* be what you want if you added a plugin but don’t want to currently process ${extension} files in Eleventy. Learn more about template formats: https://www.11ty.dev/docs/config/#template-formats or about this change: https://github.com/11ty/eleventy/issues/3302`);
} else {
console.log(chalk.green(`[${pkg.name}] PASSED`), `\`${extension}\` is an active template format, referenced as an alias via \`eleventyConfig.addExtension()\`. Learn more about template formats: https://www.11ty.dev/docs/config/#template-formats or about this change: https://github.com/11ty/eleventy/issues/3302`);
}
}

}
});

};
15 changes: 9 additions & 6 deletions src/explicit-config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ const argv = minimist(process.argv.slice(2), {
});

module.exports = function(eleventyConfig) {
let type = chalk.blue("NOTICE");

if(argv.config && !fs.existsSync(argv.config)) {
// We’ll never get here because the configuration file has to work to run the upgrade plugin.
type = chalk.red("ERROR");
if(argv.config) {
if(!fs.existsSync(argv.config)) {
// We’ll never get here because the configuration file has to work to run the upgrade plugin.
console.log(chalk.red(`[${pkg.name}] ERROR`), `Eleventy will fail with an error when you point \`--config\` to a configuration file that does not exist. Previous versions ran as-is (without application configuration). Read more: https://github.com/11ty/eleventy/issues/3373`);
} else {
console.log(chalk.green(`[${pkg.name}] PASSED`), `Eleventy will fail with an error when you point \`--config\` to a configuration file that does not exist. You are using \`--config\` but your configuration file _does_ exist—great! Read more: https://github.com/11ty/eleventy/issues/3373`);
}
} else {
console.log(chalk.green(`[${pkg.name}] PASSED`), `Eleventy will fail with an error when you point \`--config\` to a configuration file that does not exist. You are not using \`--config\`—so don’t worry about it! Read more: https://github.com/11ty/eleventy/issues/3373`);
}

console.log(chalk.blue(`[${pkg.name}]`), type, `Eleventy will fail with an error when you point \`--config\` to a configuration file that does not exist. Previous versions ran as-is (without application configuration). Read more: https://github.com/11ty/eleventy/issues/3373`);
};
6 changes: 3 additions & 3 deletions src/html-output-suffix.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const pkg = require("../package.json");

// https://v2-0-1.11ty.dev/docs/languages/html/#using-the-same-input-and-output-directories
module.exports = function(eleventyConfig) {
eleventyConfig.on("eleventy.config", ({ config }) => {
if(!("htmlOutputSuffix" in config)) {
console.log(chalk.blue(`[${pkg.name}]`), chalk.blue(`NOTICE`), `The \`htmlOutputSuffix\` feature was removed. It doesn’t look like you were using it!`);
eleventyConfig.on("eleventy.config", (templateConfig) => {
if(!("htmlOutputSuffix" in templateConfig.config)) {
console.log(chalk.green(`[${pkg.name}] PASSED`), `The \`htmlOutputSuffix\` feature was removed. It doesn’t look like you were using it! Learn more: https://github.com/11ty/eleventy/issues/3327`);
} else {
console.log(chalk.red(`[${pkg.name}]`), chalk.red(`ERROR`), `The \`htmlOutputSuffix\` feature was removed. Learn more: https://github.com/11ty/eleventy/issues/3327`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/node-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ const pkg = require("../package.json");

module.exports = function(eleventyConfig) {
// This throws an error in Eleventy core, so if we’ve made it here—we’ve passed the test.
console.log(chalk.green(`[${pkg.name}]`), chalk.green("PASSED"), `This project is using Node 18 or newer!`);
console.log(chalk.green(`[${pkg.name}]`), chalk.green("PASSED"), `You are using Node ${process.version}. Node 18 or newer is required.`);
};

0 comments on commit c9530ca

Please sign in to comment.