ai-spec-dev 0.1.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 +387 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +4569 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/index.mjs +4546 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/index.d.mts +151 -0
- package/dist/index.d.ts +151 -0
- package/dist/index.js +4245 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4188 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +70 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,4188 @@
|
|
|
1
|
+
// core/spec-generator.ts
|
|
2
|
+
import { GoogleGenerativeAI } from "@google/generative-ai";
|
|
3
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
4
|
+
import OpenAI from "openai";
|
|
5
|
+
import { ProxyAgent } from "undici";
|
|
6
|
+
|
|
7
|
+
// prompts/spec.prompt.ts
|
|
8
|
+
var specPrompt = `You are an expert Software Architect. Your task is to convert the user's raw feature idea into a structured, detailed, and immediately actionable Markdown specification.
|
|
9
|
+
|
|
10
|
+
The spec MUST be written in Chinese (\u4E2D\u6587). Be comprehensive but focused \u2014 every section should contain practical, project-specific information derived from the provided project context.
|
|
11
|
+
|
|
12
|
+
Use the EXACT following template structure:
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# Feature Spec: {\u529F\u80FD\u540D\u79F0}
|
|
17
|
+
|
|
18
|
+
## 1. \u529F\u80FD\u6982\u8FF0 (Overview)
|
|
19
|
+
\u7528 2-3 \u53E5\u8BDD\u7B80\u6D01\u8BF4\u660E\u8FD9\u4E2A\u529F\u80FD\u662F\u4EC0\u4E48\uFF0C\u4EE5\u53CA\u5B83\u89E3\u51B3\u7684\u6838\u5FC3\u95EE\u9898\u3002
|
|
20
|
+
|
|
21
|
+
## 2. \u80CC\u666F\u4E0E\u52A8\u673A (Background)
|
|
22
|
+
- \u5F53\u524D\u5B58\u5728\u4EC0\u4E48\u95EE\u9898\u6216\u7F3A\u5931\uFF1F
|
|
23
|
+
- \u4E3A\u4EC0\u4E48\u73B0\u5728\u9700\u8981\u6784\u5EFA\u8FD9\u4E2A\u529F\u80FD\uFF1F
|
|
24
|
+
- \u5BF9\u7528\u6237/\u4E1A\u52A1\u7684\u4EF7\u503C\u662F\u4EC0\u4E48\uFF1F
|
|
25
|
+
|
|
26
|
+
## 3. \u7528\u6237\u6545\u4E8B (User Stories)
|
|
27
|
+
- \u4F5C\u4E3A **[\u7528\u6237\u89D2\u8272]**\uFF0C\u6211\u5E0C\u671B **[\u5B8C\u6210\u67D0\u64CD\u4F5C]**\uFF0C\u4EE5\u4FBF **[\u83B7\u5F97\u67D0\u4EF7\u503C]**
|
|
28
|
+
\uFF08\u5217\u51FA 2-4 \u4E2A\u6838\u5FC3\u7528\u6237\u6545\u4E8B\uFF0C\u8986\u76D6\u4E3B\u8981\u4F7F\u7528\u573A\u666F\uFF09
|
|
29
|
+
|
|
30
|
+
## 4. \u529F\u80FD\u9700\u6C42 (Functional Requirements)
|
|
31
|
+
|
|
32
|
+
### 4.1 \u6838\u5FC3\u529F\u80FD
|
|
33
|
+
- [ ] \u9700\u6C42 1\uFF1A\u8BE6\u7EC6\u63CF\u8FF0\u671F\u671B\u884C\u4E3A
|
|
34
|
+
- [ ] \u9700\u6C42 2\uFF1A\u8BE6\u7EC6\u63CF\u8FF0\u671F\u671B\u884C\u4E3A
|
|
35
|
+
|
|
36
|
+
### 4.2 \u8FB9\u754C\u6761\u4EF6\u4E0E\u9519\u8BEF\u5904\u7406
|
|
37
|
+
- \u8F93\u5165\u9A8C\u8BC1\u89C4\u5219\uFF08\u5B57\u6BB5\u7C7B\u578B\u3001\u957F\u5EA6\u3001\u683C\u5F0F\u8981\u6C42\uFF09
|
|
38
|
+
- \u9519\u8BEF\u573A\u666F\u53CA\u5BF9\u5E94\u7684\u5904\u7406\u7B56\u7565
|
|
39
|
+
- \u6743\u9650\u63A7\u5236\u8981\u6C42\uFF08\u54EA\u4E9B\u89D2\u8272\u53EF\u4EE5\u8BBF\u95EE\uFF09
|
|
40
|
+
|
|
41
|
+
## 5. API \u8BBE\u8BA1 (API Design)
|
|
42
|
+
|
|
43
|
+
### \u63A5\u53E3\u5217\u8868
|
|
44
|
+
| Method | Endpoint | Auth Required | Description |
|
|
45
|
+
|--------|----------|:-------------:|-------------|
|
|
46
|
+
| POST | /api/... | \u2705 | \u521B\u5EFA... |
|
|
47
|
+
| GET | /api/... | \u2705 | \u83B7\u53D6... |
|
|
48
|
+
|
|
49
|
+
### \u8BF7\u6C42/\u54CD\u5E94\u793A\u4F8B
|
|
50
|
+
|
|
51
|
+
**[\u63A5\u53E3\u540D\u79F0]**
|
|
52
|
+
|
|
53
|
+
\`\`\`
|
|
54
|
+
POST /api/example
|
|
55
|
+
Authorization: Bearer {token}
|
|
56
|
+
Content-Type: application/json
|
|
57
|
+
\`\`\`
|
|
58
|
+
|
|
59
|
+
\u8BF7\u6C42\u4F53\uFF1A
|
|
60
|
+
\`\`\`json
|
|
61
|
+
{
|
|
62
|
+
"field1": "string",
|
|
63
|
+
"field2": 0
|
|
64
|
+
}
|
|
65
|
+
\`\`\`
|
|
66
|
+
|
|
67
|
+
\u6210\u529F\u54CD\u5E94 (200)\uFF1A
|
|
68
|
+
\`\`\`json
|
|
69
|
+
{
|
|
70
|
+
"code": 0,
|
|
71
|
+
"message": "success",
|
|
72
|
+
"data": {}
|
|
73
|
+
}
|
|
74
|
+
\`\`\`
|
|
75
|
+
|
|
76
|
+
\u9519\u8BEF\u54CD\u5E94\uFF1A
|
|
77
|
+
\`\`\`json
|
|
78
|
+
{
|
|
79
|
+
"code": 40001,
|
|
80
|
+
"message": "\u9519\u8BEF\u63CF\u8FF0"
|
|
81
|
+
}
|
|
82
|
+
\`\`\`
|
|
83
|
+
|
|
84
|
+
## 6. \u6570\u636E\u6A21\u578B (Data Model)
|
|
85
|
+
\u63CF\u8FF0\u9700\u8981\u65B0\u589E\u6216\u4FEE\u6539\u7684\u6570\u636E\u5E93\u8868/\u5B57\u6BB5\uFF08\u4F7F\u7528 Prisma Schema \u683C\u5F0F\uFF09\u3002
|
|
86
|
+
|
|
87
|
+
\`\`\`prisma
|
|
88
|
+
model ExampleModel {
|
|
89
|
+
id Int @id @default(autoincrement())
|
|
90
|
+
createdAt DateTime @default(now())
|
|
91
|
+
updatedAt DateTime @updatedAt
|
|
92
|
+
}
|
|
93
|
+
\`\`\`
|
|
94
|
+
|
|
95
|
+
## 7. \u975E\u529F\u80FD\u6027\u9700\u6C42 (Non-functional Requirements)
|
|
96
|
+
- **\u6027\u80FD**: \u63A5\u53E3\u54CD\u5E94\u65F6\u95F4\u8981\u6C42\uFF0C\u5E76\u53D1\u91CF\u9884\u4F30
|
|
97
|
+
- **\u5B89\u5168**: \u8BA4\u8BC1\u6388\u6743\u673A\u5236\uFF0C\u654F\u611F\u6570\u636E\u7684\u5904\u7406\u65B9\u5F0F
|
|
98
|
+
- **\u53EF\u9760\u6027**: \u5E42\u7B49\u6027\u8981\u6C42\uFF0C\u91CD\u8BD5\u7B56\u7565
|
|
99
|
+
- **\u53EF\u7EF4\u62A4\u6027**: \u65E5\u5FD7\u8BB0\u5F55\u8981\u6C42\uFF0C\u76D1\u63A7\u6307\u6807
|
|
100
|
+
|
|
101
|
+
## 8. \u5B9E\u65BD\u8981\u70B9 (Implementation Notes)
|
|
102
|
+
- **\u96C6\u6210\u70B9**: \u9700\u8981\u4E0E\u54EA\u4E9B\u73B0\u6709\u6A21\u5757\u3001\u670D\u52A1\u6216\u5916\u90E8 API \u4EA4\u4E92
|
|
103
|
+
- **\u5B9E\u65BD\u987A\u5E8F**: \u5EFA\u8BAE\u7684\u5F00\u53D1\u6B65\u9AA4\uFF08\u4F8B\uFF1A\u6570\u636E\u6A21\u578B \u2192 \u670D\u52A1\u5C42 \u2192 \u63A7\u5236\u5668 \u2192 \u8DEF\u7531 \u2192 \u6D4B\u8BD5\uFF09
|
|
104
|
+
- **\u6280\u672F\u6CE8\u610F\u4E8B\u9879**: \u6F5C\u5728\u7684\u6280\u672F\u96BE\u70B9\uFF0C\u63A8\u8350\u7684\u5E93\u6216\u5B9E\u73B0\u65B9\u6848
|
|
105
|
+
- **\u6D4B\u8BD5\u8981\u70B9**: \u5173\u952E\u7684\u5355\u5143\u6D4B\u8BD5\u548C\u96C6\u6210\u6D4B\u8BD5\u573A\u666F
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
\u6839\u636E\u7528\u6237\u7684\u60F3\u6CD5\u548C\u9879\u76EE\u4E0A\u4E0B\u6587\u751F\u6210\u4E0A\u8FF0\u5B8C\u6574 Spec\u3002\u786E\u4FDD API \u8BBE\u8BA1\u4E0E\u73B0\u6709\u9879\u76EE\u7684\u8DEF\u7531\u98CE\u683C\u3001\u9519\u8BEF\u7801\u89C4\u8303\u4FDD\u6301\u4E00\u81F4\uFF0C\u6570\u636E\u6A21\u578B\u4E0E\u73B0\u6709 Prisma Schema \u534F\u8C03\u3002`;
|
|
110
|
+
|
|
111
|
+
// core/spec-generator.ts
|
|
112
|
+
function geminiRequestOptions() {
|
|
113
|
+
const proxyUrl = process.env.GEMINI_PROXY || process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy;
|
|
114
|
+
if (!proxyUrl) return void 0;
|
|
115
|
+
return { fetchOptions: { dispatcher: new ProxyAgent(proxyUrl) } };
|
|
116
|
+
}
|
|
117
|
+
var PROVIDER_CATALOG = {
|
|
118
|
+
// ── International ──────────────────────────────────────────────────────────
|
|
119
|
+
gemini: {
|
|
120
|
+
displayName: "Google Gemini",
|
|
121
|
+
description: "Google AI Studio \u2014 Gemini 2.5 / 1.5 series",
|
|
122
|
+
models: [
|
|
123
|
+
"gemini-2.5-flash",
|
|
124
|
+
"gemini-2.5-pro",
|
|
125
|
+
"gemini-1.5-pro",
|
|
126
|
+
"gemini-1.5-flash"
|
|
127
|
+
],
|
|
128
|
+
envKey: "GEMINI_API_KEY"
|
|
129
|
+
},
|
|
130
|
+
claude: {
|
|
131
|
+
displayName: "Anthropic Claude",
|
|
132
|
+
description: "Anthropic \u2014 Claude 4.x series",
|
|
133
|
+
models: [
|
|
134
|
+
"claude-sonnet-4-6",
|
|
135
|
+
"claude-opus-4-6",
|
|
136
|
+
"claude-haiku-4-5"
|
|
137
|
+
],
|
|
138
|
+
envKey: "ANTHROPIC_API_KEY"
|
|
139
|
+
},
|
|
140
|
+
openai: {
|
|
141
|
+
displayName: "OpenAI",
|
|
142
|
+
description: "OpenAI \u2014 GPT-4o / o1 series",
|
|
143
|
+
models: ["gpt-4o", "gpt-4o-mini", "gpt-4-turbo", "o1-mini"],
|
|
144
|
+
envKey: "OPENAI_API_KEY",
|
|
145
|
+
baseURL: "https://api.openai.com/v1"
|
|
146
|
+
},
|
|
147
|
+
// ── Chinese Models (OpenAI-compatible) ────────────────────────────────────
|
|
148
|
+
qwen: {
|
|
149
|
+
displayName: "\u901A\u4E49\u5343\u95EE (Qwen)",
|
|
150
|
+
description: "\u963F\u91CC\u4E91\u767E\u70BC DashScope \u2014 qwen-max / plus / turbo",
|
|
151
|
+
models: [
|
|
152
|
+
"qwen-max",
|
|
153
|
+
"qwen-max-latest",
|
|
154
|
+
"qwen-plus",
|
|
155
|
+
"qwen-plus-latest",
|
|
156
|
+
"qwen-turbo",
|
|
157
|
+
"qwen-long"
|
|
158
|
+
],
|
|
159
|
+
envKey: "DASHSCOPE_API_KEY",
|
|
160
|
+
baseURL: "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
|
161
|
+
},
|
|
162
|
+
minimax: {
|
|
163
|
+
displayName: "MiniMax",
|
|
164
|
+
description: "MiniMax AI \u2014 MiniMax-Text-01 / abab series",
|
|
165
|
+
models: [
|
|
166
|
+
"MiniMax-Text-01",
|
|
167
|
+
"abab6.5s-chat",
|
|
168
|
+
"abab6.5g-chat",
|
|
169
|
+
"abab5.5-chat"
|
|
170
|
+
],
|
|
171
|
+
envKey: "MINIMAX_API_KEY",
|
|
172
|
+
baseURL: "https://api.minimax.chat/v1"
|
|
173
|
+
},
|
|
174
|
+
glm: {
|
|
175
|
+
displayName: "\u667A\u8C31 GLM (Zhipu AI)",
|
|
176
|
+
description: "\u667A\u8C31 AI \u2014 GLM-4 plus / flash / air series",
|
|
177
|
+
models: [
|
|
178
|
+
"glm-4-plus",
|
|
179
|
+
"glm-4",
|
|
180
|
+
"glm-4-flash",
|
|
181
|
+
"glm-4-air",
|
|
182
|
+
"glm-4-airx",
|
|
183
|
+
"glm-4-long"
|
|
184
|
+
],
|
|
185
|
+
envKey: "ZHIPU_API_KEY",
|
|
186
|
+
baseURL: "https://open.bigmodel.cn/api/paas/v4/"
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
var SUPPORTED_PROVIDERS = Object.keys(PROVIDER_CATALOG);
|
|
190
|
+
var DEFAULT_MODELS = Object.fromEntries(
|
|
191
|
+
Object.entries(PROVIDER_CATALOG).map(([k2, v2]) => [k2, v2.models[0]])
|
|
192
|
+
);
|
|
193
|
+
var ENV_KEY_MAP = Object.fromEntries(
|
|
194
|
+
Object.entries(PROVIDER_CATALOG).map(([k2, v2]) => [k2, v2.envKey])
|
|
195
|
+
);
|
|
196
|
+
var GeminiProvider = class {
|
|
197
|
+
genAI;
|
|
198
|
+
providerName = "gemini";
|
|
199
|
+
modelName;
|
|
200
|
+
constructor(apiKey, modelName = PROVIDER_CATALOG.gemini.models[0]) {
|
|
201
|
+
this.genAI = new GoogleGenerativeAI(apiKey);
|
|
202
|
+
this.modelName = modelName;
|
|
203
|
+
}
|
|
204
|
+
async generate(prompt, systemInstruction) {
|
|
205
|
+
const model = this.genAI.getGenerativeModel(
|
|
206
|
+
{ model: this.modelName, ...systemInstruction ? { systemInstruction } : {} },
|
|
207
|
+
geminiRequestOptions()
|
|
208
|
+
);
|
|
209
|
+
const result = await model.generateContent(prompt);
|
|
210
|
+
return result.response.text();
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
var ClaudeProvider = class {
|
|
214
|
+
client;
|
|
215
|
+
providerName = "claude";
|
|
216
|
+
modelName;
|
|
217
|
+
constructor(apiKey, modelName = PROVIDER_CATALOG.claude.models[0]) {
|
|
218
|
+
this.client = new Anthropic({ apiKey });
|
|
219
|
+
this.modelName = modelName;
|
|
220
|
+
}
|
|
221
|
+
async generate(prompt, systemInstruction) {
|
|
222
|
+
const message = await this.client.messages.create({
|
|
223
|
+
model: this.modelName,
|
|
224
|
+
max_tokens: 8192,
|
|
225
|
+
...systemInstruction ? { system: systemInstruction } : {},
|
|
226
|
+
messages: [{ role: "user", content: prompt }]
|
|
227
|
+
});
|
|
228
|
+
const block = message.content[0];
|
|
229
|
+
if (block.type === "text") return block.text;
|
|
230
|
+
throw new Error("Unexpected response type from Claude API");
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
var OpenAICompatibleProvider = class {
|
|
234
|
+
client;
|
|
235
|
+
providerName;
|
|
236
|
+
modelName;
|
|
237
|
+
constructor(providerName, apiKey, modelName, baseURL) {
|
|
238
|
+
this.providerName = providerName;
|
|
239
|
+
this.modelName = modelName;
|
|
240
|
+
this.client = new OpenAI({
|
|
241
|
+
apiKey,
|
|
242
|
+
...baseURL ? { baseURL } : {}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
async generate(prompt, systemInstruction) {
|
|
246
|
+
const messages = [];
|
|
247
|
+
if (systemInstruction) {
|
|
248
|
+
messages.push({ role: "system", content: systemInstruction });
|
|
249
|
+
}
|
|
250
|
+
messages.push({ role: "user", content: prompt });
|
|
251
|
+
const completion = await this.client.chat.completions.create({
|
|
252
|
+
model: this.modelName,
|
|
253
|
+
messages
|
|
254
|
+
});
|
|
255
|
+
return completion.choices[0].message.content ?? "";
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
function createProvider(providerName, apiKey, modelName) {
|
|
259
|
+
const meta = PROVIDER_CATALOG[providerName];
|
|
260
|
+
if (!meta) {
|
|
261
|
+
throw new Error(
|
|
262
|
+
`Unknown provider: "${providerName}". Valid options: ${SUPPORTED_PROVIDERS.join(", ")}`
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
const model = modelName || meta.models[0];
|
|
266
|
+
switch (providerName) {
|
|
267
|
+
case "gemini":
|
|
268
|
+
return new GeminiProvider(apiKey, model);
|
|
269
|
+
case "claude":
|
|
270
|
+
return new ClaudeProvider(apiKey, model);
|
|
271
|
+
// All OpenAI-compatible providers (openai, qwen, minimax, glm)
|
|
272
|
+
default:
|
|
273
|
+
return new OpenAICompatibleProvider(providerName, apiKey, model, meta.baseURL);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
var SpecGenerator = class {
|
|
277
|
+
constructor(provider) {
|
|
278
|
+
this.provider = provider;
|
|
279
|
+
}
|
|
280
|
+
async generateSpec(idea, context) {
|
|
281
|
+
const parts = [idea];
|
|
282
|
+
if (context) {
|
|
283
|
+
if (context.constitution) {
|
|
284
|
+
parts.push(
|
|
285
|
+
`
|
|
286
|
+
|
|
287
|
+
=== \u9879\u76EE\u5BAA\u6CD5 (Project Constitution \u2014 MUST follow these rules) ===
|
|
288
|
+
${context.constitution}`
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
parts.push(`
|
|
292
|
+
|
|
293
|
+
=== \u9879\u76EE\u4E0A\u4E0B\u6587 (Project Context) ===`);
|
|
294
|
+
if (context.techStack.length > 0) {
|
|
295
|
+
parts.push(`\u6280\u672F\u6808: ${context.techStack.join(", ")}`);
|
|
296
|
+
}
|
|
297
|
+
if (context.dependencies.length > 0) {
|
|
298
|
+
parts.push(`\u4E3B\u8981\u4F9D\u8D56: ${context.dependencies.slice(0, 25).join(", ")}`);
|
|
299
|
+
}
|
|
300
|
+
if (context.apiStructure.length > 0) {
|
|
301
|
+
parts.push(
|
|
302
|
+
`
|
|
303
|
+
\u73B0\u6709 API \u6587\u4EF6:
|
|
304
|
+
${context.apiStructure.slice(0, 10).map((f) => ` - ${f}`).join("\n")}`
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
if (context.routeSummary) {
|
|
308
|
+
parts.push(`
|
|
309
|
+
\u8DEF\u7531\u7ED3\u6784\uFF08\u6458\u8981\uFF09:
|
|
310
|
+
${context.routeSummary}`);
|
|
311
|
+
}
|
|
312
|
+
if (context.schema) {
|
|
313
|
+
parts.push(`
|
|
314
|
+
\u6570\u636E\u5E93 Schema (Prisma):
|
|
315
|
+
${context.schema.slice(0, 3e3)}`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return this.provider.generate(parts.join("\n"), specPrompt);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
// core/context-loader.ts
|
|
323
|
+
import * as fs2 from "fs-extra";
|
|
324
|
+
import * as path from "path";
|
|
325
|
+
|
|
326
|
+
// node_modules/glob/dist/esm/index.min.js
|
|
327
|
+
import { fileURLToPath as Wi } from "url";
|
|
328
|
+
import { posix as mi, win32 as re } from "path";
|
|
329
|
+
import { fileURLToPath as gi } from "url";
|
|
330
|
+
import { lstatSync as wi, readdir as yi, readdirSync as bi, readlinkSync as Si, realpathSync as Ei } from "fs";
|
|
331
|
+
import * as xi from "fs";
|
|
332
|
+
import { lstat as Ci, readdir as Ti, readlink as Ai, realpath as ki } from "fs/promises";
|
|
333
|
+
import { EventEmitter as ee } from "events";
|
|
334
|
+
import Pe from "stream";
|
|
335
|
+
import { StringDecoder as ni } from "string_decoder";
|
|
336
|
+
var Gt = (n7, t, e) => {
|
|
337
|
+
let s = n7 instanceof RegExp ? ce(n7, e) : n7, i = t instanceof RegExp ? ce(t, e) : t, r = s !== null && i != null && ss(s, i, e);
|
|
338
|
+
return r && { start: r[0], end: r[1], pre: e.slice(0, r[0]), body: e.slice(r[0] + s.length, r[1]), post: e.slice(r[1] + i.length) };
|
|
339
|
+
};
|
|
340
|
+
var ce = (n7, t) => {
|
|
341
|
+
let e = t.match(n7);
|
|
342
|
+
return e ? e[0] : null;
|
|
343
|
+
};
|
|
344
|
+
var ss = (n7, t, e) => {
|
|
345
|
+
let s, i, r, o, h, a = e.indexOf(n7), l = e.indexOf(t, a + 1), u = a;
|
|
346
|
+
if (a >= 0 && l > 0) {
|
|
347
|
+
if (n7 === t) return [a, l];
|
|
348
|
+
for (s = [], r = e.length; u >= 0 && !h; ) {
|
|
349
|
+
if (u === a) s.push(u), a = e.indexOf(n7, u + 1);
|
|
350
|
+
else if (s.length === 1) {
|
|
351
|
+
let c = s.pop();
|
|
352
|
+
c !== void 0 && (h = [c, l]);
|
|
353
|
+
} else i = s.pop(), i !== void 0 && i < r && (r = i, o = l), l = e.indexOf(t, u + 1);
|
|
354
|
+
u = a < l && a >= 0 ? a : l;
|
|
355
|
+
}
|
|
356
|
+
s.length && o !== void 0 && (h = [r, o]);
|
|
357
|
+
}
|
|
358
|
+
return h;
|
|
359
|
+
};
|
|
360
|
+
var fe = "\0SLASH" + Math.random() + "\0";
|
|
361
|
+
var ue = "\0OPEN" + Math.random() + "\0";
|
|
362
|
+
var qt = "\0CLOSE" + Math.random() + "\0";
|
|
363
|
+
var de = "\0COMMA" + Math.random() + "\0";
|
|
364
|
+
var pe = "\0PERIOD" + Math.random() + "\0";
|
|
365
|
+
var is = new RegExp(fe, "g");
|
|
366
|
+
var rs = new RegExp(ue, "g");
|
|
367
|
+
var ns = new RegExp(qt, "g");
|
|
368
|
+
var os = new RegExp(de, "g");
|
|
369
|
+
var hs = new RegExp(pe, "g");
|
|
370
|
+
var as = /\\\\/g;
|
|
371
|
+
var ls = /\\{/g;
|
|
372
|
+
var cs = /\\}/g;
|
|
373
|
+
var fs = /\\,/g;
|
|
374
|
+
var us = /\\./g;
|
|
375
|
+
var ds = 1e5;
|
|
376
|
+
function Ht(n7) {
|
|
377
|
+
return isNaN(n7) ? n7.charCodeAt(0) : parseInt(n7, 10);
|
|
378
|
+
}
|
|
379
|
+
function ps(n7) {
|
|
380
|
+
return n7.replace(as, fe).replace(ls, ue).replace(cs, qt).replace(fs, de).replace(us, pe);
|
|
381
|
+
}
|
|
382
|
+
function ms(n7) {
|
|
383
|
+
return n7.replace(is, "\\").replace(rs, "{").replace(ns, "}").replace(os, ",").replace(hs, ".");
|
|
384
|
+
}
|
|
385
|
+
function me(n7) {
|
|
386
|
+
if (!n7) return [""];
|
|
387
|
+
let t = [], e = Gt("{", "}", n7);
|
|
388
|
+
if (!e) return n7.split(",");
|
|
389
|
+
let { pre: s, body: i, post: r } = e, o = s.split(",");
|
|
390
|
+
o[o.length - 1] += "{" + i + "}";
|
|
391
|
+
let h = me(r);
|
|
392
|
+
return r.length && (o[o.length - 1] += h.shift(), o.push.apply(o, h)), t.push.apply(t, o), t;
|
|
393
|
+
}
|
|
394
|
+
function ge(n7, t = {}) {
|
|
395
|
+
if (!n7) return [];
|
|
396
|
+
let { max: e = ds } = t;
|
|
397
|
+
return n7.slice(0, 2) === "{}" && (n7 = "\\{\\}" + n7.slice(2)), ht(ps(n7), e, true).map(ms);
|
|
398
|
+
}
|
|
399
|
+
function gs(n7) {
|
|
400
|
+
return "{" + n7 + "}";
|
|
401
|
+
}
|
|
402
|
+
function ws(n7) {
|
|
403
|
+
return /^-?0\d/.test(n7);
|
|
404
|
+
}
|
|
405
|
+
function ys(n7, t) {
|
|
406
|
+
return n7 <= t;
|
|
407
|
+
}
|
|
408
|
+
function bs(n7, t) {
|
|
409
|
+
return n7 >= t;
|
|
410
|
+
}
|
|
411
|
+
function ht(n7, t, e) {
|
|
412
|
+
let s = [], i = Gt("{", "}", n7);
|
|
413
|
+
if (!i) return [n7];
|
|
414
|
+
let r = i.pre, o = i.post.length ? ht(i.post, t, false) : [""];
|
|
415
|
+
if (/\$$/.test(i.pre)) for (let h = 0; h < o.length && h < t; h++) {
|
|
416
|
+
let a = r + "{" + i.body + "}" + o[h];
|
|
417
|
+
s.push(a);
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
let h = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(i.body), a = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(i.body), l = h || a, u = i.body.indexOf(",") >= 0;
|
|
421
|
+
if (!l && !u) return i.post.match(/,(?!,).*\}/) ? (n7 = i.pre + "{" + i.body + qt + i.post, ht(n7, t, true)) : [n7];
|
|
422
|
+
let c;
|
|
423
|
+
if (l) c = i.body.split(/\.\./);
|
|
424
|
+
else if (c = me(i.body), c.length === 1 && c[0] !== void 0 && (c = ht(c[0], t, false).map(gs), c.length === 1)) return o.map((f) => i.pre + c[0] + f);
|
|
425
|
+
let d;
|
|
426
|
+
if (l && c[0] !== void 0 && c[1] !== void 0) {
|
|
427
|
+
let f = Ht(c[0]), m = Ht(c[1]), p = Math.max(c[0].length, c[1].length), w = c.length === 3 && c[2] !== void 0 ? Math.abs(Ht(c[2])) : 1, g = ys;
|
|
428
|
+
m < f && (w *= -1, g = bs);
|
|
429
|
+
let E = c.some(ws);
|
|
430
|
+
d = [];
|
|
431
|
+
for (let y = f; g(y, m); y += w) {
|
|
432
|
+
let b;
|
|
433
|
+
if (a) b = String.fromCharCode(y), b === "\\" && (b = "");
|
|
434
|
+
else if (b = String(y), E) {
|
|
435
|
+
let z = p - b.length;
|
|
436
|
+
if (z > 0) {
|
|
437
|
+
let $ = new Array(z + 1).join("0");
|
|
438
|
+
y < 0 ? b = "-" + $ + b.slice(1) : b = $ + b;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
d.push(b);
|
|
442
|
+
}
|
|
443
|
+
} else {
|
|
444
|
+
d = [];
|
|
445
|
+
for (let f = 0; f < c.length; f++) d.push.apply(d, ht(c[f], t, false));
|
|
446
|
+
}
|
|
447
|
+
for (let f = 0; f < d.length; f++) for (let m = 0; m < o.length && s.length < t; m++) {
|
|
448
|
+
let p = r + d[f] + o[m];
|
|
449
|
+
(!e || l || p) && s.push(p);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return s;
|
|
453
|
+
}
|
|
454
|
+
var at = (n7) => {
|
|
455
|
+
if (typeof n7 != "string") throw new TypeError("invalid pattern");
|
|
456
|
+
if (n7.length > 65536) throw new TypeError("pattern is too long");
|
|
457
|
+
};
|
|
458
|
+
var Ss = { "[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true], "[:alpha:]": ["\\p{L}\\p{Nl}", true], "[:ascii:]": ["\\x00-\\x7f", false], "[:blank:]": ["\\p{Zs}\\t", true], "[:cntrl:]": ["\\p{Cc}", true], "[:digit:]": ["\\p{Nd}", true], "[:graph:]": ["\\p{Z}\\p{C}", true, true], "[:lower:]": ["\\p{Ll}", true], "[:print:]": ["\\p{C}", true], "[:punct:]": ["\\p{P}", true], "[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", true], "[:upper:]": ["\\p{Lu}", true], "[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", true], "[:xdigit:]": ["A-Fa-f0-9", false] };
|
|
459
|
+
var lt = (n7) => n7.replace(/[[\]\\-]/g, "\\$&");
|
|
460
|
+
var Es = (n7) => n7.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
461
|
+
var we = (n7) => n7.join("");
|
|
462
|
+
var ye = (n7, t) => {
|
|
463
|
+
let e = t;
|
|
464
|
+
if (n7.charAt(e) !== "[") throw new Error("not in a brace expression");
|
|
465
|
+
let s = [], i = [], r = e + 1, o = false, h = false, a = false, l = false, u = e, c = "";
|
|
466
|
+
t: for (; r < n7.length; ) {
|
|
467
|
+
let p = n7.charAt(r);
|
|
468
|
+
if ((p === "!" || p === "^") && r === e + 1) {
|
|
469
|
+
l = true, r++;
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
if (p === "]" && o && !a) {
|
|
473
|
+
u = r + 1;
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
if (o = true, p === "\\" && !a) {
|
|
477
|
+
a = true, r++;
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
if (p === "[" && !a) {
|
|
481
|
+
for (let [w, [g, S, E]] of Object.entries(Ss)) if (n7.startsWith(w, r)) {
|
|
482
|
+
if (c) return ["$.", false, n7.length - e, true];
|
|
483
|
+
r += w.length, E ? i.push(g) : s.push(g), h = h || S;
|
|
484
|
+
continue t;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if (a = false, c) {
|
|
488
|
+
p > c ? s.push(lt(c) + "-" + lt(p)) : p === c && s.push(lt(p)), c = "", r++;
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
if (n7.startsWith("-]", r + 1)) {
|
|
492
|
+
s.push(lt(p + "-")), r += 2;
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
if (n7.startsWith("-", r + 1)) {
|
|
496
|
+
c = p, r += 2;
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
s.push(lt(p)), r++;
|
|
500
|
+
}
|
|
501
|
+
if (u < r) return ["", false, 0, false];
|
|
502
|
+
if (!s.length && !i.length) return ["$.", false, n7.length - e, true];
|
|
503
|
+
if (i.length === 0 && s.length === 1 && /^\\?.$/.test(s[0]) && !l) {
|
|
504
|
+
let p = s[0].length === 2 ? s[0].slice(-1) : s[0];
|
|
505
|
+
return [Es(p), false, u - e, false];
|
|
506
|
+
}
|
|
507
|
+
let d = "[" + (l ? "^" : "") + we(s) + "]", f = "[" + (l ? "" : "^") + we(i) + "]";
|
|
508
|
+
return [s.length && i.length ? "(" + d + "|" + f + ")" : s.length ? d : f, h, u - e, true];
|
|
509
|
+
};
|
|
510
|
+
var W = (n7, { windowsPathsNoEscape: t = false, magicalBraces: e = true } = {}) => e ? t ? n7.replace(/\[([^\/\\])\]/g, "$1") : n7.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1") : t ? n7.replace(/\[([^\/\\{}])\]/g, "$1") : n7.replace(/((?!\\).|^)\[([^\/\\{}])\]/g, "$1$2").replace(/\\([^\/{}])/g, "$1");
|
|
511
|
+
var xs = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]);
|
|
512
|
+
var be = (n7) => xs.has(n7);
|
|
513
|
+
var vs = "(?!(?:^|/)\\.\\.?(?:$|/))";
|
|
514
|
+
var Ct = "(?!\\.)";
|
|
515
|
+
var Cs = /* @__PURE__ */ new Set(["[", "."]);
|
|
516
|
+
var Ts = /* @__PURE__ */ new Set(["..", "."]);
|
|
517
|
+
var As = new Set("().*{}+?[]^$\\!");
|
|
518
|
+
var ks = (n7) => n7.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
519
|
+
var Kt = "[^/]";
|
|
520
|
+
var Se = Kt + "*?";
|
|
521
|
+
var Ee = Kt + "+?";
|
|
522
|
+
var Q = class n {
|
|
523
|
+
type;
|
|
524
|
+
#t;
|
|
525
|
+
#s;
|
|
526
|
+
#n = false;
|
|
527
|
+
#r = [];
|
|
528
|
+
#o;
|
|
529
|
+
#S;
|
|
530
|
+
#w;
|
|
531
|
+
#c = false;
|
|
532
|
+
#h;
|
|
533
|
+
#u;
|
|
534
|
+
#f = false;
|
|
535
|
+
constructor(t, e, s = {}) {
|
|
536
|
+
this.type = t, t && (this.#s = true), this.#o = e, this.#t = this.#o ? this.#o.#t : this, this.#h = this.#t === this ? s : this.#t.#h, this.#w = this.#t === this ? [] : this.#t.#w, t === "!" && !this.#t.#c && this.#w.push(this), this.#S = this.#o ? this.#o.#r.length : 0;
|
|
537
|
+
}
|
|
538
|
+
get hasMagic() {
|
|
539
|
+
if (this.#s !== void 0) return this.#s;
|
|
540
|
+
for (let t of this.#r) if (typeof t != "string" && (t.type || t.hasMagic)) return this.#s = true;
|
|
541
|
+
return this.#s;
|
|
542
|
+
}
|
|
543
|
+
toString() {
|
|
544
|
+
return this.#u !== void 0 ? this.#u : this.type ? this.#u = this.type + "(" + this.#r.map((t) => String(t)).join("|") + ")" : this.#u = this.#r.map((t) => String(t)).join("");
|
|
545
|
+
}
|
|
546
|
+
#a() {
|
|
547
|
+
if (this !== this.#t) throw new Error("should only call on root");
|
|
548
|
+
if (this.#c) return this;
|
|
549
|
+
this.toString(), this.#c = true;
|
|
550
|
+
let t;
|
|
551
|
+
for (; t = this.#w.pop(); ) {
|
|
552
|
+
if (t.type !== "!") continue;
|
|
553
|
+
let e = t, s = e.#o;
|
|
554
|
+
for (; s; ) {
|
|
555
|
+
for (let i = e.#S + 1; !s.type && i < s.#r.length; i++) for (let r of t.#r) {
|
|
556
|
+
if (typeof r == "string") throw new Error("string part in extglob AST??");
|
|
557
|
+
r.copyIn(s.#r[i]);
|
|
558
|
+
}
|
|
559
|
+
e = s, s = e.#o;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
return this;
|
|
563
|
+
}
|
|
564
|
+
push(...t) {
|
|
565
|
+
for (let e of t) if (e !== "") {
|
|
566
|
+
if (typeof e != "string" && !(e instanceof n && e.#o === this)) throw new Error("invalid part: " + e);
|
|
567
|
+
this.#r.push(e);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
toJSON() {
|
|
571
|
+
let t = this.type === null ? this.#r.slice().map((e) => typeof e == "string" ? e : e.toJSON()) : [this.type, ...this.#r.map((e) => e.toJSON())];
|
|
572
|
+
return this.isStart() && !this.type && t.unshift([]), this.isEnd() && (this === this.#t || this.#t.#c && this.#o?.type === "!") && t.push({}), t;
|
|
573
|
+
}
|
|
574
|
+
isStart() {
|
|
575
|
+
if (this.#t === this) return true;
|
|
576
|
+
if (!this.#o?.isStart()) return false;
|
|
577
|
+
if (this.#S === 0) return true;
|
|
578
|
+
let t = this.#o;
|
|
579
|
+
for (let e = 0; e < this.#S; e++) {
|
|
580
|
+
let s = t.#r[e];
|
|
581
|
+
if (!(s instanceof n && s.type === "!")) return false;
|
|
582
|
+
}
|
|
583
|
+
return true;
|
|
584
|
+
}
|
|
585
|
+
isEnd() {
|
|
586
|
+
if (this.#t === this || this.#o?.type === "!") return true;
|
|
587
|
+
if (!this.#o?.isEnd()) return false;
|
|
588
|
+
if (!this.type) return this.#o?.isEnd();
|
|
589
|
+
let t = this.#o ? this.#o.#r.length : 0;
|
|
590
|
+
return this.#S === t - 1;
|
|
591
|
+
}
|
|
592
|
+
copyIn(t) {
|
|
593
|
+
typeof t == "string" ? this.push(t) : this.push(t.clone(this));
|
|
594
|
+
}
|
|
595
|
+
clone(t) {
|
|
596
|
+
let e = new n(this.type, t);
|
|
597
|
+
for (let s of this.#r) e.copyIn(s);
|
|
598
|
+
return e;
|
|
599
|
+
}
|
|
600
|
+
static #i(t, e, s, i) {
|
|
601
|
+
let r = false, o = false, h = -1, a = false;
|
|
602
|
+
if (e.type === null) {
|
|
603
|
+
let f = s, m = "";
|
|
604
|
+
for (; f < t.length; ) {
|
|
605
|
+
let p = t.charAt(f++);
|
|
606
|
+
if (r || p === "\\") {
|
|
607
|
+
r = !r, m += p;
|
|
608
|
+
continue;
|
|
609
|
+
}
|
|
610
|
+
if (o) {
|
|
611
|
+
f === h + 1 ? (p === "^" || p === "!") && (a = true) : p === "]" && !(f === h + 2 && a) && (o = false), m += p;
|
|
612
|
+
continue;
|
|
613
|
+
} else if (p === "[") {
|
|
614
|
+
o = true, h = f, a = false, m += p;
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
if (!i.noext && be(p) && t.charAt(f) === "(") {
|
|
618
|
+
e.push(m), m = "";
|
|
619
|
+
let w = new n(p, e);
|
|
620
|
+
f = n.#i(t, w, f, i), e.push(w);
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
m += p;
|
|
624
|
+
}
|
|
625
|
+
return e.push(m), f;
|
|
626
|
+
}
|
|
627
|
+
let l = s + 1, u = new n(null, e), c = [], d = "";
|
|
628
|
+
for (; l < t.length; ) {
|
|
629
|
+
let f = t.charAt(l++);
|
|
630
|
+
if (r || f === "\\") {
|
|
631
|
+
r = !r, d += f;
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
if (o) {
|
|
635
|
+
l === h + 1 ? (f === "^" || f === "!") && (a = true) : f === "]" && !(l === h + 2 && a) && (o = false), d += f;
|
|
636
|
+
continue;
|
|
637
|
+
} else if (f === "[") {
|
|
638
|
+
o = true, h = l, a = false, d += f;
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
if (be(f) && t.charAt(l) === "(") {
|
|
642
|
+
u.push(d), d = "";
|
|
643
|
+
let m = new n(f, u);
|
|
644
|
+
u.push(m), l = n.#i(t, m, l, i);
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
if (f === "|") {
|
|
648
|
+
u.push(d), d = "", c.push(u), u = new n(null, e);
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
if (f === ")") return d === "" && e.#r.length === 0 && (e.#f = true), u.push(d), d = "", e.push(...c, u), l;
|
|
652
|
+
d += f;
|
|
653
|
+
}
|
|
654
|
+
return e.type = null, e.#s = void 0, e.#r = [t.substring(s - 1)], l;
|
|
655
|
+
}
|
|
656
|
+
static fromGlob(t, e = {}) {
|
|
657
|
+
let s = new n(null, void 0, e);
|
|
658
|
+
return n.#i(t, s, 0, e), s;
|
|
659
|
+
}
|
|
660
|
+
toMMPattern() {
|
|
661
|
+
if (this !== this.#t) return this.#t.toMMPattern();
|
|
662
|
+
let t = this.toString(), [e, s, i, r] = this.toRegExpSource();
|
|
663
|
+
if (!(i || this.#s || this.#h.nocase && !this.#h.nocaseMagicOnly && t.toUpperCase() !== t.toLowerCase())) return s;
|
|
664
|
+
let h = (this.#h.nocase ? "i" : "") + (r ? "u" : "");
|
|
665
|
+
return Object.assign(new RegExp(`^${e}$`, h), { _src: e, _glob: t });
|
|
666
|
+
}
|
|
667
|
+
get options() {
|
|
668
|
+
return this.#h;
|
|
669
|
+
}
|
|
670
|
+
toRegExpSource(t) {
|
|
671
|
+
let e = t ?? !!this.#h.dot;
|
|
672
|
+
if (this.#t === this && this.#a(), !this.type) {
|
|
673
|
+
let a = this.isStart() && this.isEnd() && !this.#r.some((f) => typeof f != "string"), l = this.#r.map((f) => {
|
|
674
|
+
let [m, p, w, g] = typeof f == "string" ? n.#E(f, this.#s, a) : f.toRegExpSource(t);
|
|
675
|
+
return this.#s = this.#s || w, this.#n = this.#n || g, m;
|
|
676
|
+
}).join(""), u = "";
|
|
677
|
+
if (this.isStart() && typeof this.#r[0] == "string" && !(this.#r.length === 1 && Ts.has(this.#r[0]))) {
|
|
678
|
+
let m = Cs, p = e && m.has(l.charAt(0)) || l.startsWith("\\.") && m.has(l.charAt(2)) || l.startsWith("\\.\\.") && m.has(l.charAt(4)), w = !e && !t && m.has(l.charAt(0));
|
|
679
|
+
u = p ? vs : w ? Ct : "";
|
|
680
|
+
}
|
|
681
|
+
let c = "";
|
|
682
|
+
return this.isEnd() && this.#t.#c && this.#o?.type === "!" && (c = "(?:$|\\/)"), [u + l + c, W(l), this.#s = !!this.#s, this.#n];
|
|
683
|
+
}
|
|
684
|
+
let s = this.type === "*" || this.type === "+", i = this.type === "!" ? "(?:(?!(?:" : "(?:", r = this.#d(e);
|
|
685
|
+
if (this.isStart() && this.isEnd() && !r && this.type !== "!") {
|
|
686
|
+
let a = this.toString();
|
|
687
|
+
return this.#r = [a], this.type = null, this.#s = void 0, [a, W(this.toString()), false, false];
|
|
688
|
+
}
|
|
689
|
+
let o = !s || t || e || !Ct ? "" : this.#d(true);
|
|
690
|
+
o === r && (o = ""), o && (r = `(?:${r})(?:${o})*?`);
|
|
691
|
+
let h = "";
|
|
692
|
+
if (this.type === "!" && this.#f) h = (this.isStart() && !e ? Ct : "") + Ee;
|
|
693
|
+
else {
|
|
694
|
+
let a = this.type === "!" ? "))" + (this.isStart() && !e && !t ? Ct : "") + Se + ")" : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && o ? ")" : this.type === "*" && o ? ")?" : `)${this.type}`;
|
|
695
|
+
h = i + r + a;
|
|
696
|
+
}
|
|
697
|
+
return [h, W(r), this.#s = !!this.#s, this.#n];
|
|
698
|
+
}
|
|
699
|
+
#d(t) {
|
|
700
|
+
return this.#r.map((e) => {
|
|
701
|
+
if (typeof e == "string") throw new Error("string type in extglob ast??");
|
|
702
|
+
let [s, i, r, o] = e.toRegExpSource(t);
|
|
703
|
+
return this.#n = this.#n || o, s;
|
|
704
|
+
}).filter((e) => !(this.isStart() && this.isEnd()) || !!e).join("|");
|
|
705
|
+
}
|
|
706
|
+
static #E(t, e, s = false) {
|
|
707
|
+
let i = false, r = "", o = false, h = false;
|
|
708
|
+
for (let a = 0; a < t.length; a++) {
|
|
709
|
+
let l = t.charAt(a);
|
|
710
|
+
if (i) {
|
|
711
|
+
i = false, r += (As.has(l) ? "\\" : "") + l;
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
if (l === "*") {
|
|
715
|
+
if (h) continue;
|
|
716
|
+
h = true, r += s && /^[*]+$/.test(t) ? Ee : Se, e = true;
|
|
717
|
+
continue;
|
|
718
|
+
} else h = false;
|
|
719
|
+
if (l === "\\") {
|
|
720
|
+
a === t.length - 1 ? r += "\\\\" : i = true;
|
|
721
|
+
continue;
|
|
722
|
+
}
|
|
723
|
+
if (l === "[") {
|
|
724
|
+
let [u, c, d, f] = ye(t, a);
|
|
725
|
+
if (d) {
|
|
726
|
+
r += u, o = o || c, a += d - 1, e = e || f;
|
|
727
|
+
continue;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
if (l === "?") {
|
|
731
|
+
r += Kt, e = true;
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
734
|
+
r += ks(l);
|
|
735
|
+
}
|
|
736
|
+
return [r, W(t), !!e, o];
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
var tt = (n7, { windowsPathsNoEscape: t = false, magicalBraces: e = false } = {}) => e ? t ? n7.replace(/[?*()[\]{}]/g, "[$&]") : n7.replace(/[?*()[\]\\{}]/g, "\\$&") : t ? n7.replace(/[?*()[\]]/g, "[$&]") : n7.replace(/[?*()[\]\\]/g, "\\$&");
|
|
740
|
+
var O = (n7, t, e = {}) => (at(t), !e.nocomment && t.charAt(0) === "#" ? false : new D(t, e).match(n7));
|
|
741
|
+
var Rs = /^\*+([^+@!?\*\[\(]*)$/;
|
|
742
|
+
var Os = (n7) => (t) => !t.startsWith(".") && t.endsWith(n7);
|
|
743
|
+
var Fs = (n7) => (t) => t.endsWith(n7);
|
|
744
|
+
var Ds = (n7) => (n7 = n7.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(n7));
|
|
745
|
+
var Ms = (n7) => (n7 = n7.toLowerCase(), (t) => t.toLowerCase().endsWith(n7));
|
|
746
|
+
var Ns = /^\*+\.\*+$/;
|
|
747
|
+
var _s = (n7) => !n7.startsWith(".") && n7.includes(".");
|
|
748
|
+
var Ls = (n7) => n7 !== "." && n7 !== ".." && n7.includes(".");
|
|
749
|
+
var Ws = /^\.\*+$/;
|
|
750
|
+
var Ps = (n7) => n7 !== "." && n7 !== ".." && n7.startsWith(".");
|
|
751
|
+
var js = /^\*+$/;
|
|
752
|
+
var Is = (n7) => n7.length !== 0 && !n7.startsWith(".");
|
|
753
|
+
var zs = (n7) => n7.length !== 0 && n7 !== "." && n7 !== "..";
|
|
754
|
+
var Bs = /^\?+([^+@!?\*\[\(]*)?$/;
|
|
755
|
+
var Us = ([n7, t = ""]) => {
|
|
756
|
+
let e = Ce([n7]);
|
|
757
|
+
return t ? (t = t.toLowerCase(), (s) => e(s) && s.toLowerCase().endsWith(t)) : e;
|
|
758
|
+
};
|
|
759
|
+
var $s = ([n7, t = ""]) => {
|
|
760
|
+
let e = Te([n7]);
|
|
761
|
+
return t ? (t = t.toLowerCase(), (s) => e(s) && s.toLowerCase().endsWith(t)) : e;
|
|
762
|
+
};
|
|
763
|
+
var Gs = ([n7, t = ""]) => {
|
|
764
|
+
let e = Te([n7]);
|
|
765
|
+
return t ? (s) => e(s) && s.endsWith(t) : e;
|
|
766
|
+
};
|
|
767
|
+
var Hs = ([n7, t = ""]) => {
|
|
768
|
+
let e = Ce([n7]);
|
|
769
|
+
return t ? (s) => e(s) && s.endsWith(t) : e;
|
|
770
|
+
};
|
|
771
|
+
var Ce = ([n7]) => {
|
|
772
|
+
let t = n7.length;
|
|
773
|
+
return (e) => e.length === t && !e.startsWith(".");
|
|
774
|
+
};
|
|
775
|
+
var Te = ([n7]) => {
|
|
776
|
+
let t = n7.length;
|
|
777
|
+
return (e) => e.length === t && e !== "." && e !== "..";
|
|
778
|
+
};
|
|
779
|
+
var Ae = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
|
|
780
|
+
var xe = { win32: { sep: "\\" }, posix: { sep: "/" } };
|
|
781
|
+
var qs = Ae === "win32" ? xe.win32.sep : xe.posix.sep;
|
|
782
|
+
O.sep = qs;
|
|
783
|
+
var A = /* @__PURE__ */ Symbol("globstar **");
|
|
784
|
+
O.GLOBSTAR = A;
|
|
785
|
+
var Ks = "[^/]";
|
|
786
|
+
var Vs = Ks + "*?";
|
|
787
|
+
var Ys = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?";
|
|
788
|
+
var Xs = "(?:(?!(?:\\/|^)\\.).)*?";
|
|
789
|
+
var Js = (n7, t = {}) => (e) => O(e, n7, t);
|
|
790
|
+
O.filter = Js;
|
|
791
|
+
var N = (n7, t = {}) => Object.assign({}, n7, t);
|
|
792
|
+
var Zs = (n7) => {
|
|
793
|
+
if (!n7 || typeof n7 != "object" || !Object.keys(n7).length) return O;
|
|
794
|
+
let t = O;
|
|
795
|
+
return Object.assign((s, i, r = {}) => t(s, i, N(n7, r)), { Minimatch: class extends t.Minimatch {
|
|
796
|
+
constructor(i, r = {}) {
|
|
797
|
+
super(i, N(n7, r));
|
|
798
|
+
}
|
|
799
|
+
static defaults(i) {
|
|
800
|
+
return t.defaults(N(n7, i)).Minimatch;
|
|
801
|
+
}
|
|
802
|
+
}, AST: class extends t.AST {
|
|
803
|
+
constructor(i, r, o = {}) {
|
|
804
|
+
super(i, r, N(n7, o));
|
|
805
|
+
}
|
|
806
|
+
static fromGlob(i, r = {}) {
|
|
807
|
+
return t.AST.fromGlob(i, N(n7, r));
|
|
808
|
+
}
|
|
809
|
+
}, unescape: (s, i = {}) => t.unescape(s, N(n7, i)), escape: (s, i = {}) => t.escape(s, N(n7, i)), filter: (s, i = {}) => t.filter(s, N(n7, i)), defaults: (s) => t.defaults(N(n7, s)), makeRe: (s, i = {}) => t.makeRe(s, N(n7, i)), braceExpand: (s, i = {}) => t.braceExpand(s, N(n7, i)), match: (s, i, r = {}) => t.match(s, i, N(n7, r)), sep: t.sep, GLOBSTAR: A });
|
|
810
|
+
};
|
|
811
|
+
O.defaults = Zs;
|
|
812
|
+
var ke = (n7, t = {}) => (at(n7), t.nobrace || !/\{(?:(?!\{).)*\}/.test(n7) ? [n7] : ge(n7, { max: t.braceExpandMax }));
|
|
813
|
+
O.braceExpand = ke;
|
|
814
|
+
var Qs = (n7, t = {}) => new D(n7, t).makeRe();
|
|
815
|
+
O.makeRe = Qs;
|
|
816
|
+
var ti = (n7, t, e = {}) => {
|
|
817
|
+
let s = new D(t, e);
|
|
818
|
+
return n7 = n7.filter((i) => s.match(i)), s.options.nonull && !n7.length && n7.push(t), n7;
|
|
819
|
+
};
|
|
820
|
+
O.match = ti;
|
|
821
|
+
var ve = /[?*]|[+@!]\(.*?\)|\[|\]/;
|
|
822
|
+
var ei = (n7) => n7.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
823
|
+
var D = class {
|
|
824
|
+
options;
|
|
825
|
+
set;
|
|
826
|
+
pattern;
|
|
827
|
+
windowsPathsNoEscape;
|
|
828
|
+
nonegate;
|
|
829
|
+
negate;
|
|
830
|
+
comment;
|
|
831
|
+
empty;
|
|
832
|
+
preserveMultipleSlashes;
|
|
833
|
+
partial;
|
|
834
|
+
globSet;
|
|
835
|
+
globParts;
|
|
836
|
+
nocase;
|
|
837
|
+
isWindows;
|
|
838
|
+
platform;
|
|
839
|
+
windowsNoMagicRoot;
|
|
840
|
+
regexp;
|
|
841
|
+
constructor(t, e = {}) {
|
|
842
|
+
at(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform || Ae, this.isWindows = this.platform === "win32";
|
|
843
|
+
let s = "allowWindowsEscape";
|
|
844
|
+
this.windowsPathsNoEscape = !!e.windowsPathsNoEscape || e[s] === false, this.windowsPathsNoEscape && (this.pattern = this.pattern.replace(/\\/g, "/")), this.preserveMultipleSlashes = !!e.preserveMultipleSlashes, this.regexp = null, this.negate = false, this.nonegate = !!e.nonegate, this.comment = false, this.empty = false, this.partial = !!e.partial, this.nocase = !!this.options.nocase, this.windowsNoMagicRoot = e.windowsNoMagicRoot !== void 0 ? e.windowsNoMagicRoot : !!(this.isWindows && this.nocase), this.globSet = [], this.globParts = [], this.set = [], this.make();
|
|
845
|
+
}
|
|
846
|
+
hasMagic() {
|
|
847
|
+
if (this.options.magicalBraces && this.set.length > 1) return true;
|
|
848
|
+
for (let t of this.set) for (let e of t) if (typeof e != "string") return true;
|
|
849
|
+
return false;
|
|
850
|
+
}
|
|
851
|
+
debug(...t) {
|
|
852
|
+
}
|
|
853
|
+
make() {
|
|
854
|
+
let t = this.pattern, e = this.options;
|
|
855
|
+
if (!e.nocomment && t.charAt(0) === "#") {
|
|
856
|
+
this.comment = true;
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
if (!t) {
|
|
860
|
+
this.empty = true;
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
this.parseNegate(), this.globSet = [...new Set(this.braceExpand())], e.debug && (this.debug = (...r) => console.error(...r)), this.debug(this.pattern, this.globSet);
|
|
864
|
+
let s = this.globSet.map((r) => this.slashSplit(r));
|
|
865
|
+
this.globParts = this.preprocess(s), this.debug(this.pattern, this.globParts);
|
|
866
|
+
let i = this.globParts.map((r, o, h) => {
|
|
867
|
+
if (this.isWindows && this.windowsNoMagicRoot) {
|
|
868
|
+
let a = r[0] === "" && r[1] === "" && (r[2] === "?" || !ve.test(r[2])) && !ve.test(r[3]), l = /^[a-z]:/i.test(r[0]);
|
|
869
|
+
if (a) return [...r.slice(0, 4), ...r.slice(4).map((u) => this.parse(u))];
|
|
870
|
+
if (l) return [r[0], ...r.slice(1).map((u) => this.parse(u))];
|
|
871
|
+
}
|
|
872
|
+
return r.map((a) => this.parse(a));
|
|
873
|
+
});
|
|
874
|
+
if (this.debug(this.pattern, i), this.set = i.filter((r) => r.indexOf(false) === -1), this.isWindows) for (let r = 0; r < this.set.length; r++) {
|
|
875
|
+
let o = this.set[r];
|
|
876
|
+
o[0] === "" && o[1] === "" && this.globParts[r][2] === "?" && typeof o[3] == "string" && /^[a-z]:$/i.test(o[3]) && (o[2] = "?");
|
|
877
|
+
}
|
|
878
|
+
this.debug(this.pattern, this.set);
|
|
879
|
+
}
|
|
880
|
+
preprocess(t) {
|
|
881
|
+
if (this.options.noglobstar) for (let s = 0; s < t.length; s++) for (let i = 0; i < t[s].length; i++) t[s][i] === "**" && (t[s][i] = "*");
|
|
882
|
+
let { optimizationLevel: e = 1 } = this.options;
|
|
883
|
+
return e >= 2 ? (t = this.firstPhasePreProcess(t), t = this.secondPhasePreProcess(t)) : e >= 1 ? t = this.levelOneOptimize(t) : t = this.adjascentGlobstarOptimize(t), t;
|
|
884
|
+
}
|
|
885
|
+
adjascentGlobstarOptimize(t) {
|
|
886
|
+
return t.map((e) => {
|
|
887
|
+
let s = -1;
|
|
888
|
+
for (; (s = e.indexOf("**", s + 1)) !== -1; ) {
|
|
889
|
+
let i = s;
|
|
890
|
+
for (; e[i + 1] === "**"; ) i++;
|
|
891
|
+
i !== s && e.splice(s, i - s);
|
|
892
|
+
}
|
|
893
|
+
return e;
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
levelOneOptimize(t) {
|
|
897
|
+
return t.map((e) => (e = e.reduce((s, i) => {
|
|
898
|
+
let r = s[s.length - 1];
|
|
899
|
+
return i === "**" && r === "**" ? s : i === ".." && r && r !== ".." && r !== "." && r !== "**" ? (s.pop(), s) : (s.push(i), s);
|
|
900
|
+
}, []), e.length === 0 ? [""] : e));
|
|
901
|
+
}
|
|
902
|
+
levelTwoFileOptimize(t) {
|
|
903
|
+
Array.isArray(t) || (t = this.slashSplit(t));
|
|
904
|
+
let e = false;
|
|
905
|
+
do {
|
|
906
|
+
if (e = false, !this.preserveMultipleSlashes) {
|
|
907
|
+
for (let i = 1; i < t.length - 1; i++) {
|
|
908
|
+
let r = t[i];
|
|
909
|
+
i === 1 && r === "" && t[0] === "" || (r === "." || r === "") && (e = true, t.splice(i, 1), i--);
|
|
910
|
+
}
|
|
911
|
+
t[0] === "." && t.length === 2 && (t[1] === "." || t[1] === "") && (e = true, t.pop());
|
|
912
|
+
}
|
|
913
|
+
let s = 0;
|
|
914
|
+
for (; (s = t.indexOf("..", s + 1)) !== -1; ) {
|
|
915
|
+
let i = t[s - 1];
|
|
916
|
+
i && i !== "." && i !== ".." && i !== "**" && (e = true, t.splice(s - 1, 2), s -= 2);
|
|
917
|
+
}
|
|
918
|
+
} while (e);
|
|
919
|
+
return t.length === 0 ? [""] : t;
|
|
920
|
+
}
|
|
921
|
+
firstPhasePreProcess(t) {
|
|
922
|
+
let e = false;
|
|
923
|
+
do {
|
|
924
|
+
e = false;
|
|
925
|
+
for (let s of t) {
|
|
926
|
+
let i = -1;
|
|
927
|
+
for (; (i = s.indexOf("**", i + 1)) !== -1; ) {
|
|
928
|
+
let o = i;
|
|
929
|
+
for (; s[o + 1] === "**"; ) o++;
|
|
930
|
+
o > i && s.splice(i + 1, o - i);
|
|
931
|
+
let h = s[i + 1], a = s[i + 2], l = s[i + 3];
|
|
932
|
+
if (h !== ".." || !a || a === "." || a === ".." || !l || l === "." || l === "..") continue;
|
|
933
|
+
e = true, s.splice(i, 1);
|
|
934
|
+
let u = s.slice(0);
|
|
935
|
+
u[i] = "**", t.push(u), i--;
|
|
936
|
+
}
|
|
937
|
+
if (!this.preserveMultipleSlashes) {
|
|
938
|
+
for (let o = 1; o < s.length - 1; o++) {
|
|
939
|
+
let h = s[o];
|
|
940
|
+
o === 1 && h === "" && s[0] === "" || (h === "." || h === "") && (e = true, s.splice(o, 1), o--);
|
|
941
|
+
}
|
|
942
|
+
s[0] === "." && s.length === 2 && (s[1] === "." || s[1] === "") && (e = true, s.pop());
|
|
943
|
+
}
|
|
944
|
+
let r = 0;
|
|
945
|
+
for (; (r = s.indexOf("..", r + 1)) !== -1; ) {
|
|
946
|
+
let o = s[r - 1];
|
|
947
|
+
if (o && o !== "." && o !== ".." && o !== "**") {
|
|
948
|
+
e = true;
|
|
949
|
+
let a = r === 1 && s[r + 1] === "**" ? ["."] : [];
|
|
950
|
+
s.splice(r - 1, 2, ...a), s.length === 0 && s.push(""), r -= 2;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
} while (e);
|
|
955
|
+
return t;
|
|
956
|
+
}
|
|
957
|
+
secondPhasePreProcess(t) {
|
|
958
|
+
for (let e = 0; e < t.length - 1; e++) for (let s = e + 1; s < t.length; s++) {
|
|
959
|
+
let i = this.partsMatch(t[e], t[s], !this.preserveMultipleSlashes);
|
|
960
|
+
if (i) {
|
|
961
|
+
t[e] = [], t[s] = i;
|
|
962
|
+
break;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
return t.filter((e) => e.length);
|
|
966
|
+
}
|
|
967
|
+
partsMatch(t, e, s = false) {
|
|
968
|
+
let i = 0, r = 0, o = [], h = "";
|
|
969
|
+
for (; i < t.length && r < e.length; ) if (t[i] === e[r]) o.push(h === "b" ? e[r] : t[i]), i++, r++;
|
|
970
|
+
else if (s && t[i] === "**" && e[r] === t[i + 1]) o.push(t[i]), i++;
|
|
971
|
+
else if (s && e[r] === "**" && t[i] === e[r + 1]) o.push(e[r]), r++;
|
|
972
|
+
else if (t[i] === "*" && e[r] && (this.options.dot || !e[r].startsWith(".")) && e[r] !== "**") {
|
|
973
|
+
if (h === "b") return false;
|
|
974
|
+
h = "a", o.push(t[i]), i++, r++;
|
|
975
|
+
} else if (e[r] === "*" && t[i] && (this.options.dot || !t[i].startsWith(".")) && t[i] !== "**") {
|
|
976
|
+
if (h === "a") return false;
|
|
977
|
+
h = "b", o.push(e[r]), i++, r++;
|
|
978
|
+
} else return false;
|
|
979
|
+
return t.length === e.length && o;
|
|
980
|
+
}
|
|
981
|
+
parseNegate() {
|
|
982
|
+
if (this.nonegate) return;
|
|
983
|
+
let t = this.pattern, e = false, s = 0;
|
|
984
|
+
for (let i = 0; i < t.length && t.charAt(i) === "!"; i++) e = !e, s++;
|
|
985
|
+
s && (this.pattern = t.slice(s)), this.negate = e;
|
|
986
|
+
}
|
|
987
|
+
matchOne(t, e, s = false) {
|
|
988
|
+
let i = this.options;
|
|
989
|
+
if (this.isWindows) {
|
|
990
|
+
let p = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), w = !p && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]), g = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), S = !g && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), E = w ? 3 : p ? 0 : void 0, y = S ? 3 : g ? 0 : void 0;
|
|
991
|
+
if (typeof E == "number" && typeof y == "number") {
|
|
992
|
+
let [b, z] = [t[E], e[y]];
|
|
993
|
+
b.toLowerCase() === z.toLowerCase() && (e[y] = b, y > E ? e = e.slice(y) : E > y && (t = t.slice(E)));
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
let { optimizationLevel: r = 1 } = this.options;
|
|
997
|
+
r >= 2 && (t = this.levelTwoFileOptimize(t)), this.debug("matchOne", this, { file: t, pattern: e }), this.debug("matchOne", t.length, e.length);
|
|
998
|
+
for (var o = 0, h = 0, a = t.length, l = e.length; o < a && h < l; o++, h++) {
|
|
999
|
+
this.debug("matchOne loop");
|
|
1000
|
+
var u = e[h], c = t[o];
|
|
1001
|
+
if (this.debug(e, u, c), u === false) return false;
|
|
1002
|
+
if (u === A) {
|
|
1003
|
+
this.debug("GLOBSTAR", [e, u, c]);
|
|
1004
|
+
var d = o, f = h + 1;
|
|
1005
|
+
if (f === l) {
|
|
1006
|
+
for (this.debug("** at the end"); o < a; o++) if (t[o] === "." || t[o] === ".." || !i.dot && t[o].charAt(0) === ".") return false;
|
|
1007
|
+
return true;
|
|
1008
|
+
}
|
|
1009
|
+
for (; d < a; ) {
|
|
1010
|
+
var m = t[d];
|
|
1011
|
+
if (this.debug(`
|
|
1012
|
+
globstar while`, t, d, e, f, m), this.matchOne(t.slice(d), e.slice(f), s)) return this.debug("globstar found match!", d, a, m), true;
|
|
1013
|
+
if (m === "." || m === ".." || !i.dot && m.charAt(0) === ".") {
|
|
1014
|
+
this.debug("dot detected!", t, d, e, f);
|
|
1015
|
+
break;
|
|
1016
|
+
}
|
|
1017
|
+
this.debug("globstar swallow a segment, and continue"), d++;
|
|
1018
|
+
}
|
|
1019
|
+
return !!(s && (this.debug(`
|
|
1020
|
+
>>> no match, partial?`, t, d, e, f), d === a));
|
|
1021
|
+
}
|
|
1022
|
+
let p;
|
|
1023
|
+
if (typeof u == "string" ? (p = c === u, this.debug("string match", u, c, p)) : (p = u.test(c), this.debug("pattern match", u, c, p)), !p) return false;
|
|
1024
|
+
}
|
|
1025
|
+
if (o === a && h === l) return true;
|
|
1026
|
+
if (o === a) return s;
|
|
1027
|
+
if (h === l) return o === a - 1 && t[o] === "";
|
|
1028
|
+
throw new Error("wtf?");
|
|
1029
|
+
}
|
|
1030
|
+
braceExpand() {
|
|
1031
|
+
return ke(this.pattern, this.options);
|
|
1032
|
+
}
|
|
1033
|
+
parse(t) {
|
|
1034
|
+
at(t);
|
|
1035
|
+
let e = this.options;
|
|
1036
|
+
if (t === "**") return A;
|
|
1037
|
+
if (t === "") return "";
|
|
1038
|
+
let s, i = null;
|
|
1039
|
+
(s = t.match(js)) ? i = e.dot ? zs : Is : (s = t.match(Rs)) ? i = (e.nocase ? e.dot ? Ms : Ds : e.dot ? Fs : Os)(s[1]) : (s = t.match(Bs)) ? i = (e.nocase ? e.dot ? $s : Us : e.dot ? Gs : Hs)(s) : (s = t.match(Ns)) ? i = e.dot ? Ls : _s : (s = t.match(Ws)) && (i = Ps);
|
|
1040
|
+
let r = Q.fromGlob(t, this.options).toMMPattern();
|
|
1041
|
+
return i && typeof r == "object" && Reflect.defineProperty(r, "test", { value: i }), r;
|
|
1042
|
+
}
|
|
1043
|
+
makeRe() {
|
|
1044
|
+
if (this.regexp || this.regexp === false) return this.regexp;
|
|
1045
|
+
let t = this.set;
|
|
1046
|
+
if (!t.length) return this.regexp = false, this.regexp;
|
|
1047
|
+
let e = this.options, s = e.noglobstar ? Vs : e.dot ? Ys : Xs, i = new Set(e.nocase ? ["i"] : []), r = t.map((a) => {
|
|
1048
|
+
let l = a.map((c) => {
|
|
1049
|
+
if (c instanceof RegExp) for (let d of c.flags.split("")) i.add(d);
|
|
1050
|
+
return typeof c == "string" ? ei(c) : c === A ? A : c._src;
|
|
1051
|
+
});
|
|
1052
|
+
l.forEach((c, d) => {
|
|
1053
|
+
let f = l[d + 1], m = l[d - 1];
|
|
1054
|
+
c !== A || m === A || (m === void 0 ? f !== void 0 && f !== A ? l[d + 1] = "(?:\\/|" + s + "\\/)?" + f : l[d] = s : f === void 0 ? l[d - 1] = m + "(?:\\/|\\/" + s + ")?" : f !== A && (l[d - 1] = m + "(?:\\/|\\/" + s + "\\/)" + f, l[d + 1] = A));
|
|
1055
|
+
});
|
|
1056
|
+
let u = l.filter((c) => c !== A);
|
|
1057
|
+
if (this.partial && u.length >= 1) {
|
|
1058
|
+
let c = [];
|
|
1059
|
+
for (let d = 1; d <= u.length; d++) c.push(u.slice(0, d).join("/"));
|
|
1060
|
+
return "(?:" + c.join("|") + ")";
|
|
1061
|
+
}
|
|
1062
|
+
return u.join("/");
|
|
1063
|
+
}).join("|"), [o, h] = t.length > 1 ? ["(?:", ")"] : ["", ""];
|
|
1064
|
+
r = "^" + o + r + h + "$", this.partial && (r = "^(?:\\/|" + o + r.slice(1, -1) + h + ")$"), this.negate && (r = "^(?!" + r + ").+$");
|
|
1065
|
+
try {
|
|
1066
|
+
this.regexp = new RegExp(r, [...i].join(""));
|
|
1067
|
+
} catch {
|
|
1068
|
+
this.regexp = false;
|
|
1069
|
+
}
|
|
1070
|
+
return this.regexp;
|
|
1071
|
+
}
|
|
1072
|
+
slashSplit(t) {
|
|
1073
|
+
return this.preserveMultipleSlashes ? t.split("/") : this.isWindows && /^\/\/[^\/]+/.test(t) ? ["", ...t.split(/\/+/)] : t.split(/\/+/);
|
|
1074
|
+
}
|
|
1075
|
+
match(t, e = this.partial) {
|
|
1076
|
+
if (this.debug("match", t, this.pattern), this.comment) return false;
|
|
1077
|
+
if (this.empty) return t === "";
|
|
1078
|
+
if (t === "/" && e) return true;
|
|
1079
|
+
let s = this.options;
|
|
1080
|
+
this.isWindows && (t = t.split("\\").join("/"));
|
|
1081
|
+
let i = this.slashSplit(t);
|
|
1082
|
+
this.debug(this.pattern, "split", i);
|
|
1083
|
+
let r = this.set;
|
|
1084
|
+
this.debug(this.pattern, "set", r);
|
|
1085
|
+
let o = i[i.length - 1];
|
|
1086
|
+
if (!o) for (let h = i.length - 2; !o && h >= 0; h--) o = i[h];
|
|
1087
|
+
for (let h = 0; h < r.length; h++) {
|
|
1088
|
+
let a = r[h], l = i;
|
|
1089
|
+
if (s.matchBase && a.length === 1 && (l = [o]), this.matchOne(l, a, e)) return s.flipNegate ? true : !this.negate;
|
|
1090
|
+
}
|
|
1091
|
+
return s.flipNegate ? false : this.negate;
|
|
1092
|
+
}
|
|
1093
|
+
static defaults(t) {
|
|
1094
|
+
return O.defaults(t).Minimatch;
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
O.AST = Q;
|
|
1098
|
+
O.Minimatch = D;
|
|
1099
|
+
O.escape = tt;
|
|
1100
|
+
O.unescape = W;
|
|
1101
|
+
var si = typeof performance == "object" && performance && typeof performance.now == "function" ? performance : Date;
|
|
1102
|
+
var Oe = /* @__PURE__ */ new Set();
|
|
1103
|
+
var Vt = typeof process == "object" && process ? process : {};
|
|
1104
|
+
var Fe = (n7, t, e, s) => {
|
|
1105
|
+
typeof Vt.emitWarning == "function" ? Vt.emitWarning(n7, t, e, s) : console.error(`[${e}] ${t}: ${n7}`);
|
|
1106
|
+
};
|
|
1107
|
+
var At = globalThis.AbortController;
|
|
1108
|
+
var Re = globalThis.AbortSignal;
|
|
1109
|
+
if (typeof At > "u") {
|
|
1110
|
+
Re = class {
|
|
1111
|
+
onabort;
|
|
1112
|
+
_onabort = [];
|
|
1113
|
+
reason;
|
|
1114
|
+
aborted = false;
|
|
1115
|
+
addEventListener(e, s) {
|
|
1116
|
+
this._onabort.push(s);
|
|
1117
|
+
}
|
|
1118
|
+
}, At = class {
|
|
1119
|
+
constructor() {
|
|
1120
|
+
t();
|
|
1121
|
+
}
|
|
1122
|
+
signal = new Re();
|
|
1123
|
+
abort(e) {
|
|
1124
|
+
if (!this.signal.aborted) {
|
|
1125
|
+
this.signal.reason = e, this.signal.aborted = true;
|
|
1126
|
+
for (let s of this.signal._onabort) s(e);
|
|
1127
|
+
this.signal.onabort?.(e);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
};
|
|
1131
|
+
let n7 = Vt.env?.LRU_CACHE_IGNORE_AC_WARNING !== "1", t = () => {
|
|
1132
|
+
n7 && (n7 = false, Fe("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.", "NO_ABORT_CONTROLLER", "ENOTSUP", t));
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
var ii = (n7) => !Oe.has(n7);
|
|
1136
|
+
var q = (n7) => n7 && n7 === Math.floor(n7) && n7 > 0 && isFinite(n7);
|
|
1137
|
+
var De = (n7) => q(n7) ? n7 <= Math.pow(2, 8) ? Uint8Array : n7 <= Math.pow(2, 16) ? Uint16Array : n7 <= Math.pow(2, 32) ? Uint32Array : n7 <= Number.MAX_SAFE_INTEGER ? Tt : null : null;
|
|
1138
|
+
var Tt = class extends Array {
|
|
1139
|
+
constructor(n7) {
|
|
1140
|
+
super(n7), this.fill(0);
|
|
1141
|
+
}
|
|
1142
|
+
};
|
|
1143
|
+
var ri = class ct {
|
|
1144
|
+
heap;
|
|
1145
|
+
length;
|
|
1146
|
+
static #t = false;
|
|
1147
|
+
static create(t) {
|
|
1148
|
+
let e = De(t);
|
|
1149
|
+
if (!e) return [];
|
|
1150
|
+
ct.#t = true;
|
|
1151
|
+
let s = new ct(t, e);
|
|
1152
|
+
return ct.#t = false, s;
|
|
1153
|
+
}
|
|
1154
|
+
constructor(t, e) {
|
|
1155
|
+
if (!ct.#t) throw new TypeError("instantiate Stack using Stack.create(n)");
|
|
1156
|
+
this.heap = new e(t), this.length = 0;
|
|
1157
|
+
}
|
|
1158
|
+
push(t) {
|
|
1159
|
+
this.heap[this.length++] = t;
|
|
1160
|
+
}
|
|
1161
|
+
pop() {
|
|
1162
|
+
return this.heap[--this.length];
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1165
|
+
var ft = class Me {
|
|
1166
|
+
#t;
|
|
1167
|
+
#s;
|
|
1168
|
+
#n;
|
|
1169
|
+
#r;
|
|
1170
|
+
#o;
|
|
1171
|
+
#S;
|
|
1172
|
+
#w;
|
|
1173
|
+
#c;
|
|
1174
|
+
get perf() {
|
|
1175
|
+
return this.#c;
|
|
1176
|
+
}
|
|
1177
|
+
ttl;
|
|
1178
|
+
ttlResolution;
|
|
1179
|
+
ttlAutopurge;
|
|
1180
|
+
updateAgeOnGet;
|
|
1181
|
+
updateAgeOnHas;
|
|
1182
|
+
allowStale;
|
|
1183
|
+
noDisposeOnSet;
|
|
1184
|
+
noUpdateTTL;
|
|
1185
|
+
maxEntrySize;
|
|
1186
|
+
sizeCalculation;
|
|
1187
|
+
noDeleteOnFetchRejection;
|
|
1188
|
+
noDeleteOnStaleGet;
|
|
1189
|
+
allowStaleOnFetchAbort;
|
|
1190
|
+
allowStaleOnFetchRejection;
|
|
1191
|
+
ignoreFetchAbort;
|
|
1192
|
+
#h;
|
|
1193
|
+
#u;
|
|
1194
|
+
#f;
|
|
1195
|
+
#a;
|
|
1196
|
+
#i;
|
|
1197
|
+
#d;
|
|
1198
|
+
#E;
|
|
1199
|
+
#b;
|
|
1200
|
+
#p;
|
|
1201
|
+
#R;
|
|
1202
|
+
#m;
|
|
1203
|
+
#C;
|
|
1204
|
+
#T;
|
|
1205
|
+
#g;
|
|
1206
|
+
#y;
|
|
1207
|
+
#x;
|
|
1208
|
+
#A;
|
|
1209
|
+
#e;
|
|
1210
|
+
#_;
|
|
1211
|
+
static unsafeExposeInternals(t) {
|
|
1212
|
+
return { starts: t.#T, ttls: t.#g, autopurgeTimers: t.#y, sizes: t.#C, keyMap: t.#f, keyList: t.#a, valList: t.#i, next: t.#d, prev: t.#E, get head() {
|
|
1213
|
+
return t.#b;
|
|
1214
|
+
}, get tail() {
|
|
1215
|
+
return t.#p;
|
|
1216
|
+
}, free: t.#R, isBackgroundFetch: (e) => t.#l(e), backgroundFetch: (e, s, i, r) => t.#U(e, s, i, r), moveToTail: (e) => t.#W(e), indexes: (e) => t.#F(e), rindexes: (e) => t.#D(e), isStale: (e) => t.#v(e) };
|
|
1217
|
+
}
|
|
1218
|
+
get max() {
|
|
1219
|
+
return this.#t;
|
|
1220
|
+
}
|
|
1221
|
+
get maxSize() {
|
|
1222
|
+
return this.#s;
|
|
1223
|
+
}
|
|
1224
|
+
get calculatedSize() {
|
|
1225
|
+
return this.#u;
|
|
1226
|
+
}
|
|
1227
|
+
get size() {
|
|
1228
|
+
return this.#h;
|
|
1229
|
+
}
|
|
1230
|
+
get fetchMethod() {
|
|
1231
|
+
return this.#S;
|
|
1232
|
+
}
|
|
1233
|
+
get memoMethod() {
|
|
1234
|
+
return this.#w;
|
|
1235
|
+
}
|
|
1236
|
+
get dispose() {
|
|
1237
|
+
return this.#n;
|
|
1238
|
+
}
|
|
1239
|
+
get onInsert() {
|
|
1240
|
+
return this.#r;
|
|
1241
|
+
}
|
|
1242
|
+
get disposeAfter() {
|
|
1243
|
+
return this.#o;
|
|
1244
|
+
}
|
|
1245
|
+
constructor(t) {
|
|
1246
|
+
let { max: e = 0, ttl: s, ttlResolution: i = 1, ttlAutopurge: r, updateAgeOnGet: o, updateAgeOnHas: h, allowStale: a, dispose: l, onInsert: u, disposeAfter: c, noDisposeOnSet: d, noUpdateTTL: f, maxSize: m = 0, maxEntrySize: p = 0, sizeCalculation: w, fetchMethod: g, memoMethod: S, noDeleteOnFetchRejection: E, noDeleteOnStaleGet: y, allowStaleOnFetchRejection: b, allowStaleOnFetchAbort: z, ignoreFetchAbort: $, perf: J } = t;
|
|
1247
|
+
if (J !== void 0 && typeof J?.now != "function") throw new TypeError("perf option must have a now() method if specified");
|
|
1248
|
+
if (this.#c = J ?? si, e !== 0 && !q(e)) throw new TypeError("max option must be a nonnegative integer");
|
|
1249
|
+
let Z = e ? De(e) : Array;
|
|
1250
|
+
if (!Z) throw new Error("invalid max value: " + e);
|
|
1251
|
+
if (this.#t = e, this.#s = m, this.maxEntrySize = p || this.#s, this.sizeCalculation = w, this.sizeCalculation) {
|
|
1252
|
+
if (!this.#s && !this.maxEntrySize) throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
|
|
1253
|
+
if (typeof this.sizeCalculation != "function") throw new TypeError("sizeCalculation set to non-function");
|
|
1254
|
+
}
|
|
1255
|
+
if (S !== void 0 && typeof S != "function") throw new TypeError("memoMethod must be a function if defined");
|
|
1256
|
+
if (this.#w = S, g !== void 0 && typeof g != "function") throw new TypeError("fetchMethod must be a function if specified");
|
|
1257
|
+
if (this.#S = g, this.#A = !!g, this.#f = /* @__PURE__ */ new Map(), this.#a = new Array(e).fill(void 0), this.#i = new Array(e).fill(void 0), this.#d = new Z(e), this.#E = new Z(e), this.#b = 0, this.#p = 0, this.#R = ri.create(e), this.#h = 0, this.#u = 0, typeof l == "function" && (this.#n = l), typeof u == "function" && (this.#r = u), typeof c == "function" ? (this.#o = c, this.#m = []) : (this.#o = void 0, this.#m = void 0), this.#x = !!this.#n, this.#_ = !!this.#r, this.#e = !!this.#o, this.noDisposeOnSet = !!d, this.noUpdateTTL = !!f, this.noDeleteOnFetchRejection = !!E, this.allowStaleOnFetchRejection = !!b, this.allowStaleOnFetchAbort = !!z, this.ignoreFetchAbort = !!$, this.maxEntrySize !== 0) {
|
|
1258
|
+
if (this.#s !== 0 && !q(this.#s)) throw new TypeError("maxSize must be a positive integer if specified");
|
|
1259
|
+
if (!q(this.maxEntrySize)) throw new TypeError("maxEntrySize must be a positive integer if specified");
|
|
1260
|
+
this.#G();
|
|
1261
|
+
}
|
|
1262
|
+
if (this.allowStale = !!a, this.noDeleteOnStaleGet = !!y, this.updateAgeOnGet = !!o, this.updateAgeOnHas = !!h, this.ttlResolution = q(i) || i === 0 ? i : 1, this.ttlAutopurge = !!r, this.ttl = s || 0, this.ttl) {
|
|
1263
|
+
if (!q(this.ttl)) throw new TypeError("ttl must be a positive integer if specified");
|
|
1264
|
+
this.#M();
|
|
1265
|
+
}
|
|
1266
|
+
if (this.#t === 0 && this.ttl === 0 && this.#s === 0) throw new TypeError("At least one of max, maxSize, or ttl is required");
|
|
1267
|
+
if (!this.ttlAutopurge && !this.#t && !this.#s) {
|
|
1268
|
+
let $t = "LRU_CACHE_UNBOUNDED";
|
|
1269
|
+
ii($t) && (Oe.add($t), Fe("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", $t, Me));
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
getRemainingTTL(t) {
|
|
1273
|
+
return this.#f.has(t) ? 1 / 0 : 0;
|
|
1274
|
+
}
|
|
1275
|
+
#M() {
|
|
1276
|
+
let t = new Tt(this.#t), e = new Tt(this.#t);
|
|
1277
|
+
this.#g = t, this.#T = e;
|
|
1278
|
+
let s = this.ttlAutopurge ? new Array(this.#t) : void 0;
|
|
1279
|
+
this.#y = s, this.#j = (o, h, a = this.#c.now()) => {
|
|
1280
|
+
if (e[o] = h !== 0 ? a : 0, t[o] = h, s?.[o] && (clearTimeout(s[o]), s[o] = void 0), h !== 0 && s) {
|
|
1281
|
+
let l = setTimeout(() => {
|
|
1282
|
+
this.#v(o) && this.#O(this.#a[o], "expire");
|
|
1283
|
+
}, h + 1);
|
|
1284
|
+
l.unref && l.unref(), s[o] = l;
|
|
1285
|
+
}
|
|
1286
|
+
}, this.#k = (o) => {
|
|
1287
|
+
e[o] = t[o] !== 0 ? this.#c.now() : 0;
|
|
1288
|
+
}, this.#N = (o, h) => {
|
|
1289
|
+
if (t[h]) {
|
|
1290
|
+
let a = t[h], l = e[h];
|
|
1291
|
+
if (!a || !l) return;
|
|
1292
|
+
o.ttl = a, o.start = l, o.now = i || r();
|
|
1293
|
+
let u = o.now - l;
|
|
1294
|
+
o.remainingTTL = a - u;
|
|
1295
|
+
}
|
|
1296
|
+
};
|
|
1297
|
+
let i = 0, r = () => {
|
|
1298
|
+
let o = this.#c.now();
|
|
1299
|
+
if (this.ttlResolution > 0) {
|
|
1300
|
+
i = o;
|
|
1301
|
+
let h = setTimeout(() => i = 0, this.ttlResolution);
|
|
1302
|
+
h.unref && h.unref();
|
|
1303
|
+
}
|
|
1304
|
+
return o;
|
|
1305
|
+
};
|
|
1306
|
+
this.getRemainingTTL = (o) => {
|
|
1307
|
+
let h = this.#f.get(o);
|
|
1308
|
+
if (h === void 0) return 0;
|
|
1309
|
+
let a = t[h], l = e[h];
|
|
1310
|
+
if (!a || !l) return 1 / 0;
|
|
1311
|
+
let u = (i || r()) - l;
|
|
1312
|
+
return a - u;
|
|
1313
|
+
}, this.#v = (o) => {
|
|
1314
|
+
let h = e[o], a = t[o];
|
|
1315
|
+
return !!a && !!h && (i || r()) - h > a;
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
#k = () => {
|
|
1319
|
+
};
|
|
1320
|
+
#N = () => {
|
|
1321
|
+
};
|
|
1322
|
+
#j = () => {
|
|
1323
|
+
};
|
|
1324
|
+
#v = () => false;
|
|
1325
|
+
#G() {
|
|
1326
|
+
let t = new Tt(this.#t);
|
|
1327
|
+
this.#u = 0, this.#C = t, this.#P = (e) => {
|
|
1328
|
+
this.#u -= t[e], t[e] = 0;
|
|
1329
|
+
}, this.#I = (e, s, i, r) => {
|
|
1330
|
+
if (this.#l(s)) return 0;
|
|
1331
|
+
if (!q(i)) if (r) {
|
|
1332
|
+
if (typeof r != "function") throw new TypeError("sizeCalculation must be a function");
|
|
1333
|
+
if (i = r(s, e), !q(i)) throw new TypeError("sizeCalculation return invalid (expect positive integer)");
|
|
1334
|
+
} else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
|
|
1335
|
+
return i;
|
|
1336
|
+
}, this.#L = (e, s, i) => {
|
|
1337
|
+
if (t[e] = s, this.#s) {
|
|
1338
|
+
let r = this.#s - t[e];
|
|
1339
|
+
for (; this.#u > r; ) this.#B(true);
|
|
1340
|
+
}
|
|
1341
|
+
this.#u += t[e], i && (i.entrySize = s, i.totalCalculatedSize = this.#u);
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
#P = (t) => {
|
|
1345
|
+
};
|
|
1346
|
+
#L = (t, e, s) => {
|
|
1347
|
+
};
|
|
1348
|
+
#I = (t, e, s, i) => {
|
|
1349
|
+
if (s || i) throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
|
|
1350
|
+
return 0;
|
|
1351
|
+
};
|
|
1352
|
+
*#F({ allowStale: t = this.allowStale } = {}) {
|
|
1353
|
+
if (this.#h) for (let e = this.#p; !(!this.#z(e) || ((t || !this.#v(e)) && (yield e), e === this.#b)); ) e = this.#E[e];
|
|
1354
|
+
}
|
|
1355
|
+
*#D({ allowStale: t = this.allowStale } = {}) {
|
|
1356
|
+
if (this.#h) for (let e = this.#b; !(!this.#z(e) || ((t || !this.#v(e)) && (yield e), e === this.#p)); ) e = this.#d[e];
|
|
1357
|
+
}
|
|
1358
|
+
#z(t) {
|
|
1359
|
+
return t !== void 0 && this.#f.get(this.#a[t]) === t;
|
|
1360
|
+
}
|
|
1361
|
+
*entries() {
|
|
1362
|
+
for (let t of this.#F()) this.#i[t] !== void 0 && this.#a[t] !== void 0 && !this.#l(this.#i[t]) && (yield [this.#a[t], this.#i[t]]);
|
|
1363
|
+
}
|
|
1364
|
+
*rentries() {
|
|
1365
|
+
for (let t of this.#D()) this.#i[t] !== void 0 && this.#a[t] !== void 0 && !this.#l(this.#i[t]) && (yield [this.#a[t], this.#i[t]]);
|
|
1366
|
+
}
|
|
1367
|
+
*keys() {
|
|
1368
|
+
for (let t of this.#F()) {
|
|
1369
|
+
let e = this.#a[t];
|
|
1370
|
+
e !== void 0 && !this.#l(this.#i[t]) && (yield e);
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
*rkeys() {
|
|
1374
|
+
for (let t of this.#D()) {
|
|
1375
|
+
let e = this.#a[t];
|
|
1376
|
+
e !== void 0 && !this.#l(this.#i[t]) && (yield e);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
*values() {
|
|
1380
|
+
for (let t of this.#F()) this.#i[t] !== void 0 && !this.#l(this.#i[t]) && (yield this.#i[t]);
|
|
1381
|
+
}
|
|
1382
|
+
*rvalues() {
|
|
1383
|
+
for (let t of this.#D()) this.#i[t] !== void 0 && !this.#l(this.#i[t]) && (yield this.#i[t]);
|
|
1384
|
+
}
|
|
1385
|
+
[Symbol.iterator]() {
|
|
1386
|
+
return this.entries();
|
|
1387
|
+
}
|
|
1388
|
+
[Symbol.toStringTag] = "LRUCache";
|
|
1389
|
+
find(t, e = {}) {
|
|
1390
|
+
for (let s of this.#F()) {
|
|
1391
|
+
let i = this.#i[s], r = this.#l(i) ? i.__staleWhileFetching : i;
|
|
1392
|
+
if (r !== void 0 && t(r, this.#a[s], this)) return this.get(this.#a[s], e);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
forEach(t, e = this) {
|
|
1396
|
+
for (let s of this.#F()) {
|
|
1397
|
+
let i = this.#i[s], r = this.#l(i) ? i.__staleWhileFetching : i;
|
|
1398
|
+
r !== void 0 && t.call(e, r, this.#a[s], this);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
rforEach(t, e = this) {
|
|
1402
|
+
for (let s of this.#D()) {
|
|
1403
|
+
let i = this.#i[s], r = this.#l(i) ? i.__staleWhileFetching : i;
|
|
1404
|
+
r !== void 0 && t.call(e, r, this.#a[s], this);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
purgeStale() {
|
|
1408
|
+
let t = false;
|
|
1409
|
+
for (let e of this.#D({ allowStale: true })) this.#v(e) && (this.#O(this.#a[e], "expire"), t = true);
|
|
1410
|
+
return t;
|
|
1411
|
+
}
|
|
1412
|
+
info(t) {
|
|
1413
|
+
let e = this.#f.get(t);
|
|
1414
|
+
if (e === void 0) return;
|
|
1415
|
+
let s = this.#i[e], i = this.#l(s) ? s.__staleWhileFetching : s;
|
|
1416
|
+
if (i === void 0) return;
|
|
1417
|
+
let r = { value: i };
|
|
1418
|
+
if (this.#g && this.#T) {
|
|
1419
|
+
let o = this.#g[e], h = this.#T[e];
|
|
1420
|
+
if (o && h) {
|
|
1421
|
+
let a = o - (this.#c.now() - h);
|
|
1422
|
+
r.ttl = a, r.start = Date.now();
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
return this.#C && (r.size = this.#C[e]), r;
|
|
1426
|
+
}
|
|
1427
|
+
dump() {
|
|
1428
|
+
let t = [];
|
|
1429
|
+
for (let e of this.#F({ allowStale: true })) {
|
|
1430
|
+
let s = this.#a[e], i = this.#i[e], r = this.#l(i) ? i.__staleWhileFetching : i;
|
|
1431
|
+
if (r === void 0 || s === void 0) continue;
|
|
1432
|
+
let o = { value: r };
|
|
1433
|
+
if (this.#g && this.#T) {
|
|
1434
|
+
o.ttl = this.#g[e];
|
|
1435
|
+
let h = this.#c.now() - this.#T[e];
|
|
1436
|
+
o.start = Math.floor(Date.now() - h);
|
|
1437
|
+
}
|
|
1438
|
+
this.#C && (o.size = this.#C[e]), t.unshift([s, o]);
|
|
1439
|
+
}
|
|
1440
|
+
return t;
|
|
1441
|
+
}
|
|
1442
|
+
load(t) {
|
|
1443
|
+
this.clear();
|
|
1444
|
+
for (let [e, s] of t) {
|
|
1445
|
+
if (s.start) {
|
|
1446
|
+
let i = Date.now() - s.start;
|
|
1447
|
+
s.start = this.#c.now() - i;
|
|
1448
|
+
}
|
|
1449
|
+
this.set(e, s.value, s);
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
set(t, e, s = {}) {
|
|
1453
|
+
if (e === void 0) return this.delete(t), this;
|
|
1454
|
+
let { ttl: i = this.ttl, start: r, noDisposeOnSet: o = this.noDisposeOnSet, sizeCalculation: h = this.sizeCalculation, status: a } = s, { noUpdateTTL: l = this.noUpdateTTL } = s, u = this.#I(t, e, s.size || 0, h);
|
|
1455
|
+
if (this.maxEntrySize && u > this.maxEntrySize) return a && (a.set = "miss", a.maxEntrySizeExceeded = true), this.#O(t, "set"), this;
|
|
1456
|
+
let c = this.#h === 0 ? void 0 : this.#f.get(t);
|
|
1457
|
+
if (c === void 0) c = this.#h === 0 ? this.#p : this.#R.length !== 0 ? this.#R.pop() : this.#h === this.#t ? this.#B(false) : this.#h, this.#a[c] = t, this.#i[c] = e, this.#f.set(t, c), this.#d[this.#p] = c, this.#E[c] = this.#p, this.#p = c, this.#h++, this.#L(c, u, a), a && (a.set = "add"), l = false, this.#_ && this.#r?.(e, t, "add");
|
|
1458
|
+
else {
|
|
1459
|
+
this.#W(c);
|
|
1460
|
+
let d = this.#i[c];
|
|
1461
|
+
if (e !== d) {
|
|
1462
|
+
if (this.#A && this.#l(d)) {
|
|
1463
|
+
d.__abortController.abort(new Error("replaced"));
|
|
1464
|
+
let { __staleWhileFetching: f } = d;
|
|
1465
|
+
f !== void 0 && !o && (this.#x && this.#n?.(f, t, "set"), this.#e && this.#m?.push([f, t, "set"]));
|
|
1466
|
+
} else o || (this.#x && this.#n?.(d, t, "set"), this.#e && this.#m?.push([d, t, "set"]));
|
|
1467
|
+
if (this.#P(c), this.#L(c, u, a), this.#i[c] = e, a) {
|
|
1468
|
+
a.set = "replace";
|
|
1469
|
+
let f = d && this.#l(d) ? d.__staleWhileFetching : d;
|
|
1470
|
+
f !== void 0 && (a.oldValue = f);
|
|
1471
|
+
}
|
|
1472
|
+
} else a && (a.set = "update");
|
|
1473
|
+
this.#_ && this.onInsert?.(e, t, e === d ? "update" : "replace");
|
|
1474
|
+
}
|
|
1475
|
+
if (i !== 0 && !this.#g && this.#M(), this.#g && (l || this.#j(c, i, r), a && this.#N(a, c)), !o && this.#e && this.#m) {
|
|
1476
|
+
let d = this.#m, f;
|
|
1477
|
+
for (; f = d?.shift(); ) this.#o?.(...f);
|
|
1478
|
+
}
|
|
1479
|
+
return this;
|
|
1480
|
+
}
|
|
1481
|
+
pop() {
|
|
1482
|
+
try {
|
|
1483
|
+
for (; this.#h; ) {
|
|
1484
|
+
let t = this.#i[this.#b];
|
|
1485
|
+
if (this.#B(true), this.#l(t)) {
|
|
1486
|
+
if (t.__staleWhileFetching) return t.__staleWhileFetching;
|
|
1487
|
+
} else if (t !== void 0) return t;
|
|
1488
|
+
}
|
|
1489
|
+
} finally {
|
|
1490
|
+
if (this.#e && this.#m) {
|
|
1491
|
+
let t = this.#m, e;
|
|
1492
|
+
for (; e = t?.shift(); ) this.#o?.(...e);
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
#B(t) {
|
|
1497
|
+
let e = this.#b, s = this.#a[e], i = this.#i[e];
|
|
1498
|
+
return this.#A && this.#l(i) ? i.__abortController.abort(new Error("evicted")) : (this.#x || this.#e) && (this.#x && this.#n?.(i, s, "evict"), this.#e && this.#m?.push([i, s, "evict"])), this.#P(e), this.#y?.[e] && (clearTimeout(this.#y[e]), this.#y[e] = void 0), t && (this.#a[e] = void 0, this.#i[e] = void 0, this.#R.push(e)), this.#h === 1 ? (this.#b = this.#p = 0, this.#R.length = 0) : this.#b = this.#d[e], this.#f.delete(s), this.#h--, e;
|
|
1499
|
+
}
|
|
1500
|
+
has(t, e = {}) {
|
|
1501
|
+
let { updateAgeOnHas: s = this.updateAgeOnHas, status: i } = e, r = this.#f.get(t);
|
|
1502
|
+
if (r !== void 0) {
|
|
1503
|
+
let o = this.#i[r];
|
|
1504
|
+
if (this.#l(o) && o.__staleWhileFetching === void 0) return false;
|
|
1505
|
+
if (this.#v(r)) i && (i.has = "stale", this.#N(i, r));
|
|
1506
|
+
else return s && this.#k(r), i && (i.has = "hit", this.#N(i, r)), true;
|
|
1507
|
+
} else i && (i.has = "miss");
|
|
1508
|
+
return false;
|
|
1509
|
+
}
|
|
1510
|
+
peek(t, e = {}) {
|
|
1511
|
+
let { allowStale: s = this.allowStale } = e, i = this.#f.get(t);
|
|
1512
|
+
if (i === void 0 || !s && this.#v(i)) return;
|
|
1513
|
+
let r = this.#i[i];
|
|
1514
|
+
return this.#l(r) ? r.__staleWhileFetching : r;
|
|
1515
|
+
}
|
|
1516
|
+
#U(t, e, s, i) {
|
|
1517
|
+
let r = e === void 0 ? void 0 : this.#i[e];
|
|
1518
|
+
if (this.#l(r)) return r;
|
|
1519
|
+
let o = new At(), { signal: h } = s;
|
|
1520
|
+
h?.addEventListener("abort", () => o.abort(h.reason), { signal: o.signal });
|
|
1521
|
+
let a = { signal: o.signal, options: s, context: i }, l = (p, w = false) => {
|
|
1522
|
+
let { aborted: g } = o.signal, S = s.ignoreFetchAbort && p !== void 0, E = s.ignoreFetchAbort || !!(s.allowStaleOnFetchAbort && p !== void 0);
|
|
1523
|
+
if (s.status && (g && !w ? (s.status.fetchAborted = true, s.status.fetchError = o.signal.reason, S && (s.status.fetchAbortIgnored = true)) : s.status.fetchResolved = true), g && !S && !w) return c(o.signal.reason, E);
|
|
1524
|
+
let y = f, b = this.#i[e];
|
|
1525
|
+
return (b === f || S && w && b === void 0) && (p === void 0 ? y.__staleWhileFetching !== void 0 ? this.#i[e] = y.__staleWhileFetching : this.#O(t, "fetch") : (s.status && (s.status.fetchUpdated = true), this.set(t, p, a.options))), p;
|
|
1526
|
+
}, u = (p) => (s.status && (s.status.fetchRejected = true, s.status.fetchError = p), c(p, false)), c = (p, w) => {
|
|
1527
|
+
let { aborted: g } = o.signal, S = g && s.allowStaleOnFetchAbort, E = S || s.allowStaleOnFetchRejection, y = E || s.noDeleteOnFetchRejection, b = f;
|
|
1528
|
+
if (this.#i[e] === f && (!y || !w && b.__staleWhileFetching === void 0 ? this.#O(t, "fetch") : S || (this.#i[e] = b.__staleWhileFetching)), E) return s.status && b.__staleWhileFetching !== void 0 && (s.status.returnedStale = true), b.__staleWhileFetching;
|
|
1529
|
+
if (b.__returned === b) throw p;
|
|
1530
|
+
}, d = (p, w) => {
|
|
1531
|
+
let g = this.#S?.(t, r, a);
|
|
1532
|
+
g && g instanceof Promise && g.then((S) => p(S === void 0 ? void 0 : S), w), o.signal.addEventListener("abort", () => {
|
|
1533
|
+
(!s.ignoreFetchAbort || s.allowStaleOnFetchAbort) && (p(void 0), s.allowStaleOnFetchAbort && (p = (S) => l(S, true)));
|
|
1534
|
+
});
|
|
1535
|
+
};
|
|
1536
|
+
s.status && (s.status.fetchDispatched = true);
|
|
1537
|
+
let f = new Promise(d).then(l, u), m = Object.assign(f, { __abortController: o, __staleWhileFetching: r, __returned: void 0 });
|
|
1538
|
+
return e === void 0 ? (this.set(t, m, { ...a.options, status: void 0 }), e = this.#f.get(t)) : this.#i[e] = m, m;
|
|
1539
|
+
}
|
|
1540
|
+
#l(t) {
|
|
1541
|
+
if (!this.#A) return false;
|
|
1542
|
+
let e = t;
|
|
1543
|
+
return !!e && e instanceof Promise && e.hasOwnProperty("__staleWhileFetching") && e.__abortController instanceof At;
|
|
1544
|
+
}
|
|
1545
|
+
async fetch(t, e = {}) {
|
|
1546
|
+
let { allowStale: s = this.allowStale, updateAgeOnGet: i = this.updateAgeOnGet, noDeleteOnStaleGet: r = this.noDeleteOnStaleGet, ttl: o = this.ttl, noDisposeOnSet: h = this.noDisposeOnSet, size: a = 0, sizeCalculation: l = this.sizeCalculation, noUpdateTTL: u = this.noUpdateTTL, noDeleteOnFetchRejection: c = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection: d = this.allowStaleOnFetchRejection, ignoreFetchAbort: f = this.ignoreFetchAbort, allowStaleOnFetchAbort: m = this.allowStaleOnFetchAbort, context: p, forceRefresh: w = false, status: g, signal: S } = e;
|
|
1547
|
+
if (!this.#A) return g && (g.fetch = "get"), this.get(t, { allowStale: s, updateAgeOnGet: i, noDeleteOnStaleGet: r, status: g });
|
|
1548
|
+
let E = { allowStale: s, updateAgeOnGet: i, noDeleteOnStaleGet: r, ttl: o, noDisposeOnSet: h, size: a, sizeCalculation: l, noUpdateTTL: u, noDeleteOnFetchRejection: c, allowStaleOnFetchRejection: d, allowStaleOnFetchAbort: m, ignoreFetchAbort: f, status: g, signal: S }, y = this.#f.get(t);
|
|
1549
|
+
if (y === void 0) {
|
|
1550
|
+
g && (g.fetch = "miss");
|
|
1551
|
+
let b = this.#U(t, y, E, p);
|
|
1552
|
+
return b.__returned = b;
|
|
1553
|
+
} else {
|
|
1554
|
+
let b = this.#i[y];
|
|
1555
|
+
if (this.#l(b)) {
|
|
1556
|
+
let Z = s && b.__staleWhileFetching !== void 0;
|
|
1557
|
+
return g && (g.fetch = "inflight", Z && (g.returnedStale = true)), Z ? b.__staleWhileFetching : b.__returned = b;
|
|
1558
|
+
}
|
|
1559
|
+
let z = this.#v(y);
|
|
1560
|
+
if (!w && !z) return g && (g.fetch = "hit"), this.#W(y), i && this.#k(y), g && this.#N(g, y), b;
|
|
1561
|
+
let $ = this.#U(t, y, E, p), J = $.__staleWhileFetching !== void 0 && s;
|
|
1562
|
+
return g && (g.fetch = z ? "stale" : "refresh", J && z && (g.returnedStale = true)), J ? $.__staleWhileFetching : $.__returned = $;
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
async forceFetch(t, e = {}) {
|
|
1566
|
+
let s = await this.fetch(t, e);
|
|
1567
|
+
if (s === void 0) throw new Error("fetch() returned undefined");
|
|
1568
|
+
return s;
|
|
1569
|
+
}
|
|
1570
|
+
memo(t, e = {}) {
|
|
1571
|
+
let s = this.#w;
|
|
1572
|
+
if (!s) throw new Error("no memoMethod provided to constructor");
|
|
1573
|
+
let { context: i, forceRefresh: r, ...o } = e, h = this.get(t, o);
|
|
1574
|
+
if (!r && h !== void 0) return h;
|
|
1575
|
+
let a = s(t, h, { options: o, context: i });
|
|
1576
|
+
return this.set(t, a, o), a;
|
|
1577
|
+
}
|
|
1578
|
+
get(t, e = {}) {
|
|
1579
|
+
let { allowStale: s = this.allowStale, updateAgeOnGet: i = this.updateAgeOnGet, noDeleteOnStaleGet: r = this.noDeleteOnStaleGet, status: o } = e, h = this.#f.get(t);
|
|
1580
|
+
if (h !== void 0) {
|
|
1581
|
+
let a = this.#i[h], l = this.#l(a);
|
|
1582
|
+
return o && this.#N(o, h), this.#v(h) ? (o && (o.get = "stale"), l ? (o && s && a.__staleWhileFetching !== void 0 && (o.returnedStale = true), s ? a.__staleWhileFetching : void 0) : (r || this.#O(t, "expire"), o && s && (o.returnedStale = true), s ? a : void 0)) : (o && (o.get = "hit"), l ? a.__staleWhileFetching : (this.#W(h), i && this.#k(h), a));
|
|
1583
|
+
} else o && (o.get = "miss");
|
|
1584
|
+
}
|
|
1585
|
+
#$(t, e) {
|
|
1586
|
+
this.#E[e] = t, this.#d[t] = e;
|
|
1587
|
+
}
|
|
1588
|
+
#W(t) {
|
|
1589
|
+
t !== this.#p && (t === this.#b ? this.#b = this.#d[t] : this.#$(this.#E[t], this.#d[t]), this.#$(this.#p, t), this.#p = t);
|
|
1590
|
+
}
|
|
1591
|
+
delete(t) {
|
|
1592
|
+
return this.#O(t, "delete");
|
|
1593
|
+
}
|
|
1594
|
+
#O(t, e) {
|
|
1595
|
+
let s = false;
|
|
1596
|
+
if (this.#h !== 0) {
|
|
1597
|
+
let i = this.#f.get(t);
|
|
1598
|
+
if (i !== void 0) if (this.#y?.[i] && (clearTimeout(this.#y?.[i]), this.#y[i] = void 0), s = true, this.#h === 1) this.#H(e);
|
|
1599
|
+
else {
|
|
1600
|
+
this.#P(i);
|
|
1601
|
+
let r = this.#i[i];
|
|
1602
|
+
if (this.#l(r) ? r.__abortController.abort(new Error("deleted")) : (this.#x || this.#e) && (this.#x && this.#n?.(r, t, e), this.#e && this.#m?.push([r, t, e])), this.#f.delete(t), this.#a[i] = void 0, this.#i[i] = void 0, i === this.#p) this.#p = this.#E[i];
|
|
1603
|
+
else if (i === this.#b) this.#b = this.#d[i];
|
|
1604
|
+
else {
|
|
1605
|
+
let o = this.#E[i];
|
|
1606
|
+
this.#d[o] = this.#d[i];
|
|
1607
|
+
let h = this.#d[i];
|
|
1608
|
+
this.#E[h] = this.#E[i];
|
|
1609
|
+
}
|
|
1610
|
+
this.#h--, this.#R.push(i);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
if (this.#e && this.#m?.length) {
|
|
1614
|
+
let i = this.#m, r;
|
|
1615
|
+
for (; r = i?.shift(); ) this.#o?.(...r);
|
|
1616
|
+
}
|
|
1617
|
+
return s;
|
|
1618
|
+
}
|
|
1619
|
+
clear() {
|
|
1620
|
+
return this.#H("delete");
|
|
1621
|
+
}
|
|
1622
|
+
#H(t) {
|
|
1623
|
+
for (let e of this.#D({ allowStale: true })) {
|
|
1624
|
+
let s = this.#i[e];
|
|
1625
|
+
if (this.#l(s)) s.__abortController.abort(new Error("deleted"));
|
|
1626
|
+
else {
|
|
1627
|
+
let i = this.#a[e];
|
|
1628
|
+
this.#x && this.#n?.(s, i, t), this.#e && this.#m?.push([s, i, t]);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
if (this.#f.clear(), this.#i.fill(void 0), this.#a.fill(void 0), this.#g && this.#T) {
|
|
1632
|
+
this.#g.fill(0), this.#T.fill(0);
|
|
1633
|
+
for (let e of this.#y ?? []) e !== void 0 && clearTimeout(e);
|
|
1634
|
+
this.#y?.fill(void 0);
|
|
1635
|
+
}
|
|
1636
|
+
if (this.#C && this.#C.fill(0), this.#b = 0, this.#p = 0, this.#R.length = 0, this.#u = 0, this.#h = 0, this.#e && this.#m) {
|
|
1637
|
+
let e = this.#m, s;
|
|
1638
|
+
for (; s = e?.shift(); ) this.#o?.(...s);
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
};
|
|
1642
|
+
var Ne = typeof process == "object" && process ? process : { stdout: null, stderr: null };
|
|
1643
|
+
var oi = (n7) => !!n7 && typeof n7 == "object" && (n7 instanceof V || n7 instanceof Pe || hi(n7) || ai(n7));
|
|
1644
|
+
var hi = (n7) => !!n7 && typeof n7 == "object" && n7 instanceof ee && typeof n7.pipe == "function" && n7.pipe !== Pe.Writable.prototype.pipe;
|
|
1645
|
+
var ai = (n7) => !!n7 && typeof n7 == "object" && n7 instanceof ee && typeof n7.write == "function" && typeof n7.end == "function";
|
|
1646
|
+
var G = /* @__PURE__ */ Symbol("EOF");
|
|
1647
|
+
var H = /* @__PURE__ */ Symbol("maybeEmitEnd");
|
|
1648
|
+
var K = /* @__PURE__ */ Symbol("emittedEnd");
|
|
1649
|
+
var kt = /* @__PURE__ */ Symbol("emittingEnd");
|
|
1650
|
+
var ut = /* @__PURE__ */ Symbol("emittedError");
|
|
1651
|
+
var Rt = /* @__PURE__ */ Symbol("closed");
|
|
1652
|
+
var _e = /* @__PURE__ */ Symbol("read");
|
|
1653
|
+
var Ot = /* @__PURE__ */ Symbol("flush");
|
|
1654
|
+
var Le = /* @__PURE__ */ Symbol("flushChunk");
|
|
1655
|
+
var P = /* @__PURE__ */ Symbol("encoding");
|
|
1656
|
+
var et = /* @__PURE__ */ Symbol("decoder");
|
|
1657
|
+
var v = /* @__PURE__ */ Symbol("flowing");
|
|
1658
|
+
var dt = /* @__PURE__ */ Symbol("paused");
|
|
1659
|
+
var st = /* @__PURE__ */ Symbol("resume");
|
|
1660
|
+
var C = /* @__PURE__ */ Symbol("buffer");
|
|
1661
|
+
var F = /* @__PURE__ */ Symbol("pipes");
|
|
1662
|
+
var T = /* @__PURE__ */ Symbol("bufferLength");
|
|
1663
|
+
var Yt = /* @__PURE__ */ Symbol("bufferPush");
|
|
1664
|
+
var Ft = /* @__PURE__ */ Symbol("bufferShift");
|
|
1665
|
+
var k = /* @__PURE__ */ Symbol("objectMode");
|
|
1666
|
+
var x = /* @__PURE__ */ Symbol("destroyed");
|
|
1667
|
+
var Xt = /* @__PURE__ */ Symbol("error");
|
|
1668
|
+
var Jt = /* @__PURE__ */ Symbol("emitData");
|
|
1669
|
+
var We = /* @__PURE__ */ Symbol("emitEnd");
|
|
1670
|
+
var Zt = /* @__PURE__ */ Symbol("emitEnd2");
|
|
1671
|
+
var B = /* @__PURE__ */ Symbol("async");
|
|
1672
|
+
var Qt = /* @__PURE__ */ Symbol("abort");
|
|
1673
|
+
var Dt = /* @__PURE__ */ Symbol("aborted");
|
|
1674
|
+
var pt = /* @__PURE__ */ Symbol("signal");
|
|
1675
|
+
var Y = /* @__PURE__ */ Symbol("dataListeners");
|
|
1676
|
+
var M = /* @__PURE__ */ Symbol("discarded");
|
|
1677
|
+
var mt = (n7) => Promise.resolve().then(n7);
|
|
1678
|
+
var li = (n7) => n7();
|
|
1679
|
+
var ci = (n7) => n7 === "end" || n7 === "finish" || n7 === "prefinish";
|
|
1680
|
+
var fi = (n7) => n7 instanceof ArrayBuffer || !!n7 && typeof n7 == "object" && n7.constructor && n7.constructor.name === "ArrayBuffer" && n7.byteLength >= 0;
|
|
1681
|
+
var ui = (n7) => !Buffer.isBuffer(n7) && ArrayBuffer.isView(n7);
|
|
1682
|
+
var Mt = class {
|
|
1683
|
+
src;
|
|
1684
|
+
dest;
|
|
1685
|
+
opts;
|
|
1686
|
+
ondrain;
|
|
1687
|
+
constructor(t, e, s) {
|
|
1688
|
+
this.src = t, this.dest = e, this.opts = s, this.ondrain = () => t[st](), this.dest.on("drain", this.ondrain);
|
|
1689
|
+
}
|
|
1690
|
+
unpipe() {
|
|
1691
|
+
this.dest.removeListener("drain", this.ondrain);
|
|
1692
|
+
}
|
|
1693
|
+
proxyErrors(t) {
|
|
1694
|
+
}
|
|
1695
|
+
end() {
|
|
1696
|
+
this.unpipe(), this.opts.end && this.dest.end();
|
|
1697
|
+
}
|
|
1698
|
+
};
|
|
1699
|
+
var te = class extends Mt {
|
|
1700
|
+
unpipe() {
|
|
1701
|
+
this.src.removeListener("error", this.proxyErrors), super.unpipe();
|
|
1702
|
+
}
|
|
1703
|
+
constructor(t, e, s) {
|
|
1704
|
+
super(t, e, s), this.proxyErrors = (i) => this.dest.emit("error", i), t.on("error", this.proxyErrors);
|
|
1705
|
+
}
|
|
1706
|
+
};
|
|
1707
|
+
var di = (n7) => !!n7.objectMode;
|
|
1708
|
+
var pi = (n7) => !n7.objectMode && !!n7.encoding && n7.encoding !== "buffer";
|
|
1709
|
+
var V = class extends ee {
|
|
1710
|
+
[v] = false;
|
|
1711
|
+
[dt] = false;
|
|
1712
|
+
[F] = [];
|
|
1713
|
+
[C] = [];
|
|
1714
|
+
[k];
|
|
1715
|
+
[P];
|
|
1716
|
+
[B];
|
|
1717
|
+
[et];
|
|
1718
|
+
[G] = false;
|
|
1719
|
+
[K] = false;
|
|
1720
|
+
[kt] = false;
|
|
1721
|
+
[Rt] = false;
|
|
1722
|
+
[ut] = null;
|
|
1723
|
+
[T] = 0;
|
|
1724
|
+
[x] = false;
|
|
1725
|
+
[pt];
|
|
1726
|
+
[Dt] = false;
|
|
1727
|
+
[Y] = 0;
|
|
1728
|
+
[M] = false;
|
|
1729
|
+
writable = true;
|
|
1730
|
+
readable = true;
|
|
1731
|
+
constructor(...t) {
|
|
1732
|
+
let e = t[0] || {};
|
|
1733
|
+
if (super(), e.objectMode && typeof e.encoding == "string") throw new TypeError("Encoding and objectMode may not be used together");
|
|
1734
|
+
di(e) ? (this[k] = true, this[P] = null) : pi(e) ? (this[P] = e.encoding, this[k] = false) : (this[k] = false, this[P] = null), this[B] = !!e.async, this[et] = this[P] ? new ni(this[P]) : null, e && e.debugExposeBuffer === true && Object.defineProperty(this, "buffer", { get: () => this[C] }), e && e.debugExposePipes === true && Object.defineProperty(this, "pipes", { get: () => this[F] });
|
|
1735
|
+
let { signal: s } = e;
|
|
1736
|
+
s && (this[pt] = s, s.aborted ? this[Qt]() : s.addEventListener("abort", () => this[Qt]()));
|
|
1737
|
+
}
|
|
1738
|
+
get bufferLength() {
|
|
1739
|
+
return this[T];
|
|
1740
|
+
}
|
|
1741
|
+
get encoding() {
|
|
1742
|
+
return this[P];
|
|
1743
|
+
}
|
|
1744
|
+
set encoding(t) {
|
|
1745
|
+
throw new Error("Encoding must be set at instantiation time");
|
|
1746
|
+
}
|
|
1747
|
+
setEncoding(t) {
|
|
1748
|
+
throw new Error("Encoding must be set at instantiation time");
|
|
1749
|
+
}
|
|
1750
|
+
get objectMode() {
|
|
1751
|
+
return this[k];
|
|
1752
|
+
}
|
|
1753
|
+
set objectMode(t) {
|
|
1754
|
+
throw new Error("objectMode must be set at instantiation time");
|
|
1755
|
+
}
|
|
1756
|
+
get async() {
|
|
1757
|
+
return this[B];
|
|
1758
|
+
}
|
|
1759
|
+
set async(t) {
|
|
1760
|
+
this[B] = this[B] || !!t;
|
|
1761
|
+
}
|
|
1762
|
+
[Qt]() {
|
|
1763
|
+
this[Dt] = true, this.emit("abort", this[pt]?.reason), this.destroy(this[pt]?.reason);
|
|
1764
|
+
}
|
|
1765
|
+
get aborted() {
|
|
1766
|
+
return this[Dt];
|
|
1767
|
+
}
|
|
1768
|
+
set aborted(t) {
|
|
1769
|
+
}
|
|
1770
|
+
write(t, e, s) {
|
|
1771
|
+
if (this[Dt]) return false;
|
|
1772
|
+
if (this[G]) throw new Error("write after end");
|
|
1773
|
+
if (this[x]) return this.emit("error", Object.assign(new Error("Cannot call write after a stream was destroyed"), { code: "ERR_STREAM_DESTROYED" })), true;
|
|
1774
|
+
typeof e == "function" && (s = e, e = "utf8"), e || (e = "utf8");
|
|
1775
|
+
let i = this[B] ? mt : li;
|
|
1776
|
+
if (!this[k] && !Buffer.isBuffer(t)) {
|
|
1777
|
+
if (ui(t)) t = Buffer.from(t.buffer, t.byteOffset, t.byteLength);
|
|
1778
|
+
else if (fi(t)) t = Buffer.from(t);
|
|
1779
|
+
else if (typeof t != "string") throw new Error("Non-contiguous data written to non-objectMode stream");
|
|
1780
|
+
}
|
|
1781
|
+
return this[k] ? (this[v] && this[T] !== 0 && this[Ot](true), this[v] ? this.emit("data", t) : this[Yt](t), this[T] !== 0 && this.emit("readable"), s && i(s), this[v]) : t.length ? (typeof t == "string" && !(e === this[P] && !this[et]?.lastNeed) && (t = Buffer.from(t, e)), Buffer.isBuffer(t) && this[P] && (t = this[et].write(t)), this[v] && this[T] !== 0 && this[Ot](true), this[v] ? this.emit("data", t) : this[Yt](t), this[T] !== 0 && this.emit("readable"), s && i(s), this[v]) : (this[T] !== 0 && this.emit("readable"), s && i(s), this[v]);
|
|
1782
|
+
}
|
|
1783
|
+
read(t) {
|
|
1784
|
+
if (this[x]) return null;
|
|
1785
|
+
if (this[M] = false, this[T] === 0 || t === 0 || t && t > this[T]) return this[H](), null;
|
|
1786
|
+
this[k] && (t = null), this[C].length > 1 && !this[k] && (this[C] = [this[P] ? this[C].join("") : Buffer.concat(this[C], this[T])]);
|
|
1787
|
+
let e = this[_e](t || null, this[C][0]);
|
|
1788
|
+
return this[H](), e;
|
|
1789
|
+
}
|
|
1790
|
+
[_e](t, e) {
|
|
1791
|
+
if (this[k]) this[Ft]();
|
|
1792
|
+
else {
|
|
1793
|
+
let s = e;
|
|
1794
|
+
t === s.length || t === null ? this[Ft]() : typeof s == "string" ? (this[C][0] = s.slice(t), e = s.slice(0, t), this[T] -= t) : (this[C][0] = s.subarray(t), e = s.subarray(0, t), this[T] -= t);
|
|
1795
|
+
}
|
|
1796
|
+
return this.emit("data", e), !this[C].length && !this[G] && this.emit("drain"), e;
|
|
1797
|
+
}
|
|
1798
|
+
end(t, e, s) {
|
|
1799
|
+
return typeof t == "function" && (s = t, t = void 0), typeof e == "function" && (s = e, e = "utf8"), t !== void 0 && this.write(t, e), s && this.once("end", s), this[G] = true, this.writable = false, (this[v] || !this[dt]) && this[H](), this;
|
|
1800
|
+
}
|
|
1801
|
+
[st]() {
|
|
1802
|
+
this[x] || (!this[Y] && !this[F].length && (this[M] = true), this[dt] = false, this[v] = true, this.emit("resume"), this[C].length ? this[Ot]() : this[G] ? this[H]() : this.emit("drain"));
|
|
1803
|
+
}
|
|
1804
|
+
resume() {
|
|
1805
|
+
return this[st]();
|
|
1806
|
+
}
|
|
1807
|
+
pause() {
|
|
1808
|
+
this[v] = false, this[dt] = true, this[M] = false;
|
|
1809
|
+
}
|
|
1810
|
+
get destroyed() {
|
|
1811
|
+
return this[x];
|
|
1812
|
+
}
|
|
1813
|
+
get flowing() {
|
|
1814
|
+
return this[v];
|
|
1815
|
+
}
|
|
1816
|
+
get paused() {
|
|
1817
|
+
return this[dt];
|
|
1818
|
+
}
|
|
1819
|
+
[Yt](t) {
|
|
1820
|
+
this[k] ? this[T] += 1 : this[T] += t.length, this[C].push(t);
|
|
1821
|
+
}
|
|
1822
|
+
[Ft]() {
|
|
1823
|
+
return this[k] ? this[T] -= 1 : this[T] -= this[C][0].length, this[C].shift();
|
|
1824
|
+
}
|
|
1825
|
+
[Ot](t = false) {
|
|
1826
|
+
do
|
|
1827
|
+
;
|
|
1828
|
+
while (this[Le](this[Ft]()) && this[C].length);
|
|
1829
|
+
!t && !this[C].length && !this[G] && this.emit("drain");
|
|
1830
|
+
}
|
|
1831
|
+
[Le](t) {
|
|
1832
|
+
return this.emit("data", t), this[v];
|
|
1833
|
+
}
|
|
1834
|
+
pipe(t, e) {
|
|
1835
|
+
if (this[x]) return t;
|
|
1836
|
+
this[M] = false;
|
|
1837
|
+
let s = this[K];
|
|
1838
|
+
return e = e || {}, t === Ne.stdout || t === Ne.stderr ? e.end = false : e.end = e.end !== false, e.proxyErrors = !!e.proxyErrors, s ? e.end && t.end() : (this[F].push(e.proxyErrors ? new te(this, t, e) : new Mt(this, t, e)), this[B] ? mt(() => this[st]()) : this[st]()), t;
|
|
1839
|
+
}
|
|
1840
|
+
unpipe(t) {
|
|
1841
|
+
let e = this[F].find((s) => s.dest === t);
|
|
1842
|
+
e && (this[F].length === 1 ? (this[v] && this[Y] === 0 && (this[v] = false), this[F] = []) : this[F].splice(this[F].indexOf(e), 1), e.unpipe());
|
|
1843
|
+
}
|
|
1844
|
+
addListener(t, e) {
|
|
1845
|
+
return this.on(t, e);
|
|
1846
|
+
}
|
|
1847
|
+
on(t, e) {
|
|
1848
|
+
let s = super.on(t, e);
|
|
1849
|
+
if (t === "data") this[M] = false, this[Y]++, !this[F].length && !this[v] && this[st]();
|
|
1850
|
+
else if (t === "readable" && this[T] !== 0) super.emit("readable");
|
|
1851
|
+
else if (ci(t) && this[K]) super.emit(t), this.removeAllListeners(t);
|
|
1852
|
+
else if (t === "error" && this[ut]) {
|
|
1853
|
+
let i = e;
|
|
1854
|
+
this[B] ? mt(() => i.call(this, this[ut])) : i.call(this, this[ut]);
|
|
1855
|
+
}
|
|
1856
|
+
return s;
|
|
1857
|
+
}
|
|
1858
|
+
removeListener(t, e) {
|
|
1859
|
+
return this.off(t, e);
|
|
1860
|
+
}
|
|
1861
|
+
off(t, e) {
|
|
1862
|
+
let s = super.off(t, e);
|
|
1863
|
+
return t === "data" && (this[Y] = this.listeners("data").length, this[Y] === 0 && !this[M] && !this[F].length && (this[v] = false)), s;
|
|
1864
|
+
}
|
|
1865
|
+
removeAllListeners(t) {
|
|
1866
|
+
let e = super.removeAllListeners(t);
|
|
1867
|
+
return (t === "data" || t === void 0) && (this[Y] = 0, !this[M] && !this[F].length && (this[v] = false)), e;
|
|
1868
|
+
}
|
|
1869
|
+
get emittedEnd() {
|
|
1870
|
+
return this[K];
|
|
1871
|
+
}
|
|
1872
|
+
[H]() {
|
|
1873
|
+
!this[kt] && !this[K] && !this[x] && this[C].length === 0 && this[G] && (this[kt] = true, this.emit("end"), this.emit("prefinish"), this.emit("finish"), this[Rt] && this.emit("close"), this[kt] = false);
|
|
1874
|
+
}
|
|
1875
|
+
emit(t, ...e) {
|
|
1876
|
+
let s = e[0];
|
|
1877
|
+
if (t !== "error" && t !== "close" && t !== x && this[x]) return false;
|
|
1878
|
+
if (t === "data") return !this[k] && !s ? false : this[B] ? (mt(() => this[Jt](s)), true) : this[Jt](s);
|
|
1879
|
+
if (t === "end") return this[We]();
|
|
1880
|
+
if (t === "close") {
|
|
1881
|
+
if (this[Rt] = true, !this[K] && !this[x]) return false;
|
|
1882
|
+
let r = super.emit("close");
|
|
1883
|
+
return this.removeAllListeners("close"), r;
|
|
1884
|
+
} else if (t === "error") {
|
|
1885
|
+
this[ut] = s, super.emit(Xt, s);
|
|
1886
|
+
let r = !this[pt] || this.listeners("error").length ? super.emit("error", s) : false;
|
|
1887
|
+
return this[H](), r;
|
|
1888
|
+
} else if (t === "resume") {
|
|
1889
|
+
let r = super.emit("resume");
|
|
1890
|
+
return this[H](), r;
|
|
1891
|
+
} else if (t === "finish" || t === "prefinish") {
|
|
1892
|
+
let r = super.emit(t);
|
|
1893
|
+
return this.removeAllListeners(t), r;
|
|
1894
|
+
}
|
|
1895
|
+
let i = super.emit(t, ...e);
|
|
1896
|
+
return this[H](), i;
|
|
1897
|
+
}
|
|
1898
|
+
[Jt](t) {
|
|
1899
|
+
for (let s of this[F]) s.dest.write(t) === false && this.pause();
|
|
1900
|
+
let e = this[M] ? false : super.emit("data", t);
|
|
1901
|
+
return this[H](), e;
|
|
1902
|
+
}
|
|
1903
|
+
[We]() {
|
|
1904
|
+
return this[K] ? false : (this[K] = true, this.readable = false, this[B] ? (mt(() => this[Zt]()), true) : this[Zt]());
|
|
1905
|
+
}
|
|
1906
|
+
[Zt]() {
|
|
1907
|
+
if (this[et]) {
|
|
1908
|
+
let e = this[et].end();
|
|
1909
|
+
if (e) {
|
|
1910
|
+
for (let s of this[F]) s.dest.write(e);
|
|
1911
|
+
this[M] || super.emit("data", e);
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
for (let e of this[F]) e.end();
|
|
1915
|
+
let t = super.emit("end");
|
|
1916
|
+
return this.removeAllListeners("end"), t;
|
|
1917
|
+
}
|
|
1918
|
+
async collect() {
|
|
1919
|
+
let t = Object.assign([], { dataLength: 0 });
|
|
1920
|
+
this[k] || (t.dataLength = 0);
|
|
1921
|
+
let e = this.promise();
|
|
1922
|
+
return this.on("data", (s) => {
|
|
1923
|
+
t.push(s), this[k] || (t.dataLength += s.length);
|
|
1924
|
+
}), await e, t;
|
|
1925
|
+
}
|
|
1926
|
+
async concat() {
|
|
1927
|
+
if (this[k]) throw new Error("cannot concat in objectMode");
|
|
1928
|
+
let t = await this.collect();
|
|
1929
|
+
return this[P] ? t.join("") : Buffer.concat(t, t.dataLength);
|
|
1930
|
+
}
|
|
1931
|
+
async promise() {
|
|
1932
|
+
return new Promise((t, e) => {
|
|
1933
|
+
this.on(x, () => e(new Error("stream destroyed"))), this.on("error", (s) => e(s)), this.on("end", () => t());
|
|
1934
|
+
});
|
|
1935
|
+
}
|
|
1936
|
+
[Symbol.asyncIterator]() {
|
|
1937
|
+
this[M] = false;
|
|
1938
|
+
let t = false, e = async () => (this.pause(), t = true, { value: void 0, done: true });
|
|
1939
|
+
return { next: () => {
|
|
1940
|
+
if (t) return e();
|
|
1941
|
+
let i = this.read();
|
|
1942
|
+
if (i !== null) return Promise.resolve({ done: false, value: i });
|
|
1943
|
+
if (this[G]) return e();
|
|
1944
|
+
let r, o, h = (c) => {
|
|
1945
|
+
this.off("data", a), this.off("end", l), this.off(x, u), e(), o(c);
|
|
1946
|
+
}, a = (c) => {
|
|
1947
|
+
this.off("error", h), this.off("end", l), this.off(x, u), this.pause(), r({ value: c, done: !!this[G] });
|
|
1948
|
+
}, l = () => {
|
|
1949
|
+
this.off("error", h), this.off("data", a), this.off(x, u), e(), r({ done: true, value: void 0 });
|
|
1950
|
+
}, u = () => h(new Error("stream destroyed"));
|
|
1951
|
+
return new Promise((c, d) => {
|
|
1952
|
+
o = d, r = c, this.once(x, u), this.once("error", h), this.once("end", l), this.once("data", a);
|
|
1953
|
+
});
|
|
1954
|
+
}, throw: e, return: e, [Symbol.asyncIterator]() {
|
|
1955
|
+
return this;
|
|
1956
|
+
}, [Symbol.asyncDispose]: async () => {
|
|
1957
|
+
} };
|
|
1958
|
+
}
|
|
1959
|
+
[Symbol.iterator]() {
|
|
1960
|
+
this[M] = false;
|
|
1961
|
+
let t = false, e = () => (this.pause(), this.off(Xt, e), this.off(x, e), this.off("end", e), t = true, { done: true, value: void 0 }), s = () => {
|
|
1962
|
+
if (t) return e();
|
|
1963
|
+
let i = this.read();
|
|
1964
|
+
return i === null ? e() : { done: false, value: i };
|
|
1965
|
+
};
|
|
1966
|
+
return this.once("end", e), this.once(Xt, e), this.once(x, e), { next: s, throw: e, return: e, [Symbol.iterator]() {
|
|
1967
|
+
return this;
|
|
1968
|
+
}, [Symbol.dispose]: () => {
|
|
1969
|
+
} };
|
|
1970
|
+
}
|
|
1971
|
+
destroy(t) {
|
|
1972
|
+
if (this[x]) return t ? this.emit("error", t) : this.emit(x), this;
|
|
1973
|
+
this[x] = true, this[M] = true, this[C].length = 0, this[T] = 0;
|
|
1974
|
+
let e = this;
|
|
1975
|
+
return typeof e.close == "function" && !this[Rt] && e.close(), t ? this.emit("error", t) : this.emit(x), this;
|
|
1976
|
+
}
|
|
1977
|
+
static get isStream() {
|
|
1978
|
+
return oi;
|
|
1979
|
+
}
|
|
1980
|
+
};
|
|
1981
|
+
var vi = Ei.native;
|
|
1982
|
+
var wt = { lstatSync: wi, readdir: yi, readdirSync: bi, readlinkSync: Si, realpathSync: vi, promises: { lstat: Ci, readdir: Ti, readlink: Ai, realpath: ki } };
|
|
1983
|
+
var Ue = (n7) => !n7 || n7 === wt || n7 === xi ? wt : { ...wt, ...n7, promises: { ...wt.promises, ...n7.promises || {} } };
|
|
1984
|
+
var $e = /^\\\\\?\\([a-z]:)\\?$/i;
|
|
1985
|
+
var Ri = (n7) => n7.replace(/\//g, "\\").replace($e, "$1\\");
|
|
1986
|
+
var Oi = /[\\\/]/;
|
|
1987
|
+
var L = 0;
|
|
1988
|
+
var Ge = 1;
|
|
1989
|
+
var He = 2;
|
|
1990
|
+
var U = 4;
|
|
1991
|
+
var qe = 6;
|
|
1992
|
+
var Ke = 8;
|
|
1993
|
+
var X = 10;
|
|
1994
|
+
var Ve = 12;
|
|
1995
|
+
var _ = 15;
|
|
1996
|
+
var gt = ~_;
|
|
1997
|
+
var se = 16;
|
|
1998
|
+
var je = 32;
|
|
1999
|
+
var yt = 64;
|
|
2000
|
+
var j = 128;
|
|
2001
|
+
var Nt = 256;
|
|
2002
|
+
var Lt = 512;
|
|
2003
|
+
var Ie = yt | j | Lt;
|
|
2004
|
+
var Fi = 1023;
|
|
2005
|
+
var ie = (n7) => n7.isFile() ? Ke : n7.isDirectory() ? U : n7.isSymbolicLink() ? X : n7.isCharacterDevice() ? He : n7.isBlockDevice() ? qe : n7.isSocket() ? Ve : n7.isFIFO() ? Ge : L;
|
|
2006
|
+
var ze = new ft({ max: 2 ** 12 });
|
|
2007
|
+
var bt = (n7) => {
|
|
2008
|
+
let t = ze.get(n7);
|
|
2009
|
+
if (t) return t;
|
|
2010
|
+
let e = n7.normalize("NFKD");
|
|
2011
|
+
return ze.set(n7, e), e;
|
|
2012
|
+
};
|
|
2013
|
+
var Be = new ft({ max: 2 ** 12 });
|
|
2014
|
+
var _t = (n7) => {
|
|
2015
|
+
let t = Be.get(n7);
|
|
2016
|
+
if (t) return t;
|
|
2017
|
+
let e = bt(n7.toLowerCase());
|
|
2018
|
+
return Be.set(n7, e), e;
|
|
2019
|
+
};
|
|
2020
|
+
var Wt = class extends ft {
|
|
2021
|
+
constructor() {
|
|
2022
|
+
super({ max: 256 });
|
|
2023
|
+
}
|
|
2024
|
+
};
|
|
2025
|
+
var ne = class extends ft {
|
|
2026
|
+
constructor(t = 16 * 1024) {
|
|
2027
|
+
super({ maxSize: t, sizeCalculation: (e) => e.length + 1 });
|
|
2028
|
+
}
|
|
2029
|
+
};
|
|
2030
|
+
var Ye = /* @__PURE__ */ Symbol("PathScurry setAsCwd");
|
|
2031
|
+
var R = class {
|
|
2032
|
+
name;
|
|
2033
|
+
root;
|
|
2034
|
+
roots;
|
|
2035
|
+
parent;
|
|
2036
|
+
nocase;
|
|
2037
|
+
isCWD = false;
|
|
2038
|
+
#t;
|
|
2039
|
+
#s;
|
|
2040
|
+
get dev() {
|
|
2041
|
+
return this.#s;
|
|
2042
|
+
}
|
|
2043
|
+
#n;
|
|
2044
|
+
get mode() {
|
|
2045
|
+
return this.#n;
|
|
2046
|
+
}
|
|
2047
|
+
#r;
|
|
2048
|
+
get nlink() {
|
|
2049
|
+
return this.#r;
|
|
2050
|
+
}
|
|
2051
|
+
#o;
|
|
2052
|
+
get uid() {
|
|
2053
|
+
return this.#o;
|
|
2054
|
+
}
|
|
2055
|
+
#S;
|
|
2056
|
+
get gid() {
|
|
2057
|
+
return this.#S;
|
|
2058
|
+
}
|
|
2059
|
+
#w;
|
|
2060
|
+
get rdev() {
|
|
2061
|
+
return this.#w;
|
|
2062
|
+
}
|
|
2063
|
+
#c;
|
|
2064
|
+
get blksize() {
|
|
2065
|
+
return this.#c;
|
|
2066
|
+
}
|
|
2067
|
+
#h;
|
|
2068
|
+
get ino() {
|
|
2069
|
+
return this.#h;
|
|
2070
|
+
}
|
|
2071
|
+
#u;
|
|
2072
|
+
get size() {
|
|
2073
|
+
return this.#u;
|
|
2074
|
+
}
|
|
2075
|
+
#f;
|
|
2076
|
+
get blocks() {
|
|
2077
|
+
return this.#f;
|
|
2078
|
+
}
|
|
2079
|
+
#a;
|
|
2080
|
+
get atimeMs() {
|
|
2081
|
+
return this.#a;
|
|
2082
|
+
}
|
|
2083
|
+
#i;
|
|
2084
|
+
get mtimeMs() {
|
|
2085
|
+
return this.#i;
|
|
2086
|
+
}
|
|
2087
|
+
#d;
|
|
2088
|
+
get ctimeMs() {
|
|
2089
|
+
return this.#d;
|
|
2090
|
+
}
|
|
2091
|
+
#E;
|
|
2092
|
+
get birthtimeMs() {
|
|
2093
|
+
return this.#E;
|
|
2094
|
+
}
|
|
2095
|
+
#b;
|
|
2096
|
+
get atime() {
|
|
2097
|
+
return this.#b;
|
|
2098
|
+
}
|
|
2099
|
+
#p;
|
|
2100
|
+
get mtime() {
|
|
2101
|
+
return this.#p;
|
|
2102
|
+
}
|
|
2103
|
+
#R;
|
|
2104
|
+
get ctime() {
|
|
2105
|
+
return this.#R;
|
|
2106
|
+
}
|
|
2107
|
+
#m;
|
|
2108
|
+
get birthtime() {
|
|
2109
|
+
return this.#m;
|
|
2110
|
+
}
|
|
2111
|
+
#C;
|
|
2112
|
+
#T;
|
|
2113
|
+
#g;
|
|
2114
|
+
#y;
|
|
2115
|
+
#x;
|
|
2116
|
+
#A;
|
|
2117
|
+
#e;
|
|
2118
|
+
#_;
|
|
2119
|
+
#M;
|
|
2120
|
+
#k;
|
|
2121
|
+
get parentPath() {
|
|
2122
|
+
return (this.parent || this).fullpath();
|
|
2123
|
+
}
|
|
2124
|
+
get path() {
|
|
2125
|
+
return this.parentPath;
|
|
2126
|
+
}
|
|
2127
|
+
constructor(t, e = L, s, i, r, o, h) {
|
|
2128
|
+
this.name = t, this.#C = r ? _t(t) : bt(t), this.#e = e & Fi, this.nocase = r, this.roots = i, this.root = s || this, this.#_ = o, this.#g = h.fullpath, this.#x = h.relative, this.#A = h.relativePosix, this.parent = h.parent, this.parent ? this.#t = this.parent.#t : this.#t = Ue(h.fs);
|
|
2129
|
+
}
|
|
2130
|
+
depth() {
|
|
2131
|
+
return this.#T !== void 0 ? this.#T : this.parent ? this.#T = this.parent.depth() + 1 : this.#T = 0;
|
|
2132
|
+
}
|
|
2133
|
+
childrenCache() {
|
|
2134
|
+
return this.#_;
|
|
2135
|
+
}
|
|
2136
|
+
resolve(t) {
|
|
2137
|
+
if (!t) return this;
|
|
2138
|
+
let e = this.getRootString(t), i = t.substring(e.length).split(this.splitSep);
|
|
2139
|
+
return e ? this.getRoot(e).#N(i) : this.#N(i);
|
|
2140
|
+
}
|
|
2141
|
+
#N(t) {
|
|
2142
|
+
let e = this;
|
|
2143
|
+
for (let s of t) e = e.child(s);
|
|
2144
|
+
return e;
|
|
2145
|
+
}
|
|
2146
|
+
children() {
|
|
2147
|
+
let t = this.#_.get(this);
|
|
2148
|
+
if (t) return t;
|
|
2149
|
+
let e = Object.assign([], { provisional: 0 });
|
|
2150
|
+
return this.#_.set(this, e), this.#e &= ~se, e;
|
|
2151
|
+
}
|
|
2152
|
+
child(t, e) {
|
|
2153
|
+
if (t === "" || t === ".") return this;
|
|
2154
|
+
if (t === "..") return this.parent || this;
|
|
2155
|
+
let s = this.children(), i = this.nocase ? _t(t) : bt(t);
|
|
2156
|
+
for (let a of s) if (a.#C === i) return a;
|
|
2157
|
+
let r = this.parent ? this.sep : "", o = this.#g ? this.#g + r + t : void 0, h = this.newChild(t, L, { ...e, parent: this, fullpath: o });
|
|
2158
|
+
return this.canReaddir() || (h.#e |= j), s.push(h), h;
|
|
2159
|
+
}
|
|
2160
|
+
relative() {
|
|
2161
|
+
if (this.isCWD) return "";
|
|
2162
|
+
if (this.#x !== void 0) return this.#x;
|
|
2163
|
+
let t = this.name, e = this.parent;
|
|
2164
|
+
if (!e) return this.#x = this.name;
|
|
2165
|
+
let s = e.relative();
|
|
2166
|
+
return s + (!s || !e.parent ? "" : this.sep) + t;
|
|
2167
|
+
}
|
|
2168
|
+
relativePosix() {
|
|
2169
|
+
if (this.sep === "/") return this.relative();
|
|
2170
|
+
if (this.isCWD) return "";
|
|
2171
|
+
if (this.#A !== void 0) return this.#A;
|
|
2172
|
+
let t = this.name, e = this.parent;
|
|
2173
|
+
if (!e) return this.#A = this.fullpathPosix();
|
|
2174
|
+
let s = e.relativePosix();
|
|
2175
|
+
return s + (!s || !e.parent ? "" : "/") + t;
|
|
2176
|
+
}
|
|
2177
|
+
fullpath() {
|
|
2178
|
+
if (this.#g !== void 0) return this.#g;
|
|
2179
|
+
let t = this.name, e = this.parent;
|
|
2180
|
+
if (!e) return this.#g = this.name;
|
|
2181
|
+
let i = e.fullpath() + (e.parent ? this.sep : "") + t;
|
|
2182
|
+
return this.#g = i;
|
|
2183
|
+
}
|
|
2184
|
+
fullpathPosix() {
|
|
2185
|
+
if (this.#y !== void 0) return this.#y;
|
|
2186
|
+
if (this.sep === "/") return this.#y = this.fullpath();
|
|
2187
|
+
if (!this.parent) {
|
|
2188
|
+
let i = this.fullpath().replace(/\\/g, "/");
|
|
2189
|
+
return /^[a-z]:\//i.test(i) ? this.#y = `//?/${i}` : this.#y = i;
|
|
2190
|
+
}
|
|
2191
|
+
let t = this.parent, e = t.fullpathPosix(), s = e + (!e || !t.parent ? "" : "/") + this.name;
|
|
2192
|
+
return this.#y = s;
|
|
2193
|
+
}
|
|
2194
|
+
isUnknown() {
|
|
2195
|
+
return (this.#e & _) === L;
|
|
2196
|
+
}
|
|
2197
|
+
isType(t) {
|
|
2198
|
+
return this[`is${t}`]();
|
|
2199
|
+
}
|
|
2200
|
+
getType() {
|
|
2201
|
+
return this.isUnknown() ? "Unknown" : this.isDirectory() ? "Directory" : this.isFile() ? "File" : this.isSymbolicLink() ? "SymbolicLink" : this.isFIFO() ? "FIFO" : this.isCharacterDevice() ? "CharacterDevice" : this.isBlockDevice() ? "BlockDevice" : this.isSocket() ? "Socket" : "Unknown";
|
|
2202
|
+
}
|
|
2203
|
+
isFile() {
|
|
2204
|
+
return (this.#e & _) === Ke;
|
|
2205
|
+
}
|
|
2206
|
+
isDirectory() {
|
|
2207
|
+
return (this.#e & _) === U;
|
|
2208
|
+
}
|
|
2209
|
+
isCharacterDevice() {
|
|
2210
|
+
return (this.#e & _) === He;
|
|
2211
|
+
}
|
|
2212
|
+
isBlockDevice() {
|
|
2213
|
+
return (this.#e & _) === qe;
|
|
2214
|
+
}
|
|
2215
|
+
isFIFO() {
|
|
2216
|
+
return (this.#e & _) === Ge;
|
|
2217
|
+
}
|
|
2218
|
+
isSocket() {
|
|
2219
|
+
return (this.#e & _) === Ve;
|
|
2220
|
+
}
|
|
2221
|
+
isSymbolicLink() {
|
|
2222
|
+
return (this.#e & X) === X;
|
|
2223
|
+
}
|
|
2224
|
+
lstatCached() {
|
|
2225
|
+
return this.#e & je ? this : void 0;
|
|
2226
|
+
}
|
|
2227
|
+
readlinkCached() {
|
|
2228
|
+
return this.#M;
|
|
2229
|
+
}
|
|
2230
|
+
realpathCached() {
|
|
2231
|
+
return this.#k;
|
|
2232
|
+
}
|
|
2233
|
+
readdirCached() {
|
|
2234
|
+
let t = this.children();
|
|
2235
|
+
return t.slice(0, t.provisional);
|
|
2236
|
+
}
|
|
2237
|
+
canReadlink() {
|
|
2238
|
+
if (this.#M) return true;
|
|
2239
|
+
if (!this.parent) return false;
|
|
2240
|
+
let t = this.#e & _;
|
|
2241
|
+
return !(t !== L && t !== X || this.#e & Nt || this.#e & j);
|
|
2242
|
+
}
|
|
2243
|
+
calledReaddir() {
|
|
2244
|
+
return !!(this.#e & se);
|
|
2245
|
+
}
|
|
2246
|
+
isENOENT() {
|
|
2247
|
+
return !!(this.#e & j);
|
|
2248
|
+
}
|
|
2249
|
+
isNamed(t) {
|
|
2250
|
+
return this.nocase ? this.#C === _t(t) : this.#C === bt(t);
|
|
2251
|
+
}
|
|
2252
|
+
async readlink() {
|
|
2253
|
+
let t = this.#M;
|
|
2254
|
+
if (t) return t;
|
|
2255
|
+
if (this.canReadlink() && this.parent) try {
|
|
2256
|
+
let e = await this.#t.promises.readlink(this.fullpath()), s = (await this.parent.realpath())?.resolve(e);
|
|
2257
|
+
if (s) return this.#M = s;
|
|
2258
|
+
} catch (e) {
|
|
2259
|
+
this.#D(e.code);
|
|
2260
|
+
return;
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
readlinkSync() {
|
|
2264
|
+
let t = this.#M;
|
|
2265
|
+
if (t) return t;
|
|
2266
|
+
if (this.canReadlink() && this.parent) try {
|
|
2267
|
+
let e = this.#t.readlinkSync(this.fullpath()), s = this.parent.realpathSync()?.resolve(e);
|
|
2268
|
+
if (s) return this.#M = s;
|
|
2269
|
+
} catch (e) {
|
|
2270
|
+
this.#D(e.code);
|
|
2271
|
+
return;
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
#j(t) {
|
|
2275
|
+
this.#e |= se;
|
|
2276
|
+
for (let e = t.provisional; e < t.length; e++) {
|
|
2277
|
+
let s = t[e];
|
|
2278
|
+
s && s.#v();
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
#v() {
|
|
2282
|
+
this.#e & j || (this.#e = (this.#e | j) & gt, this.#G());
|
|
2283
|
+
}
|
|
2284
|
+
#G() {
|
|
2285
|
+
let t = this.children();
|
|
2286
|
+
t.provisional = 0;
|
|
2287
|
+
for (let e of t) e.#v();
|
|
2288
|
+
}
|
|
2289
|
+
#P() {
|
|
2290
|
+
this.#e |= Lt, this.#L();
|
|
2291
|
+
}
|
|
2292
|
+
#L() {
|
|
2293
|
+
if (this.#e & yt) return;
|
|
2294
|
+
let t = this.#e;
|
|
2295
|
+
(t & _) === U && (t &= gt), this.#e = t | yt, this.#G();
|
|
2296
|
+
}
|
|
2297
|
+
#I(t = "") {
|
|
2298
|
+
t === "ENOTDIR" || t === "EPERM" ? this.#L() : t === "ENOENT" ? this.#v() : this.children().provisional = 0;
|
|
2299
|
+
}
|
|
2300
|
+
#F(t = "") {
|
|
2301
|
+
t === "ENOTDIR" ? this.parent.#L() : t === "ENOENT" && this.#v();
|
|
2302
|
+
}
|
|
2303
|
+
#D(t = "") {
|
|
2304
|
+
let e = this.#e;
|
|
2305
|
+
e |= Nt, t === "ENOENT" && (e |= j), (t === "EINVAL" || t === "UNKNOWN") && (e &= gt), this.#e = e, t === "ENOTDIR" && this.parent && this.parent.#L();
|
|
2306
|
+
}
|
|
2307
|
+
#z(t, e) {
|
|
2308
|
+
return this.#U(t, e) || this.#B(t, e);
|
|
2309
|
+
}
|
|
2310
|
+
#B(t, e) {
|
|
2311
|
+
let s = ie(t), i = this.newChild(t.name, s, { parent: this }), r = i.#e & _;
|
|
2312
|
+
return r !== U && r !== X && r !== L && (i.#e |= yt), e.unshift(i), e.provisional++, i;
|
|
2313
|
+
}
|
|
2314
|
+
#U(t, e) {
|
|
2315
|
+
for (let s = e.provisional; s < e.length; s++) {
|
|
2316
|
+
let i = e[s];
|
|
2317
|
+
if ((this.nocase ? _t(t.name) : bt(t.name)) === i.#C) return this.#l(t, i, s, e);
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
#l(t, e, s, i) {
|
|
2321
|
+
let r = e.name;
|
|
2322
|
+
return e.#e = e.#e & gt | ie(t), r !== t.name && (e.name = t.name), s !== i.provisional && (s === i.length - 1 ? i.pop() : i.splice(s, 1), i.unshift(e)), i.provisional++, e;
|
|
2323
|
+
}
|
|
2324
|
+
async lstat() {
|
|
2325
|
+
if ((this.#e & j) === 0) try {
|
|
2326
|
+
return this.#$(await this.#t.promises.lstat(this.fullpath())), this;
|
|
2327
|
+
} catch (t) {
|
|
2328
|
+
this.#F(t.code);
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
lstatSync() {
|
|
2332
|
+
if ((this.#e & j) === 0) try {
|
|
2333
|
+
return this.#$(this.#t.lstatSync(this.fullpath())), this;
|
|
2334
|
+
} catch (t) {
|
|
2335
|
+
this.#F(t.code);
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
#$(t) {
|
|
2339
|
+
let { atime: e, atimeMs: s, birthtime: i, birthtimeMs: r, blksize: o, blocks: h, ctime: a, ctimeMs: l, dev: u, gid: c, ino: d, mode: f, mtime: m, mtimeMs: p, nlink: w, rdev: g, size: S, uid: E } = t;
|
|
2340
|
+
this.#b = e, this.#a = s, this.#m = i, this.#E = r, this.#c = o, this.#f = h, this.#R = a, this.#d = l, this.#s = u, this.#S = c, this.#h = d, this.#n = f, this.#p = m, this.#i = p, this.#r = w, this.#w = g, this.#u = S, this.#o = E;
|
|
2341
|
+
let y = ie(t);
|
|
2342
|
+
this.#e = this.#e & gt | y | je, y !== L && y !== U && y !== X && (this.#e |= yt);
|
|
2343
|
+
}
|
|
2344
|
+
#W = [];
|
|
2345
|
+
#O = false;
|
|
2346
|
+
#H(t) {
|
|
2347
|
+
this.#O = false;
|
|
2348
|
+
let e = this.#W.slice();
|
|
2349
|
+
this.#W.length = 0, e.forEach((s) => s(null, t));
|
|
2350
|
+
}
|
|
2351
|
+
readdirCB(t, e = false) {
|
|
2352
|
+
if (!this.canReaddir()) {
|
|
2353
|
+
e ? t(null, []) : queueMicrotask(() => t(null, []));
|
|
2354
|
+
return;
|
|
2355
|
+
}
|
|
2356
|
+
let s = this.children();
|
|
2357
|
+
if (this.calledReaddir()) {
|
|
2358
|
+
let r = s.slice(0, s.provisional);
|
|
2359
|
+
e ? t(null, r) : queueMicrotask(() => t(null, r));
|
|
2360
|
+
return;
|
|
2361
|
+
}
|
|
2362
|
+
if (this.#W.push(t), this.#O) return;
|
|
2363
|
+
this.#O = true;
|
|
2364
|
+
let i = this.fullpath();
|
|
2365
|
+
this.#t.readdir(i, { withFileTypes: true }, (r, o) => {
|
|
2366
|
+
if (r) this.#I(r.code), s.provisional = 0;
|
|
2367
|
+
else {
|
|
2368
|
+
for (let h of o) this.#z(h, s);
|
|
2369
|
+
this.#j(s);
|
|
2370
|
+
}
|
|
2371
|
+
this.#H(s.slice(0, s.provisional));
|
|
2372
|
+
});
|
|
2373
|
+
}
|
|
2374
|
+
#q;
|
|
2375
|
+
async readdir() {
|
|
2376
|
+
if (!this.canReaddir()) return [];
|
|
2377
|
+
let t = this.children();
|
|
2378
|
+
if (this.calledReaddir()) return t.slice(0, t.provisional);
|
|
2379
|
+
let e = this.fullpath();
|
|
2380
|
+
if (this.#q) await this.#q;
|
|
2381
|
+
else {
|
|
2382
|
+
let s = () => {
|
|
2383
|
+
};
|
|
2384
|
+
this.#q = new Promise((i) => s = i);
|
|
2385
|
+
try {
|
|
2386
|
+
for (let i of await this.#t.promises.readdir(e, { withFileTypes: true })) this.#z(i, t);
|
|
2387
|
+
this.#j(t);
|
|
2388
|
+
} catch (i) {
|
|
2389
|
+
this.#I(i.code), t.provisional = 0;
|
|
2390
|
+
}
|
|
2391
|
+
this.#q = void 0, s();
|
|
2392
|
+
}
|
|
2393
|
+
return t.slice(0, t.provisional);
|
|
2394
|
+
}
|
|
2395
|
+
readdirSync() {
|
|
2396
|
+
if (!this.canReaddir()) return [];
|
|
2397
|
+
let t = this.children();
|
|
2398
|
+
if (this.calledReaddir()) return t.slice(0, t.provisional);
|
|
2399
|
+
let e = this.fullpath();
|
|
2400
|
+
try {
|
|
2401
|
+
for (let s of this.#t.readdirSync(e, { withFileTypes: true })) this.#z(s, t);
|
|
2402
|
+
this.#j(t);
|
|
2403
|
+
} catch (s) {
|
|
2404
|
+
this.#I(s.code), t.provisional = 0;
|
|
2405
|
+
}
|
|
2406
|
+
return t.slice(0, t.provisional);
|
|
2407
|
+
}
|
|
2408
|
+
canReaddir() {
|
|
2409
|
+
if (this.#e & Ie) return false;
|
|
2410
|
+
let t = _ & this.#e;
|
|
2411
|
+
return t === L || t === U || t === X;
|
|
2412
|
+
}
|
|
2413
|
+
shouldWalk(t, e) {
|
|
2414
|
+
return (this.#e & U) === U && !(this.#e & Ie) && !t.has(this) && (!e || e(this));
|
|
2415
|
+
}
|
|
2416
|
+
async realpath() {
|
|
2417
|
+
if (this.#k) return this.#k;
|
|
2418
|
+
if (!((Lt | Nt | j) & this.#e)) try {
|
|
2419
|
+
let t = await this.#t.promises.realpath(this.fullpath());
|
|
2420
|
+
return this.#k = this.resolve(t);
|
|
2421
|
+
} catch {
|
|
2422
|
+
this.#P();
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
realpathSync() {
|
|
2426
|
+
if (this.#k) return this.#k;
|
|
2427
|
+
if (!((Lt | Nt | j) & this.#e)) try {
|
|
2428
|
+
let t = this.#t.realpathSync(this.fullpath());
|
|
2429
|
+
return this.#k = this.resolve(t);
|
|
2430
|
+
} catch {
|
|
2431
|
+
this.#P();
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
[Ye](t) {
|
|
2435
|
+
if (t === this) return;
|
|
2436
|
+
t.isCWD = false, this.isCWD = true;
|
|
2437
|
+
let e = /* @__PURE__ */ new Set([]), s = [], i = this;
|
|
2438
|
+
for (; i && i.parent; ) e.add(i), i.#x = s.join(this.sep), i.#A = s.join("/"), i = i.parent, s.push("..");
|
|
2439
|
+
for (i = t; i && i.parent && !e.has(i); ) i.#x = void 0, i.#A = void 0, i = i.parent;
|
|
2440
|
+
}
|
|
2441
|
+
};
|
|
2442
|
+
var Pt = class n2 extends R {
|
|
2443
|
+
sep = "\\";
|
|
2444
|
+
splitSep = Oi;
|
|
2445
|
+
constructor(t, e = L, s, i, r, o, h) {
|
|
2446
|
+
super(t, e, s, i, r, o, h);
|
|
2447
|
+
}
|
|
2448
|
+
newChild(t, e = L, s = {}) {
|
|
2449
|
+
return new n2(t, e, this.root, this.roots, this.nocase, this.childrenCache(), s);
|
|
2450
|
+
}
|
|
2451
|
+
getRootString(t) {
|
|
2452
|
+
return re.parse(t).root;
|
|
2453
|
+
}
|
|
2454
|
+
getRoot(t) {
|
|
2455
|
+
if (t = Ri(t.toUpperCase()), t === this.root.name) return this.root;
|
|
2456
|
+
for (let [e, s] of Object.entries(this.roots)) if (this.sameRoot(t, e)) return this.roots[t] = s;
|
|
2457
|
+
return this.roots[t] = new it(t, this).root;
|
|
2458
|
+
}
|
|
2459
|
+
sameRoot(t, e = this.root.name) {
|
|
2460
|
+
return t = t.toUpperCase().replace(/\//g, "\\").replace($e, "$1\\"), t === e;
|
|
2461
|
+
}
|
|
2462
|
+
};
|
|
2463
|
+
var jt = class n3 extends R {
|
|
2464
|
+
splitSep = "/";
|
|
2465
|
+
sep = "/";
|
|
2466
|
+
constructor(t, e = L, s, i, r, o, h) {
|
|
2467
|
+
super(t, e, s, i, r, o, h);
|
|
2468
|
+
}
|
|
2469
|
+
getRootString(t) {
|
|
2470
|
+
return t.startsWith("/") ? "/" : "";
|
|
2471
|
+
}
|
|
2472
|
+
getRoot(t) {
|
|
2473
|
+
return this.root;
|
|
2474
|
+
}
|
|
2475
|
+
newChild(t, e = L, s = {}) {
|
|
2476
|
+
return new n3(t, e, this.root, this.roots, this.nocase, this.childrenCache(), s);
|
|
2477
|
+
}
|
|
2478
|
+
};
|
|
2479
|
+
var It = class {
|
|
2480
|
+
root;
|
|
2481
|
+
rootPath;
|
|
2482
|
+
roots;
|
|
2483
|
+
cwd;
|
|
2484
|
+
#t;
|
|
2485
|
+
#s;
|
|
2486
|
+
#n;
|
|
2487
|
+
nocase;
|
|
2488
|
+
#r;
|
|
2489
|
+
constructor(t = process.cwd(), e, s, { nocase: i, childrenCacheSize: r = 16 * 1024, fs: o = wt } = {}) {
|
|
2490
|
+
this.#r = Ue(o), (t instanceof URL || t.startsWith("file://")) && (t = gi(t));
|
|
2491
|
+
let h = e.resolve(t);
|
|
2492
|
+
this.roots = /* @__PURE__ */ Object.create(null), this.rootPath = this.parseRootPath(h), this.#t = new Wt(), this.#s = new Wt(), this.#n = new ne(r);
|
|
2493
|
+
let a = h.substring(this.rootPath.length).split(s);
|
|
2494
|
+
if (a.length === 1 && !a[0] && a.pop(), i === void 0) throw new TypeError("must provide nocase setting to PathScurryBase ctor");
|
|
2495
|
+
this.nocase = i, this.root = this.newRoot(this.#r), this.roots[this.rootPath] = this.root;
|
|
2496
|
+
let l = this.root, u = a.length - 1, c = e.sep, d = this.rootPath, f = false;
|
|
2497
|
+
for (let m of a) {
|
|
2498
|
+
let p = u--;
|
|
2499
|
+
l = l.child(m, { relative: new Array(p).fill("..").join(c), relativePosix: new Array(p).fill("..").join("/"), fullpath: d += (f ? "" : c) + m }), f = true;
|
|
2500
|
+
}
|
|
2501
|
+
this.cwd = l;
|
|
2502
|
+
}
|
|
2503
|
+
depth(t = this.cwd) {
|
|
2504
|
+
return typeof t == "string" && (t = this.cwd.resolve(t)), t.depth();
|
|
2505
|
+
}
|
|
2506
|
+
childrenCache() {
|
|
2507
|
+
return this.#n;
|
|
2508
|
+
}
|
|
2509
|
+
resolve(...t) {
|
|
2510
|
+
let e = "";
|
|
2511
|
+
for (let r = t.length - 1; r >= 0; r--) {
|
|
2512
|
+
let o = t[r];
|
|
2513
|
+
if (!(!o || o === ".") && (e = e ? `${o}/${e}` : o, this.isAbsolute(o))) break;
|
|
2514
|
+
}
|
|
2515
|
+
let s = this.#t.get(e);
|
|
2516
|
+
if (s !== void 0) return s;
|
|
2517
|
+
let i = this.cwd.resolve(e).fullpath();
|
|
2518
|
+
return this.#t.set(e, i), i;
|
|
2519
|
+
}
|
|
2520
|
+
resolvePosix(...t) {
|
|
2521
|
+
let e = "";
|
|
2522
|
+
for (let r = t.length - 1; r >= 0; r--) {
|
|
2523
|
+
let o = t[r];
|
|
2524
|
+
if (!(!o || o === ".") && (e = e ? `${o}/${e}` : o, this.isAbsolute(o))) break;
|
|
2525
|
+
}
|
|
2526
|
+
let s = this.#s.get(e);
|
|
2527
|
+
if (s !== void 0) return s;
|
|
2528
|
+
let i = this.cwd.resolve(e).fullpathPosix();
|
|
2529
|
+
return this.#s.set(e, i), i;
|
|
2530
|
+
}
|
|
2531
|
+
relative(t = this.cwd) {
|
|
2532
|
+
return typeof t == "string" && (t = this.cwd.resolve(t)), t.relative();
|
|
2533
|
+
}
|
|
2534
|
+
relativePosix(t = this.cwd) {
|
|
2535
|
+
return typeof t == "string" && (t = this.cwd.resolve(t)), t.relativePosix();
|
|
2536
|
+
}
|
|
2537
|
+
basename(t = this.cwd) {
|
|
2538
|
+
return typeof t == "string" && (t = this.cwd.resolve(t)), t.name;
|
|
2539
|
+
}
|
|
2540
|
+
dirname(t = this.cwd) {
|
|
2541
|
+
return typeof t == "string" && (t = this.cwd.resolve(t)), (t.parent || t).fullpath();
|
|
2542
|
+
}
|
|
2543
|
+
async readdir(t = this.cwd, e = { withFileTypes: true }) {
|
|
2544
|
+
typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
|
|
2545
|
+
let { withFileTypes: s } = e;
|
|
2546
|
+
if (t.canReaddir()) {
|
|
2547
|
+
let i = await t.readdir();
|
|
2548
|
+
return s ? i : i.map((r) => r.name);
|
|
2549
|
+
} else return [];
|
|
2550
|
+
}
|
|
2551
|
+
readdirSync(t = this.cwd, e = { withFileTypes: true }) {
|
|
2552
|
+
typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
|
|
2553
|
+
let { withFileTypes: s = true } = e;
|
|
2554
|
+
return t.canReaddir() ? s ? t.readdirSync() : t.readdirSync().map((i) => i.name) : [];
|
|
2555
|
+
}
|
|
2556
|
+
async lstat(t = this.cwd) {
|
|
2557
|
+
return typeof t == "string" && (t = this.cwd.resolve(t)), t.lstat();
|
|
2558
|
+
}
|
|
2559
|
+
lstatSync(t = this.cwd) {
|
|
2560
|
+
return typeof t == "string" && (t = this.cwd.resolve(t)), t.lstatSync();
|
|
2561
|
+
}
|
|
2562
|
+
async readlink(t = this.cwd, { withFileTypes: e } = { withFileTypes: false }) {
|
|
2563
|
+
typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t.withFileTypes, t = this.cwd);
|
|
2564
|
+
let s = await t.readlink();
|
|
2565
|
+
return e ? s : s?.fullpath();
|
|
2566
|
+
}
|
|
2567
|
+
readlinkSync(t = this.cwd, { withFileTypes: e } = { withFileTypes: false }) {
|
|
2568
|
+
typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t.withFileTypes, t = this.cwd);
|
|
2569
|
+
let s = t.readlinkSync();
|
|
2570
|
+
return e ? s : s?.fullpath();
|
|
2571
|
+
}
|
|
2572
|
+
async realpath(t = this.cwd, { withFileTypes: e } = { withFileTypes: false }) {
|
|
2573
|
+
typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t.withFileTypes, t = this.cwd);
|
|
2574
|
+
let s = await t.realpath();
|
|
2575
|
+
return e ? s : s?.fullpath();
|
|
2576
|
+
}
|
|
2577
|
+
realpathSync(t = this.cwd, { withFileTypes: e } = { withFileTypes: false }) {
|
|
2578
|
+
typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t.withFileTypes, t = this.cwd);
|
|
2579
|
+
let s = t.realpathSync();
|
|
2580
|
+
return e ? s : s?.fullpath();
|
|
2581
|
+
}
|
|
2582
|
+
async walk(t = this.cwd, e = {}) {
|
|
2583
|
+
typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
|
|
2584
|
+
let { withFileTypes: s = true, follow: i = false, filter: r, walkFilter: o } = e, h = [];
|
|
2585
|
+
(!r || r(t)) && h.push(s ? t : t.fullpath());
|
|
2586
|
+
let a = /* @__PURE__ */ new Set(), l = (c, d) => {
|
|
2587
|
+
a.add(c), c.readdirCB((f, m) => {
|
|
2588
|
+
if (f) return d(f);
|
|
2589
|
+
let p = m.length;
|
|
2590
|
+
if (!p) return d();
|
|
2591
|
+
let w = () => {
|
|
2592
|
+
--p === 0 && d();
|
|
2593
|
+
};
|
|
2594
|
+
for (let g of m) (!r || r(g)) && h.push(s ? g : g.fullpath()), i && g.isSymbolicLink() ? g.realpath().then((S) => S?.isUnknown() ? S.lstat() : S).then((S) => S?.shouldWalk(a, o) ? l(S, w) : w()) : g.shouldWalk(a, o) ? l(g, w) : w();
|
|
2595
|
+
}, true);
|
|
2596
|
+
}, u = t;
|
|
2597
|
+
return new Promise((c, d) => {
|
|
2598
|
+
l(u, (f) => {
|
|
2599
|
+
if (f) return d(f);
|
|
2600
|
+
c(h);
|
|
2601
|
+
});
|
|
2602
|
+
});
|
|
2603
|
+
}
|
|
2604
|
+
walkSync(t = this.cwd, e = {}) {
|
|
2605
|
+
typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
|
|
2606
|
+
let { withFileTypes: s = true, follow: i = false, filter: r, walkFilter: o } = e, h = [];
|
|
2607
|
+
(!r || r(t)) && h.push(s ? t : t.fullpath());
|
|
2608
|
+
let a = /* @__PURE__ */ new Set([t]);
|
|
2609
|
+
for (let l of a) {
|
|
2610
|
+
let u = l.readdirSync();
|
|
2611
|
+
for (let c of u) {
|
|
2612
|
+
(!r || r(c)) && h.push(s ? c : c.fullpath());
|
|
2613
|
+
let d = c;
|
|
2614
|
+
if (c.isSymbolicLink()) {
|
|
2615
|
+
if (!(i && (d = c.realpathSync()))) continue;
|
|
2616
|
+
d.isUnknown() && d.lstatSync();
|
|
2617
|
+
}
|
|
2618
|
+
d.shouldWalk(a, o) && a.add(d);
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
return h;
|
|
2622
|
+
}
|
|
2623
|
+
[Symbol.asyncIterator]() {
|
|
2624
|
+
return this.iterate();
|
|
2625
|
+
}
|
|
2626
|
+
iterate(t = this.cwd, e = {}) {
|
|
2627
|
+
return typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd), this.stream(t, e)[Symbol.asyncIterator]();
|
|
2628
|
+
}
|
|
2629
|
+
[Symbol.iterator]() {
|
|
2630
|
+
return this.iterateSync();
|
|
2631
|
+
}
|
|
2632
|
+
*iterateSync(t = this.cwd, e = {}) {
|
|
2633
|
+
typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
|
|
2634
|
+
let { withFileTypes: s = true, follow: i = false, filter: r, walkFilter: o } = e;
|
|
2635
|
+
(!r || r(t)) && (yield s ? t : t.fullpath());
|
|
2636
|
+
let h = /* @__PURE__ */ new Set([t]);
|
|
2637
|
+
for (let a of h) {
|
|
2638
|
+
let l = a.readdirSync();
|
|
2639
|
+
for (let u of l) {
|
|
2640
|
+
(!r || r(u)) && (yield s ? u : u.fullpath());
|
|
2641
|
+
let c = u;
|
|
2642
|
+
if (u.isSymbolicLink()) {
|
|
2643
|
+
if (!(i && (c = u.realpathSync()))) continue;
|
|
2644
|
+
c.isUnknown() && c.lstatSync();
|
|
2645
|
+
}
|
|
2646
|
+
c.shouldWalk(h, o) && h.add(c);
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
stream(t = this.cwd, e = {}) {
|
|
2651
|
+
typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
|
|
2652
|
+
let { withFileTypes: s = true, follow: i = false, filter: r, walkFilter: o } = e, h = new V({ objectMode: true });
|
|
2653
|
+
(!r || r(t)) && h.write(s ? t : t.fullpath());
|
|
2654
|
+
let a = /* @__PURE__ */ new Set(), l = [t], u = 0, c = () => {
|
|
2655
|
+
let d = false;
|
|
2656
|
+
for (; !d; ) {
|
|
2657
|
+
let f = l.shift();
|
|
2658
|
+
if (!f) {
|
|
2659
|
+
u === 0 && h.end();
|
|
2660
|
+
return;
|
|
2661
|
+
}
|
|
2662
|
+
u++, a.add(f);
|
|
2663
|
+
let m = (w, g, S = false) => {
|
|
2664
|
+
if (w) return h.emit("error", w);
|
|
2665
|
+
if (i && !S) {
|
|
2666
|
+
let E = [];
|
|
2667
|
+
for (let y of g) y.isSymbolicLink() && E.push(y.realpath().then((b) => b?.isUnknown() ? b.lstat() : b));
|
|
2668
|
+
if (E.length) {
|
|
2669
|
+
Promise.all(E).then(() => m(null, g, true));
|
|
2670
|
+
return;
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
for (let E of g) E && (!r || r(E)) && (h.write(s ? E : E.fullpath()) || (d = true));
|
|
2674
|
+
u--;
|
|
2675
|
+
for (let E of g) {
|
|
2676
|
+
let y = E.realpathCached() || E;
|
|
2677
|
+
y.shouldWalk(a, o) && l.push(y);
|
|
2678
|
+
}
|
|
2679
|
+
d && !h.flowing ? h.once("drain", c) : p || c();
|
|
2680
|
+
}, p = true;
|
|
2681
|
+
f.readdirCB(m, true), p = false;
|
|
2682
|
+
}
|
|
2683
|
+
};
|
|
2684
|
+
return c(), h;
|
|
2685
|
+
}
|
|
2686
|
+
streamSync(t = this.cwd, e = {}) {
|
|
2687
|
+
typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
|
|
2688
|
+
let { withFileTypes: s = true, follow: i = false, filter: r, walkFilter: o } = e, h = new V({ objectMode: true }), a = /* @__PURE__ */ new Set();
|
|
2689
|
+
(!r || r(t)) && h.write(s ? t : t.fullpath());
|
|
2690
|
+
let l = [t], u = 0, c = () => {
|
|
2691
|
+
let d = false;
|
|
2692
|
+
for (; !d; ) {
|
|
2693
|
+
let f = l.shift();
|
|
2694
|
+
if (!f) {
|
|
2695
|
+
u === 0 && h.end();
|
|
2696
|
+
return;
|
|
2697
|
+
}
|
|
2698
|
+
u++, a.add(f);
|
|
2699
|
+
let m = f.readdirSync();
|
|
2700
|
+
for (let p of m) (!r || r(p)) && (h.write(s ? p : p.fullpath()) || (d = true));
|
|
2701
|
+
u--;
|
|
2702
|
+
for (let p of m) {
|
|
2703
|
+
let w = p;
|
|
2704
|
+
if (p.isSymbolicLink()) {
|
|
2705
|
+
if (!(i && (w = p.realpathSync()))) continue;
|
|
2706
|
+
w.isUnknown() && w.lstatSync();
|
|
2707
|
+
}
|
|
2708
|
+
w.shouldWalk(a, o) && l.push(w);
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
d && !h.flowing && h.once("drain", c);
|
|
2712
|
+
};
|
|
2713
|
+
return c(), h;
|
|
2714
|
+
}
|
|
2715
|
+
chdir(t = this.cwd) {
|
|
2716
|
+
let e = this.cwd;
|
|
2717
|
+
this.cwd = typeof t == "string" ? this.cwd.resolve(t) : t, this.cwd[Ye](e);
|
|
2718
|
+
}
|
|
2719
|
+
};
|
|
2720
|
+
var it = class extends It {
|
|
2721
|
+
sep = "\\";
|
|
2722
|
+
constructor(t = process.cwd(), e = {}) {
|
|
2723
|
+
let { nocase: s = true } = e;
|
|
2724
|
+
super(t, re, "\\", { ...e, nocase: s }), this.nocase = s;
|
|
2725
|
+
for (let i = this.cwd; i; i = i.parent) i.nocase = this.nocase;
|
|
2726
|
+
}
|
|
2727
|
+
parseRootPath(t) {
|
|
2728
|
+
return re.parse(t).root.toUpperCase();
|
|
2729
|
+
}
|
|
2730
|
+
newRoot(t) {
|
|
2731
|
+
return new Pt(this.rootPath, U, void 0, this.roots, this.nocase, this.childrenCache(), { fs: t });
|
|
2732
|
+
}
|
|
2733
|
+
isAbsolute(t) {
|
|
2734
|
+
return t.startsWith("/") || t.startsWith("\\") || /^[a-z]:(\/|\\)/i.test(t);
|
|
2735
|
+
}
|
|
2736
|
+
};
|
|
2737
|
+
var rt = class extends It {
|
|
2738
|
+
sep = "/";
|
|
2739
|
+
constructor(t = process.cwd(), e = {}) {
|
|
2740
|
+
let { nocase: s = false } = e;
|
|
2741
|
+
super(t, mi, "/", { ...e, nocase: s }), this.nocase = s;
|
|
2742
|
+
}
|
|
2743
|
+
parseRootPath(t) {
|
|
2744
|
+
return "/";
|
|
2745
|
+
}
|
|
2746
|
+
newRoot(t) {
|
|
2747
|
+
return new jt(this.rootPath, U, void 0, this.roots, this.nocase, this.childrenCache(), { fs: t });
|
|
2748
|
+
}
|
|
2749
|
+
isAbsolute(t) {
|
|
2750
|
+
return t.startsWith("/");
|
|
2751
|
+
}
|
|
2752
|
+
};
|
|
2753
|
+
var St = class extends rt {
|
|
2754
|
+
constructor(t = process.cwd(), e = {}) {
|
|
2755
|
+
let { nocase: s = true } = e;
|
|
2756
|
+
super(t, { ...e, nocase: s });
|
|
2757
|
+
}
|
|
2758
|
+
};
|
|
2759
|
+
var Cr = process.platform === "win32" ? Pt : jt;
|
|
2760
|
+
var Xe = process.platform === "win32" ? it : process.platform === "darwin" ? St : rt;
|
|
2761
|
+
var Di = (n7) => n7.length >= 1;
|
|
2762
|
+
var Mi = (n7) => n7.length >= 1;
|
|
2763
|
+
var Ni = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
2764
|
+
var nt = class n4 {
|
|
2765
|
+
#t;
|
|
2766
|
+
#s;
|
|
2767
|
+
#n;
|
|
2768
|
+
length;
|
|
2769
|
+
#r;
|
|
2770
|
+
#o;
|
|
2771
|
+
#S;
|
|
2772
|
+
#w;
|
|
2773
|
+
#c;
|
|
2774
|
+
#h;
|
|
2775
|
+
#u = true;
|
|
2776
|
+
constructor(t, e, s, i) {
|
|
2777
|
+
if (!Di(t)) throw new TypeError("empty pattern list");
|
|
2778
|
+
if (!Mi(e)) throw new TypeError("empty glob list");
|
|
2779
|
+
if (e.length !== t.length) throw new TypeError("mismatched pattern list and glob list lengths");
|
|
2780
|
+
if (this.length = t.length, s < 0 || s >= this.length) throw new TypeError("index out of range");
|
|
2781
|
+
if (this.#t = t, this.#s = e, this.#n = s, this.#r = i, this.#n === 0) {
|
|
2782
|
+
if (this.isUNC()) {
|
|
2783
|
+
let [r, o, h, a, ...l] = this.#t, [u, c, d, f, ...m] = this.#s;
|
|
2784
|
+
l[0] === "" && (l.shift(), m.shift());
|
|
2785
|
+
let p = [r, o, h, a, ""].join("/"), w = [u, c, d, f, ""].join("/");
|
|
2786
|
+
this.#t = [p, ...l], this.#s = [w, ...m], this.length = this.#t.length;
|
|
2787
|
+
} else if (this.isDrive() || this.isAbsolute()) {
|
|
2788
|
+
let [r, ...o] = this.#t, [h, ...a] = this.#s;
|
|
2789
|
+
o[0] === "" && (o.shift(), a.shift());
|
|
2790
|
+
let l = r + "/", u = h + "/";
|
|
2791
|
+
this.#t = [l, ...o], this.#s = [u, ...a], this.length = this.#t.length;
|
|
2792
|
+
}
|
|
2793
|
+
}
|
|
2794
|
+
}
|
|
2795
|
+
[Ni]() {
|
|
2796
|
+
return "Pattern <" + this.#s.slice(this.#n).join("/") + ">";
|
|
2797
|
+
}
|
|
2798
|
+
pattern() {
|
|
2799
|
+
return this.#t[this.#n];
|
|
2800
|
+
}
|
|
2801
|
+
isString() {
|
|
2802
|
+
return typeof this.#t[this.#n] == "string";
|
|
2803
|
+
}
|
|
2804
|
+
isGlobstar() {
|
|
2805
|
+
return this.#t[this.#n] === A;
|
|
2806
|
+
}
|
|
2807
|
+
isRegExp() {
|
|
2808
|
+
return this.#t[this.#n] instanceof RegExp;
|
|
2809
|
+
}
|
|
2810
|
+
globString() {
|
|
2811
|
+
return this.#S = this.#S || (this.#n === 0 ? this.isAbsolute() ? this.#s[0] + this.#s.slice(1).join("/") : this.#s.join("/") : this.#s.slice(this.#n).join("/"));
|
|
2812
|
+
}
|
|
2813
|
+
hasMore() {
|
|
2814
|
+
return this.length > this.#n + 1;
|
|
2815
|
+
}
|
|
2816
|
+
rest() {
|
|
2817
|
+
return this.#o !== void 0 ? this.#o : this.hasMore() ? (this.#o = new n4(this.#t, this.#s, this.#n + 1, this.#r), this.#o.#h = this.#h, this.#o.#c = this.#c, this.#o.#w = this.#w, this.#o) : this.#o = null;
|
|
2818
|
+
}
|
|
2819
|
+
isUNC() {
|
|
2820
|
+
let t = this.#t;
|
|
2821
|
+
return this.#c !== void 0 ? this.#c : this.#c = this.#r === "win32" && this.#n === 0 && t[0] === "" && t[1] === "" && typeof t[2] == "string" && !!t[2] && typeof t[3] == "string" && !!t[3];
|
|
2822
|
+
}
|
|
2823
|
+
isDrive() {
|
|
2824
|
+
let t = this.#t;
|
|
2825
|
+
return this.#w !== void 0 ? this.#w : this.#w = this.#r === "win32" && this.#n === 0 && this.length > 1 && typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]);
|
|
2826
|
+
}
|
|
2827
|
+
isAbsolute() {
|
|
2828
|
+
let t = this.#t;
|
|
2829
|
+
return this.#h !== void 0 ? this.#h : this.#h = t[0] === "" && t.length > 1 || this.isDrive() || this.isUNC();
|
|
2830
|
+
}
|
|
2831
|
+
root() {
|
|
2832
|
+
let t = this.#t[0];
|
|
2833
|
+
return typeof t == "string" && this.isAbsolute() && this.#n === 0 ? t : "";
|
|
2834
|
+
}
|
|
2835
|
+
checkFollowGlobstar() {
|
|
2836
|
+
return !(this.#n === 0 || !this.isGlobstar() || !this.#u);
|
|
2837
|
+
}
|
|
2838
|
+
markFollowGlobstar() {
|
|
2839
|
+
return this.#n === 0 || !this.isGlobstar() || !this.#u ? false : (this.#u = false, true);
|
|
2840
|
+
}
|
|
2841
|
+
};
|
|
2842
|
+
var _i = typeof process == "object" && process && typeof process.platform == "string" ? process.platform : "linux";
|
|
2843
|
+
var ot = class {
|
|
2844
|
+
relative;
|
|
2845
|
+
relativeChildren;
|
|
2846
|
+
absolute;
|
|
2847
|
+
absoluteChildren;
|
|
2848
|
+
platform;
|
|
2849
|
+
mmopts;
|
|
2850
|
+
constructor(t, { nobrace: e, nocase: s, noext: i, noglobstar: r, platform: o = _i }) {
|
|
2851
|
+
this.relative = [], this.absolute = [], this.relativeChildren = [], this.absoluteChildren = [], this.platform = o, this.mmopts = { dot: true, nobrace: e, nocase: s, noext: i, noglobstar: r, optimizationLevel: 2, platform: o, nocomment: true, nonegate: true };
|
|
2852
|
+
for (let h of t) this.add(h);
|
|
2853
|
+
}
|
|
2854
|
+
add(t) {
|
|
2855
|
+
let e = new D(t, this.mmopts);
|
|
2856
|
+
for (let s = 0; s < e.set.length; s++) {
|
|
2857
|
+
let i = e.set[s], r = e.globParts[s];
|
|
2858
|
+
if (!i || !r) throw new Error("invalid pattern object");
|
|
2859
|
+
for (; i[0] === "." && r[0] === "."; ) i.shift(), r.shift();
|
|
2860
|
+
let o = new nt(i, r, 0, this.platform), h = new D(o.globString(), this.mmopts), a = r[r.length - 1] === "**", l = o.isAbsolute();
|
|
2861
|
+
l ? this.absolute.push(h) : this.relative.push(h), a && (l ? this.absoluteChildren.push(h) : this.relativeChildren.push(h));
|
|
2862
|
+
}
|
|
2863
|
+
}
|
|
2864
|
+
ignored(t) {
|
|
2865
|
+
let e = t.fullpath(), s = `${e}/`, i = t.relative() || ".", r = `${i}/`;
|
|
2866
|
+
for (let o of this.relative) if (o.match(i) || o.match(r)) return true;
|
|
2867
|
+
for (let o of this.absolute) if (o.match(e) || o.match(s)) return true;
|
|
2868
|
+
return false;
|
|
2869
|
+
}
|
|
2870
|
+
childrenIgnored(t) {
|
|
2871
|
+
let e = t.fullpath() + "/", s = (t.relative() || ".") + "/";
|
|
2872
|
+
for (let i of this.relativeChildren) if (i.match(s)) return true;
|
|
2873
|
+
for (let i of this.absoluteChildren) if (i.match(e)) return true;
|
|
2874
|
+
return false;
|
|
2875
|
+
}
|
|
2876
|
+
};
|
|
2877
|
+
var oe = class n5 {
|
|
2878
|
+
store;
|
|
2879
|
+
constructor(t = /* @__PURE__ */ new Map()) {
|
|
2880
|
+
this.store = t;
|
|
2881
|
+
}
|
|
2882
|
+
copy() {
|
|
2883
|
+
return new n5(new Map(this.store));
|
|
2884
|
+
}
|
|
2885
|
+
hasWalked(t, e) {
|
|
2886
|
+
return this.store.get(t.fullpath())?.has(e.globString());
|
|
2887
|
+
}
|
|
2888
|
+
storeWalked(t, e) {
|
|
2889
|
+
let s = t.fullpath(), i = this.store.get(s);
|
|
2890
|
+
i ? i.add(e.globString()) : this.store.set(s, /* @__PURE__ */ new Set([e.globString()]));
|
|
2891
|
+
}
|
|
2892
|
+
};
|
|
2893
|
+
var he = class {
|
|
2894
|
+
store = /* @__PURE__ */ new Map();
|
|
2895
|
+
add(t, e, s) {
|
|
2896
|
+
let i = (e ? 2 : 0) | (s ? 1 : 0), r = this.store.get(t);
|
|
2897
|
+
this.store.set(t, r === void 0 ? i : i & r);
|
|
2898
|
+
}
|
|
2899
|
+
entries() {
|
|
2900
|
+
return [...this.store.entries()].map(([t, e]) => [t, !!(e & 2), !!(e & 1)]);
|
|
2901
|
+
}
|
|
2902
|
+
};
|
|
2903
|
+
var ae = class {
|
|
2904
|
+
store = /* @__PURE__ */ new Map();
|
|
2905
|
+
add(t, e) {
|
|
2906
|
+
if (!t.canReaddir()) return;
|
|
2907
|
+
let s = this.store.get(t);
|
|
2908
|
+
s ? s.find((i) => i.globString() === e.globString()) || s.push(e) : this.store.set(t, [e]);
|
|
2909
|
+
}
|
|
2910
|
+
get(t) {
|
|
2911
|
+
let e = this.store.get(t);
|
|
2912
|
+
if (!e) throw new Error("attempting to walk unknown path");
|
|
2913
|
+
return e;
|
|
2914
|
+
}
|
|
2915
|
+
entries() {
|
|
2916
|
+
return this.keys().map((t) => [t, this.store.get(t)]);
|
|
2917
|
+
}
|
|
2918
|
+
keys() {
|
|
2919
|
+
return [...this.store.keys()].filter((t) => t.canReaddir());
|
|
2920
|
+
}
|
|
2921
|
+
};
|
|
2922
|
+
var Et = class n6 {
|
|
2923
|
+
hasWalkedCache;
|
|
2924
|
+
matches = new he();
|
|
2925
|
+
subwalks = new ae();
|
|
2926
|
+
patterns;
|
|
2927
|
+
follow;
|
|
2928
|
+
dot;
|
|
2929
|
+
opts;
|
|
2930
|
+
constructor(t, e) {
|
|
2931
|
+
this.opts = t, this.follow = !!t.follow, this.dot = !!t.dot, this.hasWalkedCache = e ? e.copy() : new oe();
|
|
2932
|
+
}
|
|
2933
|
+
processPatterns(t, e) {
|
|
2934
|
+
this.patterns = e;
|
|
2935
|
+
let s = e.map((i) => [t, i]);
|
|
2936
|
+
for (let [i, r] of s) {
|
|
2937
|
+
this.hasWalkedCache.storeWalked(i, r);
|
|
2938
|
+
let o = r.root(), h = r.isAbsolute() && this.opts.absolute !== false;
|
|
2939
|
+
if (o) {
|
|
2940
|
+
i = i.resolve(o === "/" && this.opts.root !== void 0 ? this.opts.root : o);
|
|
2941
|
+
let c = r.rest();
|
|
2942
|
+
if (c) r = c;
|
|
2943
|
+
else {
|
|
2944
|
+
this.matches.add(i, true, false);
|
|
2945
|
+
continue;
|
|
2946
|
+
}
|
|
2947
|
+
}
|
|
2948
|
+
if (i.isENOENT()) continue;
|
|
2949
|
+
let a, l, u = false;
|
|
2950
|
+
for (; typeof (a = r.pattern()) == "string" && (l = r.rest()); ) i = i.resolve(a), r = l, u = true;
|
|
2951
|
+
if (a = r.pattern(), l = r.rest(), u) {
|
|
2952
|
+
if (this.hasWalkedCache.hasWalked(i, r)) continue;
|
|
2953
|
+
this.hasWalkedCache.storeWalked(i, r);
|
|
2954
|
+
}
|
|
2955
|
+
if (typeof a == "string") {
|
|
2956
|
+
let c = a === ".." || a === "" || a === ".";
|
|
2957
|
+
this.matches.add(i.resolve(a), h, c);
|
|
2958
|
+
continue;
|
|
2959
|
+
} else if (a === A) {
|
|
2960
|
+
(!i.isSymbolicLink() || this.follow || r.checkFollowGlobstar()) && this.subwalks.add(i, r);
|
|
2961
|
+
let c = l?.pattern(), d = l?.rest();
|
|
2962
|
+
if (!l || (c === "" || c === ".") && !d) this.matches.add(i, h, c === "" || c === ".");
|
|
2963
|
+
else if (c === "..") {
|
|
2964
|
+
let f = i.parent || i;
|
|
2965
|
+
d ? this.hasWalkedCache.hasWalked(f, d) || this.subwalks.add(f, d) : this.matches.add(f, h, true);
|
|
2966
|
+
}
|
|
2967
|
+
} else a instanceof RegExp && this.subwalks.add(i, r);
|
|
2968
|
+
}
|
|
2969
|
+
return this;
|
|
2970
|
+
}
|
|
2971
|
+
subwalkTargets() {
|
|
2972
|
+
return this.subwalks.keys();
|
|
2973
|
+
}
|
|
2974
|
+
child() {
|
|
2975
|
+
return new n6(this.opts, this.hasWalkedCache);
|
|
2976
|
+
}
|
|
2977
|
+
filterEntries(t, e) {
|
|
2978
|
+
let s = this.subwalks.get(t), i = this.child();
|
|
2979
|
+
for (let r of e) for (let o of s) {
|
|
2980
|
+
let h = o.isAbsolute(), a = o.pattern(), l = o.rest();
|
|
2981
|
+
a === A ? i.testGlobstar(r, o, l, h) : a instanceof RegExp ? i.testRegExp(r, a, l, h) : i.testString(r, a, l, h);
|
|
2982
|
+
}
|
|
2983
|
+
return i;
|
|
2984
|
+
}
|
|
2985
|
+
testGlobstar(t, e, s, i) {
|
|
2986
|
+
if ((this.dot || !t.name.startsWith(".")) && (e.hasMore() || this.matches.add(t, i, false), t.canReaddir() && (this.follow || !t.isSymbolicLink() ? this.subwalks.add(t, e) : t.isSymbolicLink() && (s && e.checkFollowGlobstar() ? this.subwalks.add(t, s) : e.markFollowGlobstar() && this.subwalks.add(t, e)))), s) {
|
|
2987
|
+
let r = s.pattern();
|
|
2988
|
+
if (typeof r == "string" && r !== ".." && r !== "" && r !== ".") this.testString(t, r, s.rest(), i);
|
|
2989
|
+
else if (r === "..") {
|
|
2990
|
+
let o = t.parent || t;
|
|
2991
|
+
this.subwalks.add(o, s);
|
|
2992
|
+
} else r instanceof RegExp && this.testRegExp(t, r, s.rest(), i);
|
|
2993
|
+
}
|
|
2994
|
+
}
|
|
2995
|
+
testRegExp(t, e, s, i) {
|
|
2996
|
+
e.test(t.name) && (s ? this.subwalks.add(t, s) : this.matches.add(t, i, false));
|
|
2997
|
+
}
|
|
2998
|
+
testString(t, e, s, i) {
|
|
2999
|
+
t.isNamed(e) && (s ? this.subwalks.add(t, s) : this.matches.add(t, i, false));
|
|
3000
|
+
}
|
|
3001
|
+
};
|
|
3002
|
+
var Li = (n7, t) => typeof n7 == "string" ? new ot([n7], t) : Array.isArray(n7) ? new ot(n7, t) : n7;
|
|
3003
|
+
var zt = class {
|
|
3004
|
+
path;
|
|
3005
|
+
patterns;
|
|
3006
|
+
opts;
|
|
3007
|
+
seen = /* @__PURE__ */ new Set();
|
|
3008
|
+
paused = false;
|
|
3009
|
+
aborted = false;
|
|
3010
|
+
#t = [];
|
|
3011
|
+
#s;
|
|
3012
|
+
#n;
|
|
3013
|
+
signal;
|
|
3014
|
+
maxDepth;
|
|
3015
|
+
includeChildMatches;
|
|
3016
|
+
constructor(t, e, s) {
|
|
3017
|
+
if (this.patterns = t, this.path = e, this.opts = s, this.#n = !s.posix && s.platform === "win32" ? "\\" : "/", this.includeChildMatches = s.includeChildMatches !== false, (s.ignore || !this.includeChildMatches) && (this.#s = Li(s.ignore ?? [], s), !this.includeChildMatches && typeof this.#s.add != "function")) {
|
|
3018
|
+
let i = "cannot ignore child matches, ignore lacks add() method.";
|
|
3019
|
+
throw new Error(i);
|
|
3020
|
+
}
|
|
3021
|
+
this.maxDepth = s.maxDepth || 1 / 0, s.signal && (this.signal = s.signal, this.signal.addEventListener("abort", () => {
|
|
3022
|
+
this.#t.length = 0;
|
|
3023
|
+
}));
|
|
3024
|
+
}
|
|
3025
|
+
#r(t) {
|
|
3026
|
+
return this.seen.has(t) || !!this.#s?.ignored?.(t);
|
|
3027
|
+
}
|
|
3028
|
+
#o(t) {
|
|
3029
|
+
return !!this.#s?.childrenIgnored?.(t);
|
|
3030
|
+
}
|
|
3031
|
+
pause() {
|
|
3032
|
+
this.paused = true;
|
|
3033
|
+
}
|
|
3034
|
+
resume() {
|
|
3035
|
+
if (this.signal?.aborted) return;
|
|
3036
|
+
this.paused = false;
|
|
3037
|
+
let t;
|
|
3038
|
+
for (; !this.paused && (t = this.#t.shift()); ) t();
|
|
3039
|
+
}
|
|
3040
|
+
onResume(t) {
|
|
3041
|
+
this.signal?.aborted || (this.paused ? this.#t.push(t) : t());
|
|
3042
|
+
}
|
|
3043
|
+
async matchCheck(t, e) {
|
|
3044
|
+
if (e && this.opts.nodir) return;
|
|
3045
|
+
let s;
|
|
3046
|
+
if (this.opts.realpath) {
|
|
3047
|
+
if (s = t.realpathCached() || await t.realpath(), !s) return;
|
|
3048
|
+
t = s;
|
|
3049
|
+
}
|
|
3050
|
+
let r = t.isUnknown() || this.opts.stat ? await t.lstat() : t;
|
|
3051
|
+
if (this.opts.follow && this.opts.nodir && r?.isSymbolicLink()) {
|
|
3052
|
+
let o = await r.realpath();
|
|
3053
|
+
o && (o.isUnknown() || this.opts.stat) && await o.lstat();
|
|
3054
|
+
}
|
|
3055
|
+
return this.matchCheckTest(r, e);
|
|
3056
|
+
}
|
|
3057
|
+
matchCheckTest(t, e) {
|
|
3058
|
+
return t && (this.maxDepth === 1 / 0 || t.depth() <= this.maxDepth) && (!e || t.canReaddir()) && (!this.opts.nodir || !t.isDirectory()) && (!this.opts.nodir || !this.opts.follow || !t.isSymbolicLink() || !t.realpathCached()?.isDirectory()) && !this.#r(t) ? t : void 0;
|
|
3059
|
+
}
|
|
3060
|
+
matchCheckSync(t, e) {
|
|
3061
|
+
if (e && this.opts.nodir) return;
|
|
3062
|
+
let s;
|
|
3063
|
+
if (this.opts.realpath) {
|
|
3064
|
+
if (s = t.realpathCached() || t.realpathSync(), !s) return;
|
|
3065
|
+
t = s;
|
|
3066
|
+
}
|
|
3067
|
+
let r = t.isUnknown() || this.opts.stat ? t.lstatSync() : t;
|
|
3068
|
+
if (this.opts.follow && this.opts.nodir && r?.isSymbolicLink()) {
|
|
3069
|
+
let o = r.realpathSync();
|
|
3070
|
+
o && (o?.isUnknown() || this.opts.stat) && o.lstatSync();
|
|
3071
|
+
}
|
|
3072
|
+
return this.matchCheckTest(r, e);
|
|
3073
|
+
}
|
|
3074
|
+
matchFinish(t, e) {
|
|
3075
|
+
if (this.#r(t)) return;
|
|
3076
|
+
if (!this.includeChildMatches && this.#s?.add) {
|
|
3077
|
+
let r = `${t.relativePosix()}/**`;
|
|
3078
|
+
this.#s.add(r);
|
|
3079
|
+
}
|
|
3080
|
+
let s = this.opts.absolute === void 0 ? e : this.opts.absolute;
|
|
3081
|
+
this.seen.add(t);
|
|
3082
|
+
let i = this.opts.mark && t.isDirectory() ? this.#n : "";
|
|
3083
|
+
if (this.opts.withFileTypes) this.matchEmit(t);
|
|
3084
|
+
else if (s) {
|
|
3085
|
+
let r = this.opts.posix ? t.fullpathPosix() : t.fullpath();
|
|
3086
|
+
this.matchEmit(r + i);
|
|
3087
|
+
} else {
|
|
3088
|
+
let r = this.opts.posix ? t.relativePosix() : t.relative(), o = this.opts.dotRelative && !r.startsWith(".." + this.#n) ? "." + this.#n : "";
|
|
3089
|
+
this.matchEmit(r ? o + r + i : "." + i);
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3092
|
+
async match(t, e, s) {
|
|
3093
|
+
let i = await this.matchCheck(t, s);
|
|
3094
|
+
i && this.matchFinish(i, e);
|
|
3095
|
+
}
|
|
3096
|
+
matchSync(t, e, s) {
|
|
3097
|
+
let i = this.matchCheckSync(t, s);
|
|
3098
|
+
i && this.matchFinish(i, e);
|
|
3099
|
+
}
|
|
3100
|
+
walkCB(t, e, s) {
|
|
3101
|
+
this.signal?.aborted && s(), this.walkCB2(t, e, new Et(this.opts), s);
|
|
3102
|
+
}
|
|
3103
|
+
walkCB2(t, e, s, i) {
|
|
3104
|
+
if (this.#o(t)) return i();
|
|
3105
|
+
if (this.signal?.aborted && i(), this.paused) {
|
|
3106
|
+
this.onResume(() => this.walkCB2(t, e, s, i));
|
|
3107
|
+
return;
|
|
3108
|
+
}
|
|
3109
|
+
s.processPatterns(t, e);
|
|
3110
|
+
let r = 1, o = () => {
|
|
3111
|
+
--r === 0 && i();
|
|
3112
|
+
};
|
|
3113
|
+
for (let [h, a, l] of s.matches.entries()) this.#r(h) || (r++, this.match(h, a, l).then(() => o()));
|
|
3114
|
+
for (let h of s.subwalkTargets()) {
|
|
3115
|
+
if (this.maxDepth !== 1 / 0 && h.depth() >= this.maxDepth) continue;
|
|
3116
|
+
r++;
|
|
3117
|
+
let a = h.readdirCached();
|
|
3118
|
+
h.calledReaddir() ? this.walkCB3(h, a, s, o) : h.readdirCB((l, u) => this.walkCB3(h, u, s, o), true);
|
|
3119
|
+
}
|
|
3120
|
+
o();
|
|
3121
|
+
}
|
|
3122
|
+
walkCB3(t, e, s, i) {
|
|
3123
|
+
s = s.filterEntries(t, e);
|
|
3124
|
+
let r = 1, o = () => {
|
|
3125
|
+
--r === 0 && i();
|
|
3126
|
+
};
|
|
3127
|
+
for (let [h, a, l] of s.matches.entries()) this.#r(h) || (r++, this.match(h, a, l).then(() => o()));
|
|
3128
|
+
for (let [h, a] of s.subwalks.entries()) r++, this.walkCB2(h, a, s.child(), o);
|
|
3129
|
+
o();
|
|
3130
|
+
}
|
|
3131
|
+
walkCBSync(t, e, s) {
|
|
3132
|
+
this.signal?.aborted && s(), this.walkCB2Sync(t, e, new Et(this.opts), s);
|
|
3133
|
+
}
|
|
3134
|
+
walkCB2Sync(t, e, s, i) {
|
|
3135
|
+
if (this.#o(t)) return i();
|
|
3136
|
+
if (this.signal?.aborted && i(), this.paused) {
|
|
3137
|
+
this.onResume(() => this.walkCB2Sync(t, e, s, i));
|
|
3138
|
+
return;
|
|
3139
|
+
}
|
|
3140
|
+
s.processPatterns(t, e);
|
|
3141
|
+
let r = 1, o = () => {
|
|
3142
|
+
--r === 0 && i();
|
|
3143
|
+
};
|
|
3144
|
+
for (let [h, a, l] of s.matches.entries()) this.#r(h) || this.matchSync(h, a, l);
|
|
3145
|
+
for (let h of s.subwalkTargets()) {
|
|
3146
|
+
if (this.maxDepth !== 1 / 0 && h.depth() >= this.maxDepth) continue;
|
|
3147
|
+
r++;
|
|
3148
|
+
let a = h.readdirSync();
|
|
3149
|
+
this.walkCB3Sync(h, a, s, o);
|
|
3150
|
+
}
|
|
3151
|
+
o();
|
|
3152
|
+
}
|
|
3153
|
+
walkCB3Sync(t, e, s, i) {
|
|
3154
|
+
s = s.filterEntries(t, e);
|
|
3155
|
+
let r = 1, o = () => {
|
|
3156
|
+
--r === 0 && i();
|
|
3157
|
+
};
|
|
3158
|
+
for (let [h, a, l] of s.matches.entries()) this.#r(h) || this.matchSync(h, a, l);
|
|
3159
|
+
for (let [h, a] of s.subwalks.entries()) r++, this.walkCB2Sync(h, a, s.child(), o);
|
|
3160
|
+
o();
|
|
3161
|
+
}
|
|
3162
|
+
};
|
|
3163
|
+
var xt = class extends zt {
|
|
3164
|
+
matches = /* @__PURE__ */ new Set();
|
|
3165
|
+
constructor(t, e, s) {
|
|
3166
|
+
super(t, e, s);
|
|
3167
|
+
}
|
|
3168
|
+
matchEmit(t) {
|
|
3169
|
+
this.matches.add(t);
|
|
3170
|
+
}
|
|
3171
|
+
async walk() {
|
|
3172
|
+
if (this.signal?.aborted) throw this.signal.reason;
|
|
3173
|
+
return this.path.isUnknown() && await this.path.lstat(), await new Promise((t, e) => {
|
|
3174
|
+
this.walkCB(this.path, this.patterns, () => {
|
|
3175
|
+
this.signal?.aborted ? e(this.signal.reason) : t(this.matches);
|
|
3176
|
+
});
|
|
3177
|
+
}), this.matches;
|
|
3178
|
+
}
|
|
3179
|
+
walkSync() {
|
|
3180
|
+
if (this.signal?.aborted) throw this.signal.reason;
|
|
3181
|
+
return this.path.isUnknown() && this.path.lstatSync(), this.walkCBSync(this.path, this.patterns, () => {
|
|
3182
|
+
if (this.signal?.aborted) throw this.signal.reason;
|
|
3183
|
+
}), this.matches;
|
|
3184
|
+
}
|
|
3185
|
+
};
|
|
3186
|
+
var vt = class extends zt {
|
|
3187
|
+
results;
|
|
3188
|
+
constructor(t, e, s) {
|
|
3189
|
+
super(t, e, s), this.results = new V({ signal: this.signal, objectMode: true }), this.results.on("drain", () => this.resume()), this.results.on("resume", () => this.resume());
|
|
3190
|
+
}
|
|
3191
|
+
matchEmit(t) {
|
|
3192
|
+
this.results.write(t), this.results.flowing || this.pause();
|
|
3193
|
+
}
|
|
3194
|
+
stream() {
|
|
3195
|
+
let t = this.path;
|
|
3196
|
+
return t.isUnknown() ? t.lstat().then(() => {
|
|
3197
|
+
this.walkCB(t, this.patterns, () => this.results.end());
|
|
3198
|
+
}) : this.walkCB(t, this.patterns, () => this.results.end()), this.results;
|
|
3199
|
+
}
|
|
3200
|
+
streamSync() {
|
|
3201
|
+
return this.path.isUnknown() && this.path.lstatSync(), this.walkCBSync(this.path, this.patterns, () => this.results.end()), this.results;
|
|
3202
|
+
}
|
|
3203
|
+
};
|
|
3204
|
+
var Pi = typeof process == "object" && process && typeof process.platform == "string" ? process.platform : "linux";
|
|
3205
|
+
var I = class {
|
|
3206
|
+
absolute;
|
|
3207
|
+
cwd;
|
|
3208
|
+
root;
|
|
3209
|
+
dot;
|
|
3210
|
+
dotRelative;
|
|
3211
|
+
follow;
|
|
3212
|
+
ignore;
|
|
3213
|
+
magicalBraces;
|
|
3214
|
+
mark;
|
|
3215
|
+
matchBase;
|
|
3216
|
+
maxDepth;
|
|
3217
|
+
nobrace;
|
|
3218
|
+
nocase;
|
|
3219
|
+
nodir;
|
|
3220
|
+
noext;
|
|
3221
|
+
noglobstar;
|
|
3222
|
+
pattern;
|
|
3223
|
+
platform;
|
|
3224
|
+
realpath;
|
|
3225
|
+
scurry;
|
|
3226
|
+
stat;
|
|
3227
|
+
signal;
|
|
3228
|
+
windowsPathsNoEscape;
|
|
3229
|
+
withFileTypes;
|
|
3230
|
+
includeChildMatches;
|
|
3231
|
+
opts;
|
|
3232
|
+
patterns;
|
|
3233
|
+
constructor(t, e) {
|
|
3234
|
+
if (!e) throw new TypeError("glob options required");
|
|
3235
|
+
if (this.withFileTypes = !!e.withFileTypes, this.signal = e.signal, this.follow = !!e.follow, this.dot = !!e.dot, this.dotRelative = !!e.dotRelative, this.nodir = !!e.nodir, this.mark = !!e.mark, e.cwd ? (e.cwd instanceof URL || e.cwd.startsWith("file://")) && (e.cwd = Wi(e.cwd)) : this.cwd = "", this.cwd = e.cwd || "", this.root = e.root, this.magicalBraces = !!e.magicalBraces, this.nobrace = !!e.nobrace, this.noext = !!e.noext, this.realpath = !!e.realpath, this.absolute = e.absolute, this.includeChildMatches = e.includeChildMatches !== false, this.noglobstar = !!e.noglobstar, this.matchBase = !!e.matchBase, this.maxDepth = typeof e.maxDepth == "number" ? e.maxDepth : 1 / 0, this.stat = !!e.stat, this.ignore = e.ignore, this.withFileTypes && this.absolute !== void 0) throw new Error("cannot set absolute and withFileTypes:true");
|
|
3236
|
+
if (typeof t == "string" && (t = [t]), this.windowsPathsNoEscape = !!e.windowsPathsNoEscape || e.allowWindowsEscape === false, this.windowsPathsNoEscape && (t = t.map((a) => a.replace(/\\/g, "/"))), this.matchBase) {
|
|
3237
|
+
if (e.noglobstar) throw new TypeError("base matching requires globstar");
|
|
3238
|
+
t = t.map((a) => a.includes("/") ? a : `./**/${a}`);
|
|
3239
|
+
}
|
|
3240
|
+
if (this.pattern = t, this.platform = e.platform || Pi, this.opts = { ...e, platform: this.platform }, e.scurry) {
|
|
3241
|
+
if (this.scurry = e.scurry, e.nocase !== void 0 && e.nocase !== e.scurry.nocase) throw new Error("nocase option contradicts provided scurry option");
|
|
3242
|
+
} else {
|
|
3243
|
+
let a = e.platform === "win32" ? it : e.platform === "darwin" ? St : e.platform ? rt : Xe;
|
|
3244
|
+
this.scurry = new a(this.cwd, { nocase: e.nocase, fs: e.fs });
|
|
3245
|
+
}
|
|
3246
|
+
this.nocase = this.scurry.nocase;
|
|
3247
|
+
let s = this.platform === "darwin" || this.platform === "win32", i = { braceExpandMax: 1e4, ...e, dot: this.dot, matchBase: this.matchBase, nobrace: this.nobrace, nocase: this.nocase, nocaseMagicOnly: s, nocomment: true, noext: this.noext, nonegate: true, optimizationLevel: 2, platform: this.platform, windowsPathsNoEscape: this.windowsPathsNoEscape, debug: !!this.opts.debug }, r = this.pattern.map((a) => new D(a, i)), [o, h] = r.reduce((a, l) => (a[0].push(...l.set), a[1].push(...l.globParts), a), [[], []]);
|
|
3248
|
+
this.patterns = o.map((a, l) => {
|
|
3249
|
+
let u = h[l];
|
|
3250
|
+
if (!u) throw new Error("invalid pattern object");
|
|
3251
|
+
return new nt(a, u, 0, this.platform);
|
|
3252
|
+
});
|
|
3253
|
+
}
|
|
3254
|
+
async walk() {
|
|
3255
|
+
return [...await new xt(this.patterns, this.scurry.cwd, { ...this.opts, maxDepth: this.maxDepth !== 1 / 0 ? this.maxDepth + this.scurry.cwd.depth() : 1 / 0, platform: this.platform, nocase: this.nocase, includeChildMatches: this.includeChildMatches }).walk()];
|
|
3256
|
+
}
|
|
3257
|
+
walkSync() {
|
|
3258
|
+
return [...new xt(this.patterns, this.scurry.cwd, { ...this.opts, maxDepth: this.maxDepth !== 1 / 0 ? this.maxDepth + this.scurry.cwd.depth() : 1 / 0, platform: this.platform, nocase: this.nocase, includeChildMatches: this.includeChildMatches }).walkSync()];
|
|
3259
|
+
}
|
|
3260
|
+
stream() {
|
|
3261
|
+
return new vt(this.patterns, this.scurry.cwd, { ...this.opts, maxDepth: this.maxDepth !== 1 / 0 ? this.maxDepth + this.scurry.cwd.depth() : 1 / 0, platform: this.platform, nocase: this.nocase, includeChildMatches: this.includeChildMatches }).stream();
|
|
3262
|
+
}
|
|
3263
|
+
streamSync() {
|
|
3264
|
+
return new vt(this.patterns, this.scurry.cwd, { ...this.opts, maxDepth: this.maxDepth !== 1 / 0 ? this.maxDepth + this.scurry.cwd.depth() : 1 / 0, platform: this.platform, nocase: this.nocase, includeChildMatches: this.includeChildMatches }).streamSync();
|
|
3265
|
+
}
|
|
3266
|
+
iterateSync() {
|
|
3267
|
+
return this.streamSync()[Symbol.iterator]();
|
|
3268
|
+
}
|
|
3269
|
+
[Symbol.iterator]() {
|
|
3270
|
+
return this.iterateSync();
|
|
3271
|
+
}
|
|
3272
|
+
iterate() {
|
|
3273
|
+
return this.stream()[Symbol.asyncIterator]();
|
|
3274
|
+
}
|
|
3275
|
+
[Symbol.asyncIterator]() {
|
|
3276
|
+
return this.iterate();
|
|
3277
|
+
}
|
|
3278
|
+
};
|
|
3279
|
+
var le = (n7, t = {}) => {
|
|
3280
|
+
Array.isArray(n7) || (n7 = [n7]);
|
|
3281
|
+
for (let e of n7) if (new D(e, t).hasMagic()) return true;
|
|
3282
|
+
return false;
|
|
3283
|
+
};
|
|
3284
|
+
function Bt(n7, t = {}) {
|
|
3285
|
+
return new I(n7, t).streamSync();
|
|
3286
|
+
}
|
|
3287
|
+
function Qe(n7, t = {}) {
|
|
3288
|
+
return new I(n7, t).stream();
|
|
3289
|
+
}
|
|
3290
|
+
function ts(n7, t = {}) {
|
|
3291
|
+
return new I(n7, t).walkSync();
|
|
3292
|
+
}
|
|
3293
|
+
async function Je(n7, t = {}) {
|
|
3294
|
+
return new I(n7, t).walk();
|
|
3295
|
+
}
|
|
3296
|
+
function Ut(n7, t = {}) {
|
|
3297
|
+
return new I(n7, t).iterateSync();
|
|
3298
|
+
}
|
|
3299
|
+
function es(n7, t = {}) {
|
|
3300
|
+
return new I(n7, t).iterate();
|
|
3301
|
+
}
|
|
3302
|
+
var ji = Bt;
|
|
3303
|
+
var Ii = Object.assign(Qe, { sync: Bt });
|
|
3304
|
+
var zi = Ut;
|
|
3305
|
+
var Bi = Object.assign(es, { sync: Ut });
|
|
3306
|
+
var Ui = Object.assign(ts, { stream: Bt, iterate: Ut });
|
|
3307
|
+
var Ze = Object.assign(Je, { glob: Je, globSync: ts, sync: Ui, globStream: Qe, stream: Ii, globStreamSync: Bt, streamSync: ji, globIterate: es, iterate: Bi, globIterateSync: Ut, iterateSync: zi, Glob: I, hasMagic: le, escape: tt, unescape: W });
|
|
3308
|
+
Ze.glob = Ze;
|
|
3309
|
+
|
|
3310
|
+
// core/context-loader.ts
|
|
3311
|
+
var STACK_MAP = {
|
|
3312
|
+
react: "React",
|
|
3313
|
+
vue: "Vue",
|
|
3314
|
+
"next": "Next.js",
|
|
3315
|
+
"nuxt": "Nuxt.js",
|
|
3316
|
+
express: "Express",
|
|
3317
|
+
koa: "Koa",
|
|
3318
|
+
fastify: "Fastify",
|
|
3319
|
+
"@nestjs/core": "NestJS",
|
|
3320
|
+
prisma: "Prisma",
|
|
3321
|
+
mongoose: "Mongoose",
|
|
3322
|
+
typeorm: "TypeORM",
|
|
3323
|
+
sequelize: "Sequelize",
|
|
3324
|
+
tailwindcss: "Tailwind CSS",
|
|
3325
|
+
typescript: "TypeScript",
|
|
3326
|
+
"@supabase/supabase-js": "Supabase",
|
|
3327
|
+
"socket.io": "Socket.IO",
|
|
3328
|
+
redis: "Redis",
|
|
3329
|
+
bull: "Bull (Queue)",
|
|
3330
|
+
"@prisma/client": "Prisma"
|
|
3331
|
+
};
|
|
3332
|
+
var ContextLoader = class {
|
|
3333
|
+
constructor(projectRoot) {
|
|
3334
|
+
this.projectRoot = projectRoot;
|
|
3335
|
+
}
|
|
3336
|
+
async loadProjectContext() {
|
|
3337
|
+
const context = {
|
|
3338
|
+
techStack: [],
|
|
3339
|
+
fileStructure: [],
|
|
3340
|
+
dependencies: [],
|
|
3341
|
+
apiStructure: []
|
|
3342
|
+
};
|
|
3343
|
+
try {
|
|
3344
|
+
await this.loadPackageJson(context);
|
|
3345
|
+
await this.loadPrismaSchema(context);
|
|
3346
|
+
await this.loadFileStructure(context);
|
|
3347
|
+
await this.loadApiStructure(context);
|
|
3348
|
+
await this.loadConstitution(context);
|
|
3349
|
+
await this.loadErrorPatterns(context);
|
|
3350
|
+
} catch (e) {
|
|
3351
|
+
console.warn("Warning: Could not load full project context.", e);
|
|
3352
|
+
}
|
|
3353
|
+
return context;
|
|
3354
|
+
}
|
|
3355
|
+
async loadPackageJson(context) {
|
|
3356
|
+
const pkgPath = path.join(this.projectRoot, "package.json");
|
|
3357
|
+
if (!await fs2.pathExists(pkgPath)) return;
|
|
3358
|
+
const pkg = await fs2.readJson(pkgPath);
|
|
3359
|
+
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
3360
|
+
context.dependencies = Object.keys(allDeps);
|
|
3361
|
+
const detectedStack = /* @__PURE__ */ new Set();
|
|
3362
|
+
for (const [key, name] of Object.entries(STACK_MAP)) {
|
|
3363
|
+
if (context.dependencies.some((d) => d === key || d.startsWith(key + "/"))) {
|
|
3364
|
+
detectedStack.add(name);
|
|
3365
|
+
}
|
|
3366
|
+
}
|
|
3367
|
+
context.techStack = Array.from(detectedStack);
|
|
3368
|
+
}
|
|
3369
|
+
async loadPrismaSchema(context) {
|
|
3370
|
+
const schemaPath = path.join(this.projectRoot, "prisma", "schema.prisma");
|
|
3371
|
+
if (await fs2.pathExists(schemaPath)) {
|
|
3372
|
+
context.schema = await fs2.readFile(schemaPath, "utf-8");
|
|
3373
|
+
}
|
|
3374
|
+
}
|
|
3375
|
+
async loadFileStructure(context) {
|
|
3376
|
+
const files = await Ze("**/*", {
|
|
3377
|
+
cwd: this.projectRoot,
|
|
3378
|
+
ignore: [
|
|
3379
|
+
"node_modules/**",
|
|
3380
|
+
"dist/**",
|
|
3381
|
+
".git/**",
|
|
3382
|
+
"coverage/**",
|
|
3383
|
+
"*.lock",
|
|
3384
|
+
".DS_Store"
|
|
3385
|
+
],
|
|
3386
|
+
nodir: false,
|
|
3387
|
+
maxDepth: 3
|
|
3388
|
+
});
|
|
3389
|
+
context.fileStructure = files.slice(0, 60);
|
|
3390
|
+
}
|
|
3391
|
+
async loadConstitution(context) {
|
|
3392
|
+
const filePath = path.join(this.projectRoot, ".ai-spec-constitution.md");
|
|
3393
|
+
if (await fs2.pathExists(filePath)) {
|
|
3394
|
+
context.constitution = await fs2.readFile(filePath, "utf-8");
|
|
3395
|
+
}
|
|
3396
|
+
}
|
|
3397
|
+
async loadErrorPatterns(context) {
|
|
3398
|
+
const errorFiles = await Ze(
|
|
3399
|
+
"src/**/{error,errors,errorHandler,errorCodes,error-handler,error-codes}.{ts,js}",
|
|
3400
|
+
{ cwd: this.projectRoot }
|
|
3401
|
+
);
|
|
3402
|
+
const middlewareErrors = await Ze("src/**/middleware/**/{error,notFound}.{ts,js}", {
|
|
3403
|
+
cwd: this.projectRoot
|
|
3404
|
+
});
|
|
3405
|
+
const allErrorFiles = [.../* @__PURE__ */ new Set([...errorFiles, ...middlewareErrors])].slice(0, 3);
|
|
3406
|
+
if (allErrorFiles.length === 0) return;
|
|
3407
|
+
const parts = [];
|
|
3408
|
+
for (const f of allErrorFiles) {
|
|
3409
|
+
try {
|
|
3410
|
+
const content = await fs2.readFile(path.join(this.projectRoot, f), "utf-8");
|
|
3411
|
+
parts.push(`// ${f}
|
|
3412
|
+
${content.slice(0, 800)}`);
|
|
3413
|
+
} catch {
|
|
3414
|
+
}
|
|
3415
|
+
}
|
|
3416
|
+
if (parts.length > 0) {
|
|
3417
|
+
context.errorPatterns = parts.join("\n\n");
|
|
3418
|
+
}
|
|
3419
|
+
}
|
|
3420
|
+
async loadApiStructure(context) {
|
|
3421
|
+
const apiFiles = await Ze(
|
|
3422
|
+
"src/**/{routes,controllers,api,router,middleware}/**/*.{ts,js}",
|
|
3423
|
+
{
|
|
3424
|
+
cwd: this.projectRoot,
|
|
3425
|
+
ignore: ["**/*.test.*", "**/*.spec.*"]
|
|
3426
|
+
}
|
|
3427
|
+
);
|
|
3428
|
+
const rootApiFiles = await Ze("src/{routes,controllers,router}.{ts,js}", {
|
|
3429
|
+
cwd: this.projectRoot
|
|
3430
|
+
});
|
|
3431
|
+
context.apiStructure = [.../* @__PURE__ */ new Set([...apiFiles, ...rootApiFiles])];
|
|
3432
|
+
if (context.apiStructure.length > 0) {
|
|
3433
|
+
const summaryParts = [];
|
|
3434
|
+
for (const filePath of context.apiStructure.slice(0, 8)) {
|
|
3435
|
+
const fullPath = path.join(this.projectRoot, filePath);
|
|
3436
|
+
try {
|
|
3437
|
+
const content = await fs2.readFile(fullPath, "utf-8");
|
|
3438
|
+
const preview = content.split("\n").slice(0, 60).join("\n");
|
|
3439
|
+
summaryParts.push(`\`\`\`
|
|
3440
|
+
// ${filePath}
|
|
3441
|
+
${preview}
|
|
3442
|
+
\`\`\``);
|
|
3443
|
+
} catch {
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3446
|
+
if (summaryParts.length > 0) {
|
|
3447
|
+
context.routeSummary = summaryParts.join("\n\n");
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
3451
|
+
};
|
|
3452
|
+
|
|
3453
|
+
// core/spec-refiner.ts
|
|
3454
|
+
import { editor, confirm, select } from "@inquirer/prompts";
|
|
3455
|
+
import chalk from "chalk";
|
|
3456
|
+
var SpecRefiner = class {
|
|
3457
|
+
constructor(provider) {
|
|
3458
|
+
this.provider = provider;
|
|
3459
|
+
}
|
|
3460
|
+
async refineLoop(initialSpec) {
|
|
3461
|
+
let currentSpec = initialSpec;
|
|
3462
|
+
let round = 1;
|
|
3463
|
+
while (true) {
|
|
3464
|
+
console.log(chalk.cyan(`
|
|
3465
|
+
\u2500\u2500\u2500 Spec Review (Round ${round}) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`));
|
|
3466
|
+
console.log(chalk.gray(" Opening spec in editor. Save and close to continue."));
|
|
3467
|
+
currentSpec = await editor({
|
|
3468
|
+
message: "Review and edit the spec:",
|
|
3469
|
+
default: currentSpec,
|
|
3470
|
+
postfix: ".md",
|
|
3471
|
+
waitForUserInput: false
|
|
3472
|
+
});
|
|
3473
|
+
console.log(chalk.green(" \u2714 Spec saved."));
|
|
3474
|
+
const action = await select({
|
|
3475
|
+
message: "What would you like to do?",
|
|
3476
|
+
choices: [
|
|
3477
|
+
{ name: "\u2705 Finalize \u2014 proceed to code generation", value: "finalize" },
|
|
3478
|
+
{ name: "\u{1F916} AI Polish \u2014 let AI improve clarity & completeness", value: "ai" },
|
|
3479
|
+
{ name: "\u270F\uFE0F Edit again \u2014 continue editing", value: "edit" }
|
|
3480
|
+
]
|
|
3481
|
+
});
|
|
3482
|
+
if (action === "finalize") {
|
|
3483
|
+
break;
|
|
3484
|
+
}
|
|
3485
|
+
if (action === "ai") {
|
|
3486
|
+
console.log(chalk.blue(` AI (${this.provider.providerName}/${this.provider.modelName}) is polishing the spec...`));
|
|
3487
|
+
try {
|
|
3488
|
+
const improved = await this.provider.generate(
|
|
3489
|
+
`Review the following feature spec and improve it for clarity, completeness, and technical feasibility.
|
|
3490
|
+
Keep the same structure and language (Chinese). Fix any gaps in API design, missing error cases, or vague requirements.
|
|
3491
|
+
Output ONLY the improved markdown spec, nothing else.
|
|
3492
|
+
|
|
3493
|
+
${currentSpec}`,
|
|
3494
|
+
"You are a Senior Tech Lead doing a spec review. Output only the improved Markdown."
|
|
3495
|
+
);
|
|
3496
|
+
console.log(chalk.yellow("\n AI has suggested improvements. Opening diff in editor..."));
|
|
3497
|
+
const acceptImproved = await confirm({
|
|
3498
|
+
message: "Accept AI improvements? (opens editor so you can review first)",
|
|
3499
|
+
default: true
|
|
3500
|
+
});
|
|
3501
|
+
if (acceptImproved) {
|
|
3502
|
+
currentSpec = await editor({
|
|
3503
|
+
message: "Review AI-improved spec (edit if needed, then save):",
|
|
3504
|
+
default: improved,
|
|
3505
|
+
postfix: ".md",
|
|
3506
|
+
waitForUserInput: false
|
|
3507
|
+
});
|
|
3508
|
+
console.log(chalk.green(" \u2714 AI-improved spec accepted."));
|
|
3509
|
+
} else {
|
|
3510
|
+
console.log(chalk.gray(" AI improvements discarded. Keeping your version."));
|
|
3511
|
+
}
|
|
3512
|
+
} catch (err) {
|
|
3513
|
+
console.error(chalk.red(" AI improvement failed:"), err);
|
|
3514
|
+
console.log(chalk.gray(" Continuing with current spec."));
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
round++;
|
|
3518
|
+
}
|
|
3519
|
+
return currentSpec;
|
|
3520
|
+
}
|
|
3521
|
+
};
|
|
3522
|
+
|
|
3523
|
+
// core/code-generator.ts
|
|
3524
|
+
import chalk3 from "chalk";
|
|
3525
|
+
import { execSync } from "child_process";
|
|
3526
|
+
import * as path3 from "path";
|
|
3527
|
+
import * as fs4 from "fs-extra";
|
|
3528
|
+
|
|
3529
|
+
// prompts/codegen.prompt.ts
|
|
3530
|
+
var codeGenSystemPrompt = `You are a Senior Full-Stack Developer implementing features based on provided specifications.
|
|
3531
|
+
|
|
3532
|
+
Rules:
|
|
3533
|
+
1. Follow the existing project's code conventions, naming patterns, and file structure exactly
|
|
3534
|
+
2. Write complete, production-ready code \u2014 no placeholders, no TODOs, no stub implementations
|
|
3535
|
+
3. Include proper error handling, input validation, and logging
|
|
3536
|
+
4. Output ONLY raw code content \u2014 NO markdown fences, NO explanations, NO comments outside the code
|
|
3537
|
+
5. Match the imports, exports, and module patterns visible in the existing codebase
|
|
3538
|
+
6. Do not add unnecessary dependencies \u2014 reuse what is already in the project
|
|
3539
|
+
7. If modifying an existing file, preserve all unchanged code exactly`;
|
|
3540
|
+
var reviewSystemPrompt = `You are a Senior Software Architect conducting a thorough code review. Your review should be structured, constructive, and specific.
|
|
3541
|
+
|
|
3542
|
+
Always format your review with these exact sections:
|
|
3543
|
+
|
|
3544
|
+
## \u2705 \u4F18\u70B9 (What's Good)
|
|
3545
|
+
List specific things done well.
|
|
3546
|
+
|
|
3547
|
+
## \u26A0\uFE0F \u95EE\u9898 (Issues Found)
|
|
3548
|
+
List bugs, security issues, or spec deviations with line references.
|
|
3549
|
+
|
|
3550
|
+
## \u{1F4A1} \u6539\u8FDB\u5EFA\u8BAE (Suggestions)
|
|
3551
|
+
Actionable improvements that would elevate code quality.
|
|
3552
|
+
|
|
3553
|
+
## \u{1F4CA} \u603B\u4F53\u8BC4\u4EF7 (Overall Assessment)
|
|
3554
|
+
Score: X/10 \u2014 One-paragraph summary.
|
|
3555
|
+
|
|
3556
|
+
Be specific. Reference actual code, not vague principles.`;
|
|
3557
|
+
|
|
3558
|
+
// core/task-generator.ts
|
|
3559
|
+
import chalk2 from "chalk";
|
|
3560
|
+
import * as fs3 from "fs-extra";
|
|
3561
|
+
import * as path2 from "path";
|
|
3562
|
+
|
|
3563
|
+
// prompts/tasks.prompt.ts
|
|
3564
|
+
var tasksSystemPrompt = `You are a Senior Software Architect. Decompose the provided Feature Spec into an ordered list of discrete implementation tasks.
|
|
3565
|
+
|
|
3566
|
+
Output ONLY a valid JSON array. No markdown fences, no explanation.
|
|
3567
|
+
|
|
3568
|
+
Each task object must have these exact fields:
|
|
3569
|
+
{
|
|
3570
|
+
"id": "TASK-001", // sequential, zero-padded
|
|
3571
|
+
"title": "...", // short action phrase, e.g. "Add UserFavorite Prisma model"
|
|
3572
|
+
"description": "...", // 1-2 sentences, specific and actionable
|
|
3573
|
+
"layer": "data|service|api|test|infra", // implementation layer
|
|
3574
|
+
"filesToTouch": ["..."], // specific file paths relative to project root
|
|
3575
|
+
"acceptanceCriteria": ["..."], // verifiable completion conditions
|
|
3576
|
+
"dependencies": ["TASK-001"], // task ids that must complete first (empty array if none)
|
|
3577
|
+
"priority": "high|medium|low"
|
|
3578
|
+
}
|
|
3579
|
+
|
|
3580
|
+
Layer ordering guidance (implement in this order):
|
|
3581
|
+
1. "data" \u2014 DB schema changes, migrations, seed data
|
|
3582
|
+
2. "infra" \u2014 config, env vars, external service setup
|
|
3583
|
+
3. "service" \u2014 business logic, service classes
|
|
3584
|
+
4. "api" \u2014 controllers, routes, middleware, validators
|
|
3585
|
+
5. "test" \u2014 unit tests, integration tests
|
|
3586
|
+
|
|
3587
|
+
Rules:
|
|
3588
|
+
- Be specific about filesToTouch \u2014 use exact paths from the project context
|
|
3589
|
+
- acceptanceCriteria must be verifiable (not vague like "works correctly")
|
|
3590
|
+
- dependencies must reflect real implementation order
|
|
3591
|
+
- Aim for 4-10 tasks total \u2014 not too granular, not too coarse
|
|
3592
|
+
- Each task should be completable in one focused coding session`;
|
|
3593
|
+
|
|
3594
|
+
// core/task-generator.ts
|
|
3595
|
+
var LAYER_ORDER = {
|
|
3596
|
+
data: 0,
|
|
3597
|
+
infra: 1,
|
|
3598
|
+
service: 2,
|
|
3599
|
+
api: 3,
|
|
3600
|
+
test: 4
|
|
3601
|
+
};
|
|
3602
|
+
var TaskGenerator = class {
|
|
3603
|
+
constructor(provider) {
|
|
3604
|
+
this.provider = provider;
|
|
3605
|
+
}
|
|
3606
|
+
async generateTasks(spec, context) {
|
|
3607
|
+
const contextSummary = context ? `
|
|
3608
|
+
=== Project Context ===
|
|
3609
|
+
Tech: ${context.techStack.join(", ")}
|
|
3610
|
+
Files: ${context.fileStructure.slice(0, 20).join(", ")}
|
|
3611
|
+
` : "";
|
|
3612
|
+
const prompt = `${spec}${contextSummary}`;
|
|
3613
|
+
const raw = await this.provider.generate(prompt, tasksSystemPrompt);
|
|
3614
|
+
return parseTasks(raw);
|
|
3615
|
+
}
|
|
3616
|
+
async saveTasks(tasks, specFilePath) {
|
|
3617
|
+
const dir = path2.dirname(specFilePath);
|
|
3618
|
+
const base = path2.basename(specFilePath, ".md");
|
|
3619
|
+
const tasksFile = path2.join(dir, `${base}-tasks.json`);
|
|
3620
|
+
await fs3.writeJson(tasksFile, tasks, { spaces: 2 });
|
|
3621
|
+
return tasksFile;
|
|
3622
|
+
}
|
|
3623
|
+
sortByLayer(tasks) {
|
|
3624
|
+
return [...tasks].sort((a, b) => {
|
|
3625
|
+
const layerDiff = (LAYER_ORDER[a.layer] ?? 99) - (LAYER_ORDER[b.layer] ?? 99);
|
|
3626
|
+
if (layerDiff !== 0) return layerDiff;
|
|
3627
|
+
return a.id.localeCompare(b.id);
|
|
3628
|
+
});
|
|
3629
|
+
}
|
|
3630
|
+
};
|
|
3631
|
+
function parseTasks(raw) {
|
|
3632
|
+
const fenced = raw.match(/```(?:json)?\n(\[[\s\S]*?\])\n```/);
|
|
3633
|
+
const jsonStr = fenced ? fenced[1] : raw.match(/\[[\s\S]*\]/)?.[0] ?? "";
|
|
3634
|
+
try {
|
|
3635
|
+
const parsed = JSON.parse(jsonStr);
|
|
3636
|
+
if (Array.isArray(parsed)) return parsed;
|
|
3637
|
+
} catch {
|
|
3638
|
+
}
|
|
3639
|
+
return [];
|
|
3640
|
+
}
|
|
3641
|
+
function printTasks(tasks) {
|
|
3642
|
+
const layerColors = {
|
|
3643
|
+
data: chalk2.magenta,
|
|
3644
|
+
infra: chalk2.gray,
|
|
3645
|
+
service: chalk2.blue,
|
|
3646
|
+
api: chalk2.cyan,
|
|
3647
|
+
test: chalk2.green
|
|
3648
|
+
};
|
|
3649
|
+
console.log(chalk2.bold(`
|
|
3650
|
+
Tasks (${tasks.length}):`));
|
|
3651
|
+
for (const task of tasks) {
|
|
3652
|
+
const color = layerColors[task.layer] ?? chalk2.white;
|
|
3653
|
+
const badge = color(`[${task.layer}]`);
|
|
3654
|
+
const prio = task.priority === "high" ? chalk2.red("\u25CF") : task.priority === "medium" ? chalk2.yellow("\u25CF") : chalk2.gray("\u25CF");
|
|
3655
|
+
console.log(` ${prio} ${chalk2.bold(task.id)} ${badge} ${task.title}`);
|
|
3656
|
+
}
|
|
3657
|
+
}
|
|
3658
|
+
async function loadTasksForSpec(specFilePath) {
|
|
3659
|
+
const base = path2.basename(specFilePath, ".md");
|
|
3660
|
+
const dir = path2.dirname(specFilePath);
|
|
3661
|
+
const tasksFile = path2.join(dir, `${base}-tasks.json`);
|
|
3662
|
+
if (await fs3.pathExists(tasksFile)) {
|
|
3663
|
+
return fs3.readJson(tasksFile);
|
|
3664
|
+
}
|
|
3665
|
+
return null;
|
|
3666
|
+
}
|
|
3667
|
+
|
|
3668
|
+
// core/code-generator.ts
|
|
3669
|
+
function isRtkAvailable() {
|
|
3670
|
+
try {
|
|
3671
|
+
execSync("rtk --version", { stdio: "ignore" });
|
|
3672
|
+
return true;
|
|
3673
|
+
} catch {
|
|
3674
|
+
return false;
|
|
3675
|
+
}
|
|
3676
|
+
}
|
|
3677
|
+
function stripCodeFences(output) {
|
|
3678
|
+
const fenced = output.match(/^```(?:\w+)?\n([\s\S]*?)```\s*$/m);
|
|
3679
|
+
if (fenced) return fenced[1].trim();
|
|
3680
|
+
const lines = output.split("\n");
|
|
3681
|
+
if (lines[0].startsWith("```")) lines.shift();
|
|
3682
|
+
if (lines[lines.length - 1].trim() === "```") lines.pop();
|
|
3683
|
+
return lines.join("\n").trim();
|
|
3684
|
+
}
|
|
3685
|
+
function parseJsonArray(text) {
|
|
3686
|
+
const fenced = text.match(/```(?:json)?\n(\[[\s\S]*?\])\n```/);
|
|
3687
|
+
const raw = fenced ? fenced[1] : text.match(/\[[\s\S]*?\]/)?.[0] ?? "";
|
|
3688
|
+
try {
|
|
3689
|
+
const parsed = JSON.parse(raw);
|
|
3690
|
+
if (Array.isArray(parsed)) return parsed;
|
|
3691
|
+
} catch {
|
|
3692
|
+
}
|
|
3693
|
+
return [];
|
|
3694
|
+
}
|
|
3695
|
+
var CodeGenerator = class {
|
|
3696
|
+
constructor(provider, mode = "claude-code") {
|
|
3697
|
+
this.provider = provider;
|
|
3698
|
+
this.mode = mode;
|
|
3699
|
+
}
|
|
3700
|
+
async generateCode(specFilePath, workingDir, context, options = {}) {
|
|
3701
|
+
let effectiveMode = this.mode;
|
|
3702
|
+
if (effectiveMode === "claude-code" && this.provider.providerName !== "claude") {
|
|
3703
|
+
console.log(
|
|
3704
|
+
chalk3.yellow(
|
|
3705
|
+
`
|
|
3706
|
+
\u26A0 codegen \u6A21\u5F0F "claude-code" \u9700\u8981 Claude\uFF0C\u4F46\u5F53\u524D provider \u662F "${this.provider.providerName}"\u3002`
|
|
3707
|
+
)
|
|
3708
|
+
);
|
|
3709
|
+
console.log(chalk3.gray(` \u81EA\u52A8\u5207\u6362\u5230 "api" \u6A21\u5F0F\uFF08\u4F7F\u7528 ${this.provider.providerName}/${this.provider.modelName} \u751F\u6210\u4EE3\u7801\uFF09\u3002`));
|
|
3710
|
+
console.log(chalk3.gray(` \u63D0\u793A\uFF1A\u8FD0\u884C \`ai-spec config --codegen api\` \u53EF\u56FA\u5316\u6B64\u8BBE\u7F6E\u3002
|
|
3711
|
+
`));
|
|
3712
|
+
effectiveMode = "api";
|
|
3713
|
+
}
|
|
3714
|
+
switch (effectiveMode) {
|
|
3715
|
+
case "claude-code":
|
|
3716
|
+
return this.runClaudeCode(specFilePath, workingDir, options);
|
|
3717
|
+
case "api":
|
|
3718
|
+
return this.runApiMode(specFilePath, workingDir, context);
|
|
3719
|
+
case "plan":
|
|
3720
|
+
return this.runPlanMode(specFilePath);
|
|
3721
|
+
}
|
|
3722
|
+
}
|
|
3723
|
+
// ── Mode: claude-code ──────────────────────────────────────────────────────
|
|
3724
|
+
isClaudeCLIAvailable() {
|
|
3725
|
+
try {
|
|
3726
|
+
execSync("claude --version", { stdio: "ignore" });
|
|
3727
|
+
return true;
|
|
3728
|
+
} catch {
|
|
3729
|
+
return false;
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3732
|
+
async runClaudeCode(specFilePath, workingDir, options = {}) {
|
|
3733
|
+
console.log(chalk3.blue("\n\u2500\u2500\u2500 Code Generation: Claude Code CLI \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
3734
|
+
if (!this.isClaudeCLIAvailable()) {
|
|
3735
|
+
console.log(chalk3.yellow(" \u26A0\uFE0F Claude Code CLI not found. Falling back to plan mode."));
|
|
3736
|
+
console.log(chalk3.gray(" Install: npm install -g @anthropic-ai/claude-code"));
|
|
3737
|
+
return this.runPlanMode(specFilePath);
|
|
3738
|
+
}
|
|
3739
|
+
const tasks = await loadTasksForSpec(specFilePath);
|
|
3740
|
+
const taskSection = tasks && tasks.length > 0 ? `
|
|
3741
|
+
|
|
3742
|
+
== Implementation Tasks (implement in order) ==
|
|
3743
|
+
${tasks.map((t) => `${t.id} [${t.layer}] ${t.title}
|
|
3744
|
+
Files: ${t.filesToTouch.join(", ")}
|
|
3745
|
+
Criteria: ${t.acceptanceCriteria.join("; ")}`).join("\n")}` : "";
|
|
3746
|
+
const promptContent = `Please read the spec file at ${specFilePath} and implement all the requirements. Create or modify files as necessary.${taskSection}`;
|
|
3747
|
+
const promptFile = path3.join(workingDir, ".claude-prompt.txt");
|
|
3748
|
+
await fs4.writeFile(promptFile, promptContent, "utf-8");
|
|
3749
|
+
const rtkAvailable = isRtkAvailable();
|
|
3750
|
+
const claudeCmd = rtkAvailable ? "rtk claude" : "claude";
|
|
3751
|
+
if (rtkAvailable) {
|
|
3752
|
+
console.log(chalk3.green(" \u2713 RTK detected \u2014 using rtk claude for token savings"));
|
|
3753
|
+
}
|
|
3754
|
+
if (options.auto) {
|
|
3755
|
+
console.log(chalk3.cyan(` \u{1F916} Auto mode: running claude -p (non-interactive)...`));
|
|
3756
|
+
console.log(chalk3.gray(` Spec: ${specFilePath}`));
|
|
3757
|
+
if (tasks) console.log(chalk3.gray(` Tasks: ${tasks.length} tasks loaded`));
|
|
3758
|
+
try {
|
|
3759
|
+
execSync(`${claudeCmd} -p "${promptContent.replace(/"/g, '\\"')}"`, {
|
|
3760
|
+
cwd: workingDir,
|
|
3761
|
+
stdio: "inherit"
|
|
3762
|
+
});
|
|
3763
|
+
console.log(chalk3.green("\n \u2714 Claude Code completed."));
|
|
3764
|
+
} catch {
|
|
3765
|
+
console.log(chalk3.yellow("\n Claude Code exited. Check output above."));
|
|
3766
|
+
}
|
|
3767
|
+
} else {
|
|
3768
|
+
console.log(chalk3.cyan(` \u{1F680} Launching ${claudeCmd} in: ${workingDir}`));
|
|
3769
|
+
console.log(chalk3.gray(` Spec: ${specFilePath}`));
|
|
3770
|
+
if (tasks) console.log(chalk3.gray(` Tasks: ${tasks.length} tasks loaded into .claude-prompt.txt`));
|
|
3771
|
+
console.log(chalk3.gray(" Prompt pre-loaded in .claude-prompt.txt\n"));
|
|
3772
|
+
try {
|
|
3773
|
+
execSync(claudeCmd, { cwd: workingDir, stdio: "inherit" });
|
|
3774
|
+
console.log(chalk3.green("\n \u2714 Claude Code session completed."));
|
|
3775
|
+
} catch {
|
|
3776
|
+
console.log(chalk3.yellow("\n Claude Code session ended. Continuing workflow."));
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3780
|
+
// ── Mode: api ─────────────────────────────────────────────────────────────
|
|
3781
|
+
async runApiMode(specFilePath, workingDir, context) {
|
|
3782
|
+
console.log(
|
|
3783
|
+
chalk3.blue(
|
|
3784
|
+
`
|
|
3785
|
+
\u2500\u2500\u2500 Code Generation: API (${this.provider.providerName}/${this.provider.modelName}) \u2500\u2500\u2500`
|
|
3786
|
+
)
|
|
3787
|
+
);
|
|
3788
|
+
const spec = await fs4.readFile(specFilePath, "utf-8");
|
|
3789
|
+
const constitutionSection = context?.constitution ? `
|
|
3790
|
+
=== Project Constitution (MUST follow) ===
|
|
3791
|
+
${context.constitution.slice(0, 2e3)}
|
|
3792
|
+
` : "";
|
|
3793
|
+
const contextSummary = context ? `Tech Stack: ${context.techStack.join(", ")}
|
|
3794
|
+
Existing files: ${context.fileStructure.slice(0, 20).join(", ")}` : "";
|
|
3795
|
+
const tasks = await loadTasksForSpec(specFilePath);
|
|
3796
|
+
if (tasks && tasks.length > 0) {
|
|
3797
|
+
return this.runApiModeWithTasks(spec, tasks, workingDir, constitutionSection);
|
|
3798
|
+
}
|
|
3799
|
+
console.log(chalk3.gray(" [1/2] Planning implementation files..."));
|
|
3800
|
+
const planPrompt = `Based on the feature spec and project context below, list ALL files that need to be created or modified.
|
|
3801
|
+
|
|
3802
|
+
=== Feature Spec ===
|
|
3803
|
+
${spec}
|
|
3804
|
+
${constitutionSection}
|
|
3805
|
+
=== Project Context ===
|
|
3806
|
+
${contextSummary}
|
|
3807
|
+
|
|
3808
|
+
Output ONLY a valid JSON array:
|
|
3809
|
+
[
|
|
3810
|
+
{"file": "src/controllers/userController.ts", "action": "create", "description": "Handle user CRUD operations"},
|
|
3811
|
+
{"file": "src/routes/client/index.ts", "action": "modify", "description": "Register new routes"}
|
|
3812
|
+
]`;
|
|
3813
|
+
let filePlan = [];
|
|
3814
|
+
try {
|
|
3815
|
+
const planResponse = await this.provider.generate(planPrompt, codeGenSystemPrompt);
|
|
3816
|
+
filePlan = parseJsonArray(planResponse);
|
|
3817
|
+
} catch (err) {
|
|
3818
|
+
console.error(chalk3.red(" Failed to generate file plan:"), err);
|
|
3819
|
+
}
|
|
3820
|
+
if (filePlan.length === 0) {
|
|
3821
|
+
console.log(chalk3.yellow(" Could not determine file plan. Falling back to plan mode."));
|
|
3822
|
+
return this.runPlanMode(specFilePath);
|
|
3823
|
+
}
|
|
3824
|
+
console.log(chalk3.cyan(`
|
|
3825
|
+
Plan: ${filePlan.length} file(s) to process`));
|
|
3826
|
+
filePlan.forEach((item) => {
|
|
3827
|
+
const icon = item.action === "create" ? chalk3.green("+") : chalk3.yellow("~");
|
|
3828
|
+
console.log(` ${icon} ${item.file}: ${chalk3.gray(item.description)}`);
|
|
3829
|
+
});
|
|
3830
|
+
await this.generateFiles(filePlan, spec, workingDir, constitutionSection);
|
|
3831
|
+
}
|
|
3832
|
+
async runApiModeWithTasks(spec, tasks, workingDir, constitutionSection) {
|
|
3833
|
+
console.log(chalk3.cyan(`
|
|
3834
|
+
Task-based generation: ${tasks.length} tasks`));
|
|
3835
|
+
let totalSuccess = 0;
|
|
3836
|
+
let totalFiles = 0;
|
|
3837
|
+
for (const task of tasks) {
|
|
3838
|
+
console.log(chalk3.bold(`
|
|
3839
|
+
\u2192 ${task.id} [${task.layer}] ${task.title}`));
|
|
3840
|
+
if (task.filesToTouch.length === 0) {
|
|
3841
|
+
console.log(chalk3.gray(" No files specified, skipping."));
|
|
3842
|
+
continue;
|
|
3843
|
+
}
|
|
3844
|
+
const filePlan = task.filesToTouch.map((f) => ({
|
|
3845
|
+
file: f,
|
|
3846
|
+
action: "create",
|
|
3847
|
+
description: task.description
|
|
3848
|
+
}));
|
|
3849
|
+
const taskContext = `Task: ${task.id} \u2014 ${task.title}
|
|
3850
|
+
${task.description}
|
|
3851
|
+
Acceptance: ${task.acceptanceCriteria.join("; ")}`;
|
|
3852
|
+
const { success, total } = await this.generateFiles(
|
|
3853
|
+
filePlan,
|
|
3854
|
+
`${spec}
|
|
3855
|
+
|
|
3856
|
+
=== Current Task ===
|
|
3857
|
+
${taskContext}`,
|
|
3858
|
+
workingDir,
|
|
3859
|
+
constitutionSection
|
|
3860
|
+
);
|
|
3861
|
+
totalSuccess += success;
|
|
3862
|
+
totalFiles += total;
|
|
3863
|
+
}
|
|
3864
|
+
console.log(
|
|
3865
|
+
chalk3.bold(
|
|
3866
|
+
`
|
|
3867
|
+
${totalSuccess === totalFiles ? chalk3.green("\u2714") : chalk3.yellow("!")} Task-based generation: ${totalSuccess}/${totalFiles} files written across ${tasks.length} tasks.`
|
|
3868
|
+
)
|
|
3869
|
+
);
|
|
3870
|
+
}
|
|
3871
|
+
async generateFiles(filePlan, spec, workingDir, constitutionSection) {
|
|
3872
|
+
console.log(chalk3.gray(`
|
|
3873
|
+
Generating ${filePlan.length} file(s)...`));
|
|
3874
|
+
let successCount = 0;
|
|
3875
|
+
for (const item of filePlan) {
|
|
3876
|
+
const fullPath = path3.join(workingDir, item.file);
|
|
3877
|
+
let existingContent = "";
|
|
3878
|
+
if (await fs4.pathExists(fullPath)) {
|
|
3879
|
+
existingContent = await fs4.readFile(fullPath, "utf-8");
|
|
3880
|
+
}
|
|
3881
|
+
const codePrompt = `Implement this file.
|
|
3882
|
+
|
|
3883
|
+
File: ${item.file}
|
|
3884
|
+
Purpose: ${item.description}
|
|
3885
|
+
|
|
3886
|
+
=== Feature Spec ===
|
|
3887
|
+
${spec}
|
|
3888
|
+
${constitutionSection}
|
|
3889
|
+
=== ${existingContent ? "Existing content (modify and return the complete file)" : "Create this file from scratch"} ===
|
|
3890
|
+
${existingContent || "Output only the complete file content."}`;
|
|
3891
|
+
process.stdout.write(` ${existingContent ? chalk3.yellow("~") : chalk3.green("+")} ${chalk3.bold(item.file)}... `);
|
|
3892
|
+
try {
|
|
3893
|
+
const raw = await this.provider.generate(codePrompt, codeGenSystemPrompt);
|
|
3894
|
+
const fileContent = stripCodeFences(raw);
|
|
3895
|
+
await fs4.ensureDir(path3.dirname(fullPath));
|
|
3896
|
+
await fs4.writeFile(fullPath, fileContent, "utf-8");
|
|
3897
|
+
console.log(chalk3.green("\u2714"));
|
|
3898
|
+
successCount++;
|
|
3899
|
+
} catch (err) {
|
|
3900
|
+
console.log(chalk3.red("\u2718"));
|
|
3901
|
+
console.error(chalk3.red(` Error: ${err.message}`));
|
|
3902
|
+
}
|
|
3903
|
+
}
|
|
3904
|
+
console.log(
|
|
3905
|
+
chalk3.bold(
|
|
3906
|
+
` ${successCount === filePlan.length ? chalk3.green("\u2714") : chalk3.yellow("!")} ${successCount}/${filePlan.length} files written.`
|
|
3907
|
+
)
|
|
3908
|
+
);
|
|
3909
|
+
return { success: successCount, total: filePlan.length };
|
|
3910
|
+
}
|
|
3911
|
+
// ── Mode: plan ─────────────────────────────────────────────────────────────
|
|
3912
|
+
async runPlanMode(specFilePath) {
|
|
3913
|
+
console.log(chalk3.blue("\n\u2500\u2500\u2500 Implementation Plan \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
3914
|
+
const spec = await fs4.readFile(specFilePath, "utf-8");
|
|
3915
|
+
const plan = await this.provider.generate(
|
|
3916
|
+
`Create a detailed, step-by-step implementation plan for the following feature spec.
|
|
3917
|
+
Be specific about:
|
|
3918
|
+
- Which files to create or modify
|
|
3919
|
+
- Key functions/classes to implement
|
|
3920
|
+
- Data flow and integration points
|
|
3921
|
+
- Suggested implementation order
|
|
3922
|
+
|
|
3923
|
+
${spec}`,
|
|
3924
|
+
"You are a senior developer creating an actionable implementation guide."
|
|
3925
|
+
);
|
|
3926
|
+
console.log(chalk3.cyan("\n") + plan);
|
|
3927
|
+
}
|
|
3928
|
+
};
|
|
3929
|
+
|
|
3930
|
+
// core/reviewer.ts
|
|
3931
|
+
import chalk4 from "chalk";
|
|
3932
|
+
import { execSync as execSync2 } from "child_process";
|
|
3933
|
+
var CodeReviewer = class {
|
|
3934
|
+
constructor(provider) {
|
|
3935
|
+
this.provider = provider;
|
|
3936
|
+
}
|
|
3937
|
+
getGitDiff() {
|
|
3938
|
+
try {
|
|
3939
|
+
let diff = execSync2("git diff --cached", { encoding: "utf-8" });
|
|
3940
|
+
if (!diff.trim()) diff = execSync2("git diff HEAD", { encoding: "utf-8" });
|
|
3941
|
+
if (!diff.trim()) diff = execSync2("git diff", { encoding: "utf-8" });
|
|
3942
|
+
return diff;
|
|
3943
|
+
} catch {
|
|
3944
|
+
return "";
|
|
3945
|
+
}
|
|
3946
|
+
}
|
|
3947
|
+
getDiffStats(diff) {
|
|
3948
|
+
const lines = diff.split("\n");
|
|
3949
|
+
return {
|
|
3950
|
+
files: lines.filter((l) => l.startsWith("diff --git")).length,
|
|
3951
|
+
added: lines.filter((l) => l.startsWith("+") && !l.startsWith("+++")).length,
|
|
3952
|
+
removed: lines.filter((l) => l.startsWith("-") && !l.startsWith("---")).length
|
|
3953
|
+
};
|
|
3954
|
+
}
|
|
3955
|
+
async reviewCode(specContent) {
|
|
3956
|
+
console.log(chalk4.cyan("\n\u2500\u2500\u2500 Automated Code Review \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
3957
|
+
const diff = this.getGitDiff();
|
|
3958
|
+
if (!diff.trim()) {
|
|
3959
|
+
console.log(
|
|
3960
|
+
chalk4.yellow(" No git diff found. Stage or commit changes first, then run review.")
|
|
3961
|
+
);
|
|
3962
|
+
console.log(chalk4.gray(" Tip: run `git add .` then `ai-spec review` to review your work."));
|
|
3963
|
+
return "No changes";
|
|
3964
|
+
}
|
|
3965
|
+
const { files, added, removed } = this.getDiffStats(diff);
|
|
3966
|
+
console.log(
|
|
3967
|
+
chalk4.gray(` Diff: ${files} file(s), ${chalk4.green("+" + added)} ${chalk4.red("-" + removed)}`)
|
|
3968
|
+
);
|
|
3969
|
+
console.log(
|
|
3970
|
+
chalk4.blue(` Reviewing with ${this.provider.providerName}/${this.provider.modelName}...`)
|
|
3971
|
+
);
|
|
3972
|
+
const prompt = `Conduct a code review for the following change.
|
|
3973
|
+
|
|
3974
|
+
=== Feature Spec (what should be implemented) ===
|
|
3975
|
+
${specContent || "(No spec provided \u2014 review for general code quality, patterns, and correctness)"}
|
|
3976
|
+
|
|
3977
|
+
=== Git Diff (what was actually implemented) ===
|
|
3978
|
+
${diff.slice(0, 1e4)}`;
|
|
3979
|
+
const reviewResult = await this.provider.generate(prompt, reviewSystemPrompt);
|
|
3980
|
+
console.log(chalk4.cyan("\n\u2500\u2500\u2500 Review Result \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
3981
|
+
console.log(reviewResult);
|
|
3982
|
+
console.log(chalk4.cyan("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n"));
|
|
3983
|
+
return reviewResult;
|
|
3984
|
+
}
|
|
3985
|
+
};
|
|
3986
|
+
|
|
3987
|
+
// core/constitution-generator.ts
|
|
3988
|
+
import chalk5 from "chalk";
|
|
3989
|
+
import * as fs5 from "fs-extra";
|
|
3990
|
+
import * as path4 from "path";
|
|
3991
|
+
|
|
3992
|
+
// prompts/constitution.prompt.ts
|
|
3993
|
+
var constitutionSystemPrompt = `You are a Senior Software Architect. Analyze the provided project codebase context and generate a concise "Project Constitution" \u2014 a living document that captures the architectural rules, conventions, and red lines that ALL future feature specs and code generation MUST follow.
|
|
3994
|
+
|
|
3995
|
+
Output a Markdown document with EXACTLY these sections. Be specific and derive rules directly from the observed codebase \u2014 no generic advice.
|
|
3996
|
+
|
|
3997
|
+
---
|
|
3998
|
+
|
|
3999
|
+
# Project Constitution
|
|
4000
|
+
|
|
4001
|
+
## 1. \u67B6\u6784\u89C4\u5219 (Architecture Rules)
|
|
4002
|
+
\u5217\u51FA\u9879\u76EE\u7684\u6838\u5FC3\u67B6\u6784\u6A21\u5F0F\u548C\u5F3A\u5236\u7EA6\u675F\uFF08\u4ECE\u4EE3\u7801\u4E2D\u63D0\u53D6\uFF0C\u800C\u975E\u901A\u7528\u5EFA\u8BAE\uFF09\u3002
|
|
4003
|
+
- \u5206\u5C42\u67B6\u6784\u89C4\u5219\uFF08\u5982\uFF1Aroutes \u2192 controllers \u2192 services \u2192 DB\uFF09
|
|
4004
|
+
- \u7981\u6B62\u8DE8\u5C42\u76F4\u63A5\u8C03\u7528\u7684\u89C4\u5219
|
|
4005
|
+
- \u6A21\u5757\u7EC4\u7EC7\u89C4\u8303
|
|
4006
|
+
|
|
4007
|
+
## 2. \u547D\u540D\u89C4\u8303 (Naming Conventions)
|
|
4008
|
+
- \u6587\u4EF6\u547D\u540D\u89C4\u5219\uFF08\u9A7C\u5CF0/\u4E0B\u5212\u7EBF/kebab\uFF09
|
|
4009
|
+
- \u53D8\u91CF\u3001\u51FD\u6570\u3001\u7C7B\u7684\u547D\u540D\u6A21\u5F0F
|
|
4010
|
+
- \u8DEF\u7531\u8DEF\u5F84\u7684\u547D\u540D\u89C4\u8303
|
|
4011
|
+
|
|
4012
|
+
## 3. API \u89C4\u8303 (API Patterns)
|
|
4013
|
+
- \u8DEF\u7531\u524D\u7F00\u89C4\u5219\uFF08\u5982 /api/v1/client/... vs /api/v1/admin/...\uFF09
|
|
4014
|
+
- \u7EDF\u4E00\u54CD\u5E94\u7ED3\u6784\u6A21\u677F\uFF08code/message/data \u683C\u5F0F\uFF09
|
|
4015
|
+
- \u9519\u8BEF\u7801\u89C4\u8303\uFF08\u5DF2\u6709\u7684\u9519\u8BEF\u7801\u8303\u56F4\u548C\u542B\u4E49\uFF09
|
|
4016
|
+
- \u8BA4\u8BC1/\u9274\u6743\u6A21\u5F0F\uFF08middleware \u540D\u79F0\u548C\u4F7F\u7528\u4F4D\u7F6E\uFF09
|
|
4017
|
+
|
|
4018
|
+
## 4. \u6570\u636E\u5C42\u89C4\u8303 (Data Layer Rules)
|
|
4019
|
+
- ORM/\u6570\u636E\u5E93\u8BBF\u95EE\u89C4\u5219\uFF08\u4EC5\u901A\u8FC7 service \u5C42\u8BBF\u95EE\uFF1F\u76F4\u63A5\u7528 Prisma/Mongoose\uFF1F\uFF09
|
|
4020
|
+
- \u5DF2\u6709\u7684\u6570\u636E\u6A21\u578B\u547D\u540D\u89C4\u8303
|
|
4021
|
+
- \u4E8B\u52A1\u5904\u7406\u6A21\u5F0F
|
|
4022
|
+
|
|
4023
|
+
## 5. \u9519\u8BEF\u5904\u7406\u89C4\u8303 (Error Handling Patterns)
|
|
4024
|
+
- \u7EDF\u4E00\u9519\u8BEF\u5904\u7406 middleware \u7684\u4F7F\u7528\u89C4\u5219
|
|
4025
|
+
- \u9519\u8BEF\u629B\u51FA\u548C\u6355\u83B7\u7684\u6A21\u5F0F
|
|
4026
|
+
- \u5DF2\u77E5\u9519\u8BEF\u7801\u5217\u8868\uFF08\u4ECE\u4EE3\u7801\u4E2D\u63D0\u53D6\uFF09
|
|
4027
|
+
|
|
4028
|
+
## 6. \u7981\u533A (Red Lines \u2014 Never Violate)
|
|
4029
|
+
\u660E\u786E\u5217\u51FA\u7EDD\u5BF9\u4E0D\u80FD\u505A\u7684\u4E8B\u60C5\uFF08\u4ECE\u73B0\u6709\u4EE3\u7801/\u67B6\u6784\u63A8\u65AD\uFF09\uFF1A
|
|
4030
|
+
- [ ] \u7981\u6B62 ...
|
|
4031
|
+
- [ ] \u7981\u6B62 ...
|
|
4032
|
+
|
|
4033
|
+
## 7. \u6D4B\u8BD5\u89C4\u8303 (Testing Rules)
|
|
4034
|
+
- \u6D4B\u8BD5\u6587\u4EF6\u5B58\u653E\u4F4D\u7F6E
|
|
4035
|
+
- \u5FC5\u987B\u8986\u76D6\u7684\u6D4B\u8BD5\u573A\u666F\u7C7B\u578B
|
|
4036
|
+
- \u6D4B\u8BD5\u6846\u67B6\u548C\u5DE5\u5177
|
|
4037
|
+
|
|
4038
|
+
---
|
|
4039
|
+
|
|
4040
|
+
Be concise. Each rule must be specific enough to enforce, not a vague principle.`;
|
|
4041
|
+
|
|
4042
|
+
// core/constitution-generator.ts
|
|
4043
|
+
var CONSTITUTION_FILE = ".ai-spec-constitution.md";
|
|
4044
|
+
var ConstitutionGenerator = class {
|
|
4045
|
+
constructor(provider) {
|
|
4046
|
+
this.provider = provider;
|
|
4047
|
+
}
|
|
4048
|
+
async generate(projectRoot) {
|
|
4049
|
+
const loader = new ContextLoader(projectRoot);
|
|
4050
|
+
const context = await loader.loadProjectContext();
|
|
4051
|
+
const prompt = buildConstitutionPrompt(context, projectRoot);
|
|
4052
|
+
return this.provider.generate(prompt, constitutionSystemPrompt);
|
|
4053
|
+
}
|
|
4054
|
+
async saveConstitution(projectRoot, content) {
|
|
4055
|
+
const filePath = path4.join(projectRoot, CONSTITUTION_FILE);
|
|
4056
|
+
await fs5.writeFile(filePath, content, "utf-8");
|
|
4057
|
+
return filePath;
|
|
4058
|
+
}
|
|
4059
|
+
};
|
|
4060
|
+
function buildConstitutionPrompt(context, projectRoot) {
|
|
4061
|
+
const parts = [
|
|
4062
|
+
"Analyze this project and generate its Project Constitution.\n",
|
|
4063
|
+
`=== Tech Stack ===
|
|
4064
|
+
${context.techStack.join(", ") || "unknown"}
|
|
4065
|
+
`,
|
|
4066
|
+
`=== Dependencies (top 30) ===
|
|
4067
|
+
${context.dependencies.slice(0, 30).join(", ")}
|
|
4068
|
+
`
|
|
4069
|
+
];
|
|
4070
|
+
if (context.apiStructure.length > 0) {
|
|
4071
|
+
parts.push(`=== API/Route Files ===
|
|
4072
|
+
${context.apiStructure.join("\n")}
|
|
4073
|
+
`);
|
|
4074
|
+
}
|
|
4075
|
+
if (context.routeSummary) {
|
|
4076
|
+
parts.push(`=== Route Code Samples ===
|
|
4077
|
+
${context.routeSummary}
|
|
4078
|
+
`);
|
|
4079
|
+
}
|
|
4080
|
+
if (context.schema) {
|
|
4081
|
+
parts.push(`=== Prisma Schema ===
|
|
4082
|
+
${context.schema.slice(0, 4e3)}
|
|
4083
|
+
`);
|
|
4084
|
+
}
|
|
4085
|
+
if (context.errorPatterns) {
|
|
4086
|
+
parts.push(`=== Error Handling Patterns ===
|
|
4087
|
+
${context.errorPatterns}
|
|
4088
|
+
`);
|
|
4089
|
+
}
|
|
4090
|
+
return parts.join("\n");
|
|
4091
|
+
}
|
|
4092
|
+
async function loadConstitution(projectRoot) {
|
|
4093
|
+
const filePath = path4.join(projectRoot, CONSTITUTION_FILE);
|
|
4094
|
+
if (await fs5.pathExists(filePath)) {
|
|
4095
|
+
return fs5.readFile(filePath, "utf-8");
|
|
4096
|
+
}
|
|
4097
|
+
return void 0;
|
|
4098
|
+
}
|
|
4099
|
+
function printConstitutionHint(exists) {
|
|
4100
|
+
if (!exists) {
|
|
4101
|
+
console.log(
|
|
4102
|
+
chalk5.yellow(
|
|
4103
|
+
" \u26A1 Tip: Run `ai-spec init` to generate a Project Constitution for better spec quality."
|
|
4104
|
+
)
|
|
4105
|
+
);
|
|
4106
|
+
}
|
|
4107
|
+
}
|
|
4108
|
+
|
|
4109
|
+
// git/worktree.ts
|
|
4110
|
+
import { execSync as execSync3 } from "child_process";
|
|
4111
|
+
import * as path5 from "path";
|
|
4112
|
+
import * as fs6 from "fs-extra";
|
|
4113
|
+
import chalk6 from "chalk";
|
|
4114
|
+
var GitWorktreeManager = class {
|
|
4115
|
+
constructor(baseDir) {
|
|
4116
|
+
this.baseDir = baseDir;
|
|
4117
|
+
}
|
|
4118
|
+
isGitRepo() {
|
|
4119
|
+
try {
|
|
4120
|
+
execSync3("git rev-parse --is-inside-work-tree", { cwd: this.baseDir, stdio: "ignore" });
|
|
4121
|
+
return true;
|
|
4122
|
+
} catch {
|
|
4123
|
+
return false;
|
|
4124
|
+
}
|
|
4125
|
+
}
|
|
4126
|
+
sanitizeFeatureName(idea) {
|
|
4127
|
+
return idea.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").substring(0, 30) || `feature-${Date.now()}`;
|
|
4128
|
+
}
|
|
4129
|
+
async createWorktree(idea) {
|
|
4130
|
+
if (!this.isGitRepo()) {
|
|
4131
|
+
console.log(chalk6.yellow("\u26A0\uFE0F Not a git repository. Skipping worktree creation."));
|
|
4132
|
+
return null;
|
|
4133
|
+
}
|
|
4134
|
+
const featureName = this.sanitizeFeatureName(idea);
|
|
4135
|
+
const branchName = `feature/${featureName}`;
|
|
4136
|
+
const repoName = path5.basename(this.baseDir);
|
|
4137
|
+
const worktreePath = path5.resolve(this.baseDir, "..", `${repoName}-${featureName}`);
|
|
4138
|
+
console.log(chalk6.cyan(`
|
|
4139
|
+
--- Setting up Git Worktree ---`));
|
|
4140
|
+
if (await fs6.pathExists(worktreePath)) {
|
|
4141
|
+
console.log(chalk6.yellow(`\u26A0\uFE0F Worktree directory already exists at: ${worktreePath}`));
|
|
4142
|
+
return worktreePath;
|
|
4143
|
+
}
|
|
4144
|
+
try {
|
|
4145
|
+
let branchExists = false;
|
|
4146
|
+
try {
|
|
4147
|
+
execSync3(`git show-ref --verify refs/heads/${branchName}`, { cwd: this.baseDir, stdio: "ignore" });
|
|
4148
|
+
branchExists = true;
|
|
4149
|
+
} catch {
|
|
4150
|
+
}
|
|
4151
|
+
console.log(chalk6.gray(`Creating worktree at: ${worktreePath}`));
|
|
4152
|
+
if (branchExists) {
|
|
4153
|
+
execSync3(`git worktree add "${worktreePath}" ${branchName}`, { cwd: this.baseDir, stdio: "inherit" });
|
|
4154
|
+
} else {
|
|
4155
|
+
execSync3(`git worktree add -b ${branchName} "${worktreePath}"`, { cwd: this.baseDir, stdio: "inherit" });
|
|
4156
|
+
}
|
|
4157
|
+
console.log(chalk6.green(`\u2714 Worktree successfully created and isolated on branch '${branchName}'`));
|
|
4158
|
+
return worktreePath;
|
|
4159
|
+
} catch (error) {
|
|
4160
|
+
console.error(chalk6.red("Failed to create git worktree:"), error);
|
|
4161
|
+
return null;
|
|
4162
|
+
}
|
|
4163
|
+
}
|
|
4164
|
+
};
|
|
4165
|
+
export {
|
|
4166
|
+
CONSTITUTION_FILE,
|
|
4167
|
+
ClaudeProvider,
|
|
4168
|
+
CodeGenerator,
|
|
4169
|
+
CodeReviewer,
|
|
4170
|
+
ConstitutionGenerator,
|
|
4171
|
+
ContextLoader,
|
|
4172
|
+
DEFAULT_MODELS,
|
|
4173
|
+
ENV_KEY_MAP,
|
|
4174
|
+
GeminiProvider,
|
|
4175
|
+
GitWorktreeManager,
|
|
4176
|
+
OpenAICompatibleProvider,
|
|
4177
|
+
PROVIDER_CATALOG,
|
|
4178
|
+
SUPPORTED_PROVIDERS,
|
|
4179
|
+
SpecGenerator,
|
|
4180
|
+
SpecRefiner,
|
|
4181
|
+
TaskGenerator,
|
|
4182
|
+
createProvider,
|
|
4183
|
+
loadConstitution,
|
|
4184
|
+
loadTasksForSpec,
|
|
4185
|
+
printConstitutionHint,
|
|
4186
|
+
printTasks
|
|
4187
|
+
};
|
|
4188
|
+
//# sourceMappingURL=index.mjs.map
|