@walkeros/cli 3.2.0 → 3.3.0-next-1776098542393
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 +98 -0
- package/dist/cli.js +879 -863
- package/dist/examples/flow-complete.json +167 -65
- package/dist/examples/flow-order-complete.json +11 -9
- package/dist/examples/flow-selfhost-test.json +6 -4
- package/dist/examples/flow-simple.json +11 -9
- package/dist/examples/flow.json +16 -14
- package/dist/examples/server-collect.json +14 -12
- package/dist/examples/web-serve.json +20 -15
- package/dist/index.d.ts +115 -4
- package/dist/index.js +611 -447
- package/dist/index.js.map +1 -1
- package/examples/flow-complete.json +167 -65
- package/examples/flow-order-complete.json +11 -9
- package/examples/flow-selfhost-test.json +6 -4
- package/examples/flow-simple.json +11 -9
- package/examples/flow.json +16 -14
- package/examples/server-collect.json +14 -12
- package/examples/web-serve.json +20 -15
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -326,37 +326,16 @@ var init_utils = __esm({
|
|
|
326
326
|
});
|
|
327
327
|
|
|
328
328
|
// src/core/asset-resolver.ts
|
|
329
|
-
import { fileURLToPath } from "url";
|
|
330
|
-
import { existsSync as existsSync2 } from "fs";
|
|
331
329
|
import path4 from "path";
|
|
332
|
-
function getAssetDir() {
|
|
333
|
-
if (cachedAssetDir) return cachedAssetDir;
|
|
334
|
-
const currentFile = fileURLToPath(import.meta.url);
|
|
335
|
-
let dir = path4.dirname(currentFile);
|
|
336
|
-
while (dir !== path4.dirname(dir)) {
|
|
337
|
-
if (existsSync2(path4.join(dir, "examples"))) {
|
|
338
|
-
cachedAssetDir = dir;
|
|
339
|
-
return dir;
|
|
340
|
-
}
|
|
341
|
-
dir = path4.dirname(dir);
|
|
342
|
-
}
|
|
343
|
-
cachedAssetDir = path4.dirname(currentFile);
|
|
344
|
-
return cachedAssetDir;
|
|
345
|
-
}
|
|
346
330
|
function resolveAsset(assetPath, assetType, baseDir) {
|
|
347
331
|
if (isUrl(assetPath)) {
|
|
348
332
|
return assetPath;
|
|
349
333
|
}
|
|
350
|
-
if (!assetPath.includes("/") && !assetPath.includes("\\")) {
|
|
351
|
-
const assetDir = getAssetDir();
|
|
352
|
-
return path4.join(assetDir, "examples", assetPath);
|
|
353
|
-
}
|
|
354
334
|
if (path4.isAbsolute(assetPath)) {
|
|
355
335
|
return assetPath;
|
|
356
336
|
}
|
|
357
337
|
return path4.resolve(baseDir || process.cwd(), assetPath);
|
|
358
338
|
}
|
|
359
|
-
var cachedAssetDir;
|
|
360
339
|
var init_asset_resolver = __esm({
|
|
361
340
|
"src/core/asset-resolver.ts"() {
|
|
362
341
|
"use strict";
|
|
@@ -693,29 +672,6 @@ var init_event_validation = __esm({
|
|
|
693
672
|
});
|
|
694
673
|
|
|
695
674
|
// src/core/package-path.ts
|
|
696
|
-
import fs6 from "fs";
|
|
697
|
-
import path7 from "path";
|
|
698
|
-
function resolvePackageImportPath(packageName, packages, configDir, subpath) {
|
|
699
|
-
const entry = packages?.[packageName];
|
|
700
|
-
if (entry?.path) {
|
|
701
|
-
const resolved = path7.isAbsolute(entry.path) ? entry.path : path7.resolve(configDir, entry.path);
|
|
702
|
-
if (!subpath) return resolved;
|
|
703
|
-
try {
|
|
704
|
-
const pkgJson = JSON.parse(
|
|
705
|
-
fs6.readFileSync(path7.join(resolved, "package.json"), "utf8")
|
|
706
|
-
);
|
|
707
|
-
const exportKey = `.${subpath.startsWith("/") ? subpath : `/${subpath}`}`;
|
|
708
|
-
const exp = pkgJson.exports?.[exportKey];
|
|
709
|
-
if (exp) {
|
|
710
|
-
const target = typeof exp === "string" ? exp : exp.import || exp.require || exp.default;
|
|
711
|
-
if (target) return path7.join(resolved, target);
|
|
712
|
-
}
|
|
713
|
-
} catch {
|
|
714
|
-
}
|
|
715
|
-
return path7.join(resolved, subpath.replace(/^\//, ""));
|
|
716
|
-
}
|
|
717
|
-
return subpath ? `${packageName}${subpath}` : packageName;
|
|
718
|
-
}
|
|
719
675
|
var init_package_path = __esm({
|
|
720
676
|
"src/core/package-path.ts"() {
|
|
721
677
|
"use strict";
|
|
@@ -805,8 +761,8 @@ var init_build_defaults = __esm({
|
|
|
805
761
|
});
|
|
806
762
|
|
|
807
763
|
// src/config/loader.ts
|
|
808
|
-
import
|
|
809
|
-
import
|
|
764
|
+
import path7 from "path";
|
|
765
|
+
import fs6 from "fs-extra";
|
|
810
766
|
import { getFlowSettings, getPlatform } from "@walkeros/core";
|
|
811
767
|
function loadBundleConfig(rawConfig, options) {
|
|
812
768
|
const config = validateFlowConfig(rawConfig);
|
|
@@ -823,19 +779,21 @@ function loadBundleConfig(rawConfig, options) {
|
|
|
823
779
|
flowSettings = getFlowSettings(config, flowName);
|
|
824
780
|
}
|
|
825
781
|
const buildDefaults = getBuildDefaults(platform);
|
|
826
|
-
const packages = flowSettings.packages || {};
|
|
782
|
+
const packages = flowSettings.bundle?.packages || {};
|
|
783
|
+
const overrides = flowSettings.bundle?.overrides || {};
|
|
827
784
|
const output = options.buildOverrides?.output || getDefaultOutput(platform);
|
|
828
|
-
const configDir = isUrl(options.configPath) ? process.cwd() :
|
|
785
|
+
const configDir = isUrl(options.configPath) ? process.cwd() : path7.dirname(options.configPath);
|
|
829
786
|
let includes = config.include;
|
|
830
787
|
if (!includes) {
|
|
831
|
-
const defaultIncludePath =
|
|
832
|
-
if (
|
|
788
|
+
const defaultIncludePath = path7.resolve(configDir, DEFAULT_INCLUDE_FOLDER);
|
|
789
|
+
if (fs6.pathExistsSync(defaultIncludePath)) {
|
|
833
790
|
includes = [DEFAULT_INCLUDE_FOLDER];
|
|
834
791
|
}
|
|
835
792
|
}
|
|
836
793
|
const buildOptions = {
|
|
837
794
|
...buildDefaults,
|
|
838
795
|
packages,
|
|
796
|
+
overrides,
|
|
839
797
|
output,
|
|
840
798
|
include: includes,
|
|
841
799
|
configDir,
|
|
@@ -991,8 +949,8 @@ var init_cache_utils = __esm({
|
|
|
991
949
|
|
|
992
950
|
// src/commands/bundle/package-manager.ts
|
|
993
951
|
import pacote from "pacote";
|
|
994
|
-
import
|
|
995
|
-
import
|
|
952
|
+
import path8 from "path";
|
|
953
|
+
import fs7 from "fs-extra";
|
|
996
954
|
import semver2 from "semver";
|
|
997
955
|
async function withTimeout(promise, ms, errorMessage) {
|
|
998
956
|
let timer;
|
|
@@ -1006,11 +964,34 @@ async function withTimeout(promise, ms, errorMessage) {
|
|
|
1006
964
|
}
|
|
1007
965
|
}
|
|
1008
966
|
function getPackageDirectory(baseDir, packageName) {
|
|
1009
|
-
return
|
|
967
|
+
return path8.join(baseDir, "node_modules", packageName);
|
|
1010
968
|
}
|
|
1011
|
-
async function collectAllSpecs(packages, logger, configDir) {
|
|
969
|
+
async function collectAllSpecs(packages, logger, configDir, overrides = {}) {
|
|
1012
970
|
const allSpecs = /* @__PURE__ */ new Map();
|
|
1013
971
|
const visited = /* @__PURE__ */ new Set();
|
|
972
|
+
const directLocalNames = new Set(
|
|
973
|
+
packages.filter((p2) => p2.path).map((p2) => p2.name)
|
|
974
|
+
);
|
|
975
|
+
for (const overrideName of Object.keys(overrides)) {
|
|
976
|
+
if (directLocalNames.has(overrideName)) {
|
|
977
|
+
logger.warn(
|
|
978
|
+
`Override for ${overrideName} ignored \u2014 direct package is a local path`
|
|
979
|
+
);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
const substituteDep = (depName, depSpec, source, from, optional) => {
|
|
983
|
+
const overrideSpec = overrides[depName];
|
|
984
|
+
if (overrideSpec) {
|
|
985
|
+
return {
|
|
986
|
+
name: depName,
|
|
987
|
+
spec: overrideSpec,
|
|
988
|
+
source: "override",
|
|
989
|
+
from: `override (was ${depSpec} from ${from})`,
|
|
990
|
+
optional
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
return { name: depName, spec: depSpec, source, from, optional };
|
|
994
|
+
};
|
|
1014
995
|
const queue = packages.map((pkg) => ({
|
|
1015
996
|
name: pkg.name,
|
|
1016
997
|
spec: pkg.version,
|
|
@@ -1033,22 +1014,18 @@ async function collectAllSpecs(packages, logger, configDir) {
|
|
|
1033
1014
|
localPath: item.localPath
|
|
1034
1015
|
});
|
|
1035
1016
|
if (item.localPath) {
|
|
1036
|
-
const resolvedPath =
|
|
1037
|
-
const candidatePath =
|
|
1038
|
-
const hasPkgJson = await
|
|
1017
|
+
const resolvedPath = path8.isAbsolute(item.localPath) ? item.localPath : path8.resolve(configDir || process.cwd(), item.localPath);
|
|
1018
|
+
const candidatePath = path8.join(resolvedPath, "package.json");
|
|
1019
|
+
const hasPkgJson = await fs7.pathExists(candidatePath);
|
|
1039
1020
|
if (hasPkgJson) {
|
|
1040
1021
|
try {
|
|
1041
|
-
const pkgJson = await
|
|
1022
|
+
const pkgJson = await fs7.readJson(candidatePath);
|
|
1042
1023
|
const deps2 = pkgJson.dependencies || {};
|
|
1043
1024
|
for (const [depName, depSpec] of Object.entries(deps2)) {
|
|
1044
1025
|
if (typeof depSpec === "string") {
|
|
1045
|
-
queue.push(
|
|
1046
|
-
name
|
|
1047
|
-
|
|
1048
|
-
source: "dependency",
|
|
1049
|
-
from: item.name,
|
|
1050
|
-
optional: false
|
|
1051
|
-
});
|
|
1026
|
+
queue.push(
|
|
1027
|
+
substituteDep(depName, depSpec, "dependency", item.name, false)
|
|
1028
|
+
);
|
|
1052
1029
|
}
|
|
1053
1030
|
}
|
|
1054
1031
|
const peerDeps2 = pkgJson.peerDependencies || {};
|
|
@@ -1056,13 +1033,15 @@ async function collectAllSpecs(packages, logger, configDir) {
|
|
|
1056
1033
|
for (const [depName, depSpec] of Object.entries(peerDeps2)) {
|
|
1057
1034
|
if (typeof depSpec === "string") {
|
|
1058
1035
|
const isOptional = peerMeta2[depName]?.optional === true;
|
|
1059
|
-
queue.push(
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1036
|
+
queue.push(
|
|
1037
|
+
substituteDep(
|
|
1038
|
+
depName,
|
|
1039
|
+
depSpec,
|
|
1040
|
+
"peerDependency",
|
|
1041
|
+
item.name,
|
|
1042
|
+
isOptional
|
|
1043
|
+
)
|
|
1044
|
+
);
|
|
1066
1045
|
}
|
|
1067
1046
|
}
|
|
1068
1047
|
} catch (error) {
|
|
@@ -1090,13 +1069,9 @@ async function collectAllSpecs(packages, logger, configDir) {
|
|
|
1090
1069
|
const deps = m2.dependencies || {};
|
|
1091
1070
|
for (const [depName, depSpec] of Object.entries(deps)) {
|
|
1092
1071
|
if (typeof depSpec === "string") {
|
|
1093
|
-
queue.push(
|
|
1094
|
-
name
|
|
1095
|
-
|
|
1096
|
-
source: "dependency",
|
|
1097
|
-
from: item.name,
|
|
1098
|
-
optional: false
|
|
1099
|
-
});
|
|
1072
|
+
queue.push(
|
|
1073
|
+
substituteDep(depName, depSpec, "dependency", item.name, false)
|
|
1074
|
+
);
|
|
1100
1075
|
}
|
|
1101
1076
|
}
|
|
1102
1077
|
const peerDeps = m2.peerDependencies || {};
|
|
@@ -1104,13 +1079,15 @@ async function collectAllSpecs(packages, logger, configDir) {
|
|
|
1104
1079
|
for (const [depName, depSpec] of Object.entries(peerDeps)) {
|
|
1105
1080
|
if (typeof depSpec === "string") {
|
|
1106
1081
|
const isOptional = peerMeta[depName]?.optional === true;
|
|
1107
|
-
queue.push(
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1082
|
+
queue.push(
|
|
1083
|
+
substituteDep(
|
|
1084
|
+
depName,
|
|
1085
|
+
depSpec,
|
|
1086
|
+
"peerDependency",
|
|
1087
|
+
item.name,
|
|
1088
|
+
isOptional
|
|
1089
|
+
)
|
|
1090
|
+
);
|
|
1114
1091
|
}
|
|
1115
1092
|
}
|
|
1116
1093
|
}
|
|
@@ -1196,14 +1173,19 @@ function resolveVersionConflicts(allSpecs, logger) {
|
|
|
1196
1173
|
}
|
|
1197
1174
|
return resolved;
|
|
1198
1175
|
}
|
|
1199
|
-
async function downloadPackages(packages, targetDir, logger, useCache = true, configDir, tmpDir) {
|
|
1176
|
+
async function downloadPackages(packages, targetDir, logger, useCache = true, configDir, tmpDir, overrides = {}) {
|
|
1200
1177
|
const packagePaths = /* @__PURE__ */ new Map();
|
|
1201
1178
|
const userSpecifiedPackages = new Set(packages.map((p2) => p2.name));
|
|
1202
1179
|
validateNoDuplicatePackages(packages);
|
|
1203
1180
|
logger.debug("Resolving dependencies");
|
|
1204
|
-
const allSpecs = await collectAllSpecs(
|
|
1181
|
+
const allSpecs = await collectAllSpecs(
|
|
1182
|
+
packages,
|
|
1183
|
+
logger,
|
|
1184
|
+
configDir,
|
|
1185
|
+
overrides
|
|
1186
|
+
);
|
|
1205
1187
|
const resolved = resolveVersionConflicts(allSpecs, logger);
|
|
1206
|
-
await
|
|
1188
|
+
await fs7.ensureDir(targetDir);
|
|
1207
1189
|
const localPackageMap = /* @__PURE__ */ new Map();
|
|
1208
1190
|
for (const pkg of packages) {
|
|
1209
1191
|
if (pkg.path) localPackageMap.set(pkg.name, pkg.path);
|
|
@@ -1232,8 +1214,8 @@ async function downloadPackages(packages, targetDir, logger, useCache = true, co
|
|
|
1232
1214
|
logger.debug(`Downloading ${packageSpec} (cached)`);
|
|
1233
1215
|
}
|
|
1234
1216
|
try {
|
|
1235
|
-
await
|
|
1236
|
-
await
|
|
1217
|
+
await fs7.ensureDir(path8.dirname(packageDir));
|
|
1218
|
+
await fs7.copy(cachedPath, packageDir);
|
|
1237
1219
|
packagePaths.set(name, packageDir);
|
|
1238
1220
|
continue;
|
|
1239
1221
|
} catch {
|
|
@@ -1241,7 +1223,7 @@ async function downloadPackages(packages, targetDir, logger, useCache = true, co
|
|
|
1241
1223
|
}
|
|
1242
1224
|
}
|
|
1243
1225
|
try {
|
|
1244
|
-
await
|
|
1226
|
+
await fs7.ensureDir(path8.dirname(packageDir));
|
|
1245
1227
|
const cacheDir = process.env.NPM_CACHE_DIR || getTmpPath(tmpDir, "cache", "npm");
|
|
1246
1228
|
await withTimeout(
|
|
1247
1229
|
pacote.extract(packageSpec, packageDir, {
|
|
@@ -1256,8 +1238,8 @@ async function downloadPackages(packages, targetDir, logger, useCache = true, co
|
|
|
1256
1238
|
}
|
|
1257
1239
|
if (useCache) {
|
|
1258
1240
|
try {
|
|
1259
|
-
await
|
|
1260
|
-
await
|
|
1241
|
+
await fs7.ensureDir(path8.dirname(cachedPath));
|
|
1242
|
+
await fs7.copy(packageDir, cachedPath);
|
|
1261
1243
|
} catch {
|
|
1262
1244
|
}
|
|
1263
1245
|
}
|
|
@@ -1271,11 +1253,11 @@ async function downloadPackages(packages, targetDir, logger, useCache = true, co
|
|
|
1271
1253
|
async function getCachedPackagePath(pkg, tmpDir) {
|
|
1272
1254
|
const cacheDir = getTmpPath(tmpDir, "cache", "packages");
|
|
1273
1255
|
const cacheKey = await getPackageCacheKey(pkg.name, pkg.version);
|
|
1274
|
-
return
|
|
1256
|
+
return path8.join(cacheDir, cacheKey);
|
|
1275
1257
|
}
|
|
1276
1258
|
async function isPackageCached(pkg, tmpDir) {
|
|
1277
1259
|
const cachedPath = await getCachedPackagePath(pkg, tmpDir);
|
|
1278
|
-
return
|
|
1260
|
+
return fs7.pathExists(cachedPath);
|
|
1279
1261
|
}
|
|
1280
1262
|
function validateNoDuplicatePackages(packages) {
|
|
1281
1263
|
const packageMap = /* @__PURE__ */ new Map();
|
|
@@ -1314,61 +1296,62 @@ var init_package_manager = __esm({
|
|
|
1314
1296
|
};
|
|
1315
1297
|
SOURCE_PRIORITY = {
|
|
1316
1298
|
direct: 0,
|
|
1317
|
-
|
|
1318
|
-
|
|
1299
|
+
override: 1,
|
|
1300
|
+
dependency: 2,
|
|
1301
|
+
peerDependency: 3
|
|
1319
1302
|
};
|
|
1320
1303
|
}
|
|
1321
1304
|
});
|
|
1322
1305
|
|
|
1323
1306
|
// src/core/build-cache.ts
|
|
1324
|
-
import
|
|
1325
|
-
import
|
|
1307
|
+
import fs8 from "fs-extra";
|
|
1308
|
+
import path9 from "path";
|
|
1326
1309
|
import { getHashServer as getHashServer2 } from "@walkeros/server-core";
|
|
1327
1310
|
async function getBuildCachePath(configContent, tmpDir) {
|
|
1328
1311
|
const cacheDir = getTmpPath(tmpDir, "cache", "builds");
|
|
1329
1312
|
const cacheKey = await getFlowSettingsCacheKey(configContent);
|
|
1330
|
-
return
|
|
1313
|
+
return path9.join(cacheDir, `${cacheKey}.js`);
|
|
1331
1314
|
}
|
|
1332
1315
|
async function isBuildCached(configContent, tmpDir) {
|
|
1333
1316
|
const cachePath = await getBuildCachePath(configContent, tmpDir);
|
|
1334
|
-
return
|
|
1317
|
+
return fs8.pathExists(cachePath);
|
|
1335
1318
|
}
|
|
1336
1319
|
async function cacheBuild(configContent, buildOutput, tmpDir) {
|
|
1337
1320
|
const cachePath = await getBuildCachePath(configContent, tmpDir);
|
|
1338
|
-
await
|
|
1339
|
-
await
|
|
1321
|
+
await fs8.ensureDir(path9.dirname(cachePath));
|
|
1322
|
+
await fs8.writeFile(cachePath, buildOutput, "utf-8");
|
|
1340
1323
|
}
|
|
1341
1324
|
async function getCachedBuild(configContent, tmpDir) {
|
|
1342
1325
|
const cachePath = await getBuildCachePath(configContent, tmpDir);
|
|
1343
|
-
if (await
|
|
1344
|
-
return await
|
|
1326
|
+
if (await fs8.pathExists(cachePath)) {
|
|
1327
|
+
return await fs8.readFile(cachePath, "utf-8");
|
|
1345
1328
|
}
|
|
1346
1329
|
return null;
|
|
1347
1330
|
}
|
|
1348
1331
|
async function getCodeCachePath(codeContent, tmpDir) {
|
|
1349
1332
|
const cacheDir = getTmpPath(tmpDir, "cache", "code");
|
|
1350
1333
|
const cacheKey = await getHashServer2(codeContent, 12);
|
|
1351
|
-
return
|
|
1334
|
+
return path9.join(cacheDir, `${cacheKey}.js`);
|
|
1352
1335
|
}
|
|
1353
1336
|
async function cacheCode(codeContent, codeOutput, tmpDir) {
|
|
1354
1337
|
const cachePath = await getCodeCachePath(codeContent, tmpDir);
|
|
1355
|
-
await
|
|
1356
|
-
await
|
|
1338
|
+
await fs8.ensureDir(path9.dirname(cachePath));
|
|
1339
|
+
await fs8.writeFile(cachePath, codeOutput, "utf-8");
|
|
1357
1340
|
}
|
|
1358
1341
|
async function getCachedCode(codeContent, tmpDir) {
|
|
1359
1342
|
const cachePath = await getCodeCachePath(codeContent, tmpDir);
|
|
1360
|
-
if (await
|
|
1361
|
-
return
|
|
1343
|
+
if (await fs8.pathExists(cachePath)) {
|
|
1344
|
+
return fs8.readFile(cachePath, "utf-8");
|
|
1362
1345
|
}
|
|
1363
1346
|
return null;
|
|
1364
1347
|
}
|
|
1365
1348
|
async function ensureCodeOnDisk(codeContent, compiledCode, tmpDir) {
|
|
1366
1349
|
const cacheDir = getTmpPath(tmpDir, "cache", "code");
|
|
1367
1350
|
const cacheKey = await getHashServer2(codeContent, 12);
|
|
1368
|
-
const cachePath =
|
|
1369
|
-
if (!await
|
|
1370
|
-
await
|
|
1371
|
-
await
|
|
1351
|
+
const cachePath = path9.join(cacheDir, `${cacheKey}.mjs`);
|
|
1352
|
+
if (!await fs8.pathExists(cachePath)) {
|
|
1353
|
+
await fs8.ensureDir(path9.dirname(cachePath));
|
|
1354
|
+
await fs8.writeFile(cachePath, compiledCode, "utf-8");
|
|
1372
1355
|
}
|
|
1373
1356
|
return cachePath;
|
|
1374
1357
|
}
|
|
@@ -1384,8 +1367,8 @@ var init_build_cache = __esm({
|
|
|
1384
1367
|
import crypto from "crypto";
|
|
1385
1368
|
import esbuild from "esbuild";
|
|
1386
1369
|
import { builtinModules } from "module";
|
|
1387
|
-
import
|
|
1388
|
-
import
|
|
1370
|
+
import path10 from "path";
|
|
1371
|
+
import fs9 from "fs-extra";
|
|
1389
1372
|
import { packageNameToVariable, ENV_MARKER_PREFIX } from "@walkeros/core";
|
|
1390
1373
|
function isInlineCode(code) {
|
|
1391
1374
|
return code !== null && typeof code === "object" && !Array.isArray(code) && "push" in code;
|
|
@@ -1438,18 +1421,18 @@ function generateInlineCode(inline, config, env, chain, chainPropertyName, isDes
|
|
|
1438
1421
|
}
|
|
1439
1422
|
async function copyIncludes(includes, sourceDir, outputDir, logger) {
|
|
1440
1423
|
for (const include of includes) {
|
|
1441
|
-
const sourcePath =
|
|
1442
|
-
const folderName =
|
|
1443
|
-
const destPath =
|
|
1444
|
-
const resolvedOutput =
|
|
1445
|
-
const resolvedSource =
|
|
1446
|
-
if (resolvedSource === resolvedOutput || resolvedOutput.startsWith(resolvedSource +
|
|
1424
|
+
const sourcePath = path10.resolve(sourceDir, include);
|
|
1425
|
+
const folderName = path10.basename(include);
|
|
1426
|
+
const destPath = path10.join(outputDir, folderName);
|
|
1427
|
+
const resolvedOutput = path10.resolve(outputDir);
|
|
1428
|
+
const resolvedSource = path10.resolve(sourcePath);
|
|
1429
|
+
if (resolvedSource === resolvedOutput || resolvedOutput.startsWith(resolvedSource + path10.sep) || resolvedSource.startsWith(resolvedOutput + path10.sep)) {
|
|
1447
1430
|
throw new Error(
|
|
1448
1431
|
`Circular include detected: "${include}" resolves to "${resolvedSource}" which overlaps with output directory "${resolvedOutput}"`
|
|
1449
1432
|
);
|
|
1450
1433
|
}
|
|
1451
|
-
if (await
|
|
1452
|
-
await
|
|
1434
|
+
if (await fs9.pathExists(sourcePath)) {
|
|
1435
|
+
await fs9.copy(sourcePath, destPath);
|
|
1453
1436
|
logger.debug(`Copied ${include} to output`);
|
|
1454
1437
|
} else {
|
|
1455
1438
|
logger.warn(`Include folder not found: ${include}`);
|
|
@@ -1520,14 +1503,14 @@ async function bundleCore(flowSettings, buildOptions, logger, showStats = false)
|
|
|
1520
1503
|
const cachedBuild = await getCachedBuild(configContent, CACHE_DIR);
|
|
1521
1504
|
if (cachedBuild) {
|
|
1522
1505
|
logger.debug("Using cached build");
|
|
1523
|
-
const outputPath =
|
|
1524
|
-
await
|
|
1525
|
-
await
|
|
1526
|
-
const stats = await
|
|
1506
|
+
const outputPath = path10.resolve(buildOptions.output);
|
|
1507
|
+
await fs9.ensureDir(path10.dirname(outputPath));
|
|
1508
|
+
await fs9.writeFile(outputPath, cachedBuild);
|
|
1509
|
+
const stats = await fs9.stat(outputPath);
|
|
1527
1510
|
const sizeKB = (stats.size / 1024).toFixed(1);
|
|
1528
1511
|
logger.info(`Output: ${outputPath} (${sizeKB} KB, cached)`);
|
|
1529
1512
|
if (showStats) {
|
|
1530
|
-
const stats2 = await
|
|
1513
|
+
const stats2 = await fs9.stat(outputPath);
|
|
1531
1514
|
const packageStats = Object.entries(buildOptions.packages).map(
|
|
1532
1515
|
([name, pkg]) => ({
|
|
1533
1516
|
name: `${name}@${pkg.version || "latest"}`,
|
|
@@ -1550,7 +1533,7 @@ async function bundleCore(flowSettings, buildOptions, logger, showStats = false)
|
|
|
1550
1533
|
}
|
|
1551
1534
|
}
|
|
1552
1535
|
try {
|
|
1553
|
-
await
|
|
1536
|
+
await fs9.ensureDir(TEMP_DIR);
|
|
1554
1537
|
const hasSourcesOrDests = Object.keys(
|
|
1555
1538
|
flowSettings.sources || {}
|
|
1556
1539
|
).length > 0 || Object.keys(
|
|
@@ -1570,7 +1553,12 @@ async function bundleCore(flowSettings, buildOptions, logger, showStats = false)
|
|
|
1570
1553
|
imports: [`default as ${varName}`]
|
|
1571
1554
|
};
|
|
1572
1555
|
}
|
|
1573
|
-
for (const section of [
|
|
1556
|
+
for (const section of [
|
|
1557
|
+
"sources",
|
|
1558
|
+
"destinations",
|
|
1559
|
+
"transformers",
|
|
1560
|
+
"stores"
|
|
1561
|
+
]) {
|
|
1574
1562
|
const steps = flowSettings[section];
|
|
1575
1563
|
if (!steps) continue;
|
|
1576
1564
|
for (const step of Object.values(steps)) {
|
|
@@ -1600,12 +1588,13 @@ async function bundleCore(flowSettings, buildOptions, logger, showStats = false)
|
|
|
1600
1588
|
buildOptions.cache,
|
|
1601
1589
|
buildOptions.configDir,
|
|
1602
1590
|
// For resolving relative local paths
|
|
1603
|
-
CACHE_DIR
|
|
1591
|
+
CACHE_DIR,
|
|
1592
|
+
buildOptions.overrides
|
|
1604
1593
|
);
|
|
1605
1594
|
for (const [pkgName, pkgPath] of packagePaths.entries()) {
|
|
1606
1595
|
if (pkgName.startsWith("@walkeros/")) {
|
|
1607
|
-
const pkgJsonPath =
|
|
1608
|
-
const pkgJson = await
|
|
1596
|
+
const pkgJsonPath = path10.join(pkgPath, "package.json");
|
|
1597
|
+
const pkgJson = await fs9.readJSON(pkgJsonPath);
|
|
1609
1598
|
if (!pkgJson.exports && pkgJson.module) {
|
|
1610
1599
|
pkgJson.exports = {
|
|
1611
1600
|
".": {
|
|
@@ -1613,12 +1602,12 @@ async function bundleCore(flowSettings, buildOptions, logger, showStats = false)
|
|
|
1613
1602
|
require: pkgJson.main
|
|
1614
1603
|
}
|
|
1615
1604
|
};
|
|
1616
|
-
await
|
|
1605
|
+
await fs9.writeJSON(pkgJsonPath, pkgJson, { spaces: 2 });
|
|
1617
1606
|
}
|
|
1618
1607
|
}
|
|
1619
1608
|
}
|
|
1620
|
-
const packageJsonPath =
|
|
1621
|
-
await
|
|
1609
|
+
const packageJsonPath = path10.join(TEMP_DIR, "package.json");
|
|
1610
|
+
await fs9.writeFile(
|
|
1622
1611
|
packageJsonPath,
|
|
1623
1612
|
JSON.stringify({ type: "module" }, null, 2)
|
|
1624
1613
|
);
|
|
@@ -1628,8 +1617,8 @@ async function bundleCore(flowSettings, buildOptions, logger, showStats = false)
|
|
|
1628
1617
|
buildOptions,
|
|
1629
1618
|
packagePaths
|
|
1630
1619
|
);
|
|
1631
|
-
const outputPath =
|
|
1632
|
-
await
|
|
1620
|
+
const outputPath = path10.resolve(buildOptions.output);
|
|
1621
|
+
await fs9.ensureDir(path10.dirname(outputPath));
|
|
1633
1622
|
let compiledCode = null;
|
|
1634
1623
|
if (buildOptions.cache !== false) {
|
|
1635
1624
|
compiledCode = await getCachedCode(codeEntry, CACHE_DIR);
|
|
@@ -1640,8 +1629,8 @@ async function bundleCore(flowSettings, buildOptions, logger, showStats = false)
|
|
|
1640
1629
|
logger.debug(
|
|
1641
1630
|
`Running esbuild (target: ${buildOptions.target || "es2018"}, format: ${buildOptions.format})`
|
|
1642
1631
|
);
|
|
1643
|
-
const entryPath =
|
|
1644
|
-
await
|
|
1632
|
+
const entryPath = path10.join(TEMP_DIR, "entry.js");
|
|
1633
|
+
await fs9.writeFile(entryPath, codeEntry);
|
|
1645
1634
|
const esbuildOptions = createEsbuildOptions(
|
|
1646
1635
|
{ ...buildOptions, minify: false },
|
|
1647
1636
|
entryPath,
|
|
@@ -1660,7 +1649,7 @@ async function bundleCore(flowSettings, buildOptions, logger, showStats = false)
|
|
|
1660
1649
|
} finally {
|
|
1661
1650
|
await esbuild.stop();
|
|
1662
1651
|
}
|
|
1663
|
-
compiledCode = await
|
|
1652
|
+
compiledCode = await fs9.readFile(outputPath, "utf-8");
|
|
1664
1653
|
if (buildOptions.cache !== false) {
|
|
1665
1654
|
await cacheCode(codeEntry, compiledCode, CACHE_DIR);
|
|
1666
1655
|
}
|
|
@@ -1677,14 +1666,14 @@ export { __configData };`;
|
|
|
1677
1666
|
` : "";
|
|
1678
1667
|
const esmOutput = `${banner}${compiledCode}
|
|
1679
1668
|
${dataDeclaration}`;
|
|
1680
|
-
await
|
|
1669
|
+
await fs9.writeFile(outputPath, esmOutput);
|
|
1681
1670
|
} else {
|
|
1682
1671
|
const stage2Entry = (buildOptions.platform || "node") === "browser" ? generateWebEntry(stage1Path, dataPayload, {
|
|
1683
1672
|
windowCollector: buildOptions.windowCollector,
|
|
1684
1673
|
windowElb: buildOptions.windowElb
|
|
1685
1674
|
}) : generateServerEntry(stage1Path, dataPayload);
|
|
1686
|
-
const stage2EntryPath =
|
|
1687
|
-
await
|
|
1675
|
+
const stage2EntryPath = path10.join(TEMP_DIR, "stage2.mjs");
|
|
1676
|
+
await fs9.writeFile(stage2EntryPath, stage2Entry);
|
|
1688
1677
|
const stage2Options = {
|
|
1689
1678
|
entryPoints: [stage2EntryPath],
|
|
1690
1679
|
bundle: true,
|
|
@@ -1721,13 +1710,13 @@ ${dataDeclaration}`;
|
|
|
1721
1710
|
await esbuild.stop();
|
|
1722
1711
|
}
|
|
1723
1712
|
}
|
|
1724
|
-
const outputStats = await
|
|
1713
|
+
const outputStats = await fs9.stat(outputPath);
|
|
1725
1714
|
const sizeKB = (outputStats.size / 1024).toFixed(1);
|
|
1726
1715
|
const buildTime = ((Date.now() - bundleStartTime) / 1e3).toFixed(1);
|
|
1727
1716
|
logger.info(`Output: ${outputPath} (${sizeKB} KB, ${buildTime}s)`);
|
|
1728
1717
|
if (buildOptions.cache !== false) {
|
|
1729
1718
|
const configContent = generateCacheKeyContent(flowSettings, buildOptions);
|
|
1730
|
-
const buildOutput = await
|
|
1719
|
+
const buildOutput = await fs9.readFile(outputPath, "utf-8");
|
|
1731
1720
|
await cacheBuild(configContent, buildOutput, CACHE_DIR);
|
|
1732
1721
|
logger.debug("Build cached for future use");
|
|
1733
1722
|
}
|
|
@@ -1741,7 +1730,7 @@ ${dataDeclaration}`;
|
|
|
1741
1730
|
);
|
|
1742
1731
|
}
|
|
1743
1732
|
if (buildOptions.include && buildOptions.include.length > 0) {
|
|
1744
|
-
const outputDir =
|
|
1733
|
+
const outputDir = path10.dirname(outputPath);
|
|
1745
1734
|
await copyIncludes(
|
|
1746
1735
|
buildOptions.include,
|
|
1747
1736
|
buildOptions.configDir || process.cwd(),
|
|
@@ -1754,13 +1743,13 @@ ${dataDeclaration}`;
|
|
|
1754
1743
|
throw error;
|
|
1755
1744
|
} finally {
|
|
1756
1745
|
if (!buildOptions.tempDir) {
|
|
1757
|
-
|
|
1746
|
+
fs9.remove(TEMP_DIR).catch(() => {
|
|
1758
1747
|
});
|
|
1759
1748
|
}
|
|
1760
1749
|
}
|
|
1761
1750
|
}
|
|
1762
1751
|
async function collectBundleStats(outputPath, packages, startTime, entryContent) {
|
|
1763
|
-
const stats = await
|
|
1752
|
+
const stats = await fs9.stat(outputPath);
|
|
1764
1753
|
const totalSize = stats.size;
|
|
1765
1754
|
const buildTime = Date.now() - startTime;
|
|
1766
1755
|
const packageStats = Object.entries(packages).map(([name, pkg]) => {
|
|
@@ -1943,9 +1932,8 @@ function detectExplicitCodeImports(flowSettings) {
|
|
|
1943
1932
|
}
|
|
1944
1933
|
return explicitCodeImports;
|
|
1945
1934
|
}
|
|
1946
|
-
function generateImportStatements(packages, destinationPackages, sourcePackages, transformerPackages, storePackages, explicitCodeImports) {
|
|
1935
|
+
async function generateImportStatements(packages, destinationPackages, sourcePackages, transformerPackages, storePackages, explicitCodeImports, packagePaths) {
|
|
1947
1936
|
const importStatements = [];
|
|
1948
|
-
const examplesMappings = [];
|
|
1949
1937
|
const usedPackages = /* @__PURE__ */ new Set([
|
|
1950
1938
|
...destinationPackages,
|
|
1951
1939
|
...sourcePackages,
|
|
@@ -1980,21 +1968,6 @@ function generateImportStatements(packages, destinationPackages, sourcePackages,
|
|
|
1980
1968
|
}
|
|
1981
1969
|
}
|
|
1982
1970
|
}
|
|
1983
|
-
const examplesImport = uniqueImports.find(
|
|
1984
|
-
(imp) => imp.includes("examples as ")
|
|
1985
|
-
);
|
|
1986
|
-
if (examplesImport) {
|
|
1987
|
-
const examplesVarName = examplesImport.split(" as ")[1];
|
|
1988
|
-
const destinationMatch = packageName.match(
|
|
1989
|
-
/@walkeros\/web-destination-(.+)$/
|
|
1990
|
-
);
|
|
1991
|
-
if (destinationMatch) {
|
|
1992
|
-
const destinationName = destinationMatch[1];
|
|
1993
|
-
examplesMappings.push(
|
|
1994
|
-
` ${destinationName}: typeof ${examplesVarName} !== 'undefined' ? ${examplesVarName} : undefined`
|
|
1995
|
-
);
|
|
1996
|
-
}
|
|
1997
|
-
}
|
|
1998
1971
|
}
|
|
1999
1972
|
if (packageName === "@walkeros/collector" && !namedImportsToGenerate.includes("startFlow")) {
|
|
2000
1973
|
namedImportsToGenerate.push("startFlow");
|
|
@@ -2004,7 +1977,25 @@ function generateImportStatements(packages, destinationPackages, sourcePackages,
|
|
|
2004
1977
|
importStatements.push(`import { ${importList} } from '${packageName}';`);
|
|
2005
1978
|
}
|
|
2006
1979
|
}
|
|
2007
|
-
|
|
1980
|
+
const devExportEntries = [];
|
|
1981
|
+
for (const packageName of usedPackages) {
|
|
1982
|
+
const localPath = packagePaths.get(packageName);
|
|
1983
|
+
if (!localPath) continue;
|
|
1984
|
+
try {
|
|
1985
|
+
const pkgJsonPath = path10.join(localPath, "package.json");
|
|
1986
|
+
const pkgJson = await fs9.readJSON(pkgJsonPath);
|
|
1987
|
+
const exports = pkgJson.exports;
|
|
1988
|
+
if (exports && typeof exports === "object" && "./dev" in exports) {
|
|
1989
|
+
const varName = `__dev_${packageNameToVariable(packageName)}`;
|
|
1990
|
+
importStatements.push(
|
|
1991
|
+
`import * as ${varName} from '${packageName}/dev';`
|
|
1992
|
+
);
|
|
1993
|
+
devExportEntries.push(`'${packageName}': ${varName}`);
|
|
1994
|
+
}
|
|
1995
|
+
} catch {
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
return { importStatements, devExportEntries };
|
|
2008
1999
|
}
|
|
2009
2000
|
function validateComponentNames(components, section) {
|
|
2010
2001
|
for (const name of Object.keys(components)) {
|
|
@@ -2067,13 +2058,14 @@ async function createEntryPoint(flowSettings, buildOptions, packagePaths) {
|
|
|
2067
2058
|
validateComponentNames(flowWithSections.transformers, "transformers");
|
|
2068
2059
|
if (flowWithSections.stores)
|
|
2069
2060
|
validateComponentNames(flowWithSections.stores, "stores");
|
|
2070
|
-
const { importStatements } = generateImportStatements(
|
|
2061
|
+
const { importStatements, devExportEntries } = await generateImportStatements(
|
|
2071
2062
|
buildOptions.packages,
|
|
2072
2063
|
destinationPackages,
|
|
2073
2064
|
sourcePackages,
|
|
2074
2065
|
transformerPackages,
|
|
2075
2066
|
storePackages,
|
|
2076
|
-
explicitCodeImports
|
|
2067
|
+
explicitCodeImports,
|
|
2068
|
+
packagePaths
|
|
2077
2069
|
);
|
|
2078
2070
|
const importsCode = importStatements.join("\n");
|
|
2079
2071
|
const hasFlow = Object.values(flowSettings.sources || {}).some(
|
|
@@ -2097,9 +2089,14 @@ ${userCode}` : userCode,
|
|
|
2097
2089
|
codeConfigObject,
|
|
2098
2090
|
buildOptions.code || ""
|
|
2099
2091
|
);
|
|
2092
|
+
const devExportsBlock = devExportEntries.length > 0 ? `
|
|
2093
|
+
export const __devExports = {
|
|
2094
|
+
${devExportEntries.join(",\n ")},
|
|
2095
|
+
};` : "";
|
|
2096
|
+
const fullModule = wireConfigModule + devExportsBlock;
|
|
2100
2097
|
const codeEntry = importsCode ? `${importsCode}
|
|
2101
2098
|
|
|
2102
|
-
${
|
|
2099
|
+
${fullModule}` : fullModule;
|
|
2103
2100
|
return { codeEntry, dataPayload, hasFlow: true };
|
|
2104
2101
|
}
|
|
2105
2102
|
function createBuildError(buildError, code) {
|
|
@@ -2345,6 +2342,79 @@ const __configData = ${dataPayload};
|
|
|
2345
2342
|
const { collector, elb } = await startFlow(wireConfig(__configData));${assignmentCode}
|
|
2346
2343
|
})();`;
|
|
2347
2344
|
}
|
|
2345
|
+
function generateWrapEntry(stage1Path, options = {}) {
|
|
2346
|
+
const assignments = [];
|
|
2347
|
+
if (options.windowCollector) {
|
|
2348
|
+
assignments.push(
|
|
2349
|
+
` if (typeof window !== 'undefined') window['${options.windowCollector}'] = collector;`
|
|
2350
|
+
);
|
|
2351
|
+
}
|
|
2352
|
+
if (options.windowElb) {
|
|
2353
|
+
assignments.push(
|
|
2354
|
+
` if (typeof window !== 'undefined') window['${options.windowElb}'] = elb;`
|
|
2355
|
+
);
|
|
2356
|
+
}
|
|
2357
|
+
const assignmentCode = assignments.length > 0 ? "\n" + assignments.join("\n") : "";
|
|
2358
|
+
const hasPreview = !!(options.previewOrigin && options.previewScope);
|
|
2359
|
+
const previewOriginLiteral = JSON.stringify(options.previewOrigin ?? "");
|
|
2360
|
+
const previewScopeLiteral = JSON.stringify(options.previewScope ?? "");
|
|
2361
|
+
const preflightBlock = hasPreview ? `
|
|
2362
|
+
// --- Preview mode preflight ---
|
|
2363
|
+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
2364
|
+
var __previewOrigin = ${previewOriginLiteral};
|
|
2365
|
+
var __previewScope = ${previewScopeLiteral};
|
|
2366
|
+
var __params = new URLSearchParams(location.search);
|
|
2367
|
+
var __tokens = __params.getAll('elbPreview');
|
|
2368
|
+
var __param = __tokens.length > 0 ? __tokens[__tokens.length - 1] : null;
|
|
2369
|
+
var __secure = location.protocol === 'https:' ? '; Secure' : '';
|
|
2370
|
+
|
|
2371
|
+
if (__param === 'off') {
|
|
2372
|
+
document.cookie = 'elbPreview=; path=/; max-age=0; SameSite=Lax' + __secure;
|
|
2373
|
+
} else if (__param && /^[a-zA-Z0-9_-]{8,32}$/.test(__param)) {
|
|
2374
|
+
document.cookie = 'elbPreview=' + __param + '; path=/; max-age=604800; SameSite=Lax' + __secure;
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2377
|
+
var __match = /(?:^|; )elbPreview=([^;]+)/.exec(document.cookie);
|
|
2378
|
+
var __token = __match && __match[1];
|
|
2379
|
+
if (__token && /^[a-zA-Z0-9_-]{8,32}$/.test(__token)) {
|
|
2380
|
+
var __s = document.createElement('script');
|
|
2381
|
+
__s.src = 'https://' + __previewOrigin + '/preview/' + __previewScope + '/walker.' + __token + '.js';
|
|
2382
|
+
document.head.appendChild(__s);
|
|
2383
|
+
return;
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
// --- End preview mode preflight ---
|
|
2387
|
+
` : "";
|
|
2388
|
+
return `import { startFlow, wireConfig, __configData } from '${stage1Path}';
|
|
2389
|
+
|
|
2390
|
+
(async () => {${preflightBlock}
|
|
2391
|
+
const { collector, elb } = await startFlow(wireConfig(__configData));${assignmentCode}
|
|
2392
|
+
})();`;
|
|
2393
|
+
}
|
|
2394
|
+
function generateWrapEntryServer(stage1Path) {
|
|
2395
|
+
return `import { startFlow, wireConfig, __configData } from '${stage1Path}';
|
|
2396
|
+
|
|
2397
|
+
export default async function(context = {}) {
|
|
2398
|
+
const config = wireConfig(__configData);
|
|
2399
|
+
|
|
2400
|
+
if (context.logger) config.logger = context.logger;
|
|
2401
|
+
|
|
2402
|
+
if (context.sourceSettings && config.sources) {
|
|
2403
|
+
for (const src of Object.values(config.sources)) {
|
|
2404
|
+
if (src.config?.settings) {
|
|
2405
|
+
src.config.settings = { ...src.config.settings, ...context.sourceSettings };
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
const result = await startFlow(config);
|
|
2411
|
+
|
|
2412
|
+
const httpSource = Object.values(result.collector.sources || {})
|
|
2413
|
+
.find(s => 'httpHandler' in s && typeof s.httpHandler === 'function');
|
|
2414
|
+
|
|
2415
|
+
return { ...result, httpHandler: httpSource ? httpSource.httpHandler : undefined };
|
|
2416
|
+
}`;
|
|
2417
|
+
}
|
|
2348
2418
|
function processConfigValue(value) {
|
|
2349
2419
|
return serializeWithCode(value, 0);
|
|
2350
2420
|
}
|
|
@@ -2425,12 +2495,12 @@ var init_bundler = __esm({
|
|
|
2425
2495
|
});
|
|
2426
2496
|
|
|
2427
2497
|
// src/commands/bundle/upload.ts
|
|
2428
|
-
import
|
|
2498
|
+
import fs10 from "fs-extra";
|
|
2429
2499
|
function sanitizeUrl(url) {
|
|
2430
2500
|
return url.split("?")[0];
|
|
2431
2501
|
}
|
|
2432
2502
|
async function uploadBundleToUrl(filePath, url, timeoutMs = 3e4) {
|
|
2433
|
-
const bundleContent = await
|
|
2503
|
+
const bundleContent = await fs10.readFile(filePath);
|
|
2434
2504
|
const doUpload = async (attempt) => {
|
|
2435
2505
|
const response = await fetch(url, {
|
|
2436
2506
|
method: "PUT",
|
|
@@ -2509,8 +2579,8 @@ var init_api_client = __esm({
|
|
|
2509
2579
|
});
|
|
2510
2580
|
|
|
2511
2581
|
// src/commands/bundle/dockerfile.ts
|
|
2512
|
-
import
|
|
2513
|
-
import
|
|
2582
|
+
import path11 from "path";
|
|
2583
|
+
import fs11 from "fs-extra";
|
|
2514
2584
|
function buildDockerfileContent(platform, includedFolders) {
|
|
2515
2585
|
const bundleFile = platform === "web" ? "walker.js" : "bundle.mjs";
|
|
2516
2586
|
const lines = [
|
|
@@ -2520,21 +2590,21 @@ function buildDockerfileContent(platform, includedFolders) {
|
|
|
2520
2590
|
`COPY ${bundleFile} /app/flow/${bundleFile}`
|
|
2521
2591
|
];
|
|
2522
2592
|
for (const folder of includedFolders) {
|
|
2523
|
-
const name =
|
|
2593
|
+
const name = path11.basename(folder);
|
|
2524
2594
|
lines.push(`COPY ${name}/ /app/flow/${name}/`);
|
|
2525
2595
|
}
|
|
2526
2596
|
lines.push("", `ENV BUNDLE=/app/flow/${bundleFile}`, "", "EXPOSE 8080", "");
|
|
2527
2597
|
return lines.join("\n");
|
|
2528
2598
|
}
|
|
2529
2599
|
async function generateDockerfile(outputDir, platform, logger, customFile, includedFolders) {
|
|
2530
|
-
const destPath =
|
|
2531
|
-
if (customFile && await
|
|
2532
|
-
await
|
|
2600
|
+
const destPath = path11.join(outputDir, "Dockerfile");
|
|
2601
|
+
if (customFile && await fs11.pathExists(customFile)) {
|
|
2602
|
+
await fs11.copy(customFile, destPath);
|
|
2533
2603
|
logger.info(`Dockerfile: ${destPath} (copied from ${customFile})`);
|
|
2534
2604
|
return;
|
|
2535
2605
|
}
|
|
2536
2606
|
const dockerfile = buildDockerfileContent(platform, includedFolders || []);
|
|
2537
|
-
await
|
|
2607
|
+
await fs11.writeFile(destPath, dockerfile);
|
|
2538
2608
|
logger.info(`Dockerfile: ${destPath}`);
|
|
2539
2609
|
}
|
|
2540
2610
|
var init_dockerfile = __esm({
|
|
@@ -2544,15 +2614,15 @@ var init_dockerfile = __esm({
|
|
|
2544
2614
|
});
|
|
2545
2615
|
|
|
2546
2616
|
// src/commands/bundle/index.ts
|
|
2547
|
-
import
|
|
2548
|
-
import
|
|
2617
|
+
import path12 from "path";
|
|
2618
|
+
import fs12 from "fs-extra";
|
|
2549
2619
|
import { getPlatform as getPlatform2 } from "@walkeros/core";
|
|
2550
2620
|
function resolveOutputPath(output, buildOptions) {
|
|
2551
|
-
const resolved =
|
|
2552
|
-
const ext =
|
|
2553
|
-
if (output.endsWith("/") || output.endsWith(
|
|
2621
|
+
const resolved = path12.resolve(output);
|
|
2622
|
+
const ext = path12.extname(resolved);
|
|
2623
|
+
if (output.endsWith("/") || output.endsWith(path12.sep) || !ext) {
|
|
2554
2624
|
const filename = buildOptions.platform === "browser" ? "walker.js" : "bundle.mjs";
|
|
2555
|
-
return
|
|
2625
|
+
return path12.join(resolved, filename);
|
|
2556
2626
|
}
|
|
2557
2627
|
return resolved;
|
|
2558
2628
|
}
|
|
@@ -2582,7 +2652,7 @@ async function bundleCommand(options) {
|
|
|
2582
2652
|
} catch {
|
|
2583
2653
|
throw new Error("Invalid JSON received on stdin");
|
|
2584
2654
|
}
|
|
2585
|
-
configPath =
|
|
2655
|
+
configPath = path12.resolve(process.cwd(), "stdin.config.json");
|
|
2586
2656
|
} else {
|
|
2587
2657
|
const file = options.config || "bundle.config.json";
|
|
2588
2658
|
configPath = resolveAsset(file, "config");
|
|
@@ -2636,19 +2706,25 @@ async function bundleCommand(options) {
|
|
|
2636
2706
|
if (uploadUrl) {
|
|
2637
2707
|
await uploadBundleToUrl(buildOptions.output, uploadUrl);
|
|
2638
2708
|
logger.info(`Uploaded to: ${sanitizeUrl(uploadUrl)}`);
|
|
2639
|
-
await
|
|
2709
|
+
await fs12.remove(buildOptions.output);
|
|
2640
2710
|
}
|
|
2641
2711
|
if (!options.json && !options.all && options.stats && stats) {
|
|
2642
2712
|
displayStats(stats, logger);
|
|
2643
2713
|
}
|
|
2644
2714
|
if (writingToStdout && !options.json) {
|
|
2645
|
-
const bundleContent = await
|
|
2715
|
+
const bundleContent = await fs12.readFile(buildOptions.output);
|
|
2646
2716
|
await writeResult(bundleContent, {});
|
|
2717
|
+
if (process.stdout.isTTY) {
|
|
2718
|
+
const defaultPath = buildOptions.platform === "browser" ? "./dist/walker.js" : "./dist/bundle.mjs";
|
|
2719
|
+
logger.info(
|
|
2720
|
+
`Bundle written to stdout. Use -o ${defaultPath} to write to file.`
|
|
2721
|
+
);
|
|
2722
|
+
}
|
|
2647
2723
|
}
|
|
2648
2724
|
if (options.dockerfile && options.output) {
|
|
2649
2725
|
const platform = getPlatform2(flowSettings);
|
|
2650
2726
|
if (platform) {
|
|
2651
|
-
const outputDir =
|
|
2727
|
+
const outputDir = path12.dirname(buildOptions.output);
|
|
2652
2728
|
const customFile = typeof options.dockerfile === "string" ? options.dockerfile : void 0;
|
|
2653
2729
|
await generateDockerfile(
|
|
2654
2730
|
outputDir,
|
|
@@ -2719,7 +2795,7 @@ Build Summary: ${successCount}/${results.length} succeeded`
|
|
|
2719
2795
|
}
|
|
2720
2796
|
async function bundle(configOrPath, options = {}) {
|
|
2721
2797
|
let rawConfig;
|
|
2722
|
-
let configPath =
|
|
2798
|
+
let configPath = path12.resolve(process.cwd(), "walkeros.config.json");
|
|
2723
2799
|
if (typeof configOrPath === "string") {
|
|
2724
2800
|
configPath = resolveAsset(configOrPath, "config");
|
|
2725
2801
|
rawConfig = await loadJsonConfig(configPath);
|
|
@@ -2775,45 +2851,6 @@ var init_bundle = __esm({
|
|
|
2775
2851
|
}
|
|
2776
2852
|
});
|
|
2777
2853
|
|
|
2778
|
-
// src/commands/push/env-loader.ts
|
|
2779
|
-
var env_loader_exports = {};
|
|
2780
|
-
__export(env_loader_exports, {
|
|
2781
|
-
loadDestinationEnvs: () => loadDestinationEnvs
|
|
2782
|
-
});
|
|
2783
|
-
async function loadDestinationEnvs(destinations, packages, configDir) {
|
|
2784
|
-
const envs = {};
|
|
2785
|
-
const resolveDir = configDir || process.cwd();
|
|
2786
|
-
for (const [destKey, destConfig] of Object.entries(destinations)) {
|
|
2787
|
-
const typedConfig = destConfig;
|
|
2788
|
-
if (!typedConfig.package) {
|
|
2789
|
-
continue;
|
|
2790
|
-
}
|
|
2791
|
-
try {
|
|
2792
|
-
const packageName = typedConfig.package;
|
|
2793
|
-
const isDemoPackage = packageName.includes("-demo");
|
|
2794
|
-
const importPath = isDemoPackage ? resolvePackageImportPath(packageName, packages, resolveDir) : resolvePackageImportPath(packageName, packages, resolveDir, "/dev");
|
|
2795
|
-
const module = await import(importPath);
|
|
2796
|
-
const examplesModule = module.examples || module.default?.examples;
|
|
2797
|
-
const envModule = examplesModule?.env;
|
|
2798
|
-
if (envModule?.push) {
|
|
2799
|
-
envs[destKey] = {
|
|
2800
|
-
init: envModule.init,
|
|
2801
|
-
push: envModule.push,
|
|
2802
|
-
simulation: envModule.simulation || []
|
|
2803
|
-
};
|
|
2804
|
-
}
|
|
2805
|
-
} catch {
|
|
2806
|
-
}
|
|
2807
|
-
}
|
|
2808
|
-
return envs;
|
|
2809
|
-
}
|
|
2810
|
-
var init_env_loader = __esm({
|
|
2811
|
-
"src/commands/push/env-loader.ts"() {
|
|
2812
|
-
"use strict";
|
|
2813
|
-
init_package_path();
|
|
2814
|
-
}
|
|
2815
|
-
});
|
|
2816
|
-
|
|
2817
2854
|
// src/runtime/cache.ts
|
|
2818
2855
|
var cache_exports = {};
|
|
2819
2856
|
__export(cache_exports, {
|
|
@@ -2822,7 +2859,7 @@ __export(cache_exports, {
|
|
|
2822
2859
|
writeCache: () => writeCache
|
|
2823
2860
|
});
|
|
2824
2861
|
import {
|
|
2825
|
-
existsSync as
|
|
2862
|
+
existsSync as existsSync3,
|
|
2826
2863
|
mkdirSync as mkdirSync3,
|
|
2827
2864
|
copyFileSync,
|
|
2828
2865
|
writeFileSync as writeFileSync3,
|
|
@@ -2840,7 +2877,7 @@ function readCache(cacheDir) {
|
|
|
2840
2877
|
try {
|
|
2841
2878
|
const metaPath = join2(cacheDir, "meta.json");
|
|
2842
2879
|
const bundlePath = join2(cacheDir, "bundle.mjs");
|
|
2843
|
-
if (!
|
|
2880
|
+
if (!existsSync3(metaPath) || !existsSync3(bundlePath)) return null;
|
|
2844
2881
|
const meta = JSON.parse(readFileSync2(metaPath, "utf-8"));
|
|
2845
2882
|
return { bundlePath, version: meta.version };
|
|
2846
2883
|
} catch {
|
|
@@ -2850,7 +2887,7 @@ function readCache(cacheDir) {
|
|
|
2850
2887
|
function readCacheConfig(cacheDir) {
|
|
2851
2888
|
try {
|
|
2852
2889
|
const configPath = join2(cacheDir, "config.json");
|
|
2853
|
-
if (!
|
|
2890
|
+
if (!existsSync3(configPath)) return null;
|
|
2854
2891
|
return readFileSync2(configPath, "utf-8");
|
|
2855
2892
|
} catch {
|
|
2856
2893
|
return null;
|
|
@@ -2868,15 +2905,15 @@ __export(utils_exports, {
|
|
|
2868
2905
|
isPreBuiltConfig: () => isPreBuiltConfig,
|
|
2869
2906
|
prepareBundleForRun: () => prepareBundleForRun
|
|
2870
2907
|
});
|
|
2871
|
-
import
|
|
2872
|
-
import
|
|
2908
|
+
import path16 from "path";
|
|
2909
|
+
import fs15 from "fs-extra";
|
|
2873
2910
|
async function prepareBundleForRun(configPath, options) {
|
|
2874
2911
|
const tempDir = getTmpPath(
|
|
2875
2912
|
void 0,
|
|
2876
2913
|
`run-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
|
2877
2914
|
);
|
|
2878
|
-
await
|
|
2879
|
-
const tempPath =
|
|
2915
|
+
await fs15.ensureDir(tempDir);
|
|
2916
|
+
const tempPath = path16.join(tempDir, "bundle.mjs");
|
|
2880
2917
|
await bundle(configPath, {
|
|
2881
2918
|
cache: true,
|
|
2882
2919
|
verbose: options.verbose,
|
|
@@ -2891,7 +2928,7 @@ async function prepareBundleForRun(configPath, options) {
|
|
|
2891
2928
|
return {
|
|
2892
2929
|
bundlePath: tempPath,
|
|
2893
2930
|
cleanup: async () => {
|
|
2894
|
-
await
|
|
2931
|
+
await fs15.remove(tempDir);
|
|
2895
2932
|
}
|
|
2896
2933
|
};
|
|
2897
2934
|
}
|
|
@@ -2910,8 +2947,8 @@ var init_utils3 = __esm({
|
|
|
2910
2947
|
init_bundle();
|
|
2911
2948
|
|
|
2912
2949
|
// src/commands/push/index.ts
|
|
2913
|
-
import
|
|
2914
|
-
import
|
|
2950
|
+
import path15 from "path";
|
|
2951
|
+
import fs14 from "fs-extra";
|
|
2915
2952
|
import {
|
|
2916
2953
|
createIngest,
|
|
2917
2954
|
getPlatform as getPlatform4,
|
|
@@ -2924,28 +2961,28 @@ import {
|
|
|
2924
2961
|
// ../collector/dist/index.mjs
|
|
2925
2962
|
import { assign as o } from "@walkeros/core";
|
|
2926
2963
|
import { assign as r, createLogger as i } from "@walkeros/core";
|
|
2927
|
-
import {
|
|
2928
|
-
import { isArray as
|
|
2929
|
-
import { tryCatch as
|
|
2930
|
-
import { createIngest as
|
|
2931
|
-
import { createIngest as
|
|
2932
|
-
import { assign as
|
|
2933
|
-
import { isObject as
|
|
2934
|
-
import { createIngest as
|
|
2935
|
-
import { useHooks as
|
|
2936
|
-
import { useHooks as
|
|
2937
|
-
function
|
|
2964
|
+
import { assign as a, buildCacheContext as c, clone as u, compileCache as f, checkCache as l, storeCache as d, compileNext as g, createIngest as p, debounce as m, getId as h, getGrantedConsent as y, isDefined as v, isFunction as b, isObject as w, isRouteArray as k, processEventMapping as C, resolveNext as O, tryCatchAsync as j, useHooks as A } from "@walkeros/core";
|
|
2965
|
+
import { isArray as x } from "@walkeros/core";
|
|
2966
|
+
import { tryCatch as q, tryCatchAsync as S } from "@walkeros/core";
|
|
2967
|
+
import { createIngest as $, getMappingValue as D, tryCatchAsync as _, compileNext as I, resolveNext as P, isRouteArray as E, compileCache as M, checkCache as R, storeCache as H, applyUpdate as T, buildCacheContext as G } from "@walkeros/core";
|
|
2968
|
+
import { createIngest as N, isObject as B, tryCatchAsync as U, useHooks as F, compileNext as W, resolveNext as L, isRouteArray as V, compileCache as z, checkCache as J, storeCache as K, buildCacheContext as Q } from "@walkeros/core";
|
|
2969
|
+
import { assign as be, getId as we, isFunction as ke, isString as Ce } from "@walkeros/core";
|
|
2970
|
+
import { isObject as Oe } from "@walkeros/core";
|
|
2971
|
+
import { createIngest as Se, getGrantedConsent as $e, processEventMapping as De, tryCatchAsync as _e, useHooks as Ie } from "@walkeros/core";
|
|
2972
|
+
import { useHooks as Ee, tryCatchAsync as Me } from "@walkeros/core";
|
|
2973
|
+
import { useHooks as Re } from "@walkeros/core";
|
|
2974
|
+
function X(e, n) {
|
|
2938
2975
|
return e.storeId && n.stores[e.storeId] ? n.stores[e.storeId] : n.stores.__cache;
|
|
2939
2976
|
}
|
|
2940
|
-
function
|
|
2977
|
+
function Y(e) {
|
|
2941
2978
|
const n = {};
|
|
2942
2979
|
for (const [t, o2] of Object.entries(e)) {
|
|
2943
2980
|
const e2 = o2.config?.next;
|
|
2944
|
-
e2 && !
|
|
2981
|
+
e2 && !V(e2) ? n[t] = { next: e2 } : n[t] = {};
|
|
2945
2982
|
}
|
|
2946
2983
|
return n;
|
|
2947
2984
|
}
|
|
2948
|
-
function
|
|
2985
|
+
function ee(e, n = {}) {
|
|
2949
2986
|
if (!e) return [];
|
|
2950
2987
|
if (Array.isArray(e)) return e;
|
|
2951
2988
|
const t = [], o2 = /* @__PURE__ */ new Set();
|
|
@@ -2961,23 +2998,23 @@ function Z(e, n = {}) {
|
|
|
2961
2998
|
}
|
|
2962
2999
|
return t;
|
|
2963
3000
|
}
|
|
2964
|
-
async function
|
|
3001
|
+
async function ne(e, n, t) {
|
|
2965
3002
|
if (n.init && !n.config.init) {
|
|
2966
|
-
const o2 = n.type || "unknown", s = e.logger.scope(`transformer:${o2}`), r2 = { collector: e, logger: s, id: t, ingest:
|
|
3003
|
+
const o2 = n.type || "unknown", s = e.logger.scope(`transformer:${o2}`), r2 = { collector: e, logger: s, id: t, ingest: N(t), config: n.config, env: se(n.config.env) };
|
|
2967
3004
|
s.debug("init");
|
|
2968
|
-
const i2 = await
|
|
3005
|
+
const i2 = await F(n.init, "TransformerInit", e.hooks)(r2);
|
|
2969
3006
|
if (false === i2) return false;
|
|
2970
3007
|
n.config = { ...i2 || n.config, env: i2?.env || n.config.env, init: true }, s.debug("init done");
|
|
2971
3008
|
}
|
|
2972
3009
|
return true;
|
|
2973
3010
|
}
|
|
2974
|
-
async function
|
|
2975
|
-
const i2 = n.type || "unknown", a2 = e.logger.scope(`transformer:${i2}`), c2 = { collector: e, logger: a2, id: t, ingest: s, config: n.config, env: { ...
|
|
3011
|
+
async function te(e, n, t, o2, s, r2) {
|
|
3012
|
+
const i2 = n.type || "unknown", a2 = e.logger.scope(`transformer:${i2}`), c2 = { collector: e, logger: a2, id: t, ingest: s, config: n.config, env: { ...se(n.config.env), ...r2 ? { respond: r2 } : {} } };
|
|
2976
3013
|
a2.debug("push", { event: o2.name });
|
|
2977
|
-
const u2 = await
|
|
3014
|
+
const u2 = await F(n.push, "TransformerPush", e.hooks)(o2, c2);
|
|
2978
3015
|
return a2.debug("push done"), u2;
|
|
2979
3016
|
}
|
|
2980
|
-
async function
|
|
3017
|
+
async function oe(e, n, t, o2, s, r2, i2) {
|
|
2981
3018
|
i2 && s?._meta && (s._meta.chainPath = i2);
|
|
2982
3019
|
let a2 = o2, c2 = r2;
|
|
2983
3020
|
for (const o3 of t) {
|
|
@@ -2988,7 +3025,7 @@ async function te(e, n, t, o2, s, r2, i2) {
|
|
|
2988
3025
|
}
|
|
2989
3026
|
if (s && s._meta && s._meta.path.length > 256) return e.logger.error(`Max path length exceeded at ${o3}`), { event: null, respond: c2 };
|
|
2990
3027
|
s && s._meta && (s._meta.hops++, s._meta.path.push(o3));
|
|
2991
|
-
if (!await
|
|
3028
|
+
if (!await U(ne)(e, r3, o3)) return e.logger.error(`Transformer init failed: ${o3}`), { event: null, respond: c2 };
|
|
2992
3029
|
if (i2 && void 0 !== r3.config?.chainMocks?.[i2]) {
|
|
2993
3030
|
const n2 = r3.config.chainMocks[i2];
|
|
2994
3031
|
e.logger.scope(`transformer:${r3.type || "unknown"}`).debug("chainMock", { chain: i2 }), a2 = n2;
|
|
@@ -2999,10 +3036,10 @@ async function te(e, n, t, o2, s, r2, i2) {
|
|
|
2999
3036
|
continue;
|
|
3000
3037
|
}
|
|
3001
3038
|
if (r3.config?.disabled) continue;
|
|
3002
|
-
const u2 = r3.config?.cache, f2 = u2 ?
|
|
3039
|
+
const u2 = r3.config?.cache, f2 = u2 ? z(u2) : void 0, l2 = f2 ? X(f2, e) : void 0;
|
|
3003
3040
|
let d2;
|
|
3004
3041
|
if (f2 && l2) {
|
|
3005
|
-
const e2 =
|
|
3042
|
+
const e2 = Q(s, a2), n2 = J(f2, l2, e2, `t:${o3}`);
|
|
3006
3043
|
if ("HIT" === n2?.status && n2.value) {
|
|
3007
3044
|
if (a2 = n2.value, f2.full) return { event: a2, respond: c2 };
|
|
3008
3045
|
continue;
|
|
@@ -3011,31 +3048,31 @@ async function te(e, n, t, o2, s, r2, i2) {
|
|
|
3011
3048
|
}
|
|
3012
3049
|
const g2 = r3.config.before;
|
|
3013
3050
|
if (g2) {
|
|
3014
|
-
const t2 =
|
|
3051
|
+
const t2 = ee("string" == typeof g2 || Array.isArray(g2) && !V(g2) ? g2 : L(W(g2), Q(s, a2)) || void 0, Y(n));
|
|
3015
3052
|
if (t2.length > 0) {
|
|
3016
|
-
const o4 = await
|
|
3053
|
+
const o4 = await oe(e, n, t2, a2, s, c2, i2);
|
|
3017
3054
|
if (null === o4.event) return { event: null, respond: o4.respond ?? c2 };
|
|
3018
3055
|
o4.respond && (c2 = o4.respond), a2 = Array.isArray(o4.event) ? o4.event[0] : o4.event;
|
|
3019
3056
|
}
|
|
3020
3057
|
}
|
|
3021
|
-
const p2 = await
|
|
3058
|
+
const p2 = await U(te, (n2) => (e.logger.scope(`transformer:${r3.type || "unknown"}`).error("Push failed", { error: n2 }), false))(e, r3, o3, a2, s, c2);
|
|
3022
3059
|
if (false === p2) return { event: null, respond: c2 };
|
|
3023
3060
|
if (Array.isArray(p2)) {
|
|
3024
3061
|
const r4 = t.slice(t.indexOf(o3) + 1), u3 = await Promise.all(p2.map(async (t2) => {
|
|
3025
|
-
const o4 = t2.event || a2, u4 = s ? { ...s, _meta: { ...s._meta, path: [...s._meta.path] } } :
|
|
3062
|
+
const o4 = t2.event || a2, u4 = s ? { ...s, _meta: { ...s._meta, path: [...s._meta.path] } } : N("unknown");
|
|
3026
3063
|
if (t2.next) {
|
|
3027
3064
|
let s2 = t2.next;
|
|
3028
|
-
if (
|
|
3029
|
-
const e2 =
|
|
3030
|
-
s2 =
|
|
3065
|
+
if (V(t2.next)) {
|
|
3066
|
+
const e2 = W(t2.next);
|
|
3067
|
+
s2 = L(e2, Q(u4, o4));
|
|
3031
3068
|
}
|
|
3032
3069
|
if (s2) {
|
|
3033
|
-
const t3 =
|
|
3034
|
-
if (t3.length > 0) return
|
|
3070
|
+
const t3 = ee(s2, Y(n));
|
|
3071
|
+
if (t3.length > 0) return oe(e, n, t3, o4, u4, c2, i2);
|
|
3035
3072
|
}
|
|
3036
3073
|
return { event: o4, respond: c2 };
|
|
3037
3074
|
}
|
|
3038
|
-
return r4.length > 0 ?
|
|
3075
|
+
return r4.length > 0 ? oe(e, n, r4, o4, u4, c2, i2) : { event: o4, respond: c2 };
|
|
3039
3076
|
}));
|
|
3040
3077
|
let f3 = c2;
|
|
3041
3078
|
const l3 = [];
|
|
@@ -3050,41 +3087,41 @@ async function te(e, n, t, o2, s, r2, i2) {
|
|
|
3050
3087
|
const { event: t2, respond: o4, next: r4 } = p2;
|
|
3051
3088
|
if (o4 && (c2 = o4), r4) {
|
|
3052
3089
|
let o5 = r4;
|
|
3053
|
-
if (
|
|
3054
|
-
const e2 =
|
|
3055
|
-
if (o5 =
|
|
3090
|
+
if (V(r4)) {
|
|
3091
|
+
const e2 = W(r4);
|
|
3092
|
+
if (o5 = L(e2, Q(s, a2)), !o5) {
|
|
3056
3093
|
t2 && (a2 = t2);
|
|
3057
3094
|
continue;
|
|
3058
3095
|
}
|
|
3059
3096
|
}
|
|
3060
|
-
const u3 =
|
|
3061
|
-
return u3.length > 0 ?
|
|
3097
|
+
const u3 = ee(o5, Y(n));
|
|
3098
|
+
return u3.length > 0 ? oe(e, n, u3, t2 || a2, s, c2, i2) : (e.logger.warn(`Branch target not found: ${JSON.stringify(r4)}`), { event: null, respond: c2 });
|
|
3062
3099
|
}
|
|
3063
3100
|
t2 && (a2 = t2);
|
|
3064
3101
|
}
|
|
3065
|
-
if (d2 && l2 &&
|
|
3066
|
-
const t2 = r3.config.next, o4 =
|
|
3102
|
+
if (d2 && l2 && K(l2, d2.key, a2, d2.ttl), (!p2 || "object" == typeof p2 && !p2.next) && r3.config.next && V(r3.config.next)) {
|
|
3103
|
+
const t2 = r3.config.next, o4 = W(t2), u3 = L(o4, Q(s, a2));
|
|
3067
3104
|
if (u3) {
|
|
3068
|
-
const t3 =
|
|
3069
|
-
if (t3.length > 0) return
|
|
3105
|
+
const t3 = ee(u3, Y(n));
|
|
3106
|
+
if (t3.length > 0) return oe(e, n, t3, a2, s, c2, i2);
|
|
3070
3107
|
}
|
|
3071
3108
|
return { event: a2, respond: c2 };
|
|
3072
3109
|
}
|
|
3073
3110
|
}
|
|
3074
3111
|
return { event: a2, respond: c2 };
|
|
3075
3112
|
}
|
|
3076
|
-
function
|
|
3077
|
-
return e &&
|
|
3113
|
+
function se(e) {
|
|
3114
|
+
return e && B(e) ? e : {};
|
|
3078
3115
|
}
|
|
3079
|
-
function
|
|
3116
|
+
function Ge(e) {
|
|
3080
3117
|
if (null === e || "object" != typeof e) return e;
|
|
3081
|
-
if (Array.isArray(e)) return e.map(
|
|
3118
|
+
if (Array.isArray(e)) return e.map(Ge);
|
|
3082
3119
|
const n = {};
|
|
3083
|
-
for (const [t, o2] of Object.entries(e)) n[t] = "function" == typeof o2 ? o2 :
|
|
3120
|
+
for (const [t, o2] of Object.entries(e)) n[t] = "function" == typeof o2 ? o2 : Ge(o2);
|
|
3084
3121
|
return n;
|
|
3085
3122
|
}
|
|
3086
|
-
function
|
|
3087
|
-
const n = [], { simulation: t, ...o2 } = e, s =
|
|
3123
|
+
function Ne(e) {
|
|
3124
|
+
const n = [], { simulation: t, ...o2 } = e, s = Ge(o2);
|
|
3088
3125
|
for (const e2 of t) {
|
|
3089
3126
|
const t2 = e2.startsWith("call:") ? e2.slice(5) : e2, o3 = t2.split(".");
|
|
3090
3127
|
let r2 = s;
|
|
@@ -3281,12 +3318,9 @@ function applyOverrides(config, overrides) {
|
|
|
3281
3318
|
}
|
|
3282
3319
|
}
|
|
3283
3320
|
|
|
3284
|
-
// src/commands/push/index.ts
|
|
3285
|
-
init_package_path();
|
|
3286
|
-
|
|
3287
3321
|
// src/commands/push/flow-context.ts
|
|
3288
3322
|
init_utils2();
|
|
3289
|
-
import
|
|
3323
|
+
import path13 from "path";
|
|
3290
3324
|
import { pathToFileURL } from "url";
|
|
3291
3325
|
import { JSDOM, VirtualConsole } from "jsdom";
|
|
3292
3326
|
|
|
@@ -3328,7 +3362,7 @@ function installTimerInterception(options = {}) {
|
|
|
3328
3362
|
if (options.domWindow && options.domWindow !== globalThis) {
|
|
3329
3363
|
patchTarget(options.domWindow);
|
|
3330
3364
|
}
|
|
3331
|
-
const drainMicrotasks = () => new Promise((
|
|
3365
|
+
const drainMicrotasks = () => new Promise((resolve4) => realSetTimeout(resolve4, 0));
|
|
3332
3366
|
async function flush(wallTimeout = 5e3) {
|
|
3333
3367
|
const deadline = Date.now() + wallTimeout;
|
|
3334
3368
|
const maxIterations = 100;
|
|
@@ -3376,7 +3410,15 @@ function installTimerInterception(options = {}) {
|
|
|
3376
3410
|
|
|
3377
3411
|
// src/commands/push/flow-context.ts
|
|
3378
3412
|
async function withFlowContext(options, fn) {
|
|
3379
|
-
const {
|
|
3413
|
+
const {
|
|
3414
|
+
esmPath,
|
|
3415
|
+
platform,
|
|
3416
|
+
logger,
|
|
3417
|
+
snapshotCode,
|
|
3418
|
+
timeout,
|
|
3419
|
+
networkCalls,
|
|
3420
|
+
asyncDrain
|
|
3421
|
+
} = options;
|
|
3380
3422
|
const startTime = Date.now();
|
|
3381
3423
|
const g2 = global;
|
|
3382
3424
|
let savedWindow, savedDocument, savedNavigator;
|
|
@@ -3423,7 +3465,7 @@ async function withFlowContext(options, fn) {
|
|
|
3423
3465
|
vm.runInThisContext(snapshotCode);
|
|
3424
3466
|
}
|
|
3425
3467
|
}
|
|
3426
|
-
const fileUrl = pathToFileURL(
|
|
3468
|
+
const fileUrl = pathToFileURL(path13.resolve(esmPath)).href;
|
|
3427
3469
|
const module = await import(`${fileUrl}?t=${Date.now()}`);
|
|
3428
3470
|
const { wireConfig, startFlow } = module;
|
|
3429
3471
|
if (typeof wireConfig !== "function" || typeof startFlow !== "function") {
|
|
@@ -3434,7 +3476,8 @@ async function withFlowContext(options, fn) {
|
|
|
3434
3476
|
const flowModule = {
|
|
3435
3477
|
wireConfig,
|
|
3436
3478
|
startFlow,
|
|
3437
|
-
__configData: module.__configData
|
|
3479
|
+
__configData: module.__configData,
|
|
3480
|
+
__devExports: module.__devExports
|
|
3438
3481
|
};
|
|
3439
3482
|
if (timerControl) {
|
|
3440
3483
|
const result = await fn(flowModule);
|
|
@@ -3522,51 +3565,41 @@ init_cli_logger();
|
|
|
3522
3565
|
init_tmp();
|
|
3523
3566
|
init_config();
|
|
3524
3567
|
init_bundler();
|
|
3525
|
-
import
|
|
3526
|
-
import
|
|
3568
|
+
import path14 from "path";
|
|
3569
|
+
import fs13 from "fs-extra";
|
|
3527
3570
|
import { getPlatform as getPlatform3 } from "@walkeros/core";
|
|
3528
|
-
async function prepareFlow(
|
|
3571
|
+
async function prepareFlow(input) {
|
|
3529
3572
|
const logger = createCLILogger({
|
|
3530
|
-
silent:
|
|
3531
|
-
verbose:
|
|
3573
|
+
silent: input.silent,
|
|
3574
|
+
verbose: input.verbose
|
|
3532
3575
|
});
|
|
3533
3576
|
logger.debug("Loading flow configuration");
|
|
3534
|
-
const { flowSettings, buildOptions } =
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
logger
|
|
3539
|
-
}
|
|
3540
|
-
);
|
|
3577
|
+
const { flowSettings, buildOptions } = loadBundleConfig(input.config, {
|
|
3578
|
+
configPath: process.cwd(),
|
|
3579
|
+
flowName: input.flow
|
|
3580
|
+
});
|
|
3541
3581
|
const platform = getPlatform3(flowSettings);
|
|
3542
|
-
const configDir = buildOptions.configDir || process.cwd();
|
|
3543
3582
|
const overrides = buildOverrides(
|
|
3544
|
-
{ simulate:
|
|
3583
|
+
{ simulate: input.simulate, mock: input.mock },
|
|
3545
3584
|
flowSettings
|
|
3546
3585
|
);
|
|
3547
|
-
if (
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
for (const [destId, env] of Object.entries(envs)) {
|
|
3555
|
-
if (overrides.destinations[destId] && env.push) {
|
|
3556
|
-
overrides.destinations[destId].env = env.push;
|
|
3557
|
-
if (env.simulation && env.simulation.length > 0) {
|
|
3558
|
-
overrides.destinations[destId].simulation = env.simulation;
|
|
3559
|
-
}
|
|
3586
|
+
if (input.mode === "prebuilt") {
|
|
3587
|
+
return {
|
|
3588
|
+
bundlePath: input.bundlePath,
|
|
3589
|
+
platform,
|
|
3590
|
+
overrides,
|
|
3591
|
+
flowSettings,
|
|
3592
|
+
cleanup: async () => {
|
|
3560
3593
|
}
|
|
3561
|
-
}
|
|
3594
|
+
};
|
|
3562
3595
|
}
|
|
3563
3596
|
logger.debug("Bundling flow configuration");
|
|
3564
3597
|
const tempDir = getTmpPath(
|
|
3565
3598
|
void 0,
|
|
3566
3599
|
`push-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
|
3567
3600
|
);
|
|
3568
|
-
await
|
|
3569
|
-
const bundlePath =
|
|
3601
|
+
await fs13.ensureDir(tempDir);
|
|
3602
|
+
const bundlePath = path14.join(tempDir, "bundle.mjs");
|
|
3570
3603
|
const pushBuildOptions = {
|
|
3571
3604
|
...buildOptions,
|
|
3572
3605
|
output: bundlePath,
|
|
@@ -3582,9 +3615,8 @@ async function prepareFlow(options) {
|
|
|
3582
3615
|
platform,
|
|
3583
3616
|
overrides,
|
|
3584
3617
|
flowSettings,
|
|
3585
|
-
configDir,
|
|
3586
3618
|
cleanup: async () => {
|
|
3587
|
-
await
|
|
3619
|
+
await fs13.remove(tempDir).catch(() => {
|
|
3588
3620
|
});
|
|
3589
3621
|
}
|
|
3590
3622
|
};
|
|
@@ -3599,11 +3631,11 @@ function resolveBeforeChain(before, transformers, ingest, event) {
|
|
|
3599
3631
|
const compiled = compileNext(next);
|
|
3600
3632
|
const resolved = resolveNext(compiled, buildCacheContext(ingest, event));
|
|
3601
3633
|
if (!resolved) return [];
|
|
3602
|
-
return
|
|
3634
|
+
return ee(resolved, Y(transformers));
|
|
3603
3635
|
}
|
|
3604
|
-
return
|
|
3636
|
+
return ee(
|
|
3605
3637
|
next,
|
|
3606
|
-
|
|
3638
|
+
Y(transformers)
|
|
3607
3639
|
);
|
|
3608
3640
|
}
|
|
3609
3641
|
async function pushCore(inputPath, event, options = {}) {
|
|
@@ -3664,7 +3696,7 @@ async function pushCore(inputPath, event, options = {}) {
|
|
|
3664
3696
|
};
|
|
3665
3697
|
} finally {
|
|
3666
3698
|
if (tempDir) {
|
|
3667
|
-
await
|
|
3699
|
+
await fs14.remove(tempDir).catch(() => {
|
|
3668
3700
|
});
|
|
3669
3701
|
}
|
|
3670
3702
|
}
|
|
@@ -3804,35 +3836,15 @@ async function executeConfigPush(options, validatedEvent, logger, setTempDir, sn
|
|
|
3804
3836
|
logger
|
|
3805
3837
|
});
|
|
3806
3838
|
const platform = getPlatform4(flowSettings);
|
|
3807
|
-
const overrides = buildOverrides(
|
|
3808
|
-
{ mock: options.mock },
|
|
3809
|
-
flowSettings
|
|
3810
|
-
);
|
|
3811
|
-
if (overrides.destinations) {
|
|
3812
|
-
const { loadDestinationEnvs: loadDestinationEnvs2 } = await Promise.resolve().then(() => (init_env_loader(), env_loader_exports));
|
|
3813
|
-
const configDir = buildOptions.configDir || process.cwd();
|
|
3814
|
-
const envs = await loadDestinationEnvs2(
|
|
3815
|
-
flowSettings.destinations ?? {},
|
|
3816
|
-
flowSettings.packages,
|
|
3817
|
-
configDir
|
|
3818
|
-
);
|
|
3819
|
-
for (const [destId, env] of Object.entries(envs)) {
|
|
3820
|
-
if (overrides.destinations[destId] && env.push) {
|
|
3821
|
-
overrides.destinations[destId].env = env.push;
|
|
3822
|
-
if (env.simulation && env.simulation.length > 0) {
|
|
3823
|
-
overrides.destinations[destId].simulation = env.simulation;
|
|
3824
|
-
}
|
|
3825
|
-
}
|
|
3826
|
-
}
|
|
3827
|
-
}
|
|
3839
|
+
const overrides = buildOverrides({ mock: options.mock }, flowSettings);
|
|
3828
3840
|
logger.debug("Bundling flow configuration");
|
|
3829
3841
|
const tempDir = getTmpPath(
|
|
3830
3842
|
void 0,
|
|
3831
3843
|
`push-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
|
3832
3844
|
);
|
|
3833
3845
|
setTempDir(tempDir);
|
|
3834
|
-
await
|
|
3835
|
-
const tempPath =
|
|
3846
|
+
await fs14.ensureDir(tempDir);
|
|
3847
|
+
const tempPath = path15.join(tempDir, "bundle.mjs");
|
|
3836
3848
|
const pushBuildOptions = {
|
|
3837
3849
|
...buildOptions,
|
|
3838
3850
|
output: tempPath,
|
|
@@ -3862,9 +3874,9 @@ async function executeBundlePush(bundleContent, platform, validatedEvent, logger
|
|
|
3862
3874
|
`push-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
|
3863
3875
|
);
|
|
3864
3876
|
setTempDir(tempDir);
|
|
3865
|
-
await
|
|
3866
|
-
const tempPath =
|
|
3867
|
-
await
|
|
3877
|
+
await fs14.ensureDir(tempDir);
|
|
3878
|
+
const tempPath = path15.join(tempDir, "bundle.mjs");
|
|
3879
|
+
await fs14.writeFile(tempPath, bundleContent, "utf8");
|
|
3868
3880
|
logger.debug(`Bundle written to: ${tempPath}`);
|
|
3869
3881
|
logger.debug(
|
|
3870
3882
|
`Executing in ${platform} environment (${platform === "web" ? "JSDOM" : "Node.js"})`
|
|
@@ -3883,7 +3895,15 @@ async function executeDestinationPush(esmPath, event, logger, platform, override
|
|
|
3883
3895
|
const startTime = Date.now();
|
|
3884
3896
|
const networkCalls = [];
|
|
3885
3897
|
return withFlowContext(
|
|
3886
|
-
{
|
|
3898
|
+
{
|
|
3899
|
+
esmPath,
|
|
3900
|
+
platform,
|
|
3901
|
+
logger,
|
|
3902
|
+
snapshotCode,
|
|
3903
|
+
timeout,
|
|
3904
|
+
networkCalls,
|
|
3905
|
+
asyncDrain: { timeout: 5e3 }
|
|
3906
|
+
},
|
|
3887
3907
|
async (module) => {
|
|
3888
3908
|
const config = module.wireConfig(module.__configData ?? void 0);
|
|
3889
3909
|
applyOverrides(config, overrides || {});
|
|
@@ -3903,15 +3923,31 @@ async function executeDestinationPush(esmPath, event, logger, platform, override
|
|
|
3903
3923
|
}
|
|
3904
3924
|
);
|
|
3905
3925
|
}
|
|
3906
|
-
async function simulateSource(
|
|
3926
|
+
async function simulateSource(configOrPath, input, options) {
|
|
3907
3927
|
const startTime = Date.now();
|
|
3908
|
-
|
|
3909
|
-
|
|
3928
|
+
let config;
|
|
3929
|
+
if (typeof configOrPath === "string") {
|
|
3930
|
+
config = await loadJsonConfig(configOrPath);
|
|
3931
|
+
} else {
|
|
3932
|
+
config = configOrPath;
|
|
3933
|
+
}
|
|
3934
|
+
const prepareInput = options.bundlePath ? {
|
|
3935
|
+
mode: "prebuilt",
|
|
3936
|
+
bundlePath: options.bundlePath,
|
|
3937
|
+
config,
|
|
3910
3938
|
flow: options.flow,
|
|
3911
3939
|
simulate: ["source." + options.sourceId],
|
|
3912
3940
|
silent: options.silent,
|
|
3913
3941
|
verbose: options.verbose
|
|
3914
|
-
}
|
|
3942
|
+
} : {
|
|
3943
|
+
mode: "build",
|
|
3944
|
+
config,
|
|
3945
|
+
flow: options.flow,
|
|
3946
|
+
simulate: ["source." + options.sourceId],
|
|
3947
|
+
silent: options.silent,
|
|
3948
|
+
verbose: options.verbose
|
|
3949
|
+
};
|
|
3950
|
+
const prepared = await prepareFlow(prepareInput);
|
|
3915
3951
|
try {
|
|
3916
3952
|
const logger = createCLILogger({
|
|
3917
3953
|
silent: options.silent,
|
|
@@ -3919,22 +3955,7 @@ async function simulateSource(configPath, input, options) {
|
|
|
3919
3955
|
});
|
|
3920
3956
|
const sourceConfig = (prepared.flowSettings.sources ?? {})[options.sourceId];
|
|
3921
3957
|
if (!sourceConfig?.package) {
|
|
3922
|
-
throw new Error(
|
|
3923
|
-
`Source "${options.sourceId}" has no package defined`
|
|
3924
|
-
);
|
|
3925
|
-
}
|
|
3926
|
-
const devPath = resolvePackageImportPath(
|
|
3927
|
-
sourceConfig.package,
|
|
3928
|
-
prepared.flowSettings.packages,
|
|
3929
|
-
prepared.configDir,
|
|
3930
|
-
"/dev"
|
|
3931
|
-
);
|
|
3932
|
-
const devModule = await import(devPath);
|
|
3933
|
-
const createTrigger = devModule.examples?.createTrigger || devModule.default?.examples?.createTrigger;
|
|
3934
|
-
if (!createTrigger) {
|
|
3935
|
-
throw new Error(
|
|
3936
|
-
`Source package "${sourceConfig.package}" has no createTrigger in /dev export`
|
|
3937
|
-
);
|
|
3958
|
+
throw new Error(`Source "${options.sourceId}" has no package defined`);
|
|
3938
3959
|
}
|
|
3939
3960
|
let snapshotCode;
|
|
3940
3961
|
if (options.snapshot) {
|
|
@@ -3953,17 +3974,26 @@ async function simulateSource(configPath, input, options) {
|
|
|
3953
3974
|
networkCalls
|
|
3954
3975
|
},
|
|
3955
3976
|
async (module) => {
|
|
3956
|
-
const
|
|
3957
|
-
|
|
3977
|
+
const devExports = module.__devExports?.[sourceConfig.package];
|
|
3978
|
+
const createTrigger = devExports?.examples?.createTrigger;
|
|
3979
|
+
if (!createTrigger) {
|
|
3980
|
+
throw new Error(
|
|
3981
|
+
`Source package "${sourceConfig.package}" has no createTrigger in /dev export`
|
|
3982
|
+
);
|
|
3983
|
+
}
|
|
3984
|
+
const flowConfig = module.wireConfig(module.__configData ?? void 0);
|
|
3985
|
+
applyOverrides(flowConfig, prepared.overrides);
|
|
3958
3986
|
const captured = [];
|
|
3959
|
-
|
|
3960
|
-
...
|
|
3987
|
+
flowConfig.hooks = {
|
|
3988
|
+
...flowConfig.hooks || {},
|
|
3961
3989
|
prePush: ({ fn }, event) => {
|
|
3962
3990
|
captured.push({ event, timestamp: Date.now() });
|
|
3963
3991
|
return { ok: true };
|
|
3964
3992
|
}
|
|
3965
3993
|
};
|
|
3966
|
-
const instance = await createTrigger(
|
|
3994
|
+
const instance = await createTrigger(flowConfig, {
|
|
3995
|
+
sourceId: options.sourceId
|
|
3996
|
+
});
|
|
3967
3997
|
const { trigger } = instance;
|
|
3968
3998
|
logger.info("Simulating source");
|
|
3969
3999
|
const inputRecord = input ?? {};
|
|
@@ -3991,7 +4021,7 @@ async function simulateSource(configPath, input, options) {
|
|
|
3991
4021
|
await prepared.cleanup();
|
|
3992
4022
|
}
|
|
3993
4023
|
}
|
|
3994
|
-
async function simulateTransformer(
|
|
4024
|
+
async function simulateTransformer(configOrPath, event, options) {
|
|
3995
4025
|
const startTime = Date.now();
|
|
3996
4026
|
const parsed = schemas3.PartialEventSchema.safeParse(event);
|
|
3997
4027
|
if (!parsed.success) {
|
|
@@ -4001,14 +4031,31 @@ async function simulateTransformer(configPath, event, options) {
|
|
|
4001
4031
|
error: parsed.error.message
|
|
4002
4032
|
};
|
|
4003
4033
|
}
|
|
4004
|
-
|
|
4005
|
-
|
|
4034
|
+
let config;
|
|
4035
|
+
if (typeof configOrPath === "string") {
|
|
4036
|
+
config = await loadJsonConfig(configOrPath);
|
|
4037
|
+
} else {
|
|
4038
|
+
config = configOrPath;
|
|
4039
|
+
}
|
|
4040
|
+
const prepareInput = options.bundlePath ? {
|
|
4041
|
+
mode: "prebuilt",
|
|
4042
|
+
bundlePath: options.bundlePath,
|
|
4043
|
+
config,
|
|
4006
4044
|
flow: options.flow,
|
|
4007
4045
|
simulate: ["transformer." + options.transformerId],
|
|
4008
4046
|
mock: options.mock,
|
|
4009
4047
|
silent: options.silent,
|
|
4010
4048
|
verbose: options.verbose
|
|
4011
|
-
}
|
|
4049
|
+
} : {
|
|
4050
|
+
mode: "build",
|
|
4051
|
+
config,
|
|
4052
|
+
flow: options.flow,
|
|
4053
|
+
simulate: ["transformer." + options.transformerId],
|
|
4054
|
+
mock: options.mock,
|
|
4055
|
+
silent: options.silent,
|
|
4056
|
+
verbose: options.verbose
|
|
4057
|
+
};
|
|
4058
|
+
const prepared = await prepareFlow(prepareInput);
|
|
4012
4059
|
try {
|
|
4013
4060
|
const logger = createCLILogger({
|
|
4014
4061
|
silent: options.silent,
|
|
@@ -4031,11 +4078,11 @@ async function simulateTransformer(configPath, event, options) {
|
|
|
4031
4078
|
networkCalls
|
|
4032
4079
|
},
|
|
4033
4080
|
async (module) => {
|
|
4034
|
-
const
|
|
4035
|
-
applyOverrides(
|
|
4036
|
-
if (
|
|
4037
|
-
if (
|
|
4038
|
-
const result = await module.startFlow(
|
|
4081
|
+
const flowConfig = module.wireConfig(module.__configData ?? void 0);
|
|
4082
|
+
applyOverrides(flowConfig, prepared.overrides);
|
|
4083
|
+
if (flowConfig.sources) flowConfig.sources = {};
|
|
4084
|
+
if (flowConfig.destinations) flowConfig.destinations = {};
|
|
4085
|
+
const result = await module.startFlow(flowConfig);
|
|
4039
4086
|
if (!result?.collector)
|
|
4040
4087
|
throw new Error("Invalid bundle: collector not available");
|
|
4041
4088
|
const collector = result.collector;
|
|
@@ -4045,7 +4092,7 @@ async function simulateTransformer(configPath, event, options) {
|
|
|
4045
4092
|
`Transformer "${options.transformerId}" not found in collector. Available: ${Object.keys(collector.transformers || {}).join(", ") || "none"}`
|
|
4046
4093
|
);
|
|
4047
4094
|
}
|
|
4048
|
-
const initialized = await
|
|
4095
|
+
const initialized = await ne(
|
|
4049
4096
|
collector,
|
|
4050
4097
|
transformer,
|
|
4051
4098
|
options.transformerId
|
|
@@ -4070,7 +4117,7 @@ async function simulateTransformer(configPath, event, options) {
|
|
|
4070
4117
|
processedEvent
|
|
4071
4118
|
);
|
|
4072
4119
|
if (beforeChainIds.length > 0) {
|
|
4073
|
-
const beforeResult = await
|
|
4120
|
+
const beforeResult = await oe(
|
|
4074
4121
|
collector,
|
|
4075
4122
|
collector.transformers,
|
|
4076
4123
|
beforeChainIds,
|
|
@@ -4091,7 +4138,7 @@ async function simulateTransformer(configPath, event, options) {
|
|
|
4091
4138
|
processedEvent = Array.isArray(beforeResult) ? beforeResult[0] : beforeResult;
|
|
4092
4139
|
}
|
|
4093
4140
|
}
|
|
4094
|
-
const pushResult = await
|
|
4141
|
+
const pushResult = await te(
|
|
4095
4142
|
collector,
|
|
4096
4143
|
transformer,
|
|
4097
4144
|
options.transformerId,
|
|
@@ -4131,7 +4178,7 @@ async function simulateTransformer(configPath, event, options) {
|
|
|
4131
4178
|
await prepared.cleanup();
|
|
4132
4179
|
}
|
|
4133
4180
|
}
|
|
4134
|
-
async function simulateDestination(
|
|
4181
|
+
async function simulateDestination(configOrPath, event, options) {
|
|
4135
4182
|
const startTime = Date.now();
|
|
4136
4183
|
const parsed = schemas3.PartialEventSchema.safeParse(event);
|
|
4137
4184
|
if (!parsed.success) {
|
|
@@ -4141,14 +4188,31 @@ async function simulateDestination(configPath, event, options) {
|
|
|
4141
4188
|
error: parsed.error.message
|
|
4142
4189
|
};
|
|
4143
4190
|
}
|
|
4144
|
-
|
|
4145
|
-
|
|
4191
|
+
let config;
|
|
4192
|
+
if (typeof configOrPath === "string") {
|
|
4193
|
+
config = await loadJsonConfig(configOrPath);
|
|
4194
|
+
} else {
|
|
4195
|
+
config = configOrPath;
|
|
4196
|
+
}
|
|
4197
|
+
const prepareInput = options.bundlePath ? {
|
|
4198
|
+
mode: "prebuilt",
|
|
4199
|
+
bundlePath: options.bundlePath,
|
|
4200
|
+
config,
|
|
4146
4201
|
flow: options.flow,
|
|
4147
4202
|
simulate: ["destination." + options.destinationId],
|
|
4148
4203
|
mock: options.mock,
|
|
4149
4204
|
silent: options.silent,
|
|
4150
4205
|
verbose: options.verbose
|
|
4151
|
-
}
|
|
4206
|
+
} : {
|
|
4207
|
+
mode: "build",
|
|
4208
|
+
config,
|
|
4209
|
+
flow: options.flow,
|
|
4210
|
+
simulate: ["destination." + options.destinationId],
|
|
4211
|
+
mock: options.mock,
|
|
4212
|
+
silent: options.silent,
|
|
4213
|
+
verbose: options.verbose
|
|
4214
|
+
};
|
|
4215
|
+
const prepared = await prepareFlow(prepareInput);
|
|
4152
4216
|
try {
|
|
4153
4217
|
const logger = createCLILogger({
|
|
4154
4218
|
silent: options.silent,
|
|
@@ -4170,25 +4234,32 @@ async function simulateDestination(configPath, event, options) {
|
|
|
4170
4234
|
networkCalls
|
|
4171
4235
|
},
|
|
4172
4236
|
async (module) => {
|
|
4173
|
-
const
|
|
4174
|
-
applyOverrides(
|
|
4175
|
-
const
|
|
4237
|
+
const flowConfig = module.wireConfig(module.__configData ?? void 0);
|
|
4238
|
+
applyOverrides(flowConfig, prepared.overrides);
|
|
4239
|
+
const destPkg = (prepared.flowSettings.destinations ?? {})[options.destinationId];
|
|
4176
4240
|
let trackedCalls = [];
|
|
4177
|
-
if (
|
|
4178
|
-
const
|
|
4179
|
-
const
|
|
4180
|
-
if (
|
|
4181
|
-
const
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4241
|
+
if (destPkg?.package) {
|
|
4242
|
+
const devExports = module.__devExports?.[destPkg.package];
|
|
4243
|
+
const devEnv = devExports?.examples?.env;
|
|
4244
|
+
if (devEnv?.push) {
|
|
4245
|
+
const destinations = flowConfig.destinations;
|
|
4246
|
+
const destConfig = destinations[options.destinationId]?.config;
|
|
4247
|
+
if (destConfig) {
|
|
4248
|
+
destConfig.env = devEnv.push;
|
|
4249
|
+
}
|
|
4250
|
+
if (devEnv.simulation?.length) {
|
|
4251
|
+
const combined = {
|
|
4252
|
+
...devEnv.push,
|
|
4253
|
+
simulation: devEnv.simulation
|
|
4254
|
+
};
|
|
4255
|
+
const { wrappedEnv, calls } = Ne(combined);
|
|
4256
|
+
if (destConfig) destConfig.env = wrappedEnv;
|
|
4257
|
+
trackedCalls = calls;
|
|
4258
|
+
}
|
|
4188
4259
|
}
|
|
4189
4260
|
}
|
|
4190
|
-
if (
|
|
4191
|
-
const result = await module.startFlow(
|
|
4261
|
+
if (flowConfig.sources) flowConfig.sources = {};
|
|
4262
|
+
const result = await module.startFlow(flowConfig);
|
|
4192
4263
|
if (!result?.collector)
|
|
4193
4264
|
throw new Error("Invalid bundle: collector not available");
|
|
4194
4265
|
const collector = result.collector;
|
|
@@ -4228,17 +4299,17 @@ init_core();
|
|
|
4228
4299
|
init_tmp();
|
|
4229
4300
|
init_config_file();
|
|
4230
4301
|
init_auth();
|
|
4231
|
-
import
|
|
4302
|
+
import path17 from "path";
|
|
4232
4303
|
import { writeFileSync as writeFileSync5 } from "fs";
|
|
4233
4304
|
import { homedir as homedir2 } from "os";
|
|
4234
4305
|
import { join as join4 } from "path";
|
|
4235
4306
|
|
|
4236
4307
|
// src/runtime/resolve-bundle.ts
|
|
4237
4308
|
init_stdin();
|
|
4238
|
-
import { existsSync as
|
|
4309
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
4239
4310
|
import { dirname } from "path";
|
|
4240
4311
|
function getDefaultWritePath() {
|
|
4241
|
-
if (
|
|
4312
|
+
if (existsSync2("/app/flow")) return "/app/flow/bundle.mjs";
|
|
4242
4313
|
return "/tmp/walkeros-bundle.mjs";
|
|
4243
4314
|
}
|
|
4244
4315
|
function isUrl2(value) {
|
|
@@ -4246,7 +4317,7 @@ function isUrl2(value) {
|
|
|
4246
4317
|
}
|
|
4247
4318
|
function writeBundleToDisk(writePath, content) {
|
|
4248
4319
|
const dir = dirname(writePath);
|
|
4249
|
-
if (!
|
|
4320
|
+
if (!existsSync2(dir)) {
|
|
4250
4321
|
mkdirSync2(dir, { recursive: true });
|
|
4251
4322
|
}
|
|
4252
4323
|
writeFileSync2(writePath, content, "utf-8");
|
|
@@ -4272,7 +4343,7 @@ async function readBundleFromStdin(writePath) {
|
|
|
4272
4343
|
}
|
|
4273
4344
|
async function resolveBundle(bundleEnv) {
|
|
4274
4345
|
const writePath = getDefaultWritePath();
|
|
4275
|
-
if (!isUrl2(bundleEnv) &&
|
|
4346
|
+
if (!isUrl2(bundleEnv) && existsSync2(bundleEnv)) {
|
|
4276
4347
|
return { path: bundleEnv, source: "file" };
|
|
4277
4348
|
}
|
|
4278
4349
|
if (isUrl2(bundleEnv)) {
|
|
@@ -4327,7 +4398,7 @@ init_cache();
|
|
|
4327
4398
|
|
|
4328
4399
|
// src/commands/run/validators.ts
|
|
4329
4400
|
init_asset_resolver();
|
|
4330
|
-
import { existsSync as
|
|
4401
|
+
import { existsSync as existsSync4 } from "fs";
|
|
4331
4402
|
|
|
4332
4403
|
// src/schemas/primitives.ts
|
|
4333
4404
|
import { z as z2 } from "@walkeros/core/dev";
|
|
@@ -4421,7 +4492,7 @@ var PushInputSchema = z7.object(PushInputShape);
|
|
|
4421
4492
|
// src/commands/run/validators.ts
|
|
4422
4493
|
function validateFlowFile(filePath) {
|
|
4423
4494
|
const absolutePath = resolveAsset(filePath, "bundle");
|
|
4424
|
-
if (!
|
|
4495
|
+
if (!existsSync4(absolutePath)) {
|
|
4425
4496
|
throw new Error(
|
|
4426
4497
|
`Flow file not found: ${filePath}
|
|
4427
4498
|
Resolved path: ${absolutePath}
|
|
@@ -4447,12 +4518,12 @@ init_utils3();
|
|
|
4447
4518
|
// src/commands/run/pipeline.ts
|
|
4448
4519
|
init_tmp();
|
|
4449
4520
|
import { writeFileSync as writeFileSync4 } from "fs";
|
|
4450
|
-
import
|
|
4521
|
+
import fs16 from "fs-extra";
|
|
4451
4522
|
|
|
4452
4523
|
// src/runtime/health-server.ts
|
|
4453
4524
|
import http from "http";
|
|
4454
4525
|
function createHealthServer(port, logger) {
|
|
4455
|
-
return new Promise((
|
|
4526
|
+
return new Promise((resolve4, reject) => {
|
|
4456
4527
|
let flowHandler = null;
|
|
4457
4528
|
const server = http.createServer((req, res) => {
|
|
4458
4529
|
if (req.url === "/health" && req.method === "GET") {
|
|
@@ -4479,7 +4550,7 @@ function createHealthServer(port, logger) {
|
|
|
4479
4550
|
server.headersTimeout = 1e4;
|
|
4480
4551
|
server.listen(port, "0.0.0.0", () => {
|
|
4481
4552
|
logger.info(`Health server listening on port ${port}`);
|
|
4482
|
-
|
|
4553
|
+
resolve4({
|
|
4483
4554
|
server,
|
|
4484
4555
|
setFlowHandler(handler) {
|
|
4485
4556
|
flowHandler = handler;
|
|
@@ -4573,9 +4644,9 @@ import { randomBytes } from "crypto";
|
|
|
4573
4644
|
|
|
4574
4645
|
// src/version.ts
|
|
4575
4646
|
import { readFileSync as readFileSync3 } from "fs";
|
|
4576
|
-
import { fileURLToPath
|
|
4647
|
+
import { fileURLToPath } from "url";
|
|
4577
4648
|
import { dirname as dirname3, join as join3 } from "path";
|
|
4578
|
-
var versionFilename =
|
|
4649
|
+
var versionFilename = fileURLToPath(import.meta.url);
|
|
4579
4650
|
var versionDirname = dirname3(versionFilename);
|
|
4580
4651
|
function findPackageJson() {
|
|
4581
4652
|
const paths = [
|
|
@@ -4868,7 +4939,7 @@ async function runPipeline(options) {
|
|
|
4868
4939
|
await currentBundleCleanup().catch(() => {
|
|
4869
4940
|
});
|
|
4870
4941
|
if (currentConfigPath)
|
|
4871
|
-
await
|
|
4942
|
+
await fs16.remove(currentConfigPath).catch(() => {
|
|
4872
4943
|
});
|
|
4873
4944
|
currentBundleCleanup = newBundleResult.cleanup;
|
|
4874
4945
|
currentConfigPath = tmpConfigPath;
|
|
@@ -4895,7 +4966,7 @@ async function runPipeline(options) {
|
|
|
4895
4966
|
await healthServer.close();
|
|
4896
4967
|
if (currentBundleCleanup) await currentBundleCleanup().catch(() => {
|
|
4897
4968
|
});
|
|
4898
|
-
if (currentConfigPath) await
|
|
4969
|
+
if (currentConfigPath) await fs16.remove(currentConfigPath).catch(() => {
|
|
4899
4970
|
});
|
|
4900
4971
|
logger.info("Shutdown complete");
|
|
4901
4972
|
clearTimeout(forceTimer);
|
|
@@ -5045,7 +5116,7 @@ async function resolveBundlePath(configInput, apiConfig, logger) {
|
|
|
5045
5116
|
logger.info(`Bundle: ${resolved.path}`);
|
|
5046
5117
|
}
|
|
5047
5118
|
if (isPreBuiltConfig(resolved.path)) {
|
|
5048
|
-
return
|
|
5119
|
+
return path17.resolve(resolved.path);
|
|
5049
5120
|
}
|
|
5050
5121
|
const flowFile = validateFlowFile(resolved.path);
|
|
5051
5122
|
logger.debug("Building flow bundle");
|
|
@@ -5111,7 +5182,7 @@ async function resolveBundlePath(configInput, apiConfig, logger) {
|
|
|
5111
5182
|
}
|
|
5112
5183
|
const defaultFile = "server-collect.mjs";
|
|
5113
5184
|
logger.debug(`No config specified, using default: ${defaultFile}`);
|
|
5114
|
-
return
|
|
5185
|
+
return path17.resolve(defaultFile);
|
|
5115
5186
|
}
|
|
5116
5187
|
async function run(options) {
|
|
5117
5188
|
const startTime = Date.now();
|
|
@@ -5371,18 +5442,29 @@ function validateFlow(input, options = {}) {
|
|
|
5371
5442
|
}
|
|
5372
5443
|
}
|
|
5373
5444
|
}
|
|
5374
|
-
|
|
5375
|
-
if (
|
|
5376
|
-
for (const [
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5445
|
+
let totalPackageCount = 0;
|
|
5446
|
+
if (flows && typeof flows === "object") {
|
|
5447
|
+
for (const [flowName, flowValue] of Object.entries(
|
|
5448
|
+
flows
|
|
5449
|
+
)) {
|
|
5450
|
+
const flow = flowValue;
|
|
5451
|
+
const packages = flow.bundle?.packages;
|
|
5452
|
+
if (packages && typeof packages === "object") {
|
|
5453
|
+
for (const [pkgName, pkgConfig] of Object.entries(packages)) {
|
|
5454
|
+
if (!pkgConfig.version && !pkgConfig.path) {
|
|
5455
|
+
warnings.push({
|
|
5456
|
+
path: `flows.${flowName}.bundle.packages.${pkgName}`,
|
|
5457
|
+
message: `Package "${pkgName}" has no version specified`,
|
|
5458
|
+
suggestion: "Consider specifying a version for reproducible builds"
|
|
5459
|
+
});
|
|
5460
|
+
}
|
|
5461
|
+
}
|
|
5462
|
+
totalPackageCount += Object.keys(packages).length;
|
|
5383
5463
|
}
|
|
5384
5464
|
}
|
|
5385
|
-
|
|
5465
|
+
}
|
|
5466
|
+
if (totalPackageCount > 0) {
|
|
5467
|
+
details.packageCount = totalPackageCount;
|
|
5386
5468
|
}
|
|
5387
5469
|
if (coreResult.context) {
|
|
5388
5470
|
details.context = coreResult.context;
|
|
@@ -6748,20 +6830,101 @@ async function feedbackCommand(text) {
|
|
|
6748
6830
|
}
|
|
6749
6831
|
}
|
|
6750
6832
|
function promptUser(question) {
|
|
6751
|
-
return new Promise((
|
|
6833
|
+
return new Promise((resolve4) => {
|
|
6752
6834
|
const rl = createInterface({
|
|
6753
6835
|
input: process.stdin,
|
|
6754
6836
|
output: process.stderr
|
|
6755
6837
|
});
|
|
6756
6838
|
rl.question(question, (answer) => {
|
|
6757
6839
|
rl.close();
|
|
6758
|
-
|
|
6840
|
+
resolve4(answer);
|
|
6759
6841
|
});
|
|
6760
6842
|
});
|
|
6761
6843
|
}
|
|
6762
6844
|
|
|
6763
6845
|
// src/index.ts
|
|
6764
6846
|
init_bundle();
|
|
6847
|
+
|
|
6848
|
+
// src/commands/bundle/wrap.ts
|
|
6849
|
+
init_bundler();
|
|
6850
|
+
import * as path18 from "path";
|
|
6851
|
+
import * as os2 from "os";
|
|
6852
|
+
import fs17 from "fs-extra";
|
|
6853
|
+
import * as esbuild2 from "esbuild";
|
|
6854
|
+
async function wrapSkeleton(options) {
|
|
6855
|
+
const {
|
|
6856
|
+
skeletonPath,
|
|
6857
|
+
platform,
|
|
6858
|
+
outputPath,
|
|
6859
|
+
windowCollector,
|
|
6860
|
+
windowElb,
|
|
6861
|
+
target,
|
|
6862
|
+
minify = true,
|
|
6863
|
+
minifyOptions
|
|
6864
|
+
} = options;
|
|
6865
|
+
if (options.previewScope && !/^[a-zA-Z0-9_-]{1,64}$/.test(options.previewScope)) {
|
|
6866
|
+
throw new Error(
|
|
6867
|
+
`Invalid previewScope "${options.previewScope}". Must match /^[a-zA-Z0-9_-]{1,64}$/.`
|
|
6868
|
+
);
|
|
6869
|
+
}
|
|
6870
|
+
if (options.previewOrigin && !/^[a-z0-9.-]+$/.test(options.previewOrigin)) {
|
|
6871
|
+
throw new Error(
|
|
6872
|
+
`Invalid previewOrigin "${options.previewOrigin}". Must be a bare hostname matching /^[a-z0-9.-]+$/.`
|
|
6873
|
+
);
|
|
6874
|
+
}
|
|
6875
|
+
if (!await fs17.pathExists(skeletonPath)) {
|
|
6876
|
+
throw new Error(`wrapSkeleton: skeleton not found at ${skeletonPath}`);
|
|
6877
|
+
}
|
|
6878
|
+
const absoluteSkeletonPath = path18.resolve(skeletonPath);
|
|
6879
|
+
const entryText = platform === "browser" ? generateWrapEntry(absoluteSkeletonPath, {
|
|
6880
|
+
...windowCollector ? { windowCollector } : {},
|
|
6881
|
+
...windowElb ? { windowElb } : {},
|
|
6882
|
+
...options.previewOrigin ? { previewOrigin: options.previewOrigin } : {},
|
|
6883
|
+
...options.previewScope ? { previewScope: options.previewScope } : {}
|
|
6884
|
+
}) : generateWrapEntryServer(absoluteSkeletonPath);
|
|
6885
|
+
const entryDir = await fs17.mkdtemp(path18.join(os2.tmpdir(), "walkeros-wrap-"));
|
|
6886
|
+
const entryPath = path18.join(entryDir, "entry.mjs");
|
|
6887
|
+
try {
|
|
6888
|
+
await fs17.writeFile(entryPath, entryText);
|
|
6889
|
+
await fs17.ensureDir(path18.dirname(outputPath));
|
|
6890
|
+
const esbuildOptions = {
|
|
6891
|
+
entryPoints: [entryPath],
|
|
6892
|
+
bundle: true,
|
|
6893
|
+
format: "esm",
|
|
6894
|
+
platform,
|
|
6895
|
+
outfile: outputPath,
|
|
6896
|
+
treeShaking: true,
|
|
6897
|
+
logLevel: "error",
|
|
6898
|
+
minify,
|
|
6899
|
+
...minify && {
|
|
6900
|
+
minifyWhitespace: minifyOptions?.whitespace ?? true,
|
|
6901
|
+
minifyIdentifiers: minifyOptions?.identifiers ?? true,
|
|
6902
|
+
minifySyntax: minifyOptions?.syntax ?? true,
|
|
6903
|
+
legalComments: minifyOptions?.legalComments ?? "none",
|
|
6904
|
+
charset: "utf8"
|
|
6905
|
+
}
|
|
6906
|
+
};
|
|
6907
|
+
if (platform === "browser") {
|
|
6908
|
+
esbuildOptions.define = {
|
|
6909
|
+
"process.env.NODE_ENV": '"production"',
|
|
6910
|
+
global: "globalThis"
|
|
6911
|
+
};
|
|
6912
|
+
esbuildOptions.target = target ?? "es2018";
|
|
6913
|
+
} else {
|
|
6914
|
+
esbuildOptions.external = getNodeExternals();
|
|
6915
|
+
esbuildOptions.banner = {
|
|
6916
|
+
js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
|
|
6917
|
+
};
|
|
6918
|
+
esbuildOptions.target = target ?? "node18";
|
|
6919
|
+
}
|
|
6920
|
+
await esbuild2.build(esbuildOptions);
|
|
6921
|
+
} finally {
|
|
6922
|
+
await fs17.remove(entryDir).catch(() => {
|
|
6923
|
+
});
|
|
6924
|
+
}
|
|
6925
|
+
}
|
|
6926
|
+
|
|
6927
|
+
// src/index.ts
|
|
6765
6928
|
init_auth();
|
|
6766
6929
|
init_http();
|
|
6767
6930
|
init_api_client();
|
|
@@ -6940,6 +7103,7 @@ export {
|
|
|
6940
7103
|
validateCommand,
|
|
6941
7104
|
whoami,
|
|
6942
7105
|
whoamiCommand,
|
|
7106
|
+
wrapSkeleton,
|
|
6943
7107
|
writeConfig
|
|
6944
7108
|
};
|
|
6945
7109
|
//# sourceMappingURL=index.js.map
|