diff --git a/src/core/load-sources.ts b/src/core/load-sources.ts index 8df242a..3d8abda 100644 --- a/src/core/load-sources.ts +++ b/src/core/load-sources.ts @@ -1,7 +1,7 @@ import glob from 'fast-glob' import { Platforms, platforms } from '../core/platforms' -import { getPlatformFromFilePath, flatten } from './utils' +import { getPlatformFromFilePath, flatten, normalizePaths } from './utils' export async function loadSources(paths: string[][], platform: Platforms): Promise { const levels = platforms.get(platform) @@ -12,7 +12,10 @@ export async function loadSources(paths: string[][], platform: Platforms): Promi // Uses nested array with paths, cuz glob not save orders with using patterns for path. // Also uses sort after glob for idempotent result. - const result = flatten(await Promise.all(paths.map((path) => glob.sync(path).sort()))) + const resolvedPaths = await Promise.all( + paths.map((path) => glob.sync(normalizePaths(path)).sort()), + ) + const result = flatten(resolvedPaths) .filter((file) => { const filePlatform = getPlatformFromFilePath(file) return levels.includes(filePlatform) diff --git a/src/core/load-theme.ts b/src/core/load-theme.ts index 6b196ac..22a5e56 100644 --- a/src/core/load-theme.ts +++ b/src/core/load-theme.ts @@ -5,7 +5,7 @@ import glob from 'fast-glob' import pkgDir from 'pkg-dir' import { Platforms } from './platforms' -import { throwError } from './utils' +import { throwError, normalizePaths } from './utils' type InputTheme = { mappers: string[] @@ -31,10 +31,9 @@ export async function loadTheme( const theme: InputTheme = await readJSON(sources) if (theme.extends !== undefined) { - const [extendsPath] = await glob([ - resolve(cwd, 'node_modules', theme.extends), - resolve(cwd, theme.extends), - ]) + const [extendsPath] = await glob( + normalizePaths([resolve(cwd, 'node_modules', theme.extends), resolve(cwd, theme.extends)]), + ) if (extendsPath === undefined) { throwError(`Cannot load theme: "${theme.extends}".`) diff --git a/src/core/mappers.ts b/src/core/mappers.ts index aa1df97..f0c168c 100644 --- a/src/core/mappers.ts +++ b/src/core/mappers.ts @@ -2,9 +2,11 @@ import glob from 'fast-glob' import { readJSON, readFileSync } from 'fs-extra' import YAML from 'yaml' -export async function loadMappers(path: string[]): Promise { +import { normalizePaths } from './utils' + +export async function loadMappers(paths: string[]): Promise { const result = {} - for (const file of await glob(path)) { + for (const file of await glob(normalizePaths(paths))) { if (/\.ya?ml$/.test(file)) { Object.assign(result, YAML.parse(await readFileSync(file, 'utf8'))) } else { diff --git a/src/core/utils.ts b/src/core/utils.ts index 74c4081..3b3f6de 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -1,3 +1,5 @@ +import normalize from 'normalize-path' + import { Platforms } from '../core/platforms' export function throwError(messag: string): void { @@ -38,3 +40,7 @@ type ArrayType = T extends (infer U)[] ? U : never export function flatten(arrays: T[]): ArrayType[] { return arrays.reduce((acc, value) => acc.concat(value), []) } + +export function normalizePaths(paths: string[]): string[] { + return paths.map((path) => normalize(path)) +}