Skip to content

Commit

Permalink
Fix compilerOptions.paths resolution on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
daniilsapa committed Nov 12, 2024
1 parent d3340fe commit df980df
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/steiger-plugin-fsd/src/_lib/collect-related-ts-configs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TSConfckParseResult } from 'tsconfck'
import { dirname, posix } from 'node:path'
import { dirname, resolve } from 'node:path'
import { joinFromRoot } from '@steiger/toolkit'

export type CollectRelatedTsConfigsPayload = {
tsconfig: TSConfckParseResult['tsconfig']
Expand Down Expand Up @@ -115,7 +116,7 @@ function makeRelativePathAliasesAbsolute(
for (const entries of Object.entries(mergedConfig.compilerOptions.paths)) {
const [key, paths] = entries as [key: string, paths: Array<string>]
absolutePaths[key] = paths.map((relativePath: string) =>
posix.resolve(dirname(firstConfigWithPaths.tsconfigFile!), relativePath),
resolve(dirname(firstConfigWithPaths.tsconfigFile!), relativePath),
)
}

Expand Down Expand Up @@ -144,13 +145,13 @@ if (import.meta.vitest) {
const payload: CollectRelatedTsConfigsPayload = {
extended: [
{
tsconfigFile: '/tsconfig.json',
tsconfigFile: joinFromRoot('/tsconfig.json'),
tsconfig: {
extends: './.nuxt/tsconfig.json',
},
},
{
tsconfigFile: '/.nuxt/tsconfig.json',
tsconfigFile: joinFromRoot('/.nuxt', '/tsconfig.json'),
tsconfig: {
compilerOptions: {
paths: {
Expand All @@ -167,7 +168,7 @@ if (import.meta.vitest) {
},
},
],
tsconfigFile: '/tsconfig.json',
tsconfigFile: joinFromRoot('/tsconfig.json'),
tsconfig: {
extends: './.nuxt/tsconfig.json',
compilerOptions: {
Expand All @@ -190,8 +191,8 @@ if (import.meta.vitest) {
extends: './.nuxt/tsconfig.json',
compilerOptions: {
paths: {
'~': ['/'],
'~/*': ['/*'],
'~': [joinFromRoot()],
'~/*': [joinFromRoot('*')],
},
strict: true,
noUncheckedIndexedAccess: false,
Expand All @@ -208,7 +209,7 @@ if (import.meta.vitest) {

test('resolves paths independently from the current directory', () => {
const payload: CollectRelatedTsConfigsPayload = {
tsconfigFile: '/user/projects/project-0/tsconfig.json',
tsconfigFile: joinFromRoot('user', 'projects', 'project-0', 'tsconfig.json'),
tsconfig: {
compilerOptions: {
paths: {
Expand All @@ -229,8 +230,8 @@ if (import.meta.vitest) {
{
compilerOptions: {
paths: {
'~': ['/user/projects/project-0/src'],
'~/*': ['/user/projects/project-0/src/*'],
'~': [joinFromRoot('user', 'projects', 'project-0', 'src')],
'~/*': [joinFromRoot('user', 'projects', 'project-0', 'src', '*')],
},
strict: true,
noUncheckedIndexedAccess: false,
Expand Down

0 comments on commit df980df

Please sign in to comment.