@userreason/wizard 0.2.0 → 0.2.1

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.
@@ -3,9 +3,9 @@ import {
3
3
  applyAgentNote,
4
4
  offerAgentNote,
5
5
  planAgentNote
6
- } from "./chunk-KV6GSBTQ.js";
6
+ } from "./chunk-ULHKVBPD.js";
7
7
  import "./chunk-SJVLAYGG.js";
8
- import "./chunk-6DCCEVPD.js";
8
+ import "./chunk-5SC2K42Q.js";
9
9
  import "./chunk-YMSGDC4B.js";
10
10
  import "./chunk-OEGNGGZ2.js";
11
11
  import "./chunk-GGARVSPT.js";
package/dist/bin.js CHANGED
@@ -3,7 +3,7 @@ import { createRequire as createWizardRequire } from 'node:module'; import { fil
3
3
  import {
4
4
  offerAgentNote,
5
5
  planAgentNote
6
- } from "./chunk-KV6GSBTQ.js";
6
+ } from "./chunk-ULHKVBPD.js";
7
7
  import {
8
8
  offerAgentSkill,
9
9
  planAgentSkill
@@ -37,14 +37,14 @@ import {
37
37
  resolveInstallation,
38
38
  saveInstallation,
39
39
  savedInstallation
40
- } from "./chunk-FC7PZNYW.js";
40
+ } from "./chunk-ZGZOBW2B.js";
41
41
  import {
42
42
  applyIntegration,
43
43
  detectInstallation,
44
44
  integrationAdditions,
45
45
  integrationPreview,
46
46
  planIntegration
47
- } from "./chunk-6DCCEVPD.js";
47
+ } from "./chunk-5SC2K42Q.js";
48
48
  import {
49
49
  SdkInstallError,
50
50
  cliCommand,
@@ -673,8 +673,26 @@ function reactRoots(ast) {
673
673
  if (!creationCount && renders.length > 1) return [];
674
674
  return renders.flatMap((node) => node.arguments[0] ? [node.arguments[0]] : []);
675
675
  }
676
- function existing(text, config = dummy) {
677
- const ast = parse("entry.tsx", text), calls = ast ? sdkCalls(ast) : [];
676
+ function integrationReferences(ast) {
677
+ const modules = nodes(ast, import_typescript.default.isStringLiteral).filter((literal) => {
678
+ const parent = literal.parent;
679
+ return (import_typescript.default.isImportDeclaration(parent) || import_typescript.default.isExportDeclaration(parent)) && parent.moduleSpecifier === literal || import_typescript.default.isExternalModuleReference(parent) && parent.expression === literal || import_typescript.default.isCallExpression(parent) && parent.arguments[0] === literal && (parent.expression.kind === import_typescript.default.SyntaxKind.ImportKeyword || import_typescript.default.isIdentifier(parent.expression) && parent.expression.text === "require");
680
+ }).map((literal) => literal.text);
681
+ const tags = nodes(ast, (node) => import_typescript.default.isJsxOpeningElement(node) || import_typescript.default.isJsxSelfClosingElement(node)).map((node) => node.tagName.getText(ast));
682
+ const globalAccess = nodes(ast, import_typescript.default.isElementAccessExpression).some((node) => import_typescript.default.isIdentifier(node.expression) && ["window", "globalThis", "self", "global"].includes(node.expression.text) && import_typescript.default.isStringLiteralLike(node.argumentExpression) && node.argumentExpression.text === "UserReason");
683
+ const identifier = nodes(ast, import_typescript.default.isIdentifier).some((node) => {
684
+ if (node.text !== "UserReason") return false;
685
+ const parent = node.parent;
686
+ if ((import_typescript.default.isPropertyAssignment(parent) || import_typescript.default.isPropertyDeclaration(parent) || import_typescript.default.isPropertySignature(parent) || import_typescript.default.isMethodDeclaration(parent) || import_typescript.default.isMethodSignature(parent) || import_typescript.default.isGetAccessorDeclaration(parent) || import_typescript.default.isSetAccessorDeclaration(parent) || import_typescript.default.isJsxAttribute(parent)) && parent.name === node) return false;
687
+ if ((import_typescript.default.isBindingElement(parent) || import_typescript.default.isImportSpecifier(parent)) && parent.propertyName === node) return false;
688
+ if (import_typescript.default.isExportSpecifier(parent) && parent.name === node && parent.propertyName) return false;
689
+ if (import_typescript.default.isLabeledStatement(parent) || import_typescript.default.isBreakStatement(parent) || import_typescript.default.isContinueStatement(parent)) return false;
690
+ return true;
691
+ });
692
+ return { modules, tags, identifier: identifier || globalAccess };
693
+ }
694
+ function existing(text, config = dummy, path = "entry.tsx") {
695
+ const ast = parse(path, text), calls = ast ? sdkCalls(ast) : [];
678
696
  if (calls.length) {
679
697
  try {
680
698
  let first;
@@ -690,11 +708,13 @@ function existing(text, config = dummy) {
690
708
  }
691
709
  return { status: "integrated", reason: "SDK initialization is already present; its configuration is preserved." };
692
710
  }
693
- if (/userreason\.generated/.test(text) && /<UserReasonProvider\s*\/?\s*>/.test(text))
711
+ if (!ast) return;
712
+ const references = integrationReferences(ast);
713
+ if (references.modules.some((name) => /userreason\.generated/.test(name)) && references.tags.includes("UserReasonProvider"))
694
714
  return { status: "integrated", reason: "Existing generated initialization is already present." };
695
- if (/userreason\.client/.test(text) && /<UserReasonInit\s*\/?\s*>/.test(text))
715
+ if (references.modules.some((name) => /userreason\.client/.test(name)) && references.tags.includes("UserReasonInit"))
696
716
  return { status: "integrated", reason: "Browser initialization is already present." };
697
- if (/\bUserReason\b|userreason\.generated|from\s*['"]@userreason\/js['"]/.test(text))
717
+ if (references.identifier || references.modules.some((name) => name === "@userreason/js" || /userreason\.(?:generated|client)/.test(name)))
698
718
  return { status: "manual", reason: "An existing UserReason integration needs review before editing the entry." };
699
719
  }
700
720
  async function planIntegration(project, config = dummy) {
@@ -716,11 +736,13 @@ async function planIntegration(project, config = dummy) {
716
736
  const found2 = files.filter((value) => value.text !== void 0);
717
737
  if (found2.length > 1) return { status: "manual", reason: "Multiple instrumentation-client files need review." };
718
738
  for (const root of ["app/layout.tsx", "app/layout.jsx", "app/layout.js", "pages/_app.tsx", "pages/_app.jsx", "pages/_app.js"]) {
719
- const rootText = await source(project, join(directory, root));
720
- if (rootText && /userreason\.(?:generated|client)/.test(rootText)) return existing(rootText) ?? { status: "manual", reason: "Existing root initialization needs review." };
739
+ const rootPath = join(directory, root), rootText = await source(project, rootPath);
740
+ const rootAst = rootText ? parse(rootPath, rootText) : void 0;
741
+ if (rootText && rootAst && integrationReferences(rootAst).modules.some((name2) => /userreason\.(?:generated|client)/.test(name2)))
742
+ return existing(rootText, dummy, rootPath) ?? { status: "manual", reason: "Existing root initialization needs review." };
721
743
  }
722
744
  const { path: path2, text: text2 } = found2[0] ?? files[project.typescript ? 0 : 1];
723
- const current2 = text2 ? existing(text2, config) : void 0;
745
+ const current2 = text2 ? existing(text2, config, path2) : void 0;
724
746
  if (current2) return current2;
725
747
  const ast = parse(path2, text2 ?? "");
726
748
  if (!ast) return { status: "manual", reason: "Client instrumentation could not be parsed safely." };
@@ -776,7 +798,7 @@ ${initializationSource(config)}`),
776
798
  };
777
799
  const { path, text } = found[0];
778
800
  const name = project.framework === "next" ? "UserReasonInit" : "UserReason";
779
- const current = existing(text, config);
801
+ const current = existing(text, config, path);
780
802
  if (current) return current;
781
803
  let after;
782
804
  {
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-SJVLAYGG.js";
5
5
  import {
6
6
  initializationPath
7
- } from "./chunk-6DCCEVPD.js";
7
+ } from "./chunk-5SC2K42Q.js";
8
8
  import {
9
9
  cliCommand
10
10
  } from "./chunk-YMSGDC4B.js";
@@ -1,7 +1,7 @@
1
1
  import { createRequire as createWizardRequire } from 'node:module'; import { fileURLToPath as wizardFileURLToPath } from 'node:url'; import { dirname as wizardDirname } from 'node:path'; const require = createWizardRequire(import.meta.url); const __filename = wizardFileURLToPath(import.meta.url); const __dirname = wizardDirname(__filename);
2
2
  import {
3
3
  detectInstallation
4
- } from "./chunk-6DCCEVPD.js";
4
+ } from "./chunk-5SC2K42Q.js";
5
5
  import {
6
6
  DEFAULT_API
7
7
  } from "./chunk-YMSGDC4B.js";
package/dist/integrate.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  integrationAdditions,
7
7
  integrationPreview,
8
8
  planIntegration
9
- } from "./chunk-6DCCEVPD.js";
9
+ } from "./chunk-5SC2K42Q.js";
10
10
  import "./chunk-YMSGDC4B.js";
11
11
  import "./chunk-OEGNGGZ2.js";
12
12
  import "./chunk-GGARVSPT.js";
package/dist/state.js CHANGED
@@ -4,8 +4,8 @@ import {
4
4
  resolveInstallation,
5
5
  saveInstallation,
6
6
  savedInstallation
7
- } from "./chunk-FC7PZNYW.js";
8
- import "./chunk-6DCCEVPD.js";
7
+ } from "./chunk-ZGZOBW2B.js";
8
+ import "./chunk-5SC2K42Q.js";
9
9
  import "./chunk-YMSGDC4B.js";
10
10
  import "./chunk-OEGNGGZ2.js";
11
11
  import "./chunk-GGARVSPT.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@userreason/wizard",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Authenticated UserReason SDK installation wizard",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",