Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support Windows paths #6

Merged
merged 1 commit into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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