Skip to content

Commit

Permalink
fix(*): support Windows paths (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-agius4 authored and jbedard committed Feb 5, 2020
1 parent 1ad2017 commit ecf283c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion 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 Expand Up @@ -166,7 +168,7 @@ function main(params, read = fs.readFileSync, write = mkdirpWrite, timestamp = D
const rootedOutputDir = removeRootPath(outputDir).replace(/^\//, "./");
function relativeToHtml(p) {
// Ignore absolute
if (p.startsWith("/")) {
if (path.isAbsolute(p)) {
return 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) === 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 ecf283c

Please sign in to comment.