From 3cda312fab93865d9f3f8f1f954eb6fdfa4fba08 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sat, 25 Jul 2020 15:48:30 -0700 Subject: [PATCH 1/3] Fix Sapper on Windows --- mocha.opts | 3 +-- src/core/create_compilers/RollupResult.ts | 4 ++-- src/core/create_compilers/extract_css.ts | 7 +++---- src/utils.ts | 8 +++++++- test/unit/utils.test.ts | 9 +++++++++ 5 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 test/unit/utils.test.ts diff --git a/mocha.opts b/mocha.opts index 14409727d..ff9c0b5dc 100644 --- a/mocha.opts +++ b/mocha.opts @@ -1,5 +1,4 @@ --require source-map-support/register --require sucrase/register --recursive -test/unit/*/test.ts -test/apps/*/test.ts +test/**/*test.ts diff --git a/src/core/create_compilers/RollupResult.ts b/src/core/create_compilers/RollupResult.ts index 99ea2a51f..41d88f095 100644 --- a/src/core/create_compilers/RollupResult.ts +++ b/src/core/create_compilers/RollupResult.ts @@ -3,7 +3,7 @@ import colors from 'kleur'; import pb from 'pretty-bytes'; import RollupCompiler from './RollupCompiler'; import extract_css from './extract_css'; -import { left_pad } from '../../utils'; +import { left_pad, normalize_path } from '../../utils'; import { CompileResult, BuildInfo, CompileError, Chunk, CssFile } from './interfaces'; import { ManifestData, Dirs } from '../../interfaces'; @@ -31,7 +31,7 @@ export default class RollupResult implements CompileResult { this.chunks = compiler.chunks.map(chunk => ({ file: chunk.fileName, imports: chunk.imports.filter(Boolean), - modules: Object.keys(chunk.modules) + modules: Object.keys(chunk.modules).map(m => normalize_path(m)) })); this.css_files = compiler.css_files; diff --git a/src/core/create_compilers/extract_css.ts b/src/core/create_compilers/extract_css.ts index d2a22959c..71452378f 100644 --- a/src/core/create_compilers/extract_css.ts +++ b/src/core/create_compilers/extract_css.ts @@ -4,7 +4,7 @@ import hash from 'string-hash'; import * as codec from 'sourcemap-codec'; import { PageComponent, Dirs } from '../../interfaces'; import { CompileResult, Chunk } from './interfaces'; -import { posixify } from '../../utils' +import { normalize_path, posixify } from '../../utils' const inline_sourcemap_header = 'data:application/json;charset=utf-8;base64,'; @@ -192,13 +192,12 @@ export default function extract_css( // figure out which (css-having) chunks each component depends on components.forEach(component => { - const resolved = path.resolve(dirs.routes, component.file); + const resolved = normalize_path(path.resolve(dirs.routes, component.file)); const chunk: Chunk = client_result.chunks.find(chunk => chunk.modules.indexOf(resolved) !== -1); if (!chunk) { // this should never happen! - return; - // throw new Error(`Could not find chunk that owns ${component.file}`); + throw new Error(`Could not find chunk that owns ${component.file}`); } const chunk_dependencies: Set = new Set([chunk]); diff --git a/src/utils.ts b/src/utils.ts index 43bbad689..82afcd3eb 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -116,4 +116,10 @@ export const reserved_words = new Set([ 'while', 'with', 'yield', -]); \ No newline at end of file +]); + +export function normalize_path(user_path) { + const p = path.normalize(user_path); + // normalize drive letter on Windows + return p.length ? p.charAt(0).toLowerCase() + p.slice(1) : ''; +} diff --git a/test/unit/utils.test.ts b/test/unit/utils.test.ts new file mode 100644 index 000000000..89feb77f5 --- /dev/null +++ b/test/unit/utils.test.ts @@ -0,0 +1,9 @@ +import * as assert from 'assert'; +import { normalize_path } from '../../src/utils'; + +describe('normalize_path', () => { + it('lowercases the first letter', () => { + assert.equal('c:\Users\simon\Source\my-app\src\routes\index.svelte', + normalize_path('C:\Users\simon\Source\my-app\src\routes\index.svelte')); + }); +}); From ad8ffd8f1878051bb796437f33e85c1b54f571a0 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Wed, 29 Jul 2020 08:53:45 -0700 Subject: [PATCH 2/3] Swap actual and expected --- test/unit/utils.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/utils.test.ts b/test/unit/utils.test.ts index 89feb77f5..79f7dc5a3 100644 --- a/test/unit/utils.test.ts +++ b/test/unit/utils.test.ts @@ -3,7 +3,7 @@ import { normalize_path } from '../../src/utils'; describe('normalize_path', () => { it('lowercases the first letter', () => { - assert.equal('c:\Users\simon\Source\my-app\src\routes\index.svelte', - normalize_path('C:\Users\simon\Source\my-app\src\routes\index.svelte')); + assert.equal(normalize_path('C:\Users\simon\Source\my-app\src\routes\index.svelte'), + 'c:\Users\simon\Source\my-app\src\routes\index.svelte'); }); }); From 1e19660e20bd724646d3f9e6cc296aaa2a3d20d3 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Wed, 29 Jul 2020 11:40:24 -0700 Subject: [PATCH 3/3] Fix escaping in test --- test/unit/utils.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/utils.test.ts b/test/unit/utils.test.ts index 79f7dc5a3..01551844f 100644 --- a/test/unit/utils.test.ts +++ b/test/unit/utils.test.ts @@ -3,7 +3,7 @@ import { normalize_path } from '../../src/utils'; describe('normalize_path', () => { it('lowercases the first letter', () => { - assert.equal(normalize_path('C:\Users\simon\Source\my-app\src\routes\index.svelte'), - 'c:\Users\simon\Source\my-app\src\routes\index.svelte'); + assert.equal(normalize_path('C:\\Users\\simon\\Source\\my-app\\src\\routes\\index.svelte'), + 'c:\\Users\\simon\\Source\\my-app\\src\\routes\\index.svelte'); }); });