@walkeros/cli 3.2.0 → 3.3.0-next-1776113011459
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 +15708 -15746
- 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 +697 -459
- 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,43 @@ 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);
|
|
968
|
+
}
|
|
969
|
+
function getNestedPackageDirectory(baseDir, consumerName, nestedPackageName) {
|
|
970
|
+
return path8.join(
|
|
971
|
+
baseDir,
|
|
972
|
+
"node_modules",
|
|
973
|
+
consumerName,
|
|
974
|
+
"node_modules",
|
|
975
|
+
nestedPackageName
|
|
976
|
+
);
|
|
1010
977
|
}
|
|
1011
|
-
async function collectAllSpecs(packages, logger, configDir) {
|
|
978
|
+
async function collectAllSpecs(packages, logger, configDir, overrides = {}) {
|
|
1012
979
|
const allSpecs = /* @__PURE__ */ new Map();
|
|
1013
980
|
const visited = /* @__PURE__ */ new Set();
|
|
981
|
+
const directLocalNames = new Set(
|
|
982
|
+
packages.filter((p2) => p2.path).map((p2) => p2.name)
|
|
983
|
+
);
|
|
984
|
+
for (const overrideName of Object.keys(overrides)) {
|
|
985
|
+
if (directLocalNames.has(overrideName)) {
|
|
986
|
+
logger.warn(
|
|
987
|
+
`Override for ${overrideName} ignored \u2014 direct package is a local path`
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
const substituteDep = (depName, depSpec, source, from, optional) => {
|
|
992
|
+
const overrideSpec = overrides[depName];
|
|
993
|
+
if (overrideSpec) {
|
|
994
|
+
return {
|
|
995
|
+
name: depName,
|
|
996
|
+
spec: overrideSpec,
|
|
997
|
+
source: "override",
|
|
998
|
+
from: `override (was ${depSpec} from ${from})`,
|
|
999
|
+
optional
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
return { name: depName, spec: depSpec, source, from, optional };
|
|
1003
|
+
};
|
|
1014
1004
|
const queue = packages.map((pkg) => ({
|
|
1015
1005
|
name: pkg.name,
|
|
1016
1006
|
spec: pkg.version,
|
|
@@ -1033,22 +1023,18 @@ async function collectAllSpecs(packages, logger, configDir) {
|
|
|
1033
1023
|
localPath: item.localPath
|
|
1034
1024
|
});
|
|
1035
1025
|
if (item.localPath) {
|
|
1036
|
-
const resolvedPath =
|
|
1037
|
-
const candidatePath =
|
|
1038
|
-
const hasPkgJson = await
|
|
1026
|
+
const resolvedPath = path8.isAbsolute(item.localPath) ? item.localPath : path8.resolve(configDir || process.cwd(), item.localPath);
|
|
1027
|
+
const candidatePath = path8.join(resolvedPath, "package.json");
|
|
1028
|
+
const hasPkgJson = await fs7.pathExists(candidatePath);
|
|
1039
1029
|
if (hasPkgJson) {
|
|
1040
1030
|
try {
|
|
1041
|
-
const pkgJson = await
|
|
1031
|
+
const pkgJson = await fs7.readJson(candidatePath);
|
|
1042
1032
|
const deps2 = pkgJson.dependencies || {};
|
|
1043
1033
|
for (const [depName, depSpec] of Object.entries(deps2)) {
|
|
1044
1034
|
if (typeof depSpec === "string") {
|
|
1045
|
-
queue.push(
|
|
1046
|
-
name
|
|
1047
|
-
|
|
1048
|
-
source: "dependency",
|
|
1049
|
-
from: item.name,
|
|
1050
|
-
optional: false
|
|
1051
|
-
});
|
|
1035
|
+
queue.push(
|
|
1036
|
+
substituteDep(depName, depSpec, "dependency", item.name, false)
|
|
1037
|
+
);
|
|
1052
1038
|
}
|
|
1053
1039
|
}
|
|
1054
1040
|
const peerDeps2 = pkgJson.peerDependencies || {};
|
|
@@ -1056,13 +1042,15 @@ async function collectAllSpecs(packages, logger, configDir) {
|
|
|
1056
1042
|
for (const [depName, depSpec] of Object.entries(peerDeps2)) {
|
|
1057
1043
|
if (typeof depSpec === "string") {
|
|
1058
1044
|
const isOptional = peerMeta2[depName]?.optional === true;
|
|
1059
|
-
queue.push(
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1045
|
+
queue.push(
|
|
1046
|
+
substituteDep(
|
|
1047
|
+
depName,
|
|
1048
|
+
depSpec,
|
|
1049
|
+
"peerDependency",
|
|
1050
|
+
item.name,
|
|
1051
|
+
isOptional
|
|
1052
|
+
)
|
|
1053
|
+
);
|
|
1066
1054
|
}
|
|
1067
1055
|
}
|
|
1068
1056
|
} catch (error) {
|
|
@@ -1090,13 +1078,9 @@ async function collectAllSpecs(packages, logger, configDir) {
|
|
|
1090
1078
|
const deps = m2.dependencies || {};
|
|
1091
1079
|
for (const [depName, depSpec] of Object.entries(deps)) {
|
|
1092
1080
|
if (typeof depSpec === "string") {
|
|
1093
|
-
queue.push(
|
|
1094
|
-
name
|
|
1095
|
-
|
|
1096
|
-
source: "dependency",
|
|
1097
|
-
from: item.name,
|
|
1098
|
-
optional: false
|
|
1099
|
-
});
|
|
1081
|
+
queue.push(
|
|
1082
|
+
substituteDep(depName, depSpec, "dependency", item.name, false)
|
|
1083
|
+
);
|
|
1100
1084
|
}
|
|
1101
1085
|
}
|
|
1102
1086
|
const peerDeps = m2.peerDependencies || {};
|
|
@@ -1104,24 +1088,27 @@ async function collectAllSpecs(packages, logger, configDir) {
|
|
|
1104
1088
|
for (const [depName, depSpec] of Object.entries(peerDeps)) {
|
|
1105
1089
|
if (typeof depSpec === "string") {
|
|
1106
1090
|
const isOptional = peerMeta[depName]?.optional === true;
|
|
1107
|
-
queue.push(
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1091
|
+
queue.push(
|
|
1092
|
+
substituteDep(
|
|
1093
|
+
depName,
|
|
1094
|
+
depSpec,
|
|
1095
|
+
"peerDependency",
|
|
1096
|
+
item.name,
|
|
1097
|
+
isOptional
|
|
1098
|
+
)
|
|
1099
|
+
);
|
|
1114
1100
|
}
|
|
1115
1101
|
}
|
|
1116
1102
|
}
|
|
1117
1103
|
return allSpecs;
|
|
1118
1104
|
}
|
|
1119
1105
|
function resolveVersionConflicts(allSpecs, logger) {
|
|
1120
|
-
const
|
|
1106
|
+
const topLevel = /* @__PURE__ */ new Map();
|
|
1107
|
+
const nested = [];
|
|
1121
1108
|
for (const [name, specs] of allSpecs) {
|
|
1122
1109
|
const localSpec = specs.find((s) => s.localPath);
|
|
1123
1110
|
if (localSpec) {
|
|
1124
|
-
|
|
1111
|
+
topLevel.set(name, {
|
|
1125
1112
|
name,
|
|
1126
1113
|
version: "local",
|
|
1127
1114
|
localPath: localSpec.localPath
|
|
@@ -1147,6 +1134,7 @@ function resolveVersionConflicts(allSpecs, logger) {
|
|
|
1147
1134
|
const directSpecs = activeSpecs.filter((s) => s.source === "direct");
|
|
1148
1135
|
const directExact = directSpecs.find((s) => semver2.valid(s.spec) !== null);
|
|
1149
1136
|
let chosenVersion;
|
|
1137
|
+
const alreadyNested = /* @__PURE__ */ new Set();
|
|
1150
1138
|
if (directExact) {
|
|
1151
1139
|
chosenVersion = directExact.spec;
|
|
1152
1140
|
} else if (directSpecs.length > 0) {
|
|
@@ -1155,9 +1143,14 @@ function resolveVersionConflicts(allSpecs, logger) {
|
|
|
1155
1143
|
const exactVersions = activeSpecs.filter((s) => semver2.valid(s.spec) !== null).map((s) => s.spec);
|
|
1156
1144
|
const uniqueExact = [...new Set(exactVersions)];
|
|
1157
1145
|
if (uniqueExact.length > 1) {
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
)
|
|
1146
|
+
const sorted = [...uniqueExact].sort(semver2.rcompare);
|
|
1147
|
+
chosenVersion = sorted[0];
|
|
1148
|
+
for (let i2 = 1; i2 < sorted.length; i2++) {
|
|
1149
|
+
const loserVersion = sorted[i2];
|
|
1150
|
+
const consumers = activeSpecs.filter((s) => s.spec === loserVersion).map((s) => s.from);
|
|
1151
|
+
nested.push({ name, version: loserVersion, consumers });
|
|
1152
|
+
alreadyNested.add(loserVersion);
|
|
1153
|
+
}
|
|
1161
1154
|
} else if (uniqueExact.length === 1) {
|
|
1162
1155
|
chosenVersion = uniqueExact[0];
|
|
1163
1156
|
} else {
|
|
@@ -1173,6 +1166,9 @@ function resolveVersionConflicts(allSpecs, logger) {
|
|
|
1173
1166
|
logger.warn(
|
|
1174
1167
|
`${name}@${chosenVersion} differs from peer constraint ${spec.spec} (from ${spec.from})`
|
|
1175
1168
|
);
|
|
1169
|
+
} else if (!alreadyNested.has(spec.spec)) {
|
|
1170
|
+
nested.push({ name, version: spec.spec, consumers: [spec.from] });
|
|
1171
|
+
alreadyNested.add(spec.spec);
|
|
1176
1172
|
}
|
|
1177
1173
|
}
|
|
1178
1174
|
} else {
|
|
@@ -1184,31 +1180,46 @@ function resolveVersionConflicts(allSpecs, logger) {
|
|
|
1184
1180
|
`${name}@${chosenVersion} may not satisfy peer constraint ${spec.spec} (from ${spec.from})`
|
|
1185
1181
|
);
|
|
1186
1182
|
} else {
|
|
1187
|
-
|
|
1188
|
-
`Version conflict: ${name}@${chosenVersion} does not satisfy ${spec.spec} required by ${spec.from}`
|
|
1189
|
-
);
|
|
1183
|
+
nested.push({ name, version: spec.spec, consumers: [spec.from] });
|
|
1190
1184
|
}
|
|
1191
1185
|
}
|
|
1192
1186
|
}
|
|
1193
1187
|
}
|
|
1194
1188
|
}
|
|
1195
|
-
|
|
1189
|
+
topLevel.set(name, { name, version: chosenVersion });
|
|
1196
1190
|
}
|
|
1197
|
-
|
|
1191
|
+
const consolidatedMap = /* @__PURE__ */ new Map();
|
|
1192
|
+
for (const entry of nested) {
|
|
1193
|
+
const key = `${entry.name}@${entry.version}`;
|
|
1194
|
+
const existing = consolidatedMap.get(key);
|
|
1195
|
+
if (existing) {
|
|
1196
|
+
for (const c2 of entry.consumers) {
|
|
1197
|
+
if (!existing.consumers.includes(c2)) existing.consumers.push(c2);
|
|
1198
|
+
}
|
|
1199
|
+
} else {
|
|
1200
|
+
consolidatedMap.set(key, { ...entry, consumers: [...entry.consumers] });
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
return { topLevel, nested: [...consolidatedMap.values()] };
|
|
1198
1204
|
}
|
|
1199
|
-
async function downloadPackages(packages, targetDir, logger, useCache = true, configDir, tmpDir) {
|
|
1205
|
+
async function downloadPackages(packages, targetDir, logger, useCache = true, configDir, tmpDir, overrides = {}) {
|
|
1200
1206
|
const packagePaths = /* @__PURE__ */ new Map();
|
|
1201
1207
|
const userSpecifiedPackages = new Set(packages.map((p2) => p2.name));
|
|
1202
1208
|
validateNoDuplicatePackages(packages);
|
|
1203
1209
|
logger.debug("Resolving dependencies");
|
|
1204
|
-
const allSpecs = await collectAllSpecs(
|
|
1205
|
-
|
|
1206
|
-
|
|
1210
|
+
const allSpecs = await collectAllSpecs(
|
|
1211
|
+
packages,
|
|
1212
|
+
logger,
|
|
1213
|
+
configDir,
|
|
1214
|
+
overrides
|
|
1215
|
+
);
|
|
1216
|
+
const { topLevel, nested } = resolveVersionConflicts(allSpecs, logger);
|
|
1217
|
+
await fs7.ensureDir(targetDir);
|
|
1207
1218
|
const localPackageMap = /* @__PURE__ */ new Map();
|
|
1208
1219
|
for (const pkg of packages) {
|
|
1209
1220
|
if (pkg.path) localPackageMap.set(pkg.name, pkg.path);
|
|
1210
1221
|
}
|
|
1211
|
-
for (const [name, pkg] of
|
|
1222
|
+
for (const [name, pkg] of topLevel) {
|
|
1212
1223
|
if (pkg.localPath || localPackageMap.has(name)) {
|
|
1213
1224
|
const localPath = pkg.localPath || localPackageMap.get(name);
|
|
1214
1225
|
const localPkg = await resolveLocalPackage(
|
|
@@ -1232,8 +1243,8 @@ async function downloadPackages(packages, targetDir, logger, useCache = true, co
|
|
|
1232
1243
|
logger.debug(`Downloading ${packageSpec} (cached)`);
|
|
1233
1244
|
}
|
|
1234
1245
|
try {
|
|
1235
|
-
await
|
|
1236
|
-
await
|
|
1246
|
+
await fs7.ensureDir(path8.dirname(packageDir));
|
|
1247
|
+
await fs7.copy(cachedPath, packageDir);
|
|
1237
1248
|
packagePaths.set(name, packageDir);
|
|
1238
1249
|
continue;
|
|
1239
1250
|
} catch {
|
|
@@ -1241,7 +1252,7 @@ async function downloadPackages(packages, targetDir, logger, useCache = true, co
|
|
|
1241
1252
|
}
|
|
1242
1253
|
}
|
|
1243
1254
|
try {
|
|
1244
|
-
await
|
|
1255
|
+
await fs7.ensureDir(path8.dirname(packageDir));
|
|
1245
1256
|
const cacheDir = process.env.NPM_CACHE_DIR || getTmpPath(tmpDir, "cache", "npm");
|
|
1246
1257
|
await withTimeout(
|
|
1247
1258
|
pacote.extract(packageSpec, packageDir, {
|
|
@@ -1256,8 +1267,8 @@ async function downloadPackages(packages, targetDir, logger, useCache = true, co
|
|
|
1256
1267
|
}
|
|
1257
1268
|
if (useCache) {
|
|
1258
1269
|
try {
|
|
1259
|
-
await
|
|
1260
|
-
await
|
|
1270
|
+
await fs7.ensureDir(path8.dirname(cachedPath));
|
|
1271
|
+
await fs7.copy(packageDir, cachedPath);
|
|
1261
1272
|
} catch {
|
|
1262
1273
|
}
|
|
1263
1274
|
}
|
|
@@ -1266,16 +1277,58 @@ async function downloadPackages(packages, targetDir, logger, useCache = true, co
|
|
|
1266
1277
|
throw new Error(`Failed to download ${packageSpec}: ${error}`);
|
|
1267
1278
|
}
|
|
1268
1279
|
}
|
|
1280
|
+
for (const nestedPkg of nested) {
|
|
1281
|
+
let resolvedSpec = `${nestedPkg.name}@${nestedPkg.version}`;
|
|
1282
|
+
if (!semver2.valid(nestedPkg.version)) {
|
|
1283
|
+
try {
|
|
1284
|
+
const manifest = await withTimeout(
|
|
1285
|
+
pacote.manifest(resolvedSpec, PACOTE_OPTS),
|
|
1286
|
+
PACKAGE_DOWNLOAD_TIMEOUT_MS,
|
|
1287
|
+
`Manifest fetch timed out: ${resolvedSpec}`
|
|
1288
|
+
);
|
|
1289
|
+
const resolved = manifest.version;
|
|
1290
|
+
resolvedSpec = `${nestedPkg.name}@${resolved}`;
|
|
1291
|
+
} catch (error) {
|
|
1292
|
+
throw new Error(
|
|
1293
|
+
`Failed to resolve nested dependency ${resolvedSpec}: ${error}`
|
|
1294
|
+
);
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
for (const consumer of nestedPkg.consumers) {
|
|
1298
|
+
const nestedDir = getNestedPackageDirectory(
|
|
1299
|
+
targetDir,
|
|
1300
|
+
consumer,
|
|
1301
|
+
nestedPkg.name
|
|
1302
|
+
);
|
|
1303
|
+
try {
|
|
1304
|
+
await fs7.ensureDir(path8.dirname(nestedDir));
|
|
1305
|
+
const cacheDir = process.env.NPM_CACHE_DIR || getTmpPath(tmpDir, "cache", "npm");
|
|
1306
|
+
await withTimeout(
|
|
1307
|
+
pacote.extract(resolvedSpec, nestedDir, {
|
|
1308
|
+
...PACOTE_OPTS,
|
|
1309
|
+
cache: cacheDir
|
|
1310
|
+
}),
|
|
1311
|
+
PACKAGE_DOWNLOAD_TIMEOUT_MS,
|
|
1312
|
+
`Nested package download timed out: ${resolvedSpec}`
|
|
1313
|
+
);
|
|
1314
|
+
logger.debug(`Nested: ${resolvedSpec} under ${consumer}`);
|
|
1315
|
+
} catch (error) {
|
|
1316
|
+
throw new Error(
|
|
1317
|
+
`Failed to install nested ${resolvedSpec} for ${consumer}: ${error}`
|
|
1318
|
+
);
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1269
1322
|
return packagePaths;
|
|
1270
1323
|
}
|
|
1271
1324
|
async function getCachedPackagePath(pkg, tmpDir) {
|
|
1272
1325
|
const cacheDir = getTmpPath(tmpDir, "cache", "packages");
|
|
1273
1326
|
const cacheKey = await getPackageCacheKey(pkg.name, pkg.version);
|
|
1274
|
-
return
|
|
1327
|
+
return path8.join(cacheDir, cacheKey);
|
|
1275
1328
|
}
|
|
1276
1329
|
async function isPackageCached(pkg, tmpDir) {
|
|
1277
1330
|
const cachedPath = await getCachedPackagePath(pkg, tmpDir);
|
|
1278
|
-
return
|
|
1331
|
+
return fs7.pathExists(cachedPath);
|
|
1279
1332
|
}
|
|
1280
1333
|
function validateNoDuplicatePackages(packages) {
|
|
1281
1334
|
const packageMap = /* @__PURE__ */ new Map();
|
|
@@ -1314,61 +1367,62 @@ var init_package_manager = __esm({
|
|
|
1314
1367
|
};
|
|
1315
1368
|
SOURCE_PRIORITY = {
|
|
1316
1369
|
direct: 0,
|
|
1317
|
-
|
|
1318
|
-
|
|
1370
|
+
override: 1,
|
|
1371
|
+
dependency: 2,
|
|
1372
|
+
peerDependency: 3
|
|
1319
1373
|
};
|
|
1320
1374
|
}
|
|
1321
1375
|
});
|
|
1322
1376
|
|
|
1323
1377
|
// src/core/build-cache.ts
|
|
1324
|
-
import
|
|
1325
|
-
import
|
|
1378
|
+
import fs8 from "fs-extra";
|
|
1379
|
+
import path9 from "path";
|
|
1326
1380
|
import { getHashServer as getHashServer2 } from "@walkeros/server-core";
|
|
1327
1381
|
async function getBuildCachePath(configContent, tmpDir) {
|
|
1328
1382
|
const cacheDir = getTmpPath(tmpDir, "cache", "builds");
|
|
1329
1383
|
const cacheKey = await getFlowSettingsCacheKey(configContent);
|
|
1330
|
-
return
|
|
1384
|
+
return path9.join(cacheDir, `${cacheKey}.js`);
|
|
1331
1385
|
}
|
|
1332
1386
|
async function isBuildCached(configContent, tmpDir) {
|
|
1333
1387
|
const cachePath = await getBuildCachePath(configContent, tmpDir);
|
|
1334
|
-
return
|
|
1388
|
+
return fs8.pathExists(cachePath);
|
|
1335
1389
|
}
|
|
1336
1390
|
async function cacheBuild(configContent, buildOutput, tmpDir) {
|
|
1337
1391
|
const cachePath = await getBuildCachePath(configContent, tmpDir);
|
|
1338
|
-
await
|
|
1339
|
-
await
|
|
1392
|
+
await fs8.ensureDir(path9.dirname(cachePath));
|
|
1393
|
+
await fs8.writeFile(cachePath, buildOutput, "utf-8");
|
|
1340
1394
|
}
|
|
1341
1395
|
async function getCachedBuild(configContent, tmpDir) {
|
|
1342
1396
|
const cachePath = await getBuildCachePath(configContent, tmpDir);
|
|
1343
|
-
if (await
|
|
1344
|
-
return await
|
|
1397
|
+
if (await fs8.pathExists(cachePath)) {
|
|
1398
|
+
return await fs8.readFile(cachePath, "utf-8");
|
|
1345
1399
|
}
|
|
1346
1400
|
return null;
|
|
1347
1401
|
}
|
|
1348
1402
|
async function getCodeCachePath(codeContent, tmpDir) {
|
|
1349
1403
|
const cacheDir = getTmpPath(tmpDir, "cache", "code");
|
|
1350
1404
|
const cacheKey = await getHashServer2(codeContent, 12);
|
|
1351
|
-
return
|
|
1405
|
+
return path9.join(cacheDir, `${cacheKey}.js`);
|
|
1352
1406
|
}
|
|
1353
1407
|
async function cacheCode(codeContent, codeOutput, tmpDir) {
|
|
1354
1408
|
const cachePath = await getCodeCachePath(codeContent, tmpDir);
|
|
1355
|
-
await
|
|
1356
|
-
await
|
|
1409
|
+
await fs8.ensureDir(path9.dirname(cachePath));
|
|
1410
|
+
await fs8.writeFile(cachePath, codeOutput, "utf-8");
|
|
1357
1411
|
}
|
|
1358
1412
|
async function getCachedCode(codeContent, tmpDir) {
|
|
1359
1413
|
const cachePath = await getCodeCachePath(codeContent, tmpDir);
|
|
1360
|
-
if (await
|
|
1361
|
-
return
|
|
1414
|
+
if (await fs8.pathExists(cachePath)) {
|
|
1415
|
+
return fs8.readFile(cachePath, "utf-8");
|
|
1362
1416
|
}
|
|
1363
1417
|
return null;
|
|
1364
1418
|
}
|
|
1365
1419
|
async function ensureCodeOnDisk(codeContent, compiledCode, tmpDir) {
|
|
1366
1420
|
const cacheDir = getTmpPath(tmpDir, "cache", "code");
|
|
1367
1421
|
const cacheKey = await getHashServer2(codeContent, 12);
|
|
1368
|
-
const cachePath =
|
|
1369
|
-
if (!await
|
|
1370
|
-
await
|
|
1371
|
-
await
|
|
1422
|
+
const cachePath = path9.join(cacheDir, `${cacheKey}.mjs`);
|
|
1423
|
+
if (!await fs8.pathExists(cachePath)) {
|
|
1424
|
+
await fs8.ensureDir(path9.dirname(cachePath));
|
|
1425
|
+
await fs8.writeFile(cachePath, compiledCode, "utf-8");
|
|
1372
1426
|
}
|
|
1373
1427
|
return cachePath;
|
|
1374
1428
|
}
|
|
@@ -1384,8 +1438,8 @@ var init_build_cache = __esm({
|
|
|
1384
1438
|
import crypto from "crypto";
|
|
1385
1439
|
import esbuild from "esbuild";
|
|
1386
1440
|
import { builtinModules } from "module";
|
|
1387
|
-
import
|
|
1388
|
-
import
|
|
1441
|
+
import path10 from "path";
|
|
1442
|
+
import fs9 from "fs-extra";
|
|
1389
1443
|
import { packageNameToVariable, ENV_MARKER_PREFIX } from "@walkeros/core";
|
|
1390
1444
|
function isInlineCode(code) {
|
|
1391
1445
|
return code !== null && typeof code === "object" && !Array.isArray(code) && "push" in code;
|
|
@@ -1438,18 +1492,18 @@ function generateInlineCode(inline, config, env, chain, chainPropertyName, isDes
|
|
|
1438
1492
|
}
|
|
1439
1493
|
async function copyIncludes(includes, sourceDir, outputDir, logger) {
|
|
1440
1494
|
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 +
|
|
1495
|
+
const sourcePath = path10.resolve(sourceDir, include);
|
|
1496
|
+
const folderName = path10.basename(include);
|
|
1497
|
+
const destPath = path10.join(outputDir, folderName);
|
|
1498
|
+
const resolvedOutput = path10.resolve(outputDir);
|
|
1499
|
+
const resolvedSource = path10.resolve(sourcePath);
|
|
1500
|
+
if (resolvedSource === resolvedOutput || resolvedOutput.startsWith(resolvedSource + path10.sep) || resolvedSource.startsWith(resolvedOutput + path10.sep)) {
|
|
1447
1501
|
throw new Error(
|
|
1448
1502
|
`Circular include detected: "${include}" resolves to "${resolvedSource}" which overlaps with output directory "${resolvedOutput}"`
|
|
1449
1503
|
);
|
|
1450
1504
|
}
|
|
1451
|
-
if (await
|
|
1452
|
-
await
|
|
1505
|
+
if (await fs9.pathExists(sourcePath)) {
|
|
1506
|
+
await fs9.copy(sourcePath, destPath);
|
|
1453
1507
|
logger.debug(`Copied ${include} to output`);
|
|
1454
1508
|
} else {
|
|
1455
1509
|
logger.warn(`Include folder not found: ${include}`);
|
|
@@ -1520,14 +1574,14 @@ async function bundleCore(flowSettings, buildOptions, logger, showStats = false)
|
|
|
1520
1574
|
const cachedBuild = await getCachedBuild(configContent, CACHE_DIR);
|
|
1521
1575
|
if (cachedBuild) {
|
|
1522
1576
|
logger.debug("Using cached build");
|
|
1523
|
-
const outputPath =
|
|
1524
|
-
await
|
|
1525
|
-
await
|
|
1526
|
-
const stats = await
|
|
1577
|
+
const outputPath = path10.resolve(buildOptions.output);
|
|
1578
|
+
await fs9.ensureDir(path10.dirname(outputPath));
|
|
1579
|
+
await fs9.writeFile(outputPath, cachedBuild);
|
|
1580
|
+
const stats = await fs9.stat(outputPath);
|
|
1527
1581
|
const sizeKB = (stats.size / 1024).toFixed(1);
|
|
1528
1582
|
logger.info(`Output: ${outputPath} (${sizeKB} KB, cached)`);
|
|
1529
1583
|
if (showStats) {
|
|
1530
|
-
const stats2 = await
|
|
1584
|
+
const stats2 = await fs9.stat(outputPath);
|
|
1531
1585
|
const packageStats = Object.entries(buildOptions.packages).map(
|
|
1532
1586
|
([name, pkg]) => ({
|
|
1533
1587
|
name: `${name}@${pkg.version || "latest"}`,
|
|
@@ -1550,7 +1604,7 @@ async function bundleCore(flowSettings, buildOptions, logger, showStats = false)
|
|
|
1550
1604
|
}
|
|
1551
1605
|
}
|
|
1552
1606
|
try {
|
|
1553
|
-
await
|
|
1607
|
+
await fs9.ensureDir(TEMP_DIR);
|
|
1554
1608
|
const hasSourcesOrDests = Object.keys(
|
|
1555
1609
|
flowSettings.sources || {}
|
|
1556
1610
|
).length > 0 || Object.keys(
|
|
@@ -1570,7 +1624,12 @@ async function bundleCore(flowSettings, buildOptions, logger, showStats = false)
|
|
|
1570
1624
|
imports: [`default as ${varName}`]
|
|
1571
1625
|
};
|
|
1572
1626
|
}
|
|
1573
|
-
for (const section of [
|
|
1627
|
+
for (const section of [
|
|
1628
|
+
"sources",
|
|
1629
|
+
"destinations",
|
|
1630
|
+
"transformers",
|
|
1631
|
+
"stores"
|
|
1632
|
+
]) {
|
|
1574
1633
|
const steps = flowSettings[section];
|
|
1575
1634
|
if (!steps) continue;
|
|
1576
1635
|
for (const step of Object.values(steps)) {
|
|
@@ -1600,12 +1659,13 @@ async function bundleCore(flowSettings, buildOptions, logger, showStats = false)
|
|
|
1600
1659
|
buildOptions.cache,
|
|
1601
1660
|
buildOptions.configDir,
|
|
1602
1661
|
// For resolving relative local paths
|
|
1603
|
-
CACHE_DIR
|
|
1662
|
+
CACHE_DIR,
|
|
1663
|
+
buildOptions.overrides
|
|
1604
1664
|
);
|
|
1605
1665
|
for (const [pkgName, pkgPath] of packagePaths.entries()) {
|
|
1606
1666
|
if (pkgName.startsWith("@walkeros/")) {
|
|
1607
|
-
const pkgJsonPath =
|
|
1608
|
-
const pkgJson = await
|
|
1667
|
+
const pkgJsonPath = path10.join(pkgPath, "package.json");
|
|
1668
|
+
const pkgJson = await fs9.readJSON(pkgJsonPath);
|
|
1609
1669
|
if (!pkgJson.exports && pkgJson.module) {
|
|
1610
1670
|
pkgJson.exports = {
|
|
1611
1671
|
".": {
|
|
@@ -1613,12 +1673,12 @@ async function bundleCore(flowSettings, buildOptions, logger, showStats = false)
|
|
|
1613
1673
|
require: pkgJson.main
|
|
1614
1674
|
}
|
|
1615
1675
|
};
|
|
1616
|
-
await
|
|
1676
|
+
await fs9.writeJSON(pkgJsonPath, pkgJson, { spaces: 2 });
|
|
1617
1677
|
}
|
|
1618
1678
|
}
|
|
1619
1679
|
}
|
|
1620
|
-
const packageJsonPath =
|
|
1621
|
-
await
|
|
1680
|
+
const packageJsonPath = path10.join(TEMP_DIR, "package.json");
|
|
1681
|
+
await fs9.writeFile(
|
|
1622
1682
|
packageJsonPath,
|
|
1623
1683
|
JSON.stringify({ type: "module" }, null, 2)
|
|
1624
1684
|
);
|
|
@@ -1628,8 +1688,8 @@ async function bundleCore(flowSettings, buildOptions, logger, showStats = false)
|
|
|
1628
1688
|
buildOptions,
|
|
1629
1689
|
packagePaths
|
|
1630
1690
|
);
|
|
1631
|
-
const outputPath =
|
|
1632
|
-
await
|
|
1691
|
+
const outputPath = path10.resolve(buildOptions.output);
|
|
1692
|
+
await fs9.ensureDir(path10.dirname(outputPath));
|
|
1633
1693
|
let compiledCode = null;
|
|
1634
1694
|
if (buildOptions.cache !== false) {
|
|
1635
1695
|
compiledCode = await getCachedCode(codeEntry, CACHE_DIR);
|
|
@@ -1640,8 +1700,8 @@ async function bundleCore(flowSettings, buildOptions, logger, showStats = false)
|
|
|
1640
1700
|
logger.debug(
|
|
1641
1701
|
`Running esbuild (target: ${buildOptions.target || "es2018"}, format: ${buildOptions.format})`
|
|
1642
1702
|
);
|
|
1643
|
-
const entryPath =
|
|
1644
|
-
await
|
|
1703
|
+
const entryPath = path10.join(TEMP_DIR, "entry.js");
|
|
1704
|
+
await fs9.writeFile(entryPath, codeEntry);
|
|
1645
1705
|
const esbuildOptions = createEsbuildOptions(
|
|
1646
1706
|
{ ...buildOptions, minify: false },
|
|
1647
1707
|
entryPath,
|
|
@@ -1660,7 +1720,7 @@ async function bundleCore(flowSettings, buildOptions, logger, showStats = false)
|
|
|
1660
1720
|
} finally {
|
|
1661
1721
|
await esbuild.stop();
|
|
1662
1722
|
}
|
|
1663
|
-
compiledCode = await
|
|
1723
|
+
compiledCode = await fs9.readFile(outputPath, "utf-8");
|
|
1664
1724
|
if (buildOptions.cache !== false) {
|
|
1665
1725
|
await cacheCode(codeEntry, compiledCode, CACHE_DIR);
|
|
1666
1726
|
}
|
|
@@ -1677,14 +1737,14 @@ export { __configData };`;
|
|
|
1677
1737
|
` : "";
|
|
1678
1738
|
const esmOutput = `${banner}${compiledCode}
|
|
1679
1739
|
${dataDeclaration}`;
|
|
1680
|
-
await
|
|
1740
|
+
await fs9.writeFile(outputPath, esmOutput);
|
|
1681
1741
|
} else {
|
|
1682
1742
|
const stage2Entry = (buildOptions.platform || "node") === "browser" ? generateWebEntry(stage1Path, dataPayload, {
|
|
1683
1743
|
windowCollector: buildOptions.windowCollector,
|
|
1684
1744
|
windowElb: buildOptions.windowElb
|
|
1685
1745
|
}) : generateServerEntry(stage1Path, dataPayload);
|
|
1686
|
-
const stage2EntryPath =
|
|
1687
|
-
await
|
|
1746
|
+
const stage2EntryPath = path10.join(TEMP_DIR, "stage2.mjs");
|
|
1747
|
+
await fs9.writeFile(stage2EntryPath, stage2Entry);
|
|
1688
1748
|
const stage2Options = {
|
|
1689
1749
|
entryPoints: [stage2EntryPath],
|
|
1690
1750
|
bundle: true,
|
|
@@ -1721,13 +1781,13 @@ ${dataDeclaration}`;
|
|
|
1721
1781
|
await esbuild.stop();
|
|
1722
1782
|
}
|
|
1723
1783
|
}
|
|
1724
|
-
const outputStats = await
|
|
1784
|
+
const outputStats = await fs9.stat(outputPath);
|
|
1725
1785
|
const sizeKB = (outputStats.size / 1024).toFixed(1);
|
|
1726
1786
|
const buildTime = ((Date.now() - bundleStartTime) / 1e3).toFixed(1);
|
|
1727
1787
|
logger.info(`Output: ${outputPath} (${sizeKB} KB, ${buildTime}s)`);
|
|
1728
1788
|
if (buildOptions.cache !== false) {
|
|
1729
1789
|
const configContent = generateCacheKeyContent(flowSettings, buildOptions);
|
|
1730
|
-
const buildOutput = await
|
|
1790
|
+
const buildOutput = await fs9.readFile(outputPath, "utf-8");
|
|
1731
1791
|
await cacheBuild(configContent, buildOutput, CACHE_DIR);
|
|
1732
1792
|
logger.debug("Build cached for future use");
|
|
1733
1793
|
}
|
|
@@ -1741,7 +1801,7 @@ ${dataDeclaration}`;
|
|
|
1741
1801
|
);
|
|
1742
1802
|
}
|
|
1743
1803
|
if (buildOptions.include && buildOptions.include.length > 0) {
|
|
1744
|
-
const outputDir =
|
|
1804
|
+
const outputDir = path10.dirname(outputPath);
|
|
1745
1805
|
await copyIncludes(
|
|
1746
1806
|
buildOptions.include,
|
|
1747
1807
|
buildOptions.configDir || process.cwd(),
|
|
@@ -1754,13 +1814,13 @@ ${dataDeclaration}`;
|
|
|
1754
1814
|
throw error;
|
|
1755
1815
|
} finally {
|
|
1756
1816
|
if (!buildOptions.tempDir) {
|
|
1757
|
-
|
|
1817
|
+
fs9.remove(TEMP_DIR).catch(() => {
|
|
1758
1818
|
});
|
|
1759
1819
|
}
|
|
1760
1820
|
}
|
|
1761
1821
|
}
|
|
1762
1822
|
async function collectBundleStats(outputPath, packages, startTime, entryContent) {
|
|
1763
|
-
const stats = await
|
|
1823
|
+
const stats = await fs9.stat(outputPath);
|
|
1764
1824
|
const totalSize = stats.size;
|
|
1765
1825
|
const buildTime = Date.now() - startTime;
|
|
1766
1826
|
const packageStats = Object.entries(packages).map(([name, pkg]) => {
|
|
@@ -1943,9 +2003,8 @@ function detectExplicitCodeImports(flowSettings) {
|
|
|
1943
2003
|
}
|
|
1944
2004
|
return explicitCodeImports;
|
|
1945
2005
|
}
|
|
1946
|
-
function generateImportStatements(packages, destinationPackages, sourcePackages, transformerPackages, storePackages, explicitCodeImports) {
|
|
2006
|
+
async function generateImportStatements(packages, destinationPackages, sourcePackages, transformerPackages, storePackages, explicitCodeImports, packagePaths, withDev) {
|
|
1947
2007
|
const importStatements = [];
|
|
1948
|
-
const examplesMappings = [];
|
|
1949
2008
|
const usedPackages = /* @__PURE__ */ new Set([
|
|
1950
2009
|
...destinationPackages,
|
|
1951
2010
|
...sourcePackages,
|
|
@@ -1980,21 +2039,6 @@ function generateImportStatements(packages, destinationPackages, sourcePackages,
|
|
|
1980
2039
|
}
|
|
1981
2040
|
}
|
|
1982
2041
|
}
|
|
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
2042
|
}
|
|
1999
2043
|
if (packageName === "@walkeros/collector" && !namedImportsToGenerate.includes("startFlow")) {
|
|
2000
2044
|
namedImportsToGenerate.push("startFlow");
|
|
@@ -2004,7 +2048,27 @@ function generateImportStatements(packages, destinationPackages, sourcePackages,
|
|
|
2004
2048
|
importStatements.push(`import { ${importList} } from '${packageName}';`);
|
|
2005
2049
|
}
|
|
2006
2050
|
}
|
|
2007
|
-
|
|
2051
|
+
const devExportEntries = [];
|
|
2052
|
+
if (withDev) {
|
|
2053
|
+
for (const packageName of usedPackages) {
|
|
2054
|
+
const localPath = packagePaths.get(packageName);
|
|
2055
|
+
if (!localPath) continue;
|
|
2056
|
+
try {
|
|
2057
|
+
const pkgJsonPath = path10.join(localPath, "package.json");
|
|
2058
|
+
const pkgJson = await fs9.readJSON(pkgJsonPath);
|
|
2059
|
+
const exports = pkgJson.exports;
|
|
2060
|
+
if (exports && typeof exports === "object" && "./dev" in exports) {
|
|
2061
|
+
const varName = `__dev_${packageNameToVariable(packageName)}`;
|
|
2062
|
+
importStatements.push(
|
|
2063
|
+
`import * as ${varName} from '${packageName}/dev';`
|
|
2064
|
+
);
|
|
2065
|
+
devExportEntries.push(`'${packageName}': ${varName}`);
|
|
2066
|
+
}
|
|
2067
|
+
} catch {
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
return { importStatements, devExportEntries };
|
|
2008
2072
|
}
|
|
2009
2073
|
function validateComponentNames(components, section) {
|
|
2010
2074
|
for (const name of Object.keys(components)) {
|
|
@@ -2067,13 +2131,15 @@ async function createEntryPoint(flowSettings, buildOptions, packagePaths) {
|
|
|
2067
2131
|
validateComponentNames(flowWithSections.transformers, "transformers");
|
|
2068
2132
|
if (flowWithSections.stores)
|
|
2069
2133
|
validateComponentNames(flowWithSections.stores, "stores");
|
|
2070
|
-
const { importStatements } = generateImportStatements(
|
|
2134
|
+
const { importStatements, devExportEntries } = await generateImportStatements(
|
|
2071
2135
|
buildOptions.packages,
|
|
2072
2136
|
destinationPackages,
|
|
2073
2137
|
sourcePackages,
|
|
2074
2138
|
transformerPackages,
|
|
2075
2139
|
storePackages,
|
|
2076
|
-
explicitCodeImports
|
|
2140
|
+
explicitCodeImports,
|
|
2141
|
+
packagePaths,
|
|
2142
|
+
buildOptions.skipWrapper === true
|
|
2077
2143
|
);
|
|
2078
2144
|
const importsCode = importStatements.join("\n");
|
|
2079
2145
|
const hasFlow = Object.values(flowSettings.sources || {}).some(
|
|
@@ -2097,9 +2163,14 @@ ${userCode}` : userCode,
|
|
|
2097
2163
|
codeConfigObject,
|
|
2098
2164
|
buildOptions.code || ""
|
|
2099
2165
|
);
|
|
2166
|
+
const devExportsBlock = devExportEntries.length > 0 ? `
|
|
2167
|
+
export const __devExports = {
|
|
2168
|
+
${devExportEntries.join(",\n ")},
|
|
2169
|
+
};` : "";
|
|
2170
|
+
const fullModule = wireConfigModule + devExportsBlock;
|
|
2100
2171
|
const codeEntry = importsCode ? `${importsCode}
|
|
2101
2172
|
|
|
2102
|
-
${
|
|
2173
|
+
${fullModule}` : fullModule;
|
|
2103
2174
|
return { codeEntry, dataPayload, hasFlow: true };
|
|
2104
2175
|
}
|
|
2105
2176
|
function createBuildError(buildError, code) {
|
|
@@ -2345,6 +2416,79 @@ const __configData = ${dataPayload};
|
|
|
2345
2416
|
const { collector, elb } = await startFlow(wireConfig(__configData));${assignmentCode}
|
|
2346
2417
|
})();`;
|
|
2347
2418
|
}
|
|
2419
|
+
function generateWrapEntry(stage1Path, options = {}) {
|
|
2420
|
+
const assignments = [];
|
|
2421
|
+
if (options.windowCollector) {
|
|
2422
|
+
assignments.push(
|
|
2423
|
+
` if (typeof window !== 'undefined') window['${options.windowCollector}'] = collector;`
|
|
2424
|
+
);
|
|
2425
|
+
}
|
|
2426
|
+
if (options.windowElb) {
|
|
2427
|
+
assignments.push(
|
|
2428
|
+
` if (typeof window !== 'undefined') window['${options.windowElb}'] = elb;`
|
|
2429
|
+
);
|
|
2430
|
+
}
|
|
2431
|
+
const assignmentCode = assignments.length > 0 ? "\n" + assignments.join("\n") : "";
|
|
2432
|
+
const hasPreview = !!(options.previewOrigin && options.previewScope);
|
|
2433
|
+
const previewOriginLiteral = JSON.stringify(options.previewOrigin ?? "");
|
|
2434
|
+
const previewScopeLiteral = JSON.stringify(options.previewScope ?? "");
|
|
2435
|
+
const preflightBlock = hasPreview ? `
|
|
2436
|
+
// --- Preview mode preflight ---
|
|
2437
|
+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
2438
|
+
var __previewOrigin = ${previewOriginLiteral};
|
|
2439
|
+
var __previewScope = ${previewScopeLiteral};
|
|
2440
|
+
var __params = new URLSearchParams(location.search);
|
|
2441
|
+
var __tokens = __params.getAll('elbPreview');
|
|
2442
|
+
var __param = __tokens.length > 0 ? __tokens[__tokens.length - 1] : null;
|
|
2443
|
+
var __secure = location.protocol === 'https:' ? '; Secure' : '';
|
|
2444
|
+
|
|
2445
|
+
if (__param === 'off') {
|
|
2446
|
+
document.cookie = 'elbPreview=; path=/; max-age=0; SameSite=Lax' + __secure;
|
|
2447
|
+
} else if (__param && /^[a-zA-Z0-9_-]{8,32}$/.test(__param)) {
|
|
2448
|
+
document.cookie = 'elbPreview=' + __param + '; path=/; max-age=604800; SameSite=Lax' + __secure;
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
var __match = /(?:^|; )elbPreview=([^;]+)/.exec(document.cookie);
|
|
2452
|
+
var __token = __match && __match[1];
|
|
2453
|
+
if (__token && /^[a-zA-Z0-9_-]{8,32}$/.test(__token)) {
|
|
2454
|
+
var __s = document.createElement('script');
|
|
2455
|
+
__s.src = 'https://' + __previewOrigin + '/preview/' + __previewScope + '/walker.' + __token + '.js';
|
|
2456
|
+
document.head.appendChild(__s);
|
|
2457
|
+
return;
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
// --- End preview mode preflight ---
|
|
2461
|
+
` : "";
|
|
2462
|
+
return `import { startFlow, wireConfig, __configData } from '${stage1Path}';
|
|
2463
|
+
|
|
2464
|
+
(async () => {${preflightBlock}
|
|
2465
|
+
const { collector, elb } = await startFlow(wireConfig(__configData));${assignmentCode}
|
|
2466
|
+
})();`;
|
|
2467
|
+
}
|
|
2468
|
+
function generateWrapEntryServer(stage1Path) {
|
|
2469
|
+
return `import { startFlow, wireConfig, __configData } from '${stage1Path}';
|
|
2470
|
+
|
|
2471
|
+
export default async function(context = {}) {
|
|
2472
|
+
const config = wireConfig(__configData);
|
|
2473
|
+
|
|
2474
|
+
if (context.logger) config.logger = context.logger;
|
|
2475
|
+
|
|
2476
|
+
if (context.sourceSettings && config.sources) {
|
|
2477
|
+
for (const src of Object.values(config.sources)) {
|
|
2478
|
+
if (src.config?.settings) {
|
|
2479
|
+
src.config.settings = { ...src.config.settings, ...context.sourceSettings };
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2484
|
+
const result = await startFlow(config);
|
|
2485
|
+
|
|
2486
|
+
const httpSource = Object.values(result.collector.sources || {})
|
|
2487
|
+
.find(s => 'httpHandler' in s && typeof s.httpHandler === 'function');
|
|
2488
|
+
|
|
2489
|
+
return { ...result, httpHandler: httpSource ? httpSource.httpHandler : undefined };
|
|
2490
|
+
}`;
|
|
2491
|
+
}
|
|
2348
2492
|
function processConfigValue(value) {
|
|
2349
2493
|
return serializeWithCode(value, 0);
|
|
2350
2494
|
}
|
|
@@ -2425,12 +2569,12 @@ var init_bundler = __esm({
|
|
|
2425
2569
|
});
|
|
2426
2570
|
|
|
2427
2571
|
// src/commands/bundle/upload.ts
|
|
2428
|
-
import
|
|
2572
|
+
import fs10 from "fs-extra";
|
|
2429
2573
|
function sanitizeUrl(url) {
|
|
2430
2574
|
return url.split("?")[0];
|
|
2431
2575
|
}
|
|
2432
2576
|
async function uploadBundleToUrl(filePath, url, timeoutMs = 3e4) {
|
|
2433
|
-
const bundleContent = await
|
|
2577
|
+
const bundleContent = await fs10.readFile(filePath);
|
|
2434
2578
|
const doUpload = async (attempt) => {
|
|
2435
2579
|
const response = await fetch(url, {
|
|
2436
2580
|
method: "PUT",
|
|
@@ -2509,8 +2653,8 @@ var init_api_client = __esm({
|
|
|
2509
2653
|
});
|
|
2510
2654
|
|
|
2511
2655
|
// src/commands/bundle/dockerfile.ts
|
|
2512
|
-
import
|
|
2513
|
-
import
|
|
2656
|
+
import path11 from "path";
|
|
2657
|
+
import fs11 from "fs-extra";
|
|
2514
2658
|
function buildDockerfileContent(platform, includedFolders) {
|
|
2515
2659
|
const bundleFile = platform === "web" ? "walker.js" : "bundle.mjs";
|
|
2516
2660
|
const lines = [
|
|
@@ -2520,21 +2664,21 @@ function buildDockerfileContent(platform, includedFolders) {
|
|
|
2520
2664
|
`COPY ${bundleFile} /app/flow/${bundleFile}`
|
|
2521
2665
|
];
|
|
2522
2666
|
for (const folder of includedFolders) {
|
|
2523
|
-
const name =
|
|
2667
|
+
const name = path11.basename(folder);
|
|
2524
2668
|
lines.push(`COPY ${name}/ /app/flow/${name}/`);
|
|
2525
2669
|
}
|
|
2526
2670
|
lines.push("", `ENV BUNDLE=/app/flow/${bundleFile}`, "", "EXPOSE 8080", "");
|
|
2527
2671
|
return lines.join("\n");
|
|
2528
2672
|
}
|
|
2529
2673
|
async function generateDockerfile(outputDir, platform, logger, customFile, includedFolders) {
|
|
2530
|
-
const destPath =
|
|
2531
|
-
if (customFile && await
|
|
2532
|
-
await
|
|
2674
|
+
const destPath = path11.join(outputDir, "Dockerfile");
|
|
2675
|
+
if (customFile && await fs11.pathExists(customFile)) {
|
|
2676
|
+
await fs11.copy(customFile, destPath);
|
|
2533
2677
|
logger.info(`Dockerfile: ${destPath} (copied from ${customFile})`);
|
|
2534
2678
|
return;
|
|
2535
2679
|
}
|
|
2536
2680
|
const dockerfile = buildDockerfileContent(platform, includedFolders || []);
|
|
2537
|
-
await
|
|
2681
|
+
await fs11.writeFile(destPath, dockerfile);
|
|
2538
2682
|
logger.info(`Dockerfile: ${destPath}`);
|
|
2539
2683
|
}
|
|
2540
2684
|
var init_dockerfile = __esm({
|
|
@@ -2544,15 +2688,15 @@ var init_dockerfile = __esm({
|
|
|
2544
2688
|
});
|
|
2545
2689
|
|
|
2546
2690
|
// src/commands/bundle/index.ts
|
|
2547
|
-
import
|
|
2548
|
-
import
|
|
2691
|
+
import path12 from "path";
|
|
2692
|
+
import fs12 from "fs-extra";
|
|
2549
2693
|
import { getPlatform as getPlatform2 } from "@walkeros/core";
|
|
2550
2694
|
function resolveOutputPath(output, buildOptions) {
|
|
2551
|
-
const resolved =
|
|
2552
|
-
const ext =
|
|
2553
|
-
if (output.endsWith("/") || output.endsWith(
|
|
2695
|
+
const resolved = path12.resolve(output);
|
|
2696
|
+
const ext = path12.extname(resolved);
|
|
2697
|
+
if (output.endsWith("/") || output.endsWith(path12.sep) || !ext) {
|
|
2554
2698
|
const filename = buildOptions.platform === "browser" ? "walker.js" : "bundle.mjs";
|
|
2555
|
-
return
|
|
2699
|
+
return path12.join(resolved, filename);
|
|
2556
2700
|
}
|
|
2557
2701
|
return resolved;
|
|
2558
2702
|
}
|
|
@@ -2582,7 +2726,7 @@ async function bundleCommand(options) {
|
|
|
2582
2726
|
} catch {
|
|
2583
2727
|
throw new Error("Invalid JSON received on stdin");
|
|
2584
2728
|
}
|
|
2585
|
-
configPath =
|
|
2729
|
+
configPath = path12.resolve(process.cwd(), "stdin.config.json");
|
|
2586
2730
|
} else {
|
|
2587
2731
|
const file = options.config || "bundle.config.json";
|
|
2588
2732
|
configPath = resolveAsset(file, "config");
|
|
@@ -2636,19 +2780,25 @@ async function bundleCommand(options) {
|
|
|
2636
2780
|
if (uploadUrl) {
|
|
2637
2781
|
await uploadBundleToUrl(buildOptions.output, uploadUrl);
|
|
2638
2782
|
logger.info(`Uploaded to: ${sanitizeUrl(uploadUrl)}`);
|
|
2639
|
-
await
|
|
2783
|
+
await fs12.remove(buildOptions.output);
|
|
2640
2784
|
}
|
|
2641
2785
|
if (!options.json && !options.all && options.stats && stats) {
|
|
2642
2786
|
displayStats(stats, logger);
|
|
2643
2787
|
}
|
|
2644
2788
|
if (writingToStdout && !options.json) {
|
|
2645
|
-
const bundleContent = await
|
|
2789
|
+
const bundleContent = await fs12.readFile(buildOptions.output);
|
|
2646
2790
|
await writeResult(bundleContent, {});
|
|
2791
|
+
if (process.stdout.isTTY) {
|
|
2792
|
+
const defaultPath = buildOptions.platform === "browser" ? "./dist/walker.js" : "./dist/bundle.mjs";
|
|
2793
|
+
logger.info(
|
|
2794
|
+
`Bundle written to stdout. Use -o ${defaultPath} to write to file.`
|
|
2795
|
+
);
|
|
2796
|
+
}
|
|
2647
2797
|
}
|
|
2648
2798
|
if (options.dockerfile && options.output) {
|
|
2649
2799
|
const platform = getPlatform2(flowSettings);
|
|
2650
2800
|
if (platform) {
|
|
2651
|
-
const outputDir =
|
|
2801
|
+
const outputDir = path12.dirname(buildOptions.output);
|
|
2652
2802
|
const customFile = typeof options.dockerfile === "string" ? options.dockerfile : void 0;
|
|
2653
2803
|
await generateDockerfile(
|
|
2654
2804
|
outputDir,
|
|
@@ -2719,7 +2869,7 @@ Build Summary: ${successCount}/${results.length} succeeded`
|
|
|
2719
2869
|
}
|
|
2720
2870
|
async function bundle(configOrPath, options = {}) {
|
|
2721
2871
|
let rawConfig;
|
|
2722
|
-
let configPath =
|
|
2872
|
+
let configPath = path12.resolve(process.cwd(), "walkeros.config.json");
|
|
2723
2873
|
if (typeof configOrPath === "string") {
|
|
2724
2874
|
configPath = resolveAsset(configOrPath, "config");
|
|
2725
2875
|
rawConfig = await loadJsonConfig(configPath);
|
|
@@ -2775,45 +2925,6 @@ var init_bundle = __esm({
|
|
|
2775
2925
|
}
|
|
2776
2926
|
});
|
|
2777
2927
|
|
|
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
2928
|
// src/runtime/cache.ts
|
|
2818
2929
|
var cache_exports = {};
|
|
2819
2930
|
__export(cache_exports, {
|
|
@@ -2822,7 +2933,7 @@ __export(cache_exports, {
|
|
|
2822
2933
|
writeCache: () => writeCache
|
|
2823
2934
|
});
|
|
2824
2935
|
import {
|
|
2825
|
-
existsSync as
|
|
2936
|
+
existsSync as existsSync3,
|
|
2826
2937
|
mkdirSync as mkdirSync3,
|
|
2827
2938
|
copyFileSync,
|
|
2828
2939
|
writeFileSync as writeFileSync3,
|
|
@@ -2840,7 +2951,7 @@ function readCache(cacheDir) {
|
|
|
2840
2951
|
try {
|
|
2841
2952
|
const metaPath = join2(cacheDir, "meta.json");
|
|
2842
2953
|
const bundlePath = join2(cacheDir, "bundle.mjs");
|
|
2843
|
-
if (!
|
|
2954
|
+
if (!existsSync3(metaPath) || !existsSync3(bundlePath)) return null;
|
|
2844
2955
|
const meta = JSON.parse(readFileSync2(metaPath, "utf-8"));
|
|
2845
2956
|
return { bundlePath, version: meta.version };
|
|
2846
2957
|
} catch {
|
|
@@ -2850,7 +2961,7 @@ function readCache(cacheDir) {
|
|
|
2850
2961
|
function readCacheConfig(cacheDir) {
|
|
2851
2962
|
try {
|
|
2852
2963
|
const configPath = join2(cacheDir, "config.json");
|
|
2853
|
-
if (!
|
|
2964
|
+
if (!existsSync3(configPath)) return null;
|
|
2854
2965
|
return readFileSync2(configPath, "utf-8");
|
|
2855
2966
|
} catch {
|
|
2856
2967
|
return null;
|
|
@@ -2868,15 +2979,15 @@ __export(utils_exports, {
|
|
|
2868
2979
|
isPreBuiltConfig: () => isPreBuiltConfig,
|
|
2869
2980
|
prepareBundleForRun: () => prepareBundleForRun
|
|
2870
2981
|
});
|
|
2871
|
-
import
|
|
2872
|
-
import
|
|
2982
|
+
import path16 from "path";
|
|
2983
|
+
import fs15 from "fs-extra";
|
|
2873
2984
|
async function prepareBundleForRun(configPath, options) {
|
|
2874
2985
|
const tempDir = getTmpPath(
|
|
2875
2986
|
void 0,
|
|
2876
2987
|
`run-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
|
2877
2988
|
);
|
|
2878
|
-
await
|
|
2879
|
-
const tempPath =
|
|
2989
|
+
await fs15.ensureDir(tempDir);
|
|
2990
|
+
const tempPath = path16.join(tempDir, "bundle.mjs");
|
|
2880
2991
|
await bundle(configPath, {
|
|
2881
2992
|
cache: true,
|
|
2882
2993
|
verbose: options.verbose,
|
|
@@ -2891,7 +3002,7 @@ async function prepareBundleForRun(configPath, options) {
|
|
|
2891
3002
|
return {
|
|
2892
3003
|
bundlePath: tempPath,
|
|
2893
3004
|
cleanup: async () => {
|
|
2894
|
-
await
|
|
3005
|
+
await fs15.remove(tempDir);
|
|
2895
3006
|
}
|
|
2896
3007
|
};
|
|
2897
3008
|
}
|
|
@@ -2910,8 +3021,8 @@ var init_utils3 = __esm({
|
|
|
2910
3021
|
init_bundle();
|
|
2911
3022
|
|
|
2912
3023
|
// src/commands/push/index.ts
|
|
2913
|
-
import
|
|
2914
|
-
import
|
|
3024
|
+
import path15 from "path";
|
|
3025
|
+
import fs14 from "fs-extra";
|
|
2915
3026
|
import {
|
|
2916
3027
|
createIngest,
|
|
2917
3028
|
getPlatform as getPlatform4,
|
|
@@ -2924,28 +3035,28 @@ import {
|
|
|
2924
3035
|
// ../collector/dist/index.mjs
|
|
2925
3036
|
import { assign as o } from "@walkeros/core";
|
|
2926
3037
|
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
|
|
3038
|
+
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";
|
|
3039
|
+
import { isArray as x } from "@walkeros/core";
|
|
3040
|
+
import { tryCatch as q, tryCatchAsync as S } from "@walkeros/core";
|
|
3041
|
+
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";
|
|
3042
|
+
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";
|
|
3043
|
+
import { assign as be, getId as we, isFunction as ke, isString as Ce } from "@walkeros/core";
|
|
3044
|
+
import { isObject as Oe } from "@walkeros/core";
|
|
3045
|
+
import { createIngest as Se, getGrantedConsent as $e, processEventMapping as De, tryCatchAsync as _e, useHooks as Ie } from "@walkeros/core";
|
|
3046
|
+
import { useHooks as Ee, tryCatchAsync as Me } from "@walkeros/core";
|
|
3047
|
+
import { useHooks as Re } from "@walkeros/core";
|
|
3048
|
+
function X(e, n) {
|
|
2938
3049
|
return e.storeId && n.stores[e.storeId] ? n.stores[e.storeId] : n.stores.__cache;
|
|
2939
3050
|
}
|
|
2940
|
-
function
|
|
3051
|
+
function Y(e) {
|
|
2941
3052
|
const n = {};
|
|
2942
3053
|
for (const [t, o2] of Object.entries(e)) {
|
|
2943
3054
|
const e2 = o2.config?.next;
|
|
2944
|
-
e2 && !
|
|
3055
|
+
e2 && !V(e2) ? n[t] = { next: e2 } : n[t] = {};
|
|
2945
3056
|
}
|
|
2946
3057
|
return n;
|
|
2947
3058
|
}
|
|
2948
|
-
function
|
|
3059
|
+
function ee(e, n = {}) {
|
|
2949
3060
|
if (!e) return [];
|
|
2950
3061
|
if (Array.isArray(e)) return e;
|
|
2951
3062
|
const t = [], o2 = /* @__PURE__ */ new Set();
|
|
@@ -2961,23 +3072,23 @@ function Z(e, n = {}) {
|
|
|
2961
3072
|
}
|
|
2962
3073
|
return t;
|
|
2963
3074
|
}
|
|
2964
|
-
async function
|
|
3075
|
+
async function ne(e, n, t) {
|
|
2965
3076
|
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:
|
|
3077
|
+
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
3078
|
s.debug("init");
|
|
2968
|
-
const i2 = await
|
|
3079
|
+
const i2 = await F(n.init, "TransformerInit", e.hooks)(r2);
|
|
2969
3080
|
if (false === i2) return false;
|
|
2970
3081
|
n.config = { ...i2 || n.config, env: i2?.env || n.config.env, init: true }, s.debug("init done");
|
|
2971
3082
|
}
|
|
2972
3083
|
return true;
|
|
2973
3084
|
}
|
|
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: { ...
|
|
3085
|
+
async function te(e, n, t, o2, s, r2) {
|
|
3086
|
+
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
3087
|
a2.debug("push", { event: o2.name });
|
|
2977
|
-
const u2 = await
|
|
3088
|
+
const u2 = await F(n.push, "TransformerPush", e.hooks)(o2, c2);
|
|
2978
3089
|
return a2.debug("push done"), u2;
|
|
2979
3090
|
}
|
|
2980
|
-
async function
|
|
3091
|
+
async function oe(e, n, t, o2, s, r2, i2) {
|
|
2981
3092
|
i2 && s?._meta && (s._meta.chainPath = i2);
|
|
2982
3093
|
let a2 = o2, c2 = r2;
|
|
2983
3094
|
for (const o3 of t) {
|
|
@@ -2988,7 +3099,7 @@ async function te(e, n, t, o2, s, r2, i2) {
|
|
|
2988
3099
|
}
|
|
2989
3100
|
if (s && s._meta && s._meta.path.length > 256) return e.logger.error(`Max path length exceeded at ${o3}`), { event: null, respond: c2 };
|
|
2990
3101
|
s && s._meta && (s._meta.hops++, s._meta.path.push(o3));
|
|
2991
|
-
if (!await
|
|
3102
|
+
if (!await U(ne)(e, r3, o3)) return e.logger.error(`Transformer init failed: ${o3}`), { event: null, respond: c2 };
|
|
2992
3103
|
if (i2 && void 0 !== r3.config?.chainMocks?.[i2]) {
|
|
2993
3104
|
const n2 = r3.config.chainMocks[i2];
|
|
2994
3105
|
e.logger.scope(`transformer:${r3.type || "unknown"}`).debug("chainMock", { chain: i2 }), a2 = n2;
|
|
@@ -2999,10 +3110,10 @@ async function te(e, n, t, o2, s, r2, i2) {
|
|
|
2999
3110
|
continue;
|
|
3000
3111
|
}
|
|
3001
3112
|
if (r3.config?.disabled) continue;
|
|
3002
|
-
const u2 = r3.config?.cache, f2 = u2 ?
|
|
3113
|
+
const u2 = r3.config?.cache, f2 = u2 ? z(u2) : void 0, l2 = f2 ? X(f2, e) : void 0;
|
|
3003
3114
|
let d2;
|
|
3004
3115
|
if (f2 && l2) {
|
|
3005
|
-
const e2 =
|
|
3116
|
+
const e2 = Q(s, a2), n2 = J(f2, l2, e2, `t:${o3}`);
|
|
3006
3117
|
if ("HIT" === n2?.status && n2.value) {
|
|
3007
3118
|
if (a2 = n2.value, f2.full) return { event: a2, respond: c2 };
|
|
3008
3119
|
continue;
|
|
@@ -3011,31 +3122,31 @@ async function te(e, n, t, o2, s, r2, i2) {
|
|
|
3011
3122
|
}
|
|
3012
3123
|
const g2 = r3.config.before;
|
|
3013
3124
|
if (g2) {
|
|
3014
|
-
const t2 =
|
|
3125
|
+
const t2 = ee("string" == typeof g2 || Array.isArray(g2) && !V(g2) ? g2 : L(W(g2), Q(s, a2)) || void 0, Y(n));
|
|
3015
3126
|
if (t2.length > 0) {
|
|
3016
|
-
const o4 = await
|
|
3127
|
+
const o4 = await oe(e, n, t2, a2, s, c2, i2);
|
|
3017
3128
|
if (null === o4.event) return { event: null, respond: o4.respond ?? c2 };
|
|
3018
3129
|
o4.respond && (c2 = o4.respond), a2 = Array.isArray(o4.event) ? o4.event[0] : o4.event;
|
|
3019
3130
|
}
|
|
3020
3131
|
}
|
|
3021
|
-
const p2 = await
|
|
3132
|
+
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
3133
|
if (false === p2) return { event: null, respond: c2 };
|
|
3023
3134
|
if (Array.isArray(p2)) {
|
|
3024
3135
|
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] } } :
|
|
3136
|
+
const o4 = t2.event || a2, u4 = s ? { ...s, _meta: { ...s._meta, path: [...s._meta.path] } } : N("unknown");
|
|
3026
3137
|
if (t2.next) {
|
|
3027
3138
|
let s2 = t2.next;
|
|
3028
|
-
if (
|
|
3029
|
-
const e2 =
|
|
3030
|
-
s2 =
|
|
3139
|
+
if (V(t2.next)) {
|
|
3140
|
+
const e2 = W(t2.next);
|
|
3141
|
+
s2 = L(e2, Q(u4, o4));
|
|
3031
3142
|
}
|
|
3032
3143
|
if (s2) {
|
|
3033
|
-
const t3 =
|
|
3034
|
-
if (t3.length > 0) return
|
|
3144
|
+
const t3 = ee(s2, Y(n));
|
|
3145
|
+
if (t3.length > 0) return oe(e, n, t3, o4, u4, c2, i2);
|
|
3035
3146
|
}
|
|
3036
3147
|
return { event: o4, respond: c2 };
|
|
3037
3148
|
}
|
|
3038
|
-
return r4.length > 0 ?
|
|
3149
|
+
return r4.length > 0 ? oe(e, n, r4, o4, u4, c2, i2) : { event: o4, respond: c2 };
|
|
3039
3150
|
}));
|
|
3040
3151
|
let f3 = c2;
|
|
3041
3152
|
const l3 = [];
|
|
@@ -3050,41 +3161,41 @@ async function te(e, n, t, o2, s, r2, i2) {
|
|
|
3050
3161
|
const { event: t2, respond: o4, next: r4 } = p2;
|
|
3051
3162
|
if (o4 && (c2 = o4), r4) {
|
|
3052
3163
|
let o5 = r4;
|
|
3053
|
-
if (
|
|
3054
|
-
const e2 =
|
|
3055
|
-
if (o5 =
|
|
3164
|
+
if (V(r4)) {
|
|
3165
|
+
const e2 = W(r4);
|
|
3166
|
+
if (o5 = L(e2, Q(s, a2)), !o5) {
|
|
3056
3167
|
t2 && (a2 = t2);
|
|
3057
3168
|
continue;
|
|
3058
3169
|
}
|
|
3059
3170
|
}
|
|
3060
|
-
const u3 =
|
|
3061
|
-
return u3.length > 0 ?
|
|
3171
|
+
const u3 = ee(o5, Y(n));
|
|
3172
|
+
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
3173
|
}
|
|
3063
3174
|
t2 && (a2 = t2);
|
|
3064
3175
|
}
|
|
3065
|
-
if (d2 && l2 &&
|
|
3066
|
-
const t2 = r3.config.next, o4 =
|
|
3176
|
+
if (d2 && l2 && K(l2, d2.key, a2, d2.ttl), (!p2 || "object" == typeof p2 && !p2.next) && r3.config.next && V(r3.config.next)) {
|
|
3177
|
+
const t2 = r3.config.next, o4 = W(t2), u3 = L(o4, Q(s, a2));
|
|
3067
3178
|
if (u3) {
|
|
3068
|
-
const t3 =
|
|
3069
|
-
if (t3.length > 0) return
|
|
3179
|
+
const t3 = ee(u3, Y(n));
|
|
3180
|
+
if (t3.length > 0) return oe(e, n, t3, a2, s, c2, i2);
|
|
3070
3181
|
}
|
|
3071
3182
|
return { event: a2, respond: c2 };
|
|
3072
3183
|
}
|
|
3073
3184
|
}
|
|
3074
3185
|
return { event: a2, respond: c2 };
|
|
3075
3186
|
}
|
|
3076
|
-
function
|
|
3077
|
-
return e &&
|
|
3187
|
+
function se(e) {
|
|
3188
|
+
return e && B(e) ? e : {};
|
|
3078
3189
|
}
|
|
3079
|
-
function
|
|
3190
|
+
function Ge(e) {
|
|
3080
3191
|
if (null === e || "object" != typeof e) return e;
|
|
3081
|
-
if (Array.isArray(e)) return e.map(
|
|
3192
|
+
if (Array.isArray(e)) return e.map(Ge);
|
|
3082
3193
|
const n = {};
|
|
3083
|
-
for (const [t, o2] of Object.entries(e)) n[t] = "function" == typeof o2 ? o2 :
|
|
3194
|
+
for (const [t, o2] of Object.entries(e)) n[t] = "function" == typeof o2 ? o2 : Ge(o2);
|
|
3084
3195
|
return n;
|
|
3085
3196
|
}
|
|
3086
|
-
function
|
|
3087
|
-
const n = [], { simulation: t, ...o2 } = e, s =
|
|
3197
|
+
function Ne(e) {
|
|
3198
|
+
const n = [], { simulation: t, ...o2 } = e, s = Ge(o2);
|
|
3088
3199
|
for (const e2 of t) {
|
|
3089
3200
|
const t2 = e2.startsWith("call:") ? e2.slice(5) : e2, o3 = t2.split(".");
|
|
3090
3201
|
let r2 = s;
|
|
@@ -3281,12 +3392,9 @@ function applyOverrides(config, overrides) {
|
|
|
3281
3392
|
}
|
|
3282
3393
|
}
|
|
3283
3394
|
|
|
3284
|
-
// src/commands/push/index.ts
|
|
3285
|
-
init_package_path();
|
|
3286
|
-
|
|
3287
3395
|
// src/commands/push/flow-context.ts
|
|
3288
3396
|
init_utils2();
|
|
3289
|
-
import
|
|
3397
|
+
import path13 from "path";
|
|
3290
3398
|
import { pathToFileURL } from "url";
|
|
3291
3399
|
import { JSDOM, VirtualConsole } from "jsdom";
|
|
3292
3400
|
|
|
@@ -3328,7 +3436,7 @@ function installTimerInterception(options = {}) {
|
|
|
3328
3436
|
if (options.domWindow && options.domWindow !== globalThis) {
|
|
3329
3437
|
patchTarget(options.domWindow);
|
|
3330
3438
|
}
|
|
3331
|
-
const drainMicrotasks = () => new Promise((
|
|
3439
|
+
const drainMicrotasks = () => new Promise((resolve4) => realSetTimeout(resolve4, 0));
|
|
3332
3440
|
async function flush(wallTimeout = 5e3) {
|
|
3333
3441
|
const deadline = Date.now() + wallTimeout;
|
|
3334
3442
|
const maxIterations = 100;
|
|
@@ -3376,7 +3484,15 @@ function installTimerInterception(options = {}) {
|
|
|
3376
3484
|
|
|
3377
3485
|
// src/commands/push/flow-context.ts
|
|
3378
3486
|
async function withFlowContext(options, fn) {
|
|
3379
|
-
const {
|
|
3487
|
+
const {
|
|
3488
|
+
esmPath,
|
|
3489
|
+
platform,
|
|
3490
|
+
logger,
|
|
3491
|
+
snapshotCode,
|
|
3492
|
+
timeout,
|
|
3493
|
+
networkCalls,
|
|
3494
|
+
asyncDrain
|
|
3495
|
+
} = options;
|
|
3380
3496
|
const startTime = Date.now();
|
|
3381
3497
|
const g2 = global;
|
|
3382
3498
|
let savedWindow, savedDocument, savedNavigator;
|
|
@@ -3423,7 +3539,7 @@ async function withFlowContext(options, fn) {
|
|
|
3423
3539
|
vm.runInThisContext(snapshotCode);
|
|
3424
3540
|
}
|
|
3425
3541
|
}
|
|
3426
|
-
const fileUrl = pathToFileURL(
|
|
3542
|
+
const fileUrl = pathToFileURL(path13.resolve(esmPath)).href;
|
|
3427
3543
|
const module = await import(`${fileUrl}?t=${Date.now()}`);
|
|
3428
3544
|
const { wireConfig, startFlow } = module;
|
|
3429
3545
|
if (typeof wireConfig !== "function" || typeof startFlow !== "function") {
|
|
@@ -3434,7 +3550,8 @@ async function withFlowContext(options, fn) {
|
|
|
3434
3550
|
const flowModule = {
|
|
3435
3551
|
wireConfig,
|
|
3436
3552
|
startFlow,
|
|
3437
|
-
__configData: module.__configData
|
|
3553
|
+
__configData: module.__configData,
|
|
3554
|
+
__devExports: module.__devExports
|
|
3438
3555
|
};
|
|
3439
3556
|
if (timerControl) {
|
|
3440
3557
|
const result = await fn(flowModule);
|
|
@@ -3522,51 +3639,41 @@ init_cli_logger();
|
|
|
3522
3639
|
init_tmp();
|
|
3523
3640
|
init_config();
|
|
3524
3641
|
init_bundler();
|
|
3525
|
-
import
|
|
3526
|
-
import
|
|
3642
|
+
import path14 from "path";
|
|
3643
|
+
import fs13 from "fs-extra";
|
|
3527
3644
|
import { getPlatform as getPlatform3 } from "@walkeros/core";
|
|
3528
|
-
async function prepareFlow(
|
|
3645
|
+
async function prepareFlow(input) {
|
|
3529
3646
|
const logger = createCLILogger({
|
|
3530
|
-
silent:
|
|
3531
|
-
verbose:
|
|
3647
|
+
silent: input.silent,
|
|
3648
|
+
verbose: input.verbose
|
|
3532
3649
|
});
|
|
3533
3650
|
logger.debug("Loading flow configuration");
|
|
3534
|
-
const { flowSettings, buildOptions } =
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
logger
|
|
3539
|
-
}
|
|
3540
|
-
);
|
|
3651
|
+
const { flowSettings, buildOptions } = loadBundleConfig(input.config, {
|
|
3652
|
+
configPath: process.cwd(),
|
|
3653
|
+
flowName: input.flow
|
|
3654
|
+
});
|
|
3541
3655
|
const platform = getPlatform3(flowSettings);
|
|
3542
|
-
const configDir = buildOptions.configDir || process.cwd();
|
|
3543
3656
|
const overrides = buildOverrides(
|
|
3544
|
-
{ simulate:
|
|
3657
|
+
{ simulate: input.simulate, mock: input.mock },
|
|
3545
3658
|
flowSettings
|
|
3546
3659
|
);
|
|
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
|
-
}
|
|
3660
|
+
if (input.mode === "prebuilt") {
|
|
3661
|
+
return {
|
|
3662
|
+
bundlePath: input.bundlePath,
|
|
3663
|
+
platform,
|
|
3664
|
+
overrides,
|
|
3665
|
+
flowSettings,
|
|
3666
|
+
cleanup: async () => {
|
|
3560
3667
|
}
|
|
3561
|
-
}
|
|
3668
|
+
};
|
|
3562
3669
|
}
|
|
3563
3670
|
logger.debug("Bundling flow configuration");
|
|
3564
3671
|
const tempDir = getTmpPath(
|
|
3565
3672
|
void 0,
|
|
3566
3673
|
`push-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
|
3567
3674
|
);
|
|
3568
|
-
await
|
|
3569
|
-
const bundlePath =
|
|
3675
|
+
await fs13.ensureDir(tempDir);
|
|
3676
|
+
const bundlePath = path14.join(tempDir, "bundle.mjs");
|
|
3570
3677
|
const pushBuildOptions = {
|
|
3571
3678
|
...buildOptions,
|
|
3572
3679
|
output: bundlePath,
|
|
@@ -3582,9 +3689,8 @@ async function prepareFlow(options) {
|
|
|
3582
3689
|
platform,
|
|
3583
3690
|
overrides,
|
|
3584
3691
|
flowSettings,
|
|
3585
|
-
configDir,
|
|
3586
3692
|
cleanup: async () => {
|
|
3587
|
-
await
|
|
3693
|
+
await fs13.remove(tempDir).catch(() => {
|
|
3588
3694
|
});
|
|
3589
3695
|
}
|
|
3590
3696
|
};
|
|
@@ -3599,11 +3705,11 @@ function resolveBeforeChain(before, transformers, ingest, event) {
|
|
|
3599
3705
|
const compiled = compileNext(next);
|
|
3600
3706
|
const resolved = resolveNext(compiled, buildCacheContext(ingest, event));
|
|
3601
3707
|
if (!resolved) return [];
|
|
3602
|
-
return
|
|
3708
|
+
return ee(resolved, Y(transformers));
|
|
3603
3709
|
}
|
|
3604
|
-
return
|
|
3710
|
+
return ee(
|
|
3605
3711
|
next,
|
|
3606
|
-
|
|
3712
|
+
Y(transformers)
|
|
3607
3713
|
);
|
|
3608
3714
|
}
|
|
3609
3715
|
async function pushCore(inputPath, event, options = {}) {
|
|
@@ -3664,7 +3770,7 @@ async function pushCore(inputPath, event, options = {}) {
|
|
|
3664
3770
|
};
|
|
3665
3771
|
} finally {
|
|
3666
3772
|
if (tempDir) {
|
|
3667
|
-
await
|
|
3773
|
+
await fs14.remove(tempDir).catch(() => {
|
|
3668
3774
|
});
|
|
3669
3775
|
}
|
|
3670
3776
|
}
|
|
@@ -3804,35 +3910,15 @@ async function executeConfigPush(options, validatedEvent, logger, setTempDir, sn
|
|
|
3804
3910
|
logger
|
|
3805
3911
|
});
|
|
3806
3912
|
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
|
-
}
|
|
3913
|
+
const overrides = buildOverrides({ mock: options.mock }, flowSettings);
|
|
3828
3914
|
logger.debug("Bundling flow configuration");
|
|
3829
3915
|
const tempDir = getTmpPath(
|
|
3830
3916
|
void 0,
|
|
3831
3917
|
`push-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
|
3832
3918
|
);
|
|
3833
3919
|
setTempDir(tempDir);
|
|
3834
|
-
await
|
|
3835
|
-
const tempPath =
|
|
3920
|
+
await fs14.ensureDir(tempDir);
|
|
3921
|
+
const tempPath = path15.join(tempDir, "bundle.mjs");
|
|
3836
3922
|
const pushBuildOptions = {
|
|
3837
3923
|
...buildOptions,
|
|
3838
3924
|
output: tempPath,
|
|
@@ -3862,9 +3948,9 @@ async function executeBundlePush(bundleContent, platform, validatedEvent, logger
|
|
|
3862
3948
|
`push-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
|
3863
3949
|
);
|
|
3864
3950
|
setTempDir(tempDir);
|
|
3865
|
-
await
|
|
3866
|
-
const tempPath =
|
|
3867
|
-
await
|
|
3951
|
+
await fs14.ensureDir(tempDir);
|
|
3952
|
+
const tempPath = path15.join(tempDir, "bundle.mjs");
|
|
3953
|
+
await fs14.writeFile(tempPath, bundleContent, "utf8");
|
|
3868
3954
|
logger.debug(`Bundle written to: ${tempPath}`);
|
|
3869
3955
|
logger.debug(
|
|
3870
3956
|
`Executing in ${platform} environment (${platform === "web" ? "JSDOM" : "Node.js"})`
|
|
@@ -3883,7 +3969,15 @@ async function executeDestinationPush(esmPath, event, logger, platform, override
|
|
|
3883
3969
|
const startTime = Date.now();
|
|
3884
3970
|
const networkCalls = [];
|
|
3885
3971
|
return withFlowContext(
|
|
3886
|
-
{
|
|
3972
|
+
{
|
|
3973
|
+
esmPath,
|
|
3974
|
+
platform,
|
|
3975
|
+
logger,
|
|
3976
|
+
snapshotCode,
|
|
3977
|
+
timeout,
|
|
3978
|
+
networkCalls,
|
|
3979
|
+
asyncDrain: { timeout: 5e3 }
|
|
3980
|
+
},
|
|
3887
3981
|
async (module) => {
|
|
3888
3982
|
const config = module.wireConfig(module.__configData ?? void 0);
|
|
3889
3983
|
applyOverrides(config, overrides || {});
|
|
@@ -3903,15 +3997,31 @@ async function executeDestinationPush(esmPath, event, logger, platform, override
|
|
|
3903
3997
|
}
|
|
3904
3998
|
);
|
|
3905
3999
|
}
|
|
3906
|
-
async function simulateSource(
|
|
4000
|
+
async function simulateSource(configOrPath, input, options) {
|
|
3907
4001
|
const startTime = Date.now();
|
|
3908
|
-
|
|
3909
|
-
|
|
4002
|
+
let config;
|
|
4003
|
+
if (typeof configOrPath === "string") {
|
|
4004
|
+
config = await loadJsonConfig(configOrPath);
|
|
4005
|
+
} else {
|
|
4006
|
+
config = configOrPath;
|
|
4007
|
+
}
|
|
4008
|
+
const prepareInput = options.bundlePath ? {
|
|
4009
|
+
mode: "prebuilt",
|
|
4010
|
+
bundlePath: options.bundlePath,
|
|
4011
|
+
config,
|
|
3910
4012
|
flow: options.flow,
|
|
3911
4013
|
simulate: ["source." + options.sourceId],
|
|
3912
4014
|
silent: options.silent,
|
|
3913
4015
|
verbose: options.verbose
|
|
3914
|
-
}
|
|
4016
|
+
} : {
|
|
4017
|
+
mode: "build",
|
|
4018
|
+
config,
|
|
4019
|
+
flow: options.flow,
|
|
4020
|
+
simulate: ["source." + options.sourceId],
|
|
4021
|
+
silent: options.silent,
|
|
4022
|
+
verbose: options.verbose
|
|
4023
|
+
};
|
|
4024
|
+
const prepared = await prepareFlow(prepareInput);
|
|
3915
4025
|
try {
|
|
3916
4026
|
const logger = createCLILogger({
|
|
3917
4027
|
silent: options.silent,
|
|
@@ -3919,22 +4029,7 @@ async function simulateSource(configPath, input, options) {
|
|
|
3919
4029
|
});
|
|
3920
4030
|
const sourceConfig = (prepared.flowSettings.sources ?? {})[options.sourceId];
|
|
3921
4031
|
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
|
-
);
|
|
4032
|
+
throw new Error(`Source "${options.sourceId}" has no package defined`);
|
|
3938
4033
|
}
|
|
3939
4034
|
let snapshotCode;
|
|
3940
4035
|
if (options.snapshot) {
|
|
@@ -3953,17 +4048,26 @@ async function simulateSource(configPath, input, options) {
|
|
|
3953
4048
|
networkCalls
|
|
3954
4049
|
},
|
|
3955
4050
|
async (module) => {
|
|
3956
|
-
const
|
|
3957
|
-
|
|
4051
|
+
const devExports = module.__devExports?.[sourceConfig.package];
|
|
4052
|
+
const createTrigger = devExports?.examples?.createTrigger;
|
|
4053
|
+
if (!createTrigger) {
|
|
4054
|
+
throw new Error(
|
|
4055
|
+
`Source package "${sourceConfig.package}" has no createTrigger in /dev export`
|
|
4056
|
+
);
|
|
4057
|
+
}
|
|
4058
|
+
const flowConfig = module.wireConfig(module.__configData ?? void 0);
|
|
4059
|
+
applyOverrides(flowConfig, prepared.overrides);
|
|
3958
4060
|
const captured = [];
|
|
3959
|
-
|
|
3960
|
-
...
|
|
4061
|
+
flowConfig.hooks = {
|
|
4062
|
+
...flowConfig.hooks || {},
|
|
3961
4063
|
prePush: ({ fn }, event) => {
|
|
3962
4064
|
captured.push({ event, timestamp: Date.now() });
|
|
3963
4065
|
return { ok: true };
|
|
3964
4066
|
}
|
|
3965
4067
|
};
|
|
3966
|
-
const instance = await createTrigger(
|
|
4068
|
+
const instance = await createTrigger(flowConfig, {
|
|
4069
|
+
sourceId: options.sourceId
|
|
4070
|
+
});
|
|
3967
4071
|
const { trigger } = instance;
|
|
3968
4072
|
logger.info("Simulating source");
|
|
3969
4073
|
const inputRecord = input ?? {};
|
|
@@ -3991,7 +4095,7 @@ async function simulateSource(configPath, input, options) {
|
|
|
3991
4095
|
await prepared.cleanup();
|
|
3992
4096
|
}
|
|
3993
4097
|
}
|
|
3994
|
-
async function simulateTransformer(
|
|
4098
|
+
async function simulateTransformer(configOrPath, event, options) {
|
|
3995
4099
|
const startTime = Date.now();
|
|
3996
4100
|
const parsed = schemas3.PartialEventSchema.safeParse(event);
|
|
3997
4101
|
if (!parsed.success) {
|
|
@@ -4001,14 +4105,31 @@ async function simulateTransformer(configPath, event, options) {
|
|
|
4001
4105
|
error: parsed.error.message
|
|
4002
4106
|
};
|
|
4003
4107
|
}
|
|
4004
|
-
|
|
4005
|
-
|
|
4108
|
+
let config;
|
|
4109
|
+
if (typeof configOrPath === "string") {
|
|
4110
|
+
config = await loadJsonConfig(configOrPath);
|
|
4111
|
+
} else {
|
|
4112
|
+
config = configOrPath;
|
|
4113
|
+
}
|
|
4114
|
+
const prepareInput = options.bundlePath ? {
|
|
4115
|
+
mode: "prebuilt",
|
|
4116
|
+
bundlePath: options.bundlePath,
|
|
4117
|
+
config,
|
|
4006
4118
|
flow: options.flow,
|
|
4007
4119
|
simulate: ["transformer." + options.transformerId],
|
|
4008
4120
|
mock: options.mock,
|
|
4009
4121
|
silent: options.silent,
|
|
4010
4122
|
verbose: options.verbose
|
|
4011
|
-
}
|
|
4123
|
+
} : {
|
|
4124
|
+
mode: "build",
|
|
4125
|
+
config,
|
|
4126
|
+
flow: options.flow,
|
|
4127
|
+
simulate: ["transformer." + options.transformerId],
|
|
4128
|
+
mock: options.mock,
|
|
4129
|
+
silent: options.silent,
|
|
4130
|
+
verbose: options.verbose
|
|
4131
|
+
};
|
|
4132
|
+
const prepared = await prepareFlow(prepareInput);
|
|
4012
4133
|
try {
|
|
4013
4134
|
const logger = createCLILogger({
|
|
4014
4135
|
silent: options.silent,
|
|
@@ -4031,11 +4152,11 @@ async function simulateTransformer(configPath, event, options) {
|
|
|
4031
4152
|
networkCalls
|
|
4032
4153
|
},
|
|
4033
4154
|
async (module) => {
|
|
4034
|
-
const
|
|
4035
|
-
applyOverrides(
|
|
4036
|
-
if (
|
|
4037
|
-
if (
|
|
4038
|
-
const result = await module.startFlow(
|
|
4155
|
+
const flowConfig = module.wireConfig(module.__configData ?? void 0);
|
|
4156
|
+
applyOverrides(flowConfig, prepared.overrides);
|
|
4157
|
+
if (flowConfig.sources) flowConfig.sources = {};
|
|
4158
|
+
if (flowConfig.destinations) flowConfig.destinations = {};
|
|
4159
|
+
const result = await module.startFlow(flowConfig);
|
|
4039
4160
|
if (!result?.collector)
|
|
4040
4161
|
throw new Error("Invalid bundle: collector not available");
|
|
4041
4162
|
const collector = result.collector;
|
|
@@ -4045,7 +4166,7 @@ async function simulateTransformer(configPath, event, options) {
|
|
|
4045
4166
|
`Transformer "${options.transformerId}" not found in collector. Available: ${Object.keys(collector.transformers || {}).join(", ") || "none"}`
|
|
4046
4167
|
);
|
|
4047
4168
|
}
|
|
4048
|
-
const initialized = await
|
|
4169
|
+
const initialized = await ne(
|
|
4049
4170
|
collector,
|
|
4050
4171
|
transformer,
|
|
4051
4172
|
options.transformerId
|
|
@@ -4070,7 +4191,7 @@ async function simulateTransformer(configPath, event, options) {
|
|
|
4070
4191
|
processedEvent
|
|
4071
4192
|
);
|
|
4072
4193
|
if (beforeChainIds.length > 0) {
|
|
4073
|
-
const beforeResult = await
|
|
4194
|
+
const beforeResult = await oe(
|
|
4074
4195
|
collector,
|
|
4075
4196
|
collector.transformers,
|
|
4076
4197
|
beforeChainIds,
|
|
@@ -4091,7 +4212,7 @@ async function simulateTransformer(configPath, event, options) {
|
|
|
4091
4212
|
processedEvent = Array.isArray(beforeResult) ? beforeResult[0] : beforeResult;
|
|
4092
4213
|
}
|
|
4093
4214
|
}
|
|
4094
|
-
const pushResult = await
|
|
4215
|
+
const pushResult = await te(
|
|
4095
4216
|
collector,
|
|
4096
4217
|
transformer,
|
|
4097
4218
|
options.transformerId,
|
|
@@ -4131,7 +4252,7 @@ async function simulateTransformer(configPath, event, options) {
|
|
|
4131
4252
|
await prepared.cleanup();
|
|
4132
4253
|
}
|
|
4133
4254
|
}
|
|
4134
|
-
async function simulateDestination(
|
|
4255
|
+
async function simulateDestination(configOrPath, event, options) {
|
|
4135
4256
|
const startTime = Date.now();
|
|
4136
4257
|
const parsed = schemas3.PartialEventSchema.safeParse(event);
|
|
4137
4258
|
if (!parsed.success) {
|
|
@@ -4141,14 +4262,31 @@ async function simulateDestination(configPath, event, options) {
|
|
|
4141
4262
|
error: parsed.error.message
|
|
4142
4263
|
};
|
|
4143
4264
|
}
|
|
4144
|
-
|
|
4145
|
-
|
|
4265
|
+
let config;
|
|
4266
|
+
if (typeof configOrPath === "string") {
|
|
4267
|
+
config = await loadJsonConfig(configOrPath);
|
|
4268
|
+
} else {
|
|
4269
|
+
config = configOrPath;
|
|
4270
|
+
}
|
|
4271
|
+
const prepareInput = options.bundlePath ? {
|
|
4272
|
+
mode: "prebuilt",
|
|
4273
|
+
bundlePath: options.bundlePath,
|
|
4274
|
+
config,
|
|
4146
4275
|
flow: options.flow,
|
|
4147
4276
|
simulate: ["destination." + options.destinationId],
|
|
4148
4277
|
mock: options.mock,
|
|
4149
4278
|
silent: options.silent,
|
|
4150
4279
|
verbose: options.verbose
|
|
4151
|
-
}
|
|
4280
|
+
} : {
|
|
4281
|
+
mode: "build",
|
|
4282
|
+
config,
|
|
4283
|
+
flow: options.flow,
|
|
4284
|
+
simulate: ["destination." + options.destinationId],
|
|
4285
|
+
mock: options.mock,
|
|
4286
|
+
silent: options.silent,
|
|
4287
|
+
verbose: options.verbose
|
|
4288
|
+
};
|
|
4289
|
+
const prepared = await prepareFlow(prepareInput);
|
|
4152
4290
|
try {
|
|
4153
4291
|
const logger = createCLILogger({
|
|
4154
4292
|
silent: options.silent,
|
|
@@ -4170,25 +4308,32 @@ async function simulateDestination(configPath, event, options) {
|
|
|
4170
4308
|
networkCalls
|
|
4171
4309
|
},
|
|
4172
4310
|
async (module) => {
|
|
4173
|
-
const
|
|
4174
|
-
applyOverrides(
|
|
4175
|
-
const
|
|
4311
|
+
const flowConfig = module.wireConfig(module.__configData ?? void 0);
|
|
4312
|
+
applyOverrides(flowConfig, prepared.overrides);
|
|
4313
|
+
const destPkg = (prepared.flowSettings.destinations ?? {})[options.destinationId];
|
|
4176
4314
|
let trackedCalls = [];
|
|
4177
|
-
if (
|
|
4178
|
-
const
|
|
4179
|
-
const
|
|
4180
|
-
if (
|
|
4181
|
-
const
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4315
|
+
if (destPkg?.package) {
|
|
4316
|
+
const devExports = module.__devExports?.[destPkg.package];
|
|
4317
|
+
const devEnv = devExports?.examples?.env;
|
|
4318
|
+
if (devEnv?.push) {
|
|
4319
|
+
const destinations = flowConfig.destinations;
|
|
4320
|
+
const destConfig = destinations[options.destinationId]?.config;
|
|
4321
|
+
if (destConfig) {
|
|
4322
|
+
destConfig.env = devEnv.push;
|
|
4323
|
+
}
|
|
4324
|
+
if (devEnv.simulation?.length) {
|
|
4325
|
+
const combined = {
|
|
4326
|
+
...devEnv.push,
|
|
4327
|
+
simulation: devEnv.simulation
|
|
4328
|
+
};
|
|
4329
|
+
const { wrappedEnv, calls } = Ne(combined);
|
|
4330
|
+
if (destConfig) destConfig.env = wrappedEnv;
|
|
4331
|
+
trackedCalls = calls;
|
|
4332
|
+
}
|
|
4188
4333
|
}
|
|
4189
4334
|
}
|
|
4190
|
-
if (
|
|
4191
|
-
const result = await module.startFlow(
|
|
4335
|
+
if (flowConfig.sources) flowConfig.sources = {};
|
|
4336
|
+
const result = await module.startFlow(flowConfig);
|
|
4192
4337
|
if (!result?.collector)
|
|
4193
4338
|
throw new Error("Invalid bundle: collector not available");
|
|
4194
4339
|
const collector = result.collector;
|
|
@@ -4228,17 +4373,17 @@ init_core();
|
|
|
4228
4373
|
init_tmp();
|
|
4229
4374
|
init_config_file();
|
|
4230
4375
|
init_auth();
|
|
4231
|
-
import
|
|
4376
|
+
import path17 from "path";
|
|
4232
4377
|
import { writeFileSync as writeFileSync5 } from "fs";
|
|
4233
4378
|
import { homedir as homedir2 } from "os";
|
|
4234
4379
|
import { join as join4 } from "path";
|
|
4235
4380
|
|
|
4236
4381
|
// src/runtime/resolve-bundle.ts
|
|
4237
4382
|
init_stdin();
|
|
4238
|
-
import { existsSync as
|
|
4383
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
4239
4384
|
import { dirname } from "path";
|
|
4240
4385
|
function getDefaultWritePath() {
|
|
4241
|
-
if (
|
|
4386
|
+
if (existsSync2("/app/flow")) return "/app/flow/bundle.mjs";
|
|
4242
4387
|
return "/tmp/walkeros-bundle.mjs";
|
|
4243
4388
|
}
|
|
4244
4389
|
function isUrl2(value) {
|
|
@@ -4246,7 +4391,7 @@ function isUrl2(value) {
|
|
|
4246
4391
|
}
|
|
4247
4392
|
function writeBundleToDisk(writePath, content) {
|
|
4248
4393
|
const dir = dirname(writePath);
|
|
4249
|
-
if (!
|
|
4394
|
+
if (!existsSync2(dir)) {
|
|
4250
4395
|
mkdirSync2(dir, { recursive: true });
|
|
4251
4396
|
}
|
|
4252
4397
|
writeFileSync2(writePath, content, "utf-8");
|
|
@@ -4272,7 +4417,7 @@ async function readBundleFromStdin(writePath) {
|
|
|
4272
4417
|
}
|
|
4273
4418
|
async function resolveBundle(bundleEnv) {
|
|
4274
4419
|
const writePath = getDefaultWritePath();
|
|
4275
|
-
if (!isUrl2(bundleEnv) &&
|
|
4420
|
+
if (!isUrl2(bundleEnv) && existsSync2(bundleEnv)) {
|
|
4276
4421
|
return { path: bundleEnv, source: "file" };
|
|
4277
4422
|
}
|
|
4278
4423
|
if (isUrl2(bundleEnv)) {
|
|
@@ -4327,7 +4472,7 @@ init_cache();
|
|
|
4327
4472
|
|
|
4328
4473
|
// src/commands/run/validators.ts
|
|
4329
4474
|
init_asset_resolver();
|
|
4330
|
-
import { existsSync as
|
|
4475
|
+
import { existsSync as existsSync4 } from "fs";
|
|
4331
4476
|
|
|
4332
4477
|
// src/schemas/primitives.ts
|
|
4333
4478
|
import { z as z2 } from "@walkeros/core/dev";
|
|
@@ -4421,7 +4566,7 @@ var PushInputSchema = z7.object(PushInputShape);
|
|
|
4421
4566
|
// src/commands/run/validators.ts
|
|
4422
4567
|
function validateFlowFile(filePath) {
|
|
4423
4568
|
const absolutePath = resolveAsset(filePath, "bundle");
|
|
4424
|
-
if (!
|
|
4569
|
+
if (!existsSync4(absolutePath)) {
|
|
4425
4570
|
throw new Error(
|
|
4426
4571
|
`Flow file not found: ${filePath}
|
|
4427
4572
|
Resolved path: ${absolutePath}
|
|
@@ -4447,12 +4592,12 @@ init_utils3();
|
|
|
4447
4592
|
// src/commands/run/pipeline.ts
|
|
4448
4593
|
init_tmp();
|
|
4449
4594
|
import { writeFileSync as writeFileSync4 } from "fs";
|
|
4450
|
-
import
|
|
4595
|
+
import fs16 from "fs-extra";
|
|
4451
4596
|
|
|
4452
4597
|
// src/runtime/health-server.ts
|
|
4453
4598
|
import http from "http";
|
|
4454
4599
|
function createHealthServer(port, logger) {
|
|
4455
|
-
return new Promise((
|
|
4600
|
+
return new Promise((resolve4, reject) => {
|
|
4456
4601
|
let flowHandler = null;
|
|
4457
4602
|
const server = http.createServer((req, res) => {
|
|
4458
4603
|
if (req.url === "/health" && req.method === "GET") {
|
|
@@ -4479,7 +4624,7 @@ function createHealthServer(port, logger) {
|
|
|
4479
4624
|
server.headersTimeout = 1e4;
|
|
4480
4625
|
server.listen(port, "0.0.0.0", () => {
|
|
4481
4626
|
logger.info(`Health server listening on port ${port}`);
|
|
4482
|
-
|
|
4627
|
+
resolve4({
|
|
4483
4628
|
server,
|
|
4484
4629
|
setFlowHandler(handler) {
|
|
4485
4630
|
flowHandler = handler;
|
|
@@ -4573,9 +4718,9 @@ import { randomBytes } from "crypto";
|
|
|
4573
4718
|
|
|
4574
4719
|
// src/version.ts
|
|
4575
4720
|
import { readFileSync as readFileSync3 } from "fs";
|
|
4576
|
-
import { fileURLToPath
|
|
4721
|
+
import { fileURLToPath } from "url";
|
|
4577
4722
|
import { dirname as dirname3, join as join3 } from "path";
|
|
4578
|
-
var versionFilename =
|
|
4723
|
+
var versionFilename = fileURLToPath(import.meta.url);
|
|
4579
4724
|
var versionDirname = dirname3(versionFilename);
|
|
4580
4725
|
function findPackageJson() {
|
|
4581
4726
|
const paths = [
|
|
@@ -4868,7 +5013,7 @@ async function runPipeline(options) {
|
|
|
4868
5013
|
await currentBundleCleanup().catch(() => {
|
|
4869
5014
|
});
|
|
4870
5015
|
if (currentConfigPath)
|
|
4871
|
-
await
|
|
5016
|
+
await fs16.remove(currentConfigPath).catch(() => {
|
|
4872
5017
|
});
|
|
4873
5018
|
currentBundleCleanup = newBundleResult.cleanup;
|
|
4874
5019
|
currentConfigPath = tmpConfigPath;
|
|
@@ -4895,7 +5040,7 @@ async function runPipeline(options) {
|
|
|
4895
5040
|
await healthServer.close();
|
|
4896
5041
|
if (currentBundleCleanup) await currentBundleCleanup().catch(() => {
|
|
4897
5042
|
});
|
|
4898
|
-
if (currentConfigPath) await
|
|
5043
|
+
if (currentConfigPath) await fs16.remove(currentConfigPath).catch(() => {
|
|
4899
5044
|
});
|
|
4900
5045
|
logger.info("Shutdown complete");
|
|
4901
5046
|
clearTimeout(forceTimer);
|
|
@@ -5045,7 +5190,7 @@ async function resolveBundlePath(configInput, apiConfig, logger) {
|
|
|
5045
5190
|
logger.info(`Bundle: ${resolved.path}`);
|
|
5046
5191
|
}
|
|
5047
5192
|
if (isPreBuiltConfig(resolved.path)) {
|
|
5048
|
-
return
|
|
5193
|
+
return path17.resolve(resolved.path);
|
|
5049
5194
|
}
|
|
5050
5195
|
const flowFile = validateFlowFile(resolved.path);
|
|
5051
5196
|
logger.debug("Building flow bundle");
|
|
@@ -5111,7 +5256,7 @@ async function resolveBundlePath(configInput, apiConfig, logger) {
|
|
|
5111
5256
|
}
|
|
5112
5257
|
const defaultFile = "server-collect.mjs";
|
|
5113
5258
|
logger.debug(`No config specified, using default: ${defaultFile}`);
|
|
5114
|
-
return
|
|
5259
|
+
return path17.resolve(defaultFile);
|
|
5115
5260
|
}
|
|
5116
5261
|
async function run(options) {
|
|
5117
5262
|
const startTime = Date.now();
|
|
@@ -5371,18 +5516,29 @@ function validateFlow(input, options = {}) {
|
|
|
5371
5516
|
}
|
|
5372
5517
|
}
|
|
5373
5518
|
}
|
|
5374
|
-
|
|
5375
|
-
if (
|
|
5376
|
-
for (const [
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5519
|
+
let totalPackageCount = 0;
|
|
5520
|
+
if (flows && typeof flows === "object") {
|
|
5521
|
+
for (const [flowName, flowValue] of Object.entries(
|
|
5522
|
+
flows
|
|
5523
|
+
)) {
|
|
5524
|
+
const flow = flowValue;
|
|
5525
|
+
const packages = flow.bundle?.packages;
|
|
5526
|
+
if (packages && typeof packages === "object") {
|
|
5527
|
+
for (const [pkgName, pkgConfig] of Object.entries(packages)) {
|
|
5528
|
+
if (!pkgConfig.version && !pkgConfig.path) {
|
|
5529
|
+
warnings.push({
|
|
5530
|
+
path: `flows.${flowName}.bundle.packages.${pkgName}`,
|
|
5531
|
+
message: `Package "${pkgName}" has no version specified`,
|
|
5532
|
+
suggestion: "Consider specifying a version for reproducible builds"
|
|
5533
|
+
});
|
|
5534
|
+
}
|
|
5535
|
+
}
|
|
5536
|
+
totalPackageCount += Object.keys(packages).length;
|
|
5383
5537
|
}
|
|
5384
5538
|
}
|
|
5385
|
-
|
|
5539
|
+
}
|
|
5540
|
+
if (totalPackageCount > 0) {
|
|
5541
|
+
details.packageCount = totalPackageCount;
|
|
5386
5542
|
}
|
|
5387
5543
|
if (coreResult.context) {
|
|
5388
5544
|
details.context = coreResult.context;
|
|
@@ -6748,20 +6904,101 @@ async function feedbackCommand(text) {
|
|
|
6748
6904
|
}
|
|
6749
6905
|
}
|
|
6750
6906
|
function promptUser(question) {
|
|
6751
|
-
return new Promise((
|
|
6907
|
+
return new Promise((resolve4) => {
|
|
6752
6908
|
const rl = createInterface({
|
|
6753
6909
|
input: process.stdin,
|
|
6754
6910
|
output: process.stderr
|
|
6755
6911
|
});
|
|
6756
6912
|
rl.question(question, (answer) => {
|
|
6757
6913
|
rl.close();
|
|
6758
|
-
|
|
6914
|
+
resolve4(answer);
|
|
6759
6915
|
});
|
|
6760
6916
|
});
|
|
6761
6917
|
}
|
|
6762
6918
|
|
|
6763
6919
|
// src/index.ts
|
|
6764
6920
|
init_bundle();
|
|
6921
|
+
|
|
6922
|
+
// src/commands/bundle/wrap.ts
|
|
6923
|
+
init_bundler();
|
|
6924
|
+
import * as path18 from "path";
|
|
6925
|
+
import * as os2 from "os";
|
|
6926
|
+
import fs17 from "fs-extra";
|
|
6927
|
+
import * as esbuild2 from "esbuild";
|
|
6928
|
+
async function wrapSkeleton(options) {
|
|
6929
|
+
const {
|
|
6930
|
+
skeletonPath,
|
|
6931
|
+
platform,
|
|
6932
|
+
outputPath,
|
|
6933
|
+
windowCollector,
|
|
6934
|
+
windowElb,
|
|
6935
|
+
target,
|
|
6936
|
+
minify = true,
|
|
6937
|
+
minifyOptions
|
|
6938
|
+
} = options;
|
|
6939
|
+
if (options.previewScope && !/^[a-zA-Z0-9_-]{1,64}$/.test(options.previewScope)) {
|
|
6940
|
+
throw new Error(
|
|
6941
|
+
`Invalid previewScope "${options.previewScope}". Must match /^[a-zA-Z0-9_-]{1,64}$/.`
|
|
6942
|
+
);
|
|
6943
|
+
}
|
|
6944
|
+
if (options.previewOrigin && !/^[a-z0-9.-]+$/.test(options.previewOrigin)) {
|
|
6945
|
+
throw new Error(
|
|
6946
|
+
`Invalid previewOrigin "${options.previewOrigin}". Must be a bare hostname matching /^[a-z0-9.-]+$/.`
|
|
6947
|
+
);
|
|
6948
|
+
}
|
|
6949
|
+
if (!await fs17.pathExists(skeletonPath)) {
|
|
6950
|
+
throw new Error(`wrapSkeleton: skeleton not found at ${skeletonPath}`);
|
|
6951
|
+
}
|
|
6952
|
+
const absoluteSkeletonPath = path18.resolve(skeletonPath);
|
|
6953
|
+
const entryText = platform === "browser" ? generateWrapEntry(absoluteSkeletonPath, {
|
|
6954
|
+
...windowCollector ? { windowCollector } : {},
|
|
6955
|
+
...windowElb ? { windowElb } : {},
|
|
6956
|
+
...options.previewOrigin ? { previewOrigin: options.previewOrigin } : {},
|
|
6957
|
+
...options.previewScope ? { previewScope: options.previewScope } : {}
|
|
6958
|
+
}) : generateWrapEntryServer(absoluteSkeletonPath);
|
|
6959
|
+
const entryDir = await fs17.mkdtemp(path18.join(os2.tmpdir(), "walkeros-wrap-"));
|
|
6960
|
+
const entryPath = path18.join(entryDir, "entry.mjs");
|
|
6961
|
+
try {
|
|
6962
|
+
await fs17.writeFile(entryPath, entryText);
|
|
6963
|
+
await fs17.ensureDir(path18.dirname(outputPath));
|
|
6964
|
+
const esbuildOptions = {
|
|
6965
|
+
entryPoints: [entryPath],
|
|
6966
|
+
bundle: true,
|
|
6967
|
+
format: "esm",
|
|
6968
|
+
platform,
|
|
6969
|
+
outfile: outputPath,
|
|
6970
|
+
treeShaking: true,
|
|
6971
|
+
logLevel: "error",
|
|
6972
|
+
minify,
|
|
6973
|
+
...minify && {
|
|
6974
|
+
minifyWhitespace: minifyOptions?.whitespace ?? true,
|
|
6975
|
+
minifyIdentifiers: minifyOptions?.identifiers ?? true,
|
|
6976
|
+
minifySyntax: minifyOptions?.syntax ?? true,
|
|
6977
|
+
legalComments: minifyOptions?.legalComments ?? "none",
|
|
6978
|
+
charset: "utf8"
|
|
6979
|
+
}
|
|
6980
|
+
};
|
|
6981
|
+
if (platform === "browser") {
|
|
6982
|
+
esbuildOptions.define = {
|
|
6983
|
+
"process.env.NODE_ENV": '"production"',
|
|
6984
|
+
global: "globalThis"
|
|
6985
|
+
};
|
|
6986
|
+
esbuildOptions.target = target ?? "es2018";
|
|
6987
|
+
} else {
|
|
6988
|
+
esbuildOptions.external = getNodeExternals();
|
|
6989
|
+
esbuildOptions.banner = {
|
|
6990
|
+
js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
|
|
6991
|
+
};
|
|
6992
|
+
esbuildOptions.target = target ?? "node18";
|
|
6993
|
+
}
|
|
6994
|
+
await esbuild2.build(esbuildOptions);
|
|
6995
|
+
} finally {
|
|
6996
|
+
await fs17.remove(entryDir).catch(() => {
|
|
6997
|
+
});
|
|
6998
|
+
}
|
|
6999
|
+
}
|
|
7000
|
+
|
|
7001
|
+
// src/index.ts
|
|
6765
7002
|
init_auth();
|
|
6766
7003
|
init_http();
|
|
6767
7004
|
init_api_client();
|
|
@@ -6940,6 +7177,7 @@ export {
|
|
|
6940
7177
|
validateCommand,
|
|
6941
7178
|
whoami,
|
|
6942
7179
|
whoamiCommand,
|
|
7180
|
+
wrapSkeleton,
|
|
6943
7181
|
writeConfig
|
|
6944
7182
|
};
|
|
6945
7183
|
//# sourceMappingURL=index.js.map
|