-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.ts
More file actions
149 lines (127 loc) · 3.97 KB
/
Copy pathtypes.ts
File metadata and controls
149 lines (127 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import type {
Config as PrettierConfig,
Options as PrettierOptions,
} from 'prettier';
import type { FmtCacheEntry } from './cacheStore.ts';
/** Plugin objects cannot cross worker boundaries and are not planned for support. */
type FmtPluginSpecifier = string | URL;
interface FmtBuiltinOptions {
/**
* Sort `package.json` fields using `sort-package-json`.
* @default false
*/
sortPackageJson?: boolean;
}
type ResolvedFmtOptions = PrettierOptions & FmtBuiltinOptions;
type FmtOptions = Omit<PrettierOptions, 'plugins'> &
FmtBuiltinOptions & {
plugins?: FmtPluginSpecifier[];
};
type PrettierOverride = NonNullable<PrettierConfig['overrides']>[number];
type FmtOverride = Omit<PrettierOverride, 'options'> & {
options?: FmtOptions;
};
interface FmtConfig
extends Omit<PrettierConfig, 'plugins' | 'overrides'>, FmtBuiltinOptions {
plugins?: FmtPluginSpecifier[];
overrides?: FmtOverride[];
/** Gitignore-compatible patterns relative to the Rstack config root. */
ignorePatterns?: string[];
}
type FmtConfigDefinition = FmtConfig | (() => FmtConfig | Promise<FmtConfig>);
interface ResolvedFmtOverride {
/** Matches a path relative to the config root. */
matches: (relativeFilePath: string) => boolean;
options?: ResolvedFmtOptions;
}
/** Internal project config before per-file rules are applied. */
interface ResolvedFmtConfig {
/** Root for relative patterns and plugin paths. */
rootPath: string;
/** Shared Prettier options before per-file overrides. */
baseOptions: ResolvedFmtOptions;
/** Precompiled per-file override rules. */
overrides: ResolvedFmtOverride[];
/** Root-relative ignore patterns. */
ignorePatterns: string[];
}
interface DiscoverFmtFilesOptions {
/** Absolute directory used to resolve input paths. */
cwd: string;
/** Absolute directory to exclude from formatting. */
excludedDirPath?: string;
/** Files, directories, and positive or negative globs. Defaults to the current directory. */
patterns?: string[];
/** Ignore files resolved from `cwd`; each file's patterns are relative to its own directory. */
ignorePaths?: string[];
/** Whether files inside node_modules may be discovered. */
withNodeModules?: boolean;
/** Resolved project config applied to discovered files. */
config: ResolvedFmtConfig;
}
interface FmtFileRequest {
/** Absolute path to the file. */
path: string;
/** Final per-file options with project plugins resolved. */
options: ResolvedFmtOptions;
}
interface FmtCacheContext {
/** Persistent cache file to load and update. */
filePath: string;
/** Root used to create portable per-file cache keys. */
rootPath: string;
}
interface FmtFileCache {
entry: FmtCacheEntry | undefined;
optionsHash: string;
}
interface FmtWorkerResult {
status: 'changed' | 'unchanged' | 'unsupported';
cacheEntry?: FmtCacheEntry;
}
type FmtMode = 'write' | 'check' | 'list-different';
type FmtExitCode = 0 | 1 | 2;
interface RunFmtFilesOptions {
/** Files with their final per-file Prettier options. */
files: FmtFileRequest[];
/** Whether to write changes or only report them. */
mode: FmtMode;
/** Maximum number of formatting workers. */
maxWorkers?: number;
/** Internal persistent cache context. */
cache?: FmtCacheContext;
}
interface SuccessfulFmtFileResult {
path: string;
status: 'written' | 'different';
}
interface FailedFmtFileResult {
path: string;
status: 'error';
error: unknown;
}
type FmtFileResult = SuccessfulFmtFileResult | FailedFmtFileResult;
interface FmtRunResult {
files: FmtFileResult[];
/** Number of processed files, excluding files with no supported parser. */
processedFileCount: number;
/** Recommended CLI exit code. */
exitCode: FmtExitCode;
}
export type {
DiscoverFmtFilesOptions,
FmtCacheContext,
FmtConfig,
FmtConfigDefinition,
FmtExitCode,
FmtFileResult,
FmtFileRequest,
FmtFileCache,
FmtMode,
FmtPluginSpecifier,
FmtRunResult,
FmtWorkerResult,
ResolvedFmtConfig,
ResolvedFmtOptions,
RunFmtFilesOptions,
};