alchemy 0.12.9 → 0.12.11
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/lib/cloudflare/api.d.ts.map +1 -1
- package/lib/cloudflare/api.js +17 -12
- package/lib/cloudflare/api.js.map +1 -1
- package/lib/cloudflare/bucket.d.ts +16 -3
- package/lib/cloudflare/bucket.d.ts.map +1 -1
- package/lib/cloudflare/bucket.js +31 -6
- package/lib/cloudflare/bucket.js.map +1 -1
- package/lib/cloudflare/external.d.ts +2 -0
- package/lib/cloudflare/external.d.ts.map +1 -0
- package/lib/cloudflare/external.js +30 -0
- package/lib/cloudflare/external.js.map +1 -0
- package/lib/cloudflare/index.d.ts +1 -0
- package/lib/cloudflare/index.d.ts.map +1 -1
- package/lib/cloudflare/index.js +1 -0
- package/lib/cloudflare/index.js.map +1 -1
- package/lib/cloudflare/pipeline.d.ts +7 -1
- package/lib/cloudflare/pipeline.d.ts.map +1 -1
- package/lib/cloudflare/pipeline.js +1 -1
- package/lib/cloudflare/pipeline.js.map +1 -1
- package/lib/cloudflare/r2-rest-state-store.d.ts +2 -2
- package/lib/cloudflare/r2-rest-state-store.d.ts.map +1 -1
- package/lib/cloudflare/r2-rest-state-store.js +13 -5
- package/lib/cloudflare/r2-rest-state-store.js.map +1 -1
- package/lib/cloudflare/redwood.d.ts +1 -33
- package/lib/cloudflare/redwood.d.ts.map +1 -1
- package/lib/cloudflare/redwood.js +7 -46
- package/lib/cloudflare/redwood.js.map +1 -1
- package/lib/cloudflare/website.d.ts +4 -1
- package/lib/cloudflare/website.d.ts.map +1 -1
- package/lib/cloudflare/website.js +10 -2
- package/lib/cloudflare/website.js.map +1 -1
- package/lib/cloudflare/worker.d.ts.map +1 -1
- package/lib/cloudflare/worker.js +17 -33
- package/lib/cloudflare/worker.js.map +1 -1
- package/lib/cloudflare/wrangler.json.d.ts +6 -0
- package/lib/cloudflare/wrangler.json.d.ts.map +1 -1
- package/lib/cloudflare/wrangler.json.js +1 -1
- package/lib/cloudflare/wrangler.json.js.map +1 -1
- package/lib/esbuild/bundle.d.ts +4 -4
- package/lib/esbuild/bundle.d.ts.map +1 -1
- package/lib/esbuild/bundle.js +9 -7
- package/lib/esbuild/bundle.js.map +1 -1
- package/lib/os/exec.d.ts +15 -15
- package/lib/os/exec.d.ts.map +1 -1
- package/lib/os/exec.js +47 -26
- package/lib/os/exec.js.map +1 -1
- package/package.json +1 -1
- package/src/cloudflare/api.ts +15 -13
- package/src/cloudflare/bucket.ts +56 -8
- package/src/cloudflare/external.ts +30 -0
- package/src/cloudflare/index.ts +1 -0
- package/src/cloudflare/pipeline.ts +9 -2
- package/src/cloudflare/r2-rest-state-store.ts +24 -6
- package/src/cloudflare/redwood.ts +8 -46
- package/src/cloudflare/website.ts +19 -3
- package/src/cloudflare/worker.ts +22 -42
- package/src/cloudflare/wrangler.json.ts +8 -1
- package/src/esbuild/bundle.ts +11 -9
- package/src/os/exec.ts +61 -34
|
@@ -23,6 +23,13 @@ export interface WranglerJsonProps {
|
|
|
23
23
|
* @default cwd/wrangler.json
|
|
24
24
|
*/
|
|
25
25
|
path?: string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The main entry point for the worker
|
|
29
|
+
*
|
|
30
|
+
* @default worker.entrypoint
|
|
31
|
+
*/
|
|
32
|
+
main?: string;
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
/**
|
|
@@ -75,7 +82,7 @@ export const WranglerJson = Resource(
|
|
|
75
82
|
const spec: WranglerJsonSpec = {
|
|
76
83
|
name: worker.name,
|
|
77
84
|
// Use entrypoint as main if it exists
|
|
78
|
-
main: worker.entrypoint,
|
|
85
|
+
main: props.main ?? worker.entrypoint,
|
|
79
86
|
// see: https://developers.cloudflare.com/workers/configuration/compatibility-dates/
|
|
80
87
|
compatibility_date: worker.compatibilityDate,
|
|
81
88
|
compatibility_flags: props.worker.compatibilityFlags,
|
package/src/esbuild/bundle.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { Resource } from "../resource.js";
|
|
|
8
8
|
/**
|
|
9
9
|
* Properties for creating or updating an esbuild bundle
|
|
10
10
|
*/
|
|
11
|
-
export interface BundleProps {
|
|
11
|
+
export interface BundleProps extends Partial<esbuild.BuildOptions> {
|
|
12
12
|
/**
|
|
13
13
|
* Entry point for the bundle
|
|
14
14
|
* Path to the source file to bundle (e.g., "src/handler.ts")
|
|
@@ -143,7 +143,7 @@ export const Bundle = Resource(
|
|
|
143
143
|
|
|
144
144
|
const result = await bundle(props);
|
|
145
145
|
|
|
146
|
-
const bundlePath = Object.entries(result.metafile
|
|
146
|
+
const bundlePath = Object.entries(result.metafile!.outputs).find(
|
|
147
147
|
([_, output]) => {
|
|
148
148
|
if (output.entryPoint === undefined) {
|
|
149
149
|
return false;
|
|
@@ -186,7 +186,9 @@ export const Bundle = Resource(
|
|
|
186
186
|
);
|
|
187
187
|
|
|
188
188
|
export async function bundle(props: BundleProps) {
|
|
189
|
-
|
|
189
|
+
const { entryPoint, options: _, ...rest } = props;
|
|
190
|
+
const options = {
|
|
191
|
+
...rest,
|
|
190
192
|
...props.options,
|
|
191
193
|
write: !(props.outdir === undefined && props.outfile === undefined),
|
|
192
194
|
// write:
|
|
@@ -200,12 +202,12 @@ export async function bundle(props: BundleProps) {
|
|
|
200
202
|
target: props.target,
|
|
201
203
|
minify: props.minify,
|
|
202
204
|
sourcemap: props.sourcemap,
|
|
203
|
-
external: [
|
|
204
|
-
"node:*",
|
|
205
|
-
...(props.external ?? []),
|
|
206
|
-
...(props.options?.external ?? []),
|
|
207
|
-
],
|
|
205
|
+
external: [...(props.external ?? []), ...(props.options?.external ?? [])],
|
|
208
206
|
platform: props.platform,
|
|
209
207
|
metafile: true,
|
|
210
|
-
}
|
|
208
|
+
};
|
|
209
|
+
if (process.env.DEBUG) {
|
|
210
|
+
console.log(options);
|
|
211
|
+
}
|
|
212
|
+
return await esbuild.build(options);
|
|
211
213
|
}
|
package/src/os/exec.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { promisify } from "node:util";
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
3
2
|
import type { Context } from "../context.js";
|
|
4
3
|
import { Resource } from "../resource.js";
|
|
5
4
|
|
|
6
|
-
const execAsync = promisify(exec);
|
|
7
|
-
|
|
8
5
|
/**
|
|
9
6
|
* Properties for executing a shell command
|
|
10
7
|
*/
|
|
@@ -32,15 +29,15 @@ export interface ExecProps {
|
|
|
32
29
|
env?: Record<string, string>;
|
|
33
30
|
|
|
34
31
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @default 1024 * 1024 (1MB)
|
|
32
|
+
* Whether to throw an error if the command exits with a non-zero status
|
|
37
33
|
*/
|
|
38
|
-
|
|
34
|
+
throwOnError?: boolean;
|
|
39
35
|
|
|
40
36
|
/**
|
|
41
|
-
* Whether to
|
|
37
|
+
* Whether to inherit stdio from parent process
|
|
38
|
+
* @default true
|
|
42
39
|
*/
|
|
43
|
-
|
|
40
|
+
inheritStdio?: boolean;
|
|
44
41
|
}
|
|
45
42
|
|
|
46
43
|
/**
|
|
@@ -58,12 +55,12 @@ export interface Exec extends Resource<"os::Exec">, ExecProps {
|
|
|
58
55
|
exitCode: number;
|
|
59
56
|
|
|
60
57
|
/**
|
|
61
|
-
* Standard output from the command
|
|
58
|
+
* Standard output from the command (only available when inheritStdio is false)
|
|
62
59
|
*/
|
|
63
60
|
stdout: string;
|
|
64
61
|
|
|
65
62
|
/**
|
|
66
|
-
* Standard error from the command
|
|
63
|
+
* Standard error from the command (only available when inheritStdio is false)
|
|
67
64
|
*/
|
|
68
65
|
stderr: string;
|
|
69
66
|
|
|
@@ -82,11 +79,18 @@ export interface Exec extends Resource<"os::Exec">, ExecProps {
|
|
|
82
79
|
* Execute a shell command
|
|
83
80
|
*
|
|
84
81
|
* @example
|
|
85
|
-
* // Run a simple command
|
|
82
|
+
* // Run a simple command with inherited stdio (default)
|
|
86
83
|
* const result = await Exec("list-files", {
|
|
87
84
|
* command: "ls -la"
|
|
88
85
|
* });
|
|
89
86
|
*
|
|
87
|
+
* @example
|
|
88
|
+
* // Run a command and capture output instead of inheriting stdio
|
|
89
|
+
* const result = await Exec("list-files", {
|
|
90
|
+
* command: "ls -la",
|
|
91
|
+
* inheritStdio: false
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
90
94
|
* console.log(result.stdout);
|
|
91
95
|
*
|
|
92
96
|
* @example
|
|
@@ -98,13 +102,6 @@ export interface Exec extends Resource<"os::Exec">, ExecProps {
|
|
|
98
102
|
* });
|
|
99
103
|
*
|
|
100
104
|
* @example
|
|
101
|
-
* // Run a command with a larger buffer for output
|
|
102
|
-
* const logs = await Exec("get-logs", {
|
|
103
|
-
* command: "cat large-log-file.log",
|
|
104
|
-
* maxBuffer: 10 * 1024 * 1024 // 10MB
|
|
105
|
-
* });
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
105
|
* // Run a memoized command that only re-executes when the command changes
|
|
109
106
|
* const memoizedCmd = await Exec("status-check", {
|
|
110
107
|
* command: "git status",
|
|
@@ -143,31 +140,61 @@ export const Exec = Resource(
|
|
|
143
140
|
let stderr = "";
|
|
144
141
|
let exitCode = 0;
|
|
145
142
|
|
|
143
|
+
// Default to inheriting stdio unless explicitly set to false
|
|
144
|
+
const inheritStdio = props.inheritStdio !== false;
|
|
145
|
+
|
|
146
146
|
try {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
// Parse the command into command and args
|
|
148
|
+
const [cmd, ...args] = props.command.split(/\s+/);
|
|
149
|
+
|
|
150
|
+
// Use spawn for better stdio control
|
|
151
|
+
const childProcess = spawn(cmd, args, {
|
|
150
152
|
cwd: props.cwd || process.cwd(),
|
|
151
153
|
env: { ...process.env, ...props.env },
|
|
152
|
-
|
|
154
|
+
shell: true, // Use shell to handle complex commands
|
|
155
|
+
stdio: inheritStdio ? "inherit" : "pipe", // Inherit stdio when requested
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
if (!inheritStdio) {
|
|
159
|
+
// If not inheriting stdio, collect output manually
|
|
160
|
+
childProcess.stdout?.on("data", (data) => {
|
|
161
|
+
stdout += data.toString();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
childProcess.stderr?.on("data", (data) => {
|
|
165
|
+
stderr += data.toString();
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Wait for the process to complete
|
|
170
|
+
exitCode = await new Promise<number>((resolve, reject) => {
|
|
171
|
+
childProcess.on("close", (code) => {
|
|
172
|
+
resolve(code || 0);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
childProcess.on("error", (err) => {
|
|
176
|
+
if (props.throwOnError) {
|
|
177
|
+
reject(err);
|
|
178
|
+
} else {
|
|
179
|
+
stderr += err.toString();
|
|
180
|
+
resolve(1);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
153
183
|
});
|
|
154
184
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
185
|
+
if (exitCode !== 0 && props.throwOnError) {
|
|
186
|
+
throw new Error(
|
|
187
|
+
`Command failed with exit code ${exitCode}: ${props.command}`
|
|
188
|
+
);
|
|
189
|
+
}
|
|
159
190
|
} catch (error: any) {
|
|
160
|
-
console.log("error", error);
|
|
161
191
|
if (props.throwOnError) {
|
|
162
192
|
throw error;
|
|
163
193
|
}
|
|
164
194
|
|
|
165
195
|
// If not throwing, capture the error information
|
|
166
|
-
exitCode =
|
|
167
|
-
|
|
168
|
-
stderr = error.stderr || String(error);
|
|
169
|
-
console.log(stdout);
|
|
170
|
-
console.error(stderr);
|
|
196
|
+
exitCode = 1;
|
|
197
|
+
stderr += String(error);
|
|
171
198
|
}
|
|
172
199
|
|
|
173
200
|
// Return the execution result
|
|
@@ -176,9 +203,9 @@ export const Exec = Resource(
|
|
|
176
203
|
command: props.command,
|
|
177
204
|
cwd: props.cwd,
|
|
178
205
|
env: props.env,
|
|
179
|
-
maxBuffer: props.maxBuffer,
|
|
180
206
|
throwOnError: props.throwOnError,
|
|
181
207
|
memoize: props.memoize,
|
|
208
|
+
inheritStdio,
|
|
182
209
|
exitCode,
|
|
183
210
|
stdout,
|
|
184
211
|
stderr,
|