@sentry/wizard 3.14.1 → 3.15.0

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 CHANGED
@@ -1,14 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.15.0
4
+
5
+ - feat(remix): Support sourcemap uploads of Hydrogen apps (#474)
6
+ - fix(remix): Use captureRemixServerException inside handleError (#466)
7
+ - fix(remix): Fix `request` arg in `handleError` template (#469)
8
+ - fix(remix): Update documentation links to the new routes (#470)
9
+ - fix(remix): Instrument existing root `ErrorBoundary` (#472)
10
+
3
11
  ## 3.14.1
4
12
 
5
- ref(sveltekit): Add log for successful Vite plugin insertion (#465)
13
+ - ref(sveltekit): Add log for successful Vite plugin insertion (#465)
6
14
 
7
15
  ## 3.14.0
8
16
 
9
- feat(nextjs): Add telemetry collection to NextJS wizard (#458)
10
- feat(wizard): Ask for confirmation to continue if git repo is not clean (#462)
11
- fix(remix): Fix Remix version and TS checks (#464)
17
+ - feat(nextjs): Add telemetry collection to NextJS wizard (#458)
18
+ - feat(wizard): Ask for confirmation to continue if git repo is not clean (#462)
19
+ - fix(remix): Fix Remix version and TS checks (#464)
12
20
 
13
21
  ## 3.13.0
14
22
 
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/wizard",
3
- "version": "3.14.1",
3
+ "version": "3.15.0",
4
4
  "homepage": "https://github.com/getsentry/sentry-wizard",
5
5
  "repository": "https://github.com/getsentry/sentry-wizard",
6
6
  "description": "Sentry wizard helping you to configure your project",
@@ -37,6 +37,7 @@ var chalk_1 = __importDefault(require("chalk"));
37
37
  // @ts-expect-error - magicast is ESM and TS complains about that. It works though
38
38
  var magicast_1 = require("magicast");
39
39
  function instrumentHandleError(originalEntryServerMod, serverEntryFilename) {
40
+ var _a, _b;
40
41
  var originalEntryServerModAST = originalEntryServerMod.$ast;
41
42
  var handleErrorFunction = originalEntryServerModAST.body.find(function (node) {
42
43
  var _a, _b;
@@ -58,11 +59,38 @@ function instrumentHandleError(originalEntryServerMod, serverEntryFilename) {
58
59
  return false;
59
60
  }
60
61
  else {
62
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
63
+ var implementation = recast.parse(templates_1.HANDLE_ERROR_TEMPLATE_V2).program
64
+ .body[0];
61
65
  // @ts-expect-error - string works here because the AST is proxified by magicast
62
66
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
63
67
  handleErrorFunction.declaration.body.body.unshift(
64
68
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
65
69
  recast.parse(templates_1.HANDLE_ERROR_TEMPLATE_V2).program.body[0].body.body[0]);
70
+ // First parameter is the error
71
+ //
72
+ // @ts-expect-error - string works here because the AST is proxified by magicast
73
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
74
+ handleErrorFunction.declaration.params[0] = implementation.params[0];
75
+ // Second parameter is the request inside an object
76
+ // Merging the object properties to make sure it includes request
77
+ //
78
+ // @ts-expect-error - string works here because the AST is proxified by magicast
79
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
80
+ if ((_b = (_a = handleErrorFunction.declaration.params) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.properties) {
81
+ // @ts-expect-error - string works here because the AST is proxified by magicast
82
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
83
+ handleErrorFunction.declaration.params[1].properties.push(
84
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
85
+ implementation.params[1].properties[0]);
86
+ }
87
+ else {
88
+ // Create second parameter if it doesn't exist
89
+ //
90
+ // @ts-expect-error - string works here because the AST is proxified by magicast
91
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
92
+ handleErrorFunction.declaration.params[1] = implementation.params[1];
93
+ }
66
94
  }
67
95
  return true;
68
96
  }
@@ -1 +1 @@
1
- {"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ACtC,sBAAsB,CAAC,KAAK,CAC7B,EACD;QACA,OAAO,KAAK,CAAC;KACd;SAAM;QACL,gFAAgF;QAChF,yGAAyG;QACzG,mBAAmB,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO;QAC/C,sEAAsE;QACtE,MAAM,CAAC,KAAK,CAAC,oCAAwB,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CACpE,CAAC;KACH;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAhDD,sDAgDC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport type { ProxifiedModule } from 'magicast';\nimport type { Program } from '@babel/types';\n\nimport * as recast from 'recast';\n\nimport { HANDLE_ERROR_TEMPLATE_V2 } from '../templates';\nimport { getInitCallInsertionIndex, hasSentryContent } from '../utils';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { generateCode } from 'magicast';\n\nexport function instrumentHandleError(\n originalEntryServerMod: ProxifiedModule<any>,\n serverEntryFilename: string,\n): boolean {\n const originalEntryServerModAST = originalEntryServerMod.$ast as Program;\n\n const handleErrorFunction = originalEntryServerModAST.body.find(\n (node) =>\n node.type === 'ExportNamedDeclaration' &&\n node.declaration?.type === 'FunctionDeclaration' &&\n node.declaration.id?.name === 'handleError',\n );\n\n if (!handleErrorFunction) {\n clack.log.warn(\n `Could not find function ${chalk.cyan('handleError')} in ${chalk.cyan(\n serverEntryFilename,\n )}. Creating one for you.`,\n );\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const implementation = recast.parse(HANDLE_ERROR_TEMPLATE_V2).program\n .body[0];\n\n originalEntryServerModAST.body.splice(\n getInitCallInsertionIndex(originalEntryServerModAST),\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n recast.types.builders.exportNamedDeclaration(implementation),\n );\n } else if (\n hasSentryContent(\n generateCode(handleErrorFunction).code,\n originalEntryServerMod.$code,\n )\n ) {\n return false;\n } else {\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n handleErrorFunction.declaration.body.body.unshift(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n recast.parse(HANDLE_ERROR_TEMPLATE_V2).program.body[0].body.body[0],\n );\n }\n\n return true;\n}\n"]}
1
+ {"version":3,"file":"handle-error.js","sourceRoot":"","sources":["../../../../src/remix/codemods/handle-error.ts"],"names":[],"mappings":";AAAA,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAM5D,6CAAiC;AAEjC,0CAAwD;AACxD,kCAAuE;AAEvE,+EAA+E;AAC/E,2DAAmC;AACnC,gDAA0B;AAE1B,kFAAkF;AAClF,qCAAwC;AAExC,SAAgB,qBAAqB,CACnC,sBAA4C,EAC5C,mBAA2B;;IAE3B,IAAM,yBAAyB,GAAG,sBAAsB,CAAC,IAAe,CAAC;IAEzE,IAAM,mBAAmB,GAAG,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAC7D,UAAC,IAAI;;QACH,OAAA,IAAI,CAAC,IAAI,KAAK,wBAAwB;YACtC,CAAA,MAAA,IAAI,CAAC,WAAW,0CAAE,IAAI,MAAK,qBAAqB;YAChD,CAAA,MAAA,IAAI,CAAC,WAAW,CAAC,EAAE,0CAAE,IAAI,MAAK,aAAa,CAAA;KAAA,CAC9C,CAAC;IAEF,IAAI,CAAC,mBAAmB,EAAE;QACxB,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,kCAA2B,eAAK,CAAC,IAAI,CAAC,aAAa,CAAC,iBAAO,eAAK,CAAC,IAAI,CACnE,mBAAmB,CACpB,4BA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AAmB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI;YACvD,sEAAsE;YACtE,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CACvC,CAAC;SACH;aAAM;YACL,8CAA8C;YAC9C,EAAE;YACF,gFAAgF;YAChF,sEAAsE;YACtE,mBAAmB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;SACtE;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AA9ED,sDA8EC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport type { ProxifiedModule } from 'magicast';\nimport type { Program } from '@babel/types';\n\nimport * as recast from 'recast';\n\nimport { HANDLE_ERROR_TEMPLATE_V2 } from '../templates';\nimport { getInitCallInsertionIndex, hasSentryContent } from '../utils';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { generateCode } from 'magicast';\n\nexport function instrumentHandleError(\n originalEntryServerMod: ProxifiedModule<any>,\n serverEntryFilename: string,\n): boolean {\n const originalEntryServerModAST = originalEntryServerMod.$ast as Program;\n\n const handleErrorFunction = originalEntryServerModAST.body.find(\n (node) =>\n node.type === 'ExportNamedDeclaration' &&\n node.declaration?.type === 'FunctionDeclaration' &&\n node.declaration.id?.name === 'handleError',\n );\n\n if (!handleErrorFunction) {\n clack.log.warn(\n `Could not find function ${chalk.cyan('handleError')} in ${chalk.cyan(\n serverEntryFilename,\n )}. Creating one for you.`,\n );\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const implementation = recast.parse(HANDLE_ERROR_TEMPLATE_V2).program\n .body[0];\n\n originalEntryServerModAST.body.splice(\n getInitCallInsertionIndex(originalEntryServerModAST),\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n recast.types.builders.exportNamedDeclaration(implementation),\n );\n } else if (\n hasSentryContent(\n generateCode(handleErrorFunction).code,\n originalEntryServerMod.$code,\n )\n ) {\n return false;\n } else {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const implementation = recast.parse(HANDLE_ERROR_TEMPLATE_V2).program\n .body[0];\n\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n handleErrorFunction.declaration.body.body.unshift(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n recast.parse(HANDLE_ERROR_TEMPLATE_V2).program.body[0].body.body[0],\n );\n\n // First parameter is the error\n //\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n handleErrorFunction.declaration.params[0] = implementation.params[0];\n\n // Second parameter is the request inside an object\n // Merging the object properties to make sure it includes request\n //\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (handleErrorFunction.declaration.params?.[1]?.properties) {\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n handleErrorFunction.declaration.params[1].properties.push(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n implementation.params[1].properties[0],\n );\n } else {\n // Create second parameter if it doesn't exist\n //\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n handleErrorFunction.declaration.params[1] = implementation.params[1];\n }\n }\n\n return true;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { ProxifiedModule } from 'magicast';
2
+ export declare function wrapAppWithSentry(rootRouteAst: ProxifiedModule, rootFileName: string): void;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
4
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ var __importDefault = (this && this.__importDefault) || function (mod) {
29
+ return (mod && mod.__esModule) ? mod : { "default": mod };
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.wrapAppWithSentry = void 0;
33
+ var recast = __importStar(require("recast"));
34
+ // @ts-expect-error - clack is ESM and TS complains about that. It works though
35
+ var prompts_1 = __importDefault(require("@clack/prompts"));
36
+ var chalk_1 = __importDefault(require("chalk"));
37
+ // @ts-expect-error - magicast is ESM and TS complains about that. It works though
38
+ var magicast_1 = require("magicast");
39
+ function wrapAppWithSentry(rootRouteAst, rootFileName) {
40
+ rootRouteAst.imports.$add({
41
+ from: '@sentry/remix',
42
+ imported: 'withSentry',
43
+ local: 'withSentry',
44
+ });
45
+ recast.visit(rootRouteAst.$ast, {
46
+ visitExportDefaultDeclaration: function (path) {
47
+ if (path.value.declaration.type === 'FunctionDeclaration') {
48
+ // Move the function declaration just before the default export
49
+ path.insertBefore(path.value.declaration);
50
+ // Get the name of the function to be wrapped
51
+ var functionName = path.value.declaration.id.name;
52
+ // Create the wrapped function call
53
+ var functionCall = recast.types.builders.callExpression(recast.types.builders.identifier('withSentry'), [recast.types.builders.identifier(functionName)]);
54
+ // Replace the default export with the wrapped function call
55
+ path.value.declaration = functionCall;
56
+ }
57
+ else if (path.value.declaration.type === 'Identifier') {
58
+ var rootRouteExport = rootRouteAst.exports.default;
59
+ var expressionToWrap = (0, magicast_1.generateCode)(rootRouteExport.$ast).code;
60
+ rootRouteAst.exports.default = magicast_1.builders.raw("withSentry(".concat(expressionToWrap, ")"));
61
+ }
62
+ else {
63
+ prompts_1.default.log.warn(chalk_1.default.yellow("Couldn't instrument ".concat(chalk_1.default.bold(rootFileName), " automatically. Wrap your default export with: ").concat(chalk_1.default.dim('withSentry()'), "\n")));
64
+ }
65
+ this.traverse(path);
66
+ },
67
+ });
68
+ }
69
+ exports.wrapAppWithSentry = wrapAppWithSentry;
70
+ //# sourceMappingURL=root-common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root-common.js","sourceRoot":"","sources":["../../../../src/remix/codemods/root-common.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+DAA+D;AAC/D,0DAA0D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1D,6CAAiC;AACjC,+EAA+E;AAC/E,2DAAmC;AACnC,gDAA0B;AAE1B,kFAAkF;AAClF,qCAAmE;AAEnE,SAAgB,iBAAiB,CAC/B,YAA6B,EAC7B,YAAoB;IAEpB,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC;QACxB,IAAI,EAAE,eAAe;QACrB,QAAQ,EAAE,YAAY;QACtB,KAAK,EAAE,YAAY;KACpB,CAAC,CAAC;IAEH,MA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AC;QACtB,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAlDD,8CAkDC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n\nimport * as recast from 'recast';\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { builders, ProxifiedModule, generateCode } from 'magicast';\n\nexport function wrapAppWithSentry(\n rootRouteAst: ProxifiedModule,\n rootFileName: string,\n) {\n rootRouteAst.imports.$add({\n from: '@sentry/remix',\n imported: 'withSentry',\n local: 'withSentry',\n });\n\n recast.visit(rootRouteAst.$ast, {\n visitExportDefaultDeclaration(path) {\n if (path.value.declaration.type === 'FunctionDeclaration') {\n // Move the function declaration just before the default export\n path.insertBefore(path.value.declaration);\n\n // Get the name of the function to be wrapped\n const functionName: string = path.value.declaration.id.name as string;\n\n // Create the wrapped function call\n const functionCall = recast.types.builders.callExpression(\n recast.types.builders.identifier('withSentry'),\n [recast.types.builders.identifier(functionName)],\n );\n\n // Replace the default export with the wrapped function call\n path.value.declaration = functionCall;\n } else if (path.value.declaration.type === 'Identifier') {\n const rootRouteExport = rootRouteAst.exports.default;\n\n const expressionToWrap = generateCode(rootRouteExport.$ast).code;\n\n rootRouteAst.exports.default = builders.raw(\n `withSentry(${expressionToWrap})`,\n );\n } else {\n clack.log.warn(\n chalk.yellow(\n `Couldn't instrument ${chalk.bold(\n rootFileName,\n )} automatically. Wrap your default export with: ${chalk.dim(\n 'withSentry()',\n )}\\n`,\n ),\n );\n }\n\n this.traverse(path);\n },\n });\n}\n"]}
@@ -64,56 +64,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
64
64
  };
65
65
  Object.defineProperty(exports, "__esModule", { value: true });
66
66
  exports.instrumentRootRouteV1 = void 0;
67
- var recast = __importStar(require("recast"));
68
67
  var path = __importStar(require("path"));
69
68
  // @ts-expect-error - clack is ESM and TS complains about that. It works though
70
69
  var prompts_1 = __importDefault(require("@clack/prompts"));
71
70
  var chalk_1 = __importDefault(require("chalk"));
72
71
  // @ts-expect-error - magicast is ESM and TS complains about that. It works though
73
72
  var magicast_1 = require("magicast");
73
+ var root_common_1 = require("./root-common");
74
74
  function instrumentRootRouteV1(rootFileName) {
75
75
  return __awaiter(this, void 0, void 0, function () {
76
- var rootRouteAst_1, e_1;
76
+ var rootRouteAst, e_1;
77
77
  return __generator(this, function (_a) {
78
78
  switch (_a.label) {
79
79
  case 0:
80
80
  _a.trys.push([0, 3, , 4]);
81
81
  return [4 /*yield*/, (0, magicast_1.loadFile)(path.join(process.cwd(), 'app', rootFileName))];
82
82
  case 1:
83
- rootRouteAst_1 = _a.sent();
84
- rootRouteAst_1.imports.$add({
85
- from: '@sentry/remix',
86
- imported: 'withSentry',
87
- local: 'withSentry',
88
- });
89
- recast.visit(rootRouteAst_1.$ast, {
90
- visitExportDefaultDeclaration: function (path) {
91
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
92
- if (path.value.declaration.type === 'FunctionDeclaration') {
93
- // Move the function declaration just before the default export
94
- path.insertBefore(path.value.declaration);
95
- // Get the name of the function to be wrapped
96
- var functionName = path.value.declaration.id.name;
97
- // Create the wrapped function call
98
- var functionCall = recast.types.builders.callExpression(recast.types.builders.identifier('withSentry'), [recast.types.builders.identifier(functionName)]);
99
- // Replace the default export with the wrapped function call
100
- path.value.declaration = functionCall;
101
- }
102
- else if (path.value.declaration.type === 'Identifier') {
103
- var rootRouteExport = rootRouteAst_1.exports.default;
104
- var expressionToWrap = (0, magicast_1.generateCode)(
105
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
106
- rootRouteExport.$ast).code;
107
- rootRouteAst_1.exports.default = magicast_1.builders.raw("withSentry(".concat(expressionToWrap, ")"));
108
- }
109
- else {
110
- prompts_1.default.log.warn(chalk_1.default.yellow("Couldn't instrument ".concat(chalk_1.default.bold(rootFileName), " automatically. Wrap your default export with: ").concat(chalk_1.default.dim('withSentry()'), "\n")));
111
- }
112
- this.traverse(path);
113
- /* eslint-enable @typescript-eslint/no-unsafe-member-access */
114
- },
115
- });
116
- return [4 /*yield*/, (0, magicast_1.writeFile)(rootRouteAst_1.$ast, path.join(process.cwd(), 'app', rootFileName))];
83
+ rootRouteAst = _a.sent();
84
+ (0, root_common_1.wrapAppWithSentry)(rootRouteAst, rootFileName);
85
+ return [4 /*yield*/, (0, magicast_1.writeFile)(rootRouteAst.$ast, path.join(process.cwd(), 'app', rootFileName))];
117
86
  case 2:
118
87
  _a.sent();
119
88
  return [3 /*break*/, 4];
@@ -1 +1 @@
1
- {"version":3,"file":"root-v1.js","sourceRoot":"","sources":["../../../../src/remix/codemods/root-v1.ts"],"names":[],"mappings":";AAAA,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE5D,6CAAiC;AACjC,yCAA6B;AAE7B,+EAA+E;AAC/E,2DAAmC;AACnC,gDAA0B;AAE1B,kFAAkF;AAClF,qCAAuE;AAEvE,SAAsB,qBAAqB,CACzC,YAAoB;;;;;;;oBAGG,qBAAM,IAAA,mBAAQ,EACjC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAC9C,EAAA;;oBAFK,iBAAe,SAEpB;oBAED,cAAY,CAAC,OAAO,CAAC,IAAI,CAAC;wBACxB,IAAI,EAAE,eAAe;wBACrB,QAAQ,EAAE,YAAY;wBACtB,KAAK,EAAE,YAAY;qBACpB,CAAC,CAAC;oBAEH,MAAM,CAAC,KAAK,CAAC,cAAY,CAAC,IAAI,EAAE;wBAC9B,6BAA6B,YAAC,IAAI;4BAChC,+DAA+D;4BAC/D,IAAI,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,qBAAqB,EAAE;gCACzD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AO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAC9C,EAAA;;oBAHD,SAGC,CAAC;;;;oBAEF,sCAAsC;oBACtC,OAAO,CAAC,KAAK,CAAC,GAAC,CAAC,CAAC;oBACjB,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,eAAK,CAAC,MAAM,CACV,0CAAmC,eAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAE,CAC9D,CACF,CAAC;oBACF,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,qDAA8C,eAAK,CAAC,IAAI,CACtD,YAAY,CACb,eAAK,eAAK,CAAC,GAAG,CAAC,yCAAyC,CAAC,OAAI,CAC/D,CAAC;;;;;;CAEL;AA9ED,sDA8EC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\nimport * as recast from 'recast';\nimport * as path from 'path';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { builders, generateCode, loadFile, writeFile } from 'magicast';\n\nexport async function instrumentRootRouteV1(\n rootFileName: string,\n): Promise<void> {\n try {\n const rootRouteAst = await loadFile(\n path.join(process.cwd(), 'app', rootFileName),\n );\n\n rootRouteAst.imports.$add({\n from: '@sentry/remix',\n imported: 'withSentry',\n local: 'withSentry',\n });\n\n recast.visit(rootRouteAst.$ast, {\n visitExportDefaultDeclaration(path) {\n /* eslint-disable @typescript-eslint/no-unsafe-member-access */\n if (path.value.declaration.type === 'FunctionDeclaration') {\n // Move the function declaration just before the default export\n path.insertBefore(path.value.declaration);\n\n // Get the name of the function to be wrapped\n const functionName: string = path.value.declaration.id.name as string;\n\n // Create the wrapped function call\n const functionCall = recast.types.builders.callExpression(\n recast.types.builders.identifier('withSentry'),\n [recast.types.builders.identifier(functionName)],\n );\n\n // Replace the default export with the wrapped function call\n path.value.declaration = functionCall;\n } else if (path.value.declaration.type === 'Identifier') {\n const rootRouteExport = rootRouteAst.exports.default;\n\n const expressionToWrap = generateCode(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n rootRouteExport.$ast,\n ).code;\n\n rootRouteAst.exports.default = builders.raw(\n `withSentry(${expressionToWrap})`,\n );\n } else {\n clack.log.warn(\n chalk.yellow(\n `Couldn't instrument ${chalk.bold(\n rootFileName,\n )} automatically. Wrap your default export with: ${chalk.dim(\n 'withSentry()',\n )}\\n`,\n ),\n );\n }\n\n this.traverse(path);\n /* eslint-enable @typescript-eslint/no-unsafe-member-access */\n },\n });\n\n await writeFile(\n rootRouteAst.$ast,\n path.join(process.cwd(), 'app', rootFileName),\n );\n } catch (e: unknown) {\n // eslint-disable-next-line no-console\n console.error(e);\n clack.log.warn(\n chalk.yellow(\n `Something went wrong writing to ${chalk.bold(rootFileName)}`,\n ),\n );\n clack.log.info(\n `Please put the following code snippet into ${chalk.bold(\n rootFileName,\n )}: ${chalk.dim('You probably have to clean it up a bit.')}\\n`,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"root-v1.js","sourceRoot":"","sources":["../../../../src/remix/codemods/root-v1.ts"],"names":[],"mappings":";AAAA,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE5D,yCAA6B;AAE7B,+EAA+E;AAC/E,2DAAmC;AACnC,gDAA0B;AAE1B,kFAAkF;AAClF,qCAA+C;AAC/C,6CAAkD;AAElD,SAAsB,qBAAqB,CACzC,YAAoB;;;;;;;oBAGG,qBAAM,IAAA,mBAAQ,EACjC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAC9C,EAAA;;oBAFK,YAAY,GAAG,SAEpB;oBAED,IAAA,+BAAiB,EAAC,YAAY,EAAE,YAAY,CAAC,CAAC;oBAE9C,qBAAM,IAAA,oBAAS,EACb,YAAY,CAAC,IAAI,EACjB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAC9C,EAAA;;oBAHD,SAGC,CAAC;;;;oBAEF,sCAAsC;oBACtC,OAAO,CAAC,KAAK,CAAC,GAAC,CAAC,CAAC;oBACjB,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,eAAK,CAAC,MAAM,CACV,0CAAmC,eAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAE,CAC9D,CACF,CAAC;oBACF,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,qDAA8C,eAAK,CAAC,IAAI,CACtD,YAAY,CACb,eAAK,eAAK,CAAC,GAAG,CAAC,yCAAyC,CAAC,OAAI,CAC/D,CAAC;;;;;;CAEL;AA5BD,sDA4BC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\nimport * as path from 'path';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { loadFile, writeFile } from 'magicast';\nimport { wrapAppWithSentry } from './root-common';\n\nexport async function instrumentRootRouteV1(\n rootFileName: string,\n): Promise<void> {\n try {\n const rootRouteAst = await loadFile(\n path.join(process.cwd(), 'app', rootFileName),\n );\n\n wrapAppWithSentry(rootRouteAst, rootFileName);\n\n await writeFile(\n rootRouteAst.$ast,\n path.join(process.cwd(), 'app', rootFileName),\n );\n } catch (e: unknown) {\n // eslint-disable-next-line no-console\n console.error(e);\n clack.log.warn(\n chalk.yellow(\n `Something went wrong writing to ${chalk.bold(rootFileName)}`,\n ),\n );\n clack.log.info(\n `Please put the following code snippet into ${chalk.bold(\n rootFileName,\n )}: ${chalk.dim('You probably have to clean it up a bit.')}\\n`,\n );\n }\n}\n"]}
@@ -1,5 +1,8 @@
1
1
  "use strict";
2
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2
3
  /* eslint-disable @typescript-eslint/no-unsafe-assignment */
4
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
5
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
3
6
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
7
  if (k2 === undefined) k2 = k;
5
8
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -66,6 +69,8 @@ var path = __importStar(require("path"));
66
69
  // @ts-expect-error - magicast is ESM and TS complains about that. It works though
67
70
  var magicast_1 = require("magicast");
68
71
  var templates_1 = require("../templates");
72
+ var utils_1 = require("../utils");
73
+ var root_common_1 = require("./root-common");
69
74
  function instrumentRootRouteV2(rootFileName) {
70
75
  return __awaiter(this, void 0, void 0, function () {
71
76
  var rootRouteAst, exportsAst, namedExports, foundErrorBoundary;
@@ -112,12 +117,56 @@ function instrumentRootRouteV2(rootFileName) {
112
117
  });
113
118
  recast.visit(rootRouteAst.$ast, {
114
119
  visitExportDefaultDeclaration: function (path) {
115
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
116
120
  var implementation = recast.parse(templates_1.ERROR_BOUNDARY_TEMPLATE_V2).program
117
121
  .body[0];
118
- path.insertBefore(
119
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
120
- recast.types.builders.exportDeclaration(false, implementation));
122
+ path.insertBefore(recast.types.builders.exportDeclaration(false, implementation));
123
+ this.traverse(path);
124
+ },
125
+ });
126
+ // If there is already a ErrorBoundary export, and it doesn't have Sentry content
127
+ }
128
+ else if (!(0, utils_1.hasSentryContent)(rootFileName, rootRouteAst.$code)) {
129
+ rootRouteAst.imports.$add({
130
+ from: '@sentry/remix',
131
+ imported: 'captureRemixErrorBoundaryError',
132
+ local: 'captureRemixErrorBoundaryError',
133
+ });
134
+ (0, root_common_1.wrapAppWithSentry)(rootRouteAst, rootFileName);
135
+ recast.visit(rootRouteAst.$ast, {
136
+ visitExportNamedDeclaration: function (path) {
137
+ var _a, _b;
138
+ // Find ErrorBoundary export
139
+ if (((_b = (_a = path.value.declaration) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.name) === 'ErrorBoundary') {
140
+ var errorBoundaryExport = path.value.declaration;
141
+ var errorIdentifier_1;
142
+ // check if useRouteError is called
143
+ recast.visit(errorBoundaryExport, {
144
+ visitVariableDeclaration: function (path) {
145
+ var variableDeclaration = path.value.declarations[0];
146
+ var initializer = variableDeclaration.init;
147
+ if (initializer.type === 'CallExpression' &&
148
+ initializer.callee.name === 'useRouteError') {
149
+ errorIdentifier_1 = variableDeclaration.id.name;
150
+ }
151
+ this.traverse(path);
152
+ },
153
+ });
154
+ // We don't have an errorIdentifier, which means useRouteError is not called / imported
155
+ // We need to add it and capture the error
156
+ if (!errorIdentifier_1) {
157
+ rootRouteAst.imports.$add({
158
+ from: '@remix-run/react',
159
+ imported: 'useRouteError',
160
+ local: 'useRouteError',
161
+ });
162
+ var useRouteErrorCall = recast.parse("const error = useRouteError();").program.body[0];
163
+ // Insert at the top of ErrorBoundary body
164
+ errorBoundaryExport.body.body.splice(0, 0, useRouteErrorCall);
165
+ }
166
+ var captureErrorCall = recast.parse("captureRemixErrorBoundaryError(error);").program.body[0];
167
+ // Insert just before the the fallback page is returned
168
+ errorBoundaryExport.body.body.splice(errorBoundaryExport.body.body.length - 1, 0, captureErrorCall);
169
+ }
121
170
  this.traverse(path);
122
171
  },
123
172
  });
@@ -1 +1 @@
1
- {"version":3,"file":"root-v2.js","sourceRoot":"","sources":["../../../../src/remix/codemods/root-v2.ts"],"names":[],"mappings":";AAAA,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE5D,6CAAiC;AACjC,yCAA6B;AAI7B,kFAAkF;AAClF,qCAA+C;AAE/C,0CAA0D;AAE1D,SAAsB,qBAAqB,CACzC,YAAoB;;;;;wBAEC,qBAAM,IAAA,mBAAQ,EACjC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EA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Ae;4BACzB,KAAK,EAAE,eAAe;yBACvB,CAAC,CAAC;wBAEH,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE;4BAC9B,6BAA6B,YAAC,IAAI;gCAChC,sEAAsE;gCACtE,IAAM,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,sCAA0B,CAAC,CAAC,OAAO;qCACpE,IAAI,CAAC,CAAC,CAAC,CAAC;gCAEX,IAAI,CAAC,YAAY;gCACf,iEAAiE;gCACjE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,iBAAiB,CAAC,KAAK,EAAE,cAAc,CAAC,CAC/D,CAAC;gCAEF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;4BACtB,CAAC;yBACF,CAAC,CAAC;qBACJ;oBAED,qBAAM,IAAA,oBAAS,EACb,YAAY,CAAC,IAAI,EACjB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAC9C,EAAA;;oBAHD,SAGC,CAAC;;;;;CACH;AAvED,sDAuEC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\nimport * as recast from 'recast';\nimport * as path from 'path';\n\nimport type { ExportNamedDeclaration, Program } from '@babel/types';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { loadFile, writeFile } from 'magicast';\n\nimport { ERROR_BOUNDARY_TEMPLATE_V2 } from '../templates';\n\nexport async function instrumentRootRouteV2(\n rootFileName: string,\n): Promise<void> {\n const rootRouteAst = await loadFile(\n path.join(process.cwd(), 'app', rootFileName),\n );\n\n const exportsAst = rootRouteAst.exports.$ast as Program;\n\n const namedExports = exportsAst.body.filter(\n (node) => node.type === 'ExportNamedDeclaration',\n ) as ExportNamedDeclaration[];\n\n let foundErrorBoundary = false;\n\n namedExports.forEach((namedExport) => {\n const declaration = namedExport.declaration;\n\n if (!declaration) {\n return;\n }\n\n if (declaration.type === 'FunctionDeclaration') {\n if (declaration.id?.name === 'ErrorBoundary') {\n foundErrorBoundary = true;\n }\n } else if (declaration.type === 'VariableDeclaration') {\n const declarations = declaration.declarations;\n\n declarations.forEach((declaration) => {\n // @ts-expect-error - id should always have a name in this case\n if (declaration.id?.name === 'ErrorBoundary') {\n foundErrorBoundary = true;\n }\n });\n }\n });\n\n if (!foundErrorBoundary) {\n rootRouteAst.imports.$add({\n from: '@sentry/remix',\n imported: 'captureRemixErrorBoundaryError',\n local: 'captureRemixErrorBoundaryError',\n });\n\n rootRouteAst.imports.$add({\n from: '@remix-run/react',\n imported: 'useRouteError',\n local: 'useRouteError',\n });\n\n recast.visit(rootRouteAst.$ast, {\n visitExportDefaultDeclaration(path) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const implementation = recast.parse(ERROR_BOUNDARY_TEMPLATE_V2).program\n .body[0];\n\n path.insertBefore(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n recast.types.builders.exportDeclaration(false, implementation),\n );\n\n this.traverse(path);\n },\n });\n }\n\n await writeFile(\n rootRouteAst.$ast,\n path.join(process.cwd(), 'app', rootFileName),\n );\n}\n"]}
1
+ {"version":3,"file":"root-v2.js","sourceRoot":"","sources":["../../../../src/remix/codemods/root-v2.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,4DAA4D;AAC5D,sDAAsD;AACtD,0DAA0D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1D,6CAAiC;AACjC,yCAA6B;AAI7B,kFAAkF;AAClF,qCAA+C;AAE/C,0CAA0D;AAC1D,kCAA4C;AAC5C,6CAAkD;AAElD,SAAsB,qBAAqB,CACzC,YAAoB;;;;;wBAEC,qBAAM,IAAA,mBAAQ,EACjC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAC9C,EAAA;;oBAFK,YAAY,GAAG,SAEpB;oBAEK,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uIC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n\nimport * as recast from 'recast';\nimport * as path from 'path';\n\nimport type { ExportNamedDeclaration, Program } from '@babel/types';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { loadFile, writeFile } from 'magicast';\n\nimport { ERROR_BOUNDARY_TEMPLATE_V2 } from '../templates';\nimport { hasSentryContent } from '../utils';\nimport { wrapAppWithSentry } from './root-common';\n\nexport async function instrumentRootRouteV2(\n rootFileName: string,\n): Promise<void> {\n const rootRouteAst = await loadFile(\n path.join(process.cwd(), 'app', rootFileName),\n );\n\n const exportsAst = rootRouteAst.exports.$ast as Program;\n\n const namedExports = exportsAst.body.filter(\n (node) => node.type === 'ExportNamedDeclaration',\n ) as ExportNamedDeclaration[];\n\n let foundErrorBoundary = false;\n\n namedExports.forEach((namedExport) => {\n const declaration = namedExport.declaration;\n\n if (!declaration) {\n return;\n }\n\n if (declaration.type === 'FunctionDeclaration') {\n if (declaration.id?.name === 'ErrorBoundary') {\n foundErrorBoundary = true;\n }\n } else if (declaration.type === 'VariableDeclaration') {\n const declarations = declaration.declarations;\n\n declarations.forEach((declaration) => {\n // @ts-expect-error - id should always have a name in this case\n if (declaration.id?.name === 'ErrorBoundary') {\n foundErrorBoundary = true;\n }\n });\n }\n });\n\n if (!foundErrorBoundary) {\n rootRouteAst.imports.$add({\n from: '@sentry/remix',\n imported: 'captureRemixErrorBoundaryError',\n local: 'captureRemixErrorBoundaryError',\n });\n\n rootRouteAst.imports.$add({\n from: '@remix-run/react',\n imported: 'useRouteError',\n local: 'useRouteError',\n });\n\n recast.visit(rootRouteAst.$ast, {\n visitExportDefaultDeclaration(path) {\n const implementation = recast.parse(ERROR_BOUNDARY_TEMPLATE_V2).program\n .body[0];\n\n path.insertBefore(\n recast.types.builders.exportDeclaration(false, implementation),\n );\n\n this.traverse(path);\n },\n });\n // If there is already a ErrorBoundary export, and it doesn't have Sentry content\n } else if (!hasSentryContent(rootFileName, rootRouteAst.$code)) {\n rootRouteAst.imports.$add({\n from: '@sentry/remix',\n imported: 'captureRemixErrorBoundaryError',\n local: 'captureRemixErrorBoundaryError',\n });\n\n wrapAppWithSentry(rootRouteAst, rootFileName);\n\n recast.visit(rootRouteAst.$ast, {\n visitExportNamedDeclaration(path) {\n // Find ErrorBoundary export\n if (path.value.declaration?.id?.name === 'ErrorBoundary') {\n const errorBoundaryExport = path.value.declaration;\n\n let errorIdentifier;\n\n // check if useRouteError is called\n recast.visit(errorBoundaryExport, {\n visitVariableDeclaration(path) {\n const variableDeclaration = path.value.declarations[0];\n const initializer = variableDeclaration.init;\n\n if (\n initializer.type === 'CallExpression' &&\n initializer.callee.name === 'useRouteError'\n ) {\n errorIdentifier = variableDeclaration.id.name;\n }\n\n this.traverse(path);\n },\n });\n\n // We don't have an errorIdentifier, which means useRouteError is not called / imported\n // We need to add it and capture the error\n if (!errorIdentifier) {\n rootRouteAst.imports.$add({\n from: '@remix-run/react',\n imported: 'useRouteError',\n local: 'useRouteError',\n });\n\n const useRouteErrorCall = recast.parse(\n `const error = useRouteError();`,\n ).program.body[0];\n\n // Insert at the top of ErrorBoundary body\n errorBoundaryExport.body.body.splice(0, 0, useRouteErrorCall);\n }\n\n const captureErrorCall = recast.parse(\n `captureRemixErrorBoundaryError(error);`,\n ).program.body[0];\n\n // Insert just before the the fallback page is returned\n errorBoundaryExport.body.body.splice(\n errorBoundaryExport.body.body.length - 1,\n 0,\n captureErrorCall,\n );\n }\n this.traverse(path);\n },\n });\n }\n\n await writeFile(\n rootRouteAst.$ast,\n path.join(process.cwd(), 'app', rootFileName),\n );\n}\n"]}
@@ -48,6 +48,8 @@ var package_json_1 = require("../utils/package-json");
48
48
  var sdk_setup_1 = require("./sdk-setup");
49
49
  var debug_1 = require("../utils/debug");
50
50
  var telemetry_1 = require("../telemetry");
51
+ var utils_1 = require("./utils");
52
+ var Constants_1 = require("../../lib/Constants");
51
53
  function runRemixWizard(options) {
52
54
  return __awaiter(this, void 0, void 0, function () {
53
55
  return __generator(this, function (_a) {
@@ -109,7 +111,8 @@ function runRemixWizardWithTelemetry(options) {
109
111
  return [4 /*yield*/, (0, sdk_setup_1.updateBuildScript)({
110
112
  org: selectedProject.organization.slug,
111
113
  project: selectedProject.name,
112
- url: sentryUrl,
114
+ url: sentryUrl === Constants_1.DEFAULT_URL ? undefined : sentryUrl,
115
+ isHydrogen: (0, utils_1.isHydrogenApp)(packageJson),
113
116
  })];
114
117
  case 1:
115
118
  _a.sent();
@@ -138,7 +141,7 @@ function runRemixWizardWithTelemetry(options) {
138
141
  return [3 /*break*/, 3];
139
142
  case 2:
140
143
  e_2 = _a.sent();
141
- prompts_1.default.log.warn("Could not instrument root route.\n Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/");
144
+ prompts_1.default.log.warn("Could not instrument root route.\n Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/manual-setup/");
142
145
  (0, debug_1.debug)(e_2);
143
146
  return [3 /*break*/, 3];
144
147
  case 3: return [2 /*return*/];
@@ -159,7 +162,7 @@ function runRemixWizardWithTelemetry(options) {
159
162
  return [3 /*break*/, 3];
160
163
  case 2:
161
164
  e_3 = _a.sent();
162
- prompts_1.default.log.warn("Could not initialize Sentry on client entry.\n Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/");
165
+ prompts_1.default.log.warn("Could not initialize Sentry on client entry.\n Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/manual-setup/");
163
166
  (0, debug_1.debug)(e_3);
164
167
  return [3 /*break*/, 3];
165
168
  case 3: return [2 /*return*/];
@@ -180,7 +183,7 @@ function runRemixWizardWithTelemetry(options) {
180
183
  return [3 /*break*/, 3];
181
184
  case 2:
182
185
  e_4 = _a.sent();
183
- prompts_1.default.log.warn("Could not initialize Sentry on server entry.\n Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/");
186
+ prompts_1.default.log.warn("Could not initialize Sentry on server entry.\n Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/manual-setup/");
184
187
  (0, debug_1.debug)(e_4);
185
188
  return [3 /*break*/, 3];
186
189
  case 3: return [2 /*return*/];
@@ -1 +1 @@
1
- {"version":3,"file":"remix-wizard.js","sourceRoot":"","sources":["../../../src/remix/remix-wizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+EAA+E;AAC/E,2DAAmC;AACnC,gDAA0B;AAE1B,oDAU8B;AAC9B,sDAA4D;AAE5D,yCAOqB;AACrB,wCAAuC;AACvC,0CAAwD;AAExD,SAAsB,cAAc,CAAC,OAAsB;;;YACzD,sBAAO,IAAA,yBAAa,EAClB;oBACE,OAAO,EAAE,OAAO,CAAC,gBAAgB;oBACjC,WAAW,EAAE,OAAO;iBACrB,EACD,cAAM,OAAA,2BAA2B,CAAC,OAAO,CAAC,EAApC,CAAoC,CAC3C,EAAC;;;CACH;AARD,wCAQC;AAED,SAAe,2BAA2B,CACxC,OAAsB;;;;;;;oBAEtB,IAAA,0BAAY,EAAC;wBACX,UAAU,EAAE,qBAAqB;wBACjC,SAAS,EAAE,OAAO,CAAC,SAAS;wBAC5B,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;qBAC3C,CAAC,CAAC;oBAEH,qBAAM,IAAA,+CAAiC,GAAE,EAAA;;oBAAzC,SAAyC,CAAC;oBAEtB,qBAAM,IAAA,2BAAe,GAAE,EAAA;;oBAArC,WAAW,GAAG,SAAuB;oBACvB,qBAAM,IAAA,+BAAiB,GAAE,EAAA;;oBAAvC,WAAW,GAAG,SAAyB;oBAE7C,qEAAqE;oBACrE,qBAAM,IAAA,sCAAwB,EAAC,WAAW,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAA;;oBADtE,qEAAqE;oBACrE,SAA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,IAAA,aAAK,EAAC,GAAC,CAAC,CAAC;;;;;6BAEZ,CAAC,EAAA;;oBARF,SAQE,CAAC;oBAEH,qBAAM,IAAA,qBAAS,EAAC,mCAAmC,EAAE;;;;;;wCAEjD,qBAAM,IAAA,yCAA6B,EAAC,GAAG,EAAE,IAAI,CAAC,EAAA;;wCAA9C,SAA8C,CAAC;;;;wCAE/C,iBAAK,CAAC,GAAG,CAAC,IAAI,CAAC,yJACqF,CAAC,CAAC;wCACtG,IAAA,aAAK,EAAC,GAAC,CAAC,CAAC;;;;;6BAEZ,CAAC,EAAA;;oBARF,SAQE,CAAC;oBAEH,qBAAM,IAAA,qBAAS,EAAC,mCAAmC,EAAE;;;;;;wCAEjD,qBAAM,IAAA,yCAA6B,EAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,EAAA;;wCAApD,SAAoD,CAAC;;;;wCAErD,iBAAK,CAAC,GAAG,CAAC,IAAI,CAAC,yJACqF,CAAC,CAAC;wCACtG,IAAA,aAAK,EAAC,GAAC,CAAC,CAAC;;;;;6BAEZ,CAAC,EAAA;;oBARF,SAQE,CAAC;oBAEH,iBAAK,CAAC,KAAK,CAAC,YACZ,eAAK,CAAC,KAAK,CACX,iEAAiE,CAClE,iBAEC,eAAK,CAAC,IAAI,CAAC,0DAA0D,CAAC,iBAEtE,eAAK,CAAC,IAAI,CACV,uIACwD,CACzD,CAAE,CAAC,CAAC;;;;;CACJ","sourcesContent":["// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\nimport {\n addSentryCliConfig,\n confirmContinueIfNoOrDirtyGitRepo,\n ensurePackageIsInstalled,\n getOrAskForProjectData,\n getPackageDotJson,\n installPackage,\n isUsingTypeScript,\n printWelcome,\n sourceMapsCliSetupConfig,\n} from '../utils/clack-utils';\nimport { hasPackageInstalled } from '../utils/package-json';\nimport { WizardOptions } from '../utils/types';\nimport {\n initializeSentryOnEntryClient,\n initializeSentryOnEntryServer,\n updateBuildScript,\n instrumentRootRoute,\n isRemixV2,\n loadRemixConfig,\n} from './sdk-setup';\nimport { debug } from '../utils/debug';\nimport { traceStep, withTelemetry } from '../telemetry';\n\nexport async function runRemixWizard(options: WizardOptions): Promise<void> {\n return withTelemetry(\n {\n enabled: options.telemetryEnabled,\n integration: 'remix',\n },\n () => runRemixWizardWithTelemetry(options),\n );\n}\n\nasync function runRemixWizardWithTelemetry(\n options: WizardOptions,\n): Promise<void> {\n printWelcome({\n wizardName: 'Sentry Remix Wizard',\n promoCode: options.promoCode,\n telemetryEnabled: options.telemetryEnabled,\n });\n\n await confirmContinueIfNoOrDirtyGitRepo();\n\n const remixConfig = await loadRemixConfig();\n const packageJson = await getPackageDotJson();\n\n // We expect `@remix-run/dev` to be installed for every Remix project\n await ensurePackageIsInstalled(packageJson, '@remix-run/dev', 'Remix');\n\n const { selectedProject, authToken, sentryUrl } =\n await getOrAskForProjectData(options, 'javascript-remix');\n\n await installPackage({\n packageName: '@sentry/remix',\n alreadyInstalled: hasPackageInstalled('@sentry/remix', packageJson),\n });\n\n const dsn = selectedProject.keys[0].dsn.public;\n\n const isTS = isUsingTypeScript();\n const isV2 = isRemixV2(remixConfig, packageJson);\n\n await addSentryCliConfig(authToken, sourceMapsCliSetupConfig);\n\n await traceStep('Update build script for sourcemap uploads', async () => {\n try {\n await updateBuildScript({\n org: selectedProject.organization.slug,\n project: selectedProject.name,\n url: sentryUrl,\n });\n } catch (e) {\n clack.log\n .warn(`Could not update build script to generate and upload sourcemaps.\n Please update your build script manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/sourcemaps/`);\n debug(e);\n }\n });\n\n await traceStep('Instrument root route', async () => {\n try {\n await instrumentRootRoute(isV2, isTS);\n } catch (e) {\n clack.log.warn(`Could not instrument root route.\n Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/`);\n debug(e);\n }\n });\n\n await traceStep('Initialize Sentry on client entry', async () => {\n try {\n await initializeSentryOnEntryClient(dsn, isTS);\n } catch (e) {\n clack.log.warn(`Could not initialize Sentry on client entry.\n Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/`);\n debug(e);\n }\n });\n\n await traceStep('Initialize Sentry on server entry', async () => {\n try {\n await initializeSentryOnEntryServer(dsn, isV2, isTS);\n } catch (e) {\n clack.log.warn(`Could not initialize Sentry on server entry.\n Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/`);\n debug(e);\n }\n });\n\n clack.outro(`\n${chalk.green(\n 'Sentry has been successfully configured for your Remix project.',\n)}\n\n${chalk.cyan('You can now deploy your project to see Sentry in action.')}\n\n${chalk.cyan(\n `To learn more about how to use Sentry with Remix, visit our documentation:\nhttps://docs.sentry.io/platforms/javascript/guides/remix/`,\n)}`);\n}\n"]}
1
+ {"version":3,"file":"remix-wizard.js","sourceRoot":"","sources":["../../../src/remix/remix-wizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+EAA+E;AAC/E,2DAAmC;AACnC,gDAA0B;AAE1B,oDAU8B;AAC9B,sDAA4D;AAE5D,yCAOqB;AACrB,wCAAuC;AACvC,0CAAwD;AACxD,iCAAwC;AACxC,iDAAkD;AAElD,SAAsB,cAAc,CAAC,OAAsB;;;YACzD,sBAAO,IAAA,yBAAa,EAClB;oBACE,OAAO,EAAE,OAAO,CAAC,gBAAgB;oBACjC,WAAW,EAAE,OAAO;iBACrB,EACD,cAAM,OAAA,2BAA2B,CAAC,OAAO,CAAC,EAApC,CAAoC,CAC3C,EAAC;;;CACH;AARD,wCAQC;AAED,SAAe,2BAA2B,CACxC,OAAsB;;;;;;;oBAEtB,IAAA,0BAAY,EAAC;wBACX,UAAU,EAAE,qBAAqB;wBACjC,SAAS,EAAE,OAAO,CAAC,SAAS;wBAC5B,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;qBAC3C,CAAC,CAAC;oBAEH,qBAAM,IAAA,+CAAiC,GAAE,EAAA;;oB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CACV,uIACwD,CACzD,CAAE,CAAC,CAAC;;;;;CACJ","sourcesContent":["// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\nimport {\n addSentryCliConfig,\n confirmContinueIfNoOrDirtyGitRepo,\n ensurePackageIsInstalled,\n getOrAskForProjectData,\n getPackageDotJson,\n installPackage,\n isUsingTypeScript,\n printWelcome,\n sourceMapsCliSetupConfig,\n} from '../utils/clack-utils';\nimport { hasPackageInstalled } from '../utils/package-json';\nimport { WizardOptions } from '../utils/types';\nimport {\n initializeSentryOnEntryClient,\n initializeSentryOnEntryServer,\n updateBuildScript,\n instrumentRootRoute,\n isRemixV2,\n loadRemixConfig,\n} from './sdk-setup';\nimport { debug } from '../utils/debug';\nimport { traceStep, withTelemetry } from '../telemetry';\nimport { isHydrogenApp } from './utils';\nimport { DEFAULT_URL } from '../../lib/Constants';\n\nexport async function runRemixWizard(options: WizardOptions): Promise<void> {\n return withTelemetry(\n {\n enabled: options.telemetryEnabled,\n integration: 'remix',\n },\n () => runRemixWizardWithTelemetry(options),\n );\n}\n\nasync function runRemixWizardWithTelemetry(\n options: WizardOptions,\n): Promise<void> {\n printWelcome({\n wizardName: 'Sentry Remix Wizard',\n promoCode: options.promoCode,\n telemetryEnabled: options.telemetryEnabled,\n });\n\n await confirmContinueIfNoOrDirtyGitRepo();\n\n const remixConfig = await loadRemixConfig();\n const packageJson = await getPackageDotJson();\n\n // We expect `@remix-run/dev` to be installed for every Remix project\n await ensurePackageIsInstalled(packageJson, '@remix-run/dev', 'Remix');\n\n const { selectedProject, authToken, sentryUrl } =\n await getOrAskForProjectData(options, 'javascript-remix');\n\n await installPackage({\n packageName: '@sentry/remix',\n alreadyInstalled: hasPackageInstalled('@sentry/remix', packageJson),\n });\n\n const dsn = selectedProject.keys[0].dsn.public;\n\n const isTS = isUsingTypeScript();\n const isV2 = isRemixV2(remixConfig, packageJson);\n\n await addSentryCliConfig(authToken, sourceMapsCliSetupConfig);\n\n await traceStep('Update build script for sourcemap uploads', async () => {\n try {\n await updateBuildScript({\n org: selectedProject.organization.slug,\n project: selectedProject.name,\n url: sentryUrl === DEFAULT_URL ? undefined : sentryUrl,\n isHydrogen: isHydrogenApp(packageJson),\n });\n } catch (e) {\n clack.log\n .warn(`Could not update build script to generate and upload sourcemaps.\n Please update your build script manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/sourcemaps/`);\n debug(e);\n }\n });\n\n await traceStep('Instrument root route', async () => {\n try {\n await instrumentRootRoute(isV2, isTS);\n } catch (e) {\n clack.log.warn(`Could not instrument root route.\n Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/manual-setup/`);\n debug(e);\n }\n });\n\n await traceStep('Initialize Sentry on client entry', async () => {\n try {\n await initializeSentryOnEntryClient(dsn, isTS);\n } catch (e) {\n clack.log.warn(`Could not initialize Sentry on client entry.\n Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/manual-setup/`);\n debug(e);\n }\n });\n\n await traceStep('Initialize Sentry on server entry', async () => {\n try {\n await initializeSentryOnEntryServer(dsn, isV2, isTS);\n } catch (e) {\n clack.log.warn(`Could not initialize Sentry on server entry.\n Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/manual-setup/`);\n debug(e);\n }\n });\n\n clack.outro(`\n${chalk.green(\n 'Sentry has been successfully configured for your Remix project.',\n)}\n\n${chalk.cyan('You can now deploy your project to see Sentry in action.')}\n\n${chalk.cyan(\n `To learn more about how to use Sentry with Remix, visit our documentation:\nhttps://docs.sentry.io/platforms/javascript/guides/remix/`,\n)}`);\n}\n"]}
@@ -17,6 +17,7 @@ export declare function updateBuildScript(args: {
17
17
  org: string;
18
18
  project: string;
19
19
  url?: string;
20
+ isHydrogen: boolean;
20
21
  }): Promise<void>;
21
22
  export declare function initializeSentryOnEntryClient(dsn: string, isTS: boolean): Promise<void>;
22
23
  export declare function initializeSentryOnEntryServer(dsn: string, isV2: boolean, isTS: boolean): Promise<void>;
@@ -184,7 +184,7 @@ function instrumentRootRoute(isV2, isTS) {
184
184
  exports.instrumentRootRoute = instrumentRootRoute;
185
185
  function updateBuildScript(args) {
186
186
  return __awaiter(this, void 0, void 0, function () {
187
- var packageJsonPath, packageJsonString, packageJson;
187
+ var packageJsonPath, packageJsonString, packageJson, buildCommand, instrumentedBuildCommand;
188
188
  return __generator(this, function (_a) {
189
189
  switch (_a.label) {
190
190
  case 0:
@@ -196,15 +196,19 @@ function updateBuildScript(args) {
196
196
  if (!packageJson.scripts) {
197
197
  packageJson.scripts = {};
198
198
  }
199
+ buildCommand = args.isHydrogen
200
+ ? 'shopify hydrogen build'
201
+ : 'remix build';
202
+ instrumentedBuildCommand = "".concat(buildCommand, " --sourcemap && sentry-upload-sourcemaps --org ").concat(args.org, " --project ").concat(args.project) +
203
+ (args.url ? " --url ".concat(args.url) : '') +
204
+ (args.isHydrogen ? ' --buildPath ./dist' : '');
199
205
  if (!packageJson.scripts.build) {
200
- packageJson.scripts.build =
201
- "remix build --sourcemap && sentry-upload-sourcemaps --org ".concat(args.org, " --project ").concat(args.project) +
202
- (args.url ? " --url ".concat(args.url) : '');
206
+ packageJson.scripts.build = instrumentedBuildCommand;
203
207
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
204
208
  }
205
- else if (packageJson.scripts.build.includes('remix build')) {
209
+ else if (packageJson.scripts.build.includes(buildCommand)) {
206
210
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
207
- packageJson.scripts.build = packageJson.scripts.build.replace('remix build', 'remix build --sourcemap && sentry-upload-sourcemaps');
211
+ packageJson.scripts.build = packageJson.scripts.build.replace(buildCommand, instrumentedBuildCommand);
208
212
  }
209
213
  return [4 /*yield*/, fs.promises.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2))];
210
214
  case 2:
@@ -1 +1 @@
1
- {"version":3,"file":"sdk-setup.js","sourceRoot":"","sources":["../../../src/remix/sdk-setup.ts"],"names":[],"mappings":";AAAA,4DAA4D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G,CACL,CAAC;;;;;CACH;AApDD,sEAoDC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\nimport type { Program } from '@babel/types';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport type { ProxifiedModule } from 'magicast';\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as url from 'url';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport { gte, minVersion } from 'semver';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { builders, generateCode, loadFile, writeFile } from 'magicast';\nimport { PackageDotJson, getPackageVersion } from '../utils/package-json';\nimport { getInitCallInsertionIndex, hasSentryContent } from './utils';\nimport { instrumentRootRouteV1 } from './codemods/root-v1';\nimport { instrumentRootRouteV2 } from './codemods/root-v2';\nimport { instrumentHandleError } from './codemods/handle-error';\n\nexport type PartialRemixConfig = {\n unstable_dev?: boolean;\n future?: {\n v2_dev?: boolean;\n v2_errorBoundary?: boolean;\n v2_headers?: boolean;\n v2_meta?: boolean;\n v2_normalizeFormMethod?: boolean;\n v2_routeConvention?: boolean;\n };\n};\n\nconst REMIX_CONFIG_FILE = 'remix.config.js';\n\nfunction insertClientInitCall(\n dsn: string,\n originalHooksMod: ProxifiedModule<any>,\n): void {\n const initCall = builders.functionCall('Sentry.init', {\n dsn,\n tracesSampleRate: 1.0,\n replaysSessionSampleRate: 0.1,\n replaysOnErrorSampleRate: 1.0,\n integrations: [\n builders.newExpression('Sentry.BrowserTracing', {\n routingInstrumentation: builders.functionCall(\n 'Sentry.remixRouterInstrumentation',\n builders.raw('useEffect'),\n builders.raw('useLocation'),\n builders.raw('useMatches'),\n ),\n }),\n builders.newExpression('Sentry.Replay'),\n ],\n });\n\n const originalHooksModAST = originalHooksMod.$ast as Program;\n const initCallInsertionIndex = getInitCallInsertionIndex(originalHooksModAST);\n\n originalHooksModAST.body.splice(\n initCallInsertionIndex,\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n generateCode(initCall).code,\n );\n}\n\nfunction insertServerInitCall(\n dsn: string,\n originalHooksMod: ProxifiedModule<any>,\n) {\n const initCall = builders.functionCall('Sentry.init', {\n dsn,\n tracesSampleRate: 1.0,\n });\n\n const originalHooksModAST = originalHooksMod.$ast as Program;\n\n const initCallInsertionIndex = getInitCallInsertionIndex(originalHooksModAST);\n\n originalHooksModAST.body.splice(\n initCallInsertionIndex,\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n generateCode(initCall).code,\n );\n}\n\nexport function isRemixV2(\n remixConfig: PartialRemixConfig,\n packageJson: PackageDotJson,\n): boolean {\n const remixVersion = getPackageVersion('@remix-run/react', packageJson);\n if (!remixVersion) {\n return false;\n }\n\n const minVer = minVersion(remixVersion);\n\n if (!minVer) {\n return false;\n }\n\n const isV2Remix = gte(minVer, '2.0.0');\n\n return isV2Remix || remixConfig?.future?.v2_errorBoundary || false;\n}\n\nexport async function loadRemixConfig(): Promise<PartialRemixConfig> {\n const configFilePath = path.join(process.cwd(), REMIX_CONFIG_FILE);\n\n try {\n if (!fs.existsSync(configFilePath)) {\n return {};\n }\n\n const configUrl = url.pathToFileURL(configFilePath).href;\n const remixConfigModule = (await import(configUrl)) as {\n default: PartialRemixConfig;\n };\n\n return remixConfigModule?.default || {};\n } catch (e: unknown) {\n clack.log.error(`Couldn't load ${REMIX_CONFIG_FILE}.`);\n clack.log.info(\n chalk.dim(\n typeof e === 'object' && e != null && 'toString' in e\n ? e.toString()\n : typeof e === 'string'\n ? e\n : 'Unknown error',\n ),\n );\n\n return {};\n }\n}\n\nexport async function instrumentRootRoute(\n isV2?: boolean,\n isTS?: boolean,\n): Promise<void> {\n const rootFilename = `root.${isTS ? 'tsx' : 'jsx'}`;\n\n if (isV2) {\n await instrumentRootRouteV2(rootFilename);\n } else {\n await instrumentRootRouteV1(rootFilename);\n }\n\n clack.log.success(\n `Successfully instrumented root route ${chalk.cyan(rootFilename)}.`,\n );\n /* eslint-enable @typescript-eslint/no-unsafe-member-access */\n}\n\nexport async function updateBuildScript(args: {\n org: string;\n project: string;\n url?: string;\n}): Promise<void> {\n /* eslint-disable @typescript-eslint/no-unsafe-member-access */\n // Add sourcemaps option to build script\n const packageJsonPath = path.join(process.cwd(), 'package.json');\n const packageJsonString = (\n await fs.promises.readFile(packageJsonPath)\n ).toString();\n const packageJson = JSON.parse(packageJsonString);\n\n if (!packageJson.scripts) {\n packageJson.scripts = {};\n }\n\n if (!packageJson.scripts.build) {\n packageJson.scripts.build =\n `remix build --sourcemap && sentry-upload-sourcemaps --org ${args.org} --project ${args.project}` +\n (args.url ? ` --url ${args.url}` : '');\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n } else if (packageJson.scripts.build.includes('remix build')) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n packageJson.scripts.build = packageJson.scripts.build.replace(\n 'remix build',\n 'remix build --sourcemap && sentry-upload-sourcemaps',\n );\n }\n\n await fs.promises.writeFile(\n packageJsonPath,\n JSON.stringify(packageJson, null, 2),\n );\n\n clack.log.success(\n `Successfully updated ${chalk.cyan('build')} script in ${chalk.cyan(\n 'package.json',\n )} to generate and upload sourcemaps.`,\n );\n /* eslint-enable @typescript-eslint/no-unsafe-member-access */\n}\n\nexport async function initializeSentryOnEntryClient(\n dsn: string,\n isTS: boolean,\n): Promise<void> {\n const clientEntryFilename = `entry.client.${isTS ? 'tsx' : 'jsx'}`;\n\n const originalEntryClient = path.join(\n process.cwd(),\n 'app',\n clientEntryFilename,\n );\n\n const originalEntryClientMod = await loadFile(originalEntryClient);\n\n if (hasSentryContent(originalEntryClient, originalEntryClientMod.$code)) {\n return;\n }\n\n originalEntryClientMod.imports.$add({\n from: '@sentry/remix',\n imported: '*',\n local: 'Sentry',\n });\n\n originalEntryClientMod.imports.$add({\n from: 'react',\n imported: 'useEffect',\n local: 'useEffect',\n });\n\n originalEntryClientMod.imports.$add({\n from: '@remix-run/react',\n imported: 'useLocation',\n local: 'useLocation',\n });\n\n originalEntryClientMod.imports.$add({\n from: '@remix-run/react',\n imported: 'useMatches',\n local: 'useMatches',\n });\n\n insertClientInitCall(dsn, originalEntryClientMod);\n\n await writeFile(\n originalEntryClientMod.$ast,\n path.join(process.cwd(), 'app', clientEntryFilename),\n );\n\n clack.log.success(\n `Successfully initialized Sentry on client entry point ${chalk.cyan(\n clientEntryFilename,\n )}`,\n );\n}\n\nexport async function initializeSentryOnEntryServer(\n dsn: string,\n isV2: boolean,\n isTS: boolean,\n): Promise<void> {\n const serverEntryFilename = `entry.server.${isTS ? 'tsx' : 'jsx'}`;\n\n const originalEntryServer = path.join(\n process.cwd(),\n 'app',\n serverEntryFilename,\n );\n\n const originalEntryServerMod = await loadFile(originalEntryServer);\n\n if (hasSentryContent(originalEntryServer, originalEntryServerMod.$code)) {\n return;\n }\n\n originalEntryServerMod.imports.$add({\n from: '@sentry/remix',\n imported: '*',\n local: 'Sentry',\n });\n\n insertServerInitCall(dsn, originalEntryServerMod);\n\n if (isV2) {\n const handleErrorInstrumented = instrumentHandleError(\n originalEntryServerMod,\n serverEntryFilename,\n );\n\n if (handleErrorInstrumented) {\n clack.log.success(\n `Instrumented ${chalk.cyan('handleError')} in ${chalk.cyan(\n `${serverEntryFilename}`,\n )}`,\n );\n }\n }\n\n await writeFile(\n originalEntryServerMod.$ast,\n path.join(process.cwd(), 'app', serverEntryFilename),\n );\n\n clack.log.success(\n `Successfully initialized Sentry on server entry point ${chalk.cyan(\n serverEntryFilename,\n )}.`,\n );\n}\n"]}
1
+ {"version":3,"file":"sdk-setup.js","sourceRoot":"","sources":["../../../src/remix/sdk-setup.ts"],"names":[],"mappings":";AAAA,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAO5D,qCAAyB;AACzB,yCAA6B;AA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CACrD,EAAA;;oBAHD,SAGC,CAAC;oBAEF,iBAAK,CAAC,GAAG,CAAC,OAAO,CACf,gEAAyD,eAAK,CAAC,IAAI,CACjE,mBAAmB,CACpB,MAAG,CACL,CAAC;;;;;CACH;AApDD,sEAoDC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\nimport type { Program } from '@babel/types';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport type { ProxifiedModule } from 'magicast';\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as url from 'url';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport { gte, minVersion } from 'semver';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { builders, generateCode, loadFile, writeFile } from 'magicast';\nimport { PackageDotJson, getPackageVersion } from '../utils/package-json';\nimport { getInitCallInsertionIndex, hasSentryContent } from './utils';\nimport { instrumentRootRouteV1 } from './codemods/root-v1';\nimport { instrumentRootRouteV2 } from './codemods/root-v2';\nimport { instrumentHandleError } from './codemods/handle-error';\n\nexport type PartialRemixConfig = {\n unstable_dev?: boolean;\n future?: {\n v2_dev?: boolean;\n v2_errorBoundary?: boolean;\n v2_headers?: boolean;\n v2_meta?: boolean;\n v2_normalizeFormMethod?: boolean;\n v2_routeConvention?: boolean;\n };\n};\n\nconst REMIX_CONFIG_FILE = 'remix.config.js';\n\nfunction insertClientInitCall(\n dsn: string,\n originalHooksMod: ProxifiedModule<any>,\n): void {\n const initCall = builders.functionCall('Sentry.init', {\n dsn,\n tracesSampleRate: 1.0,\n replaysSessionSampleRate: 0.1,\n replaysOnErrorSampleRate: 1.0,\n integrations: [\n builders.newExpression('Sentry.BrowserTracing', {\n routingInstrumentation: builders.functionCall(\n 'Sentry.remixRouterInstrumentation',\n builders.raw('useEffect'),\n builders.raw('useLocation'),\n builders.raw('useMatches'),\n ),\n }),\n builders.newExpression('Sentry.Replay'),\n ],\n });\n\n const originalHooksModAST = originalHooksMod.$ast as Program;\n const initCallInsertionIndex = getInitCallInsertionIndex(originalHooksModAST);\n\n originalHooksModAST.body.splice(\n initCallInsertionIndex,\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n generateCode(initCall).code,\n );\n}\n\nfunction insertServerInitCall(\n dsn: string,\n originalHooksMod: ProxifiedModule<any>,\n) {\n const initCall = builders.functionCall('Sentry.init', {\n dsn,\n tracesSampleRate: 1.0,\n });\n\n const originalHooksModAST = originalHooksMod.$ast as Program;\n\n const initCallInsertionIndex = getInitCallInsertionIndex(originalHooksModAST);\n\n originalHooksModAST.body.splice(\n initCallInsertionIndex,\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n generateCode(initCall).code,\n );\n}\n\nexport function isRemixV2(\n remixConfig: PartialRemixConfig,\n packageJson: PackageDotJson,\n): boolean {\n const remixVersion = getPackageVersion('@remix-run/react', packageJson);\n if (!remixVersion) {\n return false;\n }\n\n const minVer = minVersion(remixVersion);\n\n if (!minVer) {\n return false;\n }\n\n const isV2Remix = gte(minVer, '2.0.0');\n\n return isV2Remix || remixConfig?.future?.v2_errorBoundary || false;\n}\n\nexport async function loadRemixConfig(): Promise<PartialRemixConfig> {\n const configFilePath = path.join(process.cwd(), REMIX_CONFIG_FILE);\n\n try {\n if (!fs.existsSync(configFilePath)) {\n return {};\n }\n\n const configUrl = url.pathToFileURL(configFilePath).href;\n const remixConfigModule = (await import(configUrl)) as {\n default: PartialRemixConfig;\n };\n\n return remixConfigModule?.default || {};\n } catch (e: unknown) {\n clack.log.error(`Couldn't load ${REMIX_CONFIG_FILE}.`);\n clack.log.info(\n chalk.dim(\n typeof e === 'object' && e != null && 'toString' in e\n ? e.toString()\n : typeof e === 'string'\n ? e\n : 'Unknown error',\n ),\n );\n\n return {};\n }\n}\n\nexport async function instrumentRootRoute(\n isV2?: boolean,\n isTS?: boolean,\n): Promise<void> {\n const rootFilename = `root.${isTS ? 'tsx' : 'jsx'}`;\n\n if (isV2) {\n await instrumentRootRouteV2(rootFilename);\n } else {\n await instrumentRootRouteV1(rootFilename);\n }\n\n clack.log.success(\n `Successfully instrumented root route ${chalk.cyan(rootFilename)}.`,\n );\n /* eslint-enable @typescript-eslint/no-unsafe-member-access */\n}\n\nexport async function updateBuildScript(args: {\n org: string;\n project: string;\n url?: string;\n isHydrogen: boolean;\n}): Promise<void> {\n /* eslint-disable @typescript-eslint/no-unsafe-member-access */\n // Add sourcemaps option to build script\n const packageJsonPath = path.join(process.cwd(), 'package.json');\n const packageJsonString = (\n await fs.promises.readFile(packageJsonPath)\n ).toString();\n const packageJson = JSON.parse(packageJsonString);\n\n if (!packageJson.scripts) {\n packageJson.scripts = {};\n }\n\n const buildCommand = args.isHydrogen\n ? 'shopify hydrogen build'\n : 'remix build';\n\n const instrumentedBuildCommand =\n `${buildCommand} --sourcemap && sentry-upload-sourcemaps --org ${args.org} --project ${args.project}` +\n (args.url ? ` --url ${args.url}` : '') +\n (args.isHydrogen ? ' --buildPath ./dist' : '');\n\n if (!packageJson.scripts.build) {\n packageJson.scripts.build = instrumentedBuildCommand;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n } else if (packageJson.scripts.build.includes(buildCommand)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n packageJson.scripts.build = packageJson.scripts.build.replace(\n buildCommand,\n instrumentedBuildCommand,\n );\n }\n\n await fs.promises.writeFile(\n packageJsonPath,\n JSON.stringify(packageJson, null, 2),\n );\n\n clack.log.success(\n `Successfully updated ${chalk.cyan('build')} script in ${chalk.cyan(\n 'package.json',\n )} to generate and upload sourcemaps.`,\n );\n /* eslint-enable @typescript-eslint/no-unsafe-member-access */\n}\n\nexport async function initializeSentryOnEntryClient(\n dsn: string,\n isTS: boolean,\n): Promise<void> {\n const clientEntryFilename = `entry.client.${isTS ? 'tsx' : 'jsx'}`;\n\n const originalEntryClient = path.join(\n process.cwd(),\n 'app',\n clientEntryFilename,\n );\n\n const originalEntryClientMod = await loadFile(originalEntryClient);\n\n if (hasSentryContent(originalEntryClient, originalEntryClientMod.$code)) {\n return;\n }\n\n originalEntryClientMod.imports.$add({\n from: '@sentry/remix',\n imported: '*',\n local: 'Sentry',\n });\n\n originalEntryClientMod.imports.$add({\n from: 'react',\n imported: 'useEffect',\n local: 'useEffect',\n });\n\n originalEntryClientMod.imports.$add({\n from: '@remix-run/react',\n imported: 'useLocation',\n local: 'useLocation',\n });\n\n originalEntryClientMod.imports.$add({\n from: '@remix-run/react',\n imported: 'useMatches',\n local: 'useMatches',\n });\n\n insertClientInitCall(dsn, originalEntryClientMod);\n\n await writeFile(\n originalEntryClientMod.$ast,\n path.join(process.cwd(), 'app', clientEntryFilename),\n );\n\n clack.log.success(\n `Successfully initialized Sentry on client entry point ${chalk.cyan(\n clientEntryFilename,\n )}`,\n );\n}\n\nexport async function initializeSentryOnEntryServer(\n dsn: string,\n isV2: boolean,\n isTS: boolean,\n): Promise<void> {\n const serverEntryFilename = `entry.server.${isTS ? 'tsx' : 'jsx'}`;\n\n const originalEntryServer = path.join(\n process.cwd(),\n 'app',\n serverEntryFilename,\n );\n\n const originalEntryServerMod = await loadFile(originalEntryServer);\n\n if (hasSentryContent(originalEntryServer, originalEntryServerMod.$code)) {\n return;\n }\n\n originalEntryServerMod.imports.$add({\n from: '@sentry/remix',\n imported: '*',\n local: 'Sentry',\n });\n\n insertServerInitCall(dsn, originalEntryServerMod);\n\n if (isV2) {\n const handleErrorInstrumented = instrumentHandleError(\n originalEntryServerMod,\n serverEntryFilename,\n );\n\n if (handleErrorInstrumented) {\n clack.log.success(\n `Instrumented ${chalk.cyan('handleError')} in ${chalk.cyan(\n `${serverEntryFilename}`,\n )}`,\n );\n }\n }\n\n await writeFile(\n originalEntryServerMod.$ast,\n path.join(process.cwd(), 'app', serverEntryFilename),\n );\n\n clack.log.success(\n `Successfully initialized Sentry on server entry point ${chalk.cyan(\n serverEntryFilename,\n )}.`,\n );\n}\n"]}
@@ -1,2 +1,2 @@
1
1
  export declare const ERROR_BOUNDARY_TEMPLATE_V2 = "const ErrorBoundary = () => {\n const error = useRouteError();\n captureRemixErrorBoundaryError(error);\n return <div>Something went wrong</div>;\n};\n";
2
- export declare const HANDLE_ERROR_TEMPLATE_V2 = "function handleError(error) {\n if (error instanceof Error) {\n Sentry.captureRemixErrorBoundaryError(error);\n } else {\n Sentry.captureException(error);\n }\n}\n";
2
+ export declare const HANDLE_ERROR_TEMPLATE_V2 = "function handleError(error, { request }) {\n Sentry.captureRemixServerException(error, 'remix.server', request);\n}\n";
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HANDLE_ERROR_TEMPLATE_V2 = exports.ERROR_BOUNDARY_TEMPLATE_V2 = void 0;
4
4
  exports.ERROR_BOUNDARY_TEMPLATE_V2 = "const ErrorBoundary = () => {\n const error = useRouteError();\n captureRemixErrorBoundaryError(error);\n return <div>Something went wrong</div>;\n};\n";
5
- exports.HANDLE_ERROR_TEMPLATE_V2 = "function handleError(error) {\n if (error instanceof Error) {\n Sentry.captureRemixErrorBoundaryError(error);\n } else {\n Sentry.captureException(error);\n }\n}\n";
5
+ exports.HANDLE_ERROR_TEMPLATE_V2 = "function handleError(error, { request }) {\n Sentry.captureRemixServerException(error, 'remix.server', request);\n}\n";
6
6
  //# sourceMappingURL=templates.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/remix/templates.ts"],"names":[],"mappings":";;;AAAa,QAAA,0BAA0B,GAAG,4JAKzC,CAAC;AAEW,QAAA,wBAAwB,GAAG,8KAOvC,CAAC","sourcesContent":["export const ERROR_BOUNDARY_TEMPLATE_V2 = `const ErrorBoundary = () => {\n const error = useRouteError();\n captureRemixErrorBoundaryError(error);\n return <div>Something went wrong</div>;\n};\n`;\n\nexport const HANDLE_ERROR_TEMPLATE_V2 = `function handleError(error) {\n if (error instanceof Error) {\n Sentry.captureRemixErrorBoundaryError(error);\n } else {\n Sentry.captureException(error);\n }\n}\n`;\n"]}
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/remix/templates.ts"],"names":[],"mappings":";;;AAAa,QAAA,0BAA0B,GAAG,4JAKzC,CAAC;AAEW,QAAA,wBAAwB,GAAG,wHAGvC,CAAC","sourcesContent":["export const ERROR_BOUNDARY_TEMPLATE_V2 = `const ErrorBoundary = () => {\n const error = useRouteError();\n captureRemixErrorBoundaryError(error);\n return <div>Something went wrong</div>;\n};\n`;\n\nexport const HANDLE_ERROR_TEMPLATE_V2 = `function handleError(error, { request }) {\n Sentry.captureRemixServerException(error, 'remix.server', request);\n}\n`;\n"]}
@@ -1,6 +1,8 @@
1
1
  import type { Program } from '@babel/types';
2
+ import { PackageDotJson } from '../utils/package-json';
2
3
  export declare function hasSentryContent(fileName: string, fileContent: string): boolean;
3
4
  /**
4
5
  * We want to insert the init call on top of the file but after all import statements
5
6
  */
6
7
  export declare function getInitCallInsertionIndex(originalHooksModAST: Program): number;
8
+ export declare function isHydrogenApp(packageJson: PackageDotJson): boolean;
@@ -26,11 +26,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getInitCallInsertionIndex = exports.hasSentryContent = void 0;
29
+ exports.isHydrogenApp = exports.getInitCallInsertionIndex = exports.hasSentryContent = void 0;
30
30
  var path = __importStar(require("path"));
31
31
  // @ts-expect-error - clack is ESM and TS complains about that. It works though
32
32
  var prompts_1 = __importDefault(require("@clack/prompts"));
33
33
  var chalk_1 = __importDefault(require("chalk"));
34
+ var package_json_1 = require("../utils/package-json");
34
35
  // Copied from sveltekit wizard
35
36
  function hasSentryContent(fileName, fileContent) {
36
37
  var includesContent = fileContent.includes('@sentry/remix');
@@ -52,4 +53,8 @@ function getInitCallInsertionIndex(originalHooksModAST) {
52
53
  return 0;
53
54
  }
54
55
  exports.getInitCallInsertionIndex = getInitCallInsertionIndex;
56
+ function isHydrogenApp(packageJson) {
57
+ return (0, package_json_1.hasPackageInstalled)('@shopify/hydrogen', packageJson);
58
+ }
59
+ exports.isHydrogenApp = isHydrogenApp;
55
60
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/remix/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yCAA6B;AAE7B,+EAA+E;AAC/E,2DAAmC;AACnC,gDAA0B;AAE1B,+BAA+B;AAC/B,SAAgB,gBAAgB,CAC9B,QAAgB,EAChB,WAAmB;IAEnB,IAAM,eAAe,GAAG,WAAW,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;IAE9D,IAAI,eAAe,EAAE;QACnB,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,eAAQ,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,qFACP,eAAK,CAAC,IAAI,CAC5C,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CACxB,MAAG,CACL,CAAC;KACH;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAhBD,4CAgBC;AAED;;GAEG;AACH,SAAgB,yBAAyB,CACvC,mBAA4B;IAE5B,KAAK,IAAI,CAAC,GAAG,mBAAmB,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;QAC7D,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,mBAAmB,EAAE;YAC5D,OAAO,CAAC,GAAG,CAAC,CAAC;SACd;KACF;IAED,OAAO,CAAC,CAAC;AACX,CAAC;AAVD,8DAUC","sourcesContent":["import type { Program } from '@babel/types';\n\nimport * as path from 'path';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\n// Copied from sveltekit wizard\nexport function hasSentryContent(\n fileName: string,\n fileContent: string,\n): boolean {\n const includesContent = fileContent.includes('@sentry/remix');\n\n if (includesContent) {\n clack.log.warn(\n `File ${chalk.cyan(path.basename(fileName))} already contains Sentry code.\nSkipping adding Sentry functionality to ${chalk.cyan(\n path.basename(fileName),\n )}.`,\n );\n }\n\n return includesContent;\n}\n\n/**\n * We want to insert the init call on top of the file but after all import statements\n */\nexport function getInitCallInsertionIndex(\n originalHooksModAST: Program,\n): number {\n for (let x = originalHooksModAST.body.length - 1; x >= 0; x--) {\n if (originalHooksModAST.body[x].type === 'ImportDeclaration') {\n return x + 1;\n }\n }\n\n return 0;\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/remix/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yCAA6B;AAE7B,+EAA+E;AAC/E,2DAAmC;AACnC,gDAA0B;AAC1B,sDAA4E;AAE5E,+BAA+B;AAC/B,SAAgB,gBAAgB,CAC9B,QAAgB,EAChB,WAAmB;IAEnB,IAAM,eAAe,GAAG,WAAW,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;IAE9D,IAAI,eAAe,EAAE;QACnB,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,eAAQ,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,qFACP,eAAK,CAAC,IAAI,CAC5C,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CACxB,MAAG,CACL,CAAC;KACH;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAhBD,4CAgBC;AAED;;GAEG;AACH,SAAgB,yBAAyB,CACvC,mBAA4B;IAE5B,KAAK,IAAI,CAAC,GAAG,mBAAmB,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;QAC7D,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,mBAAmB,EAAE;YAC5D,OAAO,CAAC,GAAG,CAAC,CAAC;SACd;KACF;IAED,OAAO,CAAC,CAAC;AACX,CAAC;AAVD,8DAUC;AAED,SAAgB,aAAa,CAAC,WAA2B;IACvD,OAAO,IAAA,kCAAmB,EAAC,mBAAmB,EAAE,WAAW,CAAC,CAAC;AAC/D,CAAC;AAFD,sCAEC","sourcesContent":["import type { Program } from '@babel/types';\n\nimport * as path from 'path';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport { PackageDotJson, hasPackageInstalled } from '../utils/package-json';\n\n// Copied from sveltekit wizard\nexport function hasSentryContent(\n fileName: string,\n fileContent: string,\n): boolean {\n const includesContent = fileContent.includes('@sentry/remix');\n\n if (includesContent) {\n clack.log.warn(\n `File ${chalk.cyan(path.basename(fileName))} already contains Sentry code.\nSkipping adding Sentry functionality to ${chalk.cyan(\n path.basename(fileName),\n )}.`,\n );\n }\n\n return includesContent;\n}\n\n/**\n * We want to insert the init call on top of the file but after all import statements\n */\nexport function getInitCallInsertionIndex(\n originalHooksModAST: Program,\n): number {\n for (let x = originalHooksModAST.body.length - 1; x >= 0; x--) {\n if (originalHooksModAST.body[x].type === 'ImportDeclaration') {\n return x + 1;\n }\n }\n\n return 0;\n}\n\nexport function isHydrogenApp(packageJson: PackageDotJson): boolean {\n return hasPackageInstalled('@shopify/hydrogen', packageJson);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/wizard",
3
- "version": "3.14.1",
3
+ "version": "3.15.0",
4
4
  "homepage": "https://github.com/getsentry/sentry-wizard",
5
5
  "repository": "https://github.com/getsentry/sentry-wizard",
6
6
  "description": "Sentry wizard helping you to configure your project",
@@ -55,12 +55,42 @@ export function instrumentHandleError(
55
55
  ) {
56
56
  return false;
57
57
  } else {
58
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
59
+ const implementation = recast.parse(HANDLE_ERROR_TEMPLATE_V2).program
60
+ .body[0];
61
+
58
62
  // @ts-expect-error - string works here because the AST is proxified by magicast
59
63
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
60
64
  handleErrorFunction.declaration.body.body.unshift(
61
65
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
62
66
  recast.parse(HANDLE_ERROR_TEMPLATE_V2).program.body[0].body.body[0],
63
67
  );
68
+
69
+ // First parameter is the error
70
+ //
71
+ // @ts-expect-error - string works here because the AST is proxified by magicast
72
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
73
+ handleErrorFunction.declaration.params[0] = implementation.params[0];
74
+
75
+ // Second parameter is the request inside an object
76
+ // Merging the object properties to make sure it includes request
77
+ //
78
+ // @ts-expect-error - string works here because the AST is proxified by magicast
79
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
80
+ if (handleErrorFunction.declaration.params?.[1]?.properties) {
81
+ // @ts-expect-error - string works here because the AST is proxified by magicast
82
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
83
+ handleErrorFunction.declaration.params[1].properties.push(
84
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
85
+ implementation.params[1].properties[0],
86
+ );
87
+ } else {
88
+ // Create second parameter if it doesn't exist
89
+ //
90
+ // @ts-expect-error - string works here because the AST is proxified by magicast
91
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
92
+ handleErrorFunction.declaration.params[1] = implementation.params[1];
93
+ }
64
94
  }
65
95
 
66
96
  return true;
@@ -0,0 +1,63 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
3
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
4
+
5
+ import * as recast from 'recast';
6
+ // @ts-expect-error - clack is ESM and TS complains about that. It works though
7
+ import clack from '@clack/prompts';
8
+ import chalk from 'chalk';
9
+
10
+ // @ts-expect-error - magicast is ESM and TS complains about that. It works though
11
+ import { builders, ProxifiedModule, generateCode } from 'magicast';
12
+
13
+ export function wrapAppWithSentry(
14
+ rootRouteAst: ProxifiedModule,
15
+ rootFileName: string,
16
+ ) {
17
+ rootRouteAst.imports.$add({
18
+ from: '@sentry/remix',
19
+ imported: 'withSentry',
20
+ local: 'withSentry',
21
+ });
22
+
23
+ recast.visit(rootRouteAst.$ast, {
24
+ visitExportDefaultDeclaration(path) {
25
+ if (path.value.declaration.type === 'FunctionDeclaration') {
26
+ // Move the function declaration just before the default export
27
+ path.insertBefore(path.value.declaration);
28
+
29
+ // Get the name of the function to be wrapped
30
+ const functionName: string = path.value.declaration.id.name as string;
31
+
32
+ // Create the wrapped function call
33
+ const functionCall = recast.types.builders.callExpression(
34
+ recast.types.builders.identifier('withSentry'),
35
+ [recast.types.builders.identifier(functionName)],
36
+ );
37
+
38
+ // Replace the default export with the wrapped function call
39
+ path.value.declaration = functionCall;
40
+ } else if (path.value.declaration.type === 'Identifier') {
41
+ const rootRouteExport = rootRouteAst.exports.default;
42
+
43
+ const expressionToWrap = generateCode(rootRouteExport.$ast).code;
44
+
45
+ rootRouteAst.exports.default = builders.raw(
46
+ `withSentry(${expressionToWrap})`,
47
+ );
48
+ } else {
49
+ clack.log.warn(
50
+ chalk.yellow(
51
+ `Couldn't instrument ${chalk.bold(
52
+ rootFileName,
53
+ )} automatically. Wrap your default export with: ${chalk.dim(
54
+ 'withSentry()',
55
+ )}\n`,
56
+ ),
57
+ );
58
+ }
59
+
60
+ this.traverse(path);
61
+ },
62
+ });
63
+ }
@@ -1,6 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-unsafe-assignment */
2
2
 
3
- import * as recast from 'recast';
4
3
  import * as path from 'path';
5
4
 
6
5
  // @ts-expect-error - clack is ESM and TS complains about that. It works though
@@ -8,7 +7,8 @@ import clack from '@clack/prompts';
8
7
  import chalk from 'chalk';
9
8
 
10
9
  // @ts-expect-error - magicast is ESM and TS complains about that. It works though
11
- import { builders, generateCode, loadFile, writeFile } from 'magicast';
10
+ import { loadFile, writeFile } from 'magicast';
11
+ import { wrapAppWithSentry } from './root-common';
12
12
 
13
13
  export async function instrumentRootRouteV1(
14
14
  rootFileName: string,
@@ -18,57 +18,7 @@ export async function instrumentRootRouteV1(
18
18
  path.join(process.cwd(), 'app', rootFileName),
19
19
  );
20
20
 
21
- rootRouteAst.imports.$add({
22
- from: '@sentry/remix',
23
- imported: 'withSentry',
24
- local: 'withSentry',
25
- });
26
-
27
- recast.visit(rootRouteAst.$ast, {
28
- visitExportDefaultDeclaration(path) {
29
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
30
- if (path.value.declaration.type === 'FunctionDeclaration') {
31
- // Move the function declaration just before the default export
32
- path.insertBefore(path.value.declaration);
33
-
34
- // Get the name of the function to be wrapped
35
- const functionName: string = path.value.declaration.id.name as string;
36
-
37
- // Create the wrapped function call
38
- const functionCall = recast.types.builders.callExpression(
39
- recast.types.builders.identifier('withSentry'),
40
- [recast.types.builders.identifier(functionName)],
41
- );
42
-
43
- // Replace the default export with the wrapped function call
44
- path.value.declaration = functionCall;
45
- } else if (path.value.declaration.type === 'Identifier') {
46
- const rootRouteExport = rootRouteAst.exports.default;
47
-
48
- const expressionToWrap = generateCode(
49
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
50
- rootRouteExport.$ast,
51
- ).code;
52
-
53
- rootRouteAst.exports.default = builders.raw(
54
- `withSentry(${expressionToWrap})`,
55
- );
56
- } else {
57
- clack.log.warn(
58
- chalk.yellow(
59
- `Couldn't instrument ${chalk.bold(
60
- rootFileName,
61
- )} automatically. Wrap your default export with: ${chalk.dim(
62
- 'withSentry()',
63
- )}\n`,
64
- ),
65
- );
66
- }
67
-
68
- this.traverse(path);
69
- /* eslint-enable @typescript-eslint/no-unsafe-member-access */
70
- },
71
- });
21
+ wrapAppWithSentry(rootRouteAst, rootFileName);
72
22
 
73
23
  await writeFile(
74
24
  rootRouteAst.$ast,
@@ -1,4 +1,7 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
1
2
  /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
4
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
2
5
 
3
6
  import * as recast from 'recast';
4
7
  import * as path from 'path';
@@ -9,6 +12,8 @@ import type { ExportNamedDeclaration, Program } from '@babel/types';
9
12
  import { loadFile, writeFile } from 'magicast';
10
13
 
11
14
  import { ERROR_BOUNDARY_TEMPLATE_V2 } from '../templates';
15
+ import { hasSentryContent } from '../utils';
16
+ import { wrapAppWithSentry } from './root-common';
12
17
 
13
18
  export async function instrumentRootRouteV2(
14
19
  rootFileName: string,
@@ -63,18 +68,82 @@ export async function instrumentRootRouteV2(
63
68
 
64
69
  recast.visit(rootRouteAst.$ast, {
65
70
  visitExportDefaultDeclaration(path) {
66
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
67
71
  const implementation = recast.parse(ERROR_BOUNDARY_TEMPLATE_V2).program
68
72
  .body[0];
69
73
 
70
74
  path.insertBefore(
71
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
72
75
  recast.types.builders.exportDeclaration(false, implementation),
73
76
  );
74
77
 
75
78
  this.traverse(path);
76
79
  },
77
80
  });
81
+ // If there is already a ErrorBoundary export, and it doesn't have Sentry content
82
+ } else if (!hasSentryContent(rootFileName, rootRouteAst.$code)) {
83
+ rootRouteAst.imports.$add({
84
+ from: '@sentry/remix',
85
+ imported: 'captureRemixErrorBoundaryError',
86
+ local: 'captureRemixErrorBoundaryError',
87
+ });
88
+
89
+ wrapAppWithSentry(rootRouteAst, rootFileName);
90
+
91
+ recast.visit(rootRouteAst.$ast, {
92
+ visitExportNamedDeclaration(path) {
93
+ // Find ErrorBoundary export
94
+ if (path.value.declaration?.id?.name === 'ErrorBoundary') {
95
+ const errorBoundaryExport = path.value.declaration;
96
+
97
+ let errorIdentifier;
98
+
99
+ // check if useRouteError is called
100
+ recast.visit(errorBoundaryExport, {
101
+ visitVariableDeclaration(path) {
102
+ const variableDeclaration = path.value.declarations[0];
103
+ const initializer = variableDeclaration.init;
104
+
105
+ if (
106
+ initializer.type === 'CallExpression' &&
107
+ initializer.callee.name === 'useRouteError'
108
+ ) {
109
+ errorIdentifier = variableDeclaration.id.name;
110
+ }
111
+
112
+ this.traverse(path);
113
+ },
114
+ });
115
+
116
+ // We don't have an errorIdentifier, which means useRouteError is not called / imported
117
+ // We need to add it and capture the error
118
+ if (!errorIdentifier) {
119
+ rootRouteAst.imports.$add({
120
+ from: '@remix-run/react',
121
+ imported: 'useRouteError',
122
+ local: 'useRouteError',
123
+ });
124
+
125
+ const useRouteErrorCall = recast.parse(
126
+ `const error = useRouteError();`,
127
+ ).program.body[0];
128
+
129
+ // Insert at the top of ErrorBoundary body
130
+ errorBoundaryExport.body.body.splice(0, 0, useRouteErrorCall);
131
+ }
132
+
133
+ const captureErrorCall = recast.parse(
134
+ `captureRemixErrorBoundaryError(error);`,
135
+ ).program.body[0];
136
+
137
+ // Insert just before the the fallback page is returned
138
+ errorBoundaryExport.body.body.splice(
139
+ errorBoundaryExport.body.body.length - 1,
140
+ 0,
141
+ captureErrorCall,
142
+ );
143
+ }
144
+ this.traverse(path);
145
+ },
146
+ });
78
147
  }
79
148
 
80
149
  await writeFile(
@@ -25,6 +25,8 @@ import {
25
25
  } from './sdk-setup';
26
26
  import { debug } from '../utils/debug';
27
27
  import { traceStep, withTelemetry } from '../telemetry';
28
+ import { isHydrogenApp } from './utils';
29
+ import { DEFAULT_URL } from '../../lib/Constants';
28
30
 
29
31
  export async function runRemixWizard(options: WizardOptions): Promise<void> {
30
32
  return withTelemetry(
@@ -73,7 +75,8 @@ async function runRemixWizardWithTelemetry(
73
75
  await updateBuildScript({
74
76
  org: selectedProject.organization.slug,
75
77
  project: selectedProject.name,
76
- url: sentryUrl,
78
+ url: sentryUrl === DEFAULT_URL ? undefined : sentryUrl,
79
+ isHydrogen: isHydrogenApp(packageJson),
77
80
  });
78
81
  } catch (e) {
79
82
  clack.log
@@ -88,7 +91,7 @@ async function runRemixWizardWithTelemetry(
88
91
  await instrumentRootRoute(isV2, isTS);
89
92
  } catch (e) {
90
93
  clack.log.warn(`Could not instrument root route.
91
- Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/`);
94
+ Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/manual-setup/`);
92
95
  debug(e);
93
96
  }
94
97
  });
@@ -98,7 +101,7 @@ async function runRemixWizardWithTelemetry(
98
101
  await initializeSentryOnEntryClient(dsn, isTS);
99
102
  } catch (e) {
100
103
  clack.log.warn(`Could not initialize Sentry on client entry.
101
- Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/`);
104
+ Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/manual-setup/`);
102
105
  debug(e);
103
106
  }
104
107
  });
@@ -108,7 +111,7 @@ async function runRemixWizardWithTelemetry(
108
111
  await initializeSentryOnEntryServer(dsn, isV2, isTS);
109
112
  } catch (e) {
110
113
  clack.log.warn(`Could not initialize Sentry on server entry.
111
- Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/`);
114
+ Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/manual-setup/`);
112
115
  debug(e);
113
116
  }
114
117
  });
@@ -164,6 +164,7 @@ export async function updateBuildScript(args: {
164
164
  org: string;
165
165
  project: string;
166
166
  url?: string;
167
+ isHydrogen: boolean;
167
168
  }): Promise<void> {
168
169
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
169
170
  // Add sourcemaps option to build script
@@ -177,17 +178,24 @@ export async function updateBuildScript(args: {
177
178
  packageJson.scripts = {};
178
179
  }
179
180
 
181
+ const buildCommand = args.isHydrogen
182
+ ? 'shopify hydrogen build'
183
+ : 'remix build';
184
+
185
+ const instrumentedBuildCommand =
186
+ `${buildCommand} --sourcemap && sentry-upload-sourcemaps --org ${args.org} --project ${args.project}` +
187
+ (args.url ? ` --url ${args.url}` : '') +
188
+ (args.isHydrogen ? ' --buildPath ./dist' : '');
189
+
180
190
  if (!packageJson.scripts.build) {
181
- packageJson.scripts.build =
182
- `remix build --sourcemap && sentry-upload-sourcemaps --org ${args.org} --project ${args.project}` +
183
- (args.url ? ` --url ${args.url}` : '');
191
+ packageJson.scripts.build = instrumentedBuildCommand;
184
192
 
185
193
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
186
- } else if (packageJson.scripts.build.includes('remix build')) {
194
+ } else if (packageJson.scripts.build.includes(buildCommand)) {
187
195
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
188
196
  packageJson.scripts.build = packageJson.scripts.build.replace(
189
- 'remix build',
190
- 'remix build --sourcemap && sentry-upload-sourcemaps',
197
+ buildCommand,
198
+ instrumentedBuildCommand,
191
199
  );
192
200
  }
193
201
 
@@ -5,11 +5,7 @@ export const ERROR_BOUNDARY_TEMPLATE_V2 = `const ErrorBoundary = () => {
5
5
  };
6
6
  `;
7
7
 
8
- export const HANDLE_ERROR_TEMPLATE_V2 = `function handleError(error) {
9
- if (error instanceof Error) {
10
- Sentry.captureRemixErrorBoundaryError(error);
11
- } else {
12
- Sentry.captureException(error);
13
- }
8
+ export const HANDLE_ERROR_TEMPLATE_V2 = `function handleError(error, { request }) {
9
+ Sentry.captureRemixServerException(error, 'remix.server', request);
14
10
  }
15
11
  `;
@@ -5,6 +5,7 @@ import * as path from 'path';
5
5
  // @ts-expect-error - clack is ESM and TS complains about that. It works though
6
6
  import clack from '@clack/prompts';
7
7
  import chalk from 'chalk';
8
+ import { PackageDotJson, hasPackageInstalled } from '../utils/package-json';
8
9
 
9
10
  // Copied from sveltekit wizard
10
11
  export function hasSentryContent(
@@ -39,3 +40,7 @@ export function getInitCallInsertionIndex(
39
40
 
40
41
  return 0;
41
42
  }
43
+
44
+ export function isHydrogenApp(packageJson: PackageDotJson): boolean {
45
+ return hasPackageInstalled('@shopify/hydrogen', packageJson);
46
+ }