vite-plugin-simple-tsconfig-alias 0.1.0 → 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 +3 -3
- package/dist/index.mjs +7 -20
- package/package.json +4 -2
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
|
|
2
|
+
import { getTsconfig } from "get-tsconfig";
|
|
4
3
|
|
|
5
4
|
//#region src/index.ts
|
|
6
5
|
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -18,27 +17,15 @@ 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
|
-
function toArray(value) {
|
|
28
|
-
if (Array.isArray(value)) return value.filter((v) => typeof v === "string");
|
|
29
|
-
if (typeof value === "string") return [value];
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
20
|
function parseTsconfigAliases(projectRoot, configNames) {
|
|
33
21
|
const aliases = [];
|
|
34
22
|
for (const configName of configNames) {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const baseUrl =
|
|
39
|
-
const paths =
|
|
40
|
-
for (const [from,
|
|
41
|
-
const firstTarget = toArray(to)[0];
|
|
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 ?? {};
|
|
28
|
+
for (const [from, [firstTarget]] of Object.entries(paths)) {
|
|
42
29
|
if (!firstTarget) continue;
|
|
43
30
|
const absoluteTarget = path.resolve(baseUrl, firstTarget);
|
|
44
31
|
if (!from.includes("*")) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-simple-tsconfig-alias",
|
|
3
|
-
"version": "0.
|
|
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": {
|