Skip to content

Commit

Permalink
feat(*): include output directory as default root dir
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Nov 26, 2019
1 parent 84ba9cd commit 31226ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ describe('HTML inserter', () => {
'<html><head></head><body><script type="module" src="/path/to/my.es2015.js?v=123"></script></body></html>');
});

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(
'<html><head></head><body><script src="/file.js?v=123"></script></body></html>');
});

it('should strip longest prefix', () => {
expect(inserter.main(["--out", outFile, "--html", inFile,
"--roots", 'path', 'path/to',
Expand Down

0 comments on commit 31226ae

Please sign in to comment.