@intra-mart/accel 0.5.0-dev.202608030656 → 0.5.0-dev.202608180918
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 +103 -32
- package/dist/asset/deployer.d.ts +2 -0
- package/dist/asset/deployer.js +11 -9
- package/dist/asset/git-provider.d.ts +1 -0
- package/dist/asset/git-provider.js +20 -9
- package/dist/asset/updater.d.ts +9 -2
- package/dist/asset/updater.js +12 -6
- package/dist/asset/walker.d.ts +2 -1
- package/dist/asset/walker.js +36 -0
- package/dist/commands/asset-provider.d.ts +1 -1
- package/dist/commands/asset-provider.js +2 -2
- package/dist/commands/attach.d.ts +116 -82
- package/dist/commands/attach.js +176 -145
- package/dist/commands/cache.js +11 -19
- package/dist/commands/deploy.d.ts +53 -32
- package/dist/commands/deploy.js +112 -75
- package/dist/commands/detach.d.ts +18 -0
- package/dist/commands/detach.js +69 -54
- package/dist/commands/init.d.ts +117 -83
- package/dist/commands/init.js +119 -98
- package/dist/commands/login.d.ts +12 -10
- package/dist/commands/login.js +14 -10
- package/dist/commands/preset.d.ts +31 -0
- package/dist/commands/preset.js +389 -0
- package/dist/commands/run-wrapper.d.ts +15 -0
- package/dist/commands/run-wrapper.js +62 -0
- package/dist/commands/switch.d.ts +49 -17
- package/dist/commands/switch.js +206 -122
- package/dist/commands/update.d.ts +142 -83
- package/dist/commands/update.js +359 -261
- package/dist/core/color-env.d.ts +1 -0
- package/dist/core/color-env.js +6 -0
- package/dist/core/constants.d.ts +0 -1
- package/dist/core/constants.js +0 -3
- package/dist/core/errors.d.ts +6 -0
- package/dist/core/errors.js +16 -0
- package/dist/core/logger.d.ts +15 -0
- package/dist/core/logger.js +1 -0
- package/dist/core/paths.d.ts +6 -0
- package/dist/core/paths.js +22 -0
- package/dist/core/types.d.ts +14 -1
- package/dist/core/validation.d.ts +34 -0
- package/dist/core/validation.js +87 -0
- package/dist/core/validators.d.ts +2 -0
- package/dist/core/validators.js +7 -0
- package/dist/deploy/api-client.d.ts +1 -0
- package/dist/deploy/api-client.js +7 -1
- package/dist/git/config-file.d.ts +3 -0
- package/dist/git/config-file.js +178 -0
- package/dist/git/errors.d.ts +5 -0
- package/dist/git/errors.js +21 -2
- package/dist/git/git-objects.d.ts +11 -0
- package/dist/git/git-objects.js +49 -0
- package/dist/git/http.d.ts +2 -2
- package/dist/git/http.js +22 -10
- package/dist/git/index-file.d.ts +17 -0
- package/dist/git/index-file.js +111 -0
- package/dist/git/object-cache.d.ts +1 -0
- package/dist/git/object-cache.js +11 -15
- package/dist/git/object-store.d.ts +4 -0
- package/dist/git/object-store.js +82 -107
- package/dist/git/pack-parse.d.ts +19 -0
- package/dist/git/pack-parse.js +261 -0
- package/dist/git/pack-store.d.ts +20 -0
- package/dist/git/pack-store.js +144 -0
- package/dist/git/read-capped.d.ts +1 -0
- package/dist/git/read-capped.js +26 -0
- package/dist/git/redact-url.d.ts +1 -0
- package/dist/git/redact-url.js +14 -0
- package/dist/git/repo-layout.d.ts +5 -0
- package/dist/git/repo-layout.js +44 -0
- package/dist/git/smart-http.d.ts +3 -2
- package/dist/git/smart-http.js +5 -5
- package/dist/git/untracked.d.ts +11 -0
- package/dist/git/untracked.js +93 -0
- package/dist/git/worktree-status.d.ts +4 -0
- package/dist/git/worktree-status.js +140 -0
- package/dist/git/zlib-inflate.d.ts +7 -0
- package/dist/git/zlib-inflate.js +78 -0
- package/dist/i18n/en.js +47 -0
- package/dist/i18n/index.js +1 -1
- package/dist/i18n/ja.js +47 -0
- package/dist/i18n/zh_CN.js +47 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -2
- package/dist/interactive/asset-messages.d.ts +2 -1
- package/dist/interactive/asset-messages.js +4 -4
- package/dist/interactive/clack-logger.d.ts +2 -0
- package/dist/interactive/clack-logger.js +11 -0
- package/dist/interactive/credential-auth.d.ts +2 -0
- package/dist/interactive/credential-auth.js +7 -6
- package/dist/interactive/credentials-prompts.js +10 -6
- package/dist/interactive/next-steps.d.ts +2 -1
- package/dist/interactive/next-steps.js +3 -3
- package/dist/interactive/progress.d.ts +8 -1
- package/dist/interactive/progress.js +0 -0
- package/dist/interactive/prompts.d.ts +3 -33
- package/dist/interactive/prompts.js +23 -111
- package/dist/interactive/summary.d.ts +2 -1
- package/dist/interactive/summary.js +3 -3
- package/dist/juggling/resolve.d.ts +7 -0
- package/dist/juggling/resolve.js +18 -0
- package/dist/lib.d.ts +34 -0
- package/dist/lib.js +29 -0
- package/dist/utils/args.d.ts +4 -1
- package/dist/utils/args.js +26 -3
- package/dist/utils/githooks-sync.d.ts +3 -1
- package/dist/utils/githooks-sync.js +37 -37
- package/dist/utils/mcp-generate.d.ts +26 -0
- package/dist/utils/mcp-generate.js +313 -0
- package/dist/utils/preset-io.d.ts +24 -0
- package/dist/utils/preset-io.js +167 -0
- package/dist/utils/settings-io.d.ts +2 -0
- package/dist/utils/settings-io.js +2 -2
- package/package.json +20 -13
- package/dist/utils/mcp-sync.d.ts +0 -4
- package/dist/utils/mcp-sync.js +0 -103
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/core/constants.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AccelSettings } from "./types.js";
|
|
2
|
-
export declare const CLI_VERSION: string;
|
|
3
2
|
export declare const DATABASE_OPTIONS: readonly ["postgresql", "oracle", "sqlserver"];
|
|
4
3
|
export type DatabaseOption = (typeof DATABASE_OPTIONS)[number];
|
|
5
4
|
export declare const AGENT_OPTIONS: readonly ["claude-code", "codex", "github-copilot"];
|
package/dist/core/constants.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
const pkg = createRequire(import.meta.url)("../../package.json");
|
|
3
|
-
export const CLI_VERSION = pkg.version;
|
|
4
1
|
export const DATABASE_OPTIONS = ["postgresql", "oracle", "sqlserver"];
|
|
5
2
|
export const AGENT_OPTIONS = ["claude-code", "codex", "github-copilot"];
|
|
6
3
|
export const LOCALE_OPTIONS = ["ja", "en", "zh_CN"];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const createCancelledError: (message?: string) => Error;
|
|
2
|
+
export declare const isCancelledError: (err: unknown) => err is Error;
|
|
3
|
+
export declare const isAbortError: (err: unknown) => boolean;
|
|
4
|
+
export declare const normalizeAbort: (err: unknown, signal?: AbortSignal) => unknown;
|
|
5
|
+
export declare const markReported: <T>(err: T) => T;
|
|
6
|
+
export declare const isReportedError: (err: unknown) => boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const CANCELLED_ERROR = "CancelledError";
|
|
2
|
+
export const createCancelledError = (message = "Cancelled") => Object.assign(new Error(message), { name: CANCELLED_ERROR });
|
|
3
|
+
export const isCancelledError = (err) => err instanceof Error && err.name === CANCELLED_ERROR;
|
|
4
|
+
export const isAbortError = (err) => err instanceof Error && err.name === "AbortError";
|
|
5
|
+
export const normalizeAbort = (err, signal) => isAbortError(err) || signal?.aborted === true
|
|
6
|
+
? createCancelledError()
|
|
7
|
+
: err;
|
|
8
|
+
const REPORTED = "accelErrorReported";
|
|
9
|
+
export const markReported = (err) => {
|
|
10
|
+
if (err instanceof Error) {
|
|
11
|
+
Object.assign(err, { [REPORTED]: true });
|
|
12
|
+
}
|
|
13
|
+
return err;
|
|
14
|
+
};
|
|
15
|
+
export const isReportedError = (err) => err instanceof Error &&
|
|
16
|
+
err[REPORTED] === true;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type Spinner = {
|
|
2
|
+
start(msg?: string): void;
|
|
3
|
+
stop(msg?: string): void;
|
|
4
|
+
message(msg: string): void;
|
|
5
|
+
};
|
|
6
|
+
export type Logger = {
|
|
7
|
+
intro(title: string): void;
|
|
8
|
+
outro(msg: string): void;
|
|
9
|
+
info(msg: string): void;
|
|
10
|
+
warn(msg: string): void;
|
|
11
|
+
error(msg: string): void;
|
|
12
|
+
success(msg: string): void;
|
|
13
|
+
note(msg: string, title?: string): void;
|
|
14
|
+
spinner(): Spinner;
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
let packageRootOverride;
|
|
5
|
+
let cachedVersion;
|
|
6
|
+
export const configurePaths = (opts) => {
|
|
7
|
+
packageRootOverride = opts.packageRoot;
|
|
8
|
+
cachedVersion = undefined;
|
|
9
|
+
};
|
|
10
|
+
export const getPackageRoot = () => packageRootOverride ?? fileURLToPath(new URL("../..", import.meta.url));
|
|
11
|
+
export const getCliVersion = () => {
|
|
12
|
+
if (cachedVersion === undefined) {
|
|
13
|
+
const pkgPath = join(getPackageRoot(), "package.json");
|
|
14
|
+
const { version } = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
15
|
+
if (typeof version !== "string") {
|
|
16
|
+
throw new Error(`package.json at ${pkgPath} has no string "version"`);
|
|
17
|
+
}
|
|
18
|
+
cachedVersion = version;
|
|
19
|
+
}
|
|
20
|
+
return cachedVersion;
|
|
21
|
+
};
|
|
22
|
+
export const getAssetsGithooksRoot = () => join(getPackageRoot(), "assets", "githooks");
|
package/dist/core/types.d.ts
CHANGED
|
@@ -60,6 +60,10 @@ export type RenameRule = {
|
|
|
60
60
|
from: string;
|
|
61
61
|
to: string;
|
|
62
62
|
};
|
|
63
|
+
export type McpFileRule = {
|
|
64
|
+
condition?: Condition;
|
|
65
|
+
file: string;
|
|
66
|
+
};
|
|
63
67
|
export type MessageLevel = "info" | "warn";
|
|
64
68
|
export type Message = {
|
|
65
69
|
condition?: Condition;
|
|
@@ -68,11 +72,12 @@ export type Message = {
|
|
|
68
72
|
};
|
|
69
73
|
export type MetaJson = {
|
|
70
74
|
version: string;
|
|
71
|
-
type: "file" | "directory";
|
|
75
|
+
type: "file" | "directory" | "mcp";
|
|
72
76
|
conditions?: Condition;
|
|
73
77
|
rename?: RenameRule[];
|
|
74
78
|
replacements?: Replacement[];
|
|
75
79
|
messages?: Message[];
|
|
80
|
+
files?: McpFileRule[];
|
|
76
81
|
};
|
|
77
82
|
export type AccelplatformVersion = {
|
|
78
83
|
label: string;
|
|
@@ -112,6 +117,14 @@ export type AccelSettings = {
|
|
|
112
117
|
assetSource?: AssetSourceInfo;
|
|
113
118
|
deployedAssets: Record<string, string>;
|
|
114
119
|
};
|
|
120
|
+
export type AccelPreset = {
|
|
121
|
+
name: string;
|
|
122
|
+
label?: string;
|
|
123
|
+
description?: string;
|
|
124
|
+
modules: string[];
|
|
125
|
+
features: string[];
|
|
126
|
+
agents: string[];
|
|
127
|
+
};
|
|
115
128
|
export type HashsumEntry = {
|
|
116
129
|
filePath: string;
|
|
117
130
|
version: string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AccelSettings } from "./types.js";
|
|
2
|
+
import { type Release } from "./catalog.js";
|
|
3
|
+
import { type Validators } from "./validators.js";
|
|
4
|
+
export type PromptOptions = {
|
|
5
|
+
name?: string;
|
|
6
|
+
artifactId?: string;
|
|
7
|
+
jugglingProject?: string;
|
|
8
|
+
accelplatformVersion?: string;
|
|
9
|
+
module?: string[];
|
|
10
|
+
feature?: string[];
|
|
11
|
+
group?: string;
|
|
12
|
+
projectVersion?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
database?: string;
|
|
15
|
+
javascript?: boolean;
|
|
16
|
+
agent?: string[];
|
|
17
|
+
packageManager?: string;
|
|
18
|
+
locale: string;
|
|
19
|
+
withGit?: boolean;
|
|
20
|
+
noInteraction?: boolean;
|
|
21
|
+
isInit: boolean;
|
|
22
|
+
mode?: "init" | "attach" | "update";
|
|
23
|
+
skipIntro?: boolean;
|
|
24
|
+
skipValidation?: boolean;
|
|
25
|
+
};
|
|
26
|
+
export type ResolvedOptions = Omit<AccelSettings, "cliVersion" | "createdAt" | "deployedAssets" | "assetSource" | "jugglingProject"> & {
|
|
27
|
+
withGit: boolean;
|
|
28
|
+
jugglingProject: string | null | undefined;
|
|
29
|
+
};
|
|
30
|
+
export declare const validateNonInteractive: (opts: PromptOptions) => string[];
|
|
31
|
+
export declare const validateCliValues: (opts: PromptOptions, validators: Validators) => void;
|
|
32
|
+
export declare const validateCatalogValues: (opts: PromptOptions, release: Release, locale: string) => void;
|
|
33
|
+
export declare const collectSettingsErrors: (opts: PromptOptions, locale: string, releaseIdFallback?: string) => string[];
|
|
34
|
+
export declare const checkProjectDirAvailable: (baseDir: string, name: string, locale: string) => Promise<string | undefined>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { findReleaseById } from "./catalog.js";
|
|
4
|
+
import { createValidators, createReleaseValidators, } from "./validators.js";
|
|
5
|
+
import { getMessage } from "../i18n/index.js";
|
|
6
|
+
export const validateNonInteractive = (opts) => {
|
|
7
|
+
const mode = opts.mode ?? (opts.isInit ? "init" : "attach");
|
|
8
|
+
const errors = [];
|
|
9
|
+
const missing = [];
|
|
10
|
+
if (!opts.name) {
|
|
11
|
+
if (mode === "init") {
|
|
12
|
+
errors.push(getMessage("error.initNameArgumentMissing", opts.locale));
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
missing.push("--name");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (!opts.jugglingProject && !opts.accelplatformVersion) {
|
|
19
|
+
missing.push("--accelplatform-version");
|
|
20
|
+
}
|
|
21
|
+
if (missing.length > 0) {
|
|
22
|
+
errors.push(getMessage("error.missingRequiredOptions", opts.locale, {
|
|
23
|
+
options: missing.join(", "),
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
return errors;
|
|
27
|
+
};
|
|
28
|
+
const collectFormatErrors = (opts, validators) => {
|
|
29
|
+
const errors = [];
|
|
30
|
+
const check = (validator, value) => {
|
|
31
|
+
if (value === undefined)
|
|
32
|
+
return;
|
|
33
|
+
const err = validator(value);
|
|
34
|
+
if (err)
|
|
35
|
+
errors.push(err);
|
|
36
|
+
};
|
|
37
|
+
check(validators.name, opts.name);
|
|
38
|
+
check(validators.artifactId, opts.artifactId);
|
|
39
|
+
check(validators.group, opts.group);
|
|
40
|
+
check(validators.projectVersion, opts.projectVersion);
|
|
41
|
+
check(validators.accelplatformVersion, opts.accelplatformVersion);
|
|
42
|
+
check(validators.database, opts.database);
|
|
43
|
+
for (const a of opts.agent ?? [])
|
|
44
|
+
check(validators.agent, a);
|
|
45
|
+
check(validators.packageManager, opts.packageManager);
|
|
46
|
+
return errors;
|
|
47
|
+
};
|
|
48
|
+
const collectCatalogErrors = (opts, release, locale) => {
|
|
49
|
+
const releaseValidators = createReleaseValidators(locale, release);
|
|
50
|
+
const errors = [];
|
|
51
|
+
const check = (validator, value) => {
|
|
52
|
+
const err = validator(value);
|
|
53
|
+
if (err)
|
|
54
|
+
errors.push(err);
|
|
55
|
+
};
|
|
56
|
+
for (const m of opts.module ?? [])
|
|
57
|
+
check(releaseValidators.module, m);
|
|
58
|
+
for (const f of opts.feature ?? [])
|
|
59
|
+
check(releaseValidators.feature, f);
|
|
60
|
+
return errors;
|
|
61
|
+
};
|
|
62
|
+
export const validateCliValues = (opts, validators) => {
|
|
63
|
+
const [first] = collectFormatErrors(opts, validators);
|
|
64
|
+
if (first)
|
|
65
|
+
throw new Error(first);
|
|
66
|
+
};
|
|
67
|
+
export const validateCatalogValues = (opts, release, locale) => {
|
|
68
|
+
const [first] = collectCatalogErrors(opts, release, locale);
|
|
69
|
+
if (first)
|
|
70
|
+
throw new Error(first);
|
|
71
|
+
};
|
|
72
|
+
export const collectSettingsErrors = (opts, locale, releaseIdFallback) => {
|
|
73
|
+
const errors = collectFormatErrors(opts, createValidators(locale));
|
|
74
|
+
const releaseId = opts.accelplatformVersion ?? releaseIdFallback;
|
|
75
|
+
const release = releaseId ? findReleaseById(releaseId) : undefined;
|
|
76
|
+
if (release) {
|
|
77
|
+
errors.push(...collectCatalogErrors(opts, release, locale));
|
|
78
|
+
}
|
|
79
|
+
return errors;
|
|
80
|
+
};
|
|
81
|
+
export const checkProjectDirAvailable = async (baseDir, name, locale) => {
|
|
82
|
+
const path = resolve(baseDir, name);
|
|
83
|
+
const exists = await stat(path).then(() => true, () => false);
|
|
84
|
+
return exists
|
|
85
|
+
? getMessage("error.directoryExists", locale, { path })
|
|
86
|
+
: undefined;
|
|
87
|
+
};
|
|
@@ -15,4 +15,6 @@ export type ReleaseValidators = {
|
|
|
15
15
|
feature: Validator;
|
|
16
16
|
};
|
|
17
17
|
export declare const createValidators: (locale: string) => Validators;
|
|
18
|
+
export declare const PRESET_NAME_PATTERN: RegExp;
|
|
19
|
+
export declare const createPresetNameValidator: (locale: string) => Validator;
|
|
18
20
|
export declare const createReleaseValidators: (locale: string, release: Release) => ReleaseValidators;
|
package/dist/core/validators.js
CHANGED
|
@@ -75,6 +75,13 @@ export const createValidators = (locale) => ({
|
|
|
75
75
|
});
|
|
76
76
|
},
|
|
77
77
|
});
|
|
78
|
+
export const PRESET_NAME_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
79
|
+
export const createPresetNameValidator = (locale) => (value) => {
|
|
80
|
+
const v = value ?? "";
|
|
81
|
+
return PRESET_NAME_PATTERN.test(v)
|
|
82
|
+
? undefined
|
|
83
|
+
: getMessage("preset.error.invalidName", locale, { value: v });
|
|
84
|
+
};
|
|
78
85
|
export const createReleaseValidators = (locale, release) => ({
|
|
79
86
|
module: (value) => {
|
|
80
87
|
const v = value ?? "";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isAbortError } from "../core/errors.js";
|
|
1
2
|
const STAGING_PATH = "/api/bearer/development/staging";
|
|
2
3
|
const VERIFY_PATH = "/oauth/token/verify";
|
|
3
4
|
const PAGE_LIMIT = 100;
|
|
@@ -7,7 +8,8 @@ export const isDeployError = (e) => typeof e === "object" &&
|
|
|
7
8
|
e !== null &&
|
|
8
9
|
e._tag === "DeployError";
|
|
9
10
|
export const createApiClient = (endpoint, apiKey, deps = {}) => {
|
|
10
|
-
const
|
|
11
|
+
const rawFetch = deps.fetch ?? globalThis.fetch;
|
|
12
|
+
const doFetch = (url, init) => rawFetch(url, { ...init, signal: deps.signal });
|
|
11
13
|
const baseHeaders = {
|
|
12
14
|
"X-Intramart-Session": "never",
|
|
13
15
|
Authorization: `Bearer ${apiKey}`,
|
|
@@ -18,6 +20,8 @@ export const createApiClient = (endpoint, apiKey, deps = {}) => {
|
|
|
18
20
|
res = await doFetch(url, init);
|
|
19
21
|
}
|
|
20
22
|
catch (err) {
|
|
23
|
+
if (isAbortError(err))
|
|
24
|
+
throw err;
|
|
21
25
|
throw makeDeployError("network", {
|
|
22
26
|
serverMessage: err instanceof Error ? err.message : String(err),
|
|
23
27
|
});
|
|
@@ -63,6 +67,8 @@ export const createApiClient = (endpoint, apiKey, deps = {}) => {
|
|
|
63
67
|
});
|
|
64
68
|
}
|
|
65
69
|
catch (err) {
|
|
70
|
+
if (isAbortError(err))
|
|
71
|
+
throw err;
|
|
66
72
|
throw makeDeployError("network", {
|
|
67
73
|
serverMessage: err instanceof Error ? err.message : String(err),
|
|
68
74
|
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const readConfigValue: (configPath: string, section: string, key: string) => Promise<string | undefined>;
|
|
2
|
+
export declare const parseConfigBool: (value: string | undefined, fallback: boolean) => boolean;
|
|
3
|
+
export declare const writeConfigValue: (configPath: string, section: string, key: string, value: string) => Promise<void>;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { lstat, rename, writeFile } from "node:fs/promises";
|
|
3
|
+
import { readTextFileCapped } from "./read-capped.js";
|
|
4
|
+
const SECTION_PATTERN = /^\s*\[([A-Za-z0-9.-]+)(\s+"(?:[^"\\]|\\.)*")?\]\s*(?:[#;].*)?$/;
|
|
5
|
+
const KEY_PATTERN = /^\s*([A-Za-z][A-Za-z0-9-]*)\s*(?:=\s*(.*))?$/;
|
|
6
|
+
const MAX_CONFIG_BYTES = 1024 * 1024;
|
|
7
|
+
const MAX_CONTINUATIONS = 100;
|
|
8
|
+
const endsWithContinuation = (line) => {
|
|
9
|
+
let backslashes = 0;
|
|
10
|
+
for (let i = line.length - 1; i >= 0 && line[i] === "\\"; i--)
|
|
11
|
+
backslashes++;
|
|
12
|
+
return backslashes % 2 === 1;
|
|
13
|
+
};
|
|
14
|
+
const logicalLines = (content) => {
|
|
15
|
+
const physical = content.replace(/^\uFEFF/, "").split(/\r\n|\n|\r/);
|
|
16
|
+
const lines = [];
|
|
17
|
+
for (let i = 0; i < physical.length; i++) {
|
|
18
|
+
let line = physical[i];
|
|
19
|
+
let joins = 0;
|
|
20
|
+
while (endsWithContinuation(line) &&
|
|
21
|
+
i + 1 < physical.length &&
|
|
22
|
+
++joins <= MAX_CONTINUATIONS) {
|
|
23
|
+
line = line.slice(0, -1) + physical[++i];
|
|
24
|
+
}
|
|
25
|
+
lines.push(line);
|
|
26
|
+
}
|
|
27
|
+
return lines;
|
|
28
|
+
};
|
|
29
|
+
const parseValue = (raw) => {
|
|
30
|
+
let value = "";
|
|
31
|
+
let inQuote = false;
|
|
32
|
+
let trailingSpaces = 0;
|
|
33
|
+
for (let i = 0; i < raw.length; i++) {
|
|
34
|
+
const ch = raw[i];
|
|
35
|
+
if (ch === "\\") {
|
|
36
|
+
const next = raw[++i];
|
|
37
|
+
if (next === undefined)
|
|
38
|
+
break;
|
|
39
|
+
const mapped = next === "n" ? "\n" : next === "t" ? "\t" : next === "b" ? "\b" : next;
|
|
40
|
+
value += mapped;
|
|
41
|
+
trailingSpaces = 0;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (ch === '"') {
|
|
45
|
+
inQuote = !inQuote;
|
|
46
|
+
trailingSpaces = 0;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (!inQuote && (ch === "#" || ch === ";"))
|
|
50
|
+
break;
|
|
51
|
+
value += ch;
|
|
52
|
+
if (!inQuote && (ch === " " || ch === "\t"))
|
|
53
|
+
trailingSpaces++;
|
|
54
|
+
else
|
|
55
|
+
trailingSpaces = 0;
|
|
56
|
+
}
|
|
57
|
+
return trailingSpaces > 0 ? value.slice(0, -trailingSpaces) : value;
|
|
58
|
+
};
|
|
59
|
+
export const readConfigValue = async (configPath, section, key) => {
|
|
60
|
+
const content = await readTextFileCapped(configPath, MAX_CONFIG_BYTES);
|
|
61
|
+
if (content === null)
|
|
62
|
+
return undefined;
|
|
63
|
+
const sectionLower = section.toLowerCase();
|
|
64
|
+
const keyLower = key.toLowerCase();
|
|
65
|
+
let inTargetSection = false;
|
|
66
|
+
let result;
|
|
67
|
+
for (const line of logicalLines(content)) {
|
|
68
|
+
const sectionMatch = SECTION_PATTERN.exec(line);
|
|
69
|
+
if (sectionMatch !== null) {
|
|
70
|
+
inTargetSection =
|
|
71
|
+
sectionMatch[1].toLowerCase() === sectionLower &&
|
|
72
|
+
sectionMatch[2] === undefined;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!inTargetSection)
|
|
76
|
+
continue;
|
|
77
|
+
const keyMatch = KEY_PATTERN.exec(line);
|
|
78
|
+
if (keyMatch === null || keyMatch[1].toLowerCase() !== keyLower)
|
|
79
|
+
continue;
|
|
80
|
+
result = keyMatch[2] === undefined ? "" : parseValue(keyMatch[2]);
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
84
|
+
export const parseConfigBool = (value, fallback) => {
|
|
85
|
+
if (value === undefined)
|
|
86
|
+
return fallback;
|
|
87
|
+
const lower = value.toLowerCase();
|
|
88
|
+
if (["", "true", "yes", "on", "1"].includes(lower))
|
|
89
|
+
return true;
|
|
90
|
+
if (["false", "no", "off", "0"].includes(lower))
|
|
91
|
+
return false;
|
|
92
|
+
return fallback;
|
|
93
|
+
};
|
|
94
|
+
const isValidSectionName = (name) => /^[A-Za-z0-9.-]+$/.test(name);
|
|
95
|
+
const isValidKeyName = (name) => /^[A-Za-z][A-Za-z0-9-]*$/.test(name);
|
|
96
|
+
const formatValue = (value) => {
|
|
97
|
+
if (/[\0-\x08\x0b-\x1f\x7f]/.test(value)) {
|
|
98
|
+
throw new Error("config value contains unsupported control characters");
|
|
99
|
+
}
|
|
100
|
+
return /[\s#;"\\]/.test(value)
|
|
101
|
+
? `"${value
|
|
102
|
+
.replace(/\\/g, "\\\\")
|
|
103
|
+
.replace(/"/g, '\\"')
|
|
104
|
+
.replace(/\n/g, "\\n")
|
|
105
|
+
.replace(/\t/g, "\\t")}"`
|
|
106
|
+
: value;
|
|
107
|
+
};
|
|
108
|
+
export const writeConfigValue = async (configPath, section, key, value) => {
|
|
109
|
+
if (!isValidSectionName(section) || !isValidKeyName(key)) {
|
|
110
|
+
throw new Error(`invalid config section/key: [${section}] ${key}`);
|
|
111
|
+
}
|
|
112
|
+
let content = "";
|
|
113
|
+
const stats = await lstat(configPath).catch((err) => {
|
|
114
|
+
if (err.code === "ENOENT")
|
|
115
|
+
return null;
|
|
116
|
+
throw err;
|
|
117
|
+
});
|
|
118
|
+
if (stats !== null) {
|
|
119
|
+
const existing = await readTextFileCapped(configPath, MAX_CONFIG_BYTES);
|
|
120
|
+
if (existing === null) {
|
|
121
|
+
throw new Error(`config file is not editable: ${configPath}`);
|
|
122
|
+
}
|
|
123
|
+
content = existing;
|
|
124
|
+
}
|
|
125
|
+
const sectionLower = section.toLowerCase();
|
|
126
|
+
const keyLower = key.toLowerCase();
|
|
127
|
+
const newLine = `\t${key} = ${formatValue(value)}`;
|
|
128
|
+
const physical = content.split("\n");
|
|
129
|
+
let inTargetSection = false;
|
|
130
|
+
let continuation = false;
|
|
131
|
+
let replaceAt = -1;
|
|
132
|
+
let insertAfter = -1;
|
|
133
|
+
for (let i = 0; i < physical.length; i++) {
|
|
134
|
+
const line = physical[i].replace(/\r$/, "");
|
|
135
|
+
if (continuation) {
|
|
136
|
+
continuation = endsWithContinuation(line);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
continuation = endsWithContinuation(line);
|
|
140
|
+
const sectionMatch = SECTION_PATTERN.exec(line);
|
|
141
|
+
if (sectionMatch !== null) {
|
|
142
|
+
const isTarget = sectionMatch[1].toLowerCase() === sectionLower &&
|
|
143
|
+
sectionMatch[2] === undefined;
|
|
144
|
+
if (isTarget && insertAfter === -1)
|
|
145
|
+
insertAfter = i;
|
|
146
|
+
inTargetSection = isTarget;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (!inTargetSection || replaceAt !== -1)
|
|
150
|
+
continue;
|
|
151
|
+
const keyMatch = KEY_PATTERN.exec(line);
|
|
152
|
+
if (keyMatch !== null && keyMatch[1].toLowerCase() === keyLower) {
|
|
153
|
+
replaceAt = i;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
let lines;
|
|
157
|
+
if (replaceAt !== -1) {
|
|
158
|
+
lines = [...physical];
|
|
159
|
+
lines[replaceAt] = newLine;
|
|
160
|
+
}
|
|
161
|
+
else if (insertAfter !== -1) {
|
|
162
|
+
lines = [...physical];
|
|
163
|
+
lines.splice(insertAfter + 1, 0, newLine);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
lines = [...physical];
|
|
167
|
+
if (lines.length > 0 && lines[lines.length - 1] === "")
|
|
168
|
+
lines.pop();
|
|
169
|
+
if (lines.length === 1 && lines[0] === "")
|
|
170
|
+
lines = [];
|
|
171
|
+
lines.push(`[${section}]`, newLine);
|
|
172
|
+
}
|
|
173
|
+
const text = lines.join("\n");
|
|
174
|
+
const body = text.endsWith("\n") ? text : `${text}\n`;
|
|
175
|
+
const tmpPath = `${configPath}.accel-${randomBytes(4).toString("hex")}.tmp`;
|
|
176
|
+
await writeFile(tmpPath, body, "utf-8");
|
|
177
|
+
await rename(tmpPath, configPath);
|
|
178
|
+
};
|
package/dist/git/errors.d.ts
CHANGED
|
@@ -4,3 +4,8 @@ export declare const createGitObjectMissingError: (filepath: string, oid: string
|
|
|
4
4
|
export declare const isGitObjectMissingError: (err: unknown) => err is Error;
|
|
5
5
|
export declare const createGitServerUnsupportedError: (url: string, missing: string) => Error;
|
|
6
6
|
export declare const isGitServerUnsupportedError: (err: unknown) => err is Error;
|
|
7
|
+
export declare const createGitProxyError: (url: string, cause: unknown) => Error;
|
|
8
|
+
export declare const isGitProxyError: (err: unknown) => err is Error;
|
|
9
|
+
export declare const hasProxyConnectionCause: (err: unknown) => boolean;
|
|
10
|
+
export declare const createGitPackCorruptError: (detail: string) => Error;
|
|
11
|
+
export declare const isGitPackCorruptError: (err: unknown) => err is Error;
|
package/dist/git/errors.js
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
|
+
import { redactUrlCredentials } from "./redact-url.js";
|
|
1
2
|
const GIT_AUTH_ERROR = "GitAuthError";
|
|
2
3
|
const GIT_SERVER_UNSUPPORTED_ERROR = "GitServerUnsupportedError";
|
|
3
|
-
export const createGitAuthError = (status, url) => Object.assign(new Error(`Authentication required (HTTP ${status}) for ${url}`), { name: GIT_AUTH_ERROR });
|
|
4
|
+
export const createGitAuthError = (status, url) => Object.assign(new Error(`Authentication required (HTTP ${status}) for ${redactUrlCredentials(url)}`), { name: GIT_AUTH_ERROR });
|
|
4
5
|
export const isGitAuthError = (err) => err instanceof Error && err.name === GIT_AUTH_ERROR;
|
|
5
6
|
const GIT_OBJECT_MISSING_ERROR = "GitObjectMissingError";
|
|
6
7
|
export const createGitObjectMissingError = (filepath, oid) => Object.assign(new Error(`Object ${oid} for ${filepath} has not been fetched`), { name: GIT_OBJECT_MISSING_ERROR });
|
|
7
8
|
export const isGitObjectMissingError = (err) => err instanceof Error && err.name === GIT_OBJECT_MISSING_ERROR;
|
|
8
|
-
export const createGitServerUnsupportedError = (url, missing) => Object.assign(new Error(`Server does not support required git feature (${missing}): ${url}`), { name: GIT_SERVER_UNSUPPORTED_ERROR });
|
|
9
|
+
export const createGitServerUnsupportedError = (url, missing) => Object.assign(new Error(`Server does not support required git feature (${missing}): ${redactUrlCredentials(url)}`), { name: GIT_SERVER_UNSUPPORTED_ERROR });
|
|
9
10
|
export const isGitServerUnsupportedError = (err) => err instanceof Error && err.name === GIT_SERVER_UNSUPPORTED_ERROR;
|
|
11
|
+
const GIT_PROXY_ERROR = "GitProxyError";
|
|
12
|
+
export const createGitProxyError = (url, cause) => Object.assign(new Error(`Proxy connection failed while requesting ${redactUrlCredentials(url)}`, { cause }), { name: GIT_PROXY_ERROR });
|
|
13
|
+
export const isGitProxyError = (err) => err instanceof Error && err.name === GIT_PROXY_ERROR;
|
|
14
|
+
export const hasProxyConnectionCause = (err) => {
|
|
15
|
+
let current = err;
|
|
16
|
+
for (let depth = 0; depth < 5 && current instanceof Error; depth++) {
|
|
17
|
+
if (current.code === "UND_ERR_PRX_CONN") {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
current = current.cause;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
24
|
+
const GIT_PACK_CORRUPT_ERROR = "GitPackCorruptError";
|
|
25
|
+
export const createGitPackCorruptError = (detail) => Object.assign(new Error(`Corrupt git pack data: ${detail}`), {
|
|
26
|
+
name: GIT_PACK_CORRUPT_ERROR,
|
|
27
|
+
});
|
|
28
|
+
export const isGitPackCorruptError = (err) => err instanceof Error && err.name === GIT_PACK_CORRUPT_ERROR;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type TreeEntry = {
|
|
2
|
+
mode: number;
|
|
3
|
+
name: string;
|
|
4
|
+
oid: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const isTreeMode: (mode: number) => boolean;
|
|
7
|
+
export declare const isGitlinkMode: (mode: number) => boolean;
|
|
8
|
+
export declare const isSymlinkMode: (mode: number) => boolean;
|
|
9
|
+
export declare const hashObject: (typeName: string, content: Buffer) => string;
|
|
10
|
+
export declare const parseTree: (data: Buffer) => TreeEntry[];
|
|
11
|
+
export declare const commitTreeOid: (data: Buffer) => string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { createGitPackCorruptError } from "./errors.js";
|
|
3
|
+
const SP = 0x20;
|
|
4
|
+
const NUL = 0x00;
|
|
5
|
+
const MODE_TYPE_MASK = 0o170000;
|
|
6
|
+
const MODE_TREE = 0o040000;
|
|
7
|
+
const MODE_GITLINK = 0o160000;
|
|
8
|
+
const MODE_SYMLINK = 0o120000;
|
|
9
|
+
export const isTreeMode = (mode) => (mode & MODE_TYPE_MASK) === MODE_TREE;
|
|
10
|
+
export const isGitlinkMode = (mode) => (mode & MODE_TYPE_MASK) === MODE_GITLINK;
|
|
11
|
+
export const isSymlinkMode = (mode) => (mode & MODE_TYPE_MASK) === MODE_SYMLINK;
|
|
12
|
+
export const hashObject = (typeName, content) => createHash("sha1")
|
|
13
|
+
.update(`${typeName} ${content.length}\0`)
|
|
14
|
+
.update(content)
|
|
15
|
+
.digest("hex");
|
|
16
|
+
export const parseTree = (data) => {
|
|
17
|
+
const entries = [];
|
|
18
|
+
let pos = 0;
|
|
19
|
+
while (pos < data.length) {
|
|
20
|
+
const sp = data.indexOf(SP, pos);
|
|
21
|
+
if (sp === -1 || sp === pos) {
|
|
22
|
+
throw createGitPackCorruptError("malformed tree entry (mode)");
|
|
23
|
+
}
|
|
24
|
+
const mode = Number.parseInt(data.toString("latin1", pos, sp), 8);
|
|
25
|
+
if (Number.isNaN(mode)) {
|
|
26
|
+
throw createGitPackCorruptError("malformed tree entry (mode)");
|
|
27
|
+
}
|
|
28
|
+
const nul = data.indexOf(NUL, sp + 1);
|
|
29
|
+
if (nul === -1 || nul === sp + 1 || nul + 21 > data.length) {
|
|
30
|
+
throw createGitPackCorruptError("malformed tree entry (name/oid)");
|
|
31
|
+
}
|
|
32
|
+
const name = data.toString("utf-8", sp + 1, nul);
|
|
33
|
+
const oid = data.toString("hex", nul + 1, nul + 21);
|
|
34
|
+
entries.push({ mode, name, oid });
|
|
35
|
+
pos = nul + 21;
|
|
36
|
+
}
|
|
37
|
+
return entries;
|
|
38
|
+
};
|
|
39
|
+
const OID_HEX_PATTERN = /^[0-9a-f]{40}$/;
|
|
40
|
+
export const commitTreeOid = (data) => {
|
|
41
|
+
if (data.toString("latin1", 0, 5) !== "tree ") {
|
|
42
|
+
throw createGitPackCorruptError("malformed commit (tree header)");
|
|
43
|
+
}
|
|
44
|
+
const oid = data.toString("latin1", 5, 45);
|
|
45
|
+
if (!OID_HEX_PATTERN.test(oid)) {
|
|
46
|
+
throw createGitPackCorruptError("malformed commit (tree oid)");
|
|
47
|
+
}
|
|
48
|
+
return oid;
|
|
49
|
+
};
|
package/dist/git/http.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const normalizeRepoUrl: (url: string) => string;
|
|
2
|
-
export declare const getInfoRefs: (repoUrl: string) => Promise<Buffer>;
|
|
3
|
-
export declare const postUploadPack: (repoUrl: string, body: Buffer) => Promise<Buffer>;
|
|
2
|
+
export declare const getInfoRefs: (repoUrl: string, signal?: AbortSignal) => Promise<Buffer>;
|
|
3
|
+
export declare const postUploadPack: (repoUrl: string, body: Buffer, signal?: AbortSignal) => Promise<Buffer>;
|