proxylang 0.1.7 → 0.2.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/dist/cli.js +6 -7
- package/dist/index.d.ts +21 -54
- package/dist/index.js +2 -21
- package/dist/{profile-build-BLB8hvyw.js → profile-build-jJlIs97b.js} +26 -88
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { Q as requestSchema, R as compile, U as targetCatalog, i as buildToDirectory, n as profileBuildFailure, q as StaticRuleSetUnknownError, r as runBuild, z as explain } from "./profile-build-jJlIs97b.js";
|
|
3
3
|
import { open } from "node:fs/promises";
|
|
4
4
|
import { resolve } from "node:path";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
@@ -16,7 +16,6 @@ const failure = (code) => {
|
|
|
16
16
|
};
|
|
17
17
|
const usages = {
|
|
18
18
|
"profile-build": ["proxylang profile-build config.ts --out DIRECTORY [--validation]"],
|
|
19
|
-
"surge-build": ["proxylang surge-build config.ts --out DIRECTORY [--validation]"],
|
|
20
19
|
targets: ["proxylang targets"],
|
|
21
20
|
check: ["proxylang check config.ts"],
|
|
22
21
|
explain: ["proxylang explain config.ts --target ID --request JSON", "proxylang explain config.ts --target ID --request-file FILE"],
|
|
@@ -85,7 +84,7 @@ async function main(args) {
|
|
|
85
84
|
});
|
|
86
85
|
return 0;
|
|
87
86
|
}
|
|
88
|
-
if (command === "
|
|
87
|
+
if (command === "profile-build") return profileBuildCommand(file, rest);
|
|
89
88
|
if (![
|
|
90
89
|
"check",
|
|
91
90
|
"explain",
|
|
@@ -166,9 +165,9 @@ async function main(args) {
|
|
|
166
165
|
});
|
|
167
166
|
return built.exitCode;
|
|
168
167
|
}
|
|
169
|
-
async function
|
|
168
|
+
async function profileBuildCommand(file, args) {
|
|
170
169
|
const invalid = () => {
|
|
171
|
-
print(
|
|
170
|
+
print(profileBuildFailure("INVALID_ARGUMENTS"));
|
|
172
171
|
return 1;
|
|
173
172
|
};
|
|
174
173
|
if (!file?.trim() || file.startsWith("-")) return invalid();
|
|
@@ -192,10 +191,10 @@ async function surgeBuildCommand(file, args, portable) {
|
|
|
192
191
|
const loaded = await tsImport(pathToFileURL(resolve(file)).href, import.meta.url);
|
|
193
192
|
config = loaded.default?.__esModule === true ? loaded.default.default : loaded.default;
|
|
194
193
|
} catch {
|
|
195
|
-
print(
|
|
194
|
+
print(profileBuildFailure("PROFILE_DEFINITION_FAILED", validation));
|
|
196
195
|
return 1;
|
|
197
196
|
}
|
|
198
|
-
const result =
|
|
197
|
+
const result = await runBuild(config, output, { validation });
|
|
199
198
|
print(result);
|
|
200
199
|
return result.exitCode;
|
|
201
200
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -586,31 +586,20 @@ export declare function compile(input: unknown): Compilation;
|
|
|
586
586
|
export declare function explain(compilation: Compilation, target: string, request: Request): Explanation;
|
|
587
587
|
//#endregion
|
|
588
588
|
//#region src/surge-definitions.d.ts
|
|
589
|
-
|
|
590
|
-
builtin: string;
|
|
591
|
-
}>;
|
|
592
|
-
type Destination = ProxyNode | ProxyGroupDefinition | SurgeTunnel | Builtin;
|
|
593
|
-
interface ProxyGroupDefinition<A extends GroupAlgorithm = Extract<GroupAlgorithm, {
|
|
594
|
-
type: "select" | "surge-smart";
|
|
595
|
-
}>, D extends ProfileDestination = Destination> {
|
|
589
|
+
interface ProxyGroupDefinition {
|
|
596
590
|
readonly type: "proxy-group";
|
|
597
591
|
readonly id: string;
|
|
598
592
|
readonly name: string;
|
|
599
|
-
readonly algorithm:
|
|
600
|
-
readonly members: readonly
|
|
593
|
+
readonly algorithm: GroupAlgorithm;
|
|
594
|
+
readonly members: readonly ProfileDestination[];
|
|
601
595
|
readonly url?: string;
|
|
602
596
|
readonly intervalSeconds?: number;
|
|
603
597
|
readonly timeoutSeconds?: number;
|
|
604
598
|
}
|
|
605
|
-
type RouteDefinition
|
|
599
|
+
type RouteDefinition = {
|
|
606
600
|
readonly type: "route";
|
|
607
|
-
readonly when:
|
|
608
|
-
readonly to:
|
|
609
|
-
};
|
|
610
|
-
type SurgeProfileDefinition = Omit<SurgeProfileInput, "groups" | "rules" | "fallback"> & {
|
|
611
|
-
readonly groups: readonly ProxyGroupDefinition[];
|
|
612
|
-
readonly routes: readonly RouteDefinition[];
|
|
613
|
-
readonly fallback: Destination;
|
|
601
|
+
readonly when: ProfileCondition;
|
|
602
|
+
readonly to: ProfileDestination;
|
|
614
603
|
};
|
|
615
604
|
export declare class ProfileDefinitionError extends Error {
|
|
616
605
|
readonly code: string;
|
|
@@ -633,19 +622,18 @@ export declare const outbound: {
|
|
|
633
622
|
readonly builtin: "REJECT-TINYGIF";
|
|
634
623
|
}>;
|
|
635
624
|
};
|
|
636
|
-
export declare function defineProxyGroup
|
|
637
|
-
export declare function defineRoute
|
|
638
|
-
export declare function defineRoutes
|
|
639
|
-
readonly when: readonly
|
|
640
|
-
readonly to:
|
|
641
|
-
}): RouteDefinition
|
|
625
|
+
export declare function defineProxyGroup(input: Omit<ProxyGroupDefinition, "type">): ProxyGroupDefinition;
|
|
626
|
+
export declare function defineRoute(input: Omit<RouteDefinition, "type">): RouteDefinition;
|
|
627
|
+
export declare function defineRoutes(input: {
|
|
628
|
+
readonly when: readonly ProfileCondition[];
|
|
629
|
+
readonly to: ProfileDestination;
|
|
630
|
+
}): RouteDefinition[];
|
|
642
631
|
export declare function selectProxies(nodes: readonly ProxyNode[], query?: {
|
|
643
632
|
ids?: readonly string[];
|
|
644
633
|
regions?: readonly string[];
|
|
645
634
|
providers?: readonly string[];
|
|
646
635
|
tags?: readonly string[];
|
|
647
636
|
}): ProxyNode[];
|
|
648
|
-
export declare function defineSurgeProfile(input: SurgeProfileDefinition): SurgeProfileInput;
|
|
649
637
|
//#endregion
|
|
650
638
|
//#region src/profile.d.ts
|
|
651
639
|
type DeepReadonly<T> = T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]>; } : T;
|
|
@@ -662,8 +650,7 @@ type ProfileCondition = Exclude<Match | SurgeCondition, {
|
|
|
662
650
|
readonly noResolve?: boolean;
|
|
663
651
|
readonly extendedMatching?: boolean;
|
|
664
652
|
};
|
|
665
|
-
|
|
666
|
-
type ProfileDestination = ProxyNode | ProfileProxyGroup | SurgeTunnel | TailscaleEndpoint | {
|
|
653
|
+
type ProfileDestination = ProxyNode | ProxyGroupDefinition | SurgeTunnel | TailscaleEndpoint | {
|
|
667
654
|
readonly builtin: "DIRECT" | "REJECT" | "REJECT-DROP" | "REJECT-NO-DROP" | "REJECT-TINYGIF";
|
|
668
655
|
};
|
|
669
656
|
type SurgeConfig = Pick<SurgeProfileInput, "managed" | "general" | "hosts" | "names">;
|
|
@@ -674,8 +661,8 @@ type ProfileDefinition = {
|
|
|
674
661
|
readonly version: string;
|
|
675
662
|
};
|
|
676
663
|
readonly nodes: readonly ProxyNode[];
|
|
677
|
-
readonly groups: readonly ProxyGroupDefinition
|
|
678
|
-
readonly routes: readonly RouteDefinition
|
|
664
|
+
readonly groups: readonly ProxyGroupDefinition[];
|
|
665
|
+
readonly routes: readonly RouteDefinition[];
|
|
679
666
|
readonly fallback: ProfileDestination;
|
|
680
667
|
readonly endpoints?: readonly (SurgeTunnel | TailscaleEndpoint)[];
|
|
681
668
|
readonly surge?: DeepReadonly<SurgeConfig>;
|
|
@@ -966,22 +953,12 @@ type ProxyNodeArtifact = {
|
|
|
966
953
|
export declare function compileProxyNodes(input: unknown): ProxyNodeCompilation;
|
|
967
954
|
export declare function renderProxyNodes(compilation: ProxyNodeCompilation, resolveSecret: (token: Secret) => string | undefined): ProxyNodeArtifact;
|
|
968
955
|
//#endregion
|
|
969
|
-
//#region src/
|
|
970
|
-
/** Bind shared names only for included resources; explicit input mappings remain compiler-checked. */
|
|
971
|
-
export declare function surgeProfile(input: SurgeProfileInput, names?: Readonly<Record<string, string>>): SurgeProfileInput;
|
|
972
|
-
/** Stable queries produce native-profile policy references without consumer mapping code. */
|
|
973
|
-
export declare function surgeMembers(nodes: readonly ProxyNode[], query?: Parameters<typeof selectNodes>[1]): SurgePolicy[];
|
|
974
|
-
//#endregion
|
|
975
|
-
//#region src/surge-host.d.ts
|
|
976
|
-
/** Complete-profile batches use the out symlink protocol; the Program host remains unchanged. */
|
|
977
|
-
export declare function buildSurgeProfilesToDirectory(profiles: Readonly<Record<string, SurgeProfileInput>>, output: string, resolveSecret?: (token: Secret) => string | undefined): Promise<BuildResult>;
|
|
978
|
-
//#endregion
|
|
979
|
-
//#region src/build-core.d.ts
|
|
956
|
+
//#region src/profile-build.d.ts
|
|
980
957
|
type BuildContext = {
|
|
981
958
|
readonly validation: boolean;
|
|
982
959
|
};
|
|
983
|
-
type BuildDefinition
|
|
984
|
-
readonly profiles: Readonly<Record<string,
|
|
960
|
+
type BuildDefinition = {
|
|
961
|
+
readonly profiles: Readonly<Record<string, Profile>>;
|
|
985
962
|
readonly preflight?: () => readonly string[];
|
|
986
963
|
readonly resolveSecret?: (token: Secret, context: BuildContext) => string | undefined;
|
|
987
964
|
};
|
|
@@ -990,21 +967,11 @@ type ProfileBuildResult = BuildResult & {
|
|
|
990
967
|
readonly validation: boolean;
|
|
991
968
|
readonly profileCount: number;
|
|
992
969
|
};
|
|
993
|
-
|
|
994
|
-
//#region src/surge-build.d.ts
|
|
995
|
-
type SurgeBuildContext = BuildContext;
|
|
996
|
-
type SurgeBuildDefinition = BuildDefinition$1<SurgeProfileInput>;
|
|
997
|
-
type SurgeBuildResult = ProfileBuildResult;
|
|
998
|
-
export declare function defineSurgeBuild(input: SurgeBuildDefinition): SurgeBuildDefinition;
|
|
999
|
-
export declare function runSurgeBuild(input: SurgeBuildDefinition, output: string, options?: {
|
|
1000
|
-
readonly validation?: boolean;
|
|
1001
|
-
}): Promise<SurgeBuildResult>;
|
|
1002
|
-
//#endregion
|
|
1003
|
-
//#region src/profile-build.d.ts
|
|
1004
|
-
type BuildDefinition = BuildDefinition$1<Profile>;
|
|
970
|
+
/** Capture data and callback references before application preflight can change its source. */
|
|
1005
971
|
export declare function defineBuild(input: BuildDefinition): BuildDefinition;
|
|
972
|
+
/** Pure orchestration result; the CLI owns stdout and process exit status. */
|
|
1006
973
|
export declare function runBuild(input: BuildDefinition, output: string, options?: {
|
|
1007
974
|
readonly validation?: boolean;
|
|
1008
975
|
}): Promise<ProfileBuildResult>;
|
|
1009
976
|
//#endregion
|
|
1010
|
-
export type { Artifact, BuildContext, BuildDefinition, BuildResult, CaseResult, Compilation, DeepReadonly,
|
|
977
|
+
export type { Artifact, BuildContext, BuildDefinition, BuildResult, CaseResult, Compilation, DeepReadonly, Profile, ProfileBuildResult, ProfileCompilation, ProfileCondition, ProfileDefinition, ProfileDestination, ProxyBuilder, ProxyGroupDefinition, ProxyNodeArtifact, ProxyNodeCompilation, ProxyNodeInput, RouteDefinition, StrategyGroupCompilation, StrategyGroupInput, SurgeCondition, SurgeConfig, SurgeGeneral, SurgeGroup, SurgeHost, SurgePolicy, SurgeProfileArtifact, SurgeProfileCompilation, SurgeProfileInput, SurgeRule, SurgeTunnel, TargetPlan };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as defineRoute, B as compileStrategyGroups, C as strategy, D as defineProfile, E as compileProfile, F as renderSurgeProfile, G as surgeProxy, H as nativeNameSchema, I as renderSurgeProfiles, J as assertData, K as validateProxyOptions, L as secretReader, M as outbound, N as selectProxies, O as ProfileDefinitionError, P as compileSurgeProfile, R as compile, S as slot, T as use, U as targetCatalog, V as isReservedNativeName, W as RenderError, X as idSchema, Y as deepFreeze, Z as nodeSchema, _ as ruleSet, a as render, b as sequence, c as direct, d as mihomo, f as policy, g as rule, h as route, i as buildToDirectory, j as defineRoutes, k as defineProxyGroup, l as group, m as reject, o as block, p as proxy, q as StaticRuleSetUnknownError, r as runBuild, s as defineConfig, t as defineBuild, u as match, v as secret, w as surge, x as singbox, y as selectNodes, z as explain } from "./profile-build-jJlIs97b.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
//#region src/proxy-fragments.ts
|
|
4
4
|
const inputSchema = z.strictObject({
|
|
@@ -129,23 +129,4 @@ function renderProxyNodes(compilation, resolveSecret) {
|
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
131
|
//#endregion
|
|
132
|
-
|
|
133
|
-
/** Bind shared names only for included resources; explicit input mappings remain compiler-checked. */
|
|
134
|
-
function surgeProfile(input, names = {}) {
|
|
135
|
-
const bindings = {};
|
|
136
|
-
for (const node of input.nodes) bindings[node.id] = names[node.id] ?? node.label ?? node.id;
|
|
137
|
-
for (const resource of [...input.tunnels ?? [], ...input.groups]) bindings[resource.id] = names[resource.id] ?? resource.id;
|
|
138
|
-
return {
|
|
139
|
-
...input,
|
|
140
|
-
names: {
|
|
141
|
-
...bindings,
|
|
142
|
-
...input.names
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
/** Stable queries produce native-profile policy references without consumer mapping code. */
|
|
147
|
-
function surgeMembers(nodes, query = {}) {
|
|
148
|
-
return selectNodes(nodes, query).map((ref) => ({ ref }));
|
|
149
|
-
}
|
|
150
|
-
//#endregion
|
|
151
|
-
export { ProfileDefinitionError, RenderError, StaticRuleSetUnknownError, block, buildSurgeProfilesToDirectory, buildToDirectory, compile, compileProfile, compileProxyNodes, compileStrategyGroups, compileSurgeProfile, defineBuild, defineConfig, defineProfile, defineProxyGroup, defineRoute, defineRoutes, defineSurgeBuild, defineSurgeProfile, direct, explain, group, match, mihomo, outbound, policy, proxy, reject, render, renderProxyNodes, renderSurgeProfile, renderSurgeProfiles, route, rule, ruleSet, runBuild, runSurgeBuild, secret, selectNodes, selectProxies, sequence, singbox, slot, strategy, surge, surgeMembers, surgeProfile, targetCatalog, use };
|
|
132
|
+
export { ProfileDefinitionError, RenderError, StaticRuleSetUnknownError, block, buildToDirectory, compile, compileProfile, compileProxyNodes, compileStrategyGroups, compileSurgeProfile, defineBuild, defineConfig, defineProfile, defineProxyGroup, defineRoute, defineRoutes, direct, explain, group, match, mihomo, outbound, policy, proxy, reject, render, renderProxyNodes, renderSurgeProfile, renderSurgeProfiles, route, rule, ruleSet, runBuild, secret, selectNodes, selectProxies, sequence, singbox, slot, strategy, surge, targetCatalog, use };
|
|
@@ -2101,7 +2101,7 @@ function selectProxies(nodes, query = {}) {
|
|
|
2101
2101
|
for (const values of Object.values(query)) if (values !== void 0 && !Array.isArray(values)) fail$1("DEFINITION_NOT_DATA");
|
|
2102
2102
|
return nodes.filter((node) => (!query.ids || query.ids.includes(node.id)) && (!query.regions || node.region !== void 0 && query.regions.includes(node.region)) && (!query.providers || node.provider !== void 0 && query.providers.includes(node.provider)) && (!query.tags || query.tags.every((tag) => node.tags?.includes(tag))));
|
|
2103
2103
|
}
|
|
2104
|
-
function
|
|
2104
|
+
function lowerSurgeProfile(input) {
|
|
2105
2105
|
inspectDefinition(input);
|
|
2106
2106
|
exactDefinition(input, [
|
|
2107
2107
|
"target",
|
|
@@ -2374,7 +2374,7 @@ function compileProfile(input) {
|
|
|
2374
2374
|
if (profile.target.engine === "surge") {
|
|
2375
2375
|
if (profile.singBox !== void 0) fail("PROFILE_EXTENSION_UNSUPPORTED");
|
|
2376
2376
|
if (profile.endpoints?.some((endpoint) => endpoint.type === "sing-box-tailscale")) fail("PROFILE_ENDPOINT_UNSUPPORTED");
|
|
2377
|
-
const compilation = compileSurgeProfile(
|
|
2377
|
+
const compilation = compileSurgeProfile(lowerSurgeProfile({
|
|
2378
2378
|
target: profile.target,
|
|
2379
2379
|
...profile.surge,
|
|
2380
2380
|
nodes: profile.nodes,
|
|
@@ -3094,14 +3094,8 @@ async function publishProfiles(files, surgeDirectory, io = { rename }) {
|
|
|
3094
3094
|
if (failure) throw new SurgePublishError(failure.message === "PROFILE_PUBLISH_CLEANUP_FAILED" ? committed ? "PUBLISHED_CLEANUP_FAILED" : "FAILED_CLEANUP_REQUIRED" : failure.message, committed);
|
|
3095
3095
|
}
|
|
3096
3096
|
//#endregion
|
|
3097
|
-
//#region src/
|
|
3098
|
-
|
|
3099
|
-
async function buildSurgeProfilesToDirectory(profiles, output, resolveSecret = (token) => process.env[token.name]) {
|
|
3100
|
-
if (typeof output !== "string" || !output.trim()) return {
|
|
3101
|
-
published: false,
|
|
3102
|
-
exitCode: 1,
|
|
3103
|
-
code: "INVALID_OUTPUT_DIRECTORY"
|
|
3104
|
-
};
|
|
3097
|
+
//#region src/profile-build.ts
|
|
3098
|
+
async function publish(profiles, output, resolver) {
|
|
3105
3099
|
try {
|
|
3106
3100
|
const entries = Object.entries(profiles);
|
|
3107
3101
|
if (!entries.length || entries.length > 16 || entries.some(([id]) => !/^[a-z0-9][a-z0-9-]*$/.test(id))) return {
|
|
@@ -3109,14 +3103,26 @@ async function buildSurgeProfilesToDirectory(profiles, output, resolveSecret = (
|
|
|
3109
3103
|
exitCode: 1,
|
|
3110
3104
|
code: "INVALID_PROFILE_FILENAMES"
|
|
3111
3105
|
};
|
|
3112
|
-
const compiled = entries.map(([,
|
|
3113
|
-
|
|
3106
|
+
const compiled = entries.map(([, profile]) => compileProfile(profile));
|
|
3107
|
+
const invalid = compiled.find((profile) => !profile.ok);
|
|
3108
|
+
if (invalid) return {
|
|
3114
3109
|
published: false,
|
|
3115
3110
|
exitCode: 1,
|
|
3116
|
-
code: "COMPILATION_FAILED"
|
|
3111
|
+
code: invalid.engine === "invalid" ? invalid.code : "COMPILATION_FAILED"
|
|
3117
3112
|
};
|
|
3118
|
-
|
|
3119
|
-
|
|
3113
|
+
if (compiled.some((profile) => profile.engine === "sing-box" && profile.compilation.plans.some((plan) => plan.program.endpoints?.some((endpoint) => pathsOverlap(resolve(output), endpoint.stateDirectory))))) return {
|
|
3114
|
+
published: false,
|
|
3115
|
+
exitCode: 1,
|
|
3116
|
+
code: "ENDPOINT_STATE_OVERLAP"
|
|
3117
|
+
};
|
|
3118
|
+
const read = secretReader(resolver);
|
|
3119
|
+
const files = /* @__PURE__ */ new Map();
|
|
3120
|
+
for (const [index, profile] of compiled.entries()) {
|
|
3121
|
+
if (profile.engine === "invalid") throw new Error();
|
|
3122
|
+
const artifacts = profile.engine === "surge" ? renderSurgeProfiles([profile.compilation], read) : render(profile.compilation, read);
|
|
3123
|
+
files.set(`${entries[index][0]}.${profile.engine === "surge" ? "conf" : "json"}`, artifacts[0].content);
|
|
3124
|
+
}
|
|
3125
|
+
await publishProfiles(files, output);
|
|
3120
3126
|
return {
|
|
3121
3127
|
published: true,
|
|
3122
3128
|
exitCode: 0,
|
|
@@ -3138,8 +3144,6 @@ async function buildSurgeProfilesToDirectory(profiles, output, resolveSecret = (
|
|
|
3138
3144
|
};
|
|
3139
3145
|
}
|
|
3140
3146
|
}
|
|
3141
|
-
//#endregion
|
|
3142
|
-
//#region src/build-core.ts
|
|
3143
3147
|
function record(value, keys) {
|
|
3144
3148
|
if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new ProfileDefinitionError("INVALID_BUILD_DEFINITION");
|
|
3145
3149
|
for (const key of Reflect.ownKeys(value)) {
|
|
@@ -3148,7 +3152,7 @@ function record(value, keys) {
|
|
|
3148
3152
|
}
|
|
3149
3153
|
}
|
|
3150
3154
|
/** Capture data and callback references before application preflight can change its source. */
|
|
3151
|
-
function
|
|
3155
|
+
function defineBuild(input) {
|
|
3152
3156
|
try {
|
|
3153
3157
|
record(input, [
|
|
3154
3158
|
"profiles",
|
|
@@ -3158,7 +3162,7 @@ function captureBuild(input, snapshot) {
|
|
|
3158
3162
|
record(input.profiles);
|
|
3159
3163
|
for (const callback of [input.preflight, input.resolveSecret]) if (callback !== void 0 && typeof callback !== "function") throw new Error();
|
|
3160
3164
|
return Object.freeze({
|
|
3161
|
-
profiles:
|
|
3165
|
+
profiles: snapshotProfile(input.profiles),
|
|
3162
3166
|
...input.preflight === void 0 ? {} : { preflight: input.preflight },
|
|
3163
3167
|
...input.resolveSecret === void 0 ? {} : { resolveSecret: input.resolveSecret }
|
|
3164
3168
|
});
|
|
@@ -3177,7 +3181,7 @@ function profileBuildFailure(code, validation = false, profileCount = 0) {
|
|
|
3177
3181
|
};
|
|
3178
3182
|
}
|
|
3179
3183
|
/** Pure orchestration result; the CLI owns stdout and process exit status. */
|
|
3180
|
-
async function
|
|
3184
|
+
async function runBuild(input, output, options = {}) {
|
|
3181
3185
|
let validation;
|
|
3182
3186
|
try {
|
|
3183
3187
|
record(options, ["validation"]);
|
|
@@ -3188,7 +3192,7 @@ async function executeBuild(input, output, options, capture, publish) {
|
|
|
3188
3192
|
}
|
|
3189
3193
|
let definition;
|
|
3190
3194
|
try {
|
|
3191
|
-
definition =
|
|
3195
|
+
definition = defineBuild(input);
|
|
3192
3196
|
} catch {
|
|
3193
3197
|
return profileBuildFailure("INVALID_BUILD_DEFINITION", validation);
|
|
3194
3198
|
}
|
|
@@ -3220,70 +3224,4 @@ async function executeBuild(input, output, options, capture, publish) {
|
|
|
3220
3224
|
};
|
|
3221
3225
|
}
|
|
3222
3226
|
//#endregion
|
|
3223
|
-
|
|
3224
|
-
const surgeBuildFailure = profileBuildFailure;
|
|
3225
|
-
function defineSurgeBuild(input) {
|
|
3226
|
-
return captureBuild(input, snapshotDefinition);
|
|
3227
|
-
}
|
|
3228
|
-
function runSurgeBuild(input, output, options = {}) {
|
|
3229
|
-
return executeBuild(input, output, options, defineSurgeBuild, buildSurgeProfilesToDirectory);
|
|
3230
|
-
}
|
|
3231
|
-
//#endregion
|
|
3232
|
-
//#region src/profile-build.ts
|
|
3233
|
-
function defineBuild(input) {
|
|
3234
|
-
return captureBuild(input, snapshotProfile);
|
|
3235
|
-
}
|
|
3236
|
-
async function publish(profiles, output, resolver) {
|
|
3237
|
-
try {
|
|
3238
|
-
const entries = Object.entries(profiles);
|
|
3239
|
-
if (!entries.length || entries.length > 16 || entries.some(([id]) => !/^[a-z0-9][a-z0-9-]*$/.test(id))) return {
|
|
3240
|
-
published: false,
|
|
3241
|
-
exitCode: 1,
|
|
3242
|
-
code: "INVALID_PROFILE_FILENAMES"
|
|
3243
|
-
};
|
|
3244
|
-
const compiled = entries.map(([, profile]) => compileProfile(profile));
|
|
3245
|
-
const invalid = compiled.find((profile) => !profile.ok);
|
|
3246
|
-
if (invalid) return {
|
|
3247
|
-
published: false,
|
|
3248
|
-
exitCode: 1,
|
|
3249
|
-
code: invalid.engine === "invalid" ? invalid.code : "COMPILATION_FAILED"
|
|
3250
|
-
};
|
|
3251
|
-
if (compiled.some((profile) => profile.engine === "sing-box" && profile.compilation.plans.some((plan) => plan.program.endpoints?.some((endpoint) => pathsOverlap(resolve(output), endpoint.stateDirectory))))) return {
|
|
3252
|
-
published: false,
|
|
3253
|
-
exitCode: 1,
|
|
3254
|
-
code: "ENDPOINT_STATE_OVERLAP"
|
|
3255
|
-
};
|
|
3256
|
-
const read = secretReader(resolver);
|
|
3257
|
-
const files = /* @__PURE__ */ new Map();
|
|
3258
|
-
for (const [index, profile] of compiled.entries()) {
|
|
3259
|
-
if (profile.engine === "invalid") throw new Error();
|
|
3260
|
-
const artifacts = profile.engine === "surge" ? renderSurgeProfiles([profile.compilation], read) : render(profile.compilation, read);
|
|
3261
|
-
files.set(`${entries[index][0]}.${profile.engine === "surge" ? "conf" : "json"}`, artifacts[0].content);
|
|
3262
|
-
}
|
|
3263
|
-
await publishProfiles(files, output);
|
|
3264
|
-
return {
|
|
3265
|
-
published: true,
|
|
3266
|
-
exitCode: 0,
|
|
3267
|
-
code: "PUBLISHED",
|
|
3268
|
-
active: join(resolve(output), "out")
|
|
3269
|
-
};
|
|
3270
|
-
} catch (error) {
|
|
3271
|
-
if (error instanceof SurgePublishError) return {
|
|
3272
|
-
published: error.published,
|
|
3273
|
-
exitCode: error.published ? 2 : 1,
|
|
3274
|
-
code: error.message,
|
|
3275
|
-
...error.published ? { active: join(resolve(output), "out") } : {},
|
|
3276
|
-
...error.message === "PUBLISH_RECOVERY_REQUIRED" ? { hint: "out may be absent; preserve the lock, backup, generation and temporary pointer for manual recovery" } : {}
|
|
3277
|
-
};
|
|
3278
|
-
return {
|
|
3279
|
-
published: false,
|
|
3280
|
-
exitCode: 1,
|
|
3281
|
-
code: error instanceof RenderError ? error.code : "BUILD_FAILED"
|
|
3282
|
-
};
|
|
3283
|
-
}
|
|
3284
|
-
}
|
|
3285
|
-
function runBuild(input, output, options = {}) {
|
|
3286
|
-
return executeBuild(input, output, options, defineBuild, publish);
|
|
3287
|
-
}
|
|
3288
|
-
//#endregion
|
|
3289
|
-
export { deepFreeze as $, defineProfile as A, renderSurgeProfiles as B, sequence as C, surge$1 as D, strategy as E, defineSurgeProfile as F, isReservedNativeName as G, compile as H, outbound as I, RenderError as J, nativeNameSchema as K, selectProxies as L, defineProxyGroup as M, defineRoute as N, use as O, defineRoutes as P, assertData as Q, compileSurgeProfile as R, selectNodes as S, slot as T, explain as U, secretReader as V, compileStrategyGroups as W, validateProxyOptions as X, surgeProxy as Y, StaticRuleSetUnknownError as Z, reject as _, surgeBuildFailure as a, ruleSet as b, render as c, direct as d, idSchema as et, group as f, proxy as g, policy as h, runSurgeBuild as i, ProfileDefinitionError as j, compileProfile as k, block as l, mihomo as m, runBuild as n, requestSchema as nt, buildSurgeProfilesToDirectory as o, match as p, targetCatalog as q, defineSurgeBuild as r, buildToDirectory as s, defineBuild as t, nodeSchema as tt, defineConfig as u, route as v, singbox$1 as w, secret as x, rule as y, renderSurgeProfile as z };
|
|
3227
|
+
export { defineRoute as A, compileStrategyGroups as B, strategy as C, defineProfile as D, compileProfile as E, renderSurgeProfile as F, surgeProxy as G, nativeNameSchema as H, renderSurgeProfiles as I, assertData as J, validateProxyOptions as K, secretReader as L, outbound as M, selectProxies as N, ProfileDefinitionError as O, compileSurgeProfile as P, requestSchema as Q, compile as R, slot as S, use as T, targetCatalog as U, isReservedNativeName as V, RenderError as W, idSchema as X, deepFreeze as Y, nodeSchema as Z, ruleSet as _, render as a, sequence as b, direct as c, mihomo as d, policy as f, rule as g, route as h, buildToDirectory as i, defineRoutes as j, defineProxyGroup as k, group as l, reject as m, profileBuildFailure as n, block as o, proxy as p, StaticRuleSetUnknownError as q, runBuild as r, defineConfig as s, defineBuild as t, match as u, secret as v, surge$1 as w, singbox$1 as x, selectNodes as y, explain as z };
|
package/package.json
CHANGED