New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
--version and --help might be processing global data files #1313
Comments
While it seems to be executing code in my site, it isn't generating a _site folder. |
Fascinating! Lines 48 to 80 in 727607c
I wonder if explicitly checking for |
I should add, I happened to be in a huge Eleventy project. If I didn't have the error in the code and it was a smaller project, I probably wouldn't have noticed. |
Shipping with 1.0 |
I'm using 1.0 beta4 and I still have this issue. In my case, I absolutely have a bug in current site and I want to debug, but I forgot how to do that. I tried |
@cfjedimaster Interesting! If I build a fake site locally with this global data file: module.exports = () => {
console.log(`I'm a global data file: ${__filename}`);
return {
foo: "bar",
baz: false
};
}; ... and this .eleventy.js config file: module.exports = eleventyComputed => {
console.log(`I'm a config file: ${__filename}`);
return {
dir: {
output: "www"
}
};
}; ... then I get the following output: npm run build
> eleventy
I'm a config file: /private/tmp/11ty-global-help/.eleventy.js
I'm a global data file: /private/tmp/11ty-global-help/_data/site.js
[11ty] Wrote 0 files in 0.02 seconds (v1.0.0-beta.4) So it processed my config file and global data file like I expect. If I run eleventy --version, it runs my config file, but I don't see the debug output from my global data file. eleventy --version
I'm a config file: /private/tmp/11ty-global-help/.eleventy.js
1.0.0-beta.4 And same w/ eleventy --help (processes .eleventy.js config file, but not global data file): > eleventy --help
I'm a config file: /private/tmp/11ty-global-help/.eleventy.js
Usage: eleventy
eleventy --input=. --output=./_site
eleventy --serve
Arguments:
--version
--input=.
Input template files (default: `.`)
--output=_site
Write HTML output to this folder (default: `_site`)
--serve
Run web server on --port (default 8080) and watch them too
--watch
Wait for files to change and automatically rewrite (no web server)
--formats=liquid,md
Whitelist only certain template types (default: `*`)
--quiet
Don’t print all written files (off by default)
--config=filename.js
Override the eleventy config file path (default: `.eleventy.js`)
--pathprefix='/'
Change all url template filters to use this subdirectory.
--dryrun
Don’t write any files. Useful with `DEBUG=Eleventy* npx eleventy`
--to=json
--to=ndjson
Change the output to JSON or NDJSON (default: `fs`)
--help So if eleventy [--help|--version] is still executing the .eleventy.js code, I wonder if you're trying to access any global data files or something from the config file and that's what's causing something. UPDATE: Garbage repo uploaded to https://github.com/pdehaan/11ty-global-help |
In my demo code I was using a plugin and the plugin was throwing an error - so another config file. |
Ah yes... I wrote a terrible plugin that // ./plugins/bad-plugin.js
module.exports = (eleventyConfig = {}, pluginConfig = {}) => {
console.log(`I'm a custom plugin: ${__filename}`);
if (!!pluginConfig.throws) {
throw new Error(`Thrown error from a custom plugin`);
};
eleventyConfig.addFilter("customFilter", (value) => `plugin: ${value}`);
}; // .eleventy.js
module.exports = eleventyConfig => {
console.log(`I'm a config file: ${__filename}`);
eleventyConfig.addPlugin(require("./plugins/bad-plugin"), {throws: true});
return {
dir: {
output: "www"
}
};
}; OUTPUT> eleventy --version
I'm a config file: /private/tmp/11ty-global-help/.eleventy.js
I'm a custom plugin: /private/tmp/11ty-global-help/plugins/bad-plugin.js
[11ty] Eleventy CLI Fatal Error: (more in DEBUG output)
[11ty] > Thrown error from a custom plugin
`Error` was thrown:
[11ty] Error: Thrown error from a custom plugin
at module.exports (/private/tmp/11ty-global-help/plugins/bad-plugin.js:4:11)
at UserConfig._executePlugin (/private/tmp/11ty-global-help/node_modules/@11ty/eleventy/src/UserConfig.js:335:7)
at /private/tmp/11ty-global-help/node_modules/@11ty/eleventy/src/TemplateConfig.js:187:23
at Array.forEach (<anonymous>)
at TemplateConfig.processPlugins (/private/tmp/11ty-global-help/node_modules/@11ty/eleventy/src/TemplateConfig.js:185:29)
at TemplateConfig.mergeConfig (/private/tmp/11ty-global-help/node_modules/@11ty/eleventy/src/TemplateConfig.js:253:10)
at TemplateConfig.getConfig (/private/tmp/11ty-global-help/node_modules/@11ty/eleventy/src/TemplateConfig.js:117:26)
at new Eleventy (/private/tmp/11ty-global-help/node_modules/@11ty/eleventy/src/Eleventy.js:74:39)
at Object.<anonymous> (/private/tmp/11ty-global-help/node_modules/@11ty/eleventy/cmd.js:70:14)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! 11ty-global-help@1.0.0 test:version: `eleventy --version`
npm ERR! Exit status 1 |
I think I fixed this locally (by hacking files in my node_modules/ directly), but not sure it's great solution… If we change the /**
* Reads the version of Eleventy...
*/
static getVersion() {
return pkg.version;
}
/**
* Shows a help message including usage...
*/
static getHelp() {
return `Usage: eleventy
...
} ... then check if (argv.version) {
console.log(Eleventy.getVersion());
return;
}
if (argv.help) {
console.log(Eleventy.getHelp());
return;
}
let elev = new Eleventy(argv.input, argv.output, { |
Am I correct in reading this that it was partially fixed but there still exists an issue when a plugin throws an error? |
Moving this to 1.0.1 milestone |
@zachleat yep |
Shipping with 1.0.1 and 2.0.0-canary.5 |
(Absolutely used the approach recommended by @pdehaan here #1313 (comment) though kept the instance methods for backwards compat) |
Hey sorry, this is back. Eleventy was running super slow because it was processing my node_modules. It took quite some time to run and ended up throwing an error and in one of the As soon as I |
Sorry disregard - my global eleventy CLI had fallen behind. |
Describe the bug
I noticed that
eleventy --help
was running real slow. I then noticed an error was thrown before the help text. The error was from one of my _data files, and was a valid error, but why would--help
, and--version
try to run code in my site?To Reproduce
Output the help or version for the CLI in a directory that has an Eleventy site, possibly with an error in it.
Environment:
The text was updated successfully, but these errors were encountered: