@lekman/devops-toolkit-tasks 1.4.0 → 2.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tobias Lekman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,67 +1,126 @@
1
1
  # @lekman/devops-toolkit-tasks
2
2
 
3
- Six shared [Task](https://taskfile.dev) files for AI tooling, AWS, Docker, git,
4
- module updates and container security scanning. Install once, include what you
5
- need, and the same commands work across every repository.
3
+ Shared [Task](https://taskfile.dev) files for every repository. Install the
4
+ package, include its Taskfiles, and each repository gets the same commands:
5
+
6
+ | Command | What it does |
7
+ | ------------------------------- | ---------------------------------------------------------------------------- |
8
+ | `task`, `task help`, `task h` | Prints every task, grouped by the Taskfile that defines it, with its aliases |
9
+ | `task build`, `task core:build` | Builds what the repository declares, detected the way CI detects it |
10
+ | `task package:register` | Checks, and with `-- --apply` sets up, what each package needs to publish |
6
11
 
7
12
  ## Install
8
13
 
14
+ The package is on npm. Pin it exactly:
15
+
9
16
  ```bash
10
- brew install go-task/tap/go-task # once per machine
11
- npm i -D @lekman/devops-toolkit-tasks
17
+ bun add -d -E @lekman/devops-toolkit-tasks
12
18
  ```
13
19
 
14
- ## Use
20
+ It needs `go-task` 3.39 or later (for `flatten`) and Bun.
21
+
22
+ Version 2 replaces the 1.x files under `common/` (`ai`, `aws`, `docker`,
23
+ `git`, `modules` and `security`). A repository that includes them stays on
24
+ 1.4.0 until it moves to the files below.
15
25
 
16
- Add the includes you want to `taskfile.yml` at your repository root:
26
+ ## Use
17
27
 
18
28
  ```yaml
19
29
  version: "3"
20
30
 
21
31
  includes:
22
- ai: node_modules/@lekman/devops-toolkit-tasks/common/ai.yml
23
- aws: node_modules/@lekman/devops-toolkit-tasks/common/aws.yml
24
- docker: node_modules/@lekman/devops-toolkit-tasks/common/docker.yml
25
- git: node_modules/@lekman/devops-toolkit-tasks/common/git.yml
26
- modules: node_modules/@lekman/devops-toolkit-tasks/common/modules.yml
27
- security: node_modules/@lekman/devops-toolkit-tasks/common/security.yml
28
-
29
- tasks:
30
- default:
31
- silent: true
32
- cmds:
33
- - task --list
32
+ core:
33
+ taskfile: node_modules/@lekman/devops-toolkit-tasks/tasks/core.yml
34
+ dir: .
35
+ flatten: true
36
+ vars:
37
+ HELP_TITLE: My repository # optional; the folder's name by default
38
+ PYTHON_DIR: services/worker # optional; "." by default
34
39
  ```
35
40
 
36
- Then `task --list` shows everything available, and each task is namespaced by
37
- its include:
41
+ `flatten: true` puts the tasks at the top level. A flattened task keeps the
42
+ name it has in the file, so the build is `core:build` with `build` as its
43
+ alias, and the help page is the `default` task with `help` and `h`.
38
44
 
39
- ```bash
40
- task git:prune # delete merged local branches
41
- task docker:build-image # build the image
42
- task aws:check-auth # verify the current AWS session
43
- ```
45
+ ## The help page
46
+
47
+ `task help` runs `task --list-all --json` and prints each task with its
48
+ aliases and description. The root Taskfile's tasks come first, under
49
+ "Project"; every included file follows under its own name (`core.yml` is
50
+ "core"). Internal tasks are not listed. Colour is on in a terminal and off
51
+ when the output is piped or `NO_COLOR` is set.
44
52
 
45
- ## What each file provides
53
+ ## The build
46
54
 
47
- | Include | Tasks |
48
- | ---------- | -------------------------------------------------------------------------------- |
49
- | `ai` | `setup` — install and configure the AI tooling |
50
- | `aws` | `check-auth`, `configure-docker`, `ensure-ecr-repository` |
51
- | `docker` | `ensure-docker-running`, `build-image`, `tag-image`, `push-image` |
52
- | `git` | `cd-root`, `get-root`, `prune`, `fetch-prune`, `switch-default`, `list-branches` |
53
- | `modules` | `update-tools` — update the pinned toolchain |
54
- | `security` | `scan-image` — container vulnerability scan |
55
+ `task build` decides what to build with the toolkit's own language
56
+ detection, the code CI's `detect-language` action runs, and runs the
57
+ project's own build command:
55
58
 
56
- Include only what a repository needs; an unused include costs nothing but adds
57
- noise to `task --list`.
59
+ | Found | Runs |
60
+ | ---------------------------------------------- | ----------------------------------------------------------------------------- |
61
+ | `package.json` and `turbo.json` | `turbo run build` through the package manager |
62
+ | `package.json` with a `build` script | `<pm> run build` |
63
+ | workspaces whose members have a `build` script | the package manager's workspace runner |
64
+ | `pyproject.toml` with a `[build-system]` | `poetry build`, `uv build`, `pipenv run python -m build` or `python -m build` |
58
65
 
59
- ## Requirements
66
+ The Node package manager comes from the lockfile (`bun.lock`,
67
+ `pnpm-lock.yaml`, `yarn.lock`, `package-lock.json`), then the
68
+ `packageManager` field, and is Bun when neither names one. The Python
69
+ package manager comes from the toolkit's detection: the lockfile, then the
70
+ `[tool.poetry]` or `[tool.uv]` table, then a `Pipfile`, else pip.
71
+
72
+ `task build -- --dry-run` prints the plan without running it. A repository
73
+ with nothing to build prints what was looked for and passes.
74
+
75
+ The build does not install dependencies. Run the repository's install
76
+ first.
77
+
78
+ ## Publishing setup
79
+
80
+ `task package:register` (include `package.yml` under the `package` namespace,
81
+ alias `pkg`) finds each package the repository publishes and prints a
82
+ checklist for it: `[x]` done, `[ ]` missing, `[?]` unknown, each with how it
83
+ is known.
84
+
85
+ ```yaml
86
+ includes:
87
+ package:
88
+ taskfile: node_modules/@lekman/devops-toolkit-tasks/tasks/package.yml
89
+ dir: .
90
+ aliases: [pkg]
91
+ ```
60
92
 
61
- `go-task` v3. Individual tasks may need the tool they wrap — the AWS tasks need
62
- the AWS CLI, the Docker tasks need a running Docker daemon. Each task checks and
63
- fails with a clear message rather than a stack trace.
93
+ It finds `package.json` without `private` (npm), `pyproject.toml` with a
94
+ `[build-system]` (PyPI), a Gradle build with a Maven publishing plugin or a
95
+ POM that deploys (Maven Central), and a `.csproj` marked packable (NuGet). It
96
+ reads `.github/workflows/` for the job that publishes each, its environment
97
+ and the secrets it reads, and checks:
98
+
99
+ | Registry | Checked through an API | Guided only (no API) |
100
+ | ------------- | -------------------------------------------------------------------------------------------- | ------------------------------------------ |
101
+ | npm | the package on the registry, `npm whoami`, `npm trust list` | - |
102
+ | PyPI | the project's JSON API, the GitHub environment | the trusted or pending publisher |
103
+ | Maven Central | `maven-metadata.xml` on repo1, the environment and its secret names, the GPG key, keyservers | the namespace and the Central Portal token |
104
+ | NuGet | the flat container, the environment and its secret names | the trusted publishing policy, ID prefix |
105
+
106
+ `task package:register -- --apply` asks before each change, reads every value
107
+ at a hidden prompt and never prints one. It creates GitHub environments, sets
108
+ environment secrets, generates an RSA 4096 GPG signing key, uploads it to
109
+ keyserver.ubuntu.com and keys.openpgp.org, stores `SIGNING_KEY` and
110
+ `SIGNING_PASSWORD`, runs `npm login`, the first `npm publish` and
111
+ `npm trust github` (npm 11.15 or later, with 2FA on the account), and adds the
112
+ Maven namespace's DNS TXT record through Cloudflare (`CLOUDFLARE_API_TOKEN`)
113
+ or Azure DNS (`az`) when one of them serves the domain. Each step it cannot
114
+ take prints the page and the values to enter. It checks again after each
115
+ round, and a change already made is not offered again.
116
+
117
+ ## Releases
118
+
119
+ The Taskfiles are edited in the repository's `scripts/tasks/`. `bun run
120
+ sync` copies them to `tasks/`, which the package publishes, and a test
121
+ fails when the two differ. Both are committed, because release-please
122
+ releases this package only for commits under `packages/tasks/`.
64
123
 
65
124
  ## Licence
66
125
 
67
- MIT © Tobias Lekman
126
+ MIT
package/dist/build.js ADDED
@@ -0,0 +1,499 @@
1
+ // @bun
2
+ // bin/build.ts
3
+ import { resolve as resolve3 } from "path";
4
+ import { parseArgs } from "util";
5
+
6
+ // src/build/build.ts
7
+ class Build {
8
+ static run(plan, runner, print) {
9
+ for (const note of plan.notes)
10
+ print(note);
11
+ for (const step of plan.steps) {
12
+ print(`> ${step.label}: ${Build.describe(step.command, step.cwd)}`);
13
+ const code = runner.run(step);
14
+ if (code !== 0) {
15
+ print(`Build failed: ${step.label} exited with ${code}`);
16
+ return code;
17
+ }
18
+ }
19
+ return 0;
20
+ }
21
+ static describe(command, cwd) {
22
+ const line = command.map((arg) => /[\s*]/.test(arg) ? `'${arg}'` : arg).join(" ");
23
+ return cwd === "." ? line : `${line} (in ${cwd})`;
24
+ }
25
+ }
26
+ // src/build/build-commands.ts
27
+ var TURBO = {
28
+ bun: ["bun", "x", "turbo", "run", "build"],
29
+ npm: ["npx", "turbo", "run", "build"],
30
+ pnpm: ["pnpm", "exec", "turbo", "run", "build"],
31
+ yarn: ["yarn", "turbo", "run", "build"]
32
+ };
33
+ var PYTHON = {
34
+ pip: ["python", "-m", "build"],
35
+ pipenv: ["pipenv", "run", "python", "-m", "build"],
36
+ poetry: ["poetry", "build"],
37
+ uv: ["uv", "build"]
38
+ };
39
+
40
+ class BuildCommands {
41
+ static node(facts) {
42
+ const pm = facts.packageManager;
43
+ const found = `Node (${pm}${facts.turbo ? ", turbo" : ""})`;
44
+ const step = (command, how) => ({
45
+ note: `${found}: ${how}`,
46
+ step: { label: `Node: ${how}`, command, cwd: "." }
47
+ });
48
+ if (facts.turbo)
49
+ return step(TURBO[pm], "turbo run build");
50
+ if (facts.rootBuild)
51
+ return step([pm, "run", "build"], "the root build script");
52
+ if (facts.memberBuilds.length > 0) {
53
+ const how = `build in ${facts.memberBuilds.join(", ")}`;
54
+ return step(BuildCommands.workspaces(pm, facts.yarnBerry), how);
55
+ }
56
+ const where = facts.workspaces ? "package.json or any workspace" : "package.json";
57
+ return { note: `${found}: no build script in ${where}, nothing to build` };
58
+ }
59
+ static python(facts) {
60
+ const found = `Python (${facts.packageManager}) in ${facts.dir}`;
61
+ if (!facts.buildable) {
62
+ return {
63
+ note: `${found}: no [build-system] in pyproject.toml, nothing to build`
64
+ };
65
+ }
66
+ const command = PYTHON[facts.packageManager];
67
+ return {
68
+ note: `${found}: ${command.join(" ")}`,
69
+ step: { label: `Python: ${command.join(" ")}`, command, cwd: facts.dir }
70
+ };
71
+ }
72
+ static workspaces(pm, yarnBerry) {
73
+ switch (pm) {
74
+ case "bun":
75
+ return ["bun", "run", "--filter", "*", "build"];
76
+ case "npm":
77
+ return ["npm", "run", "build", "--workspaces", "--if-present"];
78
+ case "pnpm":
79
+ return ["pnpm", "-r", "--if-present", "run", "build"];
80
+ case "yarn":
81
+ return yarnBerry ? [
82
+ "yarn",
83
+ "workspaces",
84
+ "foreach",
85
+ "--all",
86
+ "--topological",
87
+ "run",
88
+ "build"
89
+ ] : ["yarn", "workspaces", "run", "build"];
90
+ }
91
+ }
92
+ }
93
+ // src/build/node-project.ts
94
+ var LOCKFILES = [
95
+ ["bun.lock", "bun"],
96
+ ["bun.lockb", "bun"],
97
+ ["pnpm-lock.yaml", "pnpm"],
98
+ ["yarn.lock", "yarn"],
99
+ ["package-lock.json", "npm"],
100
+ ["npm-shrinkwrap.json", "npm"]
101
+ ];
102
+ var MANAGERS = ["bun", "npm", "pnpm", "yarn"];
103
+
104
+ class NodeProject {
105
+ static facts(files) {
106
+ const root = NodeProject.manifest(files, "package.json");
107
+ if (!root)
108
+ return;
109
+ const declared = NodeProject.declaredManager(root.packageManager);
110
+ const locked = LOCKFILES.find(([file]) => files.exists(file))?.[1];
111
+ const packageManager = locked ?? declared?.name ?? "bun";
112
+ const patterns = NodeProject.workspacePatterns(files, root);
113
+ return {
114
+ packageManager,
115
+ yarnBerry: packageManager === "yarn" && (files.exists(".yarnrc.yml") || (declared?.major ?? 1) >= 2),
116
+ turbo: files.exists("turbo.json"),
117
+ rootBuild: NodeProject.hasBuild(root),
118
+ memberBuilds: patterns.flatMap((pattern) => files.folders(pattern)).filter((dir) => NodeProject.hasBuild(NodeProject.manifest(files, `${dir}/package.json`))).sort(),
119
+ workspaces: patterns.length > 0
120
+ };
121
+ }
122
+ static workspacePatterns(files, root) {
123
+ const declared = Array.isArray(root.workspaces) ? root.workspaces : NodeProject.packagesOf(root.workspaces);
124
+ const pnpm = NodeProject.pnpmPatterns(files.read("pnpm-workspace.yaml"));
125
+ return [...declared, ...pnpm].filter((p) => typeof p === "string" && !p.startsWith("!"));
126
+ }
127
+ static pnpmPatterns(text) {
128
+ if (!text)
129
+ return [];
130
+ const patterns = [];
131
+ let inPackages = false;
132
+ for (const line of text.split(`
133
+ `)) {
134
+ if (/^packages:\s*$/.test(line)) {
135
+ inPackages = true;
136
+ } else if (inPackages && /^\s*-\s*/.test(line)) {
137
+ patterns.push(line.replace(/^\s*-\s*/, "").replace(/['"]/g, "").trim());
138
+ } else if (inPackages && /^\S/.test(line)) {
139
+ inPackages = false;
140
+ }
141
+ }
142
+ return patterns;
143
+ }
144
+ static declaredManager(value) {
145
+ if (typeof value !== "string")
146
+ return;
147
+ const [name, version = ""] = value.split("@");
148
+ const manager = MANAGERS.find((m) => m === name);
149
+ if (!manager)
150
+ return;
151
+ return { major: Number.parseInt(version, 10) || 0, name: manager };
152
+ }
153
+ static hasBuild(manifest) {
154
+ return typeof manifest?.scripts?.build === "string";
155
+ }
156
+ static manifest(files, path) {
157
+ const text = files.read(path);
158
+ if (text === undefined)
159
+ return;
160
+ try {
161
+ return JSON.parse(text);
162
+ } catch {
163
+ return;
164
+ }
165
+ }
166
+ static packagesOf(value) {
167
+ if (typeof value !== "object" || value === null)
168
+ return [];
169
+ const packages = value.packages;
170
+ return Array.isArray(packages) ? packages : [];
171
+ }
172
+ }
173
+
174
+ // src/build/build-plan.ts
175
+ var LOOKED_FOR = [
176
+ "package.json (Bun, npm, pnpm or Yarn, with turbo.json, a build script or workspaces)",
177
+ "pyproject.toml or setup.py (pip, pipenv, Poetry or uv)"
178
+ ];
179
+
180
+ class BuildPlan {
181
+ static create(files, python, pythonDir = ".") {
182
+ const builds = [];
183
+ const node = NodeProject.facts(files);
184
+ if (node)
185
+ builds.push(BuildCommands.node(node));
186
+ const py = python.detect(pythonDir);
187
+ if (py)
188
+ builds.push(BuildCommands.python(py));
189
+ if (builds.length === 0) {
190
+ return {
191
+ steps: [],
192
+ notes: [`Nothing to build. Looked for: ${LOOKED_FOR.join("; ")}.`]
193
+ };
194
+ }
195
+ return {
196
+ steps: builds.flatMap((build) => build.step ? [build.step] : []),
197
+ notes: builds.map((build) => build.note)
198
+ };
199
+ }
200
+ }
201
+ // src/build/build.system.ts
202
+ import { spawnSync } from "child_process";
203
+ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
204
+ import { dirname, resolve as resolve2 } from "path";
205
+
206
+ // ../devops-toolkit/dist/language-detect.js
207
+ import { appendFileSync, existsSync, readFileSync } from "fs";
208
+ import { resolve } from "path";
209
+
210
+ // ../devops-toolkit/dist/toml-lite.js
211
+ var TABLE_HEADER = /^\[{1,2}\s*([^\]]+?)\s*\]{1,2}\s*$/;
212
+ var KEY_VALUE = /^([A-Za-z0-9_.-]+|"[^"]*"|'[^']*')\s*=\s*(.*)$/;
213
+ function parseToml(content) {
214
+ const tables = [];
215
+ const values = {};
216
+ let current = "";
217
+ for (const raw of content.split(`
218
+ `)) {
219
+ const line = stripComment(raw).trim();
220
+ if (line === "")
221
+ continue;
222
+ const header = line.match(TABLE_HEADER);
223
+ if (header) {
224
+ current = normaliseTablePath(header[1]);
225
+ if (!tables.includes(current))
226
+ tables.push(current);
227
+ continue;
228
+ }
229
+ const pair = line.match(KEY_VALUE);
230
+ if (!pair)
231
+ continue;
232
+ const value = readScalar(pair[2]);
233
+ if (value === null)
234
+ continue;
235
+ const key = unquote(pair[1]);
236
+ values[current ? `${current}.${key}` : key] = value;
237
+ }
238
+ return { tables, values };
239
+ }
240
+ function hasTable(doc, path) {
241
+ return doc.tables.some((t) => t === path || t.startsWith(`${path}.`));
242
+ }
243
+ function getString(doc, path) {
244
+ const raw = doc.values[path];
245
+ return raw === undefined ? undefined : unquote(raw);
246
+ }
247
+ function getBoolean(doc, path) {
248
+ const raw = doc.values[path];
249
+ if (raw === "true")
250
+ return true;
251
+ if (raw === "false")
252
+ return false;
253
+ return;
254
+ }
255
+ function stripComment(line) {
256
+ let quote = null;
257
+ for (let i = 0;i < line.length; i++) {
258
+ const ch = line[i];
259
+ if (quote) {
260
+ if (ch === quote)
261
+ quote = null;
262
+ continue;
263
+ }
264
+ if (ch === '"' || ch === "'") {
265
+ quote = ch;
266
+ continue;
267
+ }
268
+ if (ch === "#")
269
+ return line.slice(0, i);
270
+ }
271
+ return line;
272
+ }
273
+ function normaliseTablePath(path) {
274
+ return splitDotted(path).map((segment) => unquote(segment.trim())).join(".");
275
+ }
276
+ function splitDotted(path) {
277
+ const segments = [];
278
+ let current = "";
279
+ let quote = null;
280
+ for (const ch of path) {
281
+ if (quote) {
282
+ current += ch;
283
+ if (ch === quote)
284
+ quote = null;
285
+ continue;
286
+ }
287
+ if (ch === '"' || ch === "'") {
288
+ quote = ch;
289
+ current += ch;
290
+ continue;
291
+ }
292
+ if (ch === ".") {
293
+ segments.push(current);
294
+ current = "";
295
+ continue;
296
+ }
297
+ current += ch;
298
+ }
299
+ segments.push(current);
300
+ return segments;
301
+ }
302
+ function unquote(token) {
303
+ const first = token[0];
304
+ if ((first === '"' || first === "'") && token.endsWith(first)) {
305
+ return token.slice(1, -1);
306
+ }
307
+ return token;
308
+ }
309
+ function readScalar(raw) {
310
+ const value = raw.trim();
311
+ if (value === "")
312
+ return null;
313
+ if (value.startsWith("[") || value.startsWith("{"))
314
+ return null;
315
+ const first = value[0];
316
+ if (first === '"' || first === "'") {
317
+ const closing = value.indexOf(first, 1);
318
+ if (closing === -1)
319
+ return null;
320
+ return value.slice(0, closing + 1);
321
+ }
322
+ return value;
323
+ }
324
+
325
+ // ../devops-toolkit/dist/language-detect.js
326
+ var LANGUAGE_INDICATORS = [
327
+ ["package.json", "node"],
328
+ ["pyproject.toml", "python"],
329
+ ["setup.py", "python"]
330
+ ];
331
+ var PM_LOCKFILES = [
332
+ ["poetry.lock", "poetry"],
333
+ ["Pipfile.lock", "pipenv"],
334
+ ["uv.lock", "uv"]
335
+ ];
336
+ var LINT_TABLES = [
337
+ ["ruff", "tool.ruff"],
338
+ ["black", "tool.black"],
339
+ ["flake8", "tool.flake8"],
340
+ ["pylint", "tool.pylint"]
341
+ ];
342
+ function detect(root) {
343
+ const languages = [];
344
+ for (const [file, language] of LANGUAGE_INDICATORS) {
345
+ if (existsSync(resolve(root, file)) && !languages.includes(language)) {
346
+ languages.push(language);
347
+ }
348
+ }
349
+ const hasNode = languages.includes("node");
350
+ const hasPython = languages.includes("python");
351
+ return {
352
+ languages,
353
+ hasNode,
354
+ hasPython,
355
+ ...hasPython ? { python: detectPython(root) } : {}
356
+ };
357
+ }
358
+ function detectPython(root) {
359
+ const doc = readPyproject(root);
360
+ const lintTools = doc ? detectLintTools(doc) : [];
361
+ return {
362
+ packageManager: detectPackageManager(root, doc),
363
+ version: detectVersion(root, doc),
364
+ hasBuild: doc !== null && isBuildable(doc),
365
+ hasTest: hasTestSetup(root, doc),
366
+ hasLint: lintTools.length > 0,
367
+ hasTypecheck: doc !== null && hasTable(doc, "tool.mypy"),
368
+ lintTools
369
+ };
370
+ }
371
+ function detectPackageManager(root, doc) {
372
+ for (const [file, pm] of PM_LOCKFILES) {
373
+ if (existsSync(resolve(root, file)))
374
+ return pm;
375
+ }
376
+ if (doc) {
377
+ if (hasTable(doc, "tool.poetry"))
378
+ return "poetry";
379
+ if (hasTable(doc, "tool.uv"))
380
+ return "uv";
381
+ }
382
+ if (existsSync(resolve(root, "Pipfile")))
383
+ return "pipenv";
384
+ return "pip";
385
+ }
386
+ function detectVersion(root, doc) {
387
+ const versionFile = resolve(root, ".python-version");
388
+ if (existsSync(versionFile)) {
389
+ try {
390
+ const first = readFileSync(versionFile, "utf8").split(`
391
+ `)[0].trim();
392
+ if (first)
393
+ return first;
394
+ } catch {}
395
+ }
396
+ const requires = doc ? getString(doc, "project.requires-python") : undefined;
397
+ return requires ? normaliseRequiresPython(requires) : "";
398
+ }
399
+ function normaliseRequiresPython(specifier) {
400
+ for (const clause of specifier.split(",")) {
401
+ const match = clause.trim().match(/^(>=|~=|==|>)?\s*(\d+(?:\.\d+)*)/);
402
+ if (match)
403
+ return match[2];
404
+ }
405
+ return "";
406
+ }
407
+ function isBuildable(doc) {
408
+ if (!hasTable(doc, "build-system"))
409
+ return false;
410
+ return getBoolean(doc, "tool.poetry.package-mode") !== false;
411
+ }
412
+ function hasTestSetup(root, doc) {
413
+ if (doc && hasTable(doc, "tool.pytest"))
414
+ return true;
415
+ return existsSync(resolve(root, "tests"));
416
+ }
417
+ function detectLintTools(doc) {
418
+ return LINT_TABLES.filter(([, table]) => hasTable(doc, table)).map(([tool]) => tool);
419
+ }
420
+ function readPyproject(root) {
421
+ const path = resolve(root, "pyproject.toml");
422
+ if (!existsSync(path))
423
+ return null;
424
+ try {
425
+ return parseToml(readFileSync(path, "utf8"));
426
+ } catch {
427
+ return null;
428
+ }
429
+ }
430
+ if (false) {}
431
+
432
+ // src/build/build.system.ts
433
+ class DiskProjectFiles {
434
+ root;
435
+ constructor(root) {
436
+ this.root = root;
437
+ }
438
+ exists(path) {
439
+ return existsSync2(resolve2(this.root, path));
440
+ }
441
+ folders(pattern) {
442
+ const glob = new Bun.Glob(`${pattern.replace(/\/$/, "")}/package.json`);
443
+ return [...glob.scanSync({ cwd: this.root, onlyFiles: true })].filter((path) => !path.split("/").includes("node_modules")).map((path) => dirname(path));
444
+ }
445
+ read(path) {
446
+ const file = resolve2(this.root, path);
447
+ return existsSync2(file) ? readFileSync2(file, "utf8") : undefined;
448
+ }
449
+ }
450
+
451
+ class ToolkitPythonDetector {
452
+ root;
453
+ constructor(root) {
454
+ this.root = root;
455
+ }
456
+ detect(dir) {
457
+ const result = detect(resolve2(this.root, dir));
458
+ if (!result.python)
459
+ return;
460
+ return {
461
+ dir,
462
+ packageManager: result.python.packageManager,
463
+ buildable: result.python.hasBuild
464
+ };
465
+ }
466
+ }
467
+
468
+ class ProcessRunner {
469
+ root;
470
+ constructor(root) {
471
+ this.root = root;
472
+ }
473
+ run(step) {
474
+ const [program, ...args] = step.command;
475
+ const result = spawnSync(program, args, {
476
+ cwd: resolve2(this.root, step.cwd),
477
+ stdio: "inherit"
478
+ });
479
+ if (result.error) {
480
+ process.stderr.write(`${program}: ${result.error.message}
481
+ `);
482
+ return 127;
483
+ }
484
+ return result.status ?? 1;
485
+ }
486
+ }
487
+ // bin/build.ts
488
+ var { values } = parseArgs({
489
+ options: {
490
+ dir: { type: "string" },
491
+ "dry-run": { type: "boolean", default: false },
492
+ "python-dir": { type: "string" }
493
+ }
494
+ });
495
+ var root = resolve3(values.dir ?? process.cwd());
496
+ var plan = BuildPlan.create(new DiskProjectFiles(root), new ToolkitPythonDetector(root), values["python-dir"] || ".");
497
+ var runner = values["dry-run"] ? { run: () => 0 } : new ProcessRunner(root);
498
+ process.exitCode = Build.run(plan, runner, (line) => process.stdout.write(`${line}
499
+ `));