Skip to content
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

Inliner outputs an empty web page when executed under the Node.js exec function #228

Open
ashleydavis opened this issue May 22, 2022 · 0 comments

Comments

@ashleydavis
Copy link

ashleydavis commented May 22, 2022

I've discovered an issue when you run inliner under the Node.js exec or execSync function.

Take a working inliner command line this:

npx inliner index.html > out/index.html

Put the same command line in a JavaScript file and run it through execSync:

const { execSync } = require("child_process");

const result = execSync("npx inliner index.html > out/index.html");
console.log(result);

This causes an empty file to be written to out/index.html.

I've created a simple example of the problem here, follow the readme for the repo case:
https://github.com/ashleydavis/inliner-issue

The problem originates with this line of code:

argv.useStdin = !process.stdin.isTTY;

When inliner is invoked under execSync it sets isTTY to false which sets useStdin to true.

When useStdin is enabled nothing is read because no standard input is actually applied. Because nothing is read nothing is output:

if (argv.useStdin) {

After I realised what this issue was I was able to construct a workaround which you can see in my example project.

The workaround requires rearranging the command to actually give it the input via standard input:

const { execSync } = require("child_process");

const result = execSync("cat index.html | npx inliner > out/index.html");
console.log(result);

A good fix to this problem would be to make reading of standard input explicitly enabled by the user. The user should explicitly enable it by adding a dash to the end of the inliner command:

cat index.html | npx inliner - > out/index.html

You can see an example here of how the Kubectl tool does it.

ashleydavis added a commit to data-forge-notebook/data-forge-notebook that referenced this issue May 22, 2022
Inliner automatically expects input to come from standard input when you run it under `execSync` as I'm now doing in the updated build pipeline.

Simply running Inliner under `execSync` shouldn't trigger this behaviour, I think it's a bug in Inliner.

As a workaround I've restructured Inliner to give it input via standard input.

I've created an issue to address the real problem:
remy/inliner#228

A simple repo is available here:
https://github.com/ashleydavis/inliner-issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant