@sentry/wizard 3.14.0 → 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 +15 -3
- package/dist/package.json +1 -1
- package/dist/src/remix/codemods/handle-error.js +28 -0
- package/dist/src/remix/codemods/handle-error.js.map +1 -1
- package/dist/src/remix/codemods/root-common.d.ts +2 -0
- package/dist/src/remix/codemods/root-common.js +70 -0
- package/dist/src/remix/codemods/root-common.js.map +1 -0
- package/dist/src/remix/codemods/root-v1.js +5 -36
- package/dist/src/remix/codemods/root-v1.js.map +1 -1
- package/dist/src/remix/codemods/root-v2.js +53 -4
- package/dist/src/remix/codemods/root-v2.js.map +1 -1
- package/dist/src/remix/remix-wizard.js +7 -4
- package/dist/src/remix/remix-wizard.js.map +1 -1
- package/dist/src/remix/sdk-setup.d.ts +1 -0
- package/dist/src/remix/sdk-setup.js +10 -6
- package/dist/src/remix/sdk-setup.js.map +1 -1
- package/dist/src/remix/templates.d.ts +1 -1
- package/dist/src/remix/templates.js +1 -1
- package/dist/src/remix/templates.js.map +1 -1
- package/dist/src/remix/utils.d.ts +2 -0
- package/dist/src/remix/utils.js +6 -1
- package/dist/src/remix/utils.js.map +1 -1
- package/dist/src/sveltekit/sdk-setup.js +7 -3
- package/dist/src/sveltekit/sdk-setup.js.map +1 -1
- package/package.json +1 -1
- package/src/remix/codemods/handle-error.ts +30 -0
- package/src/remix/codemods/root-common.ts +63 -0
- package/src/remix/codemods/root-v1.ts +3 -53
- package/src/remix/codemods/root-v2.ts +71 -2
- package/src/remix/remix-wizard.ts +7 -4
- package/src/remix/sdk-setup.ts +14 -6
- package/src/remix/templates.ts +2 -6
- package/src/remix/utils.ts +5 -0
- package/src/sveltekit/sdk-setup.ts +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +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
|
+
|
|
11
|
+
## 3.14.1
|
|
12
|
+
|
|
13
|
+
- ref(sveltekit): Add log for successful Vite plugin insertion (#465)
|
|
14
|
+
|
|
3
15
|
## 3.14.0
|
|
4
16
|
|
|
5
|
-
feat(nextjs): Add telemetry collection to NextJS wizard (#458)
|
|
6
|
-
feat(wizard): Ask for confirmation to continue if git repo is not clean (#462)
|
|
7
|
-
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)
|
|
8
20
|
|
|
9
21
|
## 3.13.0
|
|
10
22
|
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/wizard",
|
|
3
|
-
"version": "3.
|
|
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
|
-
{"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
|
|
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,I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;QACF,gFAAgF;QAChF,sEAAsE;QACtE,IAAI,MAAA,MAAA,mBAAmB,CAAC,WAAW,CAAC,MAAM,0CAAG,CAAC,CAAC,0CAAE,UAAU,EAAE;YAC3D,gFAAgF;YAChF,yGAAyG;YACzG,mBAAmB,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,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,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE;QAC9B,6BAA6B,YAAC,IAAI;YAChC,IAAI,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,qBAAqB,EAAE;gBACzD,+DAA+D;gBAC/D,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;gBAE1C,6CAA6C;gBAC7C,IAAM,YAAY,GAAW,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC,IAAc,CAAC;gBAEtE,mCAAmC;gBACnC,IAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,cAAc,CACvD,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,YAAY,CAAC,EAC9C,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CACjD,CAAC;gBAEF,4DAA4D;gBAC5D,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,YAAY,CAAC;aACvC;iBAAM,IAAI,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,YAAY,EAAE;gBACvD,IAAM,eAAe,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC;gBAErD,IAAM,gBAAgB,GAAG,IAAA,uBAAY,EAAC,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;gBAEjE,YAAY,CAAC,OAAO,CAAC,OAAO,GAAG,mBAAQ,CAAC,GAAG,CACzC,qBAAc,gBAAgB,MAAG,CAClC,CAAC;aACH;iBAAM;gBACL,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,eAAK,CAAC,MAAM,CACV,8BAAuB,eAAK,CAAC,IAAI,CAC/B,YAAY,CACb,4DAAkD,eAAK,CAAC,GAAG,CAC1D,cAAc,CACf,OAAI,CACN,CACF,CAAC;aACH;YAED,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;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
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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,
|
|
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
|
-
|
|
120
|
-
|
|
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;;;;;;;;;;;;;;;;;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iB,CAAC,CAAC;qCAC/D;oCAED,IAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CACnC,wCAAwC,CACzC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;oCAElB,uDAAuD;oCACvD,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAClC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EACxC,CAAC,EACD,gBAAgB,CACjB,CAAC;iCACH;gCACD,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;AAvID,sDAuIC","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":";;;;;;;;;;;;;;;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EtC,iBAAK,CAAC,GAAG,CAAC,IAAI,CAAC,0JACkG,CAAC,CAAC;wCACnH,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,sKACkG,CAAC,CAAC;wCACnH,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,sKACkG,CAAC,CAAC;wCACnH,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';\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(
|
|
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(
|
|
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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safe-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;AAC7B,uCAA2B;AAE3B,+EAA+E;AAC/E,2DAAmC;AACnC,gDAA0B;AAC1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,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"]}
|