Skip to content

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

@BananaAcid

Description

@BananaAcid

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});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions