vscode-behavior3 2.2.0 → 2.3.3

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/dist/build-cli.js CHANGED
@@ -212496,10 +212496,7 @@ function customAlphabet(alphabet, size = 21) {
212496
212496
 
212497
212497
  // webview/shared/stable-id.ts
212498
212498
  var UUID_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
212499
- var generateUuid = customAlphabet(
212500
- UUID_ALPHABET,
212501
- 10
212502
- );
212499
+ var generateUuid = customAlphabet(UUID_ALPHABET, 10);
212503
212500
  var hashString = (value) => {
212504
212501
  let hash = 2166136261;
212505
212502
  for (let index = 0; index < value.length; index += 1) {
@@ -212513,7 +212510,7 @@ var generateDeterministicUuid = (seed) => {
212513
212510
  let result = "";
212514
212511
  for (let index = 0; index < 10; index += 1) {
212515
212512
  state = Math.imul(state ^ state >>> 16, 2246822519) >>> 0;
212516
- state ^= hashString(`${seed}:${index}`);
212513
+ state = (state ^ hashString(`${seed}:${index}`)) >>> 0;
212517
212514
  result += UUID_ALPHABET[state % UUID_ALPHABET.length];
212518
212515
  }
212519
212516
  return result;
@@ -212559,6 +212556,12 @@ var asRequiredString = (value, label) => {
212559
212556
  }
212560
212557
  return value;
212561
212558
  };
212559
+ var normalizeTreeVersion = (value) => {
212560
+ if (value === void 0) {
212561
+ return DOCUMENT_VERSION;
212562
+ }
212563
+ return asRequiredString(value, "tree file version");
212564
+ };
212562
212565
  var asStringArray = (value, label) => {
212563
212566
  if (value === void 0) {
212564
212567
  return [];
@@ -212874,7 +212877,7 @@ var normalizeTreeData = (value, opts) => {
212874
212877
  const variablesValue = record.variables;
212875
212878
  const variablesRecord = variablesValue === void 0 ? void 0 : expectPlainRecord(variablesValue, "tree file variables");
212876
212879
  return {
212877
- version: asRequiredString(record.version, "tree file version"),
212880
+ version: normalizeTreeVersion(record.version),
212878
212881
  name: asRequiredString(record.name, "tree file name"),
212879
212882
  prefix: asOptionalString(record.prefix) ?? "",
212880
212883
  desc: asOptionalString(record.desc),
@@ -213034,10 +213037,10 @@ var collectReachableSubtreePaths = (root) => {
213034
213037
  });
213035
213038
  return Array.from(paths);
213036
213039
  };
213037
- var hasMissingStableIds = (content) => {
213040
+ var needsLegacyTreeWriteback = (content) => {
213038
213041
  try {
213039
213042
  const parsed = JSON.parse(content);
213040
- return subtreeNeedsMissingIds(parsed.root) || parsed.$override !== void 0 || parsed.import !== void 0 || parsed.vars !== void 0;
213043
+ return parsed.version === void 0 || subtreeNeedsMissingIds(parsed.root) || parsed.$override !== void 0 || parsed.import !== void 0 || parsed.vars !== void 0;
213041
213044
  } catch {
213042
213045
  return false;
213043
213046
  }
@@ -213060,7 +213063,7 @@ var loadSubtreeSourceCache = async (params) => {
213060
213063
  return;
213061
213064
  }
213062
213065
  try {
213063
- const needsWriteback = hasMissingStableIds(content);
213066
+ const needsWriteback = needsLegacyTreeWriteback(content);
213064
213067
  const tree = parsePersistedTreeContent(content, normalizedPath);
213065
213068
  cache[normalizedPath] = tree;
213066
213069
  await params.onTreeLoaded?.({
@@ -213347,14 +213350,15 @@ var readWorkspaceSettings = (path3) => {
213347
213350
  const content = getFs().readFileSync(path3, "utf-8");
213348
213351
  return parseWorkspaceModelContent(content).settings;
213349
213352
  };
213350
- var hasBatchHookMethod = (obj) => {
213353
+ var hasBuildHookMethod = (obj) => {
213351
213354
  if (!obj || typeof obj !== "object") {
213352
213355
  return false;
213353
213356
  }
213354
213357
  const candidate = obj;
213355
- return typeof candidate.shouldUpgradeTree === "function" || typeof candidate.onProcessTree === "function" || typeof candidate.onProcessNode === "function" || typeof candidate.onWriteFile === "function" || typeof candidate.onComplete === "function";
213358
+ return typeof candidate.onProcessTree === "function" || typeof candidate.onProcessNode === "function" || typeof candidate.onWriteFile === "function" || typeof candidate.onComplete === "function";
213356
213359
  };
213357
213360
  var BUILD_HOOK_MARKER = "__behavior3BuildHook";
213361
+ var BATCH_HOOK_MARKER = "__behavior3BatchHook";
213358
213362
  var CHECK_HOOK_MARKER = "__behavior3CheckHook";
213359
213363
  var CHECK_HOOK_NAME = "__behavior3CheckName";
213360
213364
  var markBuildHook = (ctor) => {
@@ -213364,6 +213368,13 @@ var markBuildHook = (ctor) => {
213364
213368
  });
213365
213369
  return ctor;
213366
213370
  };
213371
+ var markBatchHook = (ctor) => {
213372
+ Object.defineProperty(ctor, BATCH_HOOK_MARKER, {
213373
+ value: true,
213374
+ configurable: false
213375
+ });
213376
+ return ctor;
213377
+ };
213367
213378
  var markCheckCtor = (ctor, explicitName) => {
213368
213379
  const name = explicitName?.trim() || ctor.name;
213369
213380
  Object.defineProperty(ctor, CHECK_HOOK_MARKER, {
@@ -213382,28 +213393,51 @@ var markCheckHook = (nameOrCtor, _context) => {
213382
213393
  }
213383
213394
  return (ctor) => markCheckCtor(ctor, nameOrCtor);
213384
213395
  };
213385
- var isDecoratedHookCtor = (value) => typeof value === "function" && value[BUILD_HOOK_MARKER] === true;
213396
+ var isDecoratedBuildHookCtor = (value) => typeof value === "function" && value[BUILD_HOOK_MARKER] === true;
213397
+ var isDecoratedBatchHookCtor = (value) => typeof value === "function" && value[BATCH_HOOK_MARKER] === true;
213386
213398
  var isDecoratedCheckCtor = (value) => typeof value === "function" && value[CHECK_HOOK_MARKER] === true;
213387
- var findDecoratedHookCtor = (moduleRecord) => {
213388
- const decorated = Array.from(new Set(Object.values(moduleRecord))).filter(isDecoratedHookCtor);
213399
+ var findDecoratedBuildHookCtor = (moduleRecord) => {
213400
+ const decorated = Array.from(new Set(Object.values(moduleRecord))).filter(
213401
+ isDecoratedBuildHookCtor
213402
+ );
213389
213403
  if (decorated.length > 1) {
213390
213404
  logger.error("build script must decorate exactly one exported class with @behavior3.build");
213391
213405
  return void 0;
213392
213406
  }
213393
213407
  return decorated[0];
213394
213408
  };
213409
+ var findDecoratedBatchHookCtor = (moduleRecord) => {
213410
+ const decorated = Array.from(new Set(Object.values(moduleRecord))).filter(
213411
+ isDecoratedBatchHookCtor
213412
+ );
213413
+ if (decorated.length > 1) {
213414
+ logger.error("batch script must decorate exactly one exported class with @behavior3.batch");
213415
+ return void 0;
213416
+ }
213417
+ if (decorated.length === 1) {
213418
+ return decorated[0];
213419
+ }
213420
+ const legacyDecorated = Array.from(new Set(Object.values(moduleRecord))).filter(
213421
+ isDecoratedBuildHookCtor
213422
+ );
213423
+ if (legacyDecorated.length > 1) {
213424
+ logger.error("batch script must decorate exactly one exported class with @behavior3.batch");
213425
+ return void 0;
213426
+ }
213427
+ return legacyDecorated[0];
213428
+ };
213395
213429
  var findDecoratedCheckCtors = (moduleRecord) => Array.from(new Set(Object.values(moduleRecord))).filter(isDecoratedCheckCtor);
213396
- var createBatchHooks = (moduleExports, env, reportMissing = true) => {
213430
+ var createBuildHooks = (moduleExports, env, reportMissing = true) => {
213397
213431
  if (!moduleExports || typeof moduleExports !== "object") {
213398
213432
  return void 0;
213399
213433
  }
213400
213434
  const moduleRecord = moduleExports;
213401
- const defaultExport = isDecoratedCheckCtor(moduleRecord.default) ? void 0 : moduleRecord.default;
213402
- const ctor = moduleRecord.Hook ?? findDecoratedHookCtor(moduleRecord) ?? defaultExport;
213435
+ const defaultExport = isDecoratedCheckCtor(moduleRecord.default) || isDecoratedBatchHookCtor(moduleRecord.default) ? void 0 : moduleRecord.default;
213436
+ const ctor = moduleRecord.BuildHook ?? moduleRecord.Hook ?? findDecoratedBuildHookCtor(moduleRecord) ?? defaultExport;
213403
213437
  if (typeof ctor === "function") {
213404
213438
  try {
213405
213439
  const instance = new ctor(env);
213406
- if (hasBatchHookMethod(instance)) {
213440
+ if (hasBuildHookMethod(instance)) {
213407
213441
  return instance;
213408
213442
  }
213409
213443
  logger.error("build hook class instance has no supported hook methods");
@@ -213413,7 +213447,32 @@ var createBatchHooks = (moduleExports, env, reportMissing = true) => {
213413
213447
  }
213414
213448
  if (reportMissing) {
213415
213449
  logger.error(
213416
- "build script must export a Hook class, default class, or one @behavior3.build-decorated class"
213450
+ "build script must export a BuildHook class, Hook class, default class, or one @behavior3.build-decorated class"
213451
+ );
213452
+ }
213453
+ return void 0;
213454
+ };
213455
+ var createBatchHooks = (moduleExports, env, reportMissing = true) => {
213456
+ if (!moduleExports || typeof moduleExports !== "object") {
213457
+ return void 0;
213458
+ }
213459
+ const moduleRecord = moduleExports;
213460
+ const defaultExport = isDecoratedCheckCtor(moduleRecord.default) || isDecoratedBuildHookCtor(moduleRecord.default) || isDecoratedBatchHookCtor(moduleRecord.default) ? void 0 : moduleRecord.default;
213461
+ const ctor = moduleRecord.BatchHook ?? findDecoratedBatchHookCtor(moduleRecord) ?? moduleRecord.Hook ?? defaultExport;
213462
+ if (typeof ctor === "function") {
213463
+ try {
213464
+ const instance = new ctor(env);
213465
+ if (hasBuildHookMethod(instance) || typeof instance.shouldUpgradeTree === "function") {
213466
+ return instance;
213467
+ }
213468
+ logger.error("batch hook class instance has no supported hook methods");
213469
+ } catch (error) {
213470
+ logger.error("failed to instantiate batch hook class", error);
213471
+ }
213472
+ }
213473
+ if (reportMissing) {
213474
+ logger.error(
213475
+ "batch script must export a BatchHook class, default class, or one @behavior3.batch-decorated class"
213417
213476
  );
213418
213477
  }
213419
213478
  return void 0;
@@ -213462,13 +213521,13 @@ var createBuildScriptRuntime = (moduleExports, env) => {
213462
213521
  };
213463
213522
  }
213464
213523
  const moduleRecord = moduleExports;
213465
- const hasBuildHookCandidate = typeof moduleRecord.Hook === "function" || Object.values(moduleRecord).some(isDecoratedHookCtor) || typeof moduleRecord.default === "function" && !isDecoratedCheckCtor(moduleRecord.default);
213466
- const buildScript = createBatchHooks(moduleExports, env, false);
213524
+ const hasBuildHookCandidate = typeof moduleRecord.BuildHook === "function" || typeof moduleRecord.Hook === "function" || Object.values(moduleRecord).some(isDecoratedBuildHookCtor) || typeof moduleRecord.default === "function" && !isDecoratedCheckCtor(moduleRecord.default) && !isDecoratedBatchHookCtor(moduleRecord.default);
213525
+ const buildScript = createBuildHooks(moduleExports, env, false);
213467
213526
  const checkerResult = createNodeArgCheckers(moduleExports, env);
213468
213527
  const hasEntries = Boolean(buildScript) || checkerResult.hasCheckers;
213469
213528
  if (!hasEntries) {
213470
213529
  logger.error(
213471
- "build script must export a Hook class, default build class, @behavior3.build class, or @behavior3.check class"
213530
+ "build script must export a BuildHook class, Hook class, default build class, @behavior3.build class, or @behavior3.check class"
213472
213531
  );
213473
213532
  }
213474
213533
  return {
@@ -213889,6 +213948,7 @@ var applyBehavior3DecoratorGlobal = () => {
213889
213948
  runtimeGlobal.behavior3 = {
213890
213949
  ...decoratorGlobalState.previousBehavior3 && typeof decoratorGlobalState.previousBehavior3 === "object" ? decoratorGlobalState.previousBehavior3 : {},
213891
213950
  build: markBuildHook,
213951
+ batch: markBatchHook,
213892
213952
  check: markCheckHook
213893
213953
  };
213894
213954
  };
@@ -213909,7 +213969,7 @@ var restoreBehavior3DecoratorGlobal = () => {
213909
213969
  decoratorGlobalState.hadBehavior3 = false;
213910
213970
  decoratorGlobalState.previousBehavior3 = void 0;
213911
213971
  };
213912
- var withBehavior3BuildDecoratorGlobal = async (loader) => {
213972
+ var withBehavior3ScriptDecoratorGlobal = async (loader) => {
213913
213973
  applyBehavior3DecoratorGlobal();
213914
213974
  try {
213915
213975
  return await loader();
@@ -214048,7 +214108,7 @@ var loadRuntimeModule = async (modulePath, options) => {
214048
214108
  }
214049
214109
  }
214050
214110
  if (getRuntimeProcess()?.type === "renderer") {
214051
- return await withBehavior3BuildDecoratorGlobal(
214111
+ return await withBehavior3ScriptDecoratorGlobal(
214052
214112
  () => import(
214053
214113
  /* @vite-ignore */
214054
214114
  `${modulePath}?t=${Date.now()}`
@@ -214076,7 +214136,7 @@ var loadRuntimeModule = async (modulePath, options) => {
214076
214136
  return null;
214077
214137
  }
214078
214138
  const normalizedModulePath = b3path_default.posixPath(tempModulePath);
214079
- const result = await withBehavior3BuildDecoratorGlobal(
214139
+ const result = await withBehavior3ScriptDecoratorGlobal(
214080
214140
  () => import(
214081
214141
  /* @vite-ignore */
214082
214142
  `file:///${normalizedModulePath}?t=${Date.now()}`
@@ -217178,6 +217238,14 @@ var validateExpressionEntries = (entries, usingVars, checkExpr) => {
217178
217238
  return null;
217179
217239
  };
217180
217240
  var getArgLabel = (arg) => arg.desc || arg.name;
217241
+ var findNodeArgOneofInputIndex = (arg, inputDefs) => {
217242
+ if (!arg.oneof || !inputDefs?.length) {
217243
+ return -1;
217244
+ }
217245
+ return inputDefs.findIndex(
217246
+ (input, index) => parseSlotDefinition(input, inputDefs, index).label === arg.oneof
217247
+ );
217248
+ };
217181
217249
  var isRequiredNodeArgValueMissing = (arg, value) => {
217182
217250
  if (isNodeArgOptional(arg)) {
217183
217251
  return false;
@@ -217292,6 +217360,28 @@ var validateNodeArgValue = (params) => {
217292
217360
  }
217293
217361
  return validateNodeArgScalarValue(arg, value, args, validateOptions);
217294
217362
  };
217363
+ var validateNodeArgOneof = (params) => {
217364
+ const { arg, argValue, inputValues, inputDefs } = params;
217365
+ if (!arg.oneof) {
217366
+ return null;
217367
+ }
217368
+ const relatedInputIndex = findNodeArgOneofInputIndex(arg, inputDefs);
217369
+ if (relatedInputIndex < 0) {
217370
+ return {
217371
+ code: "missing-oneof-input",
217372
+ argName: arg.name,
217373
+ inputLabel: arg.oneof
217374
+ };
217375
+ }
217376
+ if (checkOneof(arg, argValue, inputValues?.[relatedInputIndex])) {
217377
+ return null;
217378
+ }
217379
+ return {
217380
+ code: "oneof-conflict",
217381
+ argName: arg.name,
217382
+ inputLabel: arg.oneof
217383
+ };
217384
+ };
217295
217385
 
217296
217386
  // webview/shared/b3build-context.ts
217297
217387
  var unknownNodeDef = {
@@ -217375,6 +217465,10 @@ var formatBuildDiagnostic = (diagnostic) => {
217375
217465
  return `intput field '${diagnostic.label}' is required`;
217376
217466
  case "required-output":
217377
217467
  return `output field '${diagnostic.label}' is required`;
217468
+ case "missing-oneof-input":
217469
+ return `missing oneof input slot '${diagnostic.inputLabel}' for arg '${diagnostic.argName}'`;
217470
+ case "oneof-conflict":
217471
+ return `only one of arg '${diagnostic.argName}' and input '${diagnostic.inputLabel}' can be set`;
217378
217472
  case "invalid-arg-value": {
217379
217473
  const value = JSON.stringify(diagnostic.value);
217380
217474
  switch (diagnostic.expected) {
@@ -217415,14 +217509,15 @@ var checkNodeArg = (data, conf, i, printer) => {
217415
217509
  const diagnostics = validateNodeArgValue({ arg, value, args: data.args ?? {} });
217416
217510
  let hasError = diagnostics.length > 0;
217417
217511
  diagnostics.forEach((diagnostic) => error(formatBuildDiagnostic(diagnostic)));
217418
- if (arg.oneof !== void 0) {
217419
- const idx = conf.input?.findIndex((v) => v.startsWith(arg.oneof)) ?? -1;
217420
- if (!checkOneof(arg, data.args?.[arg.name], data.input?.[idx])) {
217421
- error(
217422
- `only one is allowed for between argument '${arg.name}' and input '${data.input?.[idx]}'`
217423
- );
217424
- hasError = true;
217425
- }
217512
+ const oneofDiagnostic = validateNodeArgOneof({
217513
+ arg,
217514
+ argValue: value,
217515
+ inputValues: data.input,
217516
+ inputDefs: conf.input
217517
+ });
217518
+ if (oneofDiagnostic) {
217519
+ error(formatBuildDiagnostic(oneofDiagnostic));
217520
+ hasError = true;
217426
217521
  }
217427
217522
  return !hasError;
217428
217523
  };