Skip to content

Commit 17ac7db

Browse files
committed
feat: add root field
1 parent c8aea06 commit 17ac7db

File tree

9 files changed

+61
-26
lines changed

9 files changed

+61
-26
lines changed

packages/complex-types/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"@vue.ts/language": "workspace:*",
7272
"@vue.ts/shared": "workspace:*",
7373
"@vue/shared": "^3.5.22",
74-
"defu": "^6.1.4",
7574
"magic-string": "catalog:",
7675
"unplugin": "catalog:",
7776
"unplugin-utils": "^0.3.1"

packages/complex-types/src/core/types.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import type { Printer } from "./printer";
55

66
export type ValidTransforms = "defineEmits" | "defineProps";
77

8-
export type Options = {
9-
tsconfigPath?: string;
10-
} & Partial<Record<ValidTransforms, boolean>> &
11-
BaseOptions;
8+
export type Options = Partial<Record<ValidTransforms, boolean>> & BaseOptions;
129

1310
export type ResolvedOptions = Required<Options>;
1411
export type TransformOptions = Pick<ResolvedOptions, ValidTransforms>;
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
import { join } from "node:path";
1+
import { createOptionsResolver } from "@vue.ts/shared";
22

3-
import { defu } from "defu";
4-
5-
import type { Options, ResolvedOptions } from "./types";
3+
import type { ResolvedOptions } from "./types";
64

75
const defaultOptions: ResolvedOptions = {
6+
root: process.cwd(),
87
include: ["**/*.vue"],
98
exclude: ["node_modules/**"],
10-
tsconfigPath: join(process.cwd(), "tsconfig.json"),
9+
tsconfigPath: "tsconfig.json",
1110
defineEmits: true,
1211
defineProps: true,
1312
};
1413

15-
export const resolveOptions = (rawOptions: Options) =>
16-
defu(rawOptions, defaultOptions) as ResolvedOptions;
14+
export const resolveOptions = createOptionsResolver(defaultOptions);
1715

1816
const quotesReg = /"/g;
1917
export const escapeQuotes = (s: string) => s.replace(quotesReg, '\\"');

packages/shared/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
"prepublishOnly": "nr build",
3737
"watch": "tsdown --watch"
3838
},
39+
"dependencies": {
40+
"defu": "^6.1.4"
41+
},
3942
"devDependencies": {
4043
"unplugin": "catalog:",
4144
"vite": "catalog:"

packages/shared/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { FilterPattern } from "unplugin";
22

33
export interface BaseOptions {
4+
root?: string;
5+
tsconfigPath?: string;
46
include?: FilterPattern;
57
exclude?: FilterPattern;
68
}

packages/shared/src/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
1+
import { isAbsolute, join } from "node:path";
2+
3+
import type { BaseOptions } from "@vue.ts/shared";
4+
import { defu } from "defu";
5+
16
const windowsPathReg = /\\/g;
27
export const normalizePath = (id: string) => id.replace(windowsPathReg, "/");
8+
9+
export const createOptionsResolver =
10+
<T extends Required<BaseOptions>>(defaultOptions: T) =>
11+
(rawOptions: Partial<T>) => {
12+
const mergedOptions = defu(rawOptions, defaultOptions);
13+
if (!isAbsolute(mergedOptions.tsconfigPath)) {
14+
mergedOptions.tsconfigPath = join(
15+
mergedOptions.root,
16+
mergedOptions.tsconfigPath,
17+
);
18+
}
19+
20+
return mergedOptions;
21+
};

packages/tsx-auto-props/src/core/utils.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import { join } from "node:path";
2-
1+
import { createOptionsResolver } from "@vue.ts/shared";
32
import ts from "typescript";
43

5-
import type { Options, ResolvedOptions } from "../types";
4+
import type { ResolvedOptions } from "../types";
5+
6+
const defaultOptions: ResolvedOptions = {
7+
root: process.cwd(),
8+
include: ["**/*.vue", "**/*.tsx"],
9+
exclude: ["node_modules/**"],
10+
tsconfigPath: "tsconfig.json",
11+
};
612

7-
export const resolveOptions = (rawOptions: Options): ResolvedOptions => ({
8-
include: rawOptions.include ?? ["**/*.vue", "**/*.tsx"],
9-
exclude: rawOptions.exclude ?? ["node_modules/**"],
10-
tsconfigPath: rawOptions.tsconfigPath ?? join(process.cwd(), "tsconfig.json"),
11-
});
13+
export const resolveOptions = createOptionsResolver(defaultOptions);
1214

1315
export function getNodeAssignNode(node: ts.Node) {
1416
let parent: ts.Node | null = null;
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type { BaseOptions } from "@vue.ts/shared";
22

3-
export interface Options extends BaseOptions {
4-
tsconfigPath?: string;
5-
}
3+
export type Options = BaseOptions;
64

75
export type ResolvedOptions = Required<Options>;

pnpm-lock.yaml

Lines changed: 20 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)