@h-rig/core 0.0.6-alpha.6 → 0.0.6-alpha.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/define-config.js +13 -2
- package/dist/src/index.js +12 -2
- package/dist/src/load-config.js +126 -5
- package/dist/src/rig-init-builder.js +1 -1
- package/package.json +2 -2
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
// packages/core/src/define-config.ts
|
|
3
3
|
import { Schema } from "effect";
|
|
4
4
|
import { RigConfig } from "@rig/contracts";
|
|
5
|
+
function applyConfigDefaults(raw) {
|
|
6
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
7
|
+
return raw;
|
|
8
|
+
const record = raw;
|
|
9
|
+
return {
|
|
10
|
+
...record,
|
|
11
|
+
plugins: Array.isArray(record.plugins) ? record.plugins : [],
|
|
12
|
+
workspace: record.workspace && typeof record.workspace === "object" && !Array.isArray(record.workspace) ? record.workspace : { mainRepo: ".", isolation: "worktree" }
|
|
13
|
+
};
|
|
14
|
+
}
|
|
5
15
|
function defineConfig(cfg) {
|
|
6
16
|
const runtimeByName = new Map;
|
|
7
17
|
const plugins = cfg.plugins ?? [];
|
|
@@ -10,7 +20,7 @@ function defineConfig(cfg) {
|
|
|
10
20
|
runtimeByName.set(plugin.name, plugin.__runtime);
|
|
11
21
|
}
|
|
12
22
|
}
|
|
13
|
-
const decoded = Schema.decodeUnknownSync(RigConfig)(cfg);
|
|
23
|
+
const decoded = Schema.decodeUnknownSync(RigConfig)(applyConfigDefaults(cfg));
|
|
14
24
|
const decodedPlugins = decoded.plugins.map((p) => {
|
|
15
25
|
const runtime = runtimeByName.get(p.name);
|
|
16
26
|
if (!runtime)
|
|
@@ -20,5 +30,6 @@ function defineConfig(cfg) {
|
|
|
20
30
|
return { ...decoded, plugins: decodedPlugins };
|
|
21
31
|
}
|
|
22
32
|
export {
|
|
23
|
-
defineConfig
|
|
33
|
+
defineConfig,
|
|
34
|
+
applyConfigDefaults
|
|
24
35
|
};
|
package/dist/src/index.js
CHANGED
|
@@ -48,6 +48,16 @@ function definePlugin(meta, runtime) {
|
|
|
48
48
|
// packages/core/src/define-config.ts
|
|
49
49
|
import { Schema as Schema2 } from "effect";
|
|
50
50
|
import { RigConfig } from "@rig/contracts";
|
|
51
|
+
function applyConfigDefaults(raw) {
|
|
52
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
53
|
+
return raw;
|
|
54
|
+
const record = raw;
|
|
55
|
+
return {
|
|
56
|
+
...record,
|
|
57
|
+
plugins: Array.isArray(record.plugins) ? record.plugins : [],
|
|
58
|
+
workspace: record.workspace && typeof record.workspace === "object" && !Array.isArray(record.workspace) ? record.workspace : { mainRepo: ".", isolation: "worktree" }
|
|
59
|
+
};
|
|
60
|
+
}
|
|
51
61
|
function defineConfig(cfg) {
|
|
52
62
|
const runtimeByName = new Map;
|
|
53
63
|
const plugins = cfg.plugins ?? [];
|
|
@@ -56,7 +66,7 @@ function defineConfig(cfg) {
|
|
|
56
66
|
runtimeByName.set(plugin.name, plugin.__runtime);
|
|
57
67
|
}
|
|
58
68
|
}
|
|
59
|
-
const decoded = Schema2.decodeUnknownSync(RigConfig)(cfg);
|
|
69
|
+
const decoded = Schema2.decodeUnknownSync(RigConfig)(applyConfigDefaults(cfg));
|
|
60
70
|
const decodedPlugins = decoded.plugins.map((p) => {
|
|
61
71
|
const runtime = runtimeByName.get(p.name);
|
|
62
72
|
if (!runtime)
|
|
@@ -263,7 +273,7 @@ function buildRigInitConfigSource(input) {
|
|
|
263
273
|
lines.push(` issueUpdates: "lifecycle",`);
|
|
264
274
|
lines.push(` projects: { enabled: false },`);
|
|
265
275
|
lines.push(` },`);
|
|
266
|
-
lines.push(` automation: { maxValidationAttempts: 30, maxPrFixIterations:
|
|
276
|
+
lines.push(` automation: { maxValidationAttempts: 30, maxPrFixIterations: 100500 },`);
|
|
267
277
|
lines.push(` pr: { mode: "auto", watchChecks: true, autoFixChecks: true, autoFixReview: true },`);
|
|
268
278
|
lines.push(` merge: { mode: "auto", method: "repo-default", deleteBranch: "repo-default", bypass: false },`);
|
|
269
279
|
lines.push(` issueAnalysis: { enabled: true, harness: "pi", mode: "continuous" },`);
|
package/dist/src/load-config.js
CHANGED
|
@@ -1,17 +1,138 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/core/src/load-config.ts
|
|
3
|
-
import { existsSync, readFileSync } from "fs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync } from "fs";
|
|
4
|
+
import { tmpdir } from "os";
|
|
5
|
+
import { dirname, join } from "path";
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from "url";
|
|
7
|
+
import { Schema as Schema2 } from "effect";
|
|
8
|
+
import { RigConfig as RigConfig2 } from "@rig/contracts";
|
|
9
|
+
|
|
10
|
+
// packages/core/src/define-config.ts
|
|
6
11
|
import { Schema } from "effect";
|
|
7
12
|
import { RigConfig } from "@rig/contracts";
|
|
13
|
+
function applyConfigDefaults(raw) {
|
|
14
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
15
|
+
return raw;
|
|
16
|
+
const record = raw;
|
|
17
|
+
return {
|
|
18
|
+
...record,
|
|
19
|
+
plugins: Array.isArray(record.plugins) ? record.plugins : [],
|
|
20
|
+
workspace: record.workspace && typeof record.workspace === "object" && !Array.isArray(record.workspace) ? record.workspace : { mainRepo: ".", isolation: "worktree" }
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// packages/core/src/load-config.ts
|
|
8
25
|
var TS_NAMES = ["rig.config.ts", "rig.config.mts"];
|
|
9
26
|
var JSON_NAMES = ["rig.config.json"];
|
|
27
|
+
function isModuleResolutionError(error) {
|
|
28
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
29
|
+
return message.includes("Cannot find module") || message.includes("Could not resolve");
|
|
30
|
+
}
|
|
31
|
+
function runningFromCompiledBinary() {
|
|
32
|
+
return import.meta.url.includes("$bunfs");
|
|
33
|
+
}
|
|
34
|
+
var runtimeBundleQueue = Promise.resolve();
|
|
35
|
+
function enqueueRuntimeBundle(operation) {
|
|
36
|
+
const next = runtimeBundleQueue.then(operation, operation);
|
|
37
|
+
runtimeBundleQueue = next.then(() => {
|
|
38
|
+
return;
|
|
39
|
+
}, () => {
|
|
40
|
+
return;
|
|
41
|
+
});
|
|
42
|
+
return next;
|
|
43
|
+
}
|
|
44
|
+
async function importConfigViaRuntimeBundleUnserialized(configPath) {
|
|
45
|
+
const bun = globalThis.Bun;
|
|
46
|
+
if (!bun?.build) {
|
|
47
|
+
throw new Error(`Failed to import ${configPath}: bare imports could not be resolved and no Bun.build runtime bundler is available.`);
|
|
48
|
+
}
|
|
49
|
+
const hostDir = (() => {
|
|
50
|
+
try {
|
|
51
|
+
return dirname(fileURLToPath(import.meta.url));
|
|
52
|
+
} catch {
|
|
53
|
+
return process.cwd();
|
|
54
|
+
}
|
|
55
|
+
})();
|
|
56
|
+
const configDir = dirname(configPath);
|
|
57
|
+
const UNRESOLVED_NAMESPACE = "rig-config-unresolved";
|
|
58
|
+
const hostResolverPlugin = {
|
|
59
|
+
name: "rig-host-package-resolver",
|
|
60
|
+
setup(build) {
|
|
61
|
+
build.onResolve({ filter: /^@rig\// }, (args) => {
|
|
62
|
+
const candidates = [
|
|
63
|
+
[args.path, configDir],
|
|
64
|
+
[args.path, hostDir],
|
|
65
|
+
[args.path.replace(/^@rig\//, "@h-rig/"), hostDir]
|
|
66
|
+
];
|
|
67
|
+
for (const [specifier, parent] of candidates) {
|
|
68
|
+
try {
|
|
69
|
+
const resolved = bun.resolveSync?.(specifier, parent);
|
|
70
|
+
if (resolved)
|
|
71
|
+
return { path: resolved };
|
|
72
|
+
} catch {}
|
|
73
|
+
}
|
|
74
|
+
return;
|
|
75
|
+
});
|
|
76
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
77
|
+
if (/^(?:node|bun):/.test(args.path))
|
|
78
|
+
return;
|
|
79
|
+
const parent = args.importer ? dirname(args.importer) : configDir;
|
|
80
|
+
try {
|
|
81
|
+
const resolved = bun.resolveSync?.(args.path, parent);
|
|
82
|
+
if (resolved)
|
|
83
|
+
return { path: resolved };
|
|
84
|
+
} catch {
|
|
85
|
+
return { path: args.path, namespace: UNRESOLVED_NAMESPACE };
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
});
|
|
89
|
+
build.onLoad({ filter: /.*/, namespace: UNRESOLVED_NAMESPACE }, (args) => ({
|
|
90
|
+
loader: "js",
|
|
91
|
+
contents: `module.exports = {};
|
|
92
|
+
throw new Error(${JSON.stringify(`Failed to bundle ${configPath}: Could not resolve: "${args.path}". Maybe you need to "bun install"?`)});
|
|
93
|
+
`
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const result = await bun.build({
|
|
98
|
+
entrypoints: [configPath],
|
|
99
|
+
target: "bun",
|
|
100
|
+
format: "esm",
|
|
101
|
+
throw: false,
|
|
102
|
+
plugins: [hostResolverPlugin]
|
|
103
|
+
});
|
|
104
|
+
if (!result.success || !result.outputs[0]) {
|
|
105
|
+
const detail = result.logs.map((log) => String(log)).join(`
|
|
106
|
+
`);
|
|
107
|
+
throw new Error(`Failed to bundle ${configPath}: ${detail || "unknown bundler error"}`);
|
|
108
|
+
}
|
|
109
|
+
const dir = mkdtempSync(join(tmpdir(), "rig-config-bundle-"));
|
|
110
|
+
try {
|
|
111
|
+
const bundledPath = join(dir, "rig.config.bundled.js");
|
|
112
|
+
await bun.write(bundledPath, await result.outputs[0].text());
|
|
113
|
+
return await import(pathToFileURL(bundledPath).href);
|
|
114
|
+
} finally {
|
|
115
|
+
try {
|
|
116
|
+
rmSync(dir, { recursive: true, force: true });
|
|
117
|
+
} catch {}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
10
120
|
async function loadConfig(cwd) {
|
|
11
121
|
for (const name of TS_NAMES) {
|
|
12
122
|
const p = join(cwd, name);
|
|
13
123
|
if (existsSync(p)) {
|
|
14
|
-
const mod = await
|
|
124
|
+
const mod = await enqueueRuntimeBundle(async () => {
|
|
125
|
+
if (runningFromCompiledBinary()) {
|
|
126
|
+
return importConfigViaRuntimeBundleUnserialized(p);
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
return await import(pathToFileURL(p).href);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
if (!isModuleResolutionError(error))
|
|
132
|
+
throw error;
|
|
133
|
+
return importConfigViaRuntimeBundleUnserialized(p);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
15
136
|
const raw = mod.default ?? mod.config;
|
|
16
137
|
return decodePreservingRuntime(raw);
|
|
17
138
|
}
|
|
@@ -35,7 +156,7 @@ function decodePreservingRuntime(raw) {
|
|
|
35
156
|
}
|
|
36
157
|
}
|
|
37
158
|
}
|
|
38
|
-
const decoded =
|
|
159
|
+
const decoded = Schema2.decodeUnknownSync(RigConfig2)(applyConfigDefaults(raw));
|
|
39
160
|
const plugins = decoded.plugins.map((p) => {
|
|
40
161
|
const runtime = runtimeByName.get(p.name);
|
|
41
162
|
if (!runtime)
|
|
@@ -43,7 +43,7 @@ function buildRigInitConfigSource(input) {
|
|
|
43
43
|
lines.push(` issueUpdates: "lifecycle",`);
|
|
44
44
|
lines.push(` projects: { enabled: false },`);
|
|
45
45
|
lines.push(` },`);
|
|
46
|
-
lines.push(` automation: { maxValidationAttempts: 30, maxPrFixIterations:
|
|
46
|
+
lines.push(` automation: { maxValidationAttempts: 30, maxPrFixIterations: 100500 },`);
|
|
47
47
|
lines.push(` pr: { mode: "auto", watchChecks: true, autoFixChecks: true, autoFixReview: true },`);
|
|
48
48
|
lines.push(` merge: { mode: "auto", method: "repo-default", deleteBranch: "repo-default", bypass: false },`);
|
|
49
49
|
lines.push(` issueAnalysis: { enabled: true, harness: "pi", mode: "continuous" },`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h-rig/core",
|
|
3
|
-
"version": "0.0.6-alpha.
|
|
3
|
+
"version": "0.0.6-alpha.61",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Rig package",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"main": "./dist/src/index.js",
|
|
32
32
|
"module": "./dist/src/index.js",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.
|
|
34
|
+
"@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.61",
|
|
35
35
|
"effect": "4.0.0-beta.78"
|
|
36
36
|
}
|
|
37
37
|
}
|