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

compileFile() has a different return then compile() #22

Open
BananaAcid opened this issue Dec 20, 2019 · 2 comments
Open

compileFile() has a different return then compile() #22

BananaAcid opened this issue Dec 20, 2019 · 2 comments

Comments

@BananaAcid
Copy link

BananaAcid commented Dec 20, 2019

compile() returns fn(locals, callback) -- expected, is like pug
https://github.com/pugjs/then-pug/blob/master/packages/then-pug/lib/index.js#L384

compileFile() returns type stream -- unexpected, should be like compile()
https://github.com/pugjs/then-pug/blob/master/packages/then-pug/lib/index.js#L477

Workaround :

import {promises as fs} from 'fs';

async function renderAsync(filepath, locals) {
  
  let options = {filename: filepath};
  let fn = pug.compile(await fs.readFile(options.filename, 'utf8'), options);
  
  // promise helper
  return new Promise( ret => fn(locals, (e,r) => ret(r)) );
}

let html = await renderAsync('filename', {...locals});
@jeromew
Copy link
Contributor

jeromew commented Dec 20, 2019

Thanks for the report.

I must admit that I never used compileFile in then-pug because it reads file synchronously so I am not surprised its behavior is not as expected.

I will have to think whether it should be removed altogether from then-pug or see how we can patch the caching mechanism in handleTemplateCache

@BananaAcid
Copy link
Author

BananaAcid commented Dec 21, 2019

The only reason for me, was because of a different caching method I implemented (using LRU).

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

2 participants