-
-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b3bd31
commit 59dca2c
Showing
7 changed files
with
173 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"shadcn-svelte": patch | ||
--- | ||
|
||
fix: Support use of `jsconfig.json` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Sourced from tsconfck v2 | ||
|
||
import { promises as fs } from "fs"; | ||
import path from "path"; | ||
|
||
/** | ||
* find the closest tsconfig.json file | ||
* | ||
* @param {string} filename - path to file to find tsconfig for (absolute or relative to cwd) | ||
* @param {TSConfckFindOptions} options - options | ||
* @returns {Promise<string>} absolute path to closest tsconfig.json | ||
*/ | ||
export async function find(filename: string, options?: TSConfckFindOptions) { | ||
let dir = path.dirname(path.resolve(filename)); | ||
const root = options?.root ? path.resolve(options.root) : null; | ||
while (dir) { | ||
const tsconfig = await tsconfigInDir(dir, options); | ||
if (tsconfig) { | ||
return tsconfig; | ||
} else { | ||
if (root === dir) { | ||
break; | ||
} | ||
const parent = path.dirname(dir); | ||
if (parent === dir) { | ||
break; | ||
} else { | ||
dir = parent; | ||
} | ||
} | ||
} | ||
throw new Error(`no tsconfig file found for ${filename}`); | ||
} | ||
|
||
// Modified to also search for jsconfig.json | ||
async function tsconfigInDir( | ||
dir: string, | ||
options?: TSConfckFindOptions | ||
): Promise<string | void> { | ||
const tsconfig = path.join(dir, "tsconfig.json"); | ||
const jsconfig = path.join(dir, "jsconfig.json"); | ||
|
||
if (options?.tsConfigPaths) { | ||
return options.tsConfigPaths.has(tsconfig) ? tsconfig : undefined; | ||
} | ||
try { | ||
const stat = await fs.stat(tsconfig); | ||
if (stat.isFile() || stat.isFIFO()) { | ||
return tsconfig; | ||
} | ||
} catch (e: any) { | ||
// ignore does not exist error | ||
if (e.code !== "ENOENT") { | ||
throw e; | ||
} | ||
} | ||
|
||
try { | ||
let stat = await fs.stat(jsconfig); | ||
if (stat.isFile() || stat.isFIFO()) { | ||
return jsconfig; | ||
} | ||
} catch (e: any) { | ||
// ignore does not exist error | ||
if (e.code !== "ENOENT") { | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
export interface TSConfckFindOptions { | ||
/** | ||
* Set of known tsconfig file locations to use instead of scanning the file system | ||
* | ||
* This is better for performance in projects like vite where find is called frequently but tsconfig locations rarely change | ||
* You can use `findAll` to build this | ||
*/ | ||
tsConfigPaths?: Set<string>; | ||
|
||
/** | ||
* project root dir, does not continue scanning outside of this directory. | ||
* | ||
* Improves performance but may lead to different results from native typescript when no tsconfig is found inside root | ||
*/ | ||
root?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/cli/test/fixtures/config-jsconfig/components.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"style": "new-york", | ||
"tailwind": { | ||
"config": "tailwind.config.js", | ||
"css": "src/app.pcss", | ||
"baseColor": "zinc" | ||
}, | ||
"aliases": { | ||
"utils": "$lib/utils", | ||
"components": "$lib/components" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"checkJs": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"resolveJsonModule": true, | ||
"skipLibCheck": true, | ||
"sourceMap": true, | ||
"strict": true, | ||
"moduleResolution": "bundler", | ||
"paths": { | ||
"$lib": ["./src/lib"], | ||
"$lib/*": ["./src/lib/*"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "test-cli-config-full", | ||
"version": "0.0.0", | ||
"private": true, | ||
"devDependencies": { | ||
"@sveltejs/vite-plugin-svelte": "^3.0.0", | ||
"svelte": "^4.2.7", | ||
"svelte-check": "^3.6.0", | ||
"tslib": "^2.4.1", | ||
"typescript": "^5.0.0", | ||
"vite": "^5.0.3" | ||
}, | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters