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..01551844f --- /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(normalize_path('C:\\Users\\simon\\Source\\my-app\\src\\routes\\index.svelte'), + 'c:\\Users\\simon\\Source\\my-app\\src\\routes\\index.svelte'); + }); +});