@swell/cli 2.5.7 → 2.5.8
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.
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ChildProcess } from 'node:child_process';
|
|
1
3
|
import { PushAppCommand } from '../../push-app-command.js';
|
|
2
4
|
export default class AppDev extends PushAppCommand {
|
|
3
5
|
static delayOrientation: boolean;
|
|
@@ -16,6 +18,7 @@ export default class AppDev extends PushAppCommand {
|
|
|
16
18
|
static summary: string;
|
|
17
19
|
functionErrors: Map<string, string>;
|
|
18
20
|
functionPorts: Map<string, number>;
|
|
21
|
+
functionProcesses: Map<string, ChildProcess>;
|
|
19
22
|
tmpDir: string;
|
|
20
23
|
frontendPort: number | null;
|
|
21
24
|
isCleaningUp: boolean;
|
package/dist/commands/app/dev.js
CHANGED
|
@@ -50,6 +50,8 @@ export default class AppDev extends PushAppCommand {
|
|
|
50
50
|
functionErrors = new Map();
|
|
51
51
|
// All available functions
|
|
52
52
|
functionPorts = new Map();
|
|
53
|
+
// Wrangler child processes to kill on cleanup
|
|
54
|
+
functionProcesses = new Map();
|
|
53
55
|
// Directory for compiled function files and wrangler context
|
|
54
56
|
tmpDir = '';
|
|
55
57
|
// Port for frontend dev server (used for routing non-function requests)
|
|
@@ -84,6 +86,9 @@ export default class AppDev extends PushAppCommand {
|
|
|
84
86
|
if (this.isCleaningUp)
|
|
85
87
|
return;
|
|
86
88
|
this.isCleaningUp = true;
|
|
89
|
+
for (const [, proc] of this.functionProcesses) {
|
|
90
|
+
proc.kill();
|
|
91
|
+
}
|
|
87
92
|
try {
|
|
88
93
|
await this.updateLocalProxy(null, this.storefront?.id);
|
|
89
94
|
}
|
|
@@ -296,7 +301,9 @@ ENVIRONMENT = "development"
|
|
|
296
301
|
// Re-bundle the function
|
|
297
302
|
const { code } = await bundleFunction(fullPath);
|
|
298
303
|
// Update the bundled file (wrangler dev will auto-reload)
|
|
299
|
-
const
|
|
304
|
+
const functionDir = path.join(this.tmpDir, `${appConfig.name}`);
|
|
305
|
+
await fs.promises.mkdir(functionDir, { recursive: true });
|
|
306
|
+
const bundledPath = path.join(functionDir, `${appConfig.name}.js`);
|
|
300
307
|
await fs.promises.writeFile(bundledPath, code);
|
|
301
308
|
if (this.functionPorts.has(appConfig.name)) {
|
|
302
309
|
this.log(`\nUpdating function ${appConfig.name}...`);
|
|
@@ -355,6 +362,7 @@ ENVIRONMENT = "development"
|
|
|
355
362
|
}
|
|
356
363
|
async startFunctionServers(functions) {
|
|
357
364
|
const functionStatus = new Map();
|
|
365
|
+
const allocatedFunctionPorts = new Set();
|
|
358
366
|
const allocatedInspectorPorts = new Set();
|
|
359
367
|
/* eslint-disable no-await-in-loop */
|
|
360
368
|
for (const func of functions) {
|
|
@@ -363,7 +371,11 @@ ENVIRONMENT = "development"
|
|
|
363
371
|
// Function server already running
|
|
364
372
|
continue;
|
|
365
373
|
}
|
|
366
|
-
const functionPort = await getPort({
|
|
374
|
+
const functionPort = await getPort({
|
|
375
|
+
port: portNumbers(9000, 9100),
|
|
376
|
+
exclude: [...allocatedFunctionPorts],
|
|
377
|
+
});
|
|
378
|
+
allocatedFunctionPorts.add(functionPort);
|
|
367
379
|
const inspectorPort = await getPort({
|
|
368
380
|
port: portNumbers(9229, 9329),
|
|
369
381
|
exclude: [...allocatedInspectorPorts],
|
|
@@ -373,12 +385,15 @@ ENVIRONMENT = "development"
|
|
|
373
385
|
// Bundle the function
|
|
374
386
|
const fullPath = path.join(this.appPath, func.filePath);
|
|
375
387
|
const { code } = await bundleFunction(fullPath);
|
|
376
|
-
//
|
|
377
|
-
const
|
|
388
|
+
// Each function gets its own directory to avoid wrangler state conflicts
|
|
389
|
+
const functionDir = path.join(this.tmpDir, functionName);
|
|
390
|
+
await fs.promises.mkdir(functionDir, { recursive: true });
|
|
391
|
+
// Write bundled function to its directory
|
|
392
|
+
const bundledPath = path.join(functionDir, `${functionName}.js`);
|
|
378
393
|
await fs.promises.writeFile(bundledPath, code);
|
|
379
394
|
// Generate wrangler config
|
|
380
395
|
const wranglerConfig = this.generateWranglerConfig(functionName, bundledPath);
|
|
381
|
-
const configPath = path.join(
|
|
396
|
+
const configPath = path.join(functionDir, `${functionName}.toml`);
|
|
382
397
|
await fs.promises.writeFile(configPath, wranglerConfig);
|
|
383
398
|
functionStatus.set(functionName, 'starting');
|
|
384
399
|
// Start wrangler process in background using detected package manager
|
|
@@ -392,7 +407,7 @@ ENVIRONMENT = "development"
|
|
|
392
407
|
`--port=${functionPort}`,
|
|
393
408
|
`--inspector-port=${inspectorPort}`,
|
|
394
409
|
], {
|
|
395
|
-
cwd:
|
|
410
|
+
cwd: functionDir,
|
|
396
411
|
// stdio: 'pipe', // Capture output for debugging
|
|
397
412
|
detached: false,
|
|
398
413
|
});
|
|
@@ -458,7 +473,8 @@ ENVIRONMENT = "development"
|
|
|
458
473
|
this.functionErrors.set(functionName, `Process exited with code ${code}`);
|
|
459
474
|
}
|
|
460
475
|
});
|
|
461
|
-
// Store the port for routing
|
|
476
|
+
// Store the process and port for routing
|
|
477
|
+
this.functionProcesses.set(functionName, wranglerProcess);
|
|
462
478
|
this.functionPorts.set(functionName, functionPort);
|
|
463
479
|
}
|
|
464
480
|
catch (error) {
|
|
@@ -170,12 +170,22 @@ class SwellRequest {
|
|
|
170
170
|
...this.logParams,
|
|
171
171
|
message: {
|
|
172
172
|
...this.logParams?.message,
|
|
173
|
+
data: this.logParams?.message?.data || this.formatRequestData(),
|
|
173
174
|
logs: this._logs,
|
|
174
175
|
status: response.status,
|
|
175
176
|
},
|
|
176
177
|
},
|
|
177
178
|
};
|
|
178
179
|
}
|
|
180
|
+
formatRequestData() {
|
|
181
|
+
try {
|
|
182
|
+
const stringData = JSON.stringify(this.body ?? null);
|
|
183
|
+
return stringData.substring(0, 1024000);
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return '';
|
|
187
|
+
}
|
|
188
|
+
}
|
|
179
189
|
async ingestLogs(response) {
|
|
180
190
|
const ingestableLogs = this.getIngestableLogs(response);
|
|
181
191
|
if (!ingestableLogs) {
|
package/oclif.manifest.json
CHANGED