@eserstack/codebase 0.0.0-stage → 5.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/README.md +301 -2
- package/dist/changelog-gen.d.ts +105 -0
- package/dist/changelog-gen.js +498 -0
- package/dist/changelog-text.d.ts +39 -0
- package/dist/changelog-text.js +82 -0
- package/dist/cli-support.d.ts +140 -0
- package/dist/cli-support.js +244 -0
- package/dist/cli-system/app-opts.d.ts +15 -0
- package/dist/cli-system/app-opts.js +13 -0
- package/dist/cli-system/app.d.ts +29 -0
- package/dist/cli-system/app.js +12 -0
- package/dist/cli-system/handlers/completions-setup.d.ts +14 -0
- package/dist/cli-system/handlers/completions-setup.js +139 -0
- package/dist/cli-system/handlers/completions.d.ts +3 -0
- package/dist/cli-system/handlers/completions.js +79 -0
- package/dist/cli-system/handlers/doctor.d.ts +8 -0
- package/dist/cli-system/handlers/doctor.js +146 -0
- package/dist/cli-system/handlers/info.d.ts +3 -0
- package/dist/cli-system/handlers/info.js +69 -0
- package/dist/cli-system/handlers/install.d.ts +8 -0
- package/dist/cli-system/handlers/install.js +137 -0
- package/dist/cli-system/handlers/mod.d.ts +12 -0
- package/dist/cli-system/handlers/mod.js +13 -0
- package/dist/cli-system/handlers/uninstall.d.ts +3 -0
- package/dist/cli-system/handlers/uninstall.js +60 -0
- package/dist/cli-system/handlers/update.d.ts +76 -0
- package/dist/cli-system/handlers/update.js +310 -0
- package/dist/cli-system/handlers/version-check.d.ts +16 -0
- package/dist/cli-system/handlers/version-check.js +176 -0
- package/dist/cli-system/handlers/version.d.ts +3 -0
- package/dist/cli-system/handlers/version.js +45 -0
- package/dist/cli-system/mod.d.ts +19 -0
- package/dist/cli-system/mod.js +52 -0
- package/dist/commitmsg.d.ts +28 -0
- package/dist/commitmsg.js +232 -0
- package/dist/directive-analysis.d.ts +75 -0
- package/dist/directive-analysis.js +223 -0
- package/dist/ffi-client.d.ts +11 -0
- package/dist/ffi-client.js +12 -0
- package/dist/file-tool.d.ts +96 -0
- package/dist/file-tool.js +274 -0
- package/dist/file-tools-shared.d.ts +81 -0
- package/dist/file-tools-shared.js +276 -0
- package/dist/gh-contributors.d.ts +89 -0
- package/dist/gh-contributors.js +205 -0
- package/dist/gh.d.ts +3 -0
- package/dist/gh.js +64 -0
- package/dist/git-listing.d.ts +27 -0
- package/dist/git-listing.js +69 -0
- package/dist/git.d.ts +172 -0
- package/dist/git.js +277 -0
- package/dist/install.d.ts +34 -0
- package/dist/install.js +421 -0
- package/dist/main.d.ts +22 -0
- package/dist/main.js +14 -0
- package/dist/mod.d.ts +25 -0
- package/dist/mod.js +8 -0
- package/dist/module.d.ts +10 -0
- package/dist/module.js +221 -0
- package/dist/native-functions.d.ts +1088 -0
- package/dist/native-functions.js +2 -0
- package/dist/npm-externals.d.ts +27 -0
- package/dist/npm-externals.js +34 -0
- package/dist/npm-workspace-specifiers.d.ts +6 -0
- package/dist/npm-workspace-specifiers.js +45 -0
- package/dist/package/loader.d.ts +34 -0
- package/dist/package/loader.js +203 -0
- package/dist/package/mod.d.ts +36 -0
- package/dist/package/mod.js +5 -0
- package/dist/package/types.d.ts +142 -0
- package/dist/package/types.js +32 -0
- package/dist/package/workspace.d.ts +33 -0
- package/dist/package/workspace.js +158 -0
- package/dist/package/writer.d.ts +52 -0
- package/dist/package/writer.js +278 -0
- package/dist/package.json +275 -0
- package/dist/release-notes.d.ts +90 -0
- package/dist/release-notes.js +236 -0
- package/dist/release-tag.d.ts +46 -0
- package/dist/release-tag.js +95 -0
- package/dist/release.d.ts +145 -0
- package/dist/release.js +584 -0
- package/dist/source-mask.d.ts +3 -0
- package/dist/source-mask.js +185 -0
- package/dist/validate-bom.d.ts +5 -0
- package/dist/validate-bom.js +43 -0
- package/dist/validate-case-conflict.d.ts +5 -0
- package/dist/validate-case-conflict.js +43 -0
- package/dist/validate-circular-deps.d.ts +11 -0
- package/dist/validate-circular-deps.js +53 -0
- package/dist/validate-code-conventions.d.ts +22 -0
- package/dist/validate-code-conventions.js +166 -0
- package/dist/validate-commit-msg.d.ts +50 -0
- package/dist/validate-commit-msg.js +182 -0
- package/dist/validate-docs.d.ts +20 -0
- package/dist/validate-docs.js +78 -0
- package/dist/validate-eof.d.ts +5 -0
- package/dist/validate-eof.js +61 -0
- package/dist/validate-error-coverage.d.ts +28 -0
- package/dist/validate-error-coverage.js +93 -0
- package/dist/validate-export-names.d.ts +17 -0
- package/dist/validate-export-names.js +56 -0
- package/dist/validate-filenames.d.ts +5 -0
- package/dist/validate-filenames.js +151 -0
- package/dist/validate-json.d.ts +5 -0
- package/dist/validate-json.js +71 -0
- package/dist/validate-large-files.d.ts +5 -0
- package/dist/validate-large-files.js +41 -0
- package/dist/validate-laroux-boundaries.d.ts +19 -0
- package/dist/validate-laroux-boundaries.js +59 -0
- package/dist/validate-licenses.d.ts +5 -0
- package/dist/validate-licenses.js +137 -0
- package/dist/validate-line-endings.d.ts +5 -0
- package/dist/validate-line-endings.js +47 -0
- package/dist/validate-merge-conflict.d.ts +5 -0
- package/dist/validate-merge-conflict.js +46 -0
- package/dist/validate-mod-exports.d.ts +16 -0
- package/dist/validate-mod-exports.js +56 -0
- package/dist/validate-naming-and-todos.d.ts +5 -0
- package/dist/validate-naming-and-todos.js +70 -0
- package/dist/validate-runtime-js-apis.d.ts +5 -0
- package/dist/validate-runtime-js-apis.js +78 -0
- package/dist/validate-secrets.d.ts +5 -0
- package/dist/validate-secrets.js +82 -0
- package/dist/validate-self-imports.d.ts +5 -0
- package/dist/validate-self-imports.js +78 -0
- package/dist/validate-server-loc.d.ts +32 -0
- package/dist/validate-server-loc.js +94 -0
- package/dist/validate-shebangs.d.ts +5 -0
- package/dist/validate-shebangs.js +33 -0
- package/dist/validate-stream.d.ts +25 -0
- package/dist/validate-stream.js +62 -0
- package/dist/validate-submodules.d.ts +5 -0
- package/dist/validate-submodules.js +43 -0
- package/dist/validate-symlinks.d.ts +5 -0
- package/dist/validate-symlinks.js +46 -0
- package/dist/validate-toml.d.ts +5 -0
- package/dist/validate-toml.js +40 -0
- package/dist/validate-trailing-whitespace.d.ts +5 -0
- package/dist/validate-trailing-whitespace.js +49 -0
- package/dist/validate-yaml.d.ts +5 -0
- package/dist/validate-yaml.js +40 -0
- package/dist/validation/config.d.ts +17 -0
- package/dist/validation/config.js +30 -0
- package/dist/validation/mod.d.ts +71 -0
- package/dist/validation/mod.js +479 -0
- package/dist/validation/registry.d.ts +57 -0
- package/dist/validation/registry.js +256 -0
- package/dist/validation/types.d.ts +101 -0
- package/dist/validation/types.js +2 -0
- package/dist/validation/validators/circular-deps.d.ts +7 -0
- package/dist/validation/validators/circular-deps.js +31 -0
- package/dist/validation/validators/docs.d.ts +7 -0
- package/dist/validation/validators/docs.js +38 -0
- package/dist/validation/validators/error-coverage.d.ts +2 -0
- package/dist/validation/validators/error-coverage.js +46 -0
- package/dist/validation/validators/export-names.d.ts +7 -0
- package/dist/validation/validators/export-names.js +31 -0
- package/dist/validation/validators/laroux-boundaries.d.ts +2 -0
- package/dist/validation/validators/laroux-boundaries.js +29 -0
- package/dist/validation/validators/mod-exports.d.ts +7 -0
- package/dist/validation/validators/mod-exports.js +32 -0
- package/dist/validation/validators/mod.d.ts +11 -0
- package/dist/validation/validators/mod.js +12 -0
- package/dist/validation/validators/server-loc.d.ts +2 -0
- package/dist/validation/validators/server-loc.js +48 -0
- package/dist/versions.d.ts +166 -0
- package/dist/versions.js +349 -0
- package/dist/violation-baseline.d.ts +58 -0
- package/dist/violation-baseline.js +144 -0
- package/dist/walk-stream.d.ts +24 -0
- package/dist/walk-stream.js +55 -0
- package/dist/workspace-discovery.d.ts +60 -0
- package/dist/workspace-discovery.js +130 -0
- package/package.json +222 -3
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Server LOC ceiling validator
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import * as validateServerLoc from "../../validate-server-loc.js";
|
|
8
|
+
export const serverLocValidator = {
|
|
9
|
+
name: "validate-server-loc",
|
|
10
|
+
description: "Fail if any non-test file in a directory exceeds the line ceiling",
|
|
11
|
+
requiredStacks: ["golang"],
|
|
12
|
+
validate: async (options) => {
|
|
13
|
+
const directory = options.options?.["directory"];
|
|
14
|
+
if (directory === undefined || directory === "") {
|
|
15
|
+
return {
|
|
16
|
+
name: "validate-server-loc",
|
|
17
|
+
passed: false,
|
|
18
|
+
issues: [
|
|
19
|
+
{
|
|
20
|
+
severity: "error",
|
|
21
|
+
message: "validate-server-loc requires a `directory` parameter",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
stats: { checked: 0, violations: 0 },
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const maxLines = options.options?.["maxLines"];
|
|
28
|
+
const excludeSuffix = options.options?.["excludeSuffix"];
|
|
29
|
+
const extension = options.options?.["extension"];
|
|
30
|
+
const result = await validateServerLoc.checkServerLoc({
|
|
31
|
+
root: options.root,
|
|
32
|
+
directory,
|
|
33
|
+
maxLines,
|
|
34
|
+
excludeSuffix,
|
|
35
|
+
extension,
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
name: "validate-server-loc",
|
|
39
|
+
passed: result.passed,
|
|
40
|
+
issues: result.violations.map((v) => ({
|
|
41
|
+
severity: "error",
|
|
42
|
+
file: v.path,
|
|
43
|
+
message: `${v.lines} lines (limit ${maxLines ?? 500})`,
|
|
44
|
+
})),
|
|
45
|
+
stats: { checked: result.checked, violations: result.violations.length },
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import * as functions from "@eserstack/functions";
|
|
2
|
+
import type * as shellArgs from "@eserstack/shell/args";
|
|
3
|
+
/**
|
|
4
|
+
* Valid version commands.
|
|
5
|
+
*/
|
|
6
|
+
export type VersionCommand = "sync" | "patch" | "minor" | "major" | "explicit";
|
|
7
|
+
/**
|
|
8
|
+
* Options for version operations.
|
|
9
|
+
*/
|
|
10
|
+
export type VersionOptions = {
|
|
11
|
+
/** Root directory (default: ".") */
|
|
12
|
+
readonly root?: string;
|
|
13
|
+
/** Preview changes without applying */
|
|
14
|
+
readonly dryRun?: boolean;
|
|
15
|
+
/** Update the VERSION file in root (default: true) */
|
|
16
|
+
readonly updateVersionFile?: boolean;
|
|
17
|
+
/** Explicit version string (used when command is "explicit") */
|
|
18
|
+
readonly explicitVersion?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Information about a package version.
|
|
22
|
+
*/
|
|
23
|
+
export type PackageVersion = {
|
|
24
|
+
/** Package name */
|
|
25
|
+
readonly name: string;
|
|
26
|
+
/** Package version */
|
|
27
|
+
readonly version: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Update information for a single package.
|
|
31
|
+
*/
|
|
32
|
+
export type VersionUpdate = {
|
|
33
|
+
/** Package name */
|
|
34
|
+
readonly name: string;
|
|
35
|
+
/** Version before update */
|
|
36
|
+
readonly from: string;
|
|
37
|
+
/** Version after update */
|
|
38
|
+
readonly to: string;
|
|
39
|
+
/** Whether the package was updated */
|
|
40
|
+
readonly changed: boolean;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Result of showing versions.
|
|
44
|
+
*/
|
|
45
|
+
export type ShowVersionsResult = {
|
|
46
|
+
/** All packages with their versions */
|
|
47
|
+
readonly packages: PackageVersion[];
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Update information for a standalone file (e.g., VERSION).
|
|
51
|
+
*/
|
|
52
|
+
export type FileUpdate = {
|
|
53
|
+
/** File path relative to root */
|
|
54
|
+
readonly path: string;
|
|
55
|
+
/** Version before update */
|
|
56
|
+
readonly from: string;
|
|
57
|
+
/** Version after update */
|
|
58
|
+
readonly to: string;
|
|
59
|
+
/** Whether the file was updated */
|
|
60
|
+
readonly changed: boolean;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Result of a version operation.
|
|
64
|
+
*/
|
|
65
|
+
export type VersionsResult = {
|
|
66
|
+
/** Command that was executed */
|
|
67
|
+
readonly command: VersionCommand;
|
|
68
|
+
/** Target version */
|
|
69
|
+
readonly targetVersion: string;
|
|
70
|
+
/** All package updates */
|
|
71
|
+
readonly updates: VersionUpdate[];
|
|
72
|
+
/** Standalone file updates (e.g., VERSION file) */
|
|
73
|
+
readonly fileUpdates: FileUpdate[];
|
|
74
|
+
/** Number of packages that changed */
|
|
75
|
+
readonly changedCount: number;
|
|
76
|
+
/** Whether this was a dry run */
|
|
77
|
+
readonly dryRun: boolean;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* A package config file that a version bump could not write.
|
|
81
|
+
*/
|
|
82
|
+
export type VersionWriteFailure = {
|
|
83
|
+
/** Path of the file that was not written */
|
|
84
|
+
readonly filepath: string;
|
|
85
|
+
/** Why the write failed */
|
|
86
|
+
readonly reason: string;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Thrown by {@link versions} when one or more package config files could not
|
|
90
|
+
* be written.
|
|
91
|
+
*
|
|
92
|
+
* Every package is still attempted, so `failures` lists all of them. The
|
|
93
|
+
* VERSION file is left unchanged, so it still names the previous version.
|
|
94
|
+
*/
|
|
95
|
+
export declare class VersionWriteError extends Error {
|
|
96
|
+
/** The version the bump was writing */
|
|
97
|
+
readonly targetVersion: string;
|
|
98
|
+
/** Every file that was not written, with the reason */
|
|
99
|
+
readonly failures: readonly VersionWriteFailure[];
|
|
100
|
+
constructor(targetVersion: string, failures: readonly VersionWriteFailure[]);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Reads the current version from the VERSION file.
|
|
104
|
+
*
|
|
105
|
+
* @param options - Options with root directory
|
|
106
|
+
* @returns The version string, or undefined if the file doesn't exist
|
|
107
|
+
*/
|
|
108
|
+
export declare const readVersionFile: (options?: VersionOptions) => Promise<string | undefined>;
|
|
109
|
+
/**
|
|
110
|
+
* Purely calculates the next version from a current version and a command.
|
|
111
|
+
* Runs on the Go FFI.
|
|
112
|
+
*
|
|
113
|
+
* @param current - The current semver version string
|
|
114
|
+
* @param command - The bump command: "patch" | "minor" | "major" | "explicit" | "sync"
|
|
115
|
+
* @param explicit - Required when command is "explicit"
|
|
116
|
+
* @returns The resulting version string
|
|
117
|
+
*/
|
|
118
|
+
export declare const bumpVersion: (current: string, command: VersionCommand, explicit?: string) => Promise<string>;
|
|
119
|
+
/**
|
|
120
|
+
* Shows all package versions in the workspace.
|
|
121
|
+
*
|
|
122
|
+
* @param options - Options for the operation
|
|
123
|
+
* @returns Result with package versions
|
|
124
|
+
*/
|
|
125
|
+
export declare const showVersions: (options?: VersionOptions) => Promise<ShowVersionsResult>;
|
|
126
|
+
/**
|
|
127
|
+
* Executes a version command (sync, patch, minor, major).
|
|
128
|
+
*
|
|
129
|
+
* @param command - The command to execute
|
|
130
|
+
* @param options - Options for the operation
|
|
131
|
+
* @returns Result of the operation
|
|
132
|
+
* @throws {VersionWriteError} When a package config file could not be written
|
|
133
|
+
*/
|
|
134
|
+
export declare const versions: (command: VersionCommand, options?: VersionOptions) => Promise<VersionsResult>;
|
|
135
|
+
/**
|
|
136
|
+
* Discriminated input for the versions functions.handler.
|
|
137
|
+
*/
|
|
138
|
+
export type VersionsInput = {
|
|
139
|
+
readonly mode: "show";
|
|
140
|
+
} | {
|
|
141
|
+
readonly mode: "update";
|
|
142
|
+
readonly command: VersionCommand;
|
|
143
|
+
readonly options: VersionOptions;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Discriminated output from the versions functions.handler.
|
|
147
|
+
*/
|
|
148
|
+
export type VersionsOutput = {
|
|
149
|
+
readonly mode: "show";
|
|
150
|
+
readonly result: ShowVersionsResult;
|
|
151
|
+
} | {
|
|
152
|
+
readonly mode: "update";
|
|
153
|
+
readonly result: VersionsResult;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Core handler — wraps existing library functions using `fromPromise`.
|
|
157
|
+
*/
|
|
158
|
+
export declare const versionsHandler: functions.handler.Handler<VersionsInput, VersionsOutput, Error>;
|
|
159
|
+
/**
|
|
160
|
+
* CLI trigger — wired handler for command-line invocation.
|
|
161
|
+
*/
|
|
162
|
+
export declare const handleCli: (event: functions.triggers.CliEvent) => Promise<shellArgs.CliResult<void>>;
|
|
163
|
+
/** Parse the versions arguments: the command and `--dry-run`. */
|
|
164
|
+
export declare const parseCliArgs: (cliArgs?: readonly string[]) => functions.triggers.CliEvent;
|
|
165
|
+
/** CLI entry point for dispatcher compatibility. */
|
|
166
|
+
export declare const main: (cliArgs?: readonly string[]) => Promise<shellArgs.CliResult<void>>;
|
package/dist/versions.js
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Workspace version management tool. It syncs the VERSION file and every
|
|
4
|
+
* package.json in the workspace.
|
|
5
|
+
*
|
|
6
|
+
* Can be used as a library or as a standalone script.
|
|
7
|
+
*
|
|
8
|
+
* Library usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import * as versions from "@eserstack/codebase/versions";
|
|
11
|
+
*
|
|
12
|
+
* // Show versions
|
|
13
|
+
* const result = await versions.showVersions();
|
|
14
|
+
* console.log(result.packages);
|
|
15
|
+
*
|
|
16
|
+
* // Sync versions
|
|
17
|
+
* const syncResult = await versions.versions("sync", { dryRun: true });
|
|
18
|
+
* console.log(syncResult.updates);
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* CLI usage:
|
|
22
|
+
* node ./versions.ts # Show versions table
|
|
23
|
+
* node ./versions.ts sync # Sync all to highest version
|
|
24
|
+
* node ./versions.ts patch # Bump patch, sync all
|
|
25
|
+
* node ./versions.ts minor # Bump minor, sync all
|
|
26
|
+
* node ./versions.ts major # Bump major, sync all
|
|
27
|
+
* node ./versions.ts --dry-run # Preview without changes
|
|
28
|
+
*
|
|
29
|
+
* @module
|
|
30
|
+
*/
|
|
31
|
+
import * as semver from "semver";
|
|
32
|
+
import * as primitives from "@eserstack/primitives";
|
|
33
|
+
import * as standards from "@eserstack/standards";
|
|
34
|
+
import * as functions from "@eserstack/functions";
|
|
35
|
+
import * as tui from "@eserstack/shell/tui";
|
|
36
|
+
import * as span from "@eserstack/streams/span";
|
|
37
|
+
import * as cliSupport from "./cli-support.js";
|
|
38
|
+
import * as pkg from "./package/mod.js";
|
|
39
|
+
import * as ffiClient from "./ffi-client.js";
|
|
40
|
+
/**
|
|
41
|
+
* Thrown by {@link versions} when one or more package config files could not
|
|
42
|
+
* be written.
|
|
43
|
+
*
|
|
44
|
+
* Every package is still attempted, so `failures` lists all of them. The
|
|
45
|
+
* VERSION file is left unchanged, so it still names the previous version.
|
|
46
|
+
*/
|
|
47
|
+
export class VersionWriteError extends Error {
|
|
48
|
+
/** The version the bump was writing */
|
|
49
|
+
targetVersion;
|
|
50
|
+
/** Every file that was not written, with the reason */
|
|
51
|
+
failures;
|
|
52
|
+
constructor(targetVersion, failures) {
|
|
53
|
+
const message = [
|
|
54
|
+
`bump versions to ${targetVersion}: could not write ${failures.length} package file(s):`,
|
|
55
|
+
...failures.map((failure) => ` ${failure.filepath}: ${failure.reason}`),
|
|
56
|
+
`Every other file was written and VERSION was left unchanged. Fix the files above, then run "eser codebase versions ${targetVersion}" to finish the bump.`,
|
|
57
|
+
].join("\n");
|
|
58
|
+
super(message);
|
|
59
|
+
this.name = "VersionWriteError";
|
|
60
|
+
this.targetVersion = targetVersion;
|
|
61
|
+
this.failures = failures;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Reads the current version from the VERSION file.
|
|
66
|
+
*
|
|
67
|
+
* @param options - Options with root directory
|
|
68
|
+
* @returns The version string, or undefined if the file doesn't exist
|
|
69
|
+
*/
|
|
70
|
+
export const readVersionFile = async (options = {}) => {
|
|
71
|
+
const { root = "." } = options;
|
|
72
|
+
const versionFilePath = standards.crossRuntime.runtime.path.join(root, "VERSION");
|
|
73
|
+
try {
|
|
74
|
+
const content = await standards.crossRuntime.runtime.fs.readTextFile(versionFilePath);
|
|
75
|
+
return content.trim();
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Purely calculates the next version from a current version and a command.
|
|
83
|
+
* Runs on the Go FFI.
|
|
84
|
+
*
|
|
85
|
+
* @param current - The current semver version string
|
|
86
|
+
* @param command - The bump command: "patch" | "minor" | "major" | "explicit" | "sync"
|
|
87
|
+
* @param explicit - Required when command is "explicit"
|
|
88
|
+
* @returns The resulting version string
|
|
89
|
+
*/
|
|
90
|
+
export const bumpVersion = async (current, command, explicit) => {
|
|
91
|
+
const lib = await ffiClient.requireLib();
|
|
92
|
+
const parsed = lib.call("codebaseBumpVersion", {
|
|
93
|
+
current,
|
|
94
|
+
command,
|
|
95
|
+
explicit,
|
|
96
|
+
});
|
|
97
|
+
if (parsed.error !== undefined) {
|
|
98
|
+
throw new Error(parsed.error);
|
|
99
|
+
}
|
|
100
|
+
if (parsed.version === undefined) {
|
|
101
|
+
throw new Error("bumpVersion: FFI returned no version");
|
|
102
|
+
}
|
|
103
|
+
return parsed.version;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Writes a version string to the VERSION file.
|
|
107
|
+
*/
|
|
108
|
+
const writeVersionFile = async (root, version) => {
|
|
109
|
+
const versionFilePath = standards.crossRuntime.runtime.path.join(root, "VERSION");
|
|
110
|
+
await standards.crossRuntime.runtime.fs.writeTextFile(versionFilePath, version + "\n");
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Finds the highest version from an array of version strings.
|
|
114
|
+
*/
|
|
115
|
+
const findHighestVersion = (versions) => {
|
|
116
|
+
let highest = new semver.SemVer("0.0.0");
|
|
117
|
+
for (const version of versions) {
|
|
118
|
+
const v = new semver.SemVer(version);
|
|
119
|
+
if (semver.compare(v, highest) > 0) {
|
|
120
|
+
highest = v;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return highest.format();
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Shows all package versions in the workspace.
|
|
127
|
+
*
|
|
128
|
+
* @param options - Options for the operation
|
|
129
|
+
* @returns Result with package versions
|
|
130
|
+
*/
|
|
131
|
+
export const showVersions = async (options = {}) => {
|
|
132
|
+
const { root = "." } = options;
|
|
133
|
+
const [rootConfig, modules] = await pkg.getWorkspaceModules(root);
|
|
134
|
+
const rootVersion = rootConfig.version?.value ?? "0.0.0";
|
|
135
|
+
const rootName = rootConfig.name?.value ?? "(root)";
|
|
136
|
+
const packages = [
|
|
137
|
+
{ name: rootName, version: rootVersion },
|
|
138
|
+
...modules.map((m) => ({ name: m.name, version: m.version })),
|
|
139
|
+
];
|
|
140
|
+
return { packages };
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Executes a version command (sync, patch, minor, major).
|
|
144
|
+
*
|
|
145
|
+
* @param command - The command to execute
|
|
146
|
+
* @param options - Options for the operation
|
|
147
|
+
* @returns Result of the operation
|
|
148
|
+
* @throws {VersionWriteError} When a package config file could not be written
|
|
149
|
+
*/
|
|
150
|
+
export const versions = async (command, options = {}) => {
|
|
151
|
+
const { root = ".", dryRun = false, updateVersionFile: shouldUpdateVersionFile = true, } = options;
|
|
152
|
+
const [rootConfig, modules] = await pkg.getWorkspaceModules(root);
|
|
153
|
+
const rootVersion = rootConfig.version?.value ?? "0.0.0";
|
|
154
|
+
const rootName = rootConfig.name?.value ?? "(root)";
|
|
155
|
+
// Calculate target version
|
|
156
|
+
const allVersions = [rootVersion, ...modules.map((m) => m.version)];
|
|
157
|
+
const highestVersion = findHighestVersion(allVersions);
|
|
158
|
+
let targetVersion;
|
|
159
|
+
if (command === "explicit") {
|
|
160
|
+
if (options.explicitVersion === undefined) {
|
|
161
|
+
throw new Error('explicitVersion is required when command is "explicit".');
|
|
162
|
+
}
|
|
163
|
+
if (semver.valid(options.explicitVersion) === null) {
|
|
164
|
+
throw new TypeError(`Cannot parse version: ${options.explicitVersion}`);
|
|
165
|
+
}
|
|
166
|
+
targetVersion = options.explicitVersion;
|
|
167
|
+
}
|
|
168
|
+
else if (command === "sync") {
|
|
169
|
+
targetVersion = highestVersion;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
targetVersion = new semver.SemVer(highestVersion)
|
|
173
|
+
.inc(command)
|
|
174
|
+
.format();
|
|
175
|
+
}
|
|
176
|
+
// Apply package updates (including root)
|
|
177
|
+
const updates = [];
|
|
178
|
+
const failures = [];
|
|
179
|
+
// Update root config
|
|
180
|
+
const rootNeedsUpdate = rootVersion !== targetVersion;
|
|
181
|
+
if (!dryRun) {
|
|
182
|
+
const rootResult = await pkg.updateVersion(rootConfig, targetVersion);
|
|
183
|
+
failures.push(...rootResult.failed);
|
|
184
|
+
}
|
|
185
|
+
updates.push({
|
|
186
|
+
name: rootName,
|
|
187
|
+
from: rootVersion,
|
|
188
|
+
to: targetVersion,
|
|
189
|
+
changed: rootNeedsUpdate,
|
|
190
|
+
});
|
|
191
|
+
// Update workspace modules
|
|
192
|
+
for (const module of modules) {
|
|
193
|
+
const needsUpdate = module.version !== targetVersion;
|
|
194
|
+
if (!dryRun) {
|
|
195
|
+
// Packages are bumped one at a time to bound open file handles in a
|
|
196
|
+
// large workspace.
|
|
197
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
198
|
+
const moduleResult = await pkg.updateVersion(module.config, targetVersion);
|
|
199
|
+
failures.push(...moduleResult.failed);
|
|
200
|
+
}
|
|
201
|
+
updates.push({
|
|
202
|
+
name: module.name,
|
|
203
|
+
from: module.version,
|
|
204
|
+
to: targetVersion,
|
|
205
|
+
changed: needsUpdate,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
// The @eserstack/ajan-* platform packages are workspace members since
|
|
209
|
+
// TASK-8, so the loop above already stamped them; cli and ajan reference
|
|
210
|
+
// them with workspace:*, which needs no rewriting.
|
|
211
|
+
// A partial bump must not look complete. VERSION is written last, so it
|
|
212
|
+
// keeps the previous version until every package file has the new one.
|
|
213
|
+
if (failures.length > 0) {
|
|
214
|
+
throw new VersionWriteError(targetVersion, failures);
|
|
215
|
+
}
|
|
216
|
+
// Update VERSION file
|
|
217
|
+
const fileUpdates = [];
|
|
218
|
+
if (shouldUpdateVersionFile) {
|
|
219
|
+
const currentFileVersion = await readVersionFile({ root });
|
|
220
|
+
const fileChanged = currentFileVersion !== targetVersion;
|
|
221
|
+
if (!dryRun && fileChanged) {
|
|
222
|
+
await writeVersionFile(root, targetVersion);
|
|
223
|
+
}
|
|
224
|
+
fileUpdates.push({
|
|
225
|
+
path: "VERSION",
|
|
226
|
+
from: currentFileVersion ?? "",
|
|
227
|
+
to: targetVersion,
|
|
228
|
+
changed: fileChanged,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
const changedCount = updates.filter((u) => u.changed).length;
|
|
232
|
+
return {
|
|
233
|
+
command,
|
|
234
|
+
targetVersion,
|
|
235
|
+
updates,
|
|
236
|
+
fileUpdates,
|
|
237
|
+
changedCount,
|
|
238
|
+
dryRun,
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Core handler — wraps existing library functions using `fromPromise`.
|
|
243
|
+
*/
|
|
244
|
+
export const versionsHandler = (input) => {
|
|
245
|
+
if (input.mode === "show") {
|
|
246
|
+
return functions.task.fromPromise(async () => {
|
|
247
|
+
const result = await showVersions();
|
|
248
|
+
return { mode: "show", result };
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
return functions.task.fromPromise(async () => {
|
|
252
|
+
const result = await versions(input.command, input.options);
|
|
253
|
+
return { mode: "update", result };
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* CLI Adapter — converts a `functions.triggers.CliEvent` into `VersionsInput`.
|
|
258
|
+
*/
|
|
259
|
+
const cliAdapter = (event) => {
|
|
260
|
+
const arg = event.args[0];
|
|
261
|
+
// No args → show mode
|
|
262
|
+
if (arg === undefined) {
|
|
263
|
+
return primitives.results.ok({ mode: "show" });
|
|
264
|
+
}
|
|
265
|
+
// Has arg → update mode
|
|
266
|
+
const validCommands = ["sync", "patch", "minor", "major"];
|
|
267
|
+
let command;
|
|
268
|
+
let explicitVersion;
|
|
269
|
+
if (validCommands.includes(arg)) {
|
|
270
|
+
command = arg;
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
command = "explicit";
|
|
274
|
+
explicitVersion = arg;
|
|
275
|
+
}
|
|
276
|
+
const dryRun = event.flags["dry-run"] === true;
|
|
277
|
+
return primitives.results.ok({
|
|
278
|
+
mode: "update",
|
|
279
|
+
command,
|
|
280
|
+
options: { dryRun, explicitVersion },
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* CLI ResponseMapper — formats handler output for terminal display.
|
|
285
|
+
*/
|
|
286
|
+
const cliResponseMapper = (result) => {
|
|
287
|
+
if (primitives.results.isFail(result)) {
|
|
288
|
+
return primitives.results.fail({
|
|
289
|
+
exitCode: 1,
|
|
290
|
+
message: String(result.error),
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
const { ctx, output: out } = cliSupport.getCliContext();
|
|
294
|
+
const handlerOutput = result.value;
|
|
295
|
+
if (handlerOutput.mode === "show") {
|
|
296
|
+
out.writeln(span.table(["name", "version"], handlerOutput.result.packages.map((p) => [p.name, p.version])));
|
|
297
|
+
return primitives.results.ok(undefined);
|
|
298
|
+
}
|
|
299
|
+
// Update mode
|
|
300
|
+
const { result: updateResult } = handlerOutput;
|
|
301
|
+
if (updateResult.command === "sync") {
|
|
302
|
+
tui.log.info(ctx, "Syncing all versions...");
|
|
303
|
+
}
|
|
304
|
+
else if (updateResult.command === "explicit") {
|
|
305
|
+
tui.log.info(ctx, `Setting all versions to ${updateResult.targetVersion}...`);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
tui.log.info(ctx, `Bumping all versions (${updateResult.command})...`);
|
|
309
|
+
}
|
|
310
|
+
tui.log.info(ctx, `Target version: ${updateResult.targetVersion}`);
|
|
311
|
+
out.writeln(span.table(["name", "from", "to", "changed"], updateResult.updates.map((u) => [
|
|
312
|
+
u.name,
|
|
313
|
+
u.from,
|
|
314
|
+
u.to,
|
|
315
|
+
String(u.changed),
|
|
316
|
+
])));
|
|
317
|
+
for (const fileUpdate of updateResult.fileUpdates) {
|
|
318
|
+
if (fileUpdate.changed) {
|
|
319
|
+
tui.log.info(ctx, `${fileUpdate.path} (${fileUpdate.from} → ${fileUpdate.to})`);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (updateResult.dryRun) {
|
|
323
|
+
tui.log.info(ctx, `Dry run - ${updateResult.changedCount} packages would be modified.`);
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
tui.log.success(ctx, `Done. Updated ${updateResult.changedCount} packages.`);
|
|
327
|
+
}
|
|
328
|
+
return primitives.results.ok(undefined);
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* CLI trigger — wired handler for command-line invocation.
|
|
332
|
+
*/
|
|
333
|
+
export const handleCli = functions.handler.createTrigger({
|
|
334
|
+
handler: versionsHandler,
|
|
335
|
+
adaptInput: cliAdapter,
|
|
336
|
+
adaptOutput: cliResponseMapper,
|
|
337
|
+
});
|
|
338
|
+
/** Parse the versions arguments: the command and `--dry-run`. */
|
|
339
|
+
export const parseCliArgs = (cliArgs) => cliSupport.parseCliEvent("versions", cliArgs, {
|
|
340
|
+
"dry-run": { type: "boolean" },
|
|
341
|
+
});
|
|
342
|
+
/** CLI entry point for dispatcher compatibility. */
|
|
343
|
+
export const main = async (cliArgs) => await handleCli(parseCliArgs(cliArgs));
|
|
344
|
+
if (import.meta.main) {
|
|
345
|
+
// Entry point: the await only runs when this file is executed directly.
|
|
346
|
+
// oxlint-disable-next-line node/no-top-level-await
|
|
347
|
+
const result = await main(standards.crossRuntime.runtime.process.args);
|
|
348
|
+
cliSupport.runCliMain(result, cliSupport.getCliContext().output);
|
|
349
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { FileEntry } from "./file-tools-shared.ts";
|
|
2
|
+
/** rule -> repository-relative path -> allowed violation count */
|
|
3
|
+
export type Baseline<R extends string> = Readonly<Record<R, Readonly<Record<string, number>>>>;
|
|
4
|
+
/** One violation of a baselined rule. */
|
|
5
|
+
export type RuleViolation<R extends string> = {
|
|
6
|
+
readonly rule: R;
|
|
7
|
+
readonly line: number;
|
|
8
|
+
readonly message: string;
|
|
9
|
+
};
|
|
10
|
+
/** The violations found in one file. */
|
|
11
|
+
export type FileViolations<R extends string> = {
|
|
12
|
+
/** Absolute path, as the walker returns it */
|
|
13
|
+
readonly path: string;
|
|
14
|
+
/** Path relative to the scanned root with `/` separators, as baselines record it */
|
|
15
|
+
readonly relPath: string;
|
|
16
|
+
readonly violations: readonly RuleViolation<R>[];
|
|
17
|
+
};
|
|
18
|
+
/** A violation above the baseline, in the shape file tools report. */
|
|
19
|
+
export type BaselineIssue = {
|
|
20
|
+
readonly path: string;
|
|
21
|
+
readonly line: number;
|
|
22
|
+
readonly message: string;
|
|
23
|
+
};
|
|
24
|
+
/** A baseline that allows no violation of any of `rules`. */
|
|
25
|
+
export declare const emptyBaseline: <R extends string>(rules: readonly R[]) => Baseline<R>;
|
|
26
|
+
/** `file` relative to `root`, with `/` separators on every platform. */
|
|
27
|
+
export declare const relativePath: (root: string, file: string) => string;
|
|
28
|
+
/**
|
|
29
|
+
* Resolves the `baseline` option of a validator against the scanned root.
|
|
30
|
+
* Throws when the option is not a path, so a typo in the manifest fails loudly
|
|
31
|
+
* instead of silently allowing nothing.
|
|
32
|
+
*/
|
|
33
|
+
export declare const resolveBaselinePath: (validatorName: string, root: string, option: unknown) => string;
|
|
34
|
+
/**
|
|
35
|
+
* Reads a baseline file. A missing file is an empty baseline, so a validator
|
|
36
|
+
* without one fails on every violation.
|
|
37
|
+
*/
|
|
38
|
+
export declare const readBaseline: <R extends string>(file: string, rules: readonly R[]) => Promise<Baseline<R>>;
|
|
39
|
+
/**
|
|
40
|
+
* Loads each file and returns the violations `find` reports, leaving out the
|
|
41
|
+
* files `skip` names and the files with none.
|
|
42
|
+
*/
|
|
43
|
+
export declare const collectViolations: <R extends string>(root: string, files: readonly FileEntry[], find: (content: string) => readonly RuleViolation<R>[], skip: (relPath: string) => boolean) => Promise<FileViolations<R>[]>;
|
|
44
|
+
/**
|
|
45
|
+
* The violations of one file above its baseline. When a rule is over its
|
|
46
|
+
* count, every violation of that rule in the file is reported, since the
|
|
47
|
+
* baseline cannot tell which of them is new.
|
|
48
|
+
*/
|
|
49
|
+
export declare const issuesAboveBaseline: <R extends string>(baseline: Baseline<R>, file: FileViolations<R>) => BaselineIssue[];
|
|
50
|
+
/** Counts the given violations into a baseline for `rules`. */
|
|
51
|
+
export declare const buildBaseline: <R extends string>(rules: readonly R[], files: readonly FileViolations<R>[]) => Baseline<R>;
|
|
52
|
+
/** The number of violations a baseline allows in total. */
|
|
53
|
+
export declare const baselineTotal: <R extends string>(baseline: Baseline<R>) => number;
|
|
54
|
+
/**
|
|
55
|
+
* Writes a baseline with its files sorted, so regenerating an unchanged
|
|
56
|
+
* baseline produces no diff.
|
|
57
|
+
*/
|
|
58
|
+
export declare const writeBaselineFile: <R extends string>(file: string, baseline: Baseline<R>) => Promise<void>;
|