@sentry/wizard 5.3.0 → 6.0.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 +11 -0
- package/dist/e2e-tests/tests/angular-17.test.js +7 -1
- package/dist/e2e-tests/tests/angular-17.test.js.map +1 -1
- package/dist/e2e-tests/tests/angular-19.test.js +7 -1
- package/dist/e2e-tests/tests/angular-19.test.js.map +1 -1
- package/dist/src/remix/codemods/handle-error.js +3 -6
- package/dist/src/remix/codemods/handle-error.js.map +1 -1
- package/dist/src/remix/codemods/{root-common.d.ts → root.d.ts} +1 -0
- package/dist/src/remix/codemods/{root-v2.js → root.js} +47 -12
- package/dist/src/remix/codemods/root.js.map +1 -0
- package/dist/src/remix/remix-wizard.js +7 -5
- package/dist/src/remix/remix-wizard.js.map +1 -1
- package/dist/src/remix/sdk-setup.d.ts +3 -11
- package/dist/src/remix/sdk-setup.js +9 -18
- package/dist/src/remix/sdk-setup.js.map +1 -1
- package/dist/src/remix/templates.d.ts +2 -2
- package/dist/src/remix/templates.js +3 -3
- package/dist/src/remix/templates.js.map +1 -1
- package/dist/src/sourcemaps/sourcemaps-wizard.js +1 -1
- package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
- package/dist/src/sourcemaps/tools/sentry-cli.js +15 -17
- package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
- package/dist/src/utils/clack/index.d.ts +7 -0
- package/dist/src/utils/clack/index.js +127 -4
- package/dist/src/utils/clack/index.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/dist/test/remix/root.test.d.ts +1 -0
- package/dist/test/remix/root.test.js +31 -0
- package/dist/test/remix/root.test.js.map +1 -0
- package/package.json +1 -1
- package/dist/src/remix/codemods/root-common.js +0 -70
- package/dist/src/remix/codemods/root-common.js.map +0 -1
- package/dist/src/remix/codemods/root-v1.d.ts +0 -1
- package/dist/src/remix/codemods/root-v1.js +0 -52
- package/dist/src/remix/codemods/root-v1.js.map +0 -1
- package/dist/src/remix/codemods/root-v2.d.ts +0 -1
- package/dist/src/remix/codemods/root-v2.js.map +0 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// @ts-expect-error - magicast is ESM and TS complains about that. It works though
|
|
4
|
+
const magicast_1 = require("magicast");
|
|
5
|
+
const vitest_1 = require("vitest");
|
|
6
|
+
const root_1 = require("../../src/remix/codemods/root");
|
|
7
|
+
(0, vitest_1.describe)('wrapAppWithSentry', () => {
|
|
8
|
+
(0, vitest_1.it)('should wrap the app with Sentry', () => {
|
|
9
|
+
// Empty root.tsx file for testing
|
|
10
|
+
const originalRootAst = (0, magicast_1.parseModule)(`
|
|
11
|
+
import { Outlet } from '@remix-run/react';
|
|
12
|
+
|
|
13
|
+
export default function App() {
|
|
14
|
+
return <Outlet />;
|
|
15
|
+
}
|
|
16
|
+
`);
|
|
17
|
+
(0, root_1.wrapAppWithSentry)(originalRootAst, 'root.tsx');
|
|
18
|
+
const result = originalRootAst.generate().code;
|
|
19
|
+
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
|
|
20
|
+
"import {withSentry} from '@sentry/remix';
|
|
21
|
+
import { Outlet } from '@remix-run/react';
|
|
22
|
+
|
|
23
|
+
function App() {
|
|
24
|
+
return <Outlet />;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default withSentry(App);"
|
|
28
|
+
`);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=root.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"root.test.js","sourceRoot":"","sources":["../../../test/remix/root.test.ts"],"names":[],"mappings":";;AAAA,kFAAkF;AAClF,uCAAuC;AACvC,mCAA8C;AAC9C,wDAAkE;AAElE,IAAA,iBAAQ,EAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,IAAA,WAAE,EAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,kCAAkC;QAClC,MAAM,eAAe,GAAG,IAAA,sBAAW,EAAC;;;;;;KAMnC,CAAC,CAAC;QAEH,IAAA,wBAAiB,EAAC,eAAe,EAAE,UAAU,CAAC,CAAC;QAE/C,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC;QAE/C,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;KASpC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { parseModule } from 'magicast';\nimport { describe, expect, it } from 'vitest';\nimport { wrapAppWithSentry } from '../../src/remix/codemods/root';\n\ndescribe('wrapAppWithSentry', () => {\n it('should wrap the app with Sentry', () => {\n // Empty root.tsx file for testing\n const originalRootAst = parseModule(`\n import { Outlet } from '@remix-run/react';\n\n export default function App() {\n return <Outlet />;\n }\n `);\n\n wrapAppWithSentry(originalRootAst, 'root.tsx');\n\n const result = originalRootAst.generate().code;\n\n expect(result).toMatchInlineSnapshot(`\n \"import {withSentry} from '@sentry/remix';\n import { Outlet } from '@remix-run/react';\n\n function App() {\n return <Outlet />;\n }\n\n export default withSentry(App);\"\n `);\n });\n});\n"]}
|
package/package.json
CHANGED
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
const recast = __importStar(require("recast"));
|
|
34
|
-
// @ts-expect-error - clack is ESM and TS complains about that. It works though
|
|
35
|
-
const prompts_1 = __importDefault(require("@clack/prompts"));
|
|
36
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
37
|
-
// @ts-expect-error - magicast is ESM and TS complains about that. It works though
|
|
38
|
-
const 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(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
|
-
const functionName = path.value.declaration.id.name;
|
|
52
|
-
// Create the wrapped function call
|
|
53
|
-
const 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
|
-
const rootRouteExport = rootRouteAst.exports.default;
|
|
59
|
-
const expressionToWrap = (0, magicast_1.generateCode)(rootRouteExport.$ast).code;
|
|
60
|
-
rootRouteAst.exports.default = magicast_1.builders.raw(`withSentry(${expressionToWrap})`);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
prompts_1.default.log.warn(chalk_1.default.yellow(`Couldn't instrument ${chalk_1.default.bold(rootFileName)} automatically. Wrap your default export with: ${chalk_1.default.dim('withSentry()')}\n`));
|
|
64
|
-
}
|
|
65
|
-
this.traverse(path);
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
exports.wrapAppWithSentry = wrapAppWithSentry;
|
|
70
|
-
//# sourceMappingURL=root-common.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,+CAAiC;AACjC,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAE1B,kFAAkF;AAClF,uCAAmE;AAEnE,SAAgB,iBAAiB,CAC/B,YAA6B,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AuB,eAAK,CAAC,IAAI,CAC/B,YAAY,CACb,kDAAkD,eAAK,CAAC,GAAG,CAC1D,cAAc,CACf,IAAI,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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function instrumentRootRouteV1(rootFileName: string): Promise<void>;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.instrumentRootRouteV1 = void 0;
|
|
31
|
-
const path = __importStar(require("path"));
|
|
32
|
-
// @ts-expect-error - clack is ESM and TS complains about that. It works though
|
|
33
|
-
const prompts_1 = __importDefault(require("@clack/prompts"));
|
|
34
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
35
|
-
// @ts-expect-error - magicast is ESM and TS complains about that. It works though
|
|
36
|
-
const magicast_1 = require("magicast");
|
|
37
|
-
const root_common_1 = require("./root-common");
|
|
38
|
-
async function instrumentRootRouteV1(rootFileName) {
|
|
39
|
-
try {
|
|
40
|
-
const rootRouteAst = await (0, magicast_1.loadFile)(path.join(process.cwd(), 'app', rootFileName));
|
|
41
|
-
(0, root_common_1.wrapAppWithSentry)(rootRouteAst, rootFileName);
|
|
42
|
-
await (0, magicast_1.writeFile)(rootRouteAst.$ast, path.join(process.cwd(), 'app', rootFileName));
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
// eslint-disable-next-line no-console
|
|
46
|
-
console.error(e);
|
|
47
|
-
prompts_1.default.log.warn(chalk_1.default.yellow(`Something went wrong writing to ${chalk_1.default.bold(rootFileName)}`));
|
|
48
|
-
prompts_1.default.log.info(`Please put the following code snippet into ${chalk_1.default.bold(rootFileName)}: ${chalk_1.default.dim('You probably have to clean it up a bit.')}\n`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.instrumentRootRouteV1 = instrumentRootRouteV1;
|
|
52
|
-
//# sourceMappingURL=root-v1.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"root-v1.js","sourceRoot":"","sources":["../../../../src/remix/codemods/root-v1.ts"],"names":[],"mappings":";AAAA,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE5D,2CAA6B;AAE7B,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAE1B,kFAAkF;AAClF,uCAA+C;AAC/C,+CAAkD;AAE3C,KAAK,UAAU,qBAAqB,CACzC,YAAoB;IAEpB,IAAI;QACF,MAAM,YAAY,GAAG,MAAM,IAAA,mBAAQ,EACjC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAC9C,CAAC;QAEF,IAAA,+BAAiB,EAAC,YAAY,EAAE,YAAY,CAAC,CAAC;QAE9C,MAAM,IAAA,oBAAS,EACb,YAAY,CAAC,IAAI,EACjB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAC9C,CAAC;KACH;IAAC,OAAO,CAAU,EAAE;QACnB,sCAAsC;QACtC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,eAAK,CAAC,MAAM,CACV,mCAAmC,eAAK,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAC9D,CACF,CAAC;QACF,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,8CAA8C,eAAK,CAAC,IAAI,CACtD,YAAY,CACb,KAAK,eAAK,CAAC,GAAG,CAAC,yCAAyC,CAAC,IAAI,CAC/D,CAAC;KACH;AACH,CAAC;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 +0,0 @@
|
|
|
1
|
-
export declare function instrumentRootRouteV2(rootFileName: string): Promise<void>;
|
|
@@ -1 +0,0 @@
|
|
|
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,+CAAiC;AACjC,2CAA6B;AAI7B,kFAAkF;AAClF,uCAA+C;AAE/C,4CAA0D;AAC1D,oCAA4C;AAC5C,+CAAkD;AAE3C,KAAK,UAAU,qBAAqB,CACzC,YAAoB;IAEpB,MAAM,YAAY,GAAG,MAAM,IAAA,mBAAQ,EACjC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAC9C,CAAC;IAEF,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,IAAe,CAAC;IAExD,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,CACzC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,wBAAwB,CACrB,CAAC;IAE9B,IAAI,kBAAkB,GAAG,KAAK,CAAC;IAE/B,YAAY,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;QACnC,MAAM,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC;QAE5C,IAAI,CAAC,WAAW,EAAE;YAChB,OAAO;SACR;QAED,IAAI,WAAW,CAAC,IAAI,KAAK,qBAAqB,EAAE;YAC9C,IAAI,WAAW,CAAC,EAAE,EAAE,IAAI,KAAK,eAAe,EAAE;gBAC5C,kBAAkB,GAAG,IAAI,CAAC;aAC3B;SACF;aAAM,IAAI,WAAW,CAAC,IAAI,KAAK,qBAAqB,E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AAC;qBAC/D;oBAED,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CACnC,wCAAwC,CACzC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;oBAElB,uDAAuD;oBACvD,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAClC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EACxC,CAAC,EACD,gBAAgB,CACjB,CAAC;iBACH;gBACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACtB,CAAC;SACF,CAAC,CAAC;KACJ;IAED,MAAM,IAAA,oBAAS,EACb,YAAY,CAAC,IAAI,EACjB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAC9C,CAAC;AACJ,CAAC;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"]}
|