vite-plugin-simple-tsconfig-alias 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,9 +19,9 @@ A simple Vite plugin to resolve tsconfig paths as aliases.
19
19
  ## 📦 Installation
20
20
 
21
21
  ```bash
22
- $ npm install vite-plugin-simple-tsconfig-alias
23
- $ yarn add vite-plugin-simple-tsconfig-alias
24
- $ pnpm add vite-plugin-simple-tsconfig-alias
22
+ $ npm install -D vite-plugin-simple-tsconfig-alias
23
+ $ yarn add -D vite-plugin-simple-tsconfig-alias
24
+ $ pnpm add -D vite-plugin-simple-tsconfig-alias
25
25
  ```
26
26
 
27
27
  ## 🚀 Usage
package/dist/index.mjs CHANGED
@@ -1,6 +1,5 @@
1
- import fs from "node:fs";
2
1
  import path from "node:path";
3
- import ts from "typescript";
2
+ import { getTsconfig } from "get-tsconfig";
4
3
 
5
4
  //#region src/index.ts
6
5
  const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -18,20 +17,14 @@ function buildReplacement(target, starCount) {
18
17
  for (let i = 1; i <= starCount; i += 1) replacement = replacement.replace("*", `$${i}`);
19
18
  return replacement;
20
19
  }
21
- function readTsconfig(filePath) {
22
- if (!fs.existsSync(filePath)) return null;
23
- const read = ts.readConfigFile(filePath, ts.sys.readFile);
24
- if (read.error) return null;
25
- return ts.parseJsonConfigFileContent(read.config, ts.sys, path.dirname(filePath), void 0, filePath);
26
- }
27
20
  function parseTsconfigAliases(projectRoot, configNames) {
28
21
  const aliases = [];
29
22
  for (const configName of configNames) {
30
- const configPath = path.resolve(projectRoot, configName);
31
- const parsed = readTsconfig(configPath);
32
- if (!parsed) continue;
33
- const baseUrl = parsed.options.baseUrl ?? path.dirname(configPath);
34
- const paths = parsed.options.paths ?? {};
23
+ const tsconfig = getTsconfig(projectRoot, configName);
24
+ if (!tsconfig) continue;
25
+ const { compilerOptions } = tsconfig.config;
26
+ const baseUrl = compilerOptions?.baseUrl ?? projectRoot;
27
+ const paths = compilerOptions?.paths ?? {};
35
28
  for (const [from, [firstTarget]] of Object.entries(paths)) {
36
29
  if (!firstTarget) continue;
37
30
  const absoluteTarget = path.resolve(baseUrl, firstTarget);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-simple-tsconfig-alias",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "author": "Ray <i@mk1.io> (@so1ve)",
5
5
  "type": "module",
6
6
  "description": "A simple Vite plugin to resolve tsconfig paths as aliases.",
@@ -34,6 +34,9 @@
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
+ "dependencies": {
38
+ "get-tsconfig": "^4.13.0"
39
+ },
37
40
  "devDependencies": {
38
41
  "@antfu/ni": "^28.0.0",
39
42
  "@so1ve/eslint-config": "^4.1.2",
@@ -49,7 +52,6 @@
49
52
  "vitest": "^4.0.16"
50
53
  },
51
54
  "peerDependencies": {
52
- "typescript": "^5",
53
55
  "vite": "^4 || ^5 || ^6 || ^7"
54
56
  },
55
57
  "peerDependenciesMeta": {