@get-bb/plugin-sdk 0.6.42 → 0.6.49

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.
@@ -4454,6 +4454,7 @@ function makeQueueEntry(overrides = {}) {
4454
4454
  serviceTier: "default",
4455
4455
  groupWithNext: false,
4456
4456
  sendAt: null,
4457
+ state: "waiting",
4457
4458
  waitingOn: {
4458
4459
  kind: "plugin",
4459
4460
  pluginId: "test-plugin",
@@ -4483,6 +4484,362 @@ function makeTurnFailedEvent(overrides = {}) {
4483
4484
  // src/testing/public-sdk-only.ts
4484
4485
  import { readdirSync, readFileSync } from "node:fs";
4485
4486
  import { dirname, isAbsolute, join as join2, relative, resolve, sep } from "node:path";
4487
+
4488
+ // src/testing/module-references.ts
4489
+ var JsxMismatch = class extends Error {
4490
+ };
4491
+ var IDENTIFIER_START = /[\p{ID_Start}$_]/u;
4492
+ var IDENTIFIER_PART = /[\p{ID_Continue}$‌‍]/u;
4493
+ var JSX_NAME_PART = /[\p{ID_Continue}$\-:.]/u;
4494
+ var NUMBER_PART = /[\w.]/u;
4495
+ var WHITESPACE = /\s/u;
4496
+ var MULTI_CHARACTER_PUNCTUATORS = ["...", "?.", "=>", "++", "--"];
4497
+ var KEYWORDS_BEFORE_EXPRESSION = /* @__PURE__ */ new Set([
4498
+ "await",
4499
+ "case",
4500
+ "delete",
4501
+ "do",
4502
+ "else",
4503
+ "in",
4504
+ "instanceof",
4505
+ "new",
4506
+ "of",
4507
+ "return",
4508
+ "throw",
4509
+ "typeof",
4510
+ "void",
4511
+ "yield"
4512
+ ]);
4513
+ var DECLARATION_MODIFIERS = /* @__PURE__ */ new Set(["type", "typeof", "defer", "source"]);
4514
+ function tokenize(source, jsx) {
4515
+ const tokens = [];
4516
+ let pos = source.startsWith("#!") ? source.indexOf("\n") + 1 || source.length : 0;
4517
+ const push = (kind, value, start) => {
4518
+ tokens.push({ kind, value, start, end: pos });
4519
+ };
4520
+ const expressionMayStart = () => {
4521
+ const last = tokens.at(-1);
4522
+ if (last === void 0) return true;
4523
+ if (last.kind === "punct") {
4524
+ return ![")", "]", "++", "--"].includes(last.value);
4525
+ }
4526
+ return last.kind === "name" && KEYWORDS_BEFORE_EXPRESSION.has(last.value);
4527
+ };
4528
+ const skipComment = () => {
4529
+ if (source[pos] !== "/") return false;
4530
+ if (source[pos + 1] === "/") {
4531
+ const newline = source.indexOf("\n", pos);
4532
+ pos = newline === -1 ? source.length : newline;
4533
+ return true;
4534
+ }
4535
+ if (source[pos + 1] === "*") {
4536
+ const close = source.indexOf("*/", pos + 2);
4537
+ pos = close === -1 ? source.length : close + 2;
4538
+ return true;
4539
+ }
4540
+ return false;
4541
+ };
4542
+ const readString = () => {
4543
+ const start = pos;
4544
+ const quote = source[pos];
4545
+ pos++;
4546
+ while (pos < source.length) {
4547
+ const char = source[pos];
4548
+ if (char === "\\") {
4549
+ pos += 2;
4550
+ continue;
4551
+ }
4552
+ if (char === "\n") break;
4553
+ if (char === quote) {
4554
+ pos++;
4555
+ push("string", source.slice(start + 1, pos - 1), start);
4556
+ return;
4557
+ }
4558
+ pos++;
4559
+ }
4560
+ push("literal", source.slice(start, pos), start);
4561
+ };
4562
+ const readTemplate = () => {
4563
+ push("literal", "`", pos);
4564
+ pos++;
4565
+ while (pos < source.length) {
4566
+ const char = source[pos];
4567
+ if (char === "\\") {
4568
+ pos += 2;
4569
+ continue;
4570
+ }
4571
+ if (char === "`") {
4572
+ pos++;
4573
+ break;
4574
+ }
4575
+ if (char === "$" && source[pos + 1] === "{") {
4576
+ pos += 2;
4577
+ scan(true);
4578
+ continue;
4579
+ }
4580
+ pos++;
4581
+ }
4582
+ push("literal", "`", pos);
4583
+ };
4584
+ const readRegex = () => {
4585
+ const start = pos;
4586
+ let inClass = false;
4587
+ pos++;
4588
+ while (pos < source.length) {
4589
+ const char = source[pos];
4590
+ if (char === "\\") {
4591
+ pos += 2;
4592
+ continue;
4593
+ }
4594
+ if (char === "\n") break;
4595
+ pos++;
4596
+ if (inClass) {
4597
+ if (char === "]") inClass = false;
4598
+ } else if (char === "[") {
4599
+ inClass = true;
4600
+ } else if (char === "/") {
4601
+ while (pos < source.length && IDENTIFIER_PART.test(source[pos] ?? "")) {
4602
+ pos++;
4603
+ }
4604
+ break;
4605
+ }
4606
+ }
4607
+ push("literal", source.slice(start, pos), start);
4608
+ };
4609
+ const readWhile = (pattern) => {
4610
+ const start = pos;
4611
+ while (pos < source.length && pattern.test(source[pos] ?? "")) pos++;
4612
+ return source.slice(start, pos);
4613
+ };
4614
+ const skipJsxSpace = () => {
4615
+ while (pos < source.length) {
4616
+ if (WHITESPACE.test(source[pos] ?? "")) {
4617
+ pos++;
4618
+ } else if (!skipComment()) {
4619
+ return;
4620
+ }
4621
+ }
4622
+ };
4623
+ const readJsxName = () => IDENTIFIER_START.test(source[pos] ?? "") ? readWhile(JSX_NAME_PART) : "";
4624
+ const readJsxContainer = () => {
4625
+ push("punct", "{", pos);
4626
+ pos++;
4627
+ if (!scan(true)) throw new JsxMismatch();
4628
+ push("punct", "}", pos - 1);
4629
+ };
4630
+ const readJsxElement = () => {
4631
+ const start = pos;
4632
+ pos++;
4633
+ skipJsxSpace();
4634
+ const name = readJsxName();
4635
+ skipJsxSpace();
4636
+ if (name === "" && source[pos] !== ">") throw new JsxMismatch();
4637
+ if (source[pos] === "," || source.startsWith("extends", pos) && !IDENTIFIER_PART.test(source[pos + "extends".length] ?? "")) {
4638
+ throw new JsxMismatch();
4639
+ }
4640
+ push("literal", "<", start);
4641
+ for (; ; ) {
4642
+ skipJsxSpace();
4643
+ const char = source[pos];
4644
+ if (char === "/" && source[pos + 1] === ">") {
4645
+ pos += 2;
4646
+ return;
4647
+ }
4648
+ if (char === ">") {
4649
+ pos++;
4650
+ break;
4651
+ }
4652
+ if (char === "{") {
4653
+ readJsxContainer();
4654
+ continue;
4655
+ }
4656
+ if (readJsxName() === "") throw new JsxMismatch();
4657
+ skipJsxSpace();
4658
+ if (source[pos] !== "=") continue;
4659
+ pos++;
4660
+ skipJsxSpace();
4661
+ const value = source[pos];
4662
+ if (value === '"' || value === "'") {
4663
+ const close = source.indexOf(value, pos + 1);
4664
+ if (close === -1) throw new JsxMismatch();
4665
+ pos = close + 1;
4666
+ } else if (value === "{") {
4667
+ readJsxContainer();
4668
+ } else if (value === "<") {
4669
+ readJsxElement();
4670
+ } else {
4671
+ throw new JsxMismatch();
4672
+ }
4673
+ }
4674
+ while (pos < source.length) {
4675
+ const char = source[pos];
4676
+ if (char === "{") {
4677
+ readJsxContainer();
4678
+ } else if (char === "<") {
4679
+ const tagStart = pos;
4680
+ pos++;
4681
+ skipJsxSpace();
4682
+ if (source[pos] !== "/") {
4683
+ pos = tagStart;
4684
+ readJsxElement();
4685
+ continue;
4686
+ }
4687
+ pos++;
4688
+ skipJsxSpace();
4689
+ const closing = readJsxName();
4690
+ skipJsxSpace();
4691
+ if (closing !== name || source[pos] !== ">") throw new JsxMismatch();
4692
+ pos++;
4693
+ return;
4694
+ } else {
4695
+ pos++;
4696
+ }
4697
+ }
4698
+ throw new JsxMismatch();
4699
+ };
4700
+ const tryJsx = () => {
4701
+ const savedPos = pos;
4702
+ const savedLength = tokens.length;
4703
+ try {
4704
+ readJsxElement();
4705
+ return true;
4706
+ } catch (error) {
4707
+ if (!(error instanceof JsxMismatch)) throw error;
4708
+ pos = savedPos;
4709
+ tokens.length = savedLength;
4710
+ return false;
4711
+ }
4712
+ };
4713
+ function scan(untilClosingBrace) {
4714
+ let depth = 0;
4715
+ while (pos < source.length) {
4716
+ const char = source[pos] ?? "";
4717
+ const start = pos;
4718
+ if (WHITESPACE.test(char) || skipComment()) {
4719
+ if (pos === start) pos++;
4720
+ } else if (char === '"' || char === "'") {
4721
+ readString();
4722
+ } else if (char === "`") {
4723
+ readTemplate();
4724
+ } else if (char === "/" && expressionMayStart()) {
4725
+ readRegex();
4726
+ } else if (char === "<" && jsx && expressionMayStart() && tryJsx()) {
4727
+ continue;
4728
+ } else if (/\d/u.test(char) || char === "." && /\d/u.test(source[pos + 1] ?? "")) {
4729
+ push("literal", readWhile(NUMBER_PART), start);
4730
+ } else if (IDENTIFIER_START.test(char)) {
4731
+ push("name", readWhile(IDENTIFIER_PART), start);
4732
+ } else {
4733
+ if (char === "{") depth++;
4734
+ if (char === "}") {
4735
+ if (depth === 0 && untilClosingBrace) {
4736
+ pos++;
4737
+ return true;
4738
+ }
4739
+ depth--;
4740
+ }
4741
+ const punct = MULTI_CHARACTER_PUNCTUATORS.find(
4742
+ (candidate) => source.startsWith(candidate, pos) && !(candidate === "?." && /\d/u.test(source[pos + 2] ?? ""))
4743
+ ) ?? char;
4744
+ pos += punct.length;
4745
+ push("punct", punct, start);
4746
+ }
4747
+ }
4748
+ return false;
4749
+ }
4750
+ scan(false);
4751
+ return tokens;
4752
+ }
4753
+ function isPunct(token, value) {
4754
+ return token?.kind === "punct" && token.value === value;
4755
+ }
4756
+ function isName(token, value) {
4757
+ return token?.kind === "name" && (value === void 0 || token.value === value);
4758
+ }
4759
+ function closingIndex(tokens, open, opener, closer) {
4760
+ let depth = 0;
4761
+ for (let index = open; index < tokens.length; index++) {
4762
+ if (isPunct(tokens[index], opener)) depth++;
4763
+ if (isPunct(tokens[index], closer) && --depth === 0) return index;
4764
+ }
4765
+ return -1;
4766
+ }
4767
+ function specifierAfterFrom(tokens, index) {
4768
+ const specifier = tokens[index + 1];
4769
+ return isName(tokens[index], "from") && specifier?.kind === "string" ? specifier.value : void 0;
4770
+ }
4771
+ function importDeclarationSpecifier(tokens, keyword) {
4772
+ let index = keyword + 1;
4773
+ const first = tokens[index];
4774
+ if (first?.kind === "string") return first.value;
4775
+ const afterModifier = tokens[index + 1];
4776
+ if (first?.kind === "name" && DECLARATION_MODIFIERS.has(first.value) && (isPunct(afterModifier, "{") || isPunct(afterModifier, "*") || isName(afterModifier) && afterModifier?.value !== "from")) {
4777
+ index++;
4778
+ }
4779
+ if (isName(tokens[index])) {
4780
+ index++;
4781
+ if (!isPunct(tokens[index], ",")) return specifierAfterFrom(tokens, index);
4782
+ index++;
4783
+ }
4784
+ if (isPunct(tokens[index], "{")) {
4785
+ const close = closingIndex(tokens, index, "{", "}");
4786
+ return close === -1 ? void 0 : specifierAfterFrom(tokens, close + 1);
4787
+ }
4788
+ if (isPunct(tokens[index], "*") && isName(tokens[index + 1], "as")) {
4789
+ return specifierAfterFrom(tokens, index + 3);
4790
+ }
4791
+ return void 0;
4792
+ }
4793
+ function exportDeclarationSpecifier(tokens, keyword) {
4794
+ let index = keyword + 1;
4795
+ if (isName(tokens[index], "type")) index++;
4796
+ if (isPunct(tokens[index], "*")) {
4797
+ return isName(tokens[index + 1], "as") ? specifierAfterFrom(tokens, index + 3) : specifierAfterFrom(tokens, index + 1);
4798
+ }
4799
+ if (isPunct(tokens[index], "{")) {
4800
+ const close = closingIndex(tokens, index, "{", "}");
4801
+ return close === -1 ? void 0 : specifierAfterFrom(tokens, close + 1);
4802
+ }
4803
+ return void 0;
4804
+ }
4805
+ function moduleReferences(source, options) {
4806
+ const tokens = tokenize(source, options.jsx);
4807
+ const references = [];
4808
+ tokens.forEach((token, index) => {
4809
+ if (token.kind !== "name") return;
4810
+ const previous = tokens[index - 1];
4811
+ if ([".", "?.", "#"].some((value) => isPunct(previous, value))) return;
4812
+ const keyword = token.value;
4813
+ if ((keyword === "import" || keyword === "require") && isPunct(tokens[index + 1], "(")) {
4814
+ const close = closingIndex(tokens, index + 1, "(", ")");
4815
+ const after = tokens[close + 1];
4816
+ if (close === -1 || close === index + 2 || isPunct(after, "{") || isPunct(after, ":") && !isPunct(previous, "?")) {
4817
+ return;
4818
+ }
4819
+ const argument = tokens[index + 2];
4820
+ const argumentEnd = tokens[index + 3];
4821
+ if (argument?.kind === "string" && (isPunct(argumentEnd, ")") || isPunct(argumentEnd, ","))) {
4822
+ references.push({ specifier: argument.value, dynamic: false });
4823
+ return;
4824
+ }
4825
+ const open = tokens[index + 1];
4826
+ const closeToken = tokens[close];
4827
+ if (open === void 0 || closeToken === void 0) return;
4828
+ references.push({
4829
+ specifier: source.slice(open.end, closeToken.start).trim(),
4830
+ dynamic: true
4831
+ });
4832
+ return;
4833
+ }
4834
+ const specifier = keyword === "import" ? importDeclarationSpecifier(tokens, index) : keyword === "export" ? exportDeclarationSpecifier(tokens, index) : void 0;
4835
+ if (specifier !== void 0) {
4836
+ references.push({ specifier, dynamic: false });
4837
+ }
4838
+ });
4839
+ return references;
4840
+ }
4841
+
4842
+ // src/testing/public-sdk-only.ts
4486
4843
  var SKIPPED_DIRECTORIES = /* @__PURE__ */ new Set(["node_modules", "dist"]);
4487
4844
  var SOURCE_EXTENSIONS = /\.(?:[cm]?[jt]s|tsx)$/u;
4488
4845
  var TEST_FILE_PATTERN = /\.test\.[cm]?[jt]sx?$/u;
@@ -4498,8 +4855,6 @@ var TEST_IMPORT_ALLOWLIST = [
4498
4855
  /^@get-bb\/plugin-sdk\/(?:testing|testing\/app|testing\/host|provider-bridge\/testing)$/u,
4499
4856
  /^vitest$/u
4500
4857
  ];
4501
- var IMPORT_SPECIFIER_PATTERN = /(?:\bfrom\s*|\bimport\s*\(?\s*|\brequire\s*\(\s*)["']([^"']+)["']/gu;
4502
- var DYNAMIC_SPECIFIER_PATTERN = /\b(?:import|require)\s*\(\s*(?!["'])([^)]+)\)/gu;
4503
4858
  var RELATIVE_SPECIFIER_PATTERN = /^\.\.?\//u;
4504
4859
  function listSourceFiles(directory) {
4505
4860
  const files = [];
@@ -4516,16 +4871,6 @@ function listSourceFiles(directory) {
4516
4871
  }
4517
4872
  return files;
4518
4873
  }
4519
- function importSpecifiers(source) {
4520
- return [...source.matchAll(IMPORT_SPECIFIER_PATTERN)].map(
4521
- (match) => match[1] ?? ""
4522
- );
4523
- }
4524
- function dynamicSpecifiers(source) {
4525
- return [...source.matchAll(DYNAMIC_SPECIFIER_PATTERN)].map(
4526
- (match) => (match[1] ?? "").trim()
4527
- );
4528
- }
4529
4874
  function escapesPackage(packageRoot, file, specifier) {
4530
4875
  const target = relative(packageRoot, resolve(dirname(file), specifier));
4531
4876
  return isAbsolute(target) || target === ".." || target.startsWith(`..${sep}`);
@@ -4553,9 +4898,13 @@ function scanPublicSdkOnly(packageRoot, options = {}) {
4553
4898
  const file = relative(packageRoot, path);
4554
4899
  files.push(file);
4555
4900
  const allowlist = TEST_FILE_PATTERN.test(path) ? testAllowlist : pluginAllowlist;
4556
- const source = readFileSync(path, "utf8");
4557
- for (const specifier of importSpecifiers(source)) {
4558
- if (specifier.startsWith(PRIVATE_PACKAGE_PREFIX)) {
4901
+ const references = moduleReferences(readFileSync(path, "utf8"), {
4902
+ jsx: path.endsWith(".tsx")
4903
+ });
4904
+ for (const { specifier, dynamic } of references) {
4905
+ if (dynamic) {
4906
+ violations.push({ file, specifier, reason: "dynamic-specifier" });
4907
+ } else if (specifier.startsWith(PRIVATE_PACKAGE_PREFIX)) {
4559
4908
  violations.push({ file, specifier, reason: "private-package" });
4560
4909
  } else if (RELATIVE_SPECIFIER_PATTERN.test(specifier) && escapesPackage(packageRoot, path, specifier) && !extra.some((pattern) => pattern.test(specifier))) {
4561
4910
  violations.push({ file, specifier, reason: "outside-package" });
@@ -4563,9 +4912,6 @@ function scanPublicSdkOnly(packageRoot, options = {}) {
4563
4912
  violations.push({ file, specifier, reason: "outside-allowlist" });
4564
4913
  }
4565
4914
  }
4566
- for (const specifier of dynamicSpecifiers(source)) {
4567
- violations.push({ file, specifier, reason: "dynamic-specifier" });
4568
- }
4569
4915
  }
4570
4916
  return {
4571
4917
  files,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@get-bb/plugin-sdk",
3
- "version": "0.6.42",
3
+ "version": "0.6.49",
4
4
  "homepage": "https://github.com/get-bb/bb#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/get-bb/bb/issues"