diff --git a/src/main.js b/src/main.js index 3cff8a7..0a3b311 100644 --- a/src/main.js +++ b/src/main.js @@ -3,6 +3,7 @@ const parse5 = require('parse5'); const treeAdapter = require('parse5/lib/tree-adapters/default'); const fs = require('fs'); +const path = require('path'); function findElementByName(d, name) { if (treeAdapter.isTextNode(d)) return undefined; @@ -58,6 +59,7 @@ function parseArgs(params) { } // Make dir '/'s consistent. Always trim the longest prefix + rootDirs.push(path.dirname(outputFile)); rootDirs = rootDirs.map(r => r.endsWith('/') ? r : r + '/'); rootDirs.sort((a, b) => b.length - a.length); diff --git a/test/spec.js b/test/spec.js index b7ffdb7..8f47a92 100644 --- a/test/spec.js +++ b/test/spec.js @@ -39,6 +39,13 @@ describe('HTML inserter', () => { '
'); }); + it('should include --out file dir as default --root', () => { + expect(inserter.main(["--out", outFile, "--html", inFile, + '--assets', 'out/some/file.js'], read, write, () => 123)).toBe(0); + expect(output).toBe( + ''); + }); + it('should strip longest prefix', () => { expect(inserter.main(["--out", outFile, "--html", inFile, "--roots", 'path', 'path/to',