Skip to content

Commit

Permalink
fix: support Windows paths
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-agius4 committed Feb 5, 2020
1 parent 1ad2017 commit cc00501
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function findElementByName(d, name) {

function normalizePath(p) {
p = path.normalize(p);
// Convert paths to posix
p = p.replace(/\\/g, '/');
if (p[0] !== '/' && p[0] !== '.') {
p = `./${p}`;
}
Expand Down
17 changes: 14 additions & 3 deletions test/spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const path = require('path');
const {main, parseArgs} = require('../src/main');

const inFile = './data/some/index.html';
const inFile = path.normalize('./data/some/index.html');

function read(file) {
if (file === inFile) return `<html><head></head><body></body></html>`;
if (path.normalize(file) === path.normalize(inFile)) return `<html><head></head><body></body></html>`;
throw new Error(`no content for ${file}`);
}

Expand Down Expand Up @@ -108,7 +109,17 @@ describe('HTML inserter', () => {
"--roots", 'npm/node_modules/zone.js/dist',
'--assets', 'external/npm/node_modules/zone.js/dist/zone.min.js'], read, write, stamper)).toBe(0);
expect(output).toBe(scriptHtml('/zone.min.js'));

});

it('should strip the external workspaces prefix in Windows', () => {
if (path.win32.normalize !== path.normalize) {
spyOn(path, 'normalize').and.callFake(path.win32.normalize);
}

expect(main(["--out", "index.html", "--html", inFile,
"--roots", 'npm/node_modules/zone.js/dist',
'--assets', 'external/npm/node_modules/zone.js/dist/zone.min.js'], read, write, stamper)).toBe(0);
expect(output).toBe(scriptHtml('/zone.min.js'));
});

it('should inject .css files as stylesheet link tags', () => {
Expand Down

0 comments on commit cc00501

Please sign in to comment.