Skip to content

Commit

Permalink
feat: bundle relevant tsconfig/jsconfig.json files
Browse files Browse the repository at this point in the history
These files are currently not utilized by the backend but they might be
in the near future.
  • Loading branch information
sorccu committed Dec 22, 2024
1 parent b86a9fd commit de9ceb2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/cli/src/services/check-parser/package-files/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class PackageFiles {
}
}

type TSConfigFileLocalDependency = {
kind: 'tsconfig-file'
importPath: string
sourceFile: SourceFile
configFile: TSConfigFile
}

type TSConfigResolvedPathLocalDependency = {
kind: 'tsconfig-resolved-path'
importPath: string
Expand Down Expand Up @@ -80,6 +87,7 @@ type RelativePathLocalDependency = {
}

type LocalDependency =
TSConfigFileLocalDependency |
TSConfigResolvedPathLocalDependency |
TSConfigBaseUrlRelativePathLocalDependency |
PackageRelativePathLocalDependency |
Expand Down Expand Up @@ -163,7 +171,9 @@ export class PackageFilesResolver {
continue
}

return [sourceFile, mainSourceFile]
configJson.registerRelatedSourceFile(mainSourceFile)

return [sourceFile, mainSourceFile, configJson.jsonFile.sourceFile]
}
}

Expand Down Expand Up @@ -239,6 +249,7 @@ export class PackageFilesResolver {
if (sourceFile !== undefined) {
const resolvedFiles = this.resolveSourceFile(sourceFile)
for (const resolvedFile of resolvedFiles) {
configJson.registerRelatedSourceFile(resolvedFile)
resolved.local.push({
kind: 'tsconfig-resolved-path',
importPath,
Expand All @@ -249,6 +260,12 @@ export class PackageFilesResolver {
target,
},
})
resolved.local.push({
kind: 'tsconfig-file',
importPath,
sourceFile: configJson.jsonFile.sourceFile,
configFile: configJson,
})
found = true
}
if (found) {
Expand All @@ -270,12 +287,19 @@ export class PackageFilesResolver {
const resolvedFiles = this.resolveSourceFile(sourceFile)
let found = false
for (const resolvedFile of resolvedFiles) {
configJson.registerRelatedSourceFile(resolvedFile)
resolved.local.push({
kind: 'tsconfig-baseurl-relative-path',
importPath,
sourceFile: resolvedFile,
configFile: configJson,
})
resolved.local.push({
kind: 'tsconfig-file',
importPath,
sourceFile: configJson.jsonFile.sourceFile,
configFile: configJson,
})
found = true
}
if (found) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'node:path'

import { SourceFile } from './source-file'
import { JsonSourceFile } from './json-source-file'
import { PathResolver, ResolveResult } from './paths'
import type { LoadFile } from './loader'
Expand Down Expand Up @@ -90,6 +91,8 @@ export class TSConfigFile {
baseUrl?: string
pathResolver: PathResolver

relatedSourceFiles: SourceFile[] = []

protected constructor (jsonFile: JsonSourceFile<Schema>) {
this.jsonFile = jsonFile

Expand Down Expand Up @@ -215,4 +218,8 @@ export class TSConfigFile {

return this.extifyLookupPaths(candidates)
}

registerRelatedSourceFile (file: SourceFile) {
this.relatedSourceFiles.push(file)
}
}
2 changes: 2 additions & 0 deletions packages/cli/src/services/check-parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ export class Parser {
// This doesn't actually cause problems (both are "ESTree's"), but we need to ignore type errors here.
// @ts-ignore
walk.simple(ast, Parser.tsNodeVisitor(tsParser, dependencies))
} else if (extension === '.json') {
// No dependencies to check.
} else {
throw new Error(`Unsupported file extension for ${filePath}`)
}
Expand Down

0 comments on commit de9ceb2

Please sign in to comment.