From cc005019aa71fe7159d13e1f9552e5adbf4420a3 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Wed, 5 Feb 2020 12:07:36 +0100 Subject: [PATCH] fix: support Windows paths See: https://github.com/bazelbuild/rules_nodejs/issues/1604 --- src/main.js | 2 ++ test/spec.js | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main.js b/src/main.js index 9ae4f07..ab6a4fa 100644 --- a/src/main.js +++ b/src/main.js @@ -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}`; } diff --git a/test/spec.js b/test/spec.js index 6c320d3..3729506 100644 --- a/test/spec.js +++ b/test/spec.js @@ -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 ``; + if (path.normalize(file) === path.normalize(inFile)) return ``; throw new Error(`no content for ${file}`); } @@ -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', () => {