Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
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
3 changes: 1 addition & 2 deletions mocha.opts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
--require source-map-support/register
--require sucrase/register
--recursive
test/unit/*/test.ts
test/apps/*/test.ts
test/**/*test.ts
4 changes: 2 additions & 2 deletions src/core/create_compilers/RollupResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions src/core/create_compilers/extract_css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,';

Expand Down Expand Up @@ -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<Chunk> = new Set([chunk]);
Expand Down
8 changes: 7 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,10 @@ export const reserved_words = new Set([
'while',
'with',
'yield',
]);
]);

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) : '';
}
9 changes: 9 additions & 0 deletions test/unit/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});