@dura-run/cli 0.1.5 → 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/README.md +36 -6
- package/dist/dura.js +3188 -370
- package/package.json +7 -2
- package/skills/dura-debug.md +360 -0
- package/skills/dura-deploy.md +272 -0
- package/skills/dura-develop.md +379 -0
- package/skills/dura-overview.md +196 -0
package/dist/dura.js
CHANGED
|
@@ -2708,20 +2708,20 @@ var init_logout = __esm(() => {
|
|
|
2708
2708
|
});
|
|
2709
2709
|
|
|
2710
2710
|
// src/templates/dura.json.ts
|
|
2711
|
-
function duraJsonTemplate(name) {
|
|
2711
|
+
function duraJsonTemplate(name, kind = "get") {
|
|
2712
|
+
const trigger = kind === "cron" ? { type: "cron", schedule: "0 * * * *" } : {
|
|
2713
|
+
type: "http",
|
|
2714
|
+
method: kind.toUpperCase(),
|
|
2715
|
+
path: "/hello",
|
|
2716
|
+
public: false
|
|
2717
|
+
};
|
|
2712
2718
|
const manifest = {
|
|
2713
2719
|
name,
|
|
2714
2720
|
automations: [
|
|
2715
2721
|
{
|
|
2716
2722
|
name: "hello",
|
|
2717
2723
|
entrypoint: "routes/hello.ts",
|
|
2718
|
-
triggers: [
|
|
2719
|
-
{
|
|
2720
|
-
type: "http",
|
|
2721
|
-
method: "GET",
|
|
2722
|
-
path: "/hello"
|
|
2723
|
-
}
|
|
2724
|
-
]
|
|
2724
|
+
triggers: [trigger]
|
|
2725
2725
|
}
|
|
2726
2726
|
]
|
|
2727
2727
|
};
|
|
@@ -2730,7 +2730,18 @@ function duraJsonTemplate(name) {
|
|
|
2730
2730
|
}
|
|
2731
2731
|
|
|
2732
2732
|
// src/templates/hello.ts
|
|
2733
|
-
|
|
2733
|
+
function helloTemplate(kind) {
|
|
2734
|
+
switch (kind) {
|
|
2735
|
+
case "post":
|
|
2736
|
+
return POST_TEMPLATE;
|
|
2737
|
+
case "cron":
|
|
2738
|
+
return CRON_TEMPLATE;
|
|
2739
|
+
case "get":
|
|
2740
|
+
default:
|
|
2741
|
+
return GET_TEMPLATE;
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
var GET_TEMPLATE = `import type { DuraRequest, DuraResponse } from "@dura/sdk";
|
|
2734
2745
|
|
|
2735
2746
|
export default async function handler(req: DuraRequest): Promise<DuraResponse> {
|
|
2736
2747
|
return {
|
|
@@ -2739,7 +2750,30 @@ export default async function handler(req: DuraRequest): Promise<DuraResponse> {
|
|
|
2739
2750
|
body: { message: "Hello from Dura!" },
|
|
2740
2751
|
};
|
|
2741
2752
|
}
|
|
2742
|
-
|
|
2753
|
+
`, POST_TEMPLATE = `import type { DuraRequest, DuraResponse } from "@dura/sdk";
|
|
2754
|
+
|
|
2755
|
+
export default async function handler(req: DuraRequest): Promise<DuraResponse> {
|
|
2756
|
+
const { name = "world" } = (req.body ?? {}) as { name?: string };
|
|
2757
|
+
return {
|
|
2758
|
+
status: 200,
|
|
2759
|
+
headers: { "content-type": "application/json" },
|
|
2760
|
+
body: { greeting: \`hello, \${name}\` },
|
|
2761
|
+
};
|
|
2762
|
+
}
|
|
2763
|
+
`, CRON_TEMPLATE = `import type { DuraRequest, DuraResponse } from "@dura/sdk";
|
|
2764
|
+
|
|
2765
|
+
export default async function handler(_req: DuraRequest): Promise<DuraResponse> {
|
|
2766
|
+
// Runs on the cron schedule defined in dura.json. Add your job here.
|
|
2767
|
+
return {
|
|
2768
|
+
status: 200,
|
|
2769
|
+
headers: { "content-type": "application/json" },
|
|
2770
|
+
body: { ranAt: new Date().toISOString() },
|
|
2771
|
+
};
|
|
2772
|
+
}
|
|
2773
|
+
`, HELLO_TEMPLATE;
|
|
2774
|
+
var init_hello = __esm(() => {
|
|
2775
|
+
HELLO_TEMPLATE = GET_TEMPLATE;
|
|
2776
|
+
});
|
|
2743
2777
|
|
|
2744
2778
|
// src/commands/new.ts
|
|
2745
2779
|
var exports_new = {};
|
|
@@ -2749,12 +2783,17 @@ __export(exports_new, {
|
|
|
2749
2783
|
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
2750
2784
|
import { join as join2, resolve } from "node:path";
|
|
2751
2785
|
function registerNewCommand(program2) {
|
|
2752
|
-
program2.command("new <name>").description("Scaffold a new Dura project").option("--dir <path>", "Parent directory (defaults to current dir)").option("--org <id>", "Organization ID for API registration").option("--template <slug>", "Fork a template as the starting point").action(async (name, opts, cmd) => {
|
|
2786
|
+
program2.command("new <name>").description("Scaffold a new Dura project").option("--dir <path>", "Parent directory (defaults to current dir)").option("--org <id>", "Organization ID for API registration").option("--template <slug>", "Fork a template as the starting point").option("--trigger <kind>", "Default trigger kind for the scaffold: get | post | cron", "get").action(async (name, opts, cmd) => {
|
|
2753
2787
|
const output = getOutput(cmd);
|
|
2754
2788
|
if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(name)) {
|
|
2755
2789
|
output.error("INVALID_NAME", "Project name must start with a letter and contain only letters, numbers, hyphens, and underscores");
|
|
2756
2790
|
return;
|
|
2757
2791
|
}
|
|
2792
|
+
const triggerKind = (opts.trigger ?? "get").toLowerCase();
|
|
2793
|
+
if (!["get", "post", "cron"].includes(triggerKind)) {
|
|
2794
|
+
output.error("INVALID_TRIGGER", `Unknown trigger kind: ${opts.trigger}`, "Use one of: get, post, cron");
|
|
2795
|
+
return;
|
|
2796
|
+
}
|
|
2758
2797
|
const parentDir = opts.dir ? resolve(opts.dir) : process.cwd();
|
|
2759
2798
|
const projectDir = join2(parentDir, name);
|
|
2760
2799
|
if (existsSync2(projectDir)) {
|
|
@@ -2802,8 +2841,8 @@ Set required secrets: ${result.requiredSecrets.join(", ")}`);
|
|
|
2802
2841
|
}
|
|
2803
2842
|
mkdirSync2(join2(projectDir, "routes"), { recursive: true });
|
|
2804
2843
|
mkdirSync2(join2(projectDir, "jobs"), { recursive: true });
|
|
2805
|
-
writeFileSync2(join2(projectDir, "dura.json"), duraJsonTemplate(name));
|
|
2806
|
-
writeFileSync2(join2(projectDir, "routes", "hello.ts"),
|
|
2844
|
+
writeFileSync2(join2(projectDir, "dura.json"), duraJsonTemplate(name, triggerKind));
|
|
2845
|
+
writeFileSync2(join2(projectDir, "routes", "hello.ts"), helloTemplate(triggerKind));
|
|
2807
2846
|
writeFileSync2(join2(projectDir, ".gitignore"), GITIGNORE_CONTENT);
|
|
2808
2847
|
const token = getAuthToken();
|
|
2809
2848
|
if (token) {
|
|
@@ -2847,36 +2886,61 @@ dist
|
|
|
2847
2886
|
`;
|
|
2848
2887
|
var init_new = __esm(() => {
|
|
2849
2888
|
init_src3();
|
|
2889
|
+
init_hello();
|
|
2850
2890
|
init_api_client();
|
|
2851
2891
|
init_config_store();
|
|
2852
2892
|
});
|
|
2853
2893
|
|
|
2894
|
+
// src/lib/project-id.ts
|
|
2895
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "node:fs";
|
|
2896
|
+
import { join as join3 } from "node:path";
|
|
2897
|
+
function resolveProjectId(opts = {}) {
|
|
2898
|
+
if (opts.project && opts.project.length > 0)
|
|
2899
|
+
return opts.project;
|
|
2900
|
+
const dir = opts.dir ?? process.cwd();
|
|
2901
|
+
const manifestPath = join3(dir, "dura.json");
|
|
2902
|
+
if (!existsSync3(manifestPath))
|
|
2903
|
+
return null;
|
|
2904
|
+
try {
|
|
2905
|
+
const raw = JSON.parse(readFileSync3(manifestPath, "utf-8"));
|
|
2906
|
+
return raw.projectId ?? null;
|
|
2907
|
+
} catch {
|
|
2908
|
+
return null;
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
var init_project_id = () => {};
|
|
2912
|
+
|
|
2854
2913
|
// src/commands/secrets.ts
|
|
2855
2914
|
var exports_secrets = {};
|
|
2856
2915
|
__export(exports_secrets, {
|
|
2857
2916
|
registerSecretsCommand: () => registerSecretsCommand
|
|
2858
2917
|
});
|
|
2859
2918
|
import { writeFileSync as writeFileSync3 } from "node:fs";
|
|
2860
|
-
import { join as
|
|
2919
|
+
import { join as join4 } from "node:path";
|
|
2861
2920
|
function resolveAuth(opts, output) {
|
|
2921
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
2922
|
+
if (!projectId) {
|
|
2923
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
2924
|
+
return null;
|
|
2925
|
+
}
|
|
2862
2926
|
const token = opts.token || getAuthToken();
|
|
2863
2927
|
if (!token) {
|
|
2864
2928
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
2865
2929
|
return null;
|
|
2866
2930
|
}
|
|
2867
2931
|
const apiUrl = opts.apiUrl || getApiUrl();
|
|
2868
|
-
return { client: new ApiClient(apiUrl, token) };
|
|
2932
|
+
return { client: new ApiClient(apiUrl, token), projectId };
|
|
2869
2933
|
}
|
|
2870
2934
|
function registerSecretsCommand(program2) {
|
|
2871
2935
|
const secrets = program2.command("secrets").description("Manage project secrets");
|
|
2872
|
-
secrets.command("set <name> <value>").description("Set a secret value").
|
|
2936
|
+
secrets.command("set <name> <value>").description("Set a secret value").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (name, value, opts, cmd) => {
|
|
2873
2937
|
const output = getOutput(cmd);
|
|
2874
2938
|
const auth = resolveAuth(opts, output);
|
|
2875
2939
|
if (!auth)
|
|
2876
2940
|
return;
|
|
2877
|
-
const { client } = auth;
|
|
2941
|
+
const { client, projectId } = auth;
|
|
2878
2942
|
try {
|
|
2879
|
-
const result = await client.put(`/api/v1/projects/${
|
|
2943
|
+
const result = await client.put(`/api/v1/projects/${projectId}/secrets`, { name, value });
|
|
2880
2944
|
output.success(result);
|
|
2881
2945
|
} catch (err) {
|
|
2882
2946
|
if (err instanceof Error) {
|
|
@@ -2884,14 +2948,14 @@ function registerSecretsCommand(program2) {
|
|
|
2884
2948
|
}
|
|
2885
2949
|
}
|
|
2886
2950
|
});
|
|
2887
|
-
secrets.command("list").description("List secret names (values never shown)").
|
|
2951
|
+
secrets.command("list").description("List secret names (values never shown)").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
|
|
2888
2952
|
const output = getOutput(cmd);
|
|
2889
2953
|
const auth = resolveAuth(opts, output);
|
|
2890
2954
|
if (!auth)
|
|
2891
2955
|
return;
|
|
2892
|
-
const { client } = auth;
|
|
2956
|
+
const { client, projectId } = auth;
|
|
2893
2957
|
try {
|
|
2894
|
-
const result = await client.get(`/api/v1/projects/${
|
|
2958
|
+
const result = await client.get(`/api/v1/projects/${projectId}/secrets`);
|
|
2895
2959
|
output.table(["Name", "Created", "Updated"], result.map((s) => [s.name, s.createdAt, s.updatedAt]));
|
|
2896
2960
|
} catch (err) {
|
|
2897
2961
|
if (err instanceof Error) {
|
|
@@ -2899,7 +2963,7 @@ function registerSecretsCommand(program2) {
|
|
|
2899
2963
|
}
|
|
2900
2964
|
}
|
|
2901
2965
|
});
|
|
2902
|
-
secrets.command("remove <name>").description("Remove a secret").
|
|
2966
|
+
secrets.command("remove <name>").description("Remove a secret").option("--project <id>", "Project ID (defaults to dura.json)").option("--confirm", "Confirm this destructive operation").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (name, opts, cmd) => {
|
|
2903
2967
|
const output = getOutput(cmd);
|
|
2904
2968
|
if (!opts.confirm) {
|
|
2905
2969
|
output.error("CONFIRM_REQUIRED", "This is a destructive operation. Re-run with --confirm to proceed.");
|
|
@@ -2908,9 +2972,9 @@ function registerSecretsCommand(program2) {
|
|
|
2908
2972
|
const auth = resolveAuth(opts, output);
|
|
2909
2973
|
if (!auth)
|
|
2910
2974
|
return;
|
|
2911
|
-
const { client } = auth;
|
|
2975
|
+
const { client, projectId } = auth;
|
|
2912
2976
|
try {
|
|
2913
|
-
await client.delete(`/api/v1/projects/${
|
|
2977
|
+
await client.delete(`/api/v1/projects/${projectId}/secrets/${name}`);
|
|
2914
2978
|
output.success({ deleted: true, name });
|
|
2915
2979
|
} catch (err) {
|
|
2916
2980
|
if (err instanceof Error) {
|
|
@@ -2918,17 +2982,16 @@ function registerSecretsCommand(program2) {
|
|
|
2918
2982
|
}
|
|
2919
2983
|
}
|
|
2920
2984
|
});
|
|
2921
|
-
secrets.command("pull").description("Write secrets to .env.local for local development").
|
|
2985
|
+
secrets.command("pull").description("Write secrets to .env.local for local development").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").option("--dir <path>", "Directory to write .env.local to", ".").action(async (opts, cmd) => {
|
|
2922
2986
|
const output = getOutput(cmd);
|
|
2923
2987
|
const auth = resolveAuth(opts, output);
|
|
2924
2988
|
if (!auth)
|
|
2925
2989
|
return;
|
|
2926
|
-
const { client } = auth;
|
|
2990
|
+
const { client, projectId } = auth;
|
|
2927
2991
|
try {
|
|
2928
|
-
await client.get(`/api/v1/projects/${
|
|
2929
|
-
const values = await client.get(`/api/v1/projects/${opts.project}/secrets/pull`);
|
|
2992
|
+
const values = await client.get(`/api/v1/projects/${projectId}/secrets/pull`);
|
|
2930
2993
|
const lines = Object.entries(values).map(([k, v]) => `${k}="${v.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\n/g, "\\n")}"`);
|
|
2931
|
-
const envPath =
|
|
2994
|
+
const envPath = join4(opts.dir, ".env.local");
|
|
2932
2995
|
writeFileSync3(envPath, lines.join(`
|
|
2933
2996
|
`) + `
|
|
2934
2997
|
`, { mode: 384 });
|
|
@@ -2947,6 +3010,7 @@ var init_secrets = __esm(() => {
|
|
|
2947
3010
|
init_src3();
|
|
2948
3011
|
init_api_client();
|
|
2949
3012
|
init_config_store();
|
|
3013
|
+
init_project_id();
|
|
2950
3014
|
});
|
|
2951
3015
|
|
|
2952
3016
|
// ../shared/src/constants/defaults.ts
|
|
@@ -7010,7 +7074,8 @@ var init_manifest = __esm(() => {
|
|
|
7010
7074
|
exports_external.object({
|
|
7011
7075
|
type: exports_external.literal("http"),
|
|
7012
7076
|
method: exports_external.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]).optional(),
|
|
7013
|
-
path: exports_external.string().optional()
|
|
7077
|
+
path: exports_external.string().optional(),
|
|
7078
|
+
public: exports_external.boolean().optional()
|
|
7014
7079
|
}),
|
|
7015
7080
|
exports_external.object({
|
|
7016
7081
|
type: exports_external.literal("cron"),
|
|
@@ -10021,7 +10086,7 @@ var init_sql = __esm(() => {
|
|
|
10021
10086
|
return new SQL([new StringChunk(str)]);
|
|
10022
10087
|
}
|
|
10023
10088
|
sql2.raw = raw;
|
|
10024
|
-
function
|
|
10089
|
+
function join5(chunks, separator) {
|
|
10025
10090
|
const result = [];
|
|
10026
10091
|
for (const [i, chunk] of chunks.entries()) {
|
|
10027
10092
|
if (i > 0 && separator !== undefined) {
|
|
@@ -10031,7 +10096,7 @@ var init_sql = __esm(() => {
|
|
|
10031
10096
|
}
|
|
10032
10097
|
return new SQL(result);
|
|
10033
10098
|
}
|
|
10034
|
-
sql2.join =
|
|
10099
|
+
sql2.join = join5;
|
|
10035
10100
|
function identifier(value) {
|
|
10036
10101
|
return new Name(value);
|
|
10037
10102
|
}
|
|
@@ -11921,7 +11986,7 @@ var init_select2 = __esm(() => {
|
|
|
11921
11986
|
return (table, on) => {
|
|
11922
11987
|
const baseTableName = this.tableName;
|
|
11923
11988
|
const tableName = getTableLikeName(table);
|
|
11924
|
-
if (typeof tableName === "string" && this.config.joins?.some((
|
|
11989
|
+
if (typeof tableName === "string" && this.config.joins?.some((join5) => join5.alias === tableName)) {
|
|
11925
11990
|
throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
11926
11991
|
}
|
|
11927
11992
|
if (!this.isPartialSelect) {
|
|
@@ -12161,7 +12226,7 @@ var init_update = __esm(() => {
|
|
|
12161
12226
|
createJoin(joinType) {
|
|
12162
12227
|
return (table, on) => {
|
|
12163
12228
|
const tableName = getTableLikeName(table);
|
|
12164
|
-
if (typeof tableName === "string" && this.config.joins.some((
|
|
12229
|
+
if (typeof tableName === "string" && this.config.joins.some((join5) => join5.alias === tableName)) {
|
|
12165
12230
|
throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
12166
12231
|
}
|
|
12167
12232
|
if (typeof on === "function") {
|
|
@@ -12211,10 +12276,10 @@ var init_update = __esm(() => {
|
|
|
12211
12276
|
const fromFields = this.getTableLikeFields(this.config.from);
|
|
12212
12277
|
fields[tableName] = fromFields;
|
|
12213
12278
|
}
|
|
12214
|
-
for (const
|
|
12215
|
-
const tableName2 = getTableLikeName(
|
|
12216
|
-
if (typeof tableName2 === "string" && !is(
|
|
12217
|
-
const fromFields = this.getTableLikeFields(
|
|
12279
|
+
for (const join5 of this.config.joins) {
|
|
12280
|
+
const tableName2 = getTableLikeName(join5.table);
|
|
12281
|
+
if (typeof tableName2 === "string" && !is(join5.table, SQL)) {
|
|
12282
|
+
const fromFields = this.getTableLikeFields(join5.table);
|
|
12218
12283
|
fields[tableName2] = fromFields;
|
|
12219
12284
|
}
|
|
12220
12285
|
}
|
|
@@ -13588,16 +13653,16 @@ var init_src2 = __esm(() => {
|
|
|
13588
13653
|
});
|
|
13589
13654
|
|
|
13590
13655
|
// src/lib/manifest.ts
|
|
13591
|
-
import { existsSync as
|
|
13592
|
-
import { join as
|
|
13656
|
+
import { existsSync as existsSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
13657
|
+
import { join as join5 } from "node:path";
|
|
13593
13658
|
function readManifest(dir) {
|
|
13594
|
-
const path =
|
|
13595
|
-
if (!
|
|
13659
|
+
const path = join5(dir, "dura.json");
|
|
13660
|
+
if (!existsSync4(path)) {
|
|
13596
13661
|
throw new ManifestError(`No dura.json found in ${dir}`);
|
|
13597
13662
|
}
|
|
13598
13663
|
let raw;
|
|
13599
13664
|
try {
|
|
13600
|
-
raw = JSON.parse(
|
|
13665
|
+
raw = JSON.parse(readFileSync4(path, "utf-8"));
|
|
13601
13666
|
} catch {
|
|
13602
13667
|
throw new ManifestError("dura.json is not valid JSON");
|
|
13603
13668
|
}
|
|
@@ -13608,14 +13673,14 @@ function readManifest(dir) {
|
|
|
13608
13673
|
return result.manifest;
|
|
13609
13674
|
}
|
|
13610
13675
|
function readRawManifest(dir) {
|
|
13611
|
-
const path =
|
|
13612
|
-
if (!
|
|
13676
|
+
const path = join5(dir, "dura.json");
|
|
13677
|
+
if (!existsSync4(path)) {
|
|
13613
13678
|
throw new ManifestError(`No dura.json found in ${dir}`);
|
|
13614
13679
|
}
|
|
13615
|
-
return JSON.parse(
|
|
13680
|
+
return JSON.parse(readFileSync4(path, "utf-8"));
|
|
13616
13681
|
}
|
|
13617
13682
|
function writeRawManifest(dir, data) {
|
|
13618
|
-
const path =
|
|
13683
|
+
const path = join5(dir, "dura.json");
|
|
13619
13684
|
writeFileSync4(path, JSON.stringify(data, null, 2) + `
|
|
13620
13685
|
`);
|
|
13621
13686
|
}
|
|
@@ -13781,161 +13846,2802 @@ var init_audit = __esm(() => {
|
|
|
13781
13846
|
init_config_store();
|
|
13782
13847
|
});
|
|
13783
13848
|
|
|
13784
|
-
//
|
|
13785
|
-
|
|
13786
|
-
|
|
13787
|
-
|
|
13788
|
-
|
|
13789
|
-
|
|
13790
|
-
|
|
13791
|
-
|
|
13792
|
-
|
|
13793
|
-
|
|
13794
|
-
|
|
13795
|
-
|
|
13796
|
-
|
|
13797
|
-
|
|
13798
|
-
|
|
13799
|
-
}
|
|
13800
|
-
|
|
13801
|
-
|
|
13802
|
-
|
|
13803
|
-
|
|
13804
|
-
|
|
13805
|
-
|
|
13806
|
-
|
|
13807
|
-
|
|
13808
|
-
|
|
13809
|
-
|
|
13810
|
-
|
|
13811
|
-
|
|
13812
|
-
|
|
13813
|
-
|
|
13814
|
-
|
|
13815
|
-
|
|
13816
|
-
|
|
13817
|
-
|
|
13818
|
-
|
|
13819
|
-
}
|
|
13820
|
-
|
|
13821
|
-
|
|
13822
|
-
|
|
13849
|
+
// ../../node_modules/.bun/esbuild@0.28.0/node_modules/esbuild/lib/main.js
|
|
13850
|
+
var require_main = __commonJS((exports, module) => {
|
|
13851
|
+
var __dirname = "/Users/gldc/Developer/dura-run/node_modules/.bun/esbuild@0.28.0/node_modules/esbuild/lib", __filename = "/Users/gldc/Developer/dura-run/node_modules/.bun/esbuild@0.28.0/node_modules/esbuild/lib/main.js";
|
|
13852
|
+
var __defProp2 = Object.defineProperty;
|
|
13853
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13854
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
13855
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
13856
|
+
var __export2 = (target, all) => {
|
|
13857
|
+
for (var name in all)
|
|
13858
|
+
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
13859
|
+
};
|
|
13860
|
+
var __copyProps = (to, from, except2, desc) => {
|
|
13861
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13862
|
+
for (let key of __getOwnPropNames2(from))
|
|
13863
|
+
if (!__hasOwnProp2.call(to, key) && key !== except2)
|
|
13864
|
+
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13865
|
+
}
|
|
13866
|
+
return to;
|
|
13867
|
+
};
|
|
13868
|
+
var __toCommonJS = (mod) => __copyProps(__defProp2({}, "__esModule", { value: true }), mod);
|
|
13869
|
+
var node_exports = {};
|
|
13870
|
+
__export2(node_exports, {
|
|
13871
|
+
analyzeMetafile: () => analyzeMetafile,
|
|
13872
|
+
analyzeMetafileSync: () => analyzeMetafileSync,
|
|
13873
|
+
build: () => build,
|
|
13874
|
+
buildSync: () => buildSync,
|
|
13875
|
+
context: () => context,
|
|
13876
|
+
default: () => node_default,
|
|
13877
|
+
formatMessages: () => formatMessages,
|
|
13878
|
+
formatMessagesSync: () => formatMessagesSync,
|
|
13879
|
+
initialize: () => initialize,
|
|
13880
|
+
stop: () => stop,
|
|
13881
|
+
transform: () => transform,
|
|
13882
|
+
transformSync: () => transformSync,
|
|
13883
|
+
version: () => version2
|
|
13884
|
+
});
|
|
13885
|
+
module.exports = __toCommonJS(node_exports);
|
|
13886
|
+
function encodePacket(packet) {
|
|
13887
|
+
let visit = (value) => {
|
|
13888
|
+
if (value === null) {
|
|
13889
|
+
bb.write8(0);
|
|
13890
|
+
} else if (typeof value === "boolean") {
|
|
13891
|
+
bb.write8(1);
|
|
13892
|
+
bb.write8(+value);
|
|
13893
|
+
} else if (typeof value === "number") {
|
|
13894
|
+
bb.write8(2);
|
|
13895
|
+
bb.write32(value | 0);
|
|
13896
|
+
} else if (typeof value === "string") {
|
|
13897
|
+
bb.write8(3);
|
|
13898
|
+
bb.write(encodeUTF8(value));
|
|
13899
|
+
} else if (value instanceof Uint8Array) {
|
|
13900
|
+
bb.write8(4);
|
|
13901
|
+
bb.write(value);
|
|
13902
|
+
} else if (value instanceof Array) {
|
|
13903
|
+
bb.write8(5);
|
|
13904
|
+
bb.write32(value.length);
|
|
13905
|
+
for (let item of value) {
|
|
13906
|
+
visit(item);
|
|
13907
|
+
}
|
|
13908
|
+
} else {
|
|
13909
|
+
let keys = Object.keys(value);
|
|
13910
|
+
bb.write8(6);
|
|
13911
|
+
bb.write32(keys.length);
|
|
13912
|
+
for (let key of keys) {
|
|
13913
|
+
bb.write(encodeUTF8(key));
|
|
13914
|
+
visit(value[key]);
|
|
13915
|
+
}
|
|
13916
|
+
}
|
|
13823
13917
|
};
|
|
13918
|
+
let bb = new ByteBuffer;
|
|
13919
|
+
bb.write32(0);
|
|
13920
|
+
bb.write32(packet.id << 1 | +!packet.isRequest);
|
|
13921
|
+
visit(packet.value);
|
|
13922
|
+
writeUInt32LE(bb.buf, bb.len - 4, 0);
|
|
13923
|
+
return bb.buf.subarray(0, bb.len);
|
|
13924
|
+
}
|
|
13925
|
+
function decodePacket(bytes) {
|
|
13926
|
+
let visit = () => {
|
|
13927
|
+
switch (bb.read8()) {
|
|
13928
|
+
case 0:
|
|
13929
|
+
return null;
|
|
13930
|
+
case 1:
|
|
13931
|
+
return !!bb.read8();
|
|
13932
|
+
case 2:
|
|
13933
|
+
return bb.read32();
|
|
13934
|
+
case 3:
|
|
13935
|
+
return decodeUTF8(bb.read());
|
|
13936
|
+
case 4:
|
|
13937
|
+
return bb.read();
|
|
13938
|
+
case 5: {
|
|
13939
|
+
let count = bb.read32();
|
|
13940
|
+
let value2 = [];
|
|
13941
|
+
for (let i = 0;i < count; i++) {
|
|
13942
|
+
value2.push(visit());
|
|
13943
|
+
}
|
|
13944
|
+
return value2;
|
|
13945
|
+
}
|
|
13946
|
+
case 6: {
|
|
13947
|
+
let count = bb.read32();
|
|
13948
|
+
let value2 = {};
|
|
13949
|
+
for (let i = 0;i < count; i++) {
|
|
13950
|
+
value2[decodeUTF8(bb.read())] = visit();
|
|
13951
|
+
}
|
|
13952
|
+
return value2;
|
|
13953
|
+
}
|
|
13954
|
+
default:
|
|
13955
|
+
throw new Error("Invalid packet");
|
|
13956
|
+
}
|
|
13957
|
+
};
|
|
13958
|
+
let bb = new ByteBuffer(bytes);
|
|
13959
|
+
let id = bb.read32();
|
|
13960
|
+
let isRequest = (id & 1) === 0;
|
|
13961
|
+
id >>>= 1;
|
|
13962
|
+
let value = visit();
|
|
13963
|
+
if (bb.ptr !== bytes.length) {
|
|
13964
|
+
throw new Error("Invalid packet");
|
|
13965
|
+
}
|
|
13966
|
+
return { id, isRequest, value };
|
|
13967
|
+
}
|
|
13968
|
+
var ByteBuffer = class {
|
|
13969
|
+
constructor(buf = new Uint8Array(1024)) {
|
|
13970
|
+
this.buf = buf;
|
|
13971
|
+
this.len = 0;
|
|
13972
|
+
this.ptr = 0;
|
|
13973
|
+
}
|
|
13974
|
+
_write(delta) {
|
|
13975
|
+
if (this.len + delta > this.buf.length) {
|
|
13976
|
+
let clone = new Uint8Array((this.len + delta) * 2);
|
|
13977
|
+
clone.set(this.buf);
|
|
13978
|
+
this.buf = clone;
|
|
13979
|
+
}
|
|
13980
|
+
this.len += delta;
|
|
13981
|
+
return this.len - delta;
|
|
13982
|
+
}
|
|
13983
|
+
write8(value) {
|
|
13984
|
+
let offset = this._write(1);
|
|
13985
|
+
this.buf[offset] = value;
|
|
13986
|
+
}
|
|
13987
|
+
write32(value) {
|
|
13988
|
+
let offset = this._write(4);
|
|
13989
|
+
writeUInt32LE(this.buf, value, offset);
|
|
13990
|
+
}
|
|
13991
|
+
write(bytes) {
|
|
13992
|
+
let offset = this._write(4 + bytes.length);
|
|
13993
|
+
writeUInt32LE(this.buf, bytes.length, offset);
|
|
13994
|
+
this.buf.set(bytes, offset + 4);
|
|
13995
|
+
}
|
|
13996
|
+
_read(delta) {
|
|
13997
|
+
if (this.ptr + delta > this.buf.length) {
|
|
13998
|
+
throw new Error("Invalid packet");
|
|
13999
|
+
}
|
|
14000
|
+
this.ptr += delta;
|
|
14001
|
+
return this.ptr - delta;
|
|
14002
|
+
}
|
|
14003
|
+
read8() {
|
|
14004
|
+
return this.buf[this._read(1)];
|
|
14005
|
+
}
|
|
14006
|
+
read32() {
|
|
14007
|
+
return readUInt32LE(this.buf, this._read(4));
|
|
14008
|
+
}
|
|
14009
|
+
read() {
|
|
14010
|
+
let length = this.read32();
|
|
14011
|
+
let bytes = new Uint8Array(length);
|
|
14012
|
+
let ptr = this._read(bytes.length);
|
|
14013
|
+
bytes.set(this.buf.subarray(ptr, ptr + length));
|
|
14014
|
+
return bytes;
|
|
14015
|
+
}
|
|
14016
|
+
};
|
|
14017
|
+
var encodeUTF8;
|
|
14018
|
+
var decodeUTF8;
|
|
14019
|
+
var encodeInvariant;
|
|
14020
|
+
if (typeof TextEncoder !== "undefined" && typeof TextDecoder !== "undefined") {
|
|
14021
|
+
let encoder = new TextEncoder;
|
|
14022
|
+
let decoder = new TextDecoder;
|
|
14023
|
+
encodeUTF8 = (text3) => encoder.encode(text3);
|
|
14024
|
+
decodeUTF8 = (bytes) => decoder.decode(bytes);
|
|
14025
|
+
encodeInvariant = 'new TextEncoder().encode("")';
|
|
14026
|
+
} else if (typeof Buffer !== "undefined") {
|
|
14027
|
+
encodeUTF8 = (text3) => Buffer.from(text3);
|
|
14028
|
+
decodeUTF8 = (bytes) => {
|
|
14029
|
+
let { buffer: buffer2, byteOffset, byteLength } = bytes;
|
|
14030
|
+
return Buffer.from(buffer2, byteOffset, byteLength).toString();
|
|
14031
|
+
};
|
|
14032
|
+
encodeInvariant = 'Buffer.from("")';
|
|
14033
|
+
} else {
|
|
14034
|
+
throw new Error("No UTF-8 codec found");
|
|
13824
14035
|
}
|
|
13825
|
-
|
|
13826
|
-
|
|
13827
|
-
|
|
13828
|
-
|
|
13829
|
-
|
|
13830
|
-
|
|
13831
|
-
|
|
13832
|
-
|
|
13833
|
-
|
|
13834
|
-
|
|
13835
|
-
|
|
13836
|
-
|
|
13837
|
-
|
|
14036
|
+
if (!(encodeUTF8("") instanceof Uint8Array))
|
|
14037
|
+
throw new Error(`Invariant violation: "${encodeInvariant} instanceof Uint8Array" is incorrectly false
|
|
14038
|
+
|
|
14039
|
+
This indicates that your JavaScript environment is broken. You cannot use
|
|
14040
|
+
esbuild in this environment because esbuild relies on this invariant. This
|
|
14041
|
+
is not a problem with esbuild. You need to fix your environment instead.
|
|
14042
|
+
`);
|
|
14043
|
+
function readUInt32LE(buffer2, offset) {
|
|
14044
|
+
return (buffer2[offset++] | buffer2[offset++] << 8 | buffer2[offset++] << 16 | buffer2[offset++] << 24) >>> 0;
|
|
14045
|
+
}
|
|
14046
|
+
function writeUInt32LE(buffer2, value, offset) {
|
|
14047
|
+
buffer2[offset++] = value;
|
|
14048
|
+
buffer2[offset++] = value >> 8;
|
|
14049
|
+
buffer2[offset++] = value >> 16;
|
|
14050
|
+
buffer2[offset++] = value >> 24;
|
|
14051
|
+
}
|
|
14052
|
+
var fromCharCode = String.fromCharCode;
|
|
14053
|
+
function throwSyntaxError(bytes, index2, message) {
|
|
14054
|
+
const c = bytes[index2];
|
|
14055
|
+
let line3 = 1;
|
|
14056
|
+
let column2 = 0;
|
|
14057
|
+
for (let i = 0;i < index2; i++) {
|
|
14058
|
+
if (bytes[i] === 10) {
|
|
14059
|
+
line3++;
|
|
14060
|
+
column2 = 0;
|
|
14061
|
+
} else {
|
|
14062
|
+
column2++;
|
|
14063
|
+
}
|
|
14064
|
+
}
|
|
14065
|
+
throw new SyntaxError(message ? message : index2 === bytes.length ? "Unexpected end of input while parsing JSON" : c >= 32 && c <= 126 ? `Unexpected character ${fromCharCode(c)} in JSON at position ${index2} (line ${line3}, column ${column2})` : `Unexpected byte 0x${c.toString(16)} in JSON at position ${index2} (line ${line3}, column ${column2})`);
|
|
14066
|
+
}
|
|
14067
|
+
function JSON_parse(bytes) {
|
|
14068
|
+
if (!(bytes instanceof Uint8Array)) {
|
|
14069
|
+
throw new Error(`JSON input must be a Uint8Array`);
|
|
14070
|
+
}
|
|
14071
|
+
const propertyStack = [];
|
|
14072
|
+
const objectStack = [];
|
|
14073
|
+
const stateStack = [];
|
|
14074
|
+
const length = bytes.length;
|
|
14075
|
+
let property = null;
|
|
14076
|
+
let state = 0;
|
|
14077
|
+
let object;
|
|
14078
|
+
let i = 0;
|
|
14079
|
+
while (i < length) {
|
|
14080
|
+
let c = bytes[i++];
|
|
14081
|
+
if (c <= 32) {
|
|
14082
|
+
continue;
|
|
14083
|
+
}
|
|
14084
|
+
let value;
|
|
14085
|
+
if (state === 2 && property === null && c !== 34 && c !== 125) {
|
|
14086
|
+
throwSyntaxError(bytes, --i);
|
|
14087
|
+
}
|
|
14088
|
+
switch (c) {
|
|
14089
|
+
case 116: {
|
|
14090
|
+
if (bytes[i++] !== 114 || bytes[i++] !== 117 || bytes[i++] !== 101) {
|
|
14091
|
+
throwSyntaxError(bytes, --i);
|
|
14092
|
+
}
|
|
14093
|
+
value = true;
|
|
14094
|
+
break;
|
|
14095
|
+
}
|
|
14096
|
+
case 102: {
|
|
14097
|
+
if (bytes[i++] !== 97 || bytes[i++] !== 108 || bytes[i++] !== 115 || bytes[i++] !== 101) {
|
|
14098
|
+
throwSyntaxError(bytes, --i);
|
|
14099
|
+
}
|
|
14100
|
+
value = false;
|
|
14101
|
+
break;
|
|
14102
|
+
}
|
|
14103
|
+
case 110: {
|
|
14104
|
+
if (bytes[i++] !== 117 || bytes[i++] !== 108 || bytes[i++] !== 108) {
|
|
14105
|
+
throwSyntaxError(bytes, --i);
|
|
14106
|
+
}
|
|
14107
|
+
value = null;
|
|
14108
|
+
break;
|
|
14109
|
+
}
|
|
14110
|
+
case 45:
|
|
14111
|
+
case 46:
|
|
14112
|
+
case 48:
|
|
14113
|
+
case 49:
|
|
14114
|
+
case 50:
|
|
14115
|
+
case 51:
|
|
14116
|
+
case 52:
|
|
14117
|
+
case 53:
|
|
14118
|
+
case 54:
|
|
14119
|
+
case 55:
|
|
14120
|
+
case 56:
|
|
14121
|
+
case 57: {
|
|
14122
|
+
let index2 = i;
|
|
14123
|
+
value = fromCharCode(c);
|
|
14124
|
+
c = bytes[i];
|
|
14125
|
+
while (true) {
|
|
14126
|
+
switch (c) {
|
|
14127
|
+
case 43:
|
|
14128
|
+
case 45:
|
|
14129
|
+
case 46:
|
|
14130
|
+
case 48:
|
|
14131
|
+
case 49:
|
|
14132
|
+
case 50:
|
|
14133
|
+
case 51:
|
|
14134
|
+
case 52:
|
|
14135
|
+
case 53:
|
|
14136
|
+
case 54:
|
|
14137
|
+
case 55:
|
|
14138
|
+
case 56:
|
|
14139
|
+
case 57:
|
|
14140
|
+
case 101:
|
|
14141
|
+
case 69: {
|
|
14142
|
+
value += fromCharCode(c);
|
|
14143
|
+
c = bytes[++i];
|
|
14144
|
+
continue;
|
|
14145
|
+
}
|
|
14146
|
+
}
|
|
14147
|
+
break;
|
|
14148
|
+
}
|
|
14149
|
+
value = +value;
|
|
14150
|
+
if (isNaN(value)) {
|
|
14151
|
+
throwSyntaxError(bytes, --index2, "Invalid number");
|
|
14152
|
+
}
|
|
14153
|
+
break;
|
|
14154
|
+
}
|
|
14155
|
+
case 34: {
|
|
14156
|
+
value = "";
|
|
14157
|
+
while (true) {
|
|
14158
|
+
if (i >= length) {
|
|
14159
|
+
throwSyntaxError(bytes, length);
|
|
14160
|
+
}
|
|
14161
|
+
c = bytes[i++];
|
|
14162
|
+
if (c === 34) {
|
|
14163
|
+
break;
|
|
14164
|
+
} else if (c === 92) {
|
|
14165
|
+
switch (bytes[i++]) {
|
|
14166
|
+
case 34:
|
|
14167
|
+
value += '"';
|
|
14168
|
+
break;
|
|
14169
|
+
case 47:
|
|
14170
|
+
value += "/";
|
|
14171
|
+
break;
|
|
14172
|
+
case 92:
|
|
14173
|
+
value += "\\";
|
|
14174
|
+
break;
|
|
14175
|
+
case 98:
|
|
14176
|
+
value += "\b";
|
|
14177
|
+
break;
|
|
14178
|
+
case 102:
|
|
14179
|
+
value += "\f";
|
|
14180
|
+
break;
|
|
14181
|
+
case 110:
|
|
14182
|
+
value += `
|
|
14183
|
+
`;
|
|
14184
|
+
break;
|
|
14185
|
+
case 114:
|
|
14186
|
+
value += "\r";
|
|
14187
|
+
break;
|
|
14188
|
+
case 116:
|
|
14189
|
+
value += "\t";
|
|
14190
|
+
break;
|
|
14191
|
+
case 117: {
|
|
14192
|
+
let code = 0;
|
|
14193
|
+
for (let j = 0;j < 4; j++) {
|
|
14194
|
+
c = bytes[i++];
|
|
14195
|
+
code <<= 4;
|
|
14196
|
+
if (c >= 48 && c <= 57)
|
|
14197
|
+
code |= c - 48;
|
|
14198
|
+
else if (c >= 97 && c <= 102)
|
|
14199
|
+
code |= c + (10 - 97);
|
|
14200
|
+
else if (c >= 65 && c <= 70)
|
|
14201
|
+
code |= c + (10 - 65);
|
|
14202
|
+
else
|
|
14203
|
+
throwSyntaxError(bytes, --i);
|
|
14204
|
+
}
|
|
14205
|
+
value += fromCharCode(code);
|
|
14206
|
+
break;
|
|
14207
|
+
}
|
|
14208
|
+
default:
|
|
14209
|
+
throwSyntaxError(bytes, --i);
|
|
14210
|
+
break;
|
|
14211
|
+
}
|
|
14212
|
+
} else if (c <= 127) {
|
|
14213
|
+
value += fromCharCode(c);
|
|
14214
|
+
} else if ((c & 224) === 192) {
|
|
14215
|
+
value += fromCharCode((c & 31) << 6 | bytes[i++] & 63);
|
|
14216
|
+
} else if ((c & 240) === 224) {
|
|
14217
|
+
value += fromCharCode((c & 15) << 12 | (bytes[i++] & 63) << 6 | bytes[i++] & 63);
|
|
14218
|
+
} else if ((c & 248) == 240) {
|
|
14219
|
+
let codePoint = (c & 7) << 18 | (bytes[i++] & 63) << 12 | (bytes[i++] & 63) << 6 | bytes[i++] & 63;
|
|
14220
|
+
if (codePoint > 65535) {
|
|
14221
|
+
codePoint -= 65536;
|
|
14222
|
+
value += fromCharCode(codePoint >> 10 & 1023 | 55296);
|
|
14223
|
+
codePoint = 56320 | codePoint & 1023;
|
|
14224
|
+
}
|
|
14225
|
+
value += fromCharCode(codePoint);
|
|
14226
|
+
}
|
|
14227
|
+
}
|
|
14228
|
+
value[0];
|
|
14229
|
+
break;
|
|
14230
|
+
}
|
|
14231
|
+
case 91: {
|
|
14232
|
+
value = [];
|
|
14233
|
+
propertyStack.push(property);
|
|
14234
|
+
objectStack.push(object);
|
|
14235
|
+
stateStack.push(state);
|
|
14236
|
+
property = null;
|
|
14237
|
+
object = value;
|
|
14238
|
+
state = 1;
|
|
14239
|
+
continue;
|
|
14240
|
+
}
|
|
14241
|
+
case 123: {
|
|
14242
|
+
value = {};
|
|
14243
|
+
propertyStack.push(property);
|
|
14244
|
+
objectStack.push(object);
|
|
14245
|
+
stateStack.push(state);
|
|
14246
|
+
property = null;
|
|
14247
|
+
object = value;
|
|
14248
|
+
state = 2;
|
|
14249
|
+
continue;
|
|
14250
|
+
}
|
|
14251
|
+
case 93: {
|
|
14252
|
+
if (state !== 1) {
|
|
14253
|
+
throwSyntaxError(bytes, --i);
|
|
14254
|
+
}
|
|
14255
|
+
value = object;
|
|
14256
|
+
property = propertyStack.pop();
|
|
14257
|
+
object = objectStack.pop();
|
|
14258
|
+
state = stateStack.pop();
|
|
14259
|
+
break;
|
|
14260
|
+
}
|
|
14261
|
+
case 125: {
|
|
14262
|
+
if (state !== 2) {
|
|
14263
|
+
throwSyntaxError(bytes, --i);
|
|
14264
|
+
}
|
|
14265
|
+
value = object;
|
|
14266
|
+
property = propertyStack.pop();
|
|
14267
|
+
object = objectStack.pop();
|
|
14268
|
+
state = stateStack.pop();
|
|
14269
|
+
break;
|
|
14270
|
+
}
|
|
14271
|
+
default: {
|
|
14272
|
+
throwSyntaxError(bytes, --i);
|
|
14273
|
+
}
|
|
14274
|
+
}
|
|
14275
|
+
c = bytes[i];
|
|
14276
|
+
while (c <= 32) {
|
|
14277
|
+
c = bytes[++i];
|
|
14278
|
+
}
|
|
14279
|
+
switch (state) {
|
|
14280
|
+
case 0: {
|
|
14281
|
+
if (i === length) {
|
|
14282
|
+
return value;
|
|
14283
|
+
}
|
|
14284
|
+
break;
|
|
14285
|
+
}
|
|
14286
|
+
case 1: {
|
|
14287
|
+
object.push(value);
|
|
14288
|
+
if (c === 44) {
|
|
14289
|
+
i++;
|
|
14290
|
+
continue;
|
|
14291
|
+
}
|
|
14292
|
+
if (c === 93) {
|
|
14293
|
+
continue;
|
|
14294
|
+
}
|
|
14295
|
+
break;
|
|
14296
|
+
}
|
|
14297
|
+
case 2: {
|
|
14298
|
+
if (property === null) {
|
|
14299
|
+
property = value;
|
|
14300
|
+
if (c === 58) {
|
|
14301
|
+
i++;
|
|
14302
|
+
continue;
|
|
14303
|
+
}
|
|
14304
|
+
} else {
|
|
14305
|
+
object[property] = value;
|
|
14306
|
+
property = null;
|
|
14307
|
+
if (c === 44) {
|
|
14308
|
+
i++;
|
|
14309
|
+
continue;
|
|
14310
|
+
}
|
|
14311
|
+
if (c === 125) {
|
|
14312
|
+
continue;
|
|
14313
|
+
}
|
|
14314
|
+
}
|
|
14315
|
+
break;
|
|
14316
|
+
}
|
|
14317
|
+
}
|
|
14318
|
+
break;
|
|
13838
14319
|
}
|
|
13839
|
-
|
|
13840
|
-
|
|
13841
|
-
|
|
13842
|
-
|
|
13843
|
-
|
|
13844
|
-
|
|
13845
|
-
|
|
13846
|
-
|
|
13847
|
-
|
|
13848
|
-
|
|
13849
|
-
|
|
14320
|
+
throwSyntaxError(bytes, i);
|
|
14321
|
+
}
|
|
14322
|
+
var quote = JSON.stringify;
|
|
14323
|
+
var buildLogLevelDefault = "warning";
|
|
14324
|
+
var transformLogLevelDefault = "silent";
|
|
14325
|
+
function validateAndJoinStringArray(values2, what) {
|
|
14326
|
+
const toJoin = [];
|
|
14327
|
+
for (const value of values2) {
|
|
14328
|
+
validateStringValue(value, what);
|
|
14329
|
+
if (value.indexOf(",") >= 0)
|
|
14330
|
+
throw new Error(`Invalid ${what}: ${value}`);
|
|
14331
|
+
toJoin.push(value);
|
|
14332
|
+
}
|
|
14333
|
+
return toJoin.join(",");
|
|
14334
|
+
}
|
|
14335
|
+
var canBeAnything = () => null;
|
|
14336
|
+
var mustBeBoolean = (value) => typeof value === "boolean" ? null : "a boolean";
|
|
14337
|
+
var mustBeString = (value) => typeof value === "string" ? null : "a string";
|
|
14338
|
+
var mustBeRegExp = (value) => value instanceof RegExp ? null : "a RegExp object";
|
|
14339
|
+
var mustBeInteger = (value) => typeof value === "number" && value === (value | 0) ? null : "an integer";
|
|
14340
|
+
var mustBeValidPortNumber = (value) => typeof value === "number" && value === (value | 0) && value >= 0 && value <= 65535 ? null : "a valid port number";
|
|
14341
|
+
var mustBeFunction = (value) => typeof value === "function" ? null : "a function";
|
|
14342
|
+
var mustBeArray = (value) => Array.isArray(value) ? null : "an array";
|
|
14343
|
+
var mustBeArrayOfStrings = (value) => Array.isArray(value) && value.every((x) => typeof x === "string") ? null : "an array of strings";
|
|
14344
|
+
var mustBeObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? null : "an object";
|
|
14345
|
+
var mustBeEntryPoints = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
|
|
14346
|
+
var mustBeWebAssemblyModule = (value) => value instanceof WebAssembly.Module ? null : "a WebAssembly.Module";
|
|
14347
|
+
var mustBeObjectOrNull = (value) => typeof value === "object" && !Array.isArray(value) ? null : "an object or null";
|
|
14348
|
+
var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value === "boolean" ? null : "a string or a boolean";
|
|
14349
|
+
var mustBeStringOrObject = (value) => typeof value === "string" || typeof value === "object" && value !== null && !Array.isArray(value) ? null : "a string or an object";
|
|
14350
|
+
var mustBeStringOrArrayOfStrings = (value) => typeof value === "string" || Array.isArray(value) && value.every((x) => typeof x === "string") ? null : "a string or an array of strings";
|
|
14351
|
+
var mustBeStringOrUint8Array = (value) => typeof value === "string" || value instanceof Uint8Array ? null : "a string or a Uint8Array";
|
|
14352
|
+
var mustBeStringOrURL = (value) => typeof value === "string" || value instanceof URL ? null : "a string or a URL";
|
|
14353
|
+
function getFlag(object, keys, key, mustBeFn) {
|
|
14354
|
+
let value = object[key];
|
|
14355
|
+
keys[key + ""] = true;
|
|
14356
|
+
if (value === undefined)
|
|
14357
|
+
return;
|
|
14358
|
+
let mustBe = mustBeFn(value);
|
|
14359
|
+
if (mustBe !== null)
|
|
14360
|
+
throw new Error(`${quote(key)} must be ${mustBe}`);
|
|
14361
|
+
return value;
|
|
14362
|
+
}
|
|
14363
|
+
function checkForInvalidFlags(object, keys, where) {
|
|
14364
|
+
for (let key in object) {
|
|
14365
|
+
if (!(key in keys)) {
|
|
14366
|
+
throw new Error(`Invalid option ${where}: ${quote(key)}`);
|
|
14367
|
+
}
|
|
13850
14368
|
}
|
|
13851
14369
|
}
|
|
13852
|
-
|
|
13853
|
-
|
|
13854
|
-
|
|
13855
|
-
|
|
13856
|
-
|
|
14370
|
+
function validateInitializeOptions(options) {
|
|
14371
|
+
let keys = /* @__PURE__ */ Object.create(null);
|
|
14372
|
+
let wasmURL = getFlag(options, keys, "wasmURL", mustBeStringOrURL);
|
|
14373
|
+
let wasmModule = getFlag(options, keys, "wasmModule", mustBeWebAssemblyModule);
|
|
14374
|
+
let worker = getFlag(options, keys, "worker", mustBeBoolean);
|
|
14375
|
+
checkForInvalidFlags(options, keys, "in initialize() call");
|
|
13857
14376
|
return {
|
|
13858
|
-
|
|
13859
|
-
|
|
14377
|
+
wasmURL,
|
|
14378
|
+
wasmModule,
|
|
14379
|
+
worker
|
|
13860
14380
|
};
|
|
13861
14381
|
}
|
|
13862
|
-
|
|
13863
|
-
|
|
13864
|
-
|
|
13865
|
-
|
|
13866
|
-
|
|
13867
|
-
|
|
13868
|
-
|
|
13869
|
-
|
|
13870
|
-
|
|
13871
|
-
|
|
13872
|
-
|
|
13873
|
-
return result;
|
|
13874
|
-
}
|
|
13875
|
-
async function createTarGz(dir) {
|
|
13876
|
-
const files = collectFiles(dir, dir);
|
|
13877
|
-
const tarBuffer = createTarBuffer(files);
|
|
13878
|
-
const chunks = [];
|
|
13879
|
-
const gzip = createGzip();
|
|
13880
|
-
const input = Readable.from([tarBuffer]);
|
|
13881
|
-
return new Promise((resolve3, reject) => {
|
|
13882
|
-
gzip.on("data", (chunk) => chunks.push(chunk));
|
|
13883
|
-
gzip.on("end", () => {
|
|
13884
|
-
const totalLength = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
13885
|
-
const result = new Uint8Array(totalLength);
|
|
13886
|
-
let offset = 0;
|
|
13887
|
-
for (const chunk of chunks) {
|
|
13888
|
-
result.set(chunk, offset);
|
|
13889
|
-
offset += chunk.length;
|
|
14382
|
+
function validateMangleCache(mangleCache) {
|
|
14383
|
+
let validated;
|
|
14384
|
+
if (mangleCache !== undefined) {
|
|
14385
|
+
validated = /* @__PURE__ */ Object.create(null);
|
|
14386
|
+
for (let key in mangleCache) {
|
|
14387
|
+
let value = mangleCache[key];
|
|
14388
|
+
if (typeof value === "string" || value === false) {
|
|
14389
|
+
validated[key] = value;
|
|
14390
|
+
} else {
|
|
14391
|
+
throw new Error(`Expected ${quote(key)} in mangle cache to map to either a string or false`);
|
|
14392
|
+
}
|
|
13890
14393
|
}
|
|
13891
|
-
resolve3(result);
|
|
13892
|
-
});
|
|
13893
|
-
gzip.on("error", reject);
|
|
13894
|
-
input.pipe(gzip);
|
|
13895
|
-
});
|
|
13896
|
-
}
|
|
13897
|
-
function collectFiles(dir, base) {
|
|
13898
|
-
const result = [];
|
|
13899
|
-
const entries = readdirSync(dir, { withFileTypes: true });
|
|
13900
|
-
for (const entry of entries) {
|
|
13901
|
-
const fullPath = join5(dir, entry.name);
|
|
13902
|
-
if (entry.isFile()) {
|
|
13903
|
-
const relativePath = fullPath.slice(base.length + 1);
|
|
13904
|
-
result.push({
|
|
13905
|
-
name: relativePath,
|
|
13906
|
-
content: new Uint8Array(readFileSync4(fullPath))
|
|
13907
|
-
});
|
|
13908
|
-
} else if (entry.isDirectory()) {
|
|
13909
|
-
result.push(...collectFiles(fullPath, base));
|
|
13910
14394
|
}
|
|
14395
|
+
return validated;
|
|
13911
14396
|
}
|
|
13912
|
-
|
|
13913
|
-
|
|
13914
|
-
|
|
13915
|
-
|
|
13916
|
-
|
|
13917
|
-
|
|
13918
|
-
|
|
13919
|
-
|
|
13920
|
-
|
|
13921
|
-
|
|
13922
|
-
blocks.push(new Uint8Array(512 - remainder));
|
|
13923
|
-
}
|
|
14397
|
+
function pushLogFlags(flags, options, keys, isTTY2, logLevelDefault) {
|
|
14398
|
+
let color = getFlag(options, keys, "color", mustBeBoolean);
|
|
14399
|
+
let logLevel = getFlag(options, keys, "logLevel", mustBeString);
|
|
14400
|
+
let logLimit = getFlag(options, keys, "logLimit", mustBeInteger);
|
|
14401
|
+
if (color !== undefined)
|
|
14402
|
+
flags.push(`--color=${color}`);
|
|
14403
|
+
else if (isTTY2)
|
|
14404
|
+
flags.push(`--color=true`);
|
|
14405
|
+
flags.push(`--log-level=${logLevel || logLevelDefault}`);
|
|
14406
|
+
flags.push(`--log-limit=${logLimit || 0}`);
|
|
13924
14407
|
}
|
|
13925
|
-
|
|
13926
|
-
|
|
13927
|
-
|
|
13928
|
-
|
|
13929
|
-
|
|
13930
|
-
result.set(block, offset);
|
|
13931
|
-
offset += block.length;
|
|
14408
|
+
function validateStringValue(value, what, key) {
|
|
14409
|
+
if (typeof value !== "string") {
|
|
14410
|
+
throw new Error(`Expected value for ${what}${key !== undefined ? " " + quote(key) : ""} to be a string, got ${typeof value} instead`);
|
|
14411
|
+
}
|
|
14412
|
+
return value;
|
|
13932
14413
|
}
|
|
13933
|
-
|
|
13934
|
-
|
|
13935
|
-
|
|
13936
|
-
|
|
13937
|
-
|
|
13938
|
-
|
|
14414
|
+
function pushCommonFlags(flags, options, keys) {
|
|
14415
|
+
let legalComments = getFlag(options, keys, "legalComments", mustBeString);
|
|
14416
|
+
let sourceRoot = getFlag(options, keys, "sourceRoot", mustBeString);
|
|
14417
|
+
let sourcesContent = getFlag(options, keys, "sourcesContent", mustBeBoolean);
|
|
14418
|
+
let target = getFlag(options, keys, "target", mustBeStringOrArrayOfStrings);
|
|
14419
|
+
let format = getFlag(options, keys, "format", mustBeString);
|
|
14420
|
+
let globalName = getFlag(options, keys, "globalName", mustBeString);
|
|
14421
|
+
let mangleProps = getFlag(options, keys, "mangleProps", mustBeRegExp);
|
|
14422
|
+
let reserveProps = getFlag(options, keys, "reserveProps", mustBeRegExp);
|
|
14423
|
+
let mangleQuoted = getFlag(options, keys, "mangleQuoted", mustBeBoolean);
|
|
14424
|
+
let minify = getFlag(options, keys, "minify", mustBeBoolean);
|
|
14425
|
+
let minifySyntax = getFlag(options, keys, "minifySyntax", mustBeBoolean);
|
|
14426
|
+
let minifyWhitespace = getFlag(options, keys, "minifyWhitespace", mustBeBoolean);
|
|
14427
|
+
let minifyIdentifiers = getFlag(options, keys, "minifyIdentifiers", mustBeBoolean);
|
|
14428
|
+
let lineLimit = getFlag(options, keys, "lineLimit", mustBeInteger);
|
|
14429
|
+
let drop = getFlag(options, keys, "drop", mustBeArrayOfStrings);
|
|
14430
|
+
let dropLabels = getFlag(options, keys, "dropLabels", mustBeArrayOfStrings);
|
|
14431
|
+
let charset = getFlag(options, keys, "charset", mustBeString);
|
|
14432
|
+
let treeShaking = getFlag(options, keys, "treeShaking", mustBeBoolean);
|
|
14433
|
+
let ignoreAnnotations = getFlag(options, keys, "ignoreAnnotations", mustBeBoolean);
|
|
14434
|
+
let jsx = getFlag(options, keys, "jsx", mustBeString);
|
|
14435
|
+
let jsxFactory = getFlag(options, keys, "jsxFactory", mustBeString);
|
|
14436
|
+
let jsxFragment = getFlag(options, keys, "jsxFragment", mustBeString);
|
|
14437
|
+
let jsxImportSource = getFlag(options, keys, "jsxImportSource", mustBeString);
|
|
14438
|
+
let jsxDev = getFlag(options, keys, "jsxDev", mustBeBoolean);
|
|
14439
|
+
let jsxSideEffects = getFlag(options, keys, "jsxSideEffects", mustBeBoolean);
|
|
14440
|
+
let define = getFlag(options, keys, "define", mustBeObject);
|
|
14441
|
+
let logOverride = getFlag(options, keys, "logOverride", mustBeObject);
|
|
14442
|
+
let supported = getFlag(options, keys, "supported", mustBeObject);
|
|
14443
|
+
let pure = getFlag(options, keys, "pure", mustBeArrayOfStrings);
|
|
14444
|
+
let keepNames = getFlag(options, keys, "keepNames", mustBeBoolean);
|
|
14445
|
+
let platform = getFlag(options, keys, "platform", mustBeString);
|
|
14446
|
+
let tsconfigRaw = getFlag(options, keys, "tsconfigRaw", mustBeStringOrObject);
|
|
14447
|
+
let absPaths = getFlag(options, keys, "absPaths", mustBeArrayOfStrings);
|
|
14448
|
+
if (legalComments)
|
|
14449
|
+
flags.push(`--legal-comments=${legalComments}`);
|
|
14450
|
+
if (sourceRoot !== undefined)
|
|
14451
|
+
flags.push(`--source-root=${sourceRoot}`);
|
|
14452
|
+
if (sourcesContent !== undefined)
|
|
14453
|
+
flags.push(`--sources-content=${sourcesContent}`);
|
|
14454
|
+
if (target)
|
|
14455
|
+
flags.push(`--target=${validateAndJoinStringArray(Array.isArray(target) ? target : [target], "target")}`);
|
|
14456
|
+
if (format)
|
|
14457
|
+
flags.push(`--format=${format}`);
|
|
14458
|
+
if (globalName)
|
|
14459
|
+
flags.push(`--global-name=${globalName}`);
|
|
14460
|
+
if (platform)
|
|
14461
|
+
flags.push(`--platform=${platform}`);
|
|
14462
|
+
if (tsconfigRaw)
|
|
14463
|
+
flags.push(`--tsconfig-raw=${typeof tsconfigRaw === "string" ? tsconfigRaw : JSON.stringify(tsconfigRaw)}`);
|
|
14464
|
+
if (minify)
|
|
14465
|
+
flags.push("--minify");
|
|
14466
|
+
if (minifySyntax)
|
|
14467
|
+
flags.push("--minify-syntax");
|
|
14468
|
+
if (minifyWhitespace)
|
|
14469
|
+
flags.push("--minify-whitespace");
|
|
14470
|
+
if (minifyIdentifiers)
|
|
14471
|
+
flags.push("--minify-identifiers");
|
|
14472
|
+
if (lineLimit)
|
|
14473
|
+
flags.push(`--line-limit=${lineLimit}`);
|
|
14474
|
+
if (charset)
|
|
14475
|
+
flags.push(`--charset=${charset}`);
|
|
14476
|
+
if (treeShaking !== undefined)
|
|
14477
|
+
flags.push(`--tree-shaking=${treeShaking}`);
|
|
14478
|
+
if (ignoreAnnotations)
|
|
14479
|
+
flags.push(`--ignore-annotations`);
|
|
14480
|
+
if (drop)
|
|
14481
|
+
for (let what of drop)
|
|
14482
|
+
flags.push(`--drop:${validateStringValue(what, "drop")}`);
|
|
14483
|
+
if (dropLabels)
|
|
14484
|
+
flags.push(`--drop-labels=${validateAndJoinStringArray(dropLabels, "drop label")}`);
|
|
14485
|
+
if (absPaths)
|
|
14486
|
+
flags.push(`--abs-paths=${validateAndJoinStringArray(absPaths, "abs paths")}`);
|
|
14487
|
+
if (mangleProps)
|
|
14488
|
+
flags.push(`--mangle-props=${jsRegExpToGoRegExp(mangleProps)}`);
|
|
14489
|
+
if (reserveProps)
|
|
14490
|
+
flags.push(`--reserve-props=${jsRegExpToGoRegExp(reserveProps)}`);
|
|
14491
|
+
if (mangleQuoted !== undefined)
|
|
14492
|
+
flags.push(`--mangle-quoted=${mangleQuoted}`);
|
|
14493
|
+
if (jsx)
|
|
14494
|
+
flags.push(`--jsx=${jsx}`);
|
|
14495
|
+
if (jsxFactory)
|
|
14496
|
+
flags.push(`--jsx-factory=${jsxFactory}`);
|
|
14497
|
+
if (jsxFragment)
|
|
14498
|
+
flags.push(`--jsx-fragment=${jsxFragment}`);
|
|
14499
|
+
if (jsxImportSource)
|
|
14500
|
+
flags.push(`--jsx-import-source=${jsxImportSource}`);
|
|
14501
|
+
if (jsxDev)
|
|
14502
|
+
flags.push(`--jsx-dev`);
|
|
14503
|
+
if (jsxSideEffects)
|
|
14504
|
+
flags.push(`--jsx-side-effects`);
|
|
14505
|
+
if (define) {
|
|
14506
|
+
for (let key in define) {
|
|
14507
|
+
if (key.indexOf("=") >= 0)
|
|
14508
|
+
throw new Error(`Invalid define: ${key}`);
|
|
14509
|
+
flags.push(`--define:${key}=${validateStringValue(define[key], "define", key)}`);
|
|
14510
|
+
}
|
|
14511
|
+
}
|
|
14512
|
+
if (logOverride) {
|
|
14513
|
+
for (let key in logOverride) {
|
|
14514
|
+
if (key.indexOf("=") >= 0)
|
|
14515
|
+
throw new Error(`Invalid log override: ${key}`);
|
|
14516
|
+
flags.push(`--log-override:${key}=${validateStringValue(logOverride[key], "log override", key)}`);
|
|
14517
|
+
}
|
|
14518
|
+
}
|
|
14519
|
+
if (supported) {
|
|
14520
|
+
for (let key in supported) {
|
|
14521
|
+
if (key.indexOf("=") >= 0)
|
|
14522
|
+
throw new Error(`Invalid supported: ${key}`);
|
|
14523
|
+
const value = supported[key];
|
|
14524
|
+
if (typeof value !== "boolean")
|
|
14525
|
+
throw new Error(`Expected value for supported ${quote(key)} to be a boolean, got ${typeof value} instead`);
|
|
14526
|
+
flags.push(`--supported:${key}=${value}`);
|
|
14527
|
+
}
|
|
14528
|
+
}
|
|
14529
|
+
if (pure)
|
|
14530
|
+
for (let fn of pure)
|
|
14531
|
+
flags.push(`--pure:${validateStringValue(fn, "pure")}`);
|
|
14532
|
+
if (keepNames)
|
|
14533
|
+
flags.push(`--keep-names`);
|
|
14534
|
+
}
|
|
14535
|
+
function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeDefault) {
|
|
14536
|
+
var _a2;
|
|
14537
|
+
let flags = [];
|
|
14538
|
+
let entries = [];
|
|
14539
|
+
let keys = /* @__PURE__ */ Object.create(null);
|
|
14540
|
+
let stdinContents = null;
|
|
14541
|
+
let stdinResolveDir = null;
|
|
14542
|
+
pushLogFlags(flags, options, keys, isTTY2, logLevelDefault);
|
|
14543
|
+
pushCommonFlags(flags, options, keys);
|
|
14544
|
+
let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean);
|
|
14545
|
+
let bundle = getFlag(options, keys, "bundle", mustBeBoolean);
|
|
14546
|
+
let splitting = getFlag(options, keys, "splitting", mustBeBoolean);
|
|
14547
|
+
let preserveSymlinks = getFlag(options, keys, "preserveSymlinks", mustBeBoolean);
|
|
14548
|
+
let metafile = getFlag(options, keys, "metafile", mustBeBoolean);
|
|
14549
|
+
let outfile = getFlag(options, keys, "outfile", mustBeString);
|
|
14550
|
+
let outdir = getFlag(options, keys, "outdir", mustBeString);
|
|
14551
|
+
let outbase = getFlag(options, keys, "outbase", mustBeString);
|
|
14552
|
+
let tsconfig = getFlag(options, keys, "tsconfig", mustBeString);
|
|
14553
|
+
let resolveExtensions = getFlag(options, keys, "resolveExtensions", mustBeArrayOfStrings);
|
|
14554
|
+
let nodePathsInput = getFlag(options, keys, "nodePaths", mustBeArrayOfStrings);
|
|
14555
|
+
let mainFields = getFlag(options, keys, "mainFields", mustBeArrayOfStrings);
|
|
14556
|
+
let conditions2 = getFlag(options, keys, "conditions", mustBeArrayOfStrings);
|
|
14557
|
+
let external2 = getFlag(options, keys, "external", mustBeArrayOfStrings);
|
|
14558
|
+
let packages = getFlag(options, keys, "packages", mustBeString);
|
|
14559
|
+
let alias3 = getFlag(options, keys, "alias", mustBeObject);
|
|
14560
|
+
let loader = getFlag(options, keys, "loader", mustBeObject);
|
|
14561
|
+
let outExtension = getFlag(options, keys, "outExtension", mustBeObject);
|
|
14562
|
+
let publicPath = getFlag(options, keys, "publicPath", mustBeString);
|
|
14563
|
+
let entryNames = getFlag(options, keys, "entryNames", mustBeString);
|
|
14564
|
+
let chunkNames = getFlag(options, keys, "chunkNames", mustBeString);
|
|
14565
|
+
let assetNames = getFlag(options, keys, "assetNames", mustBeString);
|
|
14566
|
+
let inject = getFlag(options, keys, "inject", mustBeArrayOfStrings);
|
|
14567
|
+
let banner = getFlag(options, keys, "banner", mustBeObject);
|
|
14568
|
+
let footer = getFlag(options, keys, "footer", mustBeObject);
|
|
14569
|
+
let entryPoints = getFlag(options, keys, "entryPoints", mustBeEntryPoints);
|
|
14570
|
+
let absWorkingDir = getFlag(options, keys, "absWorkingDir", mustBeString);
|
|
14571
|
+
let stdin = getFlag(options, keys, "stdin", mustBeObject);
|
|
14572
|
+
let write = (_a2 = getFlag(options, keys, "write", mustBeBoolean)) != null ? _a2 : writeDefault;
|
|
14573
|
+
let allowOverwrite = getFlag(options, keys, "allowOverwrite", mustBeBoolean);
|
|
14574
|
+
let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
|
14575
|
+
keys.plugins = true;
|
|
14576
|
+
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
14577
|
+
if (sourcemap)
|
|
14578
|
+
flags.push(`--sourcemap${sourcemap === true ? "" : `=${sourcemap}`}`);
|
|
14579
|
+
if (bundle)
|
|
14580
|
+
flags.push("--bundle");
|
|
14581
|
+
if (allowOverwrite)
|
|
14582
|
+
flags.push("--allow-overwrite");
|
|
14583
|
+
if (splitting)
|
|
14584
|
+
flags.push("--splitting");
|
|
14585
|
+
if (preserveSymlinks)
|
|
14586
|
+
flags.push("--preserve-symlinks");
|
|
14587
|
+
if (metafile)
|
|
14588
|
+
flags.push(`--metafile`);
|
|
14589
|
+
if (outfile)
|
|
14590
|
+
flags.push(`--outfile=${outfile}`);
|
|
14591
|
+
if (outdir)
|
|
14592
|
+
flags.push(`--outdir=${outdir}`);
|
|
14593
|
+
if (outbase)
|
|
14594
|
+
flags.push(`--outbase=${outbase}`);
|
|
14595
|
+
if (tsconfig)
|
|
14596
|
+
flags.push(`--tsconfig=${tsconfig}`);
|
|
14597
|
+
if (packages)
|
|
14598
|
+
flags.push(`--packages=${packages}`);
|
|
14599
|
+
if (resolveExtensions)
|
|
14600
|
+
flags.push(`--resolve-extensions=${validateAndJoinStringArray(resolveExtensions, "resolve extension")}`);
|
|
14601
|
+
if (publicPath)
|
|
14602
|
+
flags.push(`--public-path=${publicPath}`);
|
|
14603
|
+
if (entryNames)
|
|
14604
|
+
flags.push(`--entry-names=${entryNames}`);
|
|
14605
|
+
if (chunkNames)
|
|
14606
|
+
flags.push(`--chunk-names=${chunkNames}`);
|
|
14607
|
+
if (assetNames)
|
|
14608
|
+
flags.push(`--asset-names=${assetNames}`);
|
|
14609
|
+
if (mainFields)
|
|
14610
|
+
flags.push(`--main-fields=${validateAndJoinStringArray(mainFields, "main field")}`);
|
|
14611
|
+
if (conditions2)
|
|
14612
|
+
flags.push(`--conditions=${validateAndJoinStringArray(conditions2, "condition")}`);
|
|
14613
|
+
if (external2)
|
|
14614
|
+
for (let name of external2)
|
|
14615
|
+
flags.push(`--external:${validateStringValue(name, "external")}`);
|
|
14616
|
+
if (alias3) {
|
|
14617
|
+
for (let old in alias3) {
|
|
14618
|
+
if (old.indexOf("=") >= 0)
|
|
14619
|
+
throw new Error(`Invalid package name in alias: ${old}`);
|
|
14620
|
+
flags.push(`--alias:${old}=${validateStringValue(alias3[old], "alias", old)}`);
|
|
14621
|
+
}
|
|
14622
|
+
}
|
|
14623
|
+
if (banner) {
|
|
14624
|
+
for (let type in banner) {
|
|
14625
|
+
if (type.indexOf("=") >= 0)
|
|
14626
|
+
throw new Error(`Invalid banner file type: ${type}`);
|
|
14627
|
+
flags.push(`--banner:${type}=${validateStringValue(banner[type], "banner", type)}`);
|
|
14628
|
+
}
|
|
14629
|
+
}
|
|
14630
|
+
if (footer) {
|
|
14631
|
+
for (let type in footer) {
|
|
14632
|
+
if (type.indexOf("=") >= 0)
|
|
14633
|
+
throw new Error(`Invalid footer file type: ${type}`);
|
|
14634
|
+
flags.push(`--footer:${type}=${validateStringValue(footer[type], "footer", type)}`);
|
|
14635
|
+
}
|
|
14636
|
+
}
|
|
14637
|
+
if (inject)
|
|
14638
|
+
for (let path3 of inject)
|
|
14639
|
+
flags.push(`--inject:${validateStringValue(path3, "inject")}`);
|
|
14640
|
+
if (loader) {
|
|
14641
|
+
for (let ext in loader) {
|
|
14642
|
+
if (ext.indexOf("=") >= 0)
|
|
14643
|
+
throw new Error(`Invalid loader extension: ${ext}`);
|
|
14644
|
+
flags.push(`--loader:${ext}=${validateStringValue(loader[ext], "loader", ext)}`);
|
|
14645
|
+
}
|
|
14646
|
+
}
|
|
14647
|
+
if (outExtension) {
|
|
14648
|
+
for (let ext in outExtension) {
|
|
14649
|
+
if (ext.indexOf("=") >= 0)
|
|
14650
|
+
throw new Error(`Invalid out extension: ${ext}`);
|
|
14651
|
+
flags.push(`--out-extension:${ext}=${validateStringValue(outExtension[ext], "out extension", ext)}`);
|
|
14652
|
+
}
|
|
14653
|
+
}
|
|
14654
|
+
if (entryPoints) {
|
|
14655
|
+
if (Array.isArray(entryPoints)) {
|
|
14656
|
+
for (let i = 0, n = entryPoints.length;i < n; i++) {
|
|
14657
|
+
let entryPoint = entryPoints[i];
|
|
14658
|
+
if (typeof entryPoint === "object" && entryPoint !== null) {
|
|
14659
|
+
let entryPointKeys = /* @__PURE__ */ Object.create(null);
|
|
14660
|
+
let input = getFlag(entryPoint, entryPointKeys, "in", mustBeString);
|
|
14661
|
+
let output = getFlag(entryPoint, entryPointKeys, "out", mustBeString);
|
|
14662
|
+
checkForInvalidFlags(entryPoint, entryPointKeys, "in entry point at index " + i);
|
|
14663
|
+
if (input === undefined)
|
|
14664
|
+
throw new Error('Missing property "in" for entry point at index ' + i);
|
|
14665
|
+
if (output === undefined)
|
|
14666
|
+
throw new Error('Missing property "out" for entry point at index ' + i);
|
|
14667
|
+
entries.push([output, input]);
|
|
14668
|
+
} else {
|
|
14669
|
+
entries.push(["", validateStringValue(entryPoint, "entry point at index " + i)]);
|
|
14670
|
+
}
|
|
14671
|
+
}
|
|
14672
|
+
} else {
|
|
14673
|
+
for (let key in entryPoints) {
|
|
14674
|
+
entries.push([key, validateStringValue(entryPoints[key], "entry point", key)]);
|
|
14675
|
+
}
|
|
14676
|
+
}
|
|
14677
|
+
}
|
|
14678
|
+
if (stdin) {
|
|
14679
|
+
let stdinKeys = /* @__PURE__ */ Object.create(null);
|
|
14680
|
+
let contents = getFlag(stdin, stdinKeys, "contents", mustBeStringOrUint8Array);
|
|
14681
|
+
let resolveDir = getFlag(stdin, stdinKeys, "resolveDir", mustBeString);
|
|
14682
|
+
let sourcefile = getFlag(stdin, stdinKeys, "sourcefile", mustBeString);
|
|
14683
|
+
let loader2 = getFlag(stdin, stdinKeys, "loader", mustBeString);
|
|
14684
|
+
checkForInvalidFlags(stdin, stdinKeys, 'in "stdin" object');
|
|
14685
|
+
if (sourcefile)
|
|
14686
|
+
flags.push(`--sourcefile=${sourcefile}`);
|
|
14687
|
+
if (loader2)
|
|
14688
|
+
flags.push(`--loader=${loader2}`);
|
|
14689
|
+
if (resolveDir)
|
|
14690
|
+
stdinResolveDir = resolveDir;
|
|
14691
|
+
if (typeof contents === "string")
|
|
14692
|
+
stdinContents = encodeUTF8(contents);
|
|
14693
|
+
else if (contents instanceof Uint8Array)
|
|
14694
|
+
stdinContents = contents;
|
|
14695
|
+
}
|
|
14696
|
+
let nodePaths = [];
|
|
14697
|
+
if (nodePathsInput) {
|
|
14698
|
+
for (let value of nodePathsInput) {
|
|
14699
|
+
value += "";
|
|
14700
|
+
nodePaths.push(value);
|
|
14701
|
+
}
|
|
14702
|
+
}
|
|
14703
|
+
return {
|
|
14704
|
+
entries,
|
|
14705
|
+
flags,
|
|
14706
|
+
write,
|
|
14707
|
+
stdinContents,
|
|
14708
|
+
stdinResolveDir,
|
|
14709
|
+
absWorkingDir,
|
|
14710
|
+
nodePaths,
|
|
14711
|
+
mangleCache: validateMangleCache(mangleCache)
|
|
14712
|
+
};
|
|
14713
|
+
}
|
|
14714
|
+
function flagsForTransformOptions(callName, options, isTTY2, logLevelDefault) {
|
|
14715
|
+
let flags = [];
|
|
14716
|
+
let keys = /* @__PURE__ */ Object.create(null);
|
|
14717
|
+
pushLogFlags(flags, options, keys, isTTY2, logLevelDefault);
|
|
14718
|
+
pushCommonFlags(flags, options, keys);
|
|
14719
|
+
let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean);
|
|
14720
|
+
let sourcefile = getFlag(options, keys, "sourcefile", mustBeString);
|
|
14721
|
+
let loader = getFlag(options, keys, "loader", mustBeString);
|
|
14722
|
+
let banner = getFlag(options, keys, "banner", mustBeString);
|
|
14723
|
+
let footer = getFlag(options, keys, "footer", mustBeString);
|
|
14724
|
+
let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
|
14725
|
+
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
14726
|
+
if (sourcemap)
|
|
14727
|
+
flags.push(`--sourcemap=${sourcemap === true ? "external" : sourcemap}`);
|
|
14728
|
+
if (sourcefile)
|
|
14729
|
+
flags.push(`--sourcefile=${sourcefile}`);
|
|
14730
|
+
if (loader)
|
|
14731
|
+
flags.push(`--loader=${loader}`);
|
|
14732
|
+
if (banner)
|
|
14733
|
+
flags.push(`--banner=${banner}`);
|
|
14734
|
+
if (footer)
|
|
14735
|
+
flags.push(`--footer=${footer}`);
|
|
14736
|
+
return {
|
|
14737
|
+
flags,
|
|
14738
|
+
mangleCache: validateMangleCache(mangleCache)
|
|
14739
|
+
};
|
|
14740
|
+
}
|
|
14741
|
+
function createChannel(streamIn) {
|
|
14742
|
+
const requestCallbacksByKey = {};
|
|
14743
|
+
const closeData = { didClose: false, reason: "" };
|
|
14744
|
+
let responseCallbacks = {};
|
|
14745
|
+
let nextRequestID = 0;
|
|
14746
|
+
let nextBuildKey = 0;
|
|
14747
|
+
let stdout = new Uint8Array(16 * 1024);
|
|
14748
|
+
let stdoutUsed = 0;
|
|
14749
|
+
let readFromStdout = (chunk) => {
|
|
14750
|
+
let limit = stdoutUsed + chunk.length;
|
|
14751
|
+
if (limit > stdout.length) {
|
|
14752
|
+
let swap = new Uint8Array(limit * 2);
|
|
14753
|
+
swap.set(stdout);
|
|
14754
|
+
stdout = swap;
|
|
14755
|
+
}
|
|
14756
|
+
stdout.set(chunk, stdoutUsed);
|
|
14757
|
+
stdoutUsed += chunk.length;
|
|
14758
|
+
let offset = 0;
|
|
14759
|
+
while (offset + 4 <= stdoutUsed) {
|
|
14760
|
+
let length = readUInt32LE(stdout, offset);
|
|
14761
|
+
if (offset + 4 + length > stdoutUsed) {
|
|
14762
|
+
break;
|
|
14763
|
+
}
|
|
14764
|
+
offset += 4;
|
|
14765
|
+
handleIncomingPacket(stdout.subarray(offset, offset + length));
|
|
14766
|
+
offset += length;
|
|
14767
|
+
}
|
|
14768
|
+
if (offset > 0) {
|
|
14769
|
+
stdout.copyWithin(0, offset, stdoutUsed);
|
|
14770
|
+
stdoutUsed -= offset;
|
|
14771
|
+
}
|
|
14772
|
+
};
|
|
14773
|
+
let afterClose = (error) => {
|
|
14774
|
+
closeData.didClose = true;
|
|
14775
|
+
if (error)
|
|
14776
|
+
closeData.reason = ": " + (error.message || error);
|
|
14777
|
+
const text3 = "The service was stopped" + closeData.reason;
|
|
14778
|
+
for (let id in responseCallbacks) {
|
|
14779
|
+
responseCallbacks[id](text3, null);
|
|
14780
|
+
}
|
|
14781
|
+
responseCallbacks = {};
|
|
14782
|
+
};
|
|
14783
|
+
let sendRequest = (refs, value, callback) => {
|
|
14784
|
+
if (closeData.didClose)
|
|
14785
|
+
return callback("The service is no longer running" + closeData.reason, null);
|
|
14786
|
+
let id = nextRequestID++;
|
|
14787
|
+
responseCallbacks[id] = (error, response) => {
|
|
14788
|
+
try {
|
|
14789
|
+
callback(error, response);
|
|
14790
|
+
} finally {
|
|
14791
|
+
if (refs)
|
|
14792
|
+
refs.unref();
|
|
14793
|
+
}
|
|
14794
|
+
};
|
|
14795
|
+
if (refs)
|
|
14796
|
+
refs.ref();
|
|
14797
|
+
streamIn.writeToStdin(encodePacket({ id, isRequest: true, value }));
|
|
14798
|
+
};
|
|
14799
|
+
let sendResponse = (id, value) => {
|
|
14800
|
+
if (closeData.didClose)
|
|
14801
|
+
throw new Error("The service is no longer running" + closeData.reason);
|
|
14802
|
+
streamIn.writeToStdin(encodePacket({ id, isRequest: false, value }));
|
|
14803
|
+
};
|
|
14804
|
+
let handleRequest = async (id, request) => {
|
|
14805
|
+
try {
|
|
14806
|
+
if (request.command === "ping") {
|
|
14807
|
+
sendResponse(id, {});
|
|
14808
|
+
return;
|
|
14809
|
+
}
|
|
14810
|
+
if (typeof request.key === "number") {
|
|
14811
|
+
const requestCallbacks = requestCallbacksByKey[request.key];
|
|
14812
|
+
if (!requestCallbacks) {
|
|
14813
|
+
return;
|
|
14814
|
+
}
|
|
14815
|
+
const callback = requestCallbacks[request.command];
|
|
14816
|
+
if (callback) {
|
|
14817
|
+
await callback(id, request);
|
|
14818
|
+
return;
|
|
14819
|
+
}
|
|
14820
|
+
}
|
|
14821
|
+
throw new Error(`Invalid command: ` + request.command);
|
|
14822
|
+
} catch (e) {
|
|
14823
|
+
const errors3 = [extractErrorMessageV8(e, streamIn, null, undefined, "")];
|
|
14824
|
+
try {
|
|
14825
|
+
sendResponse(id, { errors: errors3 });
|
|
14826
|
+
} catch {}
|
|
14827
|
+
}
|
|
14828
|
+
};
|
|
14829
|
+
let isFirstPacket = true;
|
|
14830
|
+
let handleIncomingPacket = (bytes) => {
|
|
14831
|
+
if (isFirstPacket) {
|
|
14832
|
+
isFirstPacket = false;
|
|
14833
|
+
let binaryVersion = String.fromCharCode(...bytes);
|
|
14834
|
+
if (binaryVersion !== "0.28.0") {
|
|
14835
|
+
throw new Error(`Cannot start service: Host version "${"0.28.0"}" does not match binary version ${quote(binaryVersion)}`);
|
|
14836
|
+
}
|
|
14837
|
+
return;
|
|
14838
|
+
}
|
|
14839
|
+
let packet = decodePacket(bytes);
|
|
14840
|
+
if (packet.isRequest) {
|
|
14841
|
+
handleRequest(packet.id, packet.value);
|
|
14842
|
+
} else {
|
|
14843
|
+
let callback = responseCallbacks[packet.id];
|
|
14844
|
+
delete responseCallbacks[packet.id];
|
|
14845
|
+
if (packet.value.error)
|
|
14846
|
+
callback(packet.value.error, {});
|
|
14847
|
+
else
|
|
14848
|
+
callback(null, packet.value);
|
|
14849
|
+
}
|
|
14850
|
+
};
|
|
14851
|
+
let buildOrContext = ({ callName, refs, options, isTTY: isTTY2, defaultWD: defaultWD2, callback }) => {
|
|
14852
|
+
let refCount = 0;
|
|
14853
|
+
const buildKey = nextBuildKey++;
|
|
14854
|
+
const requestCallbacks = {};
|
|
14855
|
+
const buildRefs = {
|
|
14856
|
+
ref() {
|
|
14857
|
+
if (++refCount === 1) {
|
|
14858
|
+
if (refs)
|
|
14859
|
+
refs.ref();
|
|
14860
|
+
}
|
|
14861
|
+
},
|
|
14862
|
+
unref() {
|
|
14863
|
+
if (--refCount === 0) {
|
|
14864
|
+
delete requestCallbacksByKey[buildKey];
|
|
14865
|
+
if (refs)
|
|
14866
|
+
refs.unref();
|
|
14867
|
+
}
|
|
14868
|
+
}
|
|
14869
|
+
};
|
|
14870
|
+
requestCallbacksByKey[buildKey] = requestCallbacks;
|
|
14871
|
+
buildRefs.ref();
|
|
14872
|
+
buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, buildRefs, streamIn, requestCallbacks, options, isTTY2, defaultWD2, (err, res) => {
|
|
14873
|
+
try {
|
|
14874
|
+
callback(err, res);
|
|
14875
|
+
} finally {
|
|
14876
|
+
buildRefs.unref();
|
|
14877
|
+
}
|
|
14878
|
+
});
|
|
14879
|
+
};
|
|
14880
|
+
let transform2 = ({ callName, refs, input, options, isTTY: isTTY2, fs: fs3, callback }) => {
|
|
14881
|
+
const details = createObjectStash();
|
|
14882
|
+
let start = (inputPath) => {
|
|
14883
|
+
try {
|
|
14884
|
+
if (typeof input !== "string" && !(input instanceof Uint8Array))
|
|
14885
|
+
throw new Error('The input to "transform" must be a string or a Uint8Array');
|
|
14886
|
+
let {
|
|
14887
|
+
flags,
|
|
14888
|
+
mangleCache
|
|
14889
|
+
} = flagsForTransformOptions(callName, options, isTTY2, transformLogLevelDefault);
|
|
14890
|
+
let request = {
|
|
14891
|
+
command: "transform",
|
|
14892
|
+
flags,
|
|
14893
|
+
inputFS: inputPath !== null,
|
|
14894
|
+
input: inputPath !== null ? encodeUTF8(inputPath) : typeof input === "string" ? encodeUTF8(input) : input
|
|
14895
|
+
};
|
|
14896
|
+
if (mangleCache)
|
|
14897
|
+
request.mangleCache = mangleCache;
|
|
14898
|
+
sendRequest(refs, request, (error, response) => {
|
|
14899
|
+
if (error)
|
|
14900
|
+
return callback(new Error(error), null);
|
|
14901
|
+
let errors3 = replaceDetailsInMessages(response.errors, details);
|
|
14902
|
+
let warnings = replaceDetailsInMessages(response.warnings, details);
|
|
14903
|
+
let outstanding = 1;
|
|
14904
|
+
let next = () => {
|
|
14905
|
+
if (--outstanding === 0) {
|
|
14906
|
+
let result = {
|
|
14907
|
+
warnings,
|
|
14908
|
+
code: response.code,
|
|
14909
|
+
map: response.map,
|
|
14910
|
+
mangleCache: undefined,
|
|
14911
|
+
legalComments: undefined
|
|
14912
|
+
};
|
|
14913
|
+
if ("legalComments" in response)
|
|
14914
|
+
result.legalComments = response == null ? undefined : response.legalComments;
|
|
14915
|
+
if (response.mangleCache)
|
|
14916
|
+
result.mangleCache = response == null ? undefined : response.mangleCache;
|
|
14917
|
+
callback(null, result);
|
|
14918
|
+
}
|
|
14919
|
+
};
|
|
14920
|
+
if (errors3.length > 0)
|
|
14921
|
+
return callback(failureErrorWithLog("Transform failed", errors3, warnings), null);
|
|
14922
|
+
if (response.codeFS) {
|
|
14923
|
+
outstanding++;
|
|
14924
|
+
fs3.readFile(response.code, (err, contents) => {
|
|
14925
|
+
if (err !== null) {
|
|
14926
|
+
callback(err, null);
|
|
14927
|
+
} else {
|
|
14928
|
+
response.code = contents;
|
|
14929
|
+
next();
|
|
14930
|
+
}
|
|
14931
|
+
});
|
|
14932
|
+
}
|
|
14933
|
+
if (response.mapFS) {
|
|
14934
|
+
outstanding++;
|
|
14935
|
+
fs3.readFile(response.map, (err, contents) => {
|
|
14936
|
+
if (err !== null) {
|
|
14937
|
+
callback(err, null);
|
|
14938
|
+
} else {
|
|
14939
|
+
response.map = contents;
|
|
14940
|
+
next();
|
|
14941
|
+
}
|
|
14942
|
+
});
|
|
14943
|
+
}
|
|
14944
|
+
next();
|
|
14945
|
+
});
|
|
14946
|
+
} catch (e) {
|
|
14947
|
+
let flags = [];
|
|
14948
|
+
try {
|
|
14949
|
+
pushLogFlags(flags, options, {}, isTTY2, transformLogLevelDefault);
|
|
14950
|
+
} catch {}
|
|
14951
|
+
const error = extractErrorMessageV8(e, streamIn, details, undefined, "");
|
|
14952
|
+
sendRequest(refs, { command: "error", flags, error }, () => {
|
|
14953
|
+
error.detail = details.load(error.detail);
|
|
14954
|
+
callback(failureErrorWithLog("Transform failed", [error], []), null);
|
|
14955
|
+
});
|
|
14956
|
+
}
|
|
14957
|
+
};
|
|
14958
|
+
if ((typeof input === "string" || input instanceof Uint8Array) && input.length > 1024 * 1024) {
|
|
14959
|
+
let next = start;
|
|
14960
|
+
start = () => fs3.writeFile(input, next);
|
|
14961
|
+
}
|
|
14962
|
+
start(null);
|
|
14963
|
+
};
|
|
14964
|
+
let formatMessages2 = ({ callName, refs, messages: messages2, options, callback }) => {
|
|
14965
|
+
if (!options)
|
|
14966
|
+
throw new Error(`Missing second argument in ${callName}() call`);
|
|
14967
|
+
let keys = {};
|
|
14968
|
+
let kind = getFlag(options, keys, "kind", mustBeString);
|
|
14969
|
+
let color = getFlag(options, keys, "color", mustBeBoolean);
|
|
14970
|
+
let terminalWidth = getFlag(options, keys, "terminalWidth", mustBeInteger);
|
|
14971
|
+
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
14972
|
+
if (kind === undefined)
|
|
14973
|
+
throw new Error(`Missing "kind" in ${callName}() call`);
|
|
14974
|
+
if (kind !== "error" && kind !== "warning")
|
|
14975
|
+
throw new Error(`Expected "kind" to be "error" or "warning" in ${callName}() call`);
|
|
14976
|
+
let request = {
|
|
14977
|
+
command: "format-msgs",
|
|
14978
|
+
messages: sanitizeMessages(messages2, "messages", null, "", terminalWidth),
|
|
14979
|
+
isWarning: kind === "warning"
|
|
14980
|
+
};
|
|
14981
|
+
if (color !== undefined)
|
|
14982
|
+
request.color = color;
|
|
14983
|
+
if (terminalWidth !== undefined)
|
|
14984
|
+
request.terminalWidth = terminalWidth;
|
|
14985
|
+
sendRequest(refs, request, (error, response) => {
|
|
14986
|
+
if (error)
|
|
14987
|
+
return callback(new Error(error), null);
|
|
14988
|
+
callback(null, response.messages);
|
|
14989
|
+
});
|
|
14990
|
+
};
|
|
14991
|
+
let analyzeMetafile2 = ({ callName, refs, metafile, options, callback }) => {
|
|
14992
|
+
if (options === undefined)
|
|
14993
|
+
options = {};
|
|
14994
|
+
let keys = {};
|
|
14995
|
+
let color = getFlag(options, keys, "color", mustBeBoolean);
|
|
14996
|
+
let verbose = getFlag(options, keys, "verbose", mustBeBoolean);
|
|
14997
|
+
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
14998
|
+
let request = {
|
|
14999
|
+
command: "analyze-metafile",
|
|
15000
|
+
metafile
|
|
15001
|
+
};
|
|
15002
|
+
if (color !== undefined)
|
|
15003
|
+
request.color = color;
|
|
15004
|
+
if (verbose !== undefined)
|
|
15005
|
+
request.verbose = verbose;
|
|
15006
|
+
sendRequest(refs, request, (error, response) => {
|
|
15007
|
+
if (error)
|
|
15008
|
+
return callback(new Error(error), null);
|
|
15009
|
+
callback(null, response.result);
|
|
15010
|
+
});
|
|
15011
|
+
};
|
|
15012
|
+
return {
|
|
15013
|
+
readFromStdout,
|
|
15014
|
+
afterClose,
|
|
15015
|
+
service: {
|
|
15016
|
+
buildOrContext,
|
|
15017
|
+
transform: transform2,
|
|
15018
|
+
formatMessages: formatMessages2,
|
|
15019
|
+
analyzeMetafile: analyzeMetafile2
|
|
15020
|
+
}
|
|
15021
|
+
};
|
|
15022
|
+
}
|
|
15023
|
+
function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, options, isTTY2, defaultWD2, callback) {
|
|
15024
|
+
const details = createObjectStash();
|
|
15025
|
+
const isContext = callName === "context";
|
|
15026
|
+
const handleError = (e, pluginName) => {
|
|
15027
|
+
const flags = [];
|
|
15028
|
+
try {
|
|
15029
|
+
pushLogFlags(flags, options, {}, isTTY2, buildLogLevelDefault);
|
|
15030
|
+
} catch {}
|
|
15031
|
+
const message = extractErrorMessageV8(e, streamIn, details, undefined, pluginName);
|
|
15032
|
+
sendRequest(refs, { command: "error", flags, error: message }, () => {
|
|
15033
|
+
message.detail = details.load(message.detail);
|
|
15034
|
+
callback(failureErrorWithLog(isContext ? "Context failed" : "Build failed", [message], []), null);
|
|
15035
|
+
});
|
|
15036
|
+
};
|
|
15037
|
+
let plugins;
|
|
15038
|
+
if (typeof options === "object") {
|
|
15039
|
+
const value = options.plugins;
|
|
15040
|
+
if (value !== undefined) {
|
|
15041
|
+
if (!Array.isArray(value))
|
|
15042
|
+
return handleError(new Error(`"plugins" must be an array`), "");
|
|
15043
|
+
plugins = value;
|
|
15044
|
+
}
|
|
15045
|
+
}
|
|
15046
|
+
if (plugins && plugins.length > 0) {
|
|
15047
|
+
if (streamIn.isSync)
|
|
15048
|
+
return handleError(new Error("Cannot use plugins in synchronous API calls"), "");
|
|
15049
|
+
handlePlugins(buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, options, plugins, details).then((result) => {
|
|
15050
|
+
if (!result.ok)
|
|
15051
|
+
return handleError(result.error, result.pluginName);
|
|
15052
|
+
try {
|
|
15053
|
+
buildOrContextContinue(result.requestPlugins, result.runOnEndCallbacks, result.scheduleOnDisposeCallbacks);
|
|
15054
|
+
} catch (e) {
|
|
15055
|
+
handleError(e, "");
|
|
15056
|
+
}
|
|
15057
|
+
}, (e) => handleError(e, ""));
|
|
15058
|
+
return;
|
|
15059
|
+
}
|
|
15060
|
+
try {
|
|
15061
|
+
buildOrContextContinue(null, (result, done) => done([], []), () => {});
|
|
15062
|
+
} catch (e) {
|
|
15063
|
+
handleError(e, "");
|
|
15064
|
+
}
|
|
15065
|
+
function buildOrContextContinue(requestPlugins, runOnEndCallbacks, scheduleOnDisposeCallbacks) {
|
|
15066
|
+
const writeDefault = streamIn.hasFS;
|
|
15067
|
+
const {
|
|
15068
|
+
entries,
|
|
15069
|
+
flags,
|
|
15070
|
+
write,
|
|
15071
|
+
stdinContents,
|
|
15072
|
+
stdinResolveDir,
|
|
15073
|
+
absWorkingDir,
|
|
15074
|
+
nodePaths,
|
|
15075
|
+
mangleCache
|
|
15076
|
+
} = flagsForBuildOptions(callName, options, isTTY2, buildLogLevelDefault, writeDefault);
|
|
15077
|
+
if (write && !streamIn.hasFS)
|
|
15078
|
+
throw new Error(`The "write" option is unavailable in this environment`);
|
|
15079
|
+
const request = {
|
|
15080
|
+
command: "build",
|
|
15081
|
+
key: buildKey,
|
|
15082
|
+
entries,
|
|
15083
|
+
flags,
|
|
15084
|
+
write,
|
|
15085
|
+
stdinContents,
|
|
15086
|
+
stdinResolveDir,
|
|
15087
|
+
absWorkingDir: absWorkingDir || defaultWD2,
|
|
15088
|
+
nodePaths,
|
|
15089
|
+
context: isContext
|
|
15090
|
+
};
|
|
15091
|
+
if (requestPlugins)
|
|
15092
|
+
request.plugins = requestPlugins;
|
|
15093
|
+
if (mangleCache)
|
|
15094
|
+
request.mangleCache = mangleCache;
|
|
15095
|
+
const buildResponseToResult = (response, callback2) => {
|
|
15096
|
+
const result = {
|
|
15097
|
+
errors: replaceDetailsInMessages(response.errors, details),
|
|
15098
|
+
warnings: replaceDetailsInMessages(response.warnings, details),
|
|
15099
|
+
outputFiles: undefined,
|
|
15100
|
+
metafile: undefined,
|
|
15101
|
+
mangleCache: undefined
|
|
15102
|
+
};
|
|
15103
|
+
const originalErrors = result.errors.slice();
|
|
15104
|
+
const originalWarnings = result.warnings.slice();
|
|
15105
|
+
if (response.outputFiles)
|
|
15106
|
+
result.outputFiles = response.outputFiles.map(convertOutputFiles);
|
|
15107
|
+
if (response.metafile && response.metafile.length)
|
|
15108
|
+
result.metafile = parseJSON(response.metafile);
|
|
15109
|
+
if (response.mangleCache)
|
|
15110
|
+
result.mangleCache = response.mangleCache;
|
|
15111
|
+
if (response.writeToStdout !== undefined)
|
|
15112
|
+
console.log(decodeUTF8(response.writeToStdout).replace(/\n$/, ""));
|
|
15113
|
+
runOnEndCallbacks(result, (onEndErrors, onEndWarnings) => {
|
|
15114
|
+
if (originalErrors.length > 0 || onEndErrors.length > 0) {
|
|
15115
|
+
const error = failureErrorWithLog("Build failed", originalErrors.concat(onEndErrors), originalWarnings.concat(onEndWarnings));
|
|
15116
|
+
return callback2(error, null, onEndErrors, onEndWarnings);
|
|
15117
|
+
}
|
|
15118
|
+
callback2(null, result, onEndErrors, onEndWarnings);
|
|
15119
|
+
});
|
|
15120
|
+
};
|
|
15121
|
+
let latestResultPromise;
|
|
15122
|
+
let provideLatestResult;
|
|
15123
|
+
if (isContext)
|
|
15124
|
+
requestCallbacks["on-end"] = (id, request2) => new Promise((resolve2) => {
|
|
15125
|
+
buildResponseToResult(request2, (err, result, onEndErrors, onEndWarnings) => {
|
|
15126
|
+
const response = {
|
|
15127
|
+
errors: onEndErrors,
|
|
15128
|
+
warnings: onEndWarnings
|
|
15129
|
+
};
|
|
15130
|
+
if (provideLatestResult)
|
|
15131
|
+
provideLatestResult(err, result);
|
|
15132
|
+
latestResultPromise = undefined;
|
|
15133
|
+
provideLatestResult = undefined;
|
|
15134
|
+
sendResponse(id, response);
|
|
15135
|
+
resolve2();
|
|
15136
|
+
});
|
|
15137
|
+
});
|
|
15138
|
+
sendRequest(refs, request, (error, response) => {
|
|
15139
|
+
if (error)
|
|
15140
|
+
return callback(new Error(error), null);
|
|
15141
|
+
if (!isContext) {
|
|
15142
|
+
return buildResponseToResult(response, (err, res) => {
|
|
15143
|
+
scheduleOnDisposeCallbacks();
|
|
15144
|
+
return callback(err, res);
|
|
15145
|
+
});
|
|
15146
|
+
}
|
|
15147
|
+
if (response.errors.length > 0) {
|
|
15148
|
+
return callback(failureErrorWithLog("Context failed", response.errors, response.warnings), null);
|
|
15149
|
+
}
|
|
15150
|
+
let didDispose = false;
|
|
15151
|
+
const result = {
|
|
15152
|
+
rebuild: () => {
|
|
15153
|
+
if (!latestResultPromise)
|
|
15154
|
+
latestResultPromise = new Promise((resolve2, reject) => {
|
|
15155
|
+
let settlePromise;
|
|
15156
|
+
provideLatestResult = (err, result2) => {
|
|
15157
|
+
if (!settlePromise)
|
|
15158
|
+
settlePromise = () => err ? reject(err) : resolve2(result2);
|
|
15159
|
+
};
|
|
15160
|
+
const triggerAnotherBuild = () => {
|
|
15161
|
+
const request2 = {
|
|
15162
|
+
command: "rebuild",
|
|
15163
|
+
key: buildKey
|
|
15164
|
+
};
|
|
15165
|
+
sendRequest(refs, request2, (error2, response2) => {
|
|
15166
|
+
if (error2) {
|
|
15167
|
+
reject(new Error(error2));
|
|
15168
|
+
} else if (settlePromise) {
|
|
15169
|
+
settlePromise();
|
|
15170
|
+
} else {
|
|
15171
|
+
triggerAnotherBuild();
|
|
15172
|
+
}
|
|
15173
|
+
});
|
|
15174
|
+
};
|
|
15175
|
+
triggerAnotherBuild();
|
|
15176
|
+
});
|
|
15177
|
+
return latestResultPromise;
|
|
15178
|
+
},
|
|
15179
|
+
watch: (options2 = {}) => new Promise((resolve2, reject) => {
|
|
15180
|
+
if (!streamIn.hasFS)
|
|
15181
|
+
throw new Error(`Cannot use the "watch" API in this environment`);
|
|
15182
|
+
const keys = {};
|
|
15183
|
+
const delay = getFlag(options2, keys, "delay", mustBeInteger);
|
|
15184
|
+
checkForInvalidFlags(options2, keys, `in watch() call`);
|
|
15185
|
+
const request2 = {
|
|
15186
|
+
command: "watch",
|
|
15187
|
+
key: buildKey
|
|
15188
|
+
};
|
|
15189
|
+
if (delay)
|
|
15190
|
+
request2.delay = delay;
|
|
15191
|
+
sendRequest(refs, request2, (error2) => {
|
|
15192
|
+
if (error2)
|
|
15193
|
+
reject(new Error(error2));
|
|
15194
|
+
else
|
|
15195
|
+
resolve2(undefined);
|
|
15196
|
+
});
|
|
15197
|
+
}),
|
|
15198
|
+
serve: (options2 = {}) => new Promise((resolve2, reject) => {
|
|
15199
|
+
if (!streamIn.hasFS)
|
|
15200
|
+
throw new Error(`Cannot use the "serve" API in this environment`);
|
|
15201
|
+
const keys = {};
|
|
15202
|
+
const port = getFlag(options2, keys, "port", mustBeValidPortNumber);
|
|
15203
|
+
const host = getFlag(options2, keys, "host", mustBeString);
|
|
15204
|
+
const servedir = getFlag(options2, keys, "servedir", mustBeString);
|
|
15205
|
+
const keyfile = getFlag(options2, keys, "keyfile", mustBeString);
|
|
15206
|
+
const certfile = getFlag(options2, keys, "certfile", mustBeString);
|
|
15207
|
+
const fallback = getFlag(options2, keys, "fallback", mustBeString);
|
|
15208
|
+
const cors = getFlag(options2, keys, "cors", mustBeObject);
|
|
15209
|
+
const onRequest = getFlag(options2, keys, "onRequest", mustBeFunction);
|
|
15210
|
+
checkForInvalidFlags(options2, keys, `in serve() call`);
|
|
15211
|
+
const request2 = {
|
|
15212
|
+
command: "serve",
|
|
15213
|
+
key: buildKey,
|
|
15214
|
+
onRequest: !!onRequest
|
|
15215
|
+
};
|
|
15216
|
+
if (port !== undefined)
|
|
15217
|
+
request2.port = port;
|
|
15218
|
+
if (host !== undefined)
|
|
15219
|
+
request2.host = host;
|
|
15220
|
+
if (servedir !== undefined)
|
|
15221
|
+
request2.servedir = servedir;
|
|
15222
|
+
if (keyfile !== undefined)
|
|
15223
|
+
request2.keyfile = keyfile;
|
|
15224
|
+
if (certfile !== undefined)
|
|
15225
|
+
request2.certfile = certfile;
|
|
15226
|
+
if (fallback !== undefined)
|
|
15227
|
+
request2.fallback = fallback;
|
|
15228
|
+
if (cors) {
|
|
15229
|
+
const corsKeys = {};
|
|
15230
|
+
const origin = getFlag(cors, corsKeys, "origin", mustBeStringOrArrayOfStrings);
|
|
15231
|
+
checkForInvalidFlags(cors, corsKeys, `on "cors" object`);
|
|
15232
|
+
if (Array.isArray(origin))
|
|
15233
|
+
request2.corsOrigin = origin;
|
|
15234
|
+
else if (origin !== undefined)
|
|
15235
|
+
request2.corsOrigin = [origin];
|
|
15236
|
+
}
|
|
15237
|
+
sendRequest(refs, request2, (error2, response2) => {
|
|
15238
|
+
if (error2)
|
|
15239
|
+
return reject(new Error(error2));
|
|
15240
|
+
if (onRequest) {
|
|
15241
|
+
requestCallbacks["serve-request"] = (id, request3) => {
|
|
15242
|
+
onRequest(request3.args);
|
|
15243
|
+
sendResponse(id, {});
|
|
15244
|
+
};
|
|
15245
|
+
}
|
|
15246
|
+
resolve2(response2);
|
|
15247
|
+
});
|
|
15248
|
+
}),
|
|
15249
|
+
cancel: () => new Promise((resolve2) => {
|
|
15250
|
+
if (didDispose)
|
|
15251
|
+
return resolve2();
|
|
15252
|
+
const request2 = {
|
|
15253
|
+
command: "cancel",
|
|
15254
|
+
key: buildKey
|
|
15255
|
+
};
|
|
15256
|
+
sendRequest(refs, request2, () => {
|
|
15257
|
+
resolve2();
|
|
15258
|
+
});
|
|
15259
|
+
}),
|
|
15260
|
+
dispose: () => new Promise((resolve2) => {
|
|
15261
|
+
if (didDispose)
|
|
15262
|
+
return resolve2();
|
|
15263
|
+
didDispose = true;
|
|
15264
|
+
const request2 = {
|
|
15265
|
+
command: "dispose",
|
|
15266
|
+
key: buildKey
|
|
15267
|
+
};
|
|
15268
|
+
sendRequest(refs, request2, () => {
|
|
15269
|
+
resolve2();
|
|
15270
|
+
scheduleOnDisposeCallbacks();
|
|
15271
|
+
refs.unref();
|
|
15272
|
+
});
|
|
15273
|
+
})
|
|
15274
|
+
};
|
|
15275
|
+
refs.ref();
|
|
15276
|
+
callback(null, result);
|
|
15277
|
+
});
|
|
15278
|
+
}
|
|
15279
|
+
}
|
|
15280
|
+
var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, initialOptions, plugins, details) => {
|
|
15281
|
+
let onStartCallbacks = [];
|
|
15282
|
+
let onEndCallbacks = [];
|
|
15283
|
+
let onResolveCallbacks = {};
|
|
15284
|
+
let onLoadCallbacks = {};
|
|
15285
|
+
let onDisposeCallbacks = [];
|
|
15286
|
+
let nextCallbackID = 0;
|
|
15287
|
+
let i = 0;
|
|
15288
|
+
let requestPlugins = [];
|
|
15289
|
+
let isSetupDone = false;
|
|
15290
|
+
plugins = [...plugins];
|
|
15291
|
+
for (let item of plugins) {
|
|
15292
|
+
let keys = {};
|
|
15293
|
+
if (typeof item !== "object")
|
|
15294
|
+
throw new Error(`Plugin at index ${i} must be an object`);
|
|
15295
|
+
const name = getFlag(item, keys, "name", mustBeString);
|
|
15296
|
+
if (typeof name !== "string" || name === "")
|
|
15297
|
+
throw new Error(`Plugin at index ${i} is missing a name`);
|
|
15298
|
+
try {
|
|
15299
|
+
let setup = getFlag(item, keys, "setup", mustBeFunction);
|
|
15300
|
+
if (typeof setup !== "function")
|
|
15301
|
+
throw new Error(`Plugin is missing a setup function`);
|
|
15302
|
+
checkForInvalidFlags(item, keys, `on plugin ${quote(name)}`);
|
|
15303
|
+
let plugin = {
|
|
15304
|
+
name,
|
|
15305
|
+
onStart: false,
|
|
15306
|
+
onEnd: false,
|
|
15307
|
+
onResolve: [],
|
|
15308
|
+
onLoad: []
|
|
15309
|
+
};
|
|
15310
|
+
i++;
|
|
15311
|
+
let resolve2 = (path3, options = {}) => {
|
|
15312
|
+
if (!isSetupDone)
|
|
15313
|
+
throw new Error('Cannot call "resolve" before plugin setup has completed');
|
|
15314
|
+
if (typeof path3 !== "string")
|
|
15315
|
+
throw new Error(`The path to resolve must be a string`);
|
|
15316
|
+
let keys2 = /* @__PURE__ */ Object.create(null);
|
|
15317
|
+
let pluginName = getFlag(options, keys2, "pluginName", mustBeString);
|
|
15318
|
+
let importer = getFlag(options, keys2, "importer", mustBeString);
|
|
15319
|
+
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
15320
|
+
let resolveDir = getFlag(options, keys2, "resolveDir", mustBeString);
|
|
15321
|
+
let kind = getFlag(options, keys2, "kind", mustBeString);
|
|
15322
|
+
let pluginData = getFlag(options, keys2, "pluginData", canBeAnything);
|
|
15323
|
+
let importAttributes = getFlag(options, keys2, "with", mustBeObject);
|
|
15324
|
+
checkForInvalidFlags(options, keys2, "in resolve() call");
|
|
15325
|
+
return new Promise((resolve22, reject) => {
|
|
15326
|
+
const request = {
|
|
15327
|
+
command: "resolve",
|
|
15328
|
+
path: path3,
|
|
15329
|
+
key: buildKey,
|
|
15330
|
+
pluginName: name
|
|
15331
|
+
};
|
|
15332
|
+
if (pluginName != null)
|
|
15333
|
+
request.pluginName = pluginName;
|
|
15334
|
+
if (importer != null)
|
|
15335
|
+
request.importer = importer;
|
|
15336
|
+
if (namespace != null)
|
|
15337
|
+
request.namespace = namespace;
|
|
15338
|
+
if (resolveDir != null)
|
|
15339
|
+
request.resolveDir = resolveDir;
|
|
15340
|
+
if (kind != null)
|
|
15341
|
+
request.kind = kind;
|
|
15342
|
+
else
|
|
15343
|
+
throw new Error(`Must specify "kind" when calling "resolve"`);
|
|
15344
|
+
if (pluginData != null)
|
|
15345
|
+
request.pluginData = details.store(pluginData);
|
|
15346
|
+
if (importAttributes != null)
|
|
15347
|
+
request.with = sanitizeStringMap(importAttributes, "with");
|
|
15348
|
+
sendRequest(refs, request, (error, response) => {
|
|
15349
|
+
if (error !== null)
|
|
15350
|
+
reject(new Error(error));
|
|
15351
|
+
else
|
|
15352
|
+
resolve22({
|
|
15353
|
+
errors: replaceDetailsInMessages(response.errors, details),
|
|
15354
|
+
warnings: replaceDetailsInMessages(response.warnings, details),
|
|
15355
|
+
path: response.path,
|
|
15356
|
+
external: response.external,
|
|
15357
|
+
sideEffects: response.sideEffects,
|
|
15358
|
+
namespace: response.namespace,
|
|
15359
|
+
suffix: response.suffix,
|
|
15360
|
+
pluginData: details.load(response.pluginData)
|
|
15361
|
+
});
|
|
15362
|
+
});
|
|
15363
|
+
});
|
|
15364
|
+
};
|
|
15365
|
+
let promise = setup({
|
|
15366
|
+
initialOptions,
|
|
15367
|
+
resolve: resolve2,
|
|
15368
|
+
onStart(callback) {
|
|
15369
|
+
let registeredText = `This error came from the "onStart" callback registered here:`;
|
|
15370
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onStart");
|
|
15371
|
+
onStartCallbacks.push({ name, callback, note: registeredNote });
|
|
15372
|
+
plugin.onStart = true;
|
|
15373
|
+
},
|
|
15374
|
+
onEnd(callback) {
|
|
15375
|
+
let registeredText = `This error came from the "onEnd" callback registered here:`;
|
|
15376
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onEnd");
|
|
15377
|
+
onEndCallbacks.push({ name, callback, note: registeredNote });
|
|
15378
|
+
plugin.onEnd = true;
|
|
15379
|
+
},
|
|
15380
|
+
onResolve(options, callback) {
|
|
15381
|
+
let registeredText = `This error came from the "onResolve" callback registered here:`;
|
|
15382
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onResolve");
|
|
15383
|
+
let keys2 = {};
|
|
15384
|
+
let filter = getFlag(options, keys2, "filter", mustBeRegExp);
|
|
15385
|
+
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
15386
|
+
checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${quote(name)}`);
|
|
15387
|
+
if (filter == null)
|
|
15388
|
+
throw new Error(`onResolve() call is missing a filter`);
|
|
15389
|
+
let id = nextCallbackID++;
|
|
15390
|
+
onResolveCallbacks[id] = { name, callback, note: registeredNote };
|
|
15391
|
+
plugin.onResolve.push({ id, filter: jsRegExpToGoRegExp(filter), namespace: namespace || "" });
|
|
15392
|
+
},
|
|
15393
|
+
onLoad(options, callback) {
|
|
15394
|
+
let registeredText = `This error came from the "onLoad" callback registered here:`;
|
|
15395
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onLoad");
|
|
15396
|
+
let keys2 = {};
|
|
15397
|
+
let filter = getFlag(options, keys2, "filter", mustBeRegExp);
|
|
15398
|
+
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
15399
|
+
checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${quote(name)}`);
|
|
15400
|
+
if (filter == null)
|
|
15401
|
+
throw new Error(`onLoad() call is missing a filter`);
|
|
15402
|
+
let id = nextCallbackID++;
|
|
15403
|
+
onLoadCallbacks[id] = { name, callback, note: registeredNote };
|
|
15404
|
+
plugin.onLoad.push({ id, filter: jsRegExpToGoRegExp(filter), namespace: namespace || "" });
|
|
15405
|
+
},
|
|
15406
|
+
onDispose(callback) {
|
|
15407
|
+
onDisposeCallbacks.push(callback);
|
|
15408
|
+
},
|
|
15409
|
+
esbuild: streamIn.esbuild
|
|
15410
|
+
});
|
|
15411
|
+
if (promise)
|
|
15412
|
+
await promise;
|
|
15413
|
+
requestPlugins.push(plugin);
|
|
15414
|
+
} catch (e) {
|
|
15415
|
+
return { ok: false, error: e, pluginName: name };
|
|
15416
|
+
}
|
|
15417
|
+
}
|
|
15418
|
+
requestCallbacks["on-start"] = async (id, request) => {
|
|
15419
|
+
details.clear();
|
|
15420
|
+
let response = { errors: [], warnings: [] };
|
|
15421
|
+
await Promise.all(onStartCallbacks.map(async ({ name, callback, note }) => {
|
|
15422
|
+
try {
|
|
15423
|
+
let result = await callback();
|
|
15424
|
+
if (result != null) {
|
|
15425
|
+
if (typeof result !== "object")
|
|
15426
|
+
throw new Error(`Expected onStart() callback in plugin ${quote(name)} to return an object`);
|
|
15427
|
+
let keys = {};
|
|
15428
|
+
let errors3 = getFlag(result, keys, "errors", mustBeArray);
|
|
15429
|
+
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
15430
|
+
checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${quote(name)}`);
|
|
15431
|
+
if (errors3 != null)
|
|
15432
|
+
response.errors.push(...sanitizeMessages(errors3, "errors", details, name, undefined));
|
|
15433
|
+
if (warnings != null)
|
|
15434
|
+
response.warnings.push(...sanitizeMessages(warnings, "warnings", details, name, undefined));
|
|
15435
|
+
}
|
|
15436
|
+
} catch (e) {
|
|
15437
|
+
response.errors.push(extractErrorMessageV8(e, streamIn, details, note && note(), name));
|
|
15438
|
+
}
|
|
15439
|
+
}));
|
|
15440
|
+
sendResponse(id, response);
|
|
15441
|
+
};
|
|
15442
|
+
requestCallbacks["on-resolve"] = async (id, request) => {
|
|
15443
|
+
let response = {}, name = "", callback, note;
|
|
15444
|
+
for (let id2 of request.ids) {
|
|
15445
|
+
try {
|
|
15446
|
+
({ name, callback, note } = onResolveCallbacks[id2]);
|
|
15447
|
+
let result = await callback({
|
|
15448
|
+
path: request.path,
|
|
15449
|
+
importer: request.importer,
|
|
15450
|
+
namespace: request.namespace,
|
|
15451
|
+
resolveDir: request.resolveDir,
|
|
15452
|
+
kind: request.kind,
|
|
15453
|
+
pluginData: details.load(request.pluginData),
|
|
15454
|
+
with: request.with
|
|
15455
|
+
});
|
|
15456
|
+
if (result != null) {
|
|
15457
|
+
if (typeof result !== "object")
|
|
15458
|
+
throw new Error(`Expected onResolve() callback in plugin ${quote(name)} to return an object`);
|
|
15459
|
+
let keys = {};
|
|
15460
|
+
let pluginName = getFlag(result, keys, "pluginName", mustBeString);
|
|
15461
|
+
let path3 = getFlag(result, keys, "path", mustBeString);
|
|
15462
|
+
let namespace = getFlag(result, keys, "namespace", mustBeString);
|
|
15463
|
+
let suffix = getFlag(result, keys, "suffix", mustBeString);
|
|
15464
|
+
let external2 = getFlag(result, keys, "external", mustBeBoolean);
|
|
15465
|
+
let sideEffects = getFlag(result, keys, "sideEffects", mustBeBoolean);
|
|
15466
|
+
let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
|
|
15467
|
+
let errors3 = getFlag(result, keys, "errors", mustBeArray);
|
|
15468
|
+
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
15469
|
+
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArrayOfStrings);
|
|
15470
|
+
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArrayOfStrings);
|
|
15471
|
+
checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${quote(name)}`);
|
|
15472
|
+
response.id = id2;
|
|
15473
|
+
if (pluginName != null)
|
|
15474
|
+
response.pluginName = pluginName;
|
|
15475
|
+
if (path3 != null)
|
|
15476
|
+
response.path = path3;
|
|
15477
|
+
if (namespace != null)
|
|
15478
|
+
response.namespace = namespace;
|
|
15479
|
+
if (suffix != null)
|
|
15480
|
+
response.suffix = suffix;
|
|
15481
|
+
if (external2 != null)
|
|
15482
|
+
response.external = external2;
|
|
15483
|
+
if (sideEffects != null)
|
|
15484
|
+
response.sideEffects = sideEffects;
|
|
15485
|
+
if (pluginData != null)
|
|
15486
|
+
response.pluginData = details.store(pluginData);
|
|
15487
|
+
if (errors3 != null)
|
|
15488
|
+
response.errors = sanitizeMessages(errors3, "errors", details, name, undefined);
|
|
15489
|
+
if (warnings != null)
|
|
15490
|
+
response.warnings = sanitizeMessages(warnings, "warnings", details, name, undefined);
|
|
15491
|
+
if (watchFiles != null)
|
|
15492
|
+
response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
|
|
15493
|
+
if (watchDirs != null)
|
|
15494
|
+
response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
|
|
15495
|
+
break;
|
|
15496
|
+
}
|
|
15497
|
+
} catch (e) {
|
|
15498
|
+
response = { id: id2, errors: [extractErrorMessageV8(e, streamIn, details, note && note(), name)] };
|
|
15499
|
+
break;
|
|
15500
|
+
}
|
|
15501
|
+
}
|
|
15502
|
+
sendResponse(id, response);
|
|
15503
|
+
};
|
|
15504
|
+
requestCallbacks["on-load"] = async (id, request) => {
|
|
15505
|
+
let response = {}, name = "", callback, note;
|
|
15506
|
+
for (let id2 of request.ids) {
|
|
15507
|
+
try {
|
|
15508
|
+
({ name, callback, note } = onLoadCallbacks[id2]);
|
|
15509
|
+
let result = await callback({
|
|
15510
|
+
path: request.path,
|
|
15511
|
+
namespace: request.namespace,
|
|
15512
|
+
suffix: request.suffix,
|
|
15513
|
+
pluginData: details.load(request.pluginData),
|
|
15514
|
+
with: request.with
|
|
15515
|
+
});
|
|
15516
|
+
if (result != null) {
|
|
15517
|
+
if (typeof result !== "object")
|
|
15518
|
+
throw new Error(`Expected onLoad() callback in plugin ${quote(name)} to return an object`);
|
|
15519
|
+
let keys = {};
|
|
15520
|
+
let pluginName = getFlag(result, keys, "pluginName", mustBeString);
|
|
15521
|
+
let contents = getFlag(result, keys, "contents", mustBeStringOrUint8Array);
|
|
15522
|
+
let resolveDir = getFlag(result, keys, "resolveDir", mustBeString);
|
|
15523
|
+
let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
|
|
15524
|
+
let loader = getFlag(result, keys, "loader", mustBeString);
|
|
15525
|
+
let errors3 = getFlag(result, keys, "errors", mustBeArray);
|
|
15526
|
+
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
15527
|
+
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArrayOfStrings);
|
|
15528
|
+
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArrayOfStrings);
|
|
15529
|
+
checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${quote(name)}`);
|
|
15530
|
+
response.id = id2;
|
|
15531
|
+
if (pluginName != null)
|
|
15532
|
+
response.pluginName = pluginName;
|
|
15533
|
+
if (contents instanceof Uint8Array)
|
|
15534
|
+
response.contents = contents;
|
|
15535
|
+
else if (contents != null)
|
|
15536
|
+
response.contents = encodeUTF8(contents);
|
|
15537
|
+
if (resolveDir != null)
|
|
15538
|
+
response.resolveDir = resolveDir;
|
|
15539
|
+
if (pluginData != null)
|
|
15540
|
+
response.pluginData = details.store(pluginData);
|
|
15541
|
+
if (loader != null)
|
|
15542
|
+
response.loader = loader;
|
|
15543
|
+
if (errors3 != null)
|
|
15544
|
+
response.errors = sanitizeMessages(errors3, "errors", details, name, undefined);
|
|
15545
|
+
if (warnings != null)
|
|
15546
|
+
response.warnings = sanitizeMessages(warnings, "warnings", details, name, undefined);
|
|
15547
|
+
if (watchFiles != null)
|
|
15548
|
+
response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
|
|
15549
|
+
if (watchDirs != null)
|
|
15550
|
+
response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
|
|
15551
|
+
break;
|
|
15552
|
+
}
|
|
15553
|
+
} catch (e) {
|
|
15554
|
+
response = { id: id2, errors: [extractErrorMessageV8(e, streamIn, details, note && note(), name)] };
|
|
15555
|
+
break;
|
|
15556
|
+
}
|
|
15557
|
+
}
|
|
15558
|
+
sendResponse(id, response);
|
|
15559
|
+
};
|
|
15560
|
+
let runOnEndCallbacks = (result, done) => done([], []);
|
|
15561
|
+
if (onEndCallbacks.length > 0) {
|
|
15562
|
+
runOnEndCallbacks = (result, done) => {
|
|
15563
|
+
(async () => {
|
|
15564
|
+
const onEndErrors = [];
|
|
15565
|
+
const onEndWarnings = [];
|
|
15566
|
+
for (const { name, callback, note } of onEndCallbacks) {
|
|
15567
|
+
let newErrors;
|
|
15568
|
+
let newWarnings;
|
|
15569
|
+
try {
|
|
15570
|
+
const value = await callback(result);
|
|
15571
|
+
if (value != null) {
|
|
15572
|
+
if (typeof value !== "object")
|
|
15573
|
+
throw new Error(`Expected onEnd() callback in plugin ${quote(name)} to return an object`);
|
|
15574
|
+
let keys = {};
|
|
15575
|
+
let errors3 = getFlag(value, keys, "errors", mustBeArray);
|
|
15576
|
+
let warnings = getFlag(value, keys, "warnings", mustBeArray);
|
|
15577
|
+
checkForInvalidFlags(value, keys, `from onEnd() callback in plugin ${quote(name)}`);
|
|
15578
|
+
if (errors3 != null)
|
|
15579
|
+
newErrors = sanitizeMessages(errors3, "errors", details, name, undefined);
|
|
15580
|
+
if (warnings != null)
|
|
15581
|
+
newWarnings = sanitizeMessages(warnings, "warnings", details, name, undefined);
|
|
15582
|
+
}
|
|
15583
|
+
} catch (e) {
|
|
15584
|
+
newErrors = [extractErrorMessageV8(e, streamIn, details, note && note(), name)];
|
|
15585
|
+
}
|
|
15586
|
+
if (newErrors) {
|
|
15587
|
+
onEndErrors.push(...newErrors);
|
|
15588
|
+
try {
|
|
15589
|
+
result.errors.push(...newErrors);
|
|
15590
|
+
} catch {}
|
|
15591
|
+
}
|
|
15592
|
+
if (newWarnings) {
|
|
15593
|
+
onEndWarnings.push(...newWarnings);
|
|
15594
|
+
try {
|
|
15595
|
+
result.warnings.push(...newWarnings);
|
|
15596
|
+
} catch {}
|
|
15597
|
+
}
|
|
15598
|
+
}
|
|
15599
|
+
done(onEndErrors, onEndWarnings);
|
|
15600
|
+
})();
|
|
15601
|
+
};
|
|
15602
|
+
}
|
|
15603
|
+
let scheduleOnDisposeCallbacks = () => {
|
|
15604
|
+
for (const cb of onDisposeCallbacks) {
|
|
15605
|
+
setTimeout(() => cb(), 0);
|
|
15606
|
+
}
|
|
15607
|
+
};
|
|
15608
|
+
isSetupDone = true;
|
|
15609
|
+
return {
|
|
15610
|
+
ok: true,
|
|
15611
|
+
requestPlugins,
|
|
15612
|
+
runOnEndCallbacks,
|
|
15613
|
+
scheduleOnDisposeCallbacks
|
|
15614
|
+
};
|
|
15615
|
+
};
|
|
15616
|
+
function createObjectStash() {
|
|
15617
|
+
const map = /* @__PURE__ */ new Map;
|
|
15618
|
+
let nextID = 0;
|
|
15619
|
+
return {
|
|
15620
|
+
clear() {
|
|
15621
|
+
map.clear();
|
|
15622
|
+
},
|
|
15623
|
+
load(id) {
|
|
15624
|
+
return map.get(id);
|
|
15625
|
+
},
|
|
15626
|
+
store(value) {
|
|
15627
|
+
if (value === undefined)
|
|
15628
|
+
return -1;
|
|
15629
|
+
const id = nextID++;
|
|
15630
|
+
map.set(id, value);
|
|
15631
|
+
return id;
|
|
15632
|
+
}
|
|
15633
|
+
};
|
|
15634
|
+
}
|
|
15635
|
+
function extractCallerV8(e, streamIn, ident) {
|
|
15636
|
+
let note;
|
|
15637
|
+
let tried = false;
|
|
15638
|
+
return () => {
|
|
15639
|
+
if (tried)
|
|
15640
|
+
return note;
|
|
15641
|
+
tried = true;
|
|
15642
|
+
try {
|
|
15643
|
+
let lines = (e.stack + "").split(`
|
|
15644
|
+
`);
|
|
15645
|
+
lines.splice(1, 1);
|
|
15646
|
+
let location = parseStackLinesV8(streamIn, lines, ident);
|
|
15647
|
+
if (location) {
|
|
15648
|
+
note = { text: e.message, location };
|
|
15649
|
+
return note;
|
|
15650
|
+
}
|
|
15651
|
+
} catch {}
|
|
15652
|
+
};
|
|
15653
|
+
}
|
|
15654
|
+
function extractErrorMessageV8(e, streamIn, stash, note, pluginName) {
|
|
15655
|
+
let text3 = "Internal error";
|
|
15656
|
+
let location = null;
|
|
15657
|
+
try {
|
|
15658
|
+
text3 = (e && e.message || e) + "";
|
|
15659
|
+
} catch {}
|
|
15660
|
+
try {
|
|
15661
|
+
location = parseStackLinesV8(streamIn, (e.stack + "").split(`
|
|
15662
|
+
`), "");
|
|
15663
|
+
} catch {}
|
|
15664
|
+
return { id: "", pluginName, text: text3, location, notes: note ? [note] : [], detail: stash ? stash.store(e) : -1 };
|
|
15665
|
+
}
|
|
15666
|
+
function parseStackLinesV8(streamIn, lines, ident) {
|
|
15667
|
+
let at = " at ";
|
|
15668
|
+
if (streamIn.readFileSync && !lines[0].startsWith(at) && lines[1].startsWith(at)) {
|
|
15669
|
+
for (let i = 1;i < lines.length; i++) {
|
|
15670
|
+
let line3 = lines[i];
|
|
15671
|
+
if (!line3.startsWith(at))
|
|
15672
|
+
continue;
|
|
15673
|
+
line3 = line3.slice(at.length);
|
|
15674
|
+
while (true) {
|
|
15675
|
+
let match = /^(?:new |async )?\S+ \((.*)\)$/.exec(line3);
|
|
15676
|
+
if (match) {
|
|
15677
|
+
line3 = match[1];
|
|
15678
|
+
continue;
|
|
15679
|
+
}
|
|
15680
|
+
match = /^eval at \S+ \((.*)\)(?:, \S+:\d+:\d+)?$/.exec(line3);
|
|
15681
|
+
if (match) {
|
|
15682
|
+
line3 = match[1];
|
|
15683
|
+
continue;
|
|
15684
|
+
}
|
|
15685
|
+
match = /^(\S+):(\d+):(\d+)$/.exec(line3);
|
|
15686
|
+
if (match) {
|
|
15687
|
+
let contents;
|
|
15688
|
+
try {
|
|
15689
|
+
contents = streamIn.readFileSync(match[1], "utf8");
|
|
15690
|
+
} catch {
|
|
15691
|
+
break;
|
|
15692
|
+
}
|
|
15693
|
+
let lineText = contents.split(/\r\n|\r|\n|\u2028|\u2029/)[+match[2] - 1] || "";
|
|
15694
|
+
let column2 = +match[3] - 1;
|
|
15695
|
+
let length = lineText.slice(column2, column2 + ident.length) === ident ? ident.length : 0;
|
|
15696
|
+
return {
|
|
15697
|
+
file: match[1],
|
|
15698
|
+
namespace: "file",
|
|
15699
|
+
line: +match[2],
|
|
15700
|
+
column: encodeUTF8(lineText.slice(0, column2)).length,
|
|
15701
|
+
length: encodeUTF8(lineText.slice(column2, column2 + length)).length,
|
|
15702
|
+
lineText: lineText + `
|
|
15703
|
+
` + lines.slice(1).join(`
|
|
15704
|
+
`),
|
|
15705
|
+
suggestion: ""
|
|
15706
|
+
};
|
|
15707
|
+
}
|
|
15708
|
+
break;
|
|
15709
|
+
}
|
|
15710
|
+
}
|
|
15711
|
+
}
|
|
15712
|
+
return null;
|
|
15713
|
+
}
|
|
15714
|
+
function failureErrorWithLog(text3, errors3, warnings) {
|
|
15715
|
+
let limit = 5;
|
|
15716
|
+
text3 += errors3.length < 1 ? "" : ` with ${errors3.length} error${errors3.length < 2 ? "" : "s"}:` + errors3.slice(0, limit + 1).map((e, i) => {
|
|
15717
|
+
if (i === limit)
|
|
15718
|
+
return `
|
|
15719
|
+
...`;
|
|
15720
|
+
if (!e.location)
|
|
15721
|
+
return `
|
|
15722
|
+
error: ${e.text}`;
|
|
15723
|
+
let { file, line: line3, column: column2 } = e.location;
|
|
15724
|
+
let pluginText = e.pluginName ? `[plugin: ${e.pluginName}] ` : "";
|
|
15725
|
+
return `
|
|
15726
|
+
${file}:${line3}:${column2}: ERROR: ${pluginText}${e.text}`;
|
|
15727
|
+
}).join("");
|
|
15728
|
+
let error = new Error(text3);
|
|
15729
|
+
for (const [key, value] of [["errors", errors3], ["warnings", warnings]]) {
|
|
15730
|
+
Object.defineProperty(error, key, {
|
|
15731
|
+
configurable: true,
|
|
15732
|
+
enumerable: true,
|
|
15733
|
+
get: () => value,
|
|
15734
|
+
set: (value2) => Object.defineProperty(error, key, {
|
|
15735
|
+
configurable: true,
|
|
15736
|
+
enumerable: true,
|
|
15737
|
+
value: value2
|
|
15738
|
+
})
|
|
15739
|
+
});
|
|
15740
|
+
}
|
|
15741
|
+
return error;
|
|
15742
|
+
}
|
|
15743
|
+
function replaceDetailsInMessages(messages2, stash) {
|
|
15744
|
+
for (const message of messages2) {
|
|
15745
|
+
message.detail = stash.load(message.detail);
|
|
15746
|
+
}
|
|
15747
|
+
return messages2;
|
|
15748
|
+
}
|
|
15749
|
+
function sanitizeLocation(location, where, terminalWidth) {
|
|
15750
|
+
if (location == null)
|
|
15751
|
+
return null;
|
|
15752
|
+
let keys = {};
|
|
15753
|
+
let file = getFlag(location, keys, "file", mustBeString);
|
|
15754
|
+
let namespace = getFlag(location, keys, "namespace", mustBeString);
|
|
15755
|
+
let line3 = getFlag(location, keys, "line", mustBeInteger);
|
|
15756
|
+
let column2 = getFlag(location, keys, "column", mustBeInteger);
|
|
15757
|
+
let length = getFlag(location, keys, "length", mustBeInteger);
|
|
15758
|
+
let lineText = getFlag(location, keys, "lineText", mustBeString);
|
|
15759
|
+
let suggestion = getFlag(location, keys, "suggestion", mustBeString);
|
|
15760
|
+
checkForInvalidFlags(location, keys, where);
|
|
15761
|
+
if (lineText) {
|
|
15762
|
+
const relevantASCII = lineText.slice(0, (column2 && column2 > 0 ? column2 : 0) + (length && length > 0 ? length : 0) + (terminalWidth && terminalWidth > 0 ? terminalWidth : 80));
|
|
15763
|
+
if (!/[\x7F-\uFFFF]/.test(relevantASCII) && !/\n/.test(lineText)) {
|
|
15764
|
+
lineText = relevantASCII;
|
|
15765
|
+
}
|
|
15766
|
+
}
|
|
15767
|
+
return {
|
|
15768
|
+
file: file || "",
|
|
15769
|
+
namespace: namespace || "",
|
|
15770
|
+
line: line3 || 0,
|
|
15771
|
+
column: column2 || 0,
|
|
15772
|
+
length: length || 0,
|
|
15773
|
+
lineText: lineText || "",
|
|
15774
|
+
suggestion: suggestion || ""
|
|
15775
|
+
};
|
|
15776
|
+
}
|
|
15777
|
+
function sanitizeMessages(messages2, property, stash, fallbackPluginName, terminalWidth) {
|
|
15778
|
+
let messagesClone = [];
|
|
15779
|
+
let index2 = 0;
|
|
15780
|
+
for (const message of messages2) {
|
|
15781
|
+
let keys = {};
|
|
15782
|
+
let id = getFlag(message, keys, "id", mustBeString);
|
|
15783
|
+
let pluginName = getFlag(message, keys, "pluginName", mustBeString);
|
|
15784
|
+
let text3 = getFlag(message, keys, "text", mustBeString);
|
|
15785
|
+
let location = getFlag(message, keys, "location", mustBeObjectOrNull);
|
|
15786
|
+
let notes = getFlag(message, keys, "notes", mustBeArray);
|
|
15787
|
+
let detail = getFlag(message, keys, "detail", canBeAnything);
|
|
15788
|
+
let where = `in element ${index2} of "${property}"`;
|
|
15789
|
+
checkForInvalidFlags(message, keys, where);
|
|
15790
|
+
let notesClone = [];
|
|
15791
|
+
if (notes) {
|
|
15792
|
+
for (const note of notes) {
|
|
15793
|
+
let noteKeys = {};
|
|
15794
|
+
let noteText = getFlag(note, noteKeys, "text", mustBeString);
|
|
15795
|
+
let noteLocation = getFlag(note, noteKeys, "location", mustBeObjectOrNull);
|
|
15796
|
+
checkForInvalidFlags(note, noteKeys, where);
|
|
15797
|
+
notesClone.push({
|
|
15798
|
+
text: noteText || "",
|
|
15799
|
+
location: sanitizeLocation(noteLocation, where, terminalWidth)
|
|
15800
|
+
});
|
|
15801
|
+
}
|
|
15802
|
+
}
|
|
15803
|
+
messagesClone.push({
|
|
15804
|
+
id: id || "",
|
|
15805
|
+
pluginName: pluginName || fallbackPluginName,
|
|
15806
|
+
text: text3 || "",
|
|
15807
|
+
location: sanitizeLocation(location, where, terminalWidth),
|
|
15808
|
+
notes: notesClone,
|
|
15809
|
+
detail: stash ? stash.store(detail) : -1
|
|
15810
|
+
});
|
|
15811
|
+
index2++;
|
|
15812
|
+
}
|
|
15813
|
+
return messagesClone;
|
|
15814
|
+
}
|
|
15815
|
+
function sanitizeStringArray(values2, property) {
|
|
15816
|
+
const result = [];
|
|
15817
|
+
for (const value of values2) {
|
|
15818
|
+
if (typeof value !== "string")
|
|
15819
|
+
throw new Error(`${quote(property)} must be an array of strings`);
|
|
15820
|
+
result.push(value);
|
|
15821
|
+
}
|
|
15822
|
+
return result;
|
|
15823
|
+
}
|
|
15824
|
+
function sanitizeStringMap(map, property) {
|
|
15825
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
15826
|
+
for (const key in map) {
|
|
15827
|
+
const value = map[key];
|
|
15828
|
+
if (typeof value !== "string")
|
|
15829
|
+
throw new Error(`key ${quote(key)} in object ${quote(property)} must be a string`);
|
|
15830
|
+
result[key] = value;
|
|
15831
|
+
}
|
|
15832
|
+
return result;
|
|
15833
|
+
}
|
|
15834
|
+
function convertOutputFiles({ path: path3, contents, hash }) {
|
|
15835
|
+
let text3 = null;
|
|
15836
|
+
return {
|
|
15837
|
+
path: path3,
|
|
15838
|
+
contents,
|
|
15839
|
+
hash,
|
|
15840
|
+
get text() {
|
|
15841
|
+
const binary = this.contents;
|
|
15842
|
+
if (text3 === null || binary !== contents) {
|
|
15843
|
+
contents = binary;
|
|
15844
|
+
text3 = decodeUTF8(binary);
|
|
15845
|
+
}
|
|
15846
|
+
return text3;
|
|
15847
|
+
}
|
|
15848
|
+
};
|
|
15849
|
+
}
|
|
15850
|
+
function jsRegExpToGoRegExp(regexp) {
|
|
15851
|
+
let result = regexp.source;
|
|
15852
|
+
if (regexp.flags)
|
|
15853
|
+
result = `(?${regexp.flags})${result}`;
|
|
15854
|
+
return result;
|
|
15855
|
+
}
|
|
15856
|
+
function parseJSON(bytes) {
|
|
15857
|
+
let text3;
|
|
15858
|
+
try {
|
|
15859
|
+
text3 = decodeUTF8(bytes);
|
|
15860
|
+
} catch {
|
|
15861
|
+
return JSON_parse(bytes);
|
|
15862
|
+
}
|
|
15863
|
+
return JSON.parse(text3);
|
|
15864
|
+
}
|
|
15865
|
+
var fs2 = __require("fs");
|
|
15866
|
+
var os2 = __require("os");
|
|
15867
|
+
var path = __require("path");
|
|
15868
|
+
var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
|
|
15869
|
+
var isValidBinaryPath = (x) => !!x && x !== "/usr/bin/esbuild";
|
|
15870
|
+
var packageDarwin_arm64 = "@esbuild/darwin-arm64";
|
|
15871
|
+
var packageDarwin_x64 = "@esbuild/darwin-x64";
|
|
15872
|
+
var knownWindowsPackages = {
|
|
15873
|
+
"win32 arm64 LE": "@esbuild/win32-arm64",
|
|
15874
|
+
"win32 ia32 LE": "@esbuild/win32-ia32",
|
|
15875
|
+
"win32 x64 LE": "@esbuild/win32-x64"
|
|
15876
|
+
};
|
|
15877
|
+
var knownUnixlikePackages = {
|
|
15878
|
+
"aix ppc64 BE": "@esbuild/aix-ppc64",
|
|
15879
|
+
"android arm64 LE": "@esbuild/android-arm64",
|
|
15880
|
+
"darwin arm64 LE": "@esbuild/darwin-arm64",
|
|
15881
|
+
"darwin x64 LE": "@esbuild/darwin-x64",
|
|
15882
|
+
"freebsd arm64 LE": "@esbuild/freebsd-arm64",
|
|
15883
|
+
"freebsd x64 LE": "@esbuild/freebsd-x64",
|
|
15884
|
+
"linux arm LE": "@esbuild/linux-arm",
|
|
15885
|
+
"linux arm64 LE": "@esbuild/linux-arm64",
|
|
15886
|
+
"linux ia32 LE": "@esbuild/linux-ia32",
|
|
15887
|
+
"linux mips64el LE": "@esbuild/linux-mips64el",
|
|
15888
|
+
"linux ppc64 LE": "@esbuild/linux-ppc64",
|
|
15889
|
+
"linux riscv64 LE": "@esbuild/linux-riscv64",
|
|
15890
|
+
"linux s390x BE": "@esbuild/linux-s390x",
|
|
15891
|
+
"linux x64 LE": "@esbuild/linux-x64",
|
|
15892
|
+
"linux loong64 LE": "@esbuild/linux-loong64",
|
|
15893
|
+
"netbsd arm64 LE": "@esbuild/netbsd-arm64",
|
|
15894
|
+
"netbsd x64 LE": "@esbuild/netbsd-x64",
|
|
15895
|
+
"openbsd arm64 LE": "@esbuild/openbsd-arm64",
|
|
15896
|
+
"openbsd x64 LE": "@esbuild/openbsd-x64",
|
|
15897
|
+
"sunos x64 LE": "@esbuild/sunos-x64"
|
|
15898
|
+
};
|
|
15899
|
+
var knownWebAssemblyFallbackPackages = {
|
|
15900
|
+
"android arm LE": "@esbuild/android-arm",
|
|
15901
|
+
"android x64 LE": "@esbuild/android-x64",
|
|
15902
|
+
"openharmony arm64 LE": "@esbuild/openharmony-arm64"
|
|
15903
|
+
};
|
|
15904
|
+
function pkgAndSubpathForCurrentPlatform() {
|
|
15905
|
+
let pkg;
|
|
15906
|
+
let subpath;
|
|
15907
|
+
let isWASM = false;
|
|
15908
|
+
let platformKey = `${process.platform} ${os2.arch()} ${os2.endianness()}`;
|
|
15909
|
+
if (platformKey in knownWindowsPackages) {
|
|
15910
|
+
pkg = knownWindowsPackages[platformKey];
|
|
15911
|
+
subpath = "esbuild.exe";
|
|
15912
|
+
} else if (platformKey in knownUnixlikePackages) {
|
|
15913
|
+
pkg = knownUnixlikePackages[platformKey];
|
|
15914
|
+
subpath = "bin/esbuild";
|
|
15915
|
+
} else if (platformKey in knownWebAssemblyFallbackPackages) {
|
|
15916
|
+
pkg = knownWebAssemblyFallbackPackages[platformKey];
|
|
15917
|
+
subpath = "bin/esbuild";
|
|
15918
|
+
isWASM = true;
|
|
15919
|
+
} else {
|
|
15920
|
+
throw new Error(`Unsupported platform: ${platformKey}`);
|
|
15921
|
+
}
|
|
15922
|
+
return { pkg, subpath, isWASM };
|
|
15923
|
+
}
|
|
15924
|
+
function pkgForSomeOtherPlatform() {
|
|
15925
|
+
const libMainJS = __require.resolve("esbuild");
|
|
15926
|
+
const nodeModulesDirectory = path.dirname(path.dirname(path.dirname(libMainJS)));
|
|
15927
|
+
if (path.basename(nodeModulesDirectory) === "node_modules") {
|
|
15928
|
+
for (const unixKey in knownUnixlikePackages) {
|
|
15929
|
+
try {
|
|
15930
|
+
const pkg = knownUnixlikePackages[unixKey];
|
|
15931
|
+
if (fs2.existsSync(path.join(nodeModulesDirectory, pkg)))
|
|
15932
|
+
return pkg;
|
|
15933
|
+
} catch {}
|
|
15934
|
+
}
|
|
15935
|
+
for (const windowsKey in knownWindowsPackages) {
|
|
15936
|
+
try {
|
|
15937
|
+
const pkg = knownWindowsPackages[windowsKey];
|
|
15938
|
+
if (fs2.existsSync(path.join(nodeModulesDirectory, pkg)))
|
|
15939
|
+
return pkg;
|
|
15940
|
+
} catch {}
|
|
15941
|
+
}
|
|
15942
|
+
}
|
|
15943
|
+
return null;
|
|
15944
|
+
}
|
|
15945
|
+
function downloadedBinPath(pkg, subpath) {
|
|
15946
|
+
const esbuildLibDir = path.dirname(__require.resolve("esbuild"));
|
|
15947
|
+
return path.join(esbuildLibDir, `downloaded-${pkg.replace("/", "-")}-${path.basename(subpath)}`);
|
|
15948
|
+
}
|
|
15949
|
+
function generateBinPath() {
|
|
15950
|
+
if (isValidBinaryPath(ESBUILD_BINARY_PATH)) {
|
|
15951
|
+
if (!fs2.existsSync(ESBUILD_BINARY_PATH)) {
|
|
15952
|
+
console.warn(`[esbuild] Ignoring bad configuration: ESBUILD_BINARY_PATH=${ESBUILD_BINARY_PATH}`);
|
|
15953
|
+
} else {
|
|
15954
|
+
return { binPath: ESBUILD_BINARY_PATH, isWASM: false };
|
|
15955
|
+
}
|
|
15956
|
+
}
|
|
15957
|
+
const { pkg, subpath, isWASM } = pkgAndSubpathForCurrentPlatform();
|
|
15958
|
+
let binPath;
|
|
15959
|
+
try {
|
|
15960
|
+
binPath = __require.resolve(`${pkg}/${subpath}`);
|
|
15961
|
+
} catch (e) {
|
|
15962
|
+
binPath = downloadedBinPath(pkg, subpath);
|
|
15963
|
+
if (!fs2.existsSync(binPath)) {
|
|
15964
|
+
try {
|
|
15965
|
+
__require.resolve(pkg);
|
|
15966
|
+
} catch {
|
|
15967
|
+
const otherPkg = pkgForSomeOtherPlatform();
|
|
15968
|
+
if (otherPkg) {
|
|
15969
|
+
let suggestions = `
|
|
15970
|
+
Specifically the "${otherPkg}" package is present but this platform
|
|
15971
|
+
needs the "${pkg}" package instead. People often get into this
|
|
15972
|
+
situation by installing esbuild on Windows or macOS and copying "node_modules"
|
|
15973
|
+
into a Docker image that runs Linux, or by copying "node_modules" between
|
|
15974
|
+
Windows and WSL environments.
|
|
15975
|
+
|
|
15976
|
+
If you are installing with npm, you can try not copying the "node_modules"
|
|
15977
|
+
directory when you copy the files over, and running "npm ci" or "npm install"
|
|
15978
|
+
on the destination platform after the copy. Or you could consider using yarn
|
|
15979
|
+
instead of npm which has built-in support for installing a package on multiple
|
|
15980
|
+
platforms simultaneously.
|
|
15981
|
+
|
|
15982
|
+
If you are installing with yarn, you can try listing both this platform and the
|
|
15983
|
+
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
|
|
15984
|
+
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
15985
|
+
Keep in mind that this means multiple copies of esbuild will be present.
|
|
15986
|
+
`;
|
|
15987
|
+
if (pkg === packageDarwin_x64 && otherPkg === packageDarwin_arm64 || pkg === packageDarwin_arm64 && otherPkg === packageDarwin_x64) {
|
|
15988
|
+
suggestions = `
|
|
15989
|
+
Specifically the "${otherPkg}" package is present but this platform
|
|
15990
|
+
needs the "${pkg}" package instead. People often get into this
|
|
15991
|
+
situation by installing esbuild with npm running inside of Rosetta 2 and then
|
|
15992
|
+
trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta
|
|
15993
|
+
2 is Apple's on-the-fly x86_64-to-arm64 translation service).
|
|
15994
|
+
|
|
15995
|
+
If you are installing with npm, you can try ensuring that both npm and node are
|
|
15996
|
+
not running under Rosetta 2 and then reinstalling esbuild. This likely involves
|
|
15997
|
+
changing how you installed npm and/or node. For example, installing node with
|
|
15998
|
+
the universal installer here should work: https://nodejs.org/en/download/. Or
|
|
15999
|
+
you could consider using yarn instead of npm which has built-in support for
|
|
16000
|
+
installing a package on multiple platforms simultaneously.
|
|
16001
|
+
|
|
16002
|
+
If you are installing with yarn, you can try listing both "arm64" and "x64"
|
|
16003
|
+
in your ".yarnrc.yml" file using the "supportedArchitectures" feature:
|
|
16004
|
+
https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
16005
|
+
Keep in mind that this means multiple copies of esbuild will be present.
|
|
16006
|
+
`;
|
|
16007
|
+
}
|
|
16008
|
+
throw new Error(`
|
|
16009
|
+
You installed esbuild for another platform than the one you're currently using.
|
|
16010
|
+
This won't work because esbuild is written with native code and needs to
|
|
16011
|
+
install a platform-specific binary executable.
|
|
16012
|
+
${suggestions}
|
|
16013
|
+
Another alternative is to use the "esbuild-wasm" package instead, which works
|
|
16014
|
+
the same way on all platforms. But it comes with a heavy performance cost and
|
|
16015
|
+
can sometimes be 10x slower than the "esbuild" package, so you may also not
|
|
16016
|
+
want to do that.
|
|
16017
|
+
`);
|
|
16018
|
+
}
|
|
16019
|
+
throw new Error(`The package "${pkg}" could not be found, and is needed by esbuild.
|
|
16020
|
+
|
|
16021
|
+
If you are installing esbuild with npm, make sure that you don't specify the
|
|
16022
|
+
"--no-optional" or "--omit=optional" flags. The "optionalDependencies" feature
|
|
16023
|
+
of "package.json" is used by esbuild to install the correct binary executable
|
|
16024
|
+
for your current platform.`);
|
|
16025
|
+
}
|
|
16026
|
+
throw e;
|
|
16027
|
+
}
|
|
16028
|
+
}
|
|
16029
|
+
if (/\.zip\//.test(binPath)) {
|
|
16030
|
+
let pnpapi;
|
|
16031
|
+
try {
|
|
16032
|
+
pnpapi = (()=>{throw new Error("Cannot require module "+"pnpapi");})();
|
|
16033
|
+
} catch (e) {}
|
|
16034
|
+
if (pnpapi) {
|
|
16035
|
+
const root = pnpapi.getPackageInformation(pnpapi.topLevel).packageLocation;
|
|
16036
|
+
const binTargetPath = path.join(root, "node_modules", ".cache", "esbuild", `pnpapi-${pkg.replace("/", "-")}-${"0.28.0"}-${path.basename(subpath)}`);
|
|
16037
|
+
if (!fs2.existsSync(binTargetPath)) {
|
|
16038
|
+
fs2.mkdirSync(path.dirname(binTargetPath), { recursive: true });
|
|
16039
|
+
fs2.copyFileSync(binPath, binTargetPath);
|
|
16040
|
+
fs2.chmodSync(binTargetPath, 493);
|
|
16041
|
+
}
|
|
16042
|
+
return { binPath: binTargetPath, isWASM };
|
|
16043
|
+
}
|
|
16044
|
+
}
|
|
16045
|
+
return { binPath, isWASM };
|
|
16046
|
+
}
|
|
16047
|
+
var child_process = __require("child_process");
|
|
16048
|
+
var crypto2 = __require("crypto");
|
|
16049
|
+
var path2 = __require("path");
|
|
16050
|
+
var fs22 = __require("fs");
|
|
16051
|
+
var os22 = __require("os");
|
|
16052
|
+
var tty = __require("tty");
|
|
16053
|
+
var worker_threads;
|
|
16054
|
+
if (process.env.ESBUILD_WORKER_THREADS !== "0") {
|
|
16055
|
+
try {
|
|
16056
|
+
worker_threads = __require("worker_threads");
|
|
16057
|
+
} catch {}
|
|
16058
|
+
let [major, minor] = process.versions.node.split(".");
|
|
16059
|
+
if (+major < 12 || +major === 12 && +minor < 17 || +major === 13 && +minor < 13) {
|
|
16060
|
+
worker_threads = undefined;
|
|
16061
|
+
}
|
|
16062
|
+
}
|
|
16063
|
+
var _a;
|
|
16064
|
+
var isInternalWorkerThread = ((_a = worker_threads == null ? undefined : worker_threads.workerData) == null ? undefined : _a.esbuildVersion) === "0.28.0";
|
|
16065
|
+
var esbuildCommandAndArgs = () => {
|
|
16066
|
+
if ((!ESBUILD_BINARY_PATH || false) && (path2.basename(__filename) !== "main.js" || path2.basename(__dirname) !== "lib")) {
|
|
16067
|
+
throw new Error(`The esbuild JavaScript API cannot be bundled. Please mark the "esbuild" package as external so it's not included in the bundle.
|
|
16068
|
+
|
|
16069
|
+
More information: The file containing the code for esbuild's JavaScript API (${__filename}) does not appear to be inside the esbuild package on the file system, which usually means that the esbuild package was bundled into another file. This is problematic because the API needs to run a binary executable inside the esbuild package which is located using a relative path from the API code to the executable. If the esbuild package is bundled, the relative path will be incorrect and the executable won't be found.`);
|
|
16070
|
+
}
|
|
16071
|
+
if (false) {} else {
|
|
16072
|
+
const { binPath, isWASM } = generateBinPath();
|
|
16073
|
+
if (isWASM) {
|
|
16074
|
+
return ["node", [binPath]];
|
|
16075
|
+
} else {
|
|
16076
|
+
return [binPath, []];
|
|
16077
|
+
}
|
|
16078
|
+
}
|
|
16079
|
+
};
|
|
16080
|
+
var isTTY = () => tty.isatty(2);
|
|
16081
|
+
var fsSync = {
|
|
16082
|
+
readFile(tempFile, callback) {
|
|
16083
|
+
try {
|
|
16084
|
+
let contents = fs22.readFileSync(tempFile, "utf8");
|
|
16085
|
+
try {
|
|
16086
|
+
fs22.unlinkSync(tempFile);
|
|
16087
|
+
} catch {}
|
|
16088
|
+
callback(null, contents);
|
|
16089
|
+
} catch (err) {
|
|
16090
|
+
callback(err, null);
|
|
16091
|
+
}
|
|
16092
|
+
},
|
|
16093
|
+
writeFile(contents, callback) {
|
|
16094
|
+
try {
|
|
16095
|
+
let tempFile = randomFileName();
|
|
16096
|
+
fs22.writeFileSync(tempFile, contents);
|
|
16097
|
+
callback(tempFile);
|
|
16098
|
+
} catch {
|
|
16099
|
+
callback(null);
|
|
16100
|
+
}
|
|
16101
|
+
}
|
|
16102
|
+
};
|
|
16103
|
+
var fsAsync = {
|
|
16104
|
+
readFile(tempFile, callback) {
|
|
16105
|
+
try {
|
|
16106
|
+
fs22.readFile(tempFile, "utf8", (err, contents) => {
|
|
16107
|
+
try {
|
|
16108
|
+
fs22.unlink(tempFile, () => callback(err, contents));
|
|
16109
|
+
} catch {
|
|
16110
|
+
callback(err, contents);
|
|
16111
|
+
}
|
|
16112
|
+
});
|
|
16113
|
+
} catch (err) {
|
|
16114
|
+
callback(err, null);
|
|
16115
|
+
}
|
|
16116
|
+
},
|
|
16117
|
+
writeFile(contents, callback) {
|
|
16118
|
+
try {
|
|
16119
|
+
let tempFile = randomFileName();
|
|
16120
|
+
fs22.writeFile(tempFile, contents, (err) => err !== null ? callback(null) : callback(tempFile));
|
|
16121
|
+
} catch {
|
|
16122
|
+
callback(null);
|
|
16123
|
+
}
|
|
16124
|
+
}
|
|
16125
|
+
};
|
|
16126
|
+
var version2 = "0.28.0";
|
|
16127
|
+
var build = (options) => ensureServiceIsRunning().build(options);
|
|
16128
|
+
var context = (buildOptions) => ensureServiceIsRunning().context(buildOptions);
|
|
16129
|
+
var transform = (input, options) => ensureServiceIsRunning().transform(input, options);
|
|
16130
|
+
var formatMessages = (messages2, options) => ensureServiceIsRunning().formatMessages(messages2, options);
|
|
16131
|
+
var analyzeMetafile = (messages2, options) => ensureServiceIsRunning().analyzeMetafile(messages2, options);
|
|
16132
|
+
var buildSync = (options) => {
|
|
16133
|
+
if (worker_threads && !isInternalWorkerThread) {
|
|
16134
|
+
if (!workerThreadService)
|
|
16135
|
+
workerThreadService = startWorkerThreadService(worker_threads);
|
|
16136
|
+
return workerThreadService.buildSync(options);
|
|
16137
|
+
}
|
|
16138
|
+
let result;
|
|
16139
|
+
runServiceSync((service) => service.buildOrContext({
|
|
16140
|
+
callName: "buildSync",
|
|
16141
|
+
refs: null,
|
|
16142
|
+
options,
|
|
16143
|
+
isTTY: isTTY(),
|
|
16144
|
+
defaultWD,
|
|
16145
|
+
callback: (err, res) => {
|
|
16146
|
+
if (err)
|
|
16147
|
+
throw err;
|
|
16148
|
+
result = res;
|
|
16149
|
+
}
|
|
16150
|
+
}));
|
|
16151
|
+
return result;
|
|
16152
|
+
};
|
|
16153
|
+
var transformSync = (input, options) => {
|
|
16154
|
+
if (worker_threads && !isInternalWorkerThread) {
|
|
16155
|
+
if (!workerThreadService)
|
|
16156
|
+
workerThreadService = startWorkerThreadService(worker_threads);
|
|
16157
|
+
return workerThreadService.transformSync(input, options);
|
|
16158
|
+
}
|
|
16159
|
+
let result;
|
|
16160
|
+
runServiceSync((service) => service.transform({
|
|
16161
|
+
callName: "transformSync",
|
|
16162
|
+
refs: null,
|
|
16163
|
+
input,
|
|
16164
|
+
options: options || {},
|
|
16165
|
+
isTTY: isTTY(),
|
|
16166
|
+
fs: fsSync,
|
|
16167
|
+
callback: (err, res) => {
|
|
16168
|
+
if (err)
|
|
16169
|
+
throw err;
|
|
16170
|
+
result = res;
|
|
16171
|
+
}
|
|
16172
|
+
}));
|
|
16173
|
+
return result;
|
|
16174
|
+
};
|
|
16175
|
+
var formatMessagesSync = (messages2, options) => {
|
|
16176
|
+
if (worker_threads && !isInternalWorkerThread) {
|
|
16177
|
+
if (!workerThreadService)
|
|
16178
|
+
workerThreadService = startWorkerThreadService(worker_threads);
|
|
16179
|
+
return workerThreadService.formatMessagesSync(messages2, options);
|
|
16180
|
+
}
|
|
16181
|
+
let result;
|
|
16182
|
+
runServiceSync((service) => service.formatMessages({
|
|
16183
|
+
callName: "formatMessagesSync",
|
|
16184
|
+
refs: null,
|
|
16185
|
+
messages: messages2,
|
|
16186
|
+
options,
|
|
16187
|
+
callback: (err, res) => {
|
|
16188
|
+
if (err)
|
|
16189
|
+
throw err;
|
|
16190
|
+
result = res;
|
|
16191
|
+
}
|
|
16192
|
+
}));
|
|
16193
|
+
return result;
|
|
16194
|
+
};
|
|
16195
|
+
var analyzeMetafileSync = (metafile, options) => {
|
|
16196
|
+
if (worker_threads && !isInternalWorkerThread) {
|
|
16197
|
+
if (!workerThreadService)
|
|
16198
|
+
workerThreadService = startWorkerThreadService(worker_threads);
|
|
16199
|
+
return workerThreadService.analyzeMetafileSync(metafile, options);
|
|
16200
|
+
}
|
|
16201
|
+
let result;
|
|
16202
|
+
runServiceSync((service) => service.analyzeMetafile({
|
|
16203
|
+
callName: "analyzeMetafileSync",
|
|
16204
|
+
refs: null,
|
|
16205
|
+
metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
|
|
16206
|
+
options,
|
|
16207
|
+
callback: (err, res) => {
|
|
16208
|
+
if (err)
|
|
16209
|
+
throw err;
|
|
16210
|
+
result = res;
|
|
16211
|
+
}
|
|
16212
|
+
}));
|
|
16213
|
+
return result;
|
|
16214
|
+
};
|
|
16215
|
+
var stop = () => {
|
|
16216
|
+
if (stopService)
|
|
16217
|
+
stopService();
|
|
16218
|
+
if (workerThreadService)
|
|
16219
|
+
workerThreadService.stop();
|
|
16220
|
+
return Promise.resolve();
|
|
16221
|
+
};
|
|
16222
|
+
var initializeWasCalled = false;
|
|
16223
|
+
var initialize = (options) => {
|
|
16224
|
+
options = validateInitializeOptions(options || {});
|
|
16225
|
+
if (options.wasmURL)
|
|
16226
|
+
throw new Error(`The "wasmURL" option only works in the browser`);
|
|
16227
|
+
if (options.wasmModule)
|
|
16228
|
+
throw new Error(`The "wasmModule" option only works in the browser`);
|
|
16229
|
+
if (options.worker)
|
|
16230
|
+
throw new Error(`The "worker" option only works in the browser`);
|
|
16231
|
+
if (initializeWasCalled)
|
|
16232
|
+
throw new Error('Cannot call "initialize" more than once');
|
|
16233
|
+
ensureServiceIsRunning();
|
|
16234
|
+
initializeWasCalled = true;
|
|
16235
|
+
return Promise.resolve();
|
|
16236
|
+
};
|
|
16237
|
+
var defaultWD = process.cwd();
|
|
16238
|
+
var longLivedService;
|
|
16239
|
+
var stopService;
|
|
16240
|
+
var ensureServiceIsRunning = () => {
|
|
16241
|
+
if (longLivedService)
|
|
16242
|
+
return longLivedService;
|
|
16243
|
+
let [command, args] = esbuildCommandAndArgs();
|
|
16244
|
+
let child = child_process.spawn(command, args.concat(`--service=${"0.28.0"}`, "--ping"), {
|
|
16245
|
+
windowsHide: true,
|
|
16246
|
+
stdio: ["pipe", "pipe", "inherit"],
|
|
16247
|
+
cwd: defaultWD
|
|
16248
|
+
});
|
|
16249
|
+
let { readFromStdout, afterClose, service } = createChannel({
|
|
16250
|
+
writeToStdin(bytes) {
|
|
16251
|
+
child.stdin.write(bytes, (err) => {
|
|
16252
|
+
if (err)
|
|
16253
|
+
afterClose(err);
|
|
16254
|
+
});
|
|
16255
|
+
},
|
|
16256
|
+
readFileSync: fs22.readFileSync,
|
|
16257
|
+
isSync: false,
|
|
16258
|
+
hasFS: true,
|
|
16259
|
+
esbuild: node_exports
|
|
16260
|
+
});
|
|
16261
|
+
child.stdin.on("error", afterClose);
|
|
16262
|
+
child.on("error", afterClose);
|
|
16263
|
+
const stdin = child.stdin;
|
|
16264
|
+
const stdout = child.stdout;
|
|
16265
|
+
stdout.on("data", readFromStdout);
|
|
16266
|
+
stdout.on("end", afterClose);
|
|
16267
|
+
stopService = () => {
|
|
16268
|
+
stdin.destroy();
|
|
16269
|
+
stdout.destroy();
|
|
16270
|
+
child.kill();
|
|
16271
|
+
initializeWasCalled = false;
|
|
16272
|
+
longLivedService = undefined;
|
|
16273
|
+
stopService = undefined;
|
|
16274
|
+
};
|
|
16275
|
+
let refCount = 0;
|
|
16276
|
+
child.unref();
|
|
16277
|
+
if (stdin.unref) {
|
|
16278
|
+
stdin.unref();
|
|
16279
|
+
}
|
|
16280
|
+
if (stdout.unref) {
|
|
16281
|
+
stdout.unref();
|
|
16282
|
+
}
|
|
16283
|
+
const refs = {
|
|
16284
|
+
ref() {
|
|
16285
|
+
if (++refCount === 1)
|
|
16286
|
+
child.ref();
|
|
16287
|
+
},
|
|
16288
|
+
unref() {
|
|
16289
|
+
if (--refCount === 0)
|
|
16290
|
+
child.unref();
|
|
16291
|
+
}
|
|
16292
|
+
};
|
|
16293
|
+
longLivedService = {
|
|
16294
|
+
build: (options) => new Promise((resolve2, reject) => {
|
|
16295
|
+
service.buildOrContext({
|
|
16296
|
+
callName: "build",
|
|
16297
|
+
refs,
|
|
16298
|
+
options,
|
|
16299
|
+
isTTY: isTTY(),
|
|
16300
|
+
defaultWD,
|
|
16301
|
+
callback: (err, res) => err ? reject(err) : resolve2(res)
|
|
16302
|
+
});
|
|
16303
|
+
}),
|
|
16304
|
+
context: (options) => new Promise((resolve2, reject) => service.buildOrContext({
|
|
16305
|
+
callName: "context",
|
|
16306
|
+
refs,
|
|
16307
|
+
options,
|
|
16308
|
+
isTTY: isTTY(),
|
|
16309
|
+
defaultWD,
|
|
16310
|
+
callback: (err, res) => err ? reject(err) : resolve2(res)
|
|
16311
|
+
})),
|
|
16312
|
+
transform: (input, options) => new Promise((resolve2, reject) => service.transform({
|
|
16313
|
+
callName: "transform",
|
|
16314
|
+
refs,
|
|
16315
|
+
input,
|
|
16316
|
+
options: options || {},
|
|
16317
|
+
isTTY: isTTY(),
|
|
16318
|
+
fs: fsAsync,
|
|
16319
|
+
callback: (err, res) => err ? reject(err) : resolve2(res)
|
|
16320
|
+
})),
|
|
16321
|
+
formatMessages: (messages2, options) => new Promise((resolve2, reject) => service.formatMessages({
|
|
16322
|
+
callName: "formatMessages",
|
|
16323
|
+
refs,
|
|
16324
|
+
messages: messages2,
|
|
16325
|
+
options,
|
|
16326
|
+
callback: (err, res) => err ? reject(err) : resolve2(res)
|
|
16327
|
+
})),
|
|
16328
|
+
analyzeMetafile: (metafile, options) => new Promise((resolve2, reject) => service.analyzeMetafile({
|
|
16329
|
+
callName: "analyzeMetafile",
|
|
16330
|
+
refs,
|
|
16331
|
+
metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
|
|
16332
|
+
options,
|
|
16333
|
+
callback: (err, res) => err ? reject(err) : resolve2(res)
|
|
16334
|
+
}))
|
|
16335
|
+
};
|
|
16336
|
+
return longLivedService;
|
|
16337
|
+
};
|
|
16338
|
+
var runServiceSync = (callback) => {
|
|
16339
|
+
let [command, args] = esbuildCommandAndArgs();
|
|
16340
|
+
let stdin = new Uint8Array;
|
|
16341
|
+
let { readFromStdout, afterClose, service } = createChannel({
|
|
16342
|
+
writeToStdin(bytes) {
|
|
16343
|
+
if (stdin.length !== 0)
|
|
16344
|
+
throw new Error("Must run at most one command");
|
|
16345
|
+
stdin = bytes;
|
|
16346
|
+
},
|
|
16347
|
+
isSync: true,
|
|
16348
|
+
hasFS: true,
|
|
16349
|
+
esbuild: node_exports
|
|
16350
|
+
});
|
|
16351
|
+
callback(service);
|
|
16352
|
+
let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.28.0"}`), {
|
|
16353
|
+
cwd: defaultWD,
|
|
16354
|
+
windowsHide: true,
|
|
16355
|
+
input: stdin,
|
|
16356
|
+
maxBuffer: +process.env.ESBUILD_MAX_BUFFER || 16 * 1024 * 1024
|
|
16357
|
+
});
|
|
16358
|
+
readFromStdout(stdout);
|
|
16359
|
+
afterClose(null);
|
|
16360
|
+
};
|
|
16361
|
+
var randomFileName = () => {
|
|
16362
|
+
return path2.join(os22.tmpdir(), `esbuild-${crypto2.randomBytes(32).toString("hex")}`);
|
|
16363
|
+
};
|
|
16364
|
+
var workerThreadService = null;
|
|
16365
|
+
var startWorkerThreadService = (worker_threads2) => {
|
|
16366
|
+
let { port1: mainPort, port2: workerPort } = new worker_threads2.MessageChannel;
|
|
16367
|
+
let worker = new worker_threads2.Worker(__filename, {
|
|
16368
|
+
workerData: { workerPort, defaultWD, esbuildVersion: "0.28.0" },
|
|
16369
|
+
transferList: [workerPort],
|
|
16370
|
+
execArgv: []
|
|
16371
|
+
});
|
|
16372
|
+
let nextID = 0;
|
|
16373
|
+
let fakeBuildError = (text3) => {
|
|
16374
|
+
let error = new Error(`Build failed with 1 error:
|
|
16375
|
+
error: ${text3}`);
|
|
16376
|
+
let errors3 = [{ id: "", pluginName: "", text: text3, location: null, notes: [], detail: undefined }];
|
|
16377
|
+
error.errors = errors3;
|
|
16378
|
+
error.warnings = [];
|
|
16379
|
+
return error;
|
|
16380
|
+
};
|
|
16381
|
+
let validateBuildSyncOptions = (options) => {
|
|
16382
|
+
if (!options)
|
|
16383
|
+
return;
|
|
16384
|
+
let plugins = options.plugins;
|
|
16385
|
+
if (plugins && plugins.length > 0)
|
|
16386
|
+
throw fakeBuildError(`Cannot use plugins in synchronous API calls`);
|
|
16387
|
+
};
|
|
16388
|
+
let applyProperties = (object, properties) => {
|
|
16389
|
+
for (let key in properties) {
|
|
16390
|
+
object[key] = properties[key];
|
|
16391
|
+
}
|
|
16392
|
+
};
|
|
16393
|
+
let runCallSync = (command, args) => {
|
|
16394
|
+
let id = nextID++;
|
|
16395
|
+
let sharedBuffer = new SharedArrayBuffer(8);
|
|
16396
|
+
let sharedBufferView = new Int32Array(sharedBuffer);
|
|
16397
|
+
let msg = { sharedBuffer, id, command, args };
|
|
16398
|
+
worker.postMessage(msg);
|
|
16399
|
+
let status = Atomics.wait(sharedBufferView, 0, 0);
|
|
16400
|
+
if (status !== "ok" && status !== "not-equal")
|
|
16401
|
+
throw new Error("Internal error: Atomics.wait() failed: " + status);
|
|
16402
|
+
let { message: { id: id2, resolve: resolve2, reject, properties } } = worker_threads2.receiveMessageOnPort(mainPort);
|
|
16403
|
+
if (id !== id2)
|
|
16404
|
+
throw new Error(`Internal error: Expected id ${id} but got id ${id2}`);
|
|
16405
|
+
if (reject) {
|
|
16406
|
+
applyProperties(reject, properties);
|
|
16407
|
+
throw reject;
|
|
16408
|
+
}
|
|
16409
|
+
return resolve2;
|
|
16410
|
+
};
|
|
16411
|
+
worker.unref();
|
|
16412
|
+
return {
|
|
16413
|
+
buildSync(options) {
|
|
16414
|
+
validateBuildSyncOptions(options);
|
|
16415
|
+
return runCallSync("build", [options]);
|
|
16416
|
+
},
|
|
16417
|
+
transformSync(input, options) {
|
|
16418
|
+
return runCallSync("transform", [input, options]);
|
|
16419
|
+
},
|
|
16420
|
+
formatMessagesSync(messages2, options) {
|
|
16421
|
+
return runCallSync("formatMessages", [messages2, options]);
|
|
16422
|
+
},
|
|
16423
|
+
analyzeMetafileSync(metafile, options) {
|
|
16424
|
+
return runCallSync("analyzeMetafile", [metafile, options]);
|
|
16425
|
+
},
|
|
16426
|
+
stop() {
|
|
16427
|
+
worker.terminate();
|
|
16428
|
+
workerThreadService = null;
|
|
16429
|
+
}
|
|
16430
|
+
};
|
|
16431
|
+
};
|
|
16432
|
+
var startSyncServiceWorker = () => {
|
|
16433
|
+
let workerPort = worker_threads.workerData.workerPort;
|
|
16434
|
+
let parentPort = worker_threads.parentPort;
|
|
16435
|
+
let extractProperties = (object) => {
|
|
16436
|
+
let properties = {};
|
|
16437
|
+
if (object && typeof object === "object") {
|
|
16438
|
+
for (let key in object) {
|
|
16439
|
+
properties[key] = object[key];
|
|
16440
|
+
}
|
|
16441
|
+
}
|
|
16442
|
+
return properties;
|
|
16443
|
+
};
|
|
16444
|
+
try {
|
|
16445
|
+
let service = ensureServiceIsRunning();
|
|
16446
|
+
defaultWD = worker_threads.workerData.defaultWD;
|
|
16447
|
+
parentPort.on("message", (msg) => {
|
|
16448
|
+
(async () => {
|
|
16449
|
+
let { sharedBuffer, id, command, args } = msg;
|
|
16450
|
+
let sharedBufferView = new Int32Array(sharedBuffer);
|
|
16451
|
+
try {
|
|
16452
|
+
switch (command) {
|
|
16453
|
+
case "build":
|
|
16454
|
+
workerPort.postMessage({ id, resolve: await service.build(args[0]) });
|
|
16455
|
+
break;
|
|
16456
|
+
case "transform":
|
|
16457
|
+
workerPort.postMessage({ id, resolve: await service.transform(args[0], args[1]) });
|
|
16458
|
+
break;
|
|
16459
|
+
case "formatMessages":
|
|
16460
|
+
workerPort.postMessage({ id, resolve: await service.formatMessages(args[0], args[1]) });
|
|
16461
|
+
break;
|
|
16462
|
+
case "analyzeMetafile":
|
|
16463
|
+
workerPort.postMessage({ id, resolve: await service.analyzeMetafile(args[0], args[1]) });
|
|
16464
|
+
break;
|
|
16465
|
+
default:
|
|
16466
|
+
throw new Error(`Invalid command: ${command}`);
|
|
16467
|
+
}
|
|
16468
|
+
} catch (reject) {
|
|
16469
|
+
workerPort.postMessage({ id, reject, properties: extractProperties(reject) });
|
|
16470
|
+
}
|
|
16471
|
+
Atomics.add(sharedBufferView, 0, 1);
|
|
16472
|
+
Atomics.notify(sharedBufferView, 0, Infinity);
|
|
16473
|
+
})();
|
|
16474
|
+
});
|
|
16475
|
+
} catch (reject) {
|
|
16476
|
+
parentPort.on("message", (msg) => {
|
|
16477
|
+
let { sharedBuffer, id } = msg;
|
|
16478
|
+
let sharedBufferView = new Int32Array(sharedBuffer);
|
|
16479
|
+
workerPort.postMessage({ id, reject, properties: extractProperties(reject) });
|
|
16480
|
+
Atomics.add(sharedBufferView, 0, 1);
|
|
16481
|
+
Atomics.notify(sharedBufferView, 0, Infinity);
|
|
16482
|
+
});
|
|
16483
|
+
}
|
|
16484
|
+
};
|
|
16485
|
+
if (isInternalWorkerThread) {
|
|
16486
|
+
startSyncServiceWorker();
|
|
16487
|
+
}
|
|
16488
|
+
var node_default = node_exports;
|
|
16489
|
+
});
|
|
16490
|
+
|
|
16491
|
+
// src/lib/manifest-generator.ts
|
|
16492
|
+
function generateDeploymentManifest(_projectDir, manifest) {
|
|
16493
|
+
const automations2 = manifest.automations.map((auto) => ({
|
|
16494
|
+
name: auto.name,
|
|
16495
|
+
entrypoint: auto.entrypoint,
|
|
16496
|
+
bundledFile: `${auto.name}.js`,
|
|
16497
|
+
triggers: auto.triggers,
|
|
16498
|
+
config: auto.config
|
|
16499
|
+
}));
|
|
16500
|
+
return {
|
|
16501
|
+
version: 1,
|
|
16502
|
+
projectName: manifest.name,
|
|
16503
|
+
automations: automations2,
|
|
16504
|
+
generatedAt: new Date().toISOString()
|
|
16505
|
+
};
|
|
16506
|
+
}
|
|
16507
|
+
var init_manifest_generator = () => {};
|
|
16508
|
+
|
|
16509
|
+
// src/lib/bundler.ts
|
|
16510
|
+
import { join as join6, resolve as resolve2 } from "node:path";
|
|
16511
|
+
import {
|
|
16512
|
+
existsSync as existsSync5,
|
|
16513
|
+
readFileSync as readFileSync5,
|
|
16514
|
+
writeFileSync as writeFileSync5,
|
|
16515
|
+
mkdirSync as mkdirSync3,
|
|
16516
|
+
readdirSync,
|
|
16517
|
+
rmSync
|
|
16518
|
+
} from "node:fs";
|
|
16519
|
+
import { createGzip } from "node:zlib";
|
|
16520
|
+
import { Readable } from "node:stream";
|
|
16521
|
+
async function createBundle(projectDir, options) {
|
|
16522
|
+
const maxSize = options?.maxBundleSize ?? MAX_BUNDLE_SIZE_BYTES;
|
|
16523
|
+
let duraManifest;
|
|
16524
|
+
try {
|
|
16525
|
+
duraManifest = readManifest(projectDir);
|
|
16526
|
+
} catch (err) {
|
|
16527
|
+
return {
|
|
16528
|
+
success: false,
|
|
16529
|
+
error: `Failed to read dura.json: ${err instanceof Error ? err.message : String(err)}`
|
|
16530
|
+
};
|
|
16531
|
+
}
|
|
16532
|
+
const buildDir = join6(projectDir, ".dura", "build");
|
|
16533
|
+
if (existsSync5(buildDir)) {
|
|
16534
|
+
rmSync(buildDir, { recursive: true });
|
|
16535
|
+
}
|
|
16536
|
+
mkdirSync3(buildDir, { recursive: true });
|
|
16537
|
+
for (const auto of duraManifest.automations) {
|
|
16538
|
+
const entryPath = resolve2(projectDir, auto.entrypoint);
|
|
16539
|
+
if (!existsSync5(entryPath)) {
|
|
16540
|
+
rmSync(buildDir, { recursive: true });
|
|
16541
|
+
return {
|
|
16542
|
+
success: false,
|
|
16543
|
+
error: `Entry point not found: ${auto.entrypoint}`
|
|
16544
|
+
};
|
|
16545
|
+
}
|
|
16546
|
+
const outFile = join6(buildDir, `${auto.name}.js`);
|
|
16547
|
+
try {
|
|
16548
|
+
const source = readFileSync5(entryPath, "utf-8");
|
|
16549
|
+
const xformed = await esbuild.transform(source, {
|
|
16550
|
+
loader: "ts",
|
|
16551
|
+
target: "es2022",
|
|
16552
|
+
sourcemap: false
|
|
16553
|
+
});
|
|
16554
|
+
writeFileSync5(outFile, xformed.code);
|
|
16555
|
+
} catch (err) {
|
|
16556
|
+
rmSync(buildDir, { recursive: true });
|
|
16557
|
+
return {
|
|
16558
|
+
success: false,
|
|
16559
|
+
error: `Failed to bundle ${auto.name}: ${err instanceof Error ? err.message : String(err)}`
|
|
16560
|
+
};
|
|
16561
|
+
}
|
|
16562
|
+
}
|
|
16563
|
+
const deployManifest = generateDeploymentManifest(projectDir, duraManifest);
|
|
16564
|
+
writeFileSync5(join6(buildDir, "manifest.json"), JSON.stringify(deployManifest, null, 2));
|
|
16565
|
+
const archiveBuffer = await createTarGz(buildDir);
|
|
16566
|
+
if (archiveBuffer.length > maxSize) {
|
|
16567
|
+
rmSync(buildDir, { recursive: true });
|
|
16568
|
+
return {
|
|
16569
|
+
success: false,
|
|
16570
|
+
error: `Bundle size (${archiveBuffer.length} bytes) exceeds maximum (${maxSize} bytes)`
|
|
16571
|
+
};
|
|
16572
|
+
}
|
|
16573
|
+
rmSync(buildDir, { recursive: true });
|
|
16574
|
+
return {
|
|
16575
|
+
success: true,
|
|
16576
|
+
archiveBuffer,
|
|
16577
|
+
manifest: deployManifest,
|
|
16578
|
+
sizeBytes: archiveBuffer.length
|
|
16579
|
+
};
|
|
16580
|
+
}
|
|
16581
|
+
async function createTarGz(dir) {
|
|
16582
|
+
const files = collectFiles(dir, dir);
|
|
16583
|
+
const tarBuffer = createTarBuffer(files);
|
|
16584
|
+
const chunks = [];
|
|
16585
|
+
const gzip = createGzip();
|
|
16586
|
+
const input = Readable.from([tarBuffer]);
|
|
16587
|
+
return new Promise((resolve3, reject) => {
|
|
16588
|
+
gzip.on("data", (chunk) => chunks.push(chunk));
|
|
16589
|
+
gzip.on("end", () => {
|
|
16590
|
+
const totalLength = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
16591
|
+
const result = new Uint8Array(totalLength);
|
|
16592
|
+
let offset = 0;
|
|
16593
|
+
for (const chunk of chunks) {
|
|
16594
|
+
result.set(chunk, offset);
|
|
16595
|
+
offset += chunk.length;
|
|
16596
|
+
}
|
|
16597
|
+
resolve3(result);
|
|
16598
|
+
});
|
|
16599
|
+
gzip.on("error", reject);
|
|
16600
|
+
input.pipe(gzip);
|
|
16601
|
+
});
|
|
16602
|
+
}
|
|
16603
|
+
function collectFiles(dir, base) {
|
|
16604
|
+
const result = [];
|
|
16605
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
16606
|
+
for (const entry of entries) {
|
|
16607
|
+
const fullPath = join6(dir, entry.name);
|
|
16608
|
+
if (entry.isFile()) {
|
|
16609
|
+
const relativePath = fullPath.slice(base.length + 1);
|
|
16610
|
+
result.push({
|
|
16611
|
+
name: relativePath,
|
|
16612
|
+
content: new Uint8Array(readFileSync5(fullPath))
|
|
16613
|
+
});
|
|
16614
|
+
} else if (entry.isDirectory()) {
|
|
16615
|
+
result.push(...collectFiles(fullPath, base));
|
|
16616
|
+
}
|
|
16617
|
+
}
|
|
16618
|
+
return result;
|
|
16619
|
+
}
|
|
16620
|
+
function createTarBuffer(files) {
|
|
16621
|
+
const blocks = [];
|
|
16622
|
+
for (const file of files) {
|
|
16623
|
+
const header = createTarHeader(file.name, file.content.length);
|
|
16624
|
+
blocks.push(header);
|
|
16625
|
+
blocks.push(file.content);
|
|
16626
|
+
const remainder = file.content.length % 512;
|
|
16627
|
+
if (remainder > 0) {
|
|
16628
|
+
blocks.push(new Uint8Array(512 - remainder));
|
|
16629
|
+
}
|
|
16630
|
+
}
|
|
16631
|
+
blocks.push(new Uint8Array(1024));
|
|
16632
|
+
const totalLength = blocks.reduce((sum, b2) => sum + b2.length, 0);
|
|
16633
|
+
const result = new Uint8Array(totalLength);
|
|
16634
|
+
let offset = 0;
|
|
16635
|
+
for (const block of blocks) {
|
|
16636
|
+
result.set(block, offset);
|
|
16637
|
+
offset += block.length;
|
|
16638
|
+
}
|
|
16639
|
+
return result;
|
|
16640
|
+
}
|
|
16641
|
+
function createTarHeader(name, size2) {
|
|
16642
|
+
const header = new Uint8Array(512);
|
|
16643
|
+
const encoder = new TextEncoder;
|
|
16644
|
+
const nameBytes = encoder.encode(name);
|
|
13939
16645
|
header.set(nameBytes.slice(0, 100), 0);
|
|
13940
16646
|
header.set(encoder.encode("0000644\x00"), 100);
|
|
13941
16647
|
header.set(encoder.encode("0000000\x00"), 108);
|
|
@@ -13957,10 +16663,12 @@ function createTarHeader(name, size2) {
|
|
|
13957
16663
|
header.set(encoder.encode(checksumStr), 148);
|
|
13958
16664
|
return header;
|
|
13959
16665
|
}
|
|
16666
|
+
var esbuild;
|
|
13960
16667
|
var init_bundler = __esm(() => {
|
|
13961
16668
|
init_src2();
|
|
13962
16669
|
init_manifest2();
|
|
13963
16670
|
init_manifest_generator();
|
|
16671
|
+
esbuild = __toESM(require_main(), 1);
|
|
13964
16672
|
});
|
|
13965
16673
|
|
|
13966
16674
|
// src/commands/deploy.ts
|
|
@@ -14212,8 +16920,13 @@ function parseFilters(filter) {
|
|
|
14212
16920
|
return params;
|
|
14213
16921
|
}
|
|
14214
16922
|
function registerLogsCommand(program2) {
|
|
14215
|
-
program2.command("logs [executionId]").description("View execution logs").
|
|
16923
|
+
program2.command("logs [executionId]").description("View execution logs").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").option("--limit <n>", "Number of entries", "50").option("--filter <filter>", "Filter expression (e.g., 'level=error automation=my-auto')").option("--last <duration>", "Show logs from last duration (e.g., 1h, 30m, 7d)").option("--order <order>", "Sort order: asc or desc", "desc").option("-f, --follow", "Stream logs in real time (live tail)").action(async (executionId, opts, cmd) => {
|
|
14216
16924
|
const output = getOutput(cmd);
|
|
16925
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
16926
|
+
if (!projectId) {
|
|
16927
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
16928
|
+
return;
|
|
16929
|
+
}
|
|
14217
16930
|
const token = opts.token || getAuthToken();
|
|
14218
16931
|
if (!token) {
|
|
14219
16932
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
@@ -14234,10 +16947,11 @@ function registerLogsCommand(program2) {
|
|
|
14234
16947
|
}
|
|
14235
16948
|
if (executionId)
|
|
14236
16949
|
filters.executionId = executionId;
|
|
14237
|
-
const wsUrl = buildWsUrl(apiUrl,
|
|
16950
|
+
const wsUrl = buildWsUrl(apiUrl, projectId, filters, token);
|
|
14238
16951
|
if (!output.isJson()) {
|
|
14239
|
-
output.info(`Connecting to live log stream for project ${
|
|
16952
|
+
output.info(`Connecting to live log stream for project ${projectId}…`);
|
|
14240
16953
|
}
|
|
16954
|
+
const resolvedProjectId = projectId;
|
|
14241
16955
|
await new Promise((resolve3) => {
|
|
14242
16956
|
const MAX_RETRIES = 5;
|
|
14243
16957
|
let retries = 0;
|
|
@@ -14248,7 +16962,7 @@ function registerLogsCommand(program2) {
|
|
|
14248
16962
|
currentClient?.disconnect();
|
|
14249
16963
|
});
|
|
14250
16964
|
function connect() {
|
|
14251
|
-
currentClient = createFollowClient(wsUrl,
|
|
16965
|
+
currentClient = createFollowClient(wsUrl, resolvedProjectId, filters, {
|
|
14252
16966
|
wsFactory: (url) => new WebSocket(url),
|
|
14253
16967
|
onEntry: (entry) => {
|
|
14254
16968
|
if (output.isJson()) {
|
|
@@ -14317,7 +17031,7 @@ function registerLogsCommand(program2) {
|
|
|
14317
17031
|
}
|
|
14318
17032
|
query["start"] = new Date(Date.now() - durationMs).toISOString();
|
|
14319
17033
|
}
|
|
14320
|
-
const result = await client.get(`/api/v1/projects/${
|
|
17034
|
+
const result = await client.get(`/api/v1/projects/${projectId}/logs`, query);
|
|
14321
17035
|
output.table(["Timestamp", "Level", "Automation", "Message"], result.entries.map((e) => [
|
|
14322
17036
|
e.timestamp,
|
|
14323
17037
|
e.level,
|
|
@@ -14328,7 +17042,7 @@ function registerLogsCommand(program2) {
|
|
|
14328
17042
|
output.info(`Total: ${result.totalCount} entries`);
|
|
14329
17043
|
}
|
|
14330
17044
|
} else if (executionId) {
|
|
14331
|
-
const execution = await client.get(`/api/v1/projects/${
|
|
17045
|
+
const execution = await client.get(`/api/v1/projects/${projectId}/executions/${executionId}`);
|
|
14332
17046
|
if ((execution.status === "failed" || execution.status === "timeout") && (execution.errorName || execution.errorMessage)) {
|
|
14333
17047
|
if (output.isJson()) {
|
|
14334
17048
|
output.success({
|
|
@@ -14359,10 +17073,10 @@ Error: ${name}
|
|
|
14359
17073
|
`);
|
|
14360
17074
|
}
|
|
14361
17075
|
}
|
|
14362
|
-
const logs = await client.get(`/api/v1/projects/${
|
|
17076
|
+
const logs = await client.get(`/api/v1/projects/${projectId}/executions/${executionId}/logs`);
|
|
14363
17077
|
output.table(["Timestamp", "Level", "Message"], logs.map((l) => [l.timestamp, l.level, l.message]));
|
|
14364
17078
|
} else {
|
|
14365
|
-
const executions = await client.get(`/api/v1/projects/${
|
|
17079
|
+
const executions = await client.get(`/api/v1/projects/${projectId}/executions`, { limit: opts.limit });
|
|
14366
17080
|
output.table(["ID", "Status", "Trigger", "Duration", "Created"], executions.map((e) => [
|
|
14367
17081
|
e.id,
|
|
14368
17082
|
e.status,
|
|
@@ -14384,6 +17098,7 @@ var init_logs = __esm(() => {
|
|
|
14384
17098
|
init_src3();
|
|
14385
17099
|
init_api_client();
|
|
14386
17100
|
init_config_store();
|
|
17101
|
+
init_project_id();
|
|
14387
17102
|
});
|
|
14388
17103
|
|
|
14389
17104
|
// src/commands/run.ts
|
|
@@ -14445,15 +17160,20 @@ function getClient(opts) {
|
|
|
14445
17160
|
}
|
|
14446
17161
|
function registerScheduleCommand(program2) {
|
|
14447
17162
|
const schedule = program2.command("schedule").description("Manage cron schedules for automations");
|
|
14448
|
-
schedule.command("set").description("Create or update a cron schedule").requiredOption("--cron <expression>", "Cron expression (e.g. '0 9 * * *')").requiredOption("--automation <name>", "Automation name").
|
|
17163
|
+
schedule.command("set").description("Create or update a cron schedule").requiredOption("--cron <expression>", "Cron expression (e.g. '0 9 * * *')").requiredOption("--automation <name>", "Automation name").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
|
|
14449
17164
|
const output = getOutput(cmd);
|
|
17165
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
17166
|
+
if (!projectId) {
|
|
17167
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
17168
|
+
return;
|
|
17169
|
+
}
|
|
14450
17170
|
const auth = getClient(opts);
|
|
14451
17171
|
if (!auth) {
|
|
14452
17172
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
14453
17173
|
return;
|
|
14454
17174
|
}
|
|
14455
17175
|
try {
|
|
14456
|
-
const result = await auth.client.post(`/api/v1/projects/${
|
|
17176
|
+
const result = await auth.client.post(`/api/v1/projects/${projectId}/schedules`, {
|
|
14457
17177
|
automationName: opts.automation,
|
|
14458
17178
|
cron: opts.cron
|
|
14459
17179
|
});
|
|
@@ -14466,15 +17186,20 @@ function registerScheduleCommand(program2) {
|
|
|
14466
17186
|
}
|
|
14467
17187
|
}
|
|
14468
17188
|
});
|
|
14469
|
-
schedule.command("list").description("List cron schedules for a project").
|
|
17189
|
+
schedule.command("list").description("List cron schedules for a project").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
|
|
14470
17190
|
const output = getOutput(cmd);
|
|
17191
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
17192
|
+
if (!projectId) {
|
|
17193
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
17194
|
+
return;
|
|
17195
|
+
}
|
|
14471
17196
|
const auth = getClient(opts);
|
|
14472
17197
|
if (!auth) {
|
|
14473
17198
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
14474
17199
|
return;
|
|
14475
17200
|
}
|
|
14476
17201
|
try {
|
|
14477
|
-
const result = await auth.client.get(`/api/v1/projects/${
|
|
17202
|
+
const result = await auth.client.get(`/api/v1/projects/${projectId}/schedules`);
|
|
14478
17203
|
output.success(result);
|
|
14479
17204
|
} catch (err) {
|
|
14480
17205
|
if (err instanceof ApiClientError) {
|
|
@@ -14484,19 +17209,24 @@ function registerScheduleCommand(program2) {
|
|
|
14484
17209
|
}
|
|
14485
17210
|
}
|
|
14486
17211
|
});
|
|
14487
|
-
schedule.command("remove <schedule-id>").description("Remove a cron schedule").
|
|
17212
|
+
schedule.command("remove <schedule-id>").description("Remove a cron schedule").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").option("--confirm", "Confirm the destructive delete operation").action(async (scheduleId, opts, cmd) => {
|
|
14488
17213
|
const output = getOutput(cmd);
|
|
14489
17214
|
if (!opts.confirm) {
|
|
14490
17215
|
output.error("CONFIRM_REQUIRED", "This will permanently delete the schedule. Add --confirm to proceed.");
|
|
14491
17216
|
return;
|
|
14492
17217
|
}
|
|
17218
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
17219
|
+
if (!projectId) {
|
|
17220
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
17221
|
+
return;
|
|
17222
|
+
}
|
|
14493
17223
|
const auth = getClient(opts);
|
|
14494
17224
|
if (!auth) {
|
|
14495
17225
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
14496
17226
|
return;
|
|
14497
17227
|
}
|
|
14498
17228
|
try {
|
|
14499
|
-
const result = await auth.client.delete(`/api/v1/projects/${
|
|
17229
|
+
const result = await auth.client.delete(`/api/v1/projects/${projectId}/schedules/${scheduleId}`);
|
|
14500
17230
|
output.success(result);
|
|
14501
17231
|
} catch (err) {
|
|
14502
17232
|
if (err instanceof ApiClientError) {
|
|
@@ -14511,6 +17241,7 @@ var init_schedule = __esm(() => {
|
|
|
14511
17241
|
init_src3();
|
|
14512
17242
|
init_api_client();
|
|
14513
17243
|
init_config_store();
|
|
17244
|
+
init_project_id();
|
|
14514
17245
|
});
|
|
14515
17246
|
|
|
14516
17247
|
// src/dev/server.ts
|
|
@@ -15043,8 +17774,8 @@ __export(exports_file_watcher, {
|
|
|
15043
17774
|
resolveAffectedAutomation: () => resolveAffectedAutomation,
|
|
15044
17775
|
createFileWatcher: () => createFileWatcher
|
|
15045
17776
|
});
|
|
15046
|
-
import { watch, existsSync as
|
|
15047
|
-
import { join as
|
|
17777
|
+
import { watch, existsSync as existsSync6 } from "node:fs";
|
|
17778
|
+
import { join as join7 } from "node:path";
|
|
15048
17779
|
function resolveAffectedAutomation(manifest, changedPath) {
|
|
15049
17780
|
const normalized = changedPath.replace(/\\/g, "/");
|
|
15050
17781
|
const directMatch = manifest.automations.filter((a) => a.entrypoint.replace(/\\/g, "/") === normalized);
|
|
@@ -15063,7 +17794,7 @@ function createFileWatcher(options) {
|
|
|
15063
17794
|
return;
|
|
15064
17795
|
if (!/\.(ts|tsx|js|jsx|mjs|mts)$/.test(filename))
|
|
15065
17796
|
return;
|
|
15066
|
-
const relativePath =
|
|
17797
|
+
const relativePath = join7(dir, filename).replace(/\\/g, "/");
|
|
15067
17798
|
const existing = debounceTimers.get(relativePath);
|
|
15068
17799
|
if (existing) {
|
|
15069
17800
|
clearTimeout(existing);
|
|
@@ -15079,8 +17810,8 @@ function createFileWatcher(options) {
|
|
|
15079
17810
|
return;
|
|
15080
17811
|
watching = true;
|
|
15081
17812
|
for (const dir of watchDirs) {
|
|
15082
|
-
const fullDir =
|
|
15083
|
-
if (!
|
|
17813
|
+
const fullDir = join7(projectDir, dir);
|
|
17814
|
+
if (!existsSync6(fullDir))
|
|
15084
17815
|
continue;
|
|
15085
17816
|
try {
|
|
15086
17817
|
const fsWatcher = watch(fullDir, { recursive: true }, (_eventType, filename) => {
|
|
@@ -15179,12 +17910,12 @@ function registerDevCommand(program2) {
|
|
|
15179
17910
|
}
|
|
15180
17911
|
throw err;
|
|
15181
17912
|
}
|
|
15182
|
-
const { existsSync:
|
|
15183
|
-
const { join:
|
|
15184
|
-
const envPath =
|
|
17913
|
+
const { existsSync: existsSync7, readFileSync: readFileSync6 } = await import("node:fs");
|
|
17914
|
+
const { join: join8 } = await import("node:path");
|
|
17915
|
+
const envPath = join8(projectDir, ".env.local");
|
|
15185
17916
|
let secrets2 = {};
|
|
15186
|
-
if (
|
|
15187
|
-
const content =
|
|
17917
|
+
if (existsSync7(envPath)) {
|
|
17918
|
+
const content = readFileSync6(envPath, "utf-8");
|
|
15188
17919
|
secrets2 = parseEnvFile(content);
|
|
15189
17920
|
output.info(`Loaded ${Object.keys(secrets2).length} secret(s) from .env.local`);
|
|
15190
17921
|
}
|
|
@@ -15206,6 +17937,14 @@ function registerDevCommand(program2) {
|
|
|
15206
17937
|
}
|
|
15207
17938
|
}
|
|
15208
17939
|
}
|
|
17940
|
+
if (typeof globalThis.Bun === "undefined") {
|
|
17941
|
+
try {
|
|
17942
|
+
const { register } = await import("tsx/esm/api");
|
|
17943
|
+
register();
|
|
17944
|
+
} catch (err) {
|
|
17945
|
+
output.warn(`Failed to register tsx loader — .ts handlers may fail to load. ${err instanceof Error ? err.message : ""}`);
|
|
17946
|
+
}
|
|
17947
|
+
}
|
|
15209
17948
|
const { createLocalExecutor: createLocalExecutor2 } = await Promise.resolve().then(() => (init_executor(), exports_executor));
|
|
15210
17949
|
const { installDevGlobal: installDevGlobal2 } = await Promise.resolve().then(() => exports_dev_globals);
|
|
15211
17950
|
const executor = createLocalExecutor2({ projectDir });
|
|
@@ -15526,14 +18265,14 @@ var init_comparator = __esm(() => {
|
|
|
15526
18265
|
|
|
15527
18266
|
// src/snapshot/file-manager.ts
|
|
15528
18267
|
import {
|
|
15529
|
-
existsSync as
|
|
18268
|
+
existsSync as existsSync7,
|
|
15530
18269
|
mkdirSync as mkdirSync4,
|
|
15531
|
-
readFileSync as
|
|
18270
|
+
readFileSync as readFileSync6,
|
|
15532
18271
|
writeFileSync as writeFileSync6,
|
|
15533
18272
|
readdirSync as readdirSync2,
|
|
15534
18273
|
unlinkSync
|
|
15535
18274
|
} from "node:fs";
|
|
15536
|
-
import { join as
|
|
18275
|
+
import { join as join8 } from "node:path";
|
|
15537
18276
|
function automationNameToFileName(automationName) {
|
|
15538
18277
|
return automationName.replace(/\//g, "-") + ".snap.json";
|
|
15539
18278
|
}
|
|
@@ -15544,22 +18283,22 @@ function fileNameToAutomationName(fileName) {
|
|
|
15544
18283
|
class SnapshotFileManager {
|
|
15545
18284
|
snapshotsDir;
|
|
15546
18285
|
constructor(projectDir) {
|
|
15547
|
-
this.snapshotsDir =
|
|
18286
|
+
this.snapshotsDir = join8(projectDir, SNAPSHOTS_DIR);
|
|
15548
18287
|
}
|
|
15549
18288
|
filePath(automationName) {
|
|
15550
|
-
return
|
|
18289
|
+
return join8(this.snapshotsDir, automationNameToFileName(automationName));
|
|
15551
18290
|
}
|
|
15552
18291
|
ensureDir() {
|
|
15553
|
-
if (!
|
|
18292
|
+
if (!existsSync7(this.snapshotsDir)) {
|
|
15554
18293
|
mkdirSync4(this.snapshotsDir, { recursive: true });
|
|
15555
18294
|
}
|
|
15556
18295
|
}
|
|
15557
18296
|
read(automationName) {
|
|
15558
18297
|
const path = this.filePath(automationName);
|
|
15559
|
-
if (!
|
|
18298
|
+
if (!existsSync7(path))
|
|
15560
18299
|
return null;
|
|
15561
18300
|
try {
|
|
15562
|
-
const raw =
|
|
18301
|
+
const raw = readFileSync6(path, "utf-8");
|
|
15563
18302
|
return JSON.parse(raw);
|
|
15564
18303
|
} catch {
|
|
15565
18304
|
return null;
|
|
@@ -15589,14 +18328,14 @@ class SnapshotFileManager {
|
|
|
15589
18328
|
});
|
|
15590
18329
|
}
|
|
15591
18330
|
listAutomationNames() {
|
|
15592
|
-
if (!
|
|
18331
|
+
if (!existsSync7(this.snapshotsDir))
|
|
15593
18332
|
return [];
|
|
15594
18333
|
const files = readdirSync2(this.snapshotsDir).filter((f) => f.endsWith(".snap.json"));
|
|
15595
18334
|
const names = [];
|
|
15596
18335
|
for (const file of files) {
|
|
15597
|
-
const path =
|
|
18336
|
+
const path = join8(this.snapshotsDir, file);
|
|
15598
18337
|
try {
|
|
15599
|
-
const raw =
|
|
18338
|
+
const raw = readFileSync6(path, "utf-8");
|
|
15600
18339
|
const parsed = JSON.parse(raw);
|
|
15601
18340
|
if (parsed.automationName) {
|
|
15602
18341
|
names.push(parsed.automationName);
|
|
@@ -15607,7 +18346,7 @@ class SnapshotFileManager {
|
|
|
15607
18346
|
}
|
|
15608
18347
|
delete(automationName) {
|
|
15609
18348
|
const path = this.filePath(automationName);
|
|
15610
|
-
if (
|
|
18349
|
+
if (existsSync7(path)) {
|
|
15611
18350
|
unlinkSync(path);
|
|
15612
18351
|
}
|
|
15613
18352
|
}
|
|
@@ -15616,25 +18355,25 @@ var SNAPSHOTS_DIR = "__snapshots__";
|
|
|
15616
18355
|
var init_file_manager = () => {};
|
|
15617
18356
|
|
|
15618
18357
|
// src/snapshot/config-reader.ts
|
|
15619
|
-
import { existsSync as
|
|
15620
|
-
import { join as
|
|
18358
|
+
import { existsSync as existsSync8, readFileSync as readFileSync7 } from "node:fs";
|
|
18359
|
+
import { join as join9 } from "node:path";
|
|
15621
18360
|
function readSnapshotConfig(projectDir) {
|
|
15622
|
-
const durajsonPath =
|
|
15623
|
-
const testjsonPath =
|
|
18361
|
+
const durajsonPath = join9(projectDir, "dura.json");
|
|
18362
|
+
const testjsonPath = join9(projectDir, "dura.test.json");
|
|
15624
18363
|
let fromDuraJson = {};
|
|
15625
18364
|
let fromTestJson = {};
|
|
15626
18365
|
let mocks;
|
|
15627
|
-
if (
|
|
18366
|
+
if (existsSync8(durajsonPath)) {
|
|
15628
18367
|
try {
|
|
15629
|
-
const raw = JSON.parse(
|
|
18368
|
+
const raw = JSON.parse(readFileSync7(durajsonPath, "utf-8"));
|
|
15630
18369
|
if (raw["snapshots"] && typeof raw["snapshots"] === "object" && !Array.isArray(raw["snapshots"])) {
|
|
15631
18370
|
fromDuraJson = raw["snapshots"];
|
|
15632
18371
|
}
|
|
15633
18372
|
} catch {}
|
|
15634
18373
|
}
|
|
15635
|
-
if (
|
|
18374
|
+
if (existsSync8(testjsonPath)) {
|
|
15636
18375
|
try {
|
|
15637
|
-
const raw = JSON.parse(
|
|
18376
|
+
const raw = JSON.parse(readFileSync7(testjsonPath, "utf-8"));
|
|
15638
18377
|
if (raw["snapshots"] && typeof raw["snapshots"] === "object" && !Array.isArray(raw["snapshots"])) {
|
|
15639
18378
|
fromTestJson = raw["snapshots"];
|
|
15640
18379
|
}
|
|
@@ -16199,24 +18938,29 @@ __export(exports_domains, {
|
|
|
16199
18938
|
registerDomainsCommand: () => registerDomainsCommand
|
|
16200
18939
|
});
|
|
16201
18940
|
function resolveAuth2(opts, output) {
|
|
18941
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
18942
|
+
if (!projectId) {
|
|
18943
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
18944
|
+
return null;
|
|
18945
|
+
}
|
|
16202
18946
|
const token = opts.token || getAuthToken();
|
|
16203
18947
|
if (!token) {
|
|
16204
18948
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
16205
18949
|
return null;
|
|
16206
18950
|
}
|
|
16207
18951
|
const apiUrl = opts.apiUrl || getApiUrl();
|
|
16208
|
-
return { client: new ApiClient(apiUrl, token) };
|
|
18952
|
+
return { client: new ApiClient(apiUrl, token), projectId };
|
|
16209
18953
|
}
|
|
16210
18954
|
function registerDomainsCommand(program2) {
|
|
16211
18955
|
const domains = program2.command("domains").description("Manage custom domains for a project");
|
|
16212
|
-
domains.command("add <domain>").description("Add a custom domain").
|
|
18956
|
+
domains.command("add <domain>").description("Add a custom domain").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (domain, opts, cmd) => {
|
|
16213
18957
|
const output = getOutput(cmd);
|
|
16214
18958
|
const auth = resolveAuth2(opts, output);
|
|
16215
18959
|
if (!auth)
|
|
16216
18960
|
return;
|
|
16217
|
-
const { client } = auth;
|
|
18961
|
+
const { client, projectId } = auth;
|
|
16218
18962
|
try {
|
|
16219
|
-
const result = await client.post(`/api/v1/projects/${
|
|
18963
|
+
const result = await client.post(`/api/v1/projects/${projectId}/domains`, { domain });
|
|
16220
18964
|
output.success(result);
|
|
16221
18965
|
if (!output.isJson()) {
|
|
16222
18966
|
output.info(`
|
|
@@ -16224,7 +18968,7 @@ Add this TXT record to your DNS:
|
|
|
16224
18968
|
` + ` Host: _dura-verification.${domain}
|
|
16225
18969
|
` + ` Value: ${result.txtRecord}
|
|
16226
18970
|
` + `
|
|
16227
|
-
Then run: dura domains verify ${result.id} --project ${
|
|
18971
|
+
Then run: dura domains verify ${result.id} --project ${projectId}`);
|
|
16228
18972
|
}
|
|
16229
18973
|
} catch (err) {
|
|
16230
18974
|
if (err instanceof Error) {
|
|
@@ -16232,14 +18976,14 @@ Then run: dura domains verify ${result.id} --project ${opts.project}`);
|
|
|
16232
18976
|
}
|
|
16233
18977
|
}
|
|
16234
18978
|
});
|
|
16235
|
-
domains.command("list").description("List custom domains").
|
|
18979
|
+
domains.command("list").description("List custom domains").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
|
|
16236
18980
|
const output = getOutput(cmd);
|
|
16237
18981
|
const auth = resolveAuth2(opts, output);
|
|
16238
18982
|
if (!auth)
|
|
16239
18983
|
return;
|
|
16240
|
-
const { client } = auth;
|
|
18984
|
+
const { client, projectId } = auth;
|
|
16241
18985
|
try {
|
|
16242
|
-
const result = await client.get(`/api/v1/projects/${
|
|
18986
|
+
const result = await client.get(`/api/v1/projects/${projectId}/domains`);
|
|
16243
18987
|
output.table(["Domain", "Status", "Verified", "Created"], result.map((d) => [
|
|
16244
18988
|
d.domain,
|
|
16245
18989
|
d.status,
|
|
@@ -16252,7 +18996,7 @@ Then run: dura domains verify ${result.id} --project ${opts.project}`);
|
|
|
16252
18996
|
}
|
|
16253
18997
|
}
|
|
16254
18998
|
});
|
|
16255
|
-
domains.command("remove <domainId>").description("Remove a custom domain").
|
|
18999
|
+
domains.command("remove <domainId>").description("Remove a custom domain").option("--project <id>", "Project ID (defaults to dura.json)").option("--confirm", "Confirm this destructive operation").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (domainId, opts, cmd) => {
|
|
16256
19000
|
const output = getOutput(cmd);
|
|
16257
19001
|
if (!opts.confirm) {
|
|
16258
19002
|
output.error("CONFIRM_REQUIRED", "This is a destructive operation. Re-run with --confirm to proceed.");
|
|
@@ -16261,9 +19005,9 @@ Then run: dura domains verify ${result.id} --project ${opts.project}`);
|
|
|
16261
19005
|
const auth = resolveAuth2(opts, output);
|
|
16262
19006
|
if (!auth)
|
|
16263
19007
|
return;
|
|
16264
|
-
const { client } = auth;
|
|
19008
|
+
const { client, projectId } = auth;
|
|
16265
19009
|
try {
|
|
16266
|
-
await client.delete(`/api/v1/projects/${
|
|
19010
|
+
await client.delete(`/api/v1/projects/${projectId}/domains/${domainId}`);
|
|
16267
19011
|
output.success({ deleted: true, domainId });
|
|
16268
19012
|
} catch (err) {
|
|
16269
19013
|
if (err instanceof Error) {
|
|
@@ -16271,14 +19015,14 @@ Then run: dura domains verify ${result.id} --project ${opts.project}`);
|
|
|
16271
19015
|
}
|
|
16272
19016
|
}
|
|
16273
19017
|
});
|
|
16274
|
-
domains.command("verify <domainId>").description("Verify a domain's DNS TXT record").
|
|
19018
|
+
domains.command("verify <domainId>").description("Verify a domain's DNS TXT record").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (domainId, opts, cmd) => {
|
|
16275
19019
|
const output = getOutput(cmd);
|
|
16276
19020
|
const auth = resolveAuth2(opts, output);
|
|
16277
19021
|
if (!auth)
|
|
16278
19022
|
return;
|
|
16279
|
-
const { client } = auth;
|
|
19023
|
+
const { client, projectId } = auth;
|
|
16280
19024
|
try {
|
|
16281
|
-
const result = await client.post(`/api/v1/projects/${
|
|
19025
|
+
const result = await client.post(`/api/v1/projects/${projectId}/domains/${domainId}/verify`, {});
|
|
16282
19026
|
output.success(result);
|
|
16283
19027
|
} catch (err) {
|
|
16284
19028
|
if (err instanceof Error) {
|
|
@@ -16291,6 +19035,7 @@ var init_domains = __esm(() => {
|
|
|
16291
19035
|
init_src3();
|
|
16292
19036
|
init_api_client();
|
|
16293
19037
|
init_config_store();
|
|
19038
|
+
init_project_id();
|
|
16294
19039
|
});
|
|
16295
19040
|
|
|
16296
19041
|
// src/commands/endpoint-keys.ts
|
|
@@ -16299,24 +19044,29 @@ __export(exports_endpoint_keys, {
|
|
|
16299
19044
|
registerEndpointKeysCommand: () => registerEndpointKeysCommand
|
|
16300
19045
|
});
|
|
16301
19046
|
function resolveAuth3(opts, output) {
|
|
19047
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
19048
|
+
if (!projectId) {
|
|
19049
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
19050
|
+
return null;
|
|
19051
|
+
}
|
|
16302
19052
|
const token = opts.token || getAuthToken();
|
|
16303
19053
|
if (!token) {
|
|
16304
19054
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
16305
19055
|
return null;
|
|
16306
19056
|
}
|
|
16307
19057
|
const apiUrl = opts.apiUrl || getApiUrl();
|
|
16308
|
-
return { client: new ApiClient(apiUrl, token) };
|
|
19058
|
+
return { client: new ApiClient(apiUrl, token), projectId };
|
|
16309
19059
|
}
|
|
16310
19060
|
function registerEndpointKeysCommand(program2) {
|
|
16311
19061
|
const keys = program2.command("endpoint-keys").description("Manage per-project endpoint keys for automation auth");
|
|
16312
|
-
keys.command("create <name>").description("Create a new endpoint key").
|
|
19062
|
+
keys.command("create <name>").description("Create a new endpoint key").option("--project <id>", "Project ID (defaults to dura.json)").option("--expires <date>", "Expiration date (ISO 8601)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (name, opts, cmd) => {
|
|
16313
19063
|
const output = getOutput(cmd);
|
|
16314
19064
|
const auth = resolveAuth3(opts, output);
|
|
16315
19065
|
if (!auth)
|
|
16316
19066
|
return;
|
|
16317
|
-
const { client } = auth;
|
|
19067
|
+
const { client, projectId } = auth;
|
|
16318
19068
|
try {
|
|
16319
|
-
const result = await client.post(`/api/v1/projects/${
|
|
19069
|
+
const result = await client.post(`/api/v1/projects/${projectId}/endpoint-keys`, {
|
|
16320
19070
|
name,
|
|
16321
19071
|
expiresAt: opts.expires
|
|
16322
19072
|
});
|
|
@@ -16330,14 +19080,14 @@ function registerEndpointKeysCommand(program2) {
|
|
|
16330
19080
|
}
|
|
16331
19081
|
}
|
|
16332
19082
|
});
|
|
16333
|
-
keys.command("list").description("List endpoint keys for a project").
|
|
19083
|
+
keys.command("list").description("List endpoint keys for a project").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
|
|
16334
19084
|
const output = getOutput(cmd);
|
|
16335
19085
|
const auth = resolveAuth3(opts, output);
|
|
16336
19086
|
if (!auth)
|
|
16337
19087
|
return;
|
|
16338
|
-
const { client } = auth;
|
|
19088
|
+
const { client, projectId } = auth;
|
|
16339
19089
|
try {
|
|
16340
|
-
const result = await client.get(`/api/v1/projects/${
|
|
19090
|
+
const result = await client.get(`/api/v1/projects/${projectId}/endpoint-keys`);
|
|
16341
19091
|
output.table(["Name", "Prefix", "Status", "Expires", "Last Used", "Created"], result.map((k) => [
|
|
16342
19092
|
k.name,
|
|
16343
19093
|
k.keyPrefix,
|
|
@@ -16352,7 +19102,7 @@ function registerEndpointKeysCommand(program2) {
|
|
|
16352
19102
|
}
|
|
16353
19103
|
}
|
|
16354
19104
|
});
|
|
16355
|
-
keys.command("revoke <keyId>").description("Revoke an endpoint key").
|
|
19105
|
+
keys.command("revoke <keyId>").description("Revoke an endpoint key").option("--project <id>", "Project ID (defaults to dura.json)").option("--confirm", "Confirm this destructive operation").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (keyId, opts, cmd) => {
|
|
16356
19106
|
const output = getOutput(cmd);
|
|
16357
19107
|
if (!opts.confirm) {
|
|
16358
19108
|
output.error("CONFIRM_REQUIRED", "This is a destructive operation. Re-run with --confirm to proceed.");
|
|
@@ -16361,9 +19111,9 @@ function registerEndpointKeysCommand(program2) {
|
|
|
16361
19111
|
const auth = resolveAuth3(opts, output);
|
|
16362
19112
|
if (!auth)
|
|
16363
19113
|
return;
|
|
16364
|
-
const { client } = auth;
|
|
19114
|
+
const { client, projectId } = auth;
|
|
16365
19115
|
try {
|
|
16366
|
-
await client.post(`/api/v1/projects/${
|
|
19116
|
+
await client.post(`/api/v1/projects/${projectId}/endpoint-keys/${keyId}/revoke`, {});
|
|
16367
19117
|
output.success({ revoked: true, keyId });
|
|
16368
19118
|
} catch (err) {
|
|
16369
19119
|
if (err instanceof Error) {
|
|
@@ -16376,6 +19126,7 @@ var init_endpoint_keys2 = __esm(() => {
|
|
|
16376
19126
|
init_src3();
|
|
16377
19127
|
init_api_client();
|
|
16378
19128
|
init_config_store();
|
|
19129
|
+
init_project_id();
|
|
16379
19130
|
});
|
|
16380
19131
|
|
|
16381
19132
|
// src/commands/usage.ts
|
|
@@ -16622,19 +19373,19 @@ __export(exports_export, {
|
|
|
16622
19373
|
collectExportFiles: () => collectExportFiles
|
|
16623
19374
|
});
|
|
16624
19375
|
import {
|
|
16625
|
-
existsSync as
|
|
16626
|
-
readFileSync as
|
|
19376
|
+
existsSync as existsSync9,
|
|
19377
|
+
readFileSync as readFileSync8,
|
|
16627
19378
|
readdirSync as readdirSync3,
|
|
16628
19379
|
statSync,
|
|
16629
19380
|
writeFileSync as writeFileSync7
|
|
16630
19381
|
} from "node:fs";
|
|
16631
|
-
import { join as
|
|
19382
|
+
import { join as join10, relative, resolve as resolve4 } from "node:path";
|
|
16632
19383
|
function collectExportFiles(baseDir, currentDir) {
|
|
16633
19384
|
const dir = currentDir ?? baseDir;
|
|
16634
19385
|
const entries = [];
|
|
16635
19386
|
const items = readdirSync3(dir);
|
|
16636
19387
|
for (const item of items) {
|
|
16637
|
-
const fullPath =
|
|
19388
|
+
const fullPath = join10(dir, item);
|
|
16638
19389
|
const relPath = relative(baseDir, fullPath);
|
|
16639
19390
|
const stat = statSync(fullPath);
|
|
16640
19391
|
if (stat.isDirectory()) {
|
|
@@ -16643,7 +19394,7 @@ function collectExportFiles(baseDir, currentDir) {
|
|
|
16643
19394
|
}
|
|
16644
19395
|
} else if (stat.isFile()) {
|
|
16645
19396
|
if (!EXCLUDED_FILES.has(item)) {
|
|
16646
|
-
const content =
|
|
19397
|
+
const content = readFileSync8(fullPath, "utf-8");
|
|
16647
19398
|
entries.push({ relativePath: relPath, content });
|
|
16648
19399
|
}
|
|
16649
19400
|
}
|
|
@@ -16667,14 +19418,14 @@ function registerExportCommand(program2) {
|
|
|
16667
19418
|
program2.command("export").description("Export project source + config into a portable archive").option("--dir <path>", "Project directory", ".").option("--output <path>", "Output file path").action(async (opts, cmd) => {
|
|
16668
19419
|
const output = getOutput(cmd);
|
|
16669
19420
|
const projectDir = resolve4(opts.dir ?? ".");
|
|
16670
|
-
const manifestPath =
|
|
16671
|
-
if (!
|
|
19421
|
+
const manifestPath = join10(projectDir, "dura.json");
|
|
19422
|
+
if (!existsSync9(manifestPath)) {
|
|
16672
19423
|
output.error("EXPORT_NO_MANIFEST", "No dura.json found in project directory", "Run this command from a dura project directory or use --dir");
|
|
16673
19424
|
return;
|
|
16674
19425
|
}
|
|
16675
19426
|
let projectName;
|
|
16676
19427
|
try {
|
|
16677
|
-
const manifestContent =
|
|
19428
|
+
const manifestContent = readFileSync8(manifestPath, "utf-8");
|
|
16678
19429
|
const manifest = JSON.parse(manifestContent);
|
|
16679
19430
|
projectName = manifest.name ?? "unnamed-project";
|
|
16680
19431
|
} catch {
|
|
@@ -16688,7 +19439,7 @@ function registerExportCommand(program2) {
|
|
|
16688
19439
|
return;
|
|
16689
19440
|
}
|
|
16690
19441
|
const archive = createArchive(projectName, files);
|
|
16691
|
-
const outputPath = opts.output ??
|
|
19442
|
+
const outputPath = opts.output ?? join10(projectDir, `${projectName}-export.json`);
|
|
16692
19443
|
try {
|
|
16693
19444
|
writeFileSync7(outputPath, archive, "utf-8");
|
|
16694
19445
|
} catch (err) {
|
|
@@ -16724,8 +19475,13 @@ __export(exports_replay, {
|
|
|
16724
19475
|
registerReplayCommand: () => registerReplayCommand
|
|
16725
19476
|
});
|
|
16726
19477
|
function registerReplayCommand(program2) {
|
|
16727
|
-
program2.command("replay <execution-id>").description("Replay an execution with original inputs (optionally with overrides)").
|
|
19478
|
+
program2.command("replay <execution-id>").description("Replay an execution with original inputs (optionally with overrides)").option("--project <id>", "Project ID (defaults to dura.json)").option("--body <json>", "Override the request body as JSON").option("--dry-run", "Show payload without replaying").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (executionId, opts, cmd) => {
|
|
16728
19479
|
const output = getOutput(cmd);
|
|
19480
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
19481
|
+
if (!projectId) {
|
|
19482
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
19483
|
+
return;
|
|
19484
|
+
}
|
|
16729
19485
|
const token = opts.token || getAuthToken();
|
|
16730
19486
|
if (!token) {
|
|
16731
19487
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
@@ -16735,7 +19491,7 @@ function registerReplayCommand(program2) {
|
|
|
16735
19491
|
const client = new ApiClient(apiUrl, token);
|
|
16736
19492
|
try {
|
|
16737
19493
|
if (opts.dryRun) {
|
|
16738
|
-
const payload = await client.get(`/api/v1/projects/${
|
|
19494
|
+
const payload = await client.get(`/api/v1/projects/${projectId}/executions/${executionId}/payload`);
|
|
16739
19495
|
output.success(payload);
|
|
16740
19496
|
return;
|
|
16741
19497
|
}
|
|
@@ -16754,7 +19510,7 @@ function registerReplayCommand(program2) {
|
|
|
16754
19510
|
return;
|
|
16755
19511
|
}
|
|
16756
19512
|
}
|
|
16757
|
-
const result = await client.post(`/api/v1/projects/${
|
|
19513
|
+
const result = await client.post(`/api/v1/projects/${projectId}/executions/${executionId}/replay`, { overrides });
|
|
16758
19514
|
output.success(result);
|
|
16759
19515
|
} catch (err) {
|
|
16760
19516
|
if (err instanceof ApiClientError) {
|
|
@@ -16766,8 +19522,13 @@ function registerReplayCommand(program2) {
|
|
|
16766
19522
|
});
|
|
16767
19523
|
}
|
|
16768
19524
|
function registerReplaysCommand(program2) {
|
|
16769
|
-
program2.command("replays <execution-id>").description("List all replays of an execution").
|
|
19525
|
+
program2.command("replays <execution-id>").description("List all replays of an execution").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (executionId, opts, cmd) => {
|
|
16770
19526
|
const output = getOutput(cmd);
|
|
19527
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
19528
|
+
if (!projectId) {
|
|
19529
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
19530
|
+
return;
|
|
19531
|
+
}
|
|
16771
19532
|
const token = opts.token || getAuthToken();
|
|
16772
19533
|
if (!token) {
|
|
16773
19534
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
@@ -16776,7 +19537,7 @@ function registerReplaysCommand(program2) {
|
|
|
16776
19537
|
const apiUrl = opts.apiUrl || getApiUrl();
|
|
16777
19538
|
const client = new ApiClient(apiUrl, token);
|
|
16778
19539
|
try {
|
|
16779
|
-
const replays = await client.get(`/api/v1/projects/${
|
|
19540
|
+
const replays = await client.get(`/api/v1/projects/${projectId}/executions/${executionId}/replays`);
|
|
16780
19541
|
if (replays.length === 0) {
|
|
16781
19542
|
if (!output.isJson()) {
|
|
16782
19543
|
output.info("No replays found for this execution.");
|
|
@@ -16805,6 +19566,7 @@ var init_replay = __esm(() => {
|
|
|
16805
19566
|
init_src3();
|
|
16806
19567
|
init_api_client();
|
|
16807
19568
|
init_config_store();
|
|
19569
|
+
init_project_id();
|
|
16808
19570
|
});
|
|
16809
19571
|
|
|
16810
19572
|
// src/commands/kv.ts
|
|
@@ -16813,29 +19575,34 @@ __export(exports_kv, {
|
|
|
16813
19575
|
registerKvCommand: () => registerKvCommand
|
|
16814
19576
|
});
|
|
16815
19577
|
function resolveAuth4(opts, output) {
|
|
19578
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
19579
|
+
if (!projectId) {
|
|
19580
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
19581
|
+
return null;
|
|
19582
|
+
}
|
|
16816
19583
|
const token = opts.token || getAuthToken();
|
|
16817
19584
|
if (!token) {
|
|
16818
19585
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
16819
19586
|
return null;
|
|
16820
19587
|
}
|
|
16821
19588
|
const apiUrl = opts.apiUrl || getApiUrl();
|
|
16822
|
-
return { client: new ApiClient(apiUrl, token) };
|
|
19589
|
+
return { client: new ApiClient(apiUrl, token), projectId };
|
|
16823
19590
|
}
|
|
16824
19591
|
function registerKvCommand(program2) {
|
|
16825
19592
|
const kv = program2.command("kv").description("Manage the built-in per-project key-value store");
|
|
16826
|
-
kv.command("list").description("List keys in the project KV namespace").
|
|
19593
|
+
kv.command("list").description("List keys in the project KV namespace").option("--project <id>", "Project ID (defaults to dura.json)").option("--pattern <glob>", "Filter keys by glob pattern (e.g. user:*)").option("--limit <n>", "Maximum number of keys to return").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
|
|
16827
19594
|
const output = getOutput(cmd);
|
|
16828
19595
|
const auth = resolveAuth4(opts, output);
|
|
16829
19596
|
if (!auth)
|
|
16830
19597
|
return;
|
|
16831
|
-
const { client } = auth;
|
|
19598
|
+
const { client, projectId } = auth;
|
|
16832
19599
|
const query = {};
|
|
16833
19600
|
if (opts.pattern)
|
|
16834
19601
|
query["pattern"] = opts.pattern;
|
|
16835
19602
|
if (opts.limit)
|
|
16836
19603
|
query["limit"] = opts.limit;
|
|
16837
19604
|
try {
|
|
16838
|
-
const keys = await client.get(`/api/v1/projects/${
|
|
19605
|
+
const keys = await client.get(`/api/v1/projects/${projectId}/kv`, query);
|
|
16839
19606
|
if (output.isJson()) {
|
|
16840
19607
|
output.success(keys);
|
|
16841
19608
|
return;
|
|
@@ -16853,14 +19620,14 @@ function registerKvCommand(program2) {
|
|
|
16853
19620
|
}
|
|
16854
19621
|
}
|
|
16855
19622
|
});
|
|
16856
|
-
kv.command("get <key>").description("Get the value for a key").
|
|
19623
|
+
kv.command("get <key>").description("Get the value for a key").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (key, opts, cmd) => {
|
|
16857
19624
|
const output = getOutput(cmd);
|
|
16858
19625
|
const auth = resolveAuth4(opts, output);
|
|
16859
19626
|
if (!auth)
|
|
16860
19627
|
return;
|
|
16861
|
-
const { client } = auth;
|
|
19628
|
+
const { client, projectId } = auth;
|
|
16862
19629
|
try {
|
|
16863
|
-
const result = await client.get(`/api/v1/projects/${
|
|
19630
|
+
const result = await client.get(`/api/v1/projects/${projectId}/kv/${encodeURIComponent(key)}`);
|
|
16864
19631
|
output.success(result);
|
|
16865
19632
|
} catch (err) {
|
|
16866
19633
|
if (err instanceof ApiClientError) {
|
|
@@ -16870,12 +19637,12 @@ function registerKvCommand(program2) {
|
|
|
16870
19637
|
}
|
|
16871
19638
|
}
|
|
16872
19639
|
});
|
|
16873
|
-
kv.command("set <key> <value>").description("Set a value for a key").
|
|
19640
|
+
kv.command("set <key> <value>").description("Set a value for a key").option("--project <id>", "Project ID (defaults to dura.json)").option("--ttl <seconds>", "Time-to-live in seconds (0 = no expiry)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (key, valueStr, opts, cmd) => {
|
|
16874
19641
|
const output = getOutput(cmd);
|
|
16875
19642
|
const auth = resolveAuth4(opts, output);
|
|
16876
19643
|
if (!auth)
|
|
16877
19644
|
return;
|
|
16878
|
-
const { client } = auth;
|
|
19645
|
+
const { client, projectId } = auth;
|
|
16879
19646
|
let value;
|
|
16880
19647
|
try {
|
|
16881
19648
|
value = JSON.parse(valueStr);
|
|
@@ -16887,7 +19654,7 @@ function registerKvCommand(program2) {
|
|
|
16887
19654
|
body.ttl = parseInt(opts.ttl, 10);
|
|
16888
19655
|
}
|
|
16889
19656
|
try {
|
|
16890
|
-
const result = await client.put(`/api/v1/projects/${
|
|
19657
|
+
const result = await client.put(`/api/v1/projects/${projectId}/kv/${encodeURIComponent(key)}`, body);
|
|
16891
19658
|
output.success(result);
|
|
16892
19659
|
} catch (err) {
|
|
16893
19660
|
if (err instanceof ApiClientError) {
|
|
@@ -16897,7 +19664,7 @@ function registerKvCommand(program2) {
|
|
|
16897
19664
|
}
|
|
16898
19665
|
}
|
|
16899
19666
|
});
|
|
16900
|
-
kv.command("delete <key>").description("Delete a key from the KV namespace").
|
|
19667
|
+
kv.command("delete <key>").description("Delete a key from the KV namespace").option("--project <id>", "Project ID (defaults to dura.json)").option("--confirm", "Required to actually perform the delete").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (key, opts, cmd) => {
|
|
16901
19668
|
const output = getOutput(cmd);
|
|
16902
19669
|
if (!opts.confirm) {
|
|
16903
19670
|
output.error("KV_DELETE_CONFIRM_REQUIRED", `This will permanently delete the key "${key}".`, "Re-run with --confirm to proceed.");
|
|
@@ -16906,9 +19673,9 @@ function registerKvCommand(program2) {
|
|
|
16906
19673
|
const auth = resolveAuth4(opts, output);
|
|
16907
19674
|
if (!auth)
|
|
16908
19675
|
return;
|
|
16909
|
-
const { client } = auth;
|
|
19676
|
+
const { client, projectId } = auth;
|
|
16910
19677
|
try {
|
|
16911
|
-
await client.delete(`/api/v1/projects/${
|
|
19678
|
+
await client.delete(`/api/v1/projects/${projectId}/kv/${encodeURIComponent(key)}`);
|
|
16912
19679
|
output.success({ deleted: true, key });
|
|
16913
19680
|
} catch (err) {
|
|
16914
19681
|
if (err instanceof ApiClientError) {
|
|
@@ -16918,7 +19685,7 @@ function registerKvCommand(program2) {
|
|
|
16918
19685
|
}
|
|
16919
19686
|
}
|
|
16920
19687
|
});
|
|
16921
|
-
kv.command("flush").description("Remove all keys in the project KV namespace").
|
|
19688
|
+
kv.command("flush").description("Remove all keys in the project KV namespace").option("--project <id>", "Project ID (defaults to dura.json)").option("--confirm", "Required to actually perform the flush").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
|
|
16922
19689
|
const output = getOutput(cmd);
|
|
16923
19690
|
if (!opts.confirm) {
|
|
16924
19691
|
output.error("KV_FLUSH_CONFIRM_REQUIRED", "This will permanently delete ALL keys for the project.", "Re-run with --confirm to proceed.");
|
|
@@ -16927,9 +19694,9 @@ function registerKvCommand(program2) {
|
|
|
16927
19694
|
const auth = resolveAuth4(opts, output);
|
|
16928
19695
|
if (!auth)
|
|
16929
19696
|
return;
|
|
16930
|
-
const { client } = auth;
|
|
19697
|
+
const { client, projectId } = auth;
|
|
16931
19698
|
try {
|
|
16932
|
-
await client.delete(`/api/v1/projects/${
|
|
19699
|
+
await client.delete(`/api/v1/projects/${projectId}/kv`);
|
|
16933
19700
|
output.success({ flushed: true });
|
|
16934
19701
|
} catch (err) {
|
|
16935
19702
|
if (err instanceof ApiClientError) {
|
|
@@ -16939,14 +19706,14 @@ function registerKvCommand(program2) {
|
|
|
16939
19706
|
}
|
|
16940
19707
|
}
|
|
16941
19708
|
});
|
|
16942
|
-
kv.command("stats").description("Show KV usage statistics for the project").
|
|
19709
|
+
kv.command("stats").description("Show KV usage statistics for the project").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
|
|
16943
19710
|
const output = getOutput(cmd);
|
|
16944
19711
|
const auth = resolveAuth4(opts, output);
|
|
16945
19712
|
if (!auth)
|
|
16946
19713
|
return;
|
|
16947
|
-
const { client } = auth;
|
|
19714
|
+
const { client, projectId } = auth;
|
|
16948
19715
|
try {
|
|
16949
|
-
const stats = await client.get(`/api/v1/projects/${
|
|
19716
|
+
const stats = await client.get(`/api/v1/projects/${projectId}/kv/stats`);
|
|
16950
19717
|
output.success(stats);
|
|
16951
19718
|
} catch (err) {
|
|
16952
19719
|
if (err instanceof ApiClientError) {
|
|
@@ -16961,6 +19728,7 @@ var init_kv2 = __esm(() => {
|
|
|
16961
19728
|
init_src3();
|
|
16962
19729
|
init_api_client();
|
|
16963
19730
|
init_config_store();
|
|
19731
|
+
init_project_id();
|
|
16964
19732
|
});
|
|
16965
19733
|
|
|
16966
19734
|
// src/commands/webhook.ts
|
|
@@ -17001,10 +19769,10 @@ function registerWebhookCommand(program2) {
|
|
|
17001
19769
|
return;
|
|
17002
19770
|
}
|
|
17003
19771
|
const events = opts.events ? opts.events.split(",").map((e) => e.trim()) : undefined;
|
|
17004
|
-
let
|
|
19772
|
+
let transform2;
|
|
17005
19773
|
if (opts.transform) {
|
|
17006
19774
|
try {
|
|
17007
|
-
|
|
19775
|
+
transform2 = JSON.parse(opts.transform);
|
|
17008
19776
|
} catch {
|
|
17009
19777
|
output.error("VALIDATION_ERROR", "--transform must be valid JSON");
|
|
17010
19778
|
return;
|
|
@@ -17015,7 +19783,7 @@ function registerWebhookCommand(program2) {
|
|
|
17015
19783
|
slug: opts.slug ?? opts.name.toLowerCase().replace(/[^a-z0-9]+/g, "-"),
|
|
17016
19784
|
source: { type: opts.source, events },
|
|
17017
19785
|
destinations: [{ url: opts.forward, method: "POST" }],
|
|
17018
|
-
transform:
|
|
19786
|
+
transform: transform2 ? { template: transform2 } : undefined
|
|
17019
19787
|
};
|
|
17020
19788
|
try {
|
|
17021
19789
|
const result = await client.post(webhookBase(opts.project), body);
|
|
@@ -17406,24 +20174,29 @@ __export(exports_deployments, {
|
|
|
17406
20174
|
registerDeploymentsCommand: () => registerDeploymentsCommand
|
|
17407
20175
|
});
|
|
17408
20176
|
function resolveAuth6(opts, output) {
|
|
20177
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
20178
|
+
if (!projectId) {
|
|
20179
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
20180
|
+
return null;
|
|
20181
|
+
}
|
|
17409
20182
|
const token = opts.token || getAuthToken();
|
|
17410
20183
|
if (!token) {
|
|
17411
20184
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
17412
20185
|
return null;
|
|
17413
20186
|
}
|
|
17414
20187
|
const apiUrl = opts.apiUrl || getApiUrl();
|
|
17415
|
-
return { client: new ApiClient(apiUrl, token) };
|
|
20188
|
+
return { client: new ApiClient(apiUrl, token), projectId };
|
|
17416
20189
|
}
|
|
17417
20190
|
function registerDeploymentsCommand(program2) {
|
|
17418
20191
|
const deployments2 = program2.command("deployments").description("View deployment history for a project");
|
|
17419
|
-
deployments2.command("list").description("List deployments for a project").
|
|
20192
|
+
deployments2.command("list").description("List deployments for a project").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
|
|
17420
20193
|
const output = getOutput(cmd);
|
|
17421
20194
|
const auth = resolveAuth6(opts, output);
|
|
17422
20195
|
if (!auth)
|
|
17423
20196
|
return;
|
|
17424
|
-
const { client } = auth;
|
|
20197
|
+
const { client, projectId } = auth;
|
|
17425
20198
|
try {
|
|
17426
|
-
const deploymentList = await client.get(`/api/v1/projects/${
|
|
20199
|
+
const deploymentList = await client.get(`/api/v1/projects/${projectId}/deployments`);
|
|
17427
20200
|
if (output.isJson()) {
|
|
17428
20201
|
output.success(deploymentList);
|
|
17429
20202
|
return;
|
|
@@ -17441,14 +20214,14 @@ function registerDeploymentsCommand(program2) {
|
|
|
17441
20214
|
}
|
|
17442
20215
|
}
|
|
17443
20216
|
});
|
|
17444
|
-
deployments2.command("get").description("Show details for a specific deployment").
|
|
20217
|
+
deployments2.command("get").description("Show details for a specific deployment").option("--project <id>", "Project ID (defaults to dura.json)").requiredOption("--id <deploymentId>", "Deployment ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
|
|
17445
20218
|
const output = getOutput(cmd);
|
|
17446
20219
|
const auth = resolveAuth6(opts, output);
|
|
17447
20220
|
if (!auth)
|
|
17448
20221
|
return;
|
|
17449
|
-
const { client } = auth;
|
|
20222
|
+
const { client, projectId } = auth;
|
|
17450
20223
|
try {
|
|
17451
|
-
const deployment = await client.get(`/api/v1/projects/${
|
|
20224
|
+
const deployment = await client.get(`/api/v1/projects/${projectId}/deployments/${opts.id}`);
|
|
17452
20225
|
output.success(deployment);
|
|
17453
20226
|
} catch (err) {
|
|
17454
20227
|
if (err instanceof ApiClientError) {
|
|
@@ -17463,6 +20236,7 @@ var init_deployments2 = __esm(() => {
|
|
|
17463
20236
|
init_src3();
|
|
17464
20237
|
init_api_client();
|
|
17465
20238
|
init_config_store();
|
|
20239
|
+
init_project_id();
|
|
17466
20240
|
});
|
|
17467
20241
|
|
|
17468
20242
|
// src/commands/diagnose.ts
|
|
@@ -17529,8 +20303,13 @@ Prevention: ${preventionAdvice}`);
|
|
|
17529
20303
|
`);
|
|
17530
20304
|
}
|
|
17531
20305
|
function registerDiagnoseCommand(program2) {
|
|
17532
|
-
program2.command("diagnose [execution-id]").description("AI-powered diagnosis of a failed execution — identify root cause and suggested fix").
|
|
20306
|
+
program2.command("diagnose [execution-id]").description("AI-powered diagnosis of a failed execution — identify root cause and suggested fix").option("--project <id>", "Project ID (defaults to dura.json)").option("--latest", "Diagnose the most recent failed execution").option("--lookback <duration>", "Lookback window for related executions (e.g. 24h, 48h, 7d)").option("--force", "Force regeneration even if a cached diagnosis exists").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (executionId, opts, cmd) => {
|
|
17533
20307
|
const output = getOutput(cmd);
|
|
20308
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
20309
|
+
if (!projectId) {
|
|
20310
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
20311
|
+
return;
|
|
20312
|
+
}
|
|
17534
20313
|
const token = opts.token || getAuthToken();
|
|
17535
20314
|
if (!token) {
|
|
17536
20315
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
@@ -17545,7 +20324,7 @@ function registerDiagnoseCommand(program2) {
|
|
|
17545
20324
|
try {
|
|
17546
20325
|
let targetExecutionId = executionId;
|
|
17547
20326
|
if (opts.latest) {
|
|
17548
|
-
const executions = await client.get(`/api/v1/projects/${
|
|
20327
|
+
const executions = await client.get(`/api/v1/projects/${projectId}/executions?status=failed&limit=1`);
|
|
17549
20328
|
if (!executions || executions.length === 0) {
|
|
17550
20329
|
output.error("NO_FAILED_EXECUTIONS", "No failed executions found for this project");
|
|
17551
20330
|
return;
|
|
@@ -17557,7 +20336,7 @@ function registerDiagnoseCommand(program2) {
|
|
|
17557
20336
|
Analyzing execution ${targetExecutionId}...`);
|
|
17558
20337
|
}
|
|
17559
20338
|
const lookbackHours = parseLookbackHours(opts.lookback);
|
|
17560
|
-
const diagnosis = await client.post(`/api/v1/projects/${
|
|
20339
|
+
const diagnosis = await client.post(`/api/v1/projects/${projectId}/executions/${targetExecutionId}/diagnose`, {
|
|
17561
20340
|
lookbackHours,
|
|
17562
20341
|
force: opts.force ?? false
|
|
17563
20342
|
});
|
|
@@ -17579,6 +20358,7 @@ var init_diagnose = __esm(() => {
|
|
|
17579
20358
|
init_src3();
|
|
17580
20359
|
init_api_client();
|
|
17581
20360
|
init_config_store();
|
|
20361
|
+
init_project_id();
|
|
17582
20362
|
});
|
|
17583
20363
|
|
|
17584
20364
|
// src/commands/create.ts
|
|
@@ -17588,27 +20368,27 @@ __export(exports_create, {
|
|
|
17588
20368
|
registerAddCommand: () => registerAddCommand
|
|
17589
20369
|
});
|
|
17590
20370
|
import {
|
|
17591
|
-
existsSync as
|
|
20371
|
+
existsSync as existsSync10,
|
|
17592
20372
|
mkdirSync as mkdirSync5,
|
|
17593
20373
|
writeFileSync as writeFileSync8,
|
|
17594
|
-
readFileSync as
|
|
20374
|
+
readFileSync as readFileSync9,
|
|
17595
20375
|
readdirSync as readdirSync4
|
|
17596
20376
|
} from "node:fs";
|
|
17597
|
-
import { join as
|
|
20377
|
+
import { join as join11, resolve as resolve5, dirname } from "node:path";
|
|
17598
20378
|
function slugifyDescription(description) {
|
|
17599
20379
|
return description.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 30).replace(/-+$/, "");
|
|
17600
20380
|
}
|
|
17601
20381
|
function getExistingRoutes(projectDir) {
|
|
17602
|
-
const routesDir =
|
|
17603
|
-
const jobsDir =
|
|
20382
|
+
const routesDir = join11(projectDir, "routes");
|
|
20383
|
+
const jobsDir = join11(projectDir, "jobs");
|
|
17604
20384
|
const routes = [];
|
|
17605
|
-
if (
|
|
20385
|
+
if (existsSync10(routesDir)) {
|
|
17606
20386
|
try {
|
|
17607
20387
|
const files = readdirSync4(routesDir);
|
|
17608
20388
|
routes.push(...files.map((f) => `routes/${f}`));
|
|
17609
20389
|
} catch {}
|
|
17610
20390
|
}
|
|
17611
|
-
if (
|
|
20391
|
+
if (existsSync10(jobsDir)) {
|
|
17612
20392
|
try {
|
|
17613
20393
|
const files = readdirSync4(jobsDir);
|
|
17614
20394
|
routes.push(...files.map((f) => `jobs/${f}`));
|
|
@@ -17618,9 +20398,9 @@ function getExistingRoutes(projectDir) {
|
|
|
17618
20398
|
}
|
|
17619
20399
|
function writeGeneratedFiles(projectDir, files) {
|
|
17620
20400
|
for (const file of files) {
|
|
17621
|
-
const filePath =
|
|
20401
|
+
const filePath = join11(projectDir, file.path);
|
|
17622
20402
|
const dir = dirname(filePath);
|
|
17623
|
-
if (!
|
|
20403
|
+
if (!existsSync10(dir)) {
|
|
17624
20404
|
mkdirSync5(dir, { recursive: true });
|
|
17625
20405
|
}
|
|
17626
20406
|
writeFileSync8(filePath, file.content, "utf-8");
|
|
@@ -17652,8 +20432,8 @@ function registerCreateCommand(program2) {
|
|
|
17652
20432
|
}
|
|
17653
20433
|
const projectName = opts.name || slugifyDescription(description);
|
|
17654
20434
|
const parentDir = opts.dir ? resolve5(opts.dir) : process.cwd();
|
|
17655
|
-
const projectDir =
|
|
17656
|
-
if (
|
|
20435
|
+
const projectDir = join11(parentDir, projectName);
|
|
20436
|
+
if (existsSync10(projectDir)) {
|
|
17657
20437
|
output.error("DIRECTORY_EXISTS", `Directory "${projectName}" already exists`, "Choose a different name with --name or remove the existing directory");
|
|
17658
20438
|
return;
|
|
17659
20439
|
}
|
|
@@ -17682,8 +20462,8 @@ function registerCreateCommand(program2) {
|
|
|
17682
20462
|
return;
|
|
17683
20463
|
}
|
|
17684
20464
|
}
|
|
17685
|
-
mkdirSync5(
|
|
17686
|
-
mkdirSync5(
|
|
20465
|
+
mkdirSync5(join11(projectDir, "routes"), { recursive: true });
|
|
20466
|
+
mkdirSync5(join11(projectDir, "jobs"), { recursive: true });
|
|
17687
20467
|
writeGeneratedFiles(projectDir, generateResult.files);
|
|
17688
20468
|
output.info(`Files written to ${projectDir}`);
|
|
17689
20469
|
if (opts.deploy !== false) {
|
|
@@ -17714,15 +20494,15 @@ function registerAddCommand(program2) {
|
|
|
17714
20494
|
return;
|
|
17715
20495
|
}
|
|
17716
20496
|
const projectDir = opts.dir ? resolve5(opts.dir) : process.cwd();
|
|
17717
|
-
const duraJsonPath =
|
|
17718
|
-
if (!
|
|
20497
|
+
const duraJsonPath = join11(projectDir, "dura.json");
|
|
20498
|
+
if (!existsSync10(duraJsonPath)) {
|
|
17719
20499
|
output.error("NOT_A_DURA_PROJECT", "No dura.json found in the current directory", "Run this command from a Dura project directory or use --dir");
|
|
17720
20500
|
return;
|
|
17721
20501
|
}
|
|
17722
20502
|
const existingRoutes = getExistingRoutes(projectDir);
|
|
17723
20503
|
let projectConfig = {};
|
|
17724
20504
|
try {
|
|
17725
|
-
projectConfig = JSON.parse(
|
|
20505
|
+
projectConfig = JSON.parse(readFileSync9(duraJsonPath, "utf-8"));
|
|
17726
20506
|
} catch {}
|
|
17727
20507
|
const apiUrl = getApiUrl();
|
|
17728
20508
|
const client = new ApiClient(apiUrl, token);
|
|
@@ -17994,23 +20774,29 @@ __export(exports_env, {
|
|
|
17994
20774
|
registerCanaryCommand: () => registerCanaryCommand
|
|
17995
20775
|
});
|
|
17996
20776
|
function resolveClient(opts, output) {
|
|
20777
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
20778
|
+
if (!projectId) {
|
|
20779
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
20780
|
+
return null;
|
|
20781
|
+
}
|
|
17997
20782
|
const token = opts.token || getAuthToken();
|
|
17998
20783
|
if (!token) {
|
|
17999
20784
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
18000
20785
|
return null;
|
|
18001
20786
|
}
|
|
18002
20787
|
const apiUrl = opts.apiUrl || getApiUrl();
|
|
18003
|
-
return new ApiClient(apiUrl, token);
|
|
20788
|
+
return { client: new ApiClient(apiUrl, token), projectId };
|
|
18004
20789
|
}
|
|
18005
20790
|
function registerEnvCommand(program2) {
|
|
18006
20791
|
const env = program2.command("env").description("Manage project environments");
|
|
18007
|
-
env.command("create <name>").description("Create a new environment").
|
|
20792
|
+
env.command("create <name>").description("Create a new environment").option("--project <id>", "Project ID (defaults to dura.json)").option("--type <type>", "Environment type: production, staging, preview, custom", "custom").option("--slug <slug>", "URL slug (defaults to name)").option("--inherit-secrets <env>", "Inherit secrets from this environment ID").option("--auto-deploy", "Enable auto-deploy").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (name, opts, cmd) => {
|
|
18008
20793
|
const output = getOutput(cmd);
|
|
18009
|
-
const
|
|
18010
|
-
if (!
|
|
20794
|
+
const resolved = resolveClient(opts, output);
|
|
20795
|
+
if (!resolved)
|
|
18011
20796
|
return;
|
|
20797
|
+
const { client, projectId } = resolved;
|
|
18012
20798
|
try {
|
|
18013
|
-
const env2 = await client.post(`/api/v1/projects/${
|
|
20799
|
+
const env2 = await client.post(`/api/v1/projects/${projectId}/environments`, {
|
|
18014
20800
|
name,
|
|
18015
20801
|
slug: opts.slug ?? name.toLowerCase().replace(/[^a-z0-9-]/g, "-"),
|
|
18016
20802
|
type: opts.type,
|
|
@@ -18026,13 +20812,14 @@ function registerEnvCommand(program2) {
|
|
|
18026
20812
|
}
|
|
18027
20813
|
}
|
|
18028
20814
|
});
|
|
18029
|
-
env.command("list").description("List all environments for a project").
|
|
20815
|
+
env.command("list").description("List all environments for a project").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
|
|
18030
20816
|
const output = getOutput(cmd);
|
|
18031
|
-
const
|
|
18032
|
-
if (!
|
|
20817
|
+
const resolved = resolveClient(opts, output);
|
|
20818
|
+
if (!resolved)
|
|
18033
20819
|
return;
|
|
20820
|
+
const { client, projectId } = resolved;
|
|
18034
20821
|
try {
|
|
18035
|
-
const envs = await client.get(`/api/v1/projects/${
|
|
20822
|
+
const envs = await client.get(`/api/v1/projects/${projectId}/environments`);
|
|
18036
20823
|
output.success(envs);
|
|
18037
20824
|
} catch (err) {
|
|
18038
20825
|
if (err instanceof ApiClientError) {
|
|
@@ -18042,19 +20829,20 @@ function registerEnvCommand(program2) {
|
|
|
18042
20829
|
}
|
|
18043
20830
|
}
|
|
18044
20831
|
});
|
|
18045
|
-
env.command("delete <name>").description("Delete an environment").
|
|
20832
|
+
env.command("delete <name>").description("Delete an environment").option("--project <id>", "Project ID (defaults to dura.json)").option("--env-id <id>", "Environment ID (alternative to name)").option("--confirm", "Confirm deletion (required for destructive operation)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (name, opts, cmd) => {
|
|
18046
20833
|
const output = getOutput(cmd);
|
|
18047
20834
|
if (!opts.confirm) {
|
|
18048
20835
|
output.error("CONFIRM_REQUIRED", `Pass --confirm to delete environment "${name}"`, "This action is irreversible");
|
|
18049
20836
|
return;
|
|
18050
20837
|
}
|
|
18051
|
-
const
|
|
18052
|
-
if (!
|
|
20838
|
+
const resolved = resolveClient(opts, output);
|
|
20839
|
+
if (!resolved)
|
|
18053
20840
|
return;
|
|
20841
|
+
const { client, projectId } = resolved;
|
|
18054
20842
|
try {
|
|
18055
20843
|
let envId = opts.envId;
|
|
18056
20844
|
if (!envId) {
|
|
18057
|
-
const envs = await client.get(`/api/v1/projects/${
|
|
20845
|
+
const envs = await client.get(`/api/v1/projects/${projectId}/environments`);
|
|
18058
20846
|
const found = envs.find((e) => e.name === name);
|
|
18059
20847
|
if (!found) {
|
|
18060
20848
|
output.error("ENV_NOT_FOUND", `Environment "${name}" not found`);
|
|
@@ -18062,7 +20850,7 @@ function registerEnvCommand(program2) {
|
|
|
18062
20850
|
}
|
|
18063
20851
|
envId = found.id;
|
|
18064
20852
|
}
|
|
18065
|
-
await client.delete(`/api/v1/projects/${
|
|
20853
|
+
await client.delete(`/api/v1/projects/${projectId}/environments/${envId}`);
|
|
18066
20854
|
output.success({ deleted: true, name });
|
|
18067
20855
|
} catch (err) {
|
|
18068
20856
|
if (err instanceof ApiClientError) {
|
|
@@ -18072,13 +20860,14 @@ function registerEnvCommand(program2) {
|
|
|
18072
20860
|
}
|
|
18073
20861
|
}
|
|
18074
20862
|
});
|
|
18075
|
-
env.command("diff <env1> <env2>").description("Compare two environments").
|
|
20863
|
+
env.command("diff <env1> <env2>").description("Compare two environments").option("--project <id>", "Project ID (defaults to dura.json)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (env1, env2, opts, cmd) => {
|
|
18076
20864
|
const output = getOutput(cmd);
|
|
18077
|
-
const
|
|
18078
|
-
if (!
|
|
20865
|
+
const resolved = resolveClient(opts, output);
|
|
20866
|
+
if (!resolved)
|
|
18079
20867
|
return;
|
|
20868
|
+
const { client, projectId } = resolved;
|
|
18080
20869
|
try {
|
|
18081
|
-
const envs = await client.get(`/api/v1/projects/${
|
|
20870
|
+
const envs = await client.get(`/api/v1/projects/${projectId}/environments`);
|
|
18082
20871
|
const e1 = envs.find((e) => e.name === env1 || e.slug === env1);
|
|
18083
20872
|
const e2 = envs.find((e) => e.name === env2 || e.slug === env2);
|
|
18084
20873
|
if (!e1) {
|
|
@@ -18105,8 +20894,13 @@ function registerEnvCommand(program2) {
|
|
|
18105
20894
|
});
|
|
18106
20895
|
}
|
|
18107
20896
|
function registerPromoteCommand(program2) {
|
|
18108
|
-
program2.command("promote <source> <target>").description("Promote a deployment from source to target environment").
|
|
20897
|
+
program2.command("promote <source> <target>").description("Promote a deployment from source to target environment").option("--project <id>", "Project ID (defaults to dura.json)").option("--canary", "Use canary rollout (gradual traffic shift)").option("--steps <weights>", "Canary weight steps, comma-separated (e.g. 10,25,50,100)", "10,25,50,100").option("--interval <duration>", "Time between canary steps (e.g. 5m)", "5m").option("--deployment-id <id>", "Specific deployment ID to promote (defaults to source active)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (source, target, opts, cmd) => {
|
|
18109
20898
|
const output = getOutput(cmd);
|
|
20899
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
20900
|
+
if (!projectId) {
|
|
20901
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
20902
|
+
return;
|
|
20903
|
+
}
|
|
18110
20904
|
const token = opts.token || getAuthToken();
|
|
18111
20905
|
if (!token) {
|
|
18112
20906
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
@@ -18115,7 +20909,7 @@ function registerPromoteCommand(program2) {
|
|
|
18115
20909
|
const apiUrl = opts.apiUrl || getApiUrl();
|
|
18116
20910
|
const client = new ApiClient(apiUrl, token);
|
|
18117
20911
|
try {
|
|
18118
|
-
const envs = await client.get(`/api/v1/projects/${
|
|
20912
|
+
const envs = await client.get(`/api/v1/projects/${projectId}/environments`);
|
|
18119
20913
|
const sourceEnv = envs.find((e) => e.name === source || e.slug === source);
|
|
18120
20914
|
const targetEnv = envs.find((e) => e.name === target || e.slug === target);
|
|
18121
20915
|
if (!sourceEnv) {
|
|
@@ -18139,7 +20933,7 @@ function registerPromoteCommand(program2) {
|
|
|
18139
20933
|
delayMs: intervalMs
|
|
18140
20934
|
}));
|
|
18141
20935
|
}
|
|
18142
|
-
const promotion = await client.post(`/api/v1/projects/${
|
|
20936
|
+
const promotion = await client.post(`/api/v1/projects/${projectId}/promote`, {
|
|
18143
20937
|
sourceEnvId: sourceEnv.id,
|
|
18144
20938
|
targetEnvId: targetEnv.id,
|
|
18145
20939
|
deploymentId,
|
|
@@ -18158,8 +20952,13 @@ function registerPromoteCommand(program2) {
|
|
|
18158
20952
|
}
|
|
18159
20953
|
function registerCanaryCommand(program2) {
|
|
18160
20954
|
const canary = program2.command("canary").description("Manage canary deployments");
|
|
18161
|
-
canary.command("status").description("Show active canary deployment status").
|
|
20955
|
+
canary.command("status").description("Show active canary deployment status").option("--project <id>", "Project ID (defaults to dura.json)").requiredOption("--env <id>", "Environment ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
|
|
18162
20956
|
const output = getOutput(cmd);
|
|
20957
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
20958
|
+
if (!projectId) {
|
|
20959
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
20960
|
+
return;
|
|
20961
|
+
}
|
|
18163
20962
|
const token = opts.token || getAuthToken();
|
|
18164
20963
|
if (!token) {
|
|
18165
20964
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
@@ -18168,7 +20967,7 @@ function registerCanaryCommand(program2) {
|
|
|
18168
20967
|
const apiUrl = opts.apiUrl || getApiUrl();
|
|
18169
20968
|
const client = new ApiClient(apiUrl, token);
|
|
18170
20969
|
try {
|
|
18171
|
-
const canary2 = await client.get(`/api/v1/projects/${
|
|
20970
|
+
const canary2 = await client.get(`/api/v1/projects/${projectId}/canary?envId=${opts.env}`);
|
|
18172
20971
|
output.success(canary2);
|
|
18173
20972
|
} catch (err) {
|
|
18174
20973
|
if (err instanceof ApiClientError) {
|
|
@@ -18178,8 +20977,13 @@ function registerCanaryCommand(program2) {
|
|
|
18178
20977
|
}
|
|
18179
20978
|
}
|
|
18180
20979
|
});
|
|
18181
|
-
canary.command("complete").description("Force-complete an active canary (100% traffic to new)").
|
|
20980
|
+
canary.command("complete").description("Force-complete an active canary (100% traffic to new)").option("--project <id>", "Project ID (defaults to dura.json)").requiredOption("--canary-id <id>", "Canary deployment ID").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
|
|
18182
20981
|
const output = getOutput(cmd);
|
|
20982
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
20983
|
+
if (!projectId) {
|
|
20984
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
20985
|
+
return;
|
|
20986
|
+
}
|
|
18183
20987
|
const token = opts.token || getAuthToken();
|
|
18184
20988
|
if (!token) {
|
|
18185
20989
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
@@ -18188,7 +20992,7 @@ function registerCanaryCommand(program2) {
|
|
|
18188
20992
|
const apiUrl = opts.apiUrl || getApiUrl();
|
|
18189
20993
|
const client = new ApiClient(apiUrl, token);
|
|
18190
20994
|
try {
|
|
18191
|
-
const canary2 = await client.post(`/api/v1/projects/${
|
|
20995
|
+
const canary2 = await client.post(`/api/v1/projects/${projectId}/canary/complete`, { canaryId: opts.canaryId });
|
|
18192
20996
|
output.success(canary2);
|
|
18193
20997
|
} catch (err) {
|
|
18194
20998
|
if (err instanceof ApiClientError) {
|
|
@@ -18198,12 +21002,17 @@ function registerCanaryCommand(program2) {
|
|
|
18198
21002
|
}
|
|
18199
21003
|
}
|
|
18200
21004
|
});
|
|
18201
|
-
canary.command("rollback").description("Force-rollback an active canary (restore old deployment)").
|
|
21005
|
+
canary.command("rollback").description("Force-rollback an active canary (restore old deployment)").option("--project <id>", "Project ID (defaults to dura.json)").requiredOption("--canary-id <id>", "Canary deployment ID").option("--reason <reason>", "Reason for rollback").option("--confirm", "Confirm rollback (required)").option("--api-url <url>", "API base URL").option("--token <token>", "Auth token").action(async (opts, cmd) => {
|
|
18202
21006
|
const output = getOutput(cmd);
|
|
18203
21007
|
if (!opts.confirm) {
|
|
18204
21008
|
output.error("CONFIRM_REQUIRED", "Pass --confirm to rollback the canary", "This will restore 100% traffic to the old deployment");
|
|
18205
21009
|
return;
|
|
18206
21010
|
}
|
|
21011
|
+
const projectId = resolveProjectId({ project: opts.project });
|
|
21012
|
+
if (!projectId) {
|
|
21013
|
+
output.error("PROJECT_REQUIRED", "No project ID. Use --project or run this command inside a dura.json project.");
|
|
21014
|
+
return;
|
|
21015
|
+
}
|
|
18207
21016
|
const token = opts.token || getAuthToken();
|
|
18208
21017
|
if (!token) {
|
|
18209
21018
|
output.error("AUTH_REQUIRED", "Not logged in", "Run: dura login");
|
|
@@ -18212,7 +21021,7 @@ function registerCanaryCommand(program2) {
|
|
|
18212
21021
|
const apiUrl = opts.apiUrl || getApiUrl();
|
|
18213
21022
|
const client = new ApiClient(apiUrl, token);
|
|
18214
21023
|
try {
|
|
18215
|
-
const canary2 = await client.post(`/api/v1/projects/${
|
|
21024
|
+
const canary2 = await client.post(`/api/v1/projects/${projectId}/canary/rollback`, { canaryId: opts.canaryId, reason: opts.reason });
|
|
18216
21025
|
output.success(canary2);
|
|
18217
21026
|
} catch (err) {
|
|
18218
21027
|
if (err instanceof ApiClientError) {
|
|
@@ -18246,6 +21055,7 @@ var init_env = __esm(() => {
|
|
|
18246
21055
|
init_src3();
|
|
18247
21056
|
init_api_client();
|
|
18248
21057
|
init_config_store();
|
|
21058
|
+
init_project_id();
|
|
18249
21059
|
});
|
|
18250
21060
|
|
|
18251
21061
|
// src/commands/reports.ts
|
|
@@ -18881,30 +21691,30 @@ var init_heal = __esm(() => {
|
|
|
18881
21691
|
});
|
|
18882
21692
|
|
|
18883
21693
|
// src/lib/skill-installer.ts
|
|
18884
|
-
import { existsSync as
|
|
18885
|
-
import { join as
|
|
21694
|
+
import { existsSync as existsSync11, mkdirSync as mkdirSync6, readFileSync as readFileSync10, writeFileSync as writeFileSync9 } from "node:fs";
|
|
21695
|
+
import { join as join12, dirname as dirname2 } from "node:path";
|
|
18886
21696
|
import { homedir as homedir2 } from "node:os";
|
|
18887
21697
|
import { fileURLToPath } from "node:url";
|
|
18888
21698
|
function getSkillSourceDir() {
|
|
18889
21699
|
const __filename2 = fileURLToPath(import.meta.url);
|
|
18890
|
-
return
|
|
21700
|
+
return join12(dirname2(dirname2(__filename2)), "skills");
|
|
18891
21701
|
}
|
|
18892
21702
|
function getGlobalSkillsDir() {
|
|
18893
|
-
return
|
|
21703
|
+
return join12(homedir2(), ".claude", "skills", "dura");
|
|
18894
21704
|
}
|
|
18895
21705
|
function getLocalSkillsDir(projectDir) {
|
|
18896
|
-
return
|
|
21706
|
+
return join12(projectDir, ".claude", "skills", "dura");
|
|
18897
21707
|
}
|
|
18898
21708
|
function installSkills(targetDir) {
|
|
18899
21709
|
const sourceDir = getSkillSourceDir();
|
|
18900
|
-
if (!
|
|
21710
|
+
if (!existsSync11(targetDir)) {
|
|
18901
21711
|
mkdirSync6(targetDir, { recursive: true });
|
|
18902
21712
|
}
|
|
18903
21713
|
const installedFiles = [];
|
|
18904
21714
|
for (const file of SKILL_FILES) {
|
|
18905
|
-
const sourcePath =
|
|
18906
|
-
const targetPath =
|
|
18907
|
-
const content =
|
|
21715
|
+
const sourcePath = join12(sourceDir, file);
|
|
21716
|
+
const targetPath = join12(targetDir, file);
|
|
21717
|
+
const content = readFileSync10(sourcePath, "utf-8");
|
|
18908
21718
|
writeFileSync9(targetPath, content, "utf-8");
|
|
18909
21719
|
installedFiles.push(targetPath);
|
|
18910
21720
|
}
|
|
@@ -18929,8 +21739,8 @@ var exports_init = {};
|
|
|
18929
21739
|
__export(exports_init, {
|
|
18930
21740
|
registerInitCommand: () => registerInitCommand
|
|
18931
21741
|
});
|
|
18932
|
-
import { existsSync as
|
|
18933
|
-
import { join as
|
|
21742
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync7, writeFileSync as writeFileSync10 } from "node:fs";
|
|
21743
|
+
import { join as join13, resolve as resolve6, basename } from "node:path";
|
|
18934
21744
|
function registerInitCommand(program2) {
|
|
18935
21745
|
program2.command("init").description("Initialize a Dura project in the current directory and install AI agent skills").option("--dir <path>", "Project directory (defaults to current dir)").option("--name <name>", "Project name (defaults to directory name)").option("--global", "Install AI agent skills globally (~/.claude/skills/dura/)").option("--local", "Install AI agent skills locally (.claude/skills/dura/)").option("--skip-skills", "Skip AI agent skill installation").action(async (opts, cmd) => {
|
|
18936
21746
|
const output = getOutput(cmd);
|
|
@@ -18940,24 +21750,30 @@ function registerInitCommand(program2) {
|
|
|
18940
21750
|
output.error("INVALID_NAME", `Invalid project name "${projectName}"`, "Project name must start with a letter and contain only letters, numbers, hyphens, and underscores. Use --name to specify a valid name.");
|
|
18941
21751
|
return;
|
|
18942
21752
|
}
|
|
18943
|
-
|
|
18944
|
-
|
|
18945
|
-
|
|
21753
|
+
mkdirSync7(join13(projectDir, "routes"), { recursive: true });
|
|
21754
|
+
mkdirSync7(join13(projectDir, "jobs"), { recursive: true });
|
|
21755
|
+
const manifestPath = join13(projectDir, "dura.json");
|
|
21756
|
+
const alreadyInitialized = existsSync12(manifestPath);
|
|
21757
|
+
if (!alreadyInitialized) {
|
|
21758
|
+
writeFileSync10(manifestPath, duraJsonTemplate(projectName));
|
|
21759
|
+
} else {
|
|
21760
|
+
output.info(`dura.json already exists in ${projectDir} — leaving it in place.`);
|
|
18946
21761
|
}
|
|
18947
|
-
|
|
18948
|
-
|
|
18949
|
-
writeFileSync10(join12(projectDir, "dura.json"), duraJsonTemplate(projectName));
|
|
18950
|
-
const helloPath = join12(projectDir, "routes", "hello.ts");
|
|
18951
|
-
if (existsSync11(helloPath)) {
|
|
21762
|
+
const helloPath = join13(projectDir, "routes", "hello.ts");
|
|
21763
|
+
if (existsSync12(helloPath)) {
|
|
18952
21764
|
output.warn("routes/hello.ts already exists — skipping");
|
|
18953
21765
|
} else {
|
|
18954
21766
|
writeFileSync10(helloPath, HELLO_TEMPLATE);
|
|
18955
21767
|
}
|
|
18956
|
-
const gitignorePath =
|
|
18957
|
-
if (!
|
|
21768
|
+
const gitignorePath = join13(projectDir, ".gitignore");
|
|
21769
|
+
if (!existsSync12(gitignorePath)) {
|
|
18958
21770
|
writeFileSync10(gitignorePath, GITIGNORE_CONTENT2);
|
|
18959
21771
|
}
|
|
18960
|
-
|
|
21772
|
+
if (alreadyInitialized) {
|
|
21773
|
+
output.info(`Re-checked Dura project "${projectName}" in ${projectDir}`);
|
|
21774
|
+
} else {
|
|
21775
|
+
output.info(`Initialized Dura project "${projectName}"`);
|
|
21776
|
+
}
|
|
18961
21777
|
if (!opts.skipSkills) {
|
|
18962
21778
|
let skillScope;
|
|
18963
21779
|
if (opts.global) {
|
|
@@ -18982,6 +21798,7 @@ function registerInitCommand(program2) {
|
|
|
18982
21798
|
}
|
|
18983
21799
|
output.success({
|
|
18984
21800
|
initialized: true,
|
|
21801
|
+
alreadyInitialized,
|
|
18985
21802
|
name: projectName,
|
|
18986
21803
|
path: projectDir,
|
|
18987
21804
|
files: ["dura.json", "routes/hello.ts", "jobs/", ".gitignore"]
|
|
@@ -19027,6 +21844,7 @@ dist
|
|
|
19027
21844
|
`;
|
|
19028
21845
|
var init_init = __esm(() => {
|
|
19029
21846
|
init_src3();
|
|
21847
|
+
init_hello();
|
|
19030
21848
|
init_skill_installer();
|
|
19031
21849
|
});
|
|
19032
21850
|
|
|
@@ -19211,7 +22029,7 @@ async function registerAllCommands(program2) {
|
|
|
19211
22029
|
registerOpenApiCommand2(program2);
|
|
19212
22030
|
return program2;
|
|
19213
22031
|
}
|
|
19214
|
-
var CLI_VERSION = "0.
|
|
22032
|
+
var CLI_VERSION = "0.2.0";
|
|
19215
22033
|
var init_src3 = __esm(() => {
|
|
19216
22034
|
init_esm();
|
|
19217
22035
|
if (import.meta.url === `file://${realpathSync(process.argv[1] ?? "").replace(/\\/g, "/")}`) {
|
|
@@ -19228,4 +22046,4 @@ export {
|
|
|
19228
22046
|
CLI_VERSION
|
|
19229
22047
|
};
|
|
19230
22048
|
|
|
19231
|
-
//# debugId=
|
|
22049
|
+
//# debugId=53C9238AA228047C64756E2164756E21
|