@walkeros/cli 0.6.0 → 0.6.1-next-1766186076625
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/CHANGELOG.md +12 -0
- package/README.md +53 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +364 -194
- package/dist/index.js.map +1 -1
- package/dist/runtime/main.js +3 -2
- package/dist/runtime/main.js.map +1 -1
- package/package.json +2 -2
- package/dist/__tests__/bundle/bundler-helpers.test.d.ts +0 -2
- package/dist/__tests__/bundle/bundler-helpers.test.d.ts.map +0 -1
- package/dist/__tests__/bundle/bundler-helpers.test.js +0 -151
- package/dist/__tests__/bundle/bundler-helpers.test.js.map +0 -1
- package/dist/__tests__/bundle/bundler.test.d.ts +0 -2
- package/dist/__tests__/bundle/bundler.test.d.ts.map +0 -1
- package/dist/__tests__/bundle/bundler.test.js +0 -352
- package/dist/__tests__/bundle/bundler.test.js.map +0 -1
- package/dist/__tests__/bundle/programmatic.test.d.ts +0 -2
- package/dist/__tests__/bundle/programmatic.test.d.ts.map +0 -1
- package/dist/__tests__/bundle/programmatic.test.js +0 -148
- package/dist/__tests__/bundle/programmatic.test.js.map +0 -1
- package/dist/__tests__/cli-e2e.test.d.ts +0 -8
- package/dist/__tests__/cli-e2e.test.d.ts.map +0 -1
- package/dist/__tests__/cli-e2e.test.js +0 -145
- package/dist/__tests__/cli-e2e.test.js.map +0 -1
- package/dist/__tests__/cli.test.d.ts +0 -2
- package/dist/__tests__/cli.test.d.ts.map +0 -1
- package/dist/__tests__/cli.test.js +0 -179
- package/dist/__tests__/cli.test.js.map +0 -1
- package/dist/__tests__/config-loader.test.d.ts +0 -7
- package/dist/__tests__/config-loader.test.d.ts.map +0 -1
- package/dist/__tests__/config-loader.test.js +0 -414
- package/dist/__tests__/config-loader.test.js.map +0 -1
- package/dist/__tests__/core/asset-resolver.test.d.ts +0 -2
- package/dist/__tests__/core/asset-resolver.test.d.ts.map +0 -1
- package/dist/__tests__/core/asset-resolver.test.js +0 -14
- package/dist/__tests__/core/asset-resolver.test.js.map +0 -1
- package/dist/__tests__/core/build-cache.test.d.ts +0 -2
- package/dist/__tests__/core/build-cache.test.d.ts.map +0 -1
- package/dist/__tests__/core/build-cache.test.js +0 -55
- package/dist/__tests__/core/build-cache.test.js.map +0 -1
- package/dist/__tests__/core/cache-utils.test.d.ts +0 -2
- package/dist/__tests__/core/cache-utils.test.d.ts.map +0 -1
- package/dist/__tests__/core/cache-utils.test.js +0 -70
- package/dist/__tests__/core/cache-utils.test.js.map +0 -1
- package/dist/__tests__/core/config.test.d.ts +0 -2
- package/dist/__tests__/core/config.test.d.ts.map +0 -1
- package/dist/__tests__/core/config.test.js +0 -79
- package/dist/__tests__/core/config.test.js.map +0 -1
- package/dist/__tests__/core/logger.test.d.ts +0 -2
- package/dist/__tests__/core/logger.test.d.ts.map +0 -1
- package/dist/__tests__/core/logger.test.js +0 -53
- package/dist/__tests__/core/logger.test.js.map +0 -1
- package/dist/__tests__/integration/bundle-run.integration.test.d.ts +0 -8
- package/dist/__tests__/integration/bundle-run.integration.test.d.ts.map +0 -1
- package/dist/__tests__/integration/bundle-run.integration.test.js +0 -54
- package/dist/__tests__/integration/bundle-run.integration.test.js.map +0 -1
- package/dist/__tests__/push/push.test.d.ts +0 -7
- package/dist/__tests__/push/push.test.d.ts.map +0 -1
- package/dist/__tests__/push/push.test.js +0 -197
- package/dist/__tests__/push/push.test.js.map +0 -1
- package/dist/__tests__/simulate/env-loader.test.d.ts +0 -2
- package/dist/__tests__/simulate/env-loader.test.d.ts.map +0 -1
- package/dist/__tests__/simulate/env-loader.test.js +0 -47
- package/dist/__tests__/simulate/env-loader.test.js.map +0 -1
- package/dist/__tests__/simulate/node-executor.test.d.ts +0 -5
- package/dist/__tests__/simulate/node-executor.test.d.ts.map +0 -1
- package/dist/__tests__/simulate/node-executor.test.js +0 -25
- package/dist/__tests__/simulate/node-executor.test.js.map +0 -1
- package/dist/__tests__/simulate/server-simulate.integration.test.d.ts +0 -5
- package/dist/__tests__/simulate/server-simulate.integration.test.d.ts.map +0 -1
- package/dist/__tests__/simulate/server-simulate.integration.test.js +0 -58
- package/dist/__tests__/simulate/server-simulate.integration.test.js.map +0 -1
- package/dist/__tests__/smoke/production.smoke.test.d.ts +0 -8
- package/dist/__tests__/smoke/production.smoke.test.d.ts.map +0 -1
- package/dist/__tests__/smoke/production.smoke.test.js +0 -65
- package/dist/__tests__/smoke/production.smoke.test.js.map +0 -1
- package/dist/commands/bundle/bundler.d.ts +0 -32
- package/dist/commands/bundle/bundler.d.ts.map +0 -1
- package/dist/commands/bundle/bundler.js +0 -569
- package/dist/commands/bundle/bundler.js.map +0 -1
- package/dist/commands/bundle/index.d.ts +0 -59
- package/dist/commands/bundle/index.d.ts.map +0 -1
- package/dist/commands/bundle/index.js +0 -184
- package/dist/commands/bundle/index.js.map +0 -1
- package/dist/commands/bundle/package-manager.d.ts +0 -8
- package/dist/commands/bundle/package-manager.d.ts.map +0 -1
- package/dist/commands/bundle/package-manager.js +0 -220
- package/dist/commands/bundle/package-manager.js.map +0 -1
- package/dist/commands/bundle/stats.d.ts +0 -23
- package/dist/commands/bundle/stats.d.ts.map +0 -1
- package/dist/commands/bundle/stats.js +0 -52
- package/dist/commands/bundle/stats.js.map +0 -1
- package/dist/commands/cache.d.ts +0 -7
- package/dist/commands/cache.d.ts.map +0 -1
- package/dist/commands/cache.js +0 -68
- package/dist/commands/cache.js.map +0 -1
- package/dist/commands/push/index.d.ts +0 -7
- package/dist/commands/push/index.d.ts.map +0 -1
- package/dist/commands/push/index.js +0 -247
- package/dist/commands/push/index.js.map +0 -1
- package/dist/commands/push/types.d.ts +0 -22
- package/dist/commands/push/types.d.ts.map +0 -1
- package/dist/commands/push/types.js +0 -2
- package/dist/commands/push/types.js.map +0 -1
- package/dist/commands/run/__tests__/run.integration.test.d.ts +0 -7
- package/dist/commands/run/__tests__/run.integration.test.d.ts.map +0 -1
- package/dist/commands/run/__tests__/run.integration.test.js +0 -51
- package/dist/commands/run/__tests__/run.integration.test.js.map +0 -1
- package/dist/commands/run/__tests__/validators.test.d.ts +0 -2
- package/dist/commands/run/__tests__/validators.test.d.ts.map +0 -1
- package/dist/commands/run/__tests__/validators.test.js +0 -80
- package/dist/commands/run/__tests__/validators.test.js.map +0 -1
- package/dist/commands/run/execution.d.ts +0 -14
- package/dist/commands/run/execution.d.ts.map +0 -1
- package/dist/commands/run/execution.js +0 -41
- package/dist/commands/run/execution.js.map +0 -1
- package/dist/commands/run/index.d.ts +0 -38
- package/dist/commands/run/index.d.ts.map +0 -1
- package/dist/commands/run/index.js +0 -154
- package/dist/commands/run/index.js.map +0 -1
- package/dist/commands/run/types.d.ts +0 -65
- package/dist/commands/run/types.d.ts.map +0 -1
- package/dist/commands/run/types.js +0 -7
- package/dist/commands/run/types.js.map +0 -1
- package/dist/commands/run/utils.d.ts +0 -29
- package/dist/commands/run/utils.d.ts.map +0 -1
- package/dist/commands/run/utils.js +0 -52
- package/dist/commands/run/utils.js.map +0 -1
- package/dist/commands/run/validators.d.ts +0 -33
- package/dist/commands/run/validators.d.ts.map +0 -1
- package/dist/commands/run/validators.js +0 -58
- package/dist/commands/run/validators.js.map +0 -1
- package/dist/commands/simulate/env-loader.d.ts +0 -19
- package/dist/commands/simulate/env-loader.d.ts.map +0 -1
- package/dist/commands/simulate/env-loader.js +0 -44
- package/dist/commands/simulate/env-loader.js.map +0 -1
- package/dist/commands/simulate/index.d.ts +0 -48
- package/dist/commands/simulate/index.d.ts.map +0 -1
- package/dist/commands/simulate/index.js +0 -113
- package/dist/commands/simulate/index.js.map +0 -1
- package/dist/commands/simulate/jsdom-executor.d.ts +0 -37
- package/dist/commands/simulate/jsdom-executor.d.ts.map +0 -1
- package/dist/commands/simulate/jsdom-executor.js +0 -137
- package/dist/commands/simulate/jsdom-executor.js.map +0 -1
- package/dist/commands/simulate/node-executor.d.ts +0 -28
- package/dist/commands/simulate/node-executor.d.ts.map +0 -1
- package/dist/commands/simulate/node-executor.js +0 -94
- package/dist/commands/simulate/node-executor.js.map +0 -1
- package/dist/commands/simulate/simulator.d.ts +0 -14
- package/dist/commands/simulate/simulator.d.ts.map +0 -1
- package/dist/commands/simulate/simulator.js +0 -163
- package/dist/commands/simulate/simulator.js.map +0 -1
- package/dist/commands/simulate/tracker.d.ts +0 -30
- package/dist/commands/simulate/tracker.d.ts.map +0 -1
- package/dist/commands/simulate/tracker.js +0 -96
- package/dist/commands/simulate/tracker.js.map +0 -1
- package/dist/commands/simulate/types.d.ts +0 -20
- package/dist/commands/simulate/types.d.ts.map +0 -1
- package/dist/commands/simulate/types.js +0 -2
- package/dist/commands/simulate/types.js.map +0 -1
- package/dist/config/build-defaults.d.ts +0 -49
- package/dist/config/build-defaults.d.ts.map +0 -1
- package/dist/config/build-defaults.js +0 -68
- package/dist/config/build-defaults.js.map +0 -1
- package/dist/config/index.d.ts +0 -13
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -15
- package/dist/config/index.js.map +0 -1
- package/dist/config/loader.d.ts +0 -81
- package/dist/config/loader.d.ts.map +0 -1
- package/dist/config/loader.js +0 -153
- package/dist/config/loader.js.map +0 -1
- package/dist/config/utils.d.ts +0 -101
- package/dist/config/utils.d.ts.map +0 -1
- package/dist/config/utils.js +0 -235
- package/dist/config/utils.js.map +0 -1
- package/dist/config/validators.d.ts +0 -52
- package/dist/config/validators.d.ts.map +0 -1
- package/dist/config/validators.js +0 -85
- package/dist/config/validators.js.map +0 -1
- package/dist/core/asset-resolver.d.ts +0 -34
- package/dist/core/asset-resolver.d.ts.map +0 -1
- package/dist/core/asset-resolver.js +0 -70
- package/dist/core/asset-resolver.js.map +0 -1
- package/dist/core/build-cache.d.ts +0 -23
- package/dist/core/build-cache.d.ts.map +0 -1
- package/dist/core/build-cache.js +0 -44
- package/dist/core/build-cache.js.map +0 -1
- package/dist/core/cache-utils.d.ts +0 -27
- package/dist/core/cache-utils.d.ts.map +0 -1
- package/dist/core/cache-utils.js +0 -60
- package/dist/core/cache-utils.js.map +0 -1
- package/dist/core/index.d.ts +0 -8
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -8
- package/dist/core/index.js.map +0 -1
- package/dist/core/local-packages.d.ts +0 -19
- package/dist/core/local-packages.d.ts.map +0 -1
- package/dist/core/local-packages.js +0 -60
- package/dist/core/local-packages.js.map +0 -1
- package/dist/core/logger.d.ts +0 -30
- package/dist/core/logger.d.ts.map +0 -1
- package/dist/core/logger.js +0 -85
- package/dist/core/logger.js.map +0 -1
- package/dist/core/output.d.ts +0 -30
- package/dist/core/output.d.ts.map +0 -1
- package/dist/core/output.js +0 -46
- package/dist/core/output.js.map +0 -1
- package/dist/core/timer.d.ts +0 -14
- package/dist/core/timer.d.ts.map +0 -1
- package/dist/core/timer.js +0 -29
- package/dist/core/timer.js.map +0 -1
- package/dist/core/tmp.d.ts +0 -27
- package/dist/core/tmp.d.ts.map +0 -1
- package/dist/core/tmp.js +0 -36
- package/dist/core/tmp.js.map +0 -1
- package/dist/core/utils.d.ts +0 -10
- package/dist/core/utils.d.ts.map +0 -1
- package/dist/core/utils.js +0 -12
- package/dist/core/utils.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/runtime/index.d.ts +0 -10
- package/dist/runtime/index.d.ts.map +0 -1
- package/dist/runtime/index.js +0 -10
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/main.d.ts.map +0 -1
- package/dist/runtime/runner.d.ts +0 -20
- package/dist/runtime/runner.d.ts.map +0 -1
- package/dist/runtime/runner.js +0 -72
- package/dist/runtime/runner.js.map +0 -1
- package/dist/runtime/serve.d.ts +0 -19
- package/dist/runtime/serve.d.ts.map +0 -1
- package/dist/runtime/serve.js +0 -97
- package/dist/runtime/serve.js.map +0 -1
- package/dist/schemas/index.d.ts +0 -9
- package/dist/schemas/index.d.ts.map +0 -1
- package/dist/schemas/index.js +0 -9
- package/dist/schemas/index.js.map +0 -1
- package/dist/schemas/primitives.d.ts +0 -37
- package/dist/schemas/primitives.d.ts.map +0 -1
- package/dist/schemas/primitives.js +0 -43
- package/dist/schemas/primitives.js.map +0 -1
- package/dist/schemas/run.d.ts +0 -23
- package/dist/schemas/run.d.ts.map +0 -1
- package/dist/schemas/run.js +0 -20
- package/dist/schemas/run.js.map +0 -1
- package/dist/types/bundle.d.ts +0 -141
- package/dist/types/bundle.d.ts.map +0 -1
- package/dist/types/bundle.js +0 -10
- package/dist/types/bundle.js.map +0 -1
- package/dist/types/global.d.ts +0 -38
- package/dist/types/global.d.ts.map +0 -1
- package/dist/types/global.js +0 -24
- package/dist/types/global.js.map +0 -1
- package/dist/types/index.d.ts +0 -8
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -8
- package/dist/types/index.js.map +0 -1
- package/dist/version.d.ts +0 -3
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js +0 -27
- package/dist/version.js.map +0 -1
- package/dist/walker.js +0 -1
package/dist/index.js
CHANGED
|
@@ -108,6 +108,23 @@ function createCommandLogger(options) {
|
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
// src/core/collector-logger.ts
|
|
112
|
+
function createCollectorLoggerConfig(cliLogger, verbose) {
|
|
113
|
+
return {
|
|
114
|
+
level: verbose ? "DEBUG" : "ERROR",
|
|
115
|
+
handler: (level, message, context, scope) => {
|
|
116
|
+
const scopePath = scope.length > 0 ? `[${scope.join(":")}] ` : "";
|
|
117
|
+
const hasContext = Object.keys(context).length > 0;
|
|
118
|
+
const contextStr = hasContext ? ` ${JSON.stringify(context)}` : "";
|
|
119
|
+
if (level === 0) {
|
|
120
|
+
cliLogger.error(`${scopePath}${message}${contextStr}`);
|
|
121
|
+
} else if (verbose) {
|
|
122
|
+
cliLogger.debug(`${scopePath}${message}${contextStr}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
111
128
|
// src/core/timer.ts
|
|
112
129
|
function createTimer() {
|
|
113
130
|
let startTime = 0;
|
|
@@ -374,6 +391,33 @@ async function copyLocalPackage(localPkg, targetDir, logger2) {
|
|
|
374
391
|
return packageDir;
|
|
375
392
|
}
|
|
376
393
|
|
|
394
|
+
// src/core/input-detector.ts
|
|
395
|
+
import fs3 from "fs-extra";
|
|
396
|
+
async function detectInput(inputPath, platformOverride) {
|
|
397
|
+
const content = await loadContent(inputPath);
|
|
398
|
+
try {
|
|
399
|
+
JSON.parse(content);
|
|
400
|
+
return { type: "config", content };
|
|
401
|
+
} catch {
|
|
402
|
+
const platform = platformOverride ?? detectPlatformFromPath(inputPath);
|
|
403
|
+
return { type: "bundle", content, platform };
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function detectPlatformFromPath(inputPath) {
|
|
407
|
+
const cleanPath = inputPath.split("?")[0];
|
|
408
|
+
return cleanPath.endsWith(".mjs") ? "server" : "web";
|
|
409
|
+
}
|
|
410
|
+
async function loadContent(inputPath) {
|
|
411
|
+
if (isUrl(inputPath)) {
|
|
412
|
+
const response = await fetch(inputPath);
|
|
413
|
+
if (!response.ok) {
|
|
414
|
+
throw new Error(`Failed to fetch ${inputPath}: ${response.status}`);
|
|
415
|
+
}
|
|
416
|
+
return response.text();
|
|
417
|
+
}
|
|
418
|
+
return fs3.readFile(inputPath, "utf8");
|
|
419
|
+
}
|
|
420
|
+
|
|
377
421
|
// src/config/validators.ts
|
|
378
422
|
import { schemas } from "@walkeros/core/dev";
|
|
379
423
|
var { safeParseSetup } = schemas;
|
|
@@ -428,7 +472,7 @@ function getDefaultOutput(platform) {
|
|
|
428
472
|
|
|
429
473
|
// src/config/loader.ts
|
|
430
474
|
import path5 from "path";
|
|
431
|
-
import
|
|
475
|
+
import fs4 from "fs-extra";
|
|
432
476
|
import { getFlowConfig, getPlatform } from "@walkeros/core";
|
|
433
477
|
var DEFAULT_INCLUDE_FOLDER = "./shared";
|
|
434
478
|
function loadBundleConfig(rawConfig, options) {
|
|
@@ -449,7 +493,7 @@ function loadBundleConfig(rawConfig, options) {
|
|
|
449
493
|
let includes = setup.include;
|
|
450
494
|
if (!includes) {
|
|
451
495
|
const defaultIncludePath = path5.resolve(configDir, DEFAULT_INCLUDE_FOLDER);
|
|
452
|
-
if (
|
|
496
|
+
if (fs4.pathExistsSync(defaultIncludePath)) {
|
|
453
497
|
includes = [DEFAULT_INCLUDE_FOLDER];
|
|
454
498
|
}
|
|
455
499
|
}
|
|
@@ -508,17 +552,21 @@ function loadAllFlows(rawConfig, options) {
|
|
|
508
552
|
})
|
|
509
553
|
);
|
|
510
554
|
}
|
|
555
|
+
async function loadFlowConfig(configPath, options) {
|
|
556
|
+
const rawConfig = await loadJsonConfig(configPath);
|
|
557
|
+
return loadBundleConfig(rawConfig, { configPath, ...options });
|
|
558
|
+
}
|
|
511
559
|
|
|
512
560
|
// src/commands/bundle/bundler.ts
|
|
513
561
|
import esbuild from "esbuild";
|
|
514
562
|
import path8 from "path";
|
|
515
|
-
import
|
|
563
|
+
import fs7 from "fs-extra";
|
|
516
564
|
import { packageNameToVariable } from "@walkeros/core";
|
|
517
565
|
|
|
518
566
|
// src/commands/bundle/package-manager.ts
|
|
519
567
|
import pacote from "pacote";
|
|
520
568
|
import path6 from "path";
|
|
521
|
-
import
|
|
569
|
+
import fs5 from "fs-extra";
|
|
522
570
|
|
|
523
571
|
// src/core/cache-utils.ts
|
|
524
572
|
import { getHashServer } from "@walkeros/server-core";
|
|
@@ -568,7 +616,7 @@ async function getCachedPackagePath(pkg, tmpDir) {
|
|
|
568
616
|
}
|
|
569
617
|
async function isPackageCached(pkg, tmpDir) {
|
|
570
618
|
const cachedPath = await getCachedPackagePath(pkg, tmpDir);
|
|
571
|
-
return
|
|
619
|
+
return fs5.pathExists(cachedPath);
|
|
572
620
|
}
|
|
573
621
|
function validateNoDuplicatePackages(packages) {
|
|
574
622
|
const packageMap = /* @__PURE__ */ new Map();
|
|
@@ -603,8 +651,8 @@ async function resolveDependencies(pkg, packageDir, logger2, visited = /* @__PUR
|
|
|
603
651
|
visited.add(pkgKey);
|
|
604
652
|
try {
|
|
605
653
|
const packageJsonPath = path6.join(packageDir, "package.json");
|
|
606
|
-
if (await
|
|
607
|
-
const packageJson = await
|
|
654
|
+
if (await fs5.pathExists(packageJsonPath)) {
|
|
655
|
+
const packageJson = await fs5.readJson(packageJsonPath);
|
|
608
656
|
const deps = {
|
|
609
657
|
...packageJson.dependencies,
|
|
610
658
|
...packageJson.peerDependencies
|
|
@@ -632,7 +680,7 @@ async function downloadPackages(packages, targetDir, logger2, useCache = true, c
|
|
|
632
680
|
}
|
|
633
681
|
}
|
|
634
682
|
validateNoDuplicatePackages(packages);
|
|
635
|
-
await
|
|
683
|
+
await fs5.ensureDir(targetDir);
|
|
636
684
|
while (downloadQueue.length > 0) {
|
|
637
685
|
const pkg = downloadQueue.shift();
|
|
638
686
|
const pkgKey = `${pkg.name}@${pkg.version}`;
|
|
@@ -669,8 +717,8 @@ async function downloadPackages(packages, targetDir, logger2, useCache = true, c
|
|
|
669
717
|
logger2.debug(`Downloading ${packageSpec} (cached)`);
|
|
670
718
|
}
|
|
671
719
|
try {
|
|
672
|
-
await
|
|
673
|
-
await
|
|
720
|
+
await fs5.ensureDir(path6.dirname(packageDir));
|
|
721
|
+
await fs5.copy(cachedPath, packageDir);
|
|
674
722
|
packagePaths.set(pkg.name, packageDir);
|
|
675
723
|
const deps = await resolveDependencies(pkg, packageDir, logger2);
|
|
676
724
|
for (const dep of deps) {
|
|
@@ -687,7 +735,7 @@ async function downloadPackages(packages, targetDir, logger2, useCache = true, c
|
|
|
687
735
|
}
|
|
688
736
|
}
|
|
689
737
|
try {
|
|
690
|
-
await
|
|
738
|
+
await fs5.ensureDir(path6.dirname(packageDir));
|
|
691
739
|
const cacheDir = process.env.NPM_CACHE_DIR || getTmpPath(void 0, "cache", "npm");
|
|
692
740
|
await withTimeout(
|
|
693
741
|
pacote.extract(packageSpec, packageDir, {
|
|
@@ -704,15 +752,15 @@ async function downloadPackages(packages, targetDir, logger2, useCache = true, c
|
|
|
704
752
|
`Package download timed out after ${PACKAGE_DOWNLOAD_TIMEOUT_MS / 1e3}s: ${packageSpec}`
|
|
705
753
|
);
|
|
706
754
|
if (userSpecifiedPackages.has(pkg.name)) {
|
|
707
|
-
const pkgStats = await
|
|
755
|
+
const pkgStats = await fs5.stat(path6.join(packageDir, "package.json"));
|
|
708
756
|
const pkgJsonSize = pkgStats.size;
|
|
709
757
|
const sizeKB = (pkgJsonSize / 1024).toFixed(1);
|
|
710
758
|
logger2.debug(`Downloading ${packageSpec} (${sizeKB} KB)`);
|
|
711
759
|
}
|
|
712
760
|
if (useCache) {
|
|
713
761
|
try {
|
|
714
|
-
await
|
|
715
|
-
await
|
|
762
|
+
await fs5.ensureDir(path6.dirname(cachedPath));
|
|
763
|
+
await fs5.copy(packageDir, cachedPath);
|
|
716
764
|
} catch (cacheError) {
|
|
717
765
|
}
|
|
718
766
|
}
|
|
@@ -732,7 +780,7 @@ async function downloadPackages(packages, targetDir, logger2, useCache = true, c
|
|
|
732
780
|
}
|
|
733
781
|
|
|
734
782
|
// src/core/build-cache.ts
|
|
735
|
-
import
|
|
783
|
+
import fs6 from "fs-extra";
|
|
736
784
|
import path7 from "path";
|
|
737
785
|
async function getBuildCachePath(configContent, tmpDir) {
|
|
738
786
|
const cacheDir = getTmpPath(tmpDir, "cache", "builds");
|
|
@@ -741,17 +789,17 @@ async function getBuildCachePath(configContent, tmpDir) {
|
|
|
741
789
|
}
|
|
742
790
|
async function isBuildCached(configContent, tmpDir) {
|
|
743
791
|
const cachePath = await getBuildCachePath(configContent, tmpDir);
|
|
744
|
-
return
|
|
792
|
+
return fs6.pathExists(cachePath);
|
|
745
793
|
}
|
|
746
794
|
async function cacheBuild(configContent, buildOutput, tmpDir) {
|
|
747
795
|
const cachePath = await getBuildCachePath(configContent, tmpDir);
|
|
748
|
-
await
|
|
749
|
-
await
|
|
796
|
+
await fs6.ensureDir(path7.dirname(cachePath));
|
|
797
|
+
await fs6.writeFile(cachePath, buildOutput, "utf-8");
|
|
750
798
|
}
|
|
751
799
|
async function getCachedBuild(configContent, tmpDir) {
|
|
752
800
|
const cachePath = await getBuildCachePath(configContent, tmpDir);
|
|
753
|
-
if (await
|
|
754
|
-
return await
|
|
801
|
+
if (await fs6.pathExists(cachePath)) {
|
|
802
|
+
return await fs6.readFile(cachePath, "utf-8");
|
|
755
803
|
}
|
|
756
804
|
return null;
|
|
757
805
|
}
|
|
@@ -762,8 +810,8 @@ async function copyIncludes(includes, sourceDir, outputDir, logger2) {
|
|
|
762
810
|
const sourcePath = path8.resolve(sourceDir, include);
|
|
763
811
|
const folderName = path8.basename(include);
|
|
764
812
|
const destPath = path8.join(outputDir, folderName);
|
|
765
|
-
if (await
|
|
766
|
-
await
|
|
813
|
+
if (await fs7.pathExists(sourcePath)) {
|
|
814
|
+
await fs7.copy(sourcePath, destPath);
|
|
767
815
|
logger2.debug(`Copied ${include} to output`);
|
|
768
816
|
} else {
|
|
769
817
|
logger2.debug(`Include folder not found: ${include}`);
|
|
@@ -793,13 +841,13 @@ async function bundleCore(flowConfig, buildOptions, logger2, showStats = false)
|
|
|
793
841
|
if (cachedBuild) {
|
|
794
842
|
logger2.debug("Using cached build");
|
|
795
843
|
const outputPath = path8.resolve(buildOptions.output);
|
|
796
|
-
await
|
|
797
|
-
await
|
|
798
|
-
const stats = await
|
|
844
|
+
await fs7.ensureDir(path8.dirname(outputPath));
|
|
845
|
+
await fs7.writeFile(outputPath, cachedBuild);
|
|
846
|
+
const stats = await fs7.stat(outputPath);
|
|
799
847
|
const sizeKB = (stats.size / 1024).toFixed(1);
|
|
800
848
|
logger2.log(`Output: ${outputPath} (${sizeKB} KB, cached)`);
|
|
801
849
|
if (showStats) {
|
|
802
|
-
const stats2 = await
|
|
850
|
+
const stats2 = await fs7.stat(outputPath);
|
|
803
851
|
const packageStats = Object.entries(buildOptions.packages).map(
|
|
804
852
|
([name, pkg]) => ({
|
|
805
853
|
name: `${name}@${pkg.version || "latest"}`,
|
|
@@ -819,7 +867,7 @@ async function bundleCore(flowConfig, buildOptions, logger2, showStats = false)
|
|
|
819
867
|
}
|
|
820
868
|
}
|
|
821
869
|
try {
|
|
822
|
-
await
|
|
870
|
+
await fs7.ensureDir(TEMP_DIR);
|
|
823
871
|
logger2.debug("Downloading packages");
|
|
824
872
|
const packagesArray = Object.entries(buildOptions.packages).map(
|
|
825
873
|
([name, packageConfig]) => ({
|
|
@@ -840,7 +888,7 @@ async function bundleCore(flowConfig, buildOptions, logger2, showStats = false)
|
|
|
840
888
|
for (const [pkgName, pkgPath] of packagePaths.entries()) {
|
|
841
889
|
if (pkgName.startsWith("@walkeros/")) {
|
|
842
890
|
const pkgJsonPath = path8.join(pkgPath, "package.json");
|
|
843
|
-
const pkgJson = await
|
|
891
|
+
const pkgJson = await fs7.readJSON(pkgJsonPath);
|
|
844
892
|
if (!pkgJson.exports && pkgJson.module) {
|
|
845
893
|
pkgJson.exports = {
|
|
846
894
|
".": {
|
|
@@ -848,12 +896,12 @@ async function bundleCore(flowConfig, buildOptions, logger2, showStats = false)
|
|
|
848
896
|
require: pkgJson.main
|
|
849
897
|
}
|
|
850
898
|
};
|
|
851
|
-
await
|
|
899
|
+
await fs7.writeJSON(pkgJsonPath, pkgJson, { spaces: 2 });
|
|
852
900
|
}
|
|
853
901
|
}
|
|
854
902
|
}
|
|
855
903
|
const packageJsonPath = path8.join(TEMP_DIR, "package.json");
|
|
856
|
-
await
|
|
904
|
+
await fs7.writeFile(
|
|
857
905
|
packageJsonPath,
|
|
858
906
|
JSON.stringify({ type: "module" }, null, 2)
|
|
859
907
|
);
|
|
@@ -864,12 +912,12 @@ async function bundleCore(flowConfig, buildOptions, logger2, showStats = false)
|
|
|
864
912
|
packagePaths
|
|
865
913
|
);
|
|
866
914
|
const entryPath = path8.join(TEMP_DIR, "entry.js");
|
|
867
|
-
await
|
|
915
|
+
await fs7.writeFile(entryPath, entryContent);
|
|
868
916
|
logger2.debug(
|
|
869
917
|
`Running esbuild (target: ${buildOptions.target || "es2018"}, format: ${buildOptions.format})`
|
|
870
918
|
);
|
|
871
919
|
const outputPath = path8.resolve(buildOptions.output);
|
|
872
|
-
await
|
|
920
|
+
await fs7.ensureDir(path8.dirname(outputPath));
|
|
873
921
|
const esbuildOptions = createEsbuildOptions(
|
|
874
922
|
buildOptions,
|
|
875
923
|
entryPath,
|
|
@@ -886,13 +934,13 @@ async function bundleCore(flowConfig, buildOptions, logger2, showStats = false)
|
|
|
886
934
|
buildOptions.code || ""
|
|
887
935
|
);
|
|
888
936
|
}
|
|
889
|
-
const outputStats = await
|
|
937
|
+
const outputStats = await fs7.stat(outputPath);
|
|
890
938
|
const sizeKB = (outputStats.size / 1024).toFixed(1);
|
|
891
939
|
const buildTime = ((Date.now() - bundleStartTime) / 1e3).toFixed(1);
|
|
892
940
|
logger2.log(`Output: ${outputPath} (${sizeKB} KB, ${buildTime}s)`);
|
|
893
941
|
if (buildOptions.cache !== false) {
|
|
894
942
|
const configContent = generateCacheKeyContent(flowConfig, buildOptions);
|
|
895
|
-
const buildOutput = await
|
|
943
|
+
const buildOutput = await fs7.readFile(outputPath, "utf-8");
|
|
896
944
|
await cacheBuild(configContent, buildOutput);
|
|
897
945
|
logger2.debug("Build cached for future use");
|
|
898
946
|
}
|
|
@@ -920,7 +968,7 @@ async function bundleCore(flowConfig, buildOptions, logger2, showStats = false)
|
|
|
920
968
|
}
|
|
921
969
|
}
|
|
922
970
|
async function collectBundleStats(outputPath, packages, startTime, entryContent) {
|
|
923
|
-
const stats = await
|
|
971
|
+
const stats = await fs7.stat(outputPath);
|
|
924
972
|
const totalSize = stats.size;
|
|
925
973
|
const buildTime = Date.now() - startTime;
|
|
926
974
|
const packageStats = Object.entries(packages).map(([name, pkg]) => {
|
|
@@ -1248,6 +1296,11 @@ function generatePlatformWrapper(configObject, userCode, buildOptions) {
|
|
|
1248
1296
|
` : "";
|
|
1249
1297
|
return `export default async function(context = {}) {
|
|
1250
1298
|
const config = ${configObject};${codeSection}
|
|
1299
|
+
// Apply context overrides (e.g., logger config from CLI)
|
|
1300
|
+
if (context.logger) {
|
|
1301
|
+
config.logger = { ...config.logger, ...context.logger };
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1251
1304
|
return await startFlow(config);
|
|
1252
1305
|
}`;
|
|
1253
1306
|
}
|
|
@@ -1415,7 +1468,7 @@ async function bundle(configOrPath, options = {}) {
|
|
|
1415
1468
|
|
|
1416
1469
|
// src/commands/simulate/simulator.ts
|
|
1417
1470
|
import path10 from "path";
|
|
1418
|
-
import
|
|
1471
|
+
import fs9 from "fs-extra";
|
|
1419
1472
|
import { getPlatform as getPlatform2 } from "@walkeros/core";
|
|
1420
1473
|
|
|
1421
1474
|
// src/commands/simulate/tracker.ts
|
|
@@ -1498,7 +1551,7 @@ var CallTracker = class {
|
|
|
1498
1551
|
|
|
1499
1552
|
// src/commands/simulate/jsdom-executor.ts
|
|
1500
1553
|
import { JSDOM, VirtualConsole } from "jsdom";
|
|
1501
|
-
import
|
|
1554
|
+
import fs8 from "fs-extra";
|
|
1502
1555
|
function buildSandboxFromEnvs(envs, destinations, tracker) {
|
|
1503
1556
|
const baseBrowserMocks = {
|
|
1504
1557
|
Image: class MockImage {
|
|
@@ -1567,7 +1620,7 @@ async function executeInJSDOM(bundlePath, destinations, event, tracker, envs, ti
|
|
|
1567
1620
|
const sandbox = buildSandboxFromEnvs(envs, destinations, tracker);
|
|
1568
1621
|
Object.assign(window, sandbox.window);
|
|
1569
1622
|
Object.assign(window.document, sandbox.document);
|
|
1570
|
-
const bundleCode = await
|
|
1623
|
+
const bundleCode = await fs8.readFile(bundlePath, "utf8");
|
|
1571
1624
|
try {
|
|
1572
1625
|
window.eval(bundleCode);
|
|
1573
1626
|
} catch (error) {
|
|
@@ -1638,7 +1691,7 @@ function injectGlobalMocks(mocks) {
|
|
|
1638
1691
|
}
|
|
1639
1692
|
};
|
|
1640
1693
|
}
|
|
1641
|
-
async function executeInNode(bundlePath, destinations, event, tracker, envs, timeout = 3e4) {
|
|
1694
|
+
async function executeInNode(bundlePath, destinations, event, tracker, envs, timeout = 3e4, context = {}) {
|
|
1642
1695
|
const start = Date.now();
|
|
1643
1696
|
const globalMocks = buildGlobalMocksFromEnvs(envs, destinations, tracker);
|
|
1644
1697
|
const cleanupMocks = injectGlobalMocks(globalMocks);
|
|
@@ -1649,16 +1702,19 @@ async function executeInNode(bundlePath, destinations, event, tracker, envs, tim
|
|
|
1649
1702
|
if (!module.default || typeof module.default !== "function") {
|
|
1650
1703
|
throw new Error("Bundle does not export default factory function");
|
|
1651
1704
|
}
|
|
1652
|
-
const result = await module.default();
|
|
1653
|
-
if (!result || !result.
|
|
1705
|
+
const result = await module.default(context);
|
|
1706
|
+
if (!result || !result.collector || typeof result.collector.push !== "function") {
|
|
1654
1707
|
throw new Error(
|
|
1655
|
-
"Factory function did not return valid result with
|
|
1708
|
+
"Factory function did not return valid result with collector"
|
|
1656
1709
|
);
|
|
1657
1710
|
}
|
|
1658
1711
|
const { collector, elb } = result;
|
|
1659
1712
|
let elbResult;
|
|
1660
1713
|
try {
|
|
1661
|
-
elbResult = await
|
|
1714
|
+
elbResult = await collector.push({
|
|
1715
|
+
name: event.name,
|
|
1716
|
+
data: event.data
|
|
1717
|
+
});
|
|
1662
1718
|
} catch (error) {
|
|
1663
1719
|
throw new Error(`Event execution failed: ${getErrorMessage(error)}`);
|
|
1664
1720
|
}
|
|
@@ -1716,29 +1772,21 @@ async function loadDestinationEnvs(destinations) {
|
|
|
1716
1772
|
function generateId() {
|
|
1717
1773
|
return `${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
|
|
1718
1774
|
}
|
|
1719
|
-
async function simulateCore(
|
|
1775
|
+
async function simulateCore(inputPath, event, options = {}) {
|
|
1720
1776
|
const logger2 = createLogger({
|
|
1721
1777
|
verbose: options.verbose || false,
|
|
1722
1778
|
silent: options.silent || false,
|
|
1723
1779
|
json: options.json || false
|
|
1724
1780
|
});
|
|
1725
1781
|
try {
|
|
1726
|
-
logger2.
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
logger2.info(`\u{1F680} Executing simulation with event: ${JSON.stringify(event)}`);
|
|
1732
|
-
const result = await executeSimulation(event, fullConfigPath);
|
|
1733
|
-
if (result.success) {
|
|
1734
|
-
logger2.info(`\u2705 Simulation completed successfully`);
|
|
1735
|
-
} else {
|
|
1736
|
-
logger2.error(`\u274C Simulation failed: ${result.error}`);
|
|
1737
|
-
}
|
|
1782
|
+
logger2.debug(`Simulating event: ${JSON.stringify(event)}`);
|
|
1783
|
+
const result = await executeSimulation(event, inputPath, options.platform, {
|
|
1784
|
+
logger: logger2,
|
|
1785
|
+
verbose: options.verbose
|
|
1786
|
+
});
|
|
1738
1787
|
return result;
|
|
1739
1788
|
} catch (error) {
|
|
1740
1789
|
const errorMessage = getErrorMessage(error);
|
|
1741
|
-
logger2.error(`\u{1F4A5} Simulation error: ${errorMessage}`);
|
|
1742
1790
|
return {
|
|
1743
1791
|
success: false,
|
|
1744
1792
|
error: errorMessage
|
|
@@ -1755,87 +1803,43 @@ function formatSimulationResult(result, options = {}) {
|
|
|
1755
1803
|
return JSON.stringify(output, null, 2);
|
|
1756
1804
|
}
|
|
1757
1805
|
if (result.success) {
|
|
1758
|
-
return "
|
|
1806
|
+
return "Simulation completed";
|
|
1759
1807
|
} else {
|
|
1760
|
-
return
|
|
1808
|
+
return `Simulation failed: ${result.error}`;
|
|
1761
1809
|
}
|
|
1762
1810
|
}
|
|
1763
|
-
async function executeSimulation(event,
|
|
1811
|
+
async function executeSimulation(event, inputPath, platformOverride, options = {}) {
|
|
1764
1812
|
const startTime = Date.now();
|
|
1765
|
-
let bundlePath;
|
|
1766
1813
|
const tempDir = getTmpPath();
|
|
1814
|
+
const collectorLoggerConfig = options.logger ? createCollectorLoggerConfig(options.logger, options.verbose) : void 0;
|
|
1767
1815
|
try {
|
|
1816
|
+
await fs9.ensureDir(tempDir);
|
|
1817
|
+
const detected = await detectInput(inputPath, platformOverride);
|
|
1768
1818
|
if (!isObject(event) || !("name" in event) || typeof event.name !== "string") {
|
|
1769
1819
|
throw new Error(
|
|
1770
1820
|
'Event must be an object with a "name" property of type string'
|
|
1771
1821
|
);
|
|
1772
1822
|
}
|
|
1773
1823
|
const typedEvent = event;
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
});
|
|
1779
|
-
const platform = getPlatform2(flowConfig);
|
|
1780
|
-
const tracker = new CallTracker();
|
|
1781
|
-
const tempOutput = path10.join(
|
|
1782
|
-
tempDir,
|
|
1783
|
-
`simulation-bundle-${generateId()}.${platform === "web" ? "js" : "mjs"}`
|
|
1784
|
-
);
|
|
1785
|
-
const destinations = flowConfig.destinations;
|
|
1786
|
-
const simulationBuildOptions = {
|
|
1787
|
-
...buildOptions,
|
|
1788
|
-
code: buildOptions.code || "",
|
|
1789
|
-
output: tempOutput,
|
|
1790
|
-
tempDir,
|
|
1791
|
-
...platform === "web" ? {
|
|
1792
|
-
format: "iife",
|
|
1793
|
-
platform: "browser",
|
|
1794
|
-
windowCollector: "collector",
|
|
1795
|
-
windowElb: "elb"
|
|
1796
|
-
} : {
|
|
1797
|
-
format: "esm",
|
|
1798
|
-
platform: "node"
|
|
1799
|
-
}
|
|
1800
|
-
};
|
|
1801
|
-
await bundleCore(
|
|
1802
|
-
flowConfig,
|
|
1803
|
-
simulationBuildOptions,
|
|
1804
|
-
createLogger({ silent: true }),
|
|
1805
|
-
false
|
|
1806
|
-
);
|
|
1807
|
-
bundlePath = tempOutput;
|
|
1808
|
-
const envs = await loadDestinationEnvs(destinations || {});
|
|
1809
|
-
let result;
|
|
1810
|
-
if (platform === "web") {
|
|
1811
|
-
result = await executeInJSDOM(
|
|
1812
|
-
tempOutput,
|
|
1813
|
-
destinations || {},
|
|
1824
|
+
if (detected.type === "config") {
|
|
1825
|
+
return await executeConfigSimulation(
|
|
1826
|
+
detected.content,
|
|
1827
|
+
inputPath,
|
|
1814
1828
|
typedEvent,
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1829
|
+
tempDir,
|
|
1830
|
+
startTime,
|
|
1831
|
+
collectorLoggerConfig
|
|
1818
1832
|
);
|
|
1819
1833
|
} else {
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1834
|
+
return await executeBundleSimulation(
|
|
1835
|
+
detected.content,
|
|
1836
|
+
detected.platform,
|
|
1823
1837
|
typedEvent,
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1838
|
+
tempDir,
|
|
1839
|
+
startTime,
|
|
1840
|
+
collectorLoggerConfig
|
|
1827
1841
|
);
|
|
1828
1842
|
}
|
|
1829
|
-
const elbResult = result.elbResult;
|
|
1830
|
-
const usage = result.usage;
|
|
1831
|
-
const duration = Date.now() - startTime;
|
|
1832
|
-
return {
|
|
1833
|
-
success: true,
|
|
1834
|
-
elbResult,
|
|
1835
|
-
usage,
|
|
1836
|
-
duration,
|
|
1837
|
-
logs: []
|
|
1838
|
-
};
|
|
1839
1843
|
} catch (error) {
|
|
1840
1844
|
const duration = Date.now() - startTime;
|
|
1841
1845
|
return {
|
|
@@ -1845,11 +1849,109 @@ async function executeSimulation(event, configPath) {
|
|
|
1845
1849
|
};
|
|
1846
1850
|
} finally {
|
|
1847
1851
|
if (tempDir) {
|
|
1848
|
-
await
|
|
1852
|
+
await fs9.remove(tempDir).catch(() => {
|
|
1849
1853
|
});
|
|
1850
1854
|
}
|
|
1851
1855
|
}
|
|
1852
1856
|
}
|
|
1857
|
+
async function executeConfigSimulation(_content, configPath, typedEvent, tempDir, startTime, loggerConfig2) {
|
|
1858
|
+
const { flowConfig, buildOptions } = await loadFlowConfig(configPath);
|
|
1859
|
+
const platform = getPlatform2(flowConfig);
|
|
1860
|
+
const tracker = new CallTracker();
|
|
1861
|
+
const tempOutput = path10.join(
|
|
1862
|
+
tempDir,
|
|
1863
|
+
`simulation-bundle-${generateId()}.${platform === "web" ? "js" : "mjs"}`
|
|
1864
|
+
);
|
|
1865
|
+
const destinations = flowConfig.destinations;
|
|
1866
|
+
const simulationBuildOptions = {
|
|
1867
|
+
...buildOptions,
|
|
1868
|
+
code: buildOptions.code || "",
|
|
1869
|
+
output: tempOutput,
|
|
1870
|
+
tempDir,
|
|
1871
|
+
...platform === "web" ? {
|
|
1872
|
+
format: "iife",
|
|
1873
|
+
platform: "browser",
|
|
1874
|
+
windowCollector: "collector",
|
|
1875
|
+
windowElb: "elb"
|
|
1876
|
+
} : {
|
|
1877
|
+
format: "esm",
|
|
1878
|
+
platform: "node"
|
|
1879
|
+
}
|
|
1880
|
+
};
|
|
1881
|
+
await bundleCore(
|
|
1882
|
+
flowConfig,
|
|
1883
|
+
simulationBuildOptions,
|
|
1884
|
+
createLogger({ silent: true }),
|
|
1885
|
+
false
|
|
1886
|
+
);
|
|
1887
|
+
const envs = await loadDestinationEnvs(destinations || {});
|
|
1888
|
+
let result;
|
|
1889
|
+
if (platform === "web") {
|
|
1890
|
+
result = await executeInJSDOM(
|
|
1891
|
+
tempOutput,
|
|
1892
|
+
destinations || {},
|
|
1893
|
+
typedEvent,
|
|
1894
|
+
tracker,
|
|
1895
|
+
envs,
|
|
1896
|
+
1e4
|
|
1897
|
+
);
|
|
1898
|
+
} else {
|
|
1899
|
+
result = await executeInNode(
|
|
1900
|
+
tempOutput,
|
|
1901
|
+
destinations || {},
|
|
1902
|
+
typedEvent,
|
|
1903
|
+
tracker,
|
|
1904
|
+
envs,
|
|
1905
|
+
3e4,
|
|
1906
|
+
loggerConfig2 ? { logger: loggerConfig2 } : {}
|
|
1907
|
+
);
|
|
1908
|
+
}
|
|
1909
|
+
const duration = Date.now() - startTime;
|
|
1910
|
+
return {
|
|
1911
|
+
success: true,
|
|
1912
|
+
elbResult: result.elbResult,
|
|
1913
|
+
usage: result.usage,
|
|
1914
|
+
duration,
|
|
1915
|
+
logs: []
|
|
1916
|
+
};
|
|
1917
|
+
}
|
|
1918
|
+
async function executeBundleSimulation(bundleContent, platform, typedEvent, tempDir, startTime, loggerConfig2) {
|
|
1919
|
+
const tempOutput = path10.join(
|
|
1920
|
+
tempDir,
|
|
1921
|
+
`bundle-${generateId()}.${platform === "server" ? "mjs" : "js"}`
|
|
1922
|
+
);
|
|
1923
|
+
await fs9.writeFile(tempOutput, bundleContent, "utf8");
|
|
1924
|
+
const tracker = new CallTracker();
|
|
1925
|
+
let result;
|
|
1926
|
+
if (platform === "web") {
|
|
1927
|
+
result = await executeInJSDOM(
|
|
1928
|
+
tempOutput,
|
|
1929
|
+
{},
|
|
1930
|
+
typedEvent,
|
|
1931
|
+
tracker,
|
|
1932
|
+
{},
|
|
1933
|
+
1e4
|
|
1934
|
+
);
|
|
1935
|
+
} else {
|
|
1936
|
+
result = await executeInNode(
|
|
1937
|
+
tempOutput,
|
|
1938
|
+
{},
|
|
1939
|
+
typedEvent,
|
|
1940
|
+
tracker,
|
|
1941
|
+
{},
|
|
1942
|
+
3e4,
|
|
1943
|
+
loggerConfig2 ? { logger: loggerConfig2 } : {}
|
|
1944
|
+
);
|
|
1945
|
+
}
|
|
1946
|
+
const duration = Date.now() - startTime;
|
|
1947
|
+
return {
|
|
1948
|
+
success: true,
|
|
1949
|
+
elbResult: result.elbResult,
|
|
1950
|
+
usage: result.usage,
|
|
1951
|
+
duration,
|
|
1952
|
+
logs: []
|
|
1953
|
+
};
|
|
1954
|
+
}
|
|
1853
1955
|
|
|
1854
1956
|
// src/commands/simulate/index.ts
|
|
1855
1957
|
async function simulateCommand(options) {
|
|
@@ -1914,12 +2016,15 @@ async function simulate(configOrPath, event, options = {}) {
|
|
|
1914
2016
|
// src/commands/push/index.ts
|
|
1915
2017
|
import path11 from "path";
|
|
1916
2018
|
import { JSDOM as JSDOM2, VirtualConsole as VirtualConsole2 } from "jsdom";
|
|
1917
|
-
import
|
|
1918
|
-
import {
|
|
2019
|
+
import fs10 from "fs-extra";
|
|
2020
|
+
import {
|
|
2021
|
+
getPlatform as getPlatform3
|
|
2022
|
+
} from "@walkeros/core";
|
|
1919
2023
|
import { schemas as schemas2 } from "@walkeros/core/dev";
|
|
1920
2024
|
async function pushCommand(options) {
|
|
1921
2025
|
const logger2 = createCommandLogger(options);
|
|
1922
2026
|
const startTime = Date.now();
|
|
2027
|
+
let tempDir;
|
|
1923
2028
|
try {
|
|
1924
2029
|
logger2.debug("Loading event");
|
|
1925
2030
|
const event = await loadJsonFromSource(options.event, {
|
|
@@ -1943,49 +2048,33 @@ async function pushCommand(options) {
|
|
|
1943
2048
|
`Warning: Event name "${validatedEvent.name}" should follow "ENTITY ACTION" format (e.g., "page view")`
|
|
1944
2049
|
);
|
|
1945
2050
|
}
|
|
1946
|
-
logger2.debug("
|
|
1947
|
-
const
|
|
1948
|
-
const rawConfig = await loadJsonConfig(configPath);
|
|
1949
|
-
const { flowConfig, buildOptions, flowName, isMultiFlow } = loadBundleConfig(rawConfig, {
|
|
1950
|
-
configPath: options.config,
|
|
1951
|
-
flowName: options.flow,
|
|
1952
|
-
logger: logger2
|
|
1953
|
-
});
|
|
1954
|
-
const platform = getPlatform3(flowConfig);
|
|
1955
|
-
logger2.debug("Bundling flow configuration");
|
|
1956
|
-
const configDir = path11.dirname(configPath);
|
|
1957
|
-
const tempDir = path11.join(
|
|
1958
|
-
configDir,
|
|
1959
|
-
".tmp",
|
|
1960
|
-
`push-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
|
1961
|
-
);
|
|
1962
|
-
await fs9.ensureDir(tempDir);
|
|
1963
|
-
const tempPath = path11.join(
|
|
1964
|
-
tempDir,
|
|
1965
|
-
`bundle.${platform === "web" ? "js" : "mjs"}`
|
|
1966
|
-
);
|
|
1967
|
-
const pushBuildOptions = {
|
|
1968
|
-
...buildOptions,
|
|
1969
|
-
output: tempPath,
|
|
1970
|
-
// Web uses IIFE for browser-like execution, server uses ESM
|
|
1971
|
-
format: platform === "web" ? "iife" : "esm",
|
|
1972
|
-
platform: platform === "web" ? "browser" : "node",
|
|
1973
|
-
...platform === "web" && {
|
|
1974
|
-
windowCollector: "collector",
|
|
1975
|
-
windowElb: "elb"
|
|
1976
|
-
}
|
|
1977
|
-
};
|
|
1978
|
-
await bundleCore(flowConfig, pushBuildOptions, logger2, false);
|
|
1979
|
-
logger2.debug(`Bundle created: ${tempPath}`);
|
|
2051
|
+
logger2.debug("Detecting input type");
|
|
2052
|
+
const detected = await detectInput(options.config, options.platform);
|
|
1980
2053
|
let result;
|
|
1981
|
-
if (
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
2054
|
+
if (detected.type === "config") {
|
|
2055
|
+
result = await executeConfigPush(
|
|
2056
|
+
options,
|
|
2057
|
+
validatedEvent,
|
|
2058
|
+
logger2,
|
|
2059
|
+
(dir) => {
|
|
2060
|
+
tempDir = dir;
|
|
2061
|
+
}
|
|
2062
|
+
);
|
|
1987
2063
|
} else {
|
|
1988
|
-
|
|
2064
|
+
const collectorLoggerConfig = createCollectorLoggerConfig(
|
|
2065
|
+
logger2,
|
|
2066
|
+
options.verbose
|
|
2067
|
+
);
|
|
2068
|
+
result = await executeBundlePush(
|
|
2069
|
+
detected.content,
|
|
2070
|
+
detected.platform,
|
|
2071
|
+
validatedEvent,
|
|
2072
|
+
logger2,
|
|
2073
|
+
(dir) => {
|
|
2074
|
+
tempDir = dir;
|
|
2075
|
+
},
|
|
2076
|
+
{ logger: collectorLoggerConfig }
|
|
2077
|
+
);
|
|
1989
2078
|
}
|
|
1990
2079
|
const duration = Date.now() - startTime;
|
|
1991
2080
|
if (options.json) {
|
|
@@ -2015,10 +2104,6 @@ async function pushCommand(options) {
|
|
|
2015
2104
|
process.exit(1);
|
|
2016
2105
|
}
|
|
2017
2106
|
}
|
|
2018
|
-
try {
|
|
2019
|
-
await fs9.remove(tempDir);
|
|
2020
|
-
} catch {
|
|
2021
|
-
}
|
|
2022
2107
|
} catch (error) {
|
|
2023
2108
|
const duration = Date.now() - startTime;
|
|
2024
2109
|
const errorMessage = getErrorMessage(error);
|
|
@@ -2032,6 +2117,81 @@ async function pushCommand(options) {
|
|
|
2032
2117
|
logger2.error(`Error: ${errorMessage}`);
|
|
2033
2118
|
}
|
|
2034
2119
|
process.exit(1);
|
|
2120
|
+
} finally {
|
|
2121
|
+
if (tempDir) {
|
|
2122
|
+
await fs10.remove(tempDir).catch(() => {
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
async function executeConfigPush(options, validatedEvent, logger2, setTempDir) {
|
|
2128
|
+
logger2.debug("Loading flow configuration");
|
|
2129
|
+
const { flowConfig, buildOptions } = await loadFlowConfig(options.config, {
|
|
2130
|
+
flowName: options.flow,
|
|
2131
|
+
logger: logger2
|
|
2132
|
+
});
|
|
2133
|
+
const platform = getPlatform3(flowConfig);
|
|
2134
|
+
logger2.debug("Bundling flow configuration");
|
|
2135
|
+
const configDir = buildOptions.configDir || process.cwd();
|
|
2136
|
+
const tempDir = path11.join(
|
|
2137
|
+
configDir,
|
|
2138
|
+
".tmp",
|
|
2139
|
+
`push-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
|
2140
|
+
);
|
|
2141
|
+
setTempDir(tempDir);
|
|
2142
|
+
await fs10.ensureDir(tempDir);
|
|
2143
|
+
const tempPath = path11.join(
|
|
2144
|
+
tempDir,
|
|
2145
|
+
`bundle.${platform === "web" ? "js" : "mjs"}`
|
|
2146
|
+
);
|
|
2147
|
+
const pushBuildOptions = {
|
|
2148
|
+
...buildOptions,
|
|
2149
|
+
output: tempPath,
|
|
2150
|
+
format: platform === "web" ? "iife" : "esm",
|
|
2151
|
+
platform: platform === "web" ? "browser" : "node",
|
|
2152
|
+
...platform === "web" && {
|
|
2153
|
+
windowCollector: "collector",
|
|
2154
|
+
windowElb: "elb"
|
|
2155
|
+
}
|
|
2156
|
+
};
|
|
2157
|
+
await bundleCore(flowConfig, pushBuildOptions, logger2, false);
|
|
2158
|
+
logger2.debug(`Bundle created: ${tempPath}`);
|
|
2159
|
+
if (platform === "web") {
|
|
2160
|
+
logger2.debug("Executing in web environment (JSDOM)");
|
|
2161
|
+
return executeWebPush(tempPath, validatedEvent, logger2);
|
|
2162
|
+
} else if (platform === "server") {
|
|
2163
|
+
logger2.debug("Executing in server environment (Node.js)");
|
|
2164
|
+
const collectorLoggerConfig = createCollectorLoggerConfig(
|
|
2165
|
+
logger2,
|
|
2166
|
+
options.verbose
|
|
2167
|
+
);
|
|
2168
|
+
return executeServerPush(tempPath, validatedEvent, logger2, 6e4, {
|
|
2169
|
+
logger: collectorLoggerConfig
|
|
2170
|
+
});
|
|
2171
|
+
} else {
|
|
2172
|
+
throw new Error(`Unsupported platform: ${platform}`);
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
async function executeBundlePush(bundleContent, platform, validatedEvent, logger2, setTempDir, context = {}) {
|
|
2176
|
+
const tempDir = path11.join(
|
|
2177
|
+
process.cwd(),
|
|
2178
|
+
".tmp",
|
|
2179
|
+
`push-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
|
2180
|
+
);
|
|
2181
|
+
setTempDir(tempDir);
|
|
2182
|
+
await fs10.ensureDir(tempDir);
|
|
2183
|
+
const tempPath = path11.join(
|
|
2184
|
+
tempDir,
|
|
2185
|
+
`bundle.${platform === "server" ? "mjs" : "js"}`
|
|
2186
|
+
);
|
|
2187
|
+
await fs10.writeFile(tempPath, bundleContent, "utf8");
|
|
2188
|
+
logger2.debug(`Bundle written to: ${tempPath}`);
|
|
2189
|
+
if (platform === "web") {
|
|
2190
|
+
logger2.debug("Executing in web environment (JSDOM)");
|
|
2191
|
+
return executeWebPush(tempPath, validatedEvent, logger2);
|
|
2192
|
+
} else {
|
|
2193
|
+
logger2.debug("Executing in server environment (Node.js)");
|
|
2194
|
+
return executeServerPush(tempPath, validatedEvent, logger2, 6e4, context);
|
|
2035
2195
|
}
|
|
2036
2196
|
}
|
|
2037
2197
|
async function executeWebPush(bundlePath, event, logger2) {
|
|
@@ -2046,18 +2206,21 @@ async function executeWebPush(bundlePath, event, logger2) {
|
|
|
2046
2206
|
});
|
|
2047
2207
|
const { window } = dom;
|
|
2048
2208
|
logger2.debug("Loading bundle...");
|
|
2049
|
-
const bundleCode = await
|
|
2209
|
+
const bundleCode = await fs10.readFile(bundlePath, "utf8");
|
|
2050
2210
|
window.eval(bundleCode);
|
|
2051
|
-
logger2.debug("Waiting for
|
|
2211
|
+
logger2.debug("Waiting for collector...");
|
|
2052
2212
|
await waitForWindowProperty2(
|
|
2053
2213
|
window,
|
|
2054
|
-
"
|
|
2214
|
+
"collector",
|
|
2055
2215
|
5e3
|
|
2056
2216
|
);
|
|
2057
2217
|
const windowObj = window;
|
|
2058
|
-
const
|
|
2218
|
+
const collector = windowObj.collector;
|
|
2059
2219
|
logger2.log(`Pushing event: ${event.name}`);
|
|
2060
|
-
const elbResult = await
|
|
2220
|
+
const elbResult = await collector.push({
|
|
2221
|
+
name: event.name,
|
|
2222
|
+
data: event.data
|
|
2223
|
+
});
|
|
2061
2224
|
return {
|
|
2062
2225
|
success: true,
|
|
2063
2226
|
elbResult,
|
|
@@ -2071,7 +2234,7 @@ async function executeWebPush(bundlePath, event, logger2) {
|
|
|
2071
2234
|
};
|
|
2072
2235
|
}
|
|
2073
2236
|
}
|
|
2074
|
-
async function executeServerPush(bundlePath, event, logger2, timeout = 6e4) {
|
|
2237
|
+
async function executeServerPush(bundlePath, event, logger2, timeout = 6e4, context = {}) {
|
|
2075
2238
|
const startTime = Date.now();
|
|
2076
2239
|
try {
|
|
2077
2240
|
const timeoutPromise = new Promise((_, reject) => {
|
|
@@ -2087,15 +2250,18 @@ async function executeServerPush(bundlePath, event, logger2, timeout = 6e4) {
|
|
|
2087
2250
|
throw new Error("Bundle does not export default factory function");
|
|
2088
2251
|
}
|
|
2089
2252
|
logger2.debug("Calling factory function...");
|
|
2090
|
-
const result = await flowModule.default();
|
|
2091
|
-
if (!result || !result.
|
|
2253
|
+
const result = await flowModule.default(context);
|
|
2254
|
+
if (!result || !result.collector || typeof result.collector.push !== "function") {
|
|
2092
2255
|
throw new Error(
|
|
2093
|
-
"Factory function did not return valid result with
|
|
2256
|
+
"Factory function did not return valid result with collector"
|
|
2094
2257
|
);
|
|
2095
2258
|
}
|
|
2096
|
-
const {
|
|
2259
|
+
const { collector } = result;
|
|
2097
2260
|
logger2.log(`Pushing event: ${event.name}`);
|
|
2098
|
-
const elbResult = await
|
|
2261
|
+
const elbResult = await collector.push({
|
|
2262
|
+
name: event.name,
|
|
2263
|
+
data: event.data
|
|
2264
|
+
});
|
|
2099
2265
|
return {
|
|
2100
2266
|
success: true,
|
|
2101
2267
|
elbResult,
|
|
@@ -2187,7 +2353,7 @@ function validatePort(port) {
|
|
|
2187
2353
|
|
|
2188
2354
|
// src/commands/run/utils.ts
|
|
2189
2355
|
import path12 from "path";
|
|
2190
|
-
import
|
|
2356
|
+
import fs11 from "fs-extra";
|
|
2191
2357
|
async function prepareBundleForRun(configPath, options) {
|
|
2192
2358
|
const configDir = path12.dirname(path12.resolve(configPath));
|
|
2193
2359
|
const tempDir = path12.join(
|
|
@@ -2195,7 +2361,7 @@ async function prepareBundleForRun(configPath, options) {
|
|
|
2195
2361
|
".tmp",
|
|
2196
2362
|
`run-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
|
2197
2363
|
);
|
|
2198
|
-
await
|
|
2364
|
+
await fs11.ensureDir(tempDir);
|
|
2199
2365
|
const tempPath = path12.join(tempDir, "bundle.mjs");
|
|
2200
2366
|
await bundle(configPath, {
|
|
2201
2367
|
cache: true,
|
|
@@ -2219,7 +2385,7 @@ import { createLogger as createLogger2, Level } from "@walkeros/core";
|
|
|
2219
2385
|
// src/runtime/runner.ts
|
|
2220
2386
|
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
2221
2387
|
import { resolve, dirname as dirname2 } from "path";
|
|
2222
|
-
async function runFlow(file, config, logger2) {
|
|
2388
|
+
async function runFlow(file, config, logger2, loggerConfig2) {
|
|
2223
2389
|
logger2.info(`Loading flow from ${file}`);
|
|
2224
2390
|
try {
|
|
2225
2391
|
const absolutePath = resolve(file);
|
|
@@ -2232,7 +2398,8 @@ async function runFlow(file, config, logger2) {
|
|
|
2232
2398
|
`Invalid flow bundle: ${file} must export a default function`
|
|
2233
2399
|
);
|
|
2234
2400
|
}
|
|
2235
|
-
const
|
|
2401
|
+
const flowContext = loggerConfig2 ? { ...config, logger: loggerConfig2 } : config;
|
|
2402
|
+
const result = await module.default(flowContext);
|
|
2236
2403
|
if (!result || !result.collector) {
|
|
2237
2404
|
logger2.throw(`Invalid flow bundle: ${file} must return { collector }`);
|
|
2238
2405
|
}
|
|
@@ -2338,7 +2505,8 @@ async function runServeMode(config, logger2) {
|
|
|
2338
2505
|
|
|
2339
2506
|
// src/commands/run/execution.ts
|
|
2340
2507
|
var logLevel = process.env.VERBOSE === "true" ? Level.DEBUG : Level.INFO;
|
|
2341
|
-
var
|
|
2508
|
+
var loggerConfig = { level: logLevel };
|
|
2509
|
+
var logger = createLogger2(loggerConfig);
|
|
2342
2510
|
async function executeRunLocal(mode, flowPath, options) {
|
|
2343
2511
|
switch (mode) {
|
|
2344
2512
|
case "collect": {
|
|
@@ -2349,7 +2517,7 @@ async function executeRunLocal(mode, flowPath, options) {
|
|
|
2349
2517
|
port: options.port,
|
|
2350
2518
|
host: options.host
|
|
2351
2519
|
};
|
|
2352
|
-
await runFlow(flowPath, config, logger.scope("runner"));
|
|
2520
|
+
await runFlow(flowPath, config, logger.scope("runner"), loggerConfig);
|
|
2353
2521
|
break;
|
|
2354
2522
|
}
|
|
2355
2523
|
case "serve": {
|
|
@@ -2467,20 +2635,20 @@ async function run(mode, options) {
|
|
|
2467
2635
|
}
|
|
2468
2636
|
|
|
2469
2637
|
// src/commands/cache.ts
|
|
2470
|
-
import
|
|
2638
|
+
import fs12 from "fs-extra";
|
|
2471
2639
|
function registerCacheCommand(program2) {
|
|
2472
2640
|
const cache = program2.command("cache").description("Manage the CLI cache");
|
|
2473
2641
|
cache.command("clear").description("Clear all cached packages and builds").option("--packages", "Clear only package cache").option("--builds", "Clear only build cache").option("--tmp-dir <dir>", "Custom temp directory").option("--silent", "Suppress output").action(async (options) => {
|
|
2474
2642
|
const logger2 = createLogger({ silent: options.silent });
|
|
2475
2643
|
const tmpDir = options.tmpDir;
|
|
2476
2644
|
if (options.packages) {
|
|
2477
|
-
await
|
|
2645
|
+
await fs12.remove(getTmpPath(tmpDir, "cache", "packages"));
|
|
2478
2646
|
logger2.log("Package cache cleared");
|
|
2479
2647
|
} else if (options.builds) {
|
|
2480
|
-
await
|
|
2648
|
+
await fs12.remove(getTmpPath(tmpDir, "cache", "builds"));
|
|
2481
2649
|
logger2.log("Build cache cleared");
|
|
2482
2650
|
} else {
|
|
2483
|
-
await
|
|
2651
|
+
await fs12.remove(getTmpPath(tmpDir, "cache"));
|
|
2484
2652
|
logger2.log("All caches cleared");
|
|
2485
2653
|
}
|
|
2486
2654
|
});
|
|
@@ -2500,13 +2668,13 @@ function registerCleanCommand(program2) {
|
|
|
2500
2668
|
program2.command("clean").description("Clear the entire temp directory (.tmp/)").option("--tmp-dir <dir>", "Custom temp directory").option("--silent", "Suppress output").action(async (options) => {
|
|
2501
2669
|
const logger2 = createLogger({ silent: options.silent });
|
|
2502
2670
|
const tmpDir = options.tmpDir || getDefaultTmpRoot();
|
|
2503
|
-
await
|
|
2671
|
+
await fs12.remove(tmpDir);
|
|
2504
2672
|
logger2.log(`Temp directory cleared: ${tmpDir}`);
|
|
2505
2673
|
});
|
|
2506
2674
|
}
|
|
2507
2675
|
async function countEntries(dir) {
|
|
2508
|
-
if (!await
|
|
2509
|
-
const entries = await
|
|
2676
|
+
if (!await fs12.pathExists(dir)) return 0;
|
|
2677
|
+
const entries = await fs12.readdir(dir);
|
|
2510
2678
|
return entries.length;
|
|
2511
2679
|
}
|
|
2512
2680
|
|
|
@@ -2535,10 +2703,11 @@ program.command("bundle [file]").description("Bundle NPM packages with custom co
|
|
|
2535
2703
|
program.command("simulate [file]").description("Simulate event processing and capture API calls").option(
|
|
2536
2704
|
"-e, --event <source>",
|
|
2537
2705
|
"Event to simulate (JSON string, file path, or URL)"
|
|
2538
|
-
).option("--json", "Output results as JSON").option("-v, --verbose", "Verbose output").option("--dry-run", "preview command without executing").option("--silent", "suppress output").action(async (file, options) => {
|
|
2706
|
+
).option("-p, --platform <platform>", "Platform override (web or server)").option("--json", "Output results as JSON").option("-v, --verbose", "Verbose output").option("--dry-run", "preview command without executing").option("--silent", "suppress output").action(async (file, options) => {
|
|
2539
2707
|
await simulateCommand({
|
|
2540
2708
|
config: file || "bundle.config.json",
|
|
2541
2709
|
event: options.event,
|
|
2710
|
+
platform: options.platform,
|
|
2542
2711
|
json: options.json,
|
|
2543
2712
|
verbose: options.verbose,
|
|
2544
2713
|
dryRun: options.dryRun,
|
|
@@ -2548,11 +2717,12 @@ program.command("simulate [file]").description("Simulate event processing and ca
|
|
|
2548
2717
|
program.command("push [file]").description("Push an event through the flow with real API execution").requiredOption(
|
|
2549
2718
|
"-e, --event <source>",
|
|
2550
2719
|
"Event to push (JSON string, file path, or URL)"
|
|
2551
|
-
).option("--flow <name>", "Flow name (for multi-flow configs)").option("--json", "Output results as JSON").option("-v, --verbose", "Verbose output").option("-s, --silent", "Suppress output").action(async (file, options) => {
|
|
2720
|
+
).option("--flow <name>", "Flow name (for multi-flow configs)").option("-p, --platform <platform>", "Platform override (web or server)").option("--json", "Output results as JSON").option("-v, --verbose", "Verbose output").option("-s, --silent", "Suppress output").action(async (file, options) => {
|
|
2552
2721
|
await pushCommand({
|
|
2553
2722
|
config: file || "bundle.config.json",
|
|
2554
2723
|
event: options.event,
|
|
2555
2724
|
flow: options.flow,
|
|
2725
|
+
platform: options.platform,
|
|
2556
2726
|
json: options.json,
|
|
2557
2727
|
verbose: options.verbose,
|
|
2558
2728
|
silent: options.silent
|