@narumitw/pi-starship 0.55.1 → 0.55.2
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/dist/chunks/{chunk-UX6PBXVK.js → chunk-JO5PH6FN.js} +28 -110
- package/dist/chunks/chunk-JO5PH6FN.js.map +7 -0
- package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
- package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
- package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
- package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
- package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
- package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
- package/dist/chunks/{commands-53ZO2JUK.js → commands-ATILSUVK.js} +13 -42
- package/dist/chunks/commands-ATILSUVK.js.map +7 -0
- package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
- package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
- package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
- package/dist/chunks/development-OUYXDPBS.js.map +7 -0
- package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
- package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
- package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
- package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
- package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
- package/dist/chunks/package-YXRZQAOV.js.map +7 -0
- package/dist/index.ts +20 -55
- package/dist/index.ts.map +2 -2
- package/package.json +60 -61
- package/skills/configuring-pi-starship/scripts/apply.mjs +43 -47
- package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
- package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
- package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
- package/src/command-configuration.ts +267 -286
- package/src/command-contract.ts +6 -6
- package/src/command-inspector.ts +27 -27
- package/src/command-preset-picker.ts +45 -50
- package/src/command-preview.ts +153 -166
- package/src/commands.ts +588 -618
- package/src/config.ts +580 -660
- package/src/effective-config.ts +46 -48
- package/src/format/formatter.ts +211 -227
- package/src/format/style.ts +205 -216
- package/src/modules/activity.ts +74 -74
- package/src/modules/brand.ts +9 -9
- package/src/modules/cache.ts +18 -18
- package/src/modules/catalog.ts +79 -83
- package/src/modules/cloud.ts +54 -54
- package/src/modules/context.ts +27 -27
- package/src/modules/cost.ts +23 -23
- package/src/modules/deployment.ts +45 -45
- package/src/modules/development.ts +80 -81
- package/src/modules/directory.ts +89 -113
- package/src/modules/display.ts +9 -9
- package/src/modules/execution.ts +62 -69
- package/src/modules/extension-status.ts +59 -64
- package/src/modules/fill.ts +10 -10
- package/src/modules/git/branch.ts +26 -26
- package/src/modules/git/commit.ts +21 -23
- package/src/modules/git/metrics.ts +22 -22
- package/src/modules/git/runtime.ts +299 -334
- package/src/modules/git/state.ts +17 -17
- package/src/modules/git/status.ts +77 -79
- package/src/modules/git/worktree.ts +10 -12
- package/src/modules/github-pr.ts +20 -20
- package/src/modules/helpers.ts +3 -3
- package/src/modules/index.ts +21 -21
- package/src/modules/inspection.ts +101 -108
- package/src/modules/languages.ts +52 -59
- package/src/modules/model.ts +57 -67
- package/src/modules/package.ts +12 -12
- package/src/modules/provider.ts +22 -24
- package/src/modules/render.ts +124 -140
- package/src/modules/thinking.ts +27 -26
- package/src/modules/time.ts +10 -13
- package/src/modules/tokens.ts +13 -13
- package/src/modules/truncation.ts +14 -17
- package/src/modules/turn.ts +9 -9
- package/src/modules/types.ts +125 -132
- package/src/modules/workspace-helpers.ts +4 -7
- package/src/pi-starship.ts +567 -603
- package/src/presets/catalog.ts +113 -113
- package/src/runtime/cloud.ts +122 -150
- package/src/runtime/command.ts +106 -108
- package/src/runtime/deployment.ts +150 -179
- package/src/runtime/development.ts +107 -124
- package/src/runtime/execution.ts +110 -124
- package/src/runtime/github-pr.ts +223 -252
- package/src/runtime/helpers.ts +186 -199
- package/src/runtime/languages.ts +149 -180
- package/src/runtime/package.ts +74 -87
- package/src/runtime/refresh-controller.ts +82 -86
- package/src/runtime/types.ts +38 -38
- package/src/runtime/workspace.ts +108 -116
- package/src/usage.ts +40 -40
- package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
- package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
- package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
- package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
- package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
- package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
- package/dist/chunks/development-BERD42HW.js.map +0 -7
- package/dist/chunks/execution-42JTEY3N.js.map +0 -7
- package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
- package/dist/chunks/package-LG5H7BBM.js.map +0 -7
package/src/runtime/languages.ts
CHANGED
|
@@ -1,205 +1,174 @@
|
|
|
1
1
|
import { delimiter, join } from "node:path";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
directMatch,
|
|
4
|
+
formatVersion,
|
|
5
|
+
MAX_METADATA_FILE_BYTES,
|
|
6
|
+
optionString,
|
|
7
|
+
optionStrings,
|
|
8
|
+
pathName,
|
|
9
|
+
runBounded,
|
|
10
|
+
safeMetadata,
|
|
11
11
|
} from "./helpers.js";
|
|
12
12
|
import type { CollectorContext, MutableModuleSnapshot } from "./types.js";
|
|
13
13
|
|
|
14
14
|
const LANGUAGE_NAMES = ["nodejs", "python", "rust", "golang", "bun", "deno"] as const;
|
|
15
15
|
type LanguageName = (typeof LANGUAGE_NAMES)[number];
|
|
16
16
|
|
|
17
|
-
const DEFAULT_DETECTION: Record<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
folders: ["node_modules"],
|
|
33
|
-
},
|
|
34
|
-
python: {
|
|
35
|
-
files: ["pyproject.toml", "requirements.txt", "Pipfile", "poetry.lock", ".python-version"],
|
|
36
|
-
extensions: ["py"],
|
|
37
|
-
folders: [".venv", "venv"],
|
|
38
|
-
},
|
|
39
|
-
rust: { files: ["Cargo.toml"], extensions: ["rs"], folders: [] },
|
|
40
|
-
golang: { files: ["go.mod", "go.sum", "go.work"], extensions: ["go"], folders: [] },
|
|
41
|
-
bun: { files: ["bun.lock", "bun.lockb", "bunfig.toml"], extensions: [], folders: [] },
|
|
42
|
-
deno: { files: ["deno.json", "deno.jsonc", "deno.lock"], extensions: [], folders: [] },
|
|
17
|
+
const DEFAULT_DETECTION: Record<LanguageName, { files: string[]; extensions: string[]; folders: string[] }> = {
|
|
18
|
+
nodejs: {
|
|
19
|
+
files: ["package.json", ".node-version", ".nvmrc", "!bun.lock", "!bun.lockb", "!deno.json", "!deno.jsonc"],
|
|
20
|
+
extensions: ["js", "mjs", "cjs", "ts", "mts", "cts"],
|
|
21
|
+
folders: ["node_modules"],
|
|
22
|
+
},
|
|
23
|
+
python: {
|
|
24
|
+
files: ["pyproject.toml", "requirements.txt", "Pipfile", "poetry.lock", ".python-version"],
|
|
25
|
+
extensions: ["py"],
|
|
26
|
+
folders: [".venv", "venv"],
|
|
27
|
+
},
|
|
28
|
+
rust: { files: ["Cargo.toml"], extensions: ["rs"], folders: [] },
|
|
29
|
+
golang: { files: ["go.mod", "go.sum", "go.work"], extensions: ["go"], folders: [] },
|
|
30
|
+
bun: { files: ["bun.lock", "bun.lockb", "bunfig.toml"], extensions: [], folders: [] },
|
|
31
|
+
deno: { files: ["deno.json", "deno.jsonc", "deno.lock"], extensions: [], folders: [] },
|
|
43
32
|
};
|
|
44
33
|
|
|
45
34
|
export async function collectLanguages(context: CollectorContext): Promise<MutableModuleSnapshot> {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
35
|
+
const result: MutableModuleSnapshot = {};
|
|
36
|
+
if (!LANGUAGE_NAMES.some((name) => context.needs(name))) return result;
|
|
37
|
+
const entries = await context.entries();
|
|
38
|
+
for (const name of LANGUAGE_NAMES) {
|
|
39
|
+
if (!context.needs(name)) continue;
|
|
40
|
+
const defaults = DEFAULT_DETECTION[name];
|
|
41
|
+
const files = optionStrings(context, name, "detect_files");
|
|
42
|
+
const extensions = optionStrings(context, name, "detect_extensions");
|
|
43
|
+
const folders = optionStrings(context, name, "detect_folders");
|
|
44
|
+
if (
|
|
45
|
+
!directMatch(
|
|
46
|
+
entries,
|
|
47
|
+
files.length > 0 ? files : defaults.files,
|
|
48
|
+
extensions.length > 0 ? extensions : defaults.extensions,
|
|
49
|
+
folders.length > 0 ? folders : defaults.folders,
|
|
50
|
+
)
|
|
51
|
+
) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const values: Record<string, string> = {};
|
|
55
|
+
addEnvironmentValues(context, name, values);
|
|
56
|
+
if (context.needs(name, "engines_version")) {
|
|
57
|
+
const engine = await readNodeEngine(context);
|
|
58
|
+
if (engine) values.engines_version = engine;
|
|
59
|
+
}
|
|
60
|
+
const needsVersion = context.needs(name, "version");
|
|
61
|
+
const needsNumver = name === "rust" && context.needs(name, "numver");
|
|
62
|
+
if (needsVersion || needsNumver) {
|
|
63
|
+
const command = await versionCommand(context, name);
|
|
64
|
+
if (command) {
|
|
65
|
+
const output = await runBounded(context, command[0], command[1]);
|
|
66
|
+
const version = output ? parseRuntimeVersion(name, output) : undefined;
|
|
67
|
+
if (version) {
|
|
68
|
+
if (needsVersion) {
|
|
69
|
+
values.version = formatVersion(version, optionString(context, name, "version_format"));
|
|
70
|
+
}
|
|
71
|
+
if (needsNumver) values.numver = version.replace(/^v/u, "");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
result[name] = values;
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
89
78
|
}
|
|
90
79
|
|
|
91
|
-
function addEnvironmentValues(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (name === "rust") {
|
|
104
|
-
const toolchain = safeMetadata(env.RUSTUP_TOOLCHAIN);
|
|
105
|
-
if (toolchain && context.needs(name, "toolchain")) values.toolchain = toolchain;
|
|
106
|
-
}
|
|
80
|
+
function addEnvironmentValues(context: CollectorContext, name: LanguageName, values: Record<string, string>): void {
|
|
81
|
+
const env = context.input.environment;
|
|
82
|
+
if (name === "python") {
|
|
83
|
+
const virtualenv = safeMetadata(env.VIRTUAL_ENV) ?? safeMetadata(env.CONDA_DEFAULT_ENV);
|
|
84
|
+
if (virtualenv && context.needs(name, "virtualenv")) values.virtualenv = pathName(virtualenv);
|
|
85
|
+
const pyenv = safeMetadata(env.PYENV_VERSION);
|
|
86
|
+
if (pyenv && context.needs(name, "pyenv_prefix")) values.pyenv_prefix = pyenv;
|
|
87
|
+
}
|
|
88
|
+
if (name === "rust") {
|
|
89
|
+
const toolchain = safeMetadata(env.RUSTUP_TOOLCHAIN);
|
|
90
|
+
if (toolchain && context.needs(name, "toolchain")) values.toolchain = toolchain;
|
|
91
|
+
}
|
|
107
92
|
}
|
|
108
93
|
|
|
109
94
|
async function readNodeEngine(context: CollectorContext): Promise<string | undefined> {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
} catch {
|
|
119
|
-
return undefined;
|
|
120
|
-
}
|
|
95
|
+
const source = await context.fs.readFile(join(context.input.cwd, "package.json"), MAX_METADATA_FILE_BYTES);
|
|
96
|
+
if (!source) return undefined;
|
|
97
|
+
try {
|
|
98
|
+
const document = JSON.parse(source) as { engines?: { node?: unknown } };
|
|
99
|
+
return safeMetadata(document.engines?.node, 80);
|
|
100
|
+
} catch {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
121
103
|
}
|
|
122
104
|
|
|
123
|
-
async function versionCommand(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return ["go", ["version"]];
|
|
147
|
-
case "bun":
|
|
148
|
-
return ["bun", ["--version"]];
|
|
149
|
-
case "deno":
|
|
150
|
-
return ["deno", ["-V"]];
|
|
151
|
-
}
|
|
105
|
+
async function versionCommand(context: CollectorContext, name: LanguageName): Promise<[string, string[]] | undefined> {
|
|
106
|
+
switch (name) {
|
|
107
|
+
case "nodejs":
|
|
108
|
+
return ["node", ["--version"]];
|
|
109
|
+
case "python": {
|
|
110
|
+
const virtualenv = safeMetadata(context.input.environment.VIRTUAL_ENV);
|
|
111
|
+
if (virtualenv) {
|
|
112
|
+
const candidate = join(virtualenv, context.input.platform === "win32" ? "Scripts/python.exe" : "bin/python");
|
|
113
|
+
if (await context.fs.fileExists(candidate)) return [candidate, ["--version"]];
|
|
114
|
+
}
|
|
115
|
+
return ["python", ["--version"]];
|
|
116
|
+
}
|
|
117
|
+
case "rust": {
|
|
118
|
+
const rustc = await safeRustCompiler(context);
|
|
119
|
+
return rustc ? [rustc, ["--version"]] : undefined;
|
|
120
|
+
}
|
|
121
|
+
case "golang":
|
|
122
|
+
return ["go", ["version"]];
|
|
123
|
+
case "bun":
|
|
124
|
+
return ["bun", ["--version"]];
|
|
125
|
+
case "deno":
|
|
126
|
+
return ["deno", ["-V"]];
|
|
127
|
+
}
|
|
152
128
|
}
|
|
153
129
|
|
|
154
130
|
async function safeRustCompiler(context: CollectorContext): Promise<string | undefined> {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
return undefined;
|
|
131
|
+
const candidates = [
|
|
132
|
+
context.input.environment.RUSTC,
|
|
133
|
+
...(context.input.environment.PATH ?? "")
|
|
134
|
+
.split(delimiter)
|
|
135
|
+
.filter(Boolean)
|
|
136
|
+
.map((directory) => join(directory, context.input.platform === "win32" ? "rustc.exe" : "rustc")),
|
|
137
|
+
];
|
|
138
|
+
for (const rawCandidate of candidates) {
|
|
139
|
+
const candidate = safeMetadata(rawCandidate, 1_024);
|
|
140
|
+
if (!candidate || /(?:^|[\\/])\.(?:cargo|rustup)(?:[\\/]|$)/iu.test(candidate)) continue;
|
|
141
|
+
if (await context.fs.fileExists(candidate)) return candidate;
|
|
142
|
+
}
|
|
143
|
+
return undefined;
|
|
170
144
|
}
|
|
171
145
|
|
|
172
146
|
export function parseRuntimeVersion(name: LanguageName, output: string): string | undefined {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
match = /^(?:deno\s+)?(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)$/u.exec(normalized);
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
const version = match?.[1];
|
|
204
|
-
return version ? `v${version}` : undefined;
|
|
147
|
+
const normalized = output.trim();
|
|
148
|
+
if (!normalized || normalized.includes("\n") || normalized.includes("\r") || normalized.includes("�")) {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
let match: RegExpExecArray | null;
|
|
152
|
+
switch (name) {
|
|
153
|
+
case "nodejs":
|
|
154
|
+
match = /^v(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)$/u.exec(normalized);
|
|
155
|
+
break;
|
|
156
|
+
case "python":
|
|
157
|
+
match = /^Python (\d+\.\d+(?:\.\d+)?(?:[0-9A-Za-z.+-]*)?)$/u.exec(normalized);
|
|
158
|
+
break;
|
|
159
|
+
case "rust":
|
|
160
|
+
match = /^rustc (\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)(?: .*)?$/u.exec(normalized);
|
|
161
|
+
break;
|
|
162
|
+
case "golang":
|
|
163
|
+
match = /^go version go(\d+\.\d+(?:\.\d+)?(?:[0-9A-Za-z.+-]*))(?:\s+.*)?$/u.exec(normalized);
|
|
164
|
+
break;
|
|
165
|
+
case "bun":
|
|
166
|
+
match = /^(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)$/u.exec(normalized);
|
|
167
|
+
break;
|
|
168
|
+
case "deno":
|
|
169
|
+
match = /^(?:deno\s+)?(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)$/u.exec(normalized);
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
const version = match?.[1];
|
|
173
|
+
return version ? `v${version}` : undefined;
|
|
205
174
|
}
|
package/src/runtime/package.ts
CHANGED
|
@@ -1,112 +1,99 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { parse } from "smol-toml";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
formatVersion,
|
|
5
|
+
isRecord,
|
|
6
|
+
MAX_METADATA_FILE_BYTES,
|
|
7
|
+
optionString,
|
|
8
|
+
parentDirectories,
|
|
9
|
+
safeMetadata,
|
|
10
10
|
} from "./helpers.js";
|
|
11
11
|
import type { CollectorContext } from "./types.js";
|
|
12
12
|
|
|
13
|
-
export async function collectPackage(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
return undefined;
|
|
13
|
+
export async function collectPackage(context: CollectorContext): Promise<Record<string, string> | undefined> {
|
|
14
|
+
if (!context.needs("package")) return undefined;
|
|
15
|
+
const versionFormat = optionString(context, "package", "version_format");
|
|
16
|
+
for (const reader of [readPackageJson, readCargo, readPyproject]) {
|
|
17
|
+
const result = await reader(context);
|
|
18
|
+
if (!result) continue;
|
|
19
|
+
return {
|
|
20
|
+
source: result.source,
|
|
21
|
+
version: formatVersion(result.version, versionFormat),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
interface PackageVersion {
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
version: string;
|
|
29
|
+
source: string;
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
async function readPackageJson(context: CollectorContext): Promise<PackageVersion | undefined> {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} catch {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
33
|
+
const source = await context.fs.readFile(join(context.input.cwd, "package.json"), MAX_METADATA_FILE_BYTES);
|
|
34
|
+
if (!source) return undefined;
|
|
35
|
+
try {
|
|
36
|
+
const document = JSON.parse(source) as unknown;
|
|
37
|
+
const version = isRecord(document) ? safeVersion(document.version) : undefined;
|
|
38
|
+
return version ? { version, source: "package.json" } : undefined;
|
|
39
|
+
} catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
47
42
|
}
|
|
48
43
|
|
|
49
44
|
async function readCargo(context: CollectorContext): Promise<PackageVersion | undefined> {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
} catch {
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
45
|
+
const path = join(context.input.cwd, "Cargo.toml");
|
|
46
|
+
const source = await context.fs.readFile(path, MAX_METADATA_FILE_BYTES);
|
|
47
|
+
if (!source) return undefined;
|
|
48
|
+
try {
|
|
49
|
+
const document = parse(source);
|
|
50
|
+
const packageTable = isRecord(document.package) ? document.package : undefined;
|
|
51
|
+
const direct = safeVersion(packageTable?.version);
|
|
52
|
+
if (direct) return { version: direct, source: "Cargo.toml" };
|
|
53
|
+
const inherited = isRecord(packageTable?.version) && packageTable.version.workspace === true;
|
|
54
|
+
if (!inherited) return undefined;
|
|
55
|
+
const localWorkspaceVersion = workspacePackageVersion(document);
|
|
56
|
+
if (localWorkspaceVersion) {
|
|
57
|
+
return { version: localWorkspaceVersion, source: "Cargo.toml workspace" };
|
|
58
|
+
}
|
|
59
|
+
for (const parent of parentDirectories(context.input.cwd, 8)) {
|
|
60
|
+
const parentSource = await context.fs.readFile(join(parent, "Cargo.toml"), MAX_METADATA_FILE_BYTES);
|
|
61
|
+
if (!parentSource) continue;
|
|
62
|
+
const parentDocument = parse(parentSource);
|
|
63
|
+
const version = workspacePackageVersion(parentDocument);
|
|
64
|
+
if (version) return { version, source: "Cargo.toml workspace" };
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
} catch {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
78
70
|
}
|
|
79
71
|
|
|
80
72
|
function workspacePackageVersion(document: Record<string, unknown>): string | undefined {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
const workspace = isRecord(document.workspace) ? document.workspace : undefined;
|
|
74
|
+
const workspacePackage = isRecord(workspace?.package) ? workspace.package : undefined;
|
|
75
|
+
return safeVersion(workspacePackage?.version);
|
|
84
76
|
}
|
|
85
77
|
|
|
86
78
|
async function readPyproject(context: CollectorContext): Promise<PackageVersion | undefined> {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
? { version: poetryVersion, source: "pyproject.toml (Poetry)" }
|
|
103
|
-
: undefined;
|
|
104
|
-
} catch {
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
79
|
+
const source = await context.fs.readFile(join(context.input.cwd, "pyproject.toml"), MAX_METADATA_FILE_BYTES);
|
|
80
|
+
if (!source) return undefined;
|
|
81
|
+
try {
|
|
82
|
+
const document = parse(source);
|
|
83
|
+
const project = isRecord(document.project) ? document.project : undefined;
|
|
84
|
+
if (Array.isArray(project?.dynamic) && project.dynamic.includes("version")) return undefined;
|
|
85
|
+
const pepVersion = safeVersion(project?.version);
|
|
86
|
+
if (pepVersion) return { version: pepVersion, source: "pyproject.toml (PEP 621)" };
|
|
87
|
+
const tool = isRecord(document.tool) ? document.tool : undefined;
|
|
88
|
+
const poetry = isRecord(tool?.poetry) ? tool.poetry : undefined;
|
|
89
|
+
const poetryVersion = safeVersion(poetry?.version);
|
|
90
|
+
return poetryVersion ? { version: poetryVersion, source: "pyproject.toml (Poetry)" } : undefined;
|
|
91
|
+
} catch {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
107
94
|
}
|
|
108
95
|
|
|
109
96
|
function safeVersion(value: unknown): string | undefined {
|
|
110
|
-
|
|
111
|
-
|
|
97
|
+
const version = safeMetadata(value, 80);
|
|
98
|
+
return version && /^[0-9A-Za-z][0-9A-Za-z.+_-]*$/u.test(version) ? version : undefined;
|
|
112
99
|
}
|