@sentry/wizard 3.11.0 → 3.13.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 +20 -0
- package/dist/lib/Steps/ChooseIntegration.js +1 -0
- package/dist/lib/Steps/ChooseIntegration.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/src/android/android-wizard.js +14 -4
- package/dist/src/android/android-wizard.js.map +1 -1
- package/dist/src/android/code-tools.d.ts +8 -0
- package/dist/src/android/code-tools.js +20 -8
- package/dist/src/android/code-tools.js.map +1 -1
- package/dist/src/android/gradle.js +6 -1
- package/dist/src/android/gradle.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard.js +5 -2
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/nextjs/templates.d.ts +1 -1
- package/dist/src/nextjs/templates.js +2 -2
- package/dist/src/nextjs/templates.js.map +1 -1
- package/dist/src/remix/remix-wizard.js +8 -4
- package/dist/src/remix/remix-wizard.js.map +1 -1
- package/dist/src/remix/sdk-setup.d.ts +5 -1
- package/dist/src/remix/sdk-setup.js +3 -2
- package/dist/src/remix/sdk-setup.js.map +1 -1
- package/dist/src/sourcemaps/tools/sentry-cli.d.ts +9 -0
- package/dist/src/sourcemaps/tools/sentry-cli.js +26 -22
- package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
- package/dist/src/sourcemaps/tools/tsc.d.ts +6 -0
- package/dist/src/sourcemaps/tools/tsc.js +98 -17
- package/dist/src/sourcemaps/tools/tsc.js.map +1 -1
- package/dist/src/sourcemaps/tools/vite.js +39 -124
- package/dist/src/sourcemaps/tools/vite.js.map +1 -1
- package/dist/src/sourcemaps/tools/webpack.d.ts +6 -1
- package/dist/src/sourcemaps/tools/webpack.js +280 -25
- package/dist/src/sourcemaps/tools/webpack.js.map +1 -1
- package/dist/src/sveltekit/sdk-setup.js +123 -49
- package/dist/src/sveltekit/sdk-setup.js.map +1 -1
- package/dist/src/sveltekit/sveltekit-wizard.d.ts +1 -0
- package/dist/src/sveltekit/sveltekit-wizard.js +119 -44
- package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
- package/dist/src/sveltekit/utils.d.ts +2 -0
- package/dist/src/sveltekit/utils.js +48 -0
- package/dist/src/sveltekit/utils.js.map +1 -0
- package/dist/src/utils/ast-utils.d.ts +77 -3
- package/dist/src/utils/ast-utils.js +172 -6
- package/dist/src/utils/ast-utils.js.map +1 -1
- package/dist/src/utils/clack-utils.d.ts +85 -1
- package/dist/src/utils/clack-utils.js +214 -51
- package/dist/src/utils/clack-utils.js.map +1 -1
- package/dist/src/utils/package-manager.d.ts +5 -0
- package/dist/src/utils/package-manager.js +11 -7
- package/dist/src/utils/package-manager.js.map +1 -1
- package/dist/test/android/code-tools.test.d.ts +1 -0
- package/dist/test/android/code-tools.test.js +34 -0
- package/dist/test/android/code-tools.test.js.map +1 -0
- package/dist/test/sourcemaps/tools/sentry-cli.test.d.ts +1 -0
- package/dist/test/sourcemaps/tools/sentry-cli.test.js +112 -0
- package/dist/test/sourcemaps/tools/sentry-cli.test.js.map +1 -0
- package/dist/test/sourcemaps/tools/tsc.test.d.ts +1 -0
- package/dist/test/sourcemaps/tools/tsc.test.js +121 -0
- package/dist/test/sourcemaps/tools/tsc.test.js.map +1 -0
- package/dist/test/sourcemaps/tools/webpack.test.d.ts +1 -0
- package/dist/test/sourcemaps/tools/webpack.test.js +179 -0
- package/dist/test/sourcemaps/tools/webpack.test.js.map +1 -0
- package/dist/test/utils/ast-utils.test.js +181 -15
- package/dist/test/utils/ast-utils.test.js.map +1 -1
- package/dist/test/utils/clack-utils.test.d.ts +1 -0
- package/dist/test/utils/clack-utils.test.js +200 -0
- package/dist/test/utils/clack-utils.test.js.map +1 -0
- package/lib/Steps/ChooseIntegration.ts +1 -0
- package/package.json +1 -1
- package/src/android/android-wizard.ts +16 -5
- package/src/android/code-tools.ts +21 -7
- package/src/android/gradle.ts +6 -1
- package/src/nextjs/nextjs-wizard.ts +15 -3
- package/src/nextjs/templates.ts +3 -2
- package/src/remix/remix-wizard.ts +8 -11
- package/src/remix/sdk-setup.ts +8 -2
- package/src/sourcemaps/tools/sentry-cli.ts +16 -9
- package/src/sourcemaps/tools/tsc.ts +133 -28
- package/src/sourcemaps/tools/vite.ts +37 -127
- package/src/sourcemaps/tools/webpack.ts +343 -27
- package/src/sveltekit/sdk-setup.ts +115 -39
- package/src/sveltekit/sveltekit-wizard.ts +93 -25
- package/src/sveltekit/utils.ts +50 -0
- package/src/utils/ast-utils.ts +203 -7
- package/src/utils/clack-utils.ts +211 -44
- package/src/utils/package-manager.ts +12 -6
- package/test/android/code-tools.test.ts +49 -0
- package/test/sourcemaps/tools/sentry-cli.test.ts +51 -0
- package/test/sourcemaps/tools/tsc.test.ts +181 -0
- package/test/sourcemaps/tools/webpack.test.ts +303 -0
- package/test/utils/ast-utils.test.ts +240 -20
- package/test/utils/clack-utils.test.ts +142 -0
|
@@ -62,32 +62,113 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
62
62
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
63
|
};
|
|
64
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
-
exports.configureTscSourcemapGenerationFlow = void 0;
|
|
65
|
+
exports.enableSourcemaps = exports.configureTscSourcemapGenerationFlow = void 0;
|
|
66
|
+
var fs = __importStar(require("fs"));
|
|
67
|
+
var path = __importStar(require("path"));
|
|
68
|
+
var recast = __importStar(require("recast"));
|
|
69
|
+
var Sentry = __importStar(require("@sentry/node"));
|
|
66
70
|
// @ts-ignore - clack is ESM and TS complains about that. It works though
|
|
67
|
-
var
|
|
71
|
+
var clack = __importStar(require("@clack/prompts"));
|
|
68
72
|
var chalk_1 = __importDefault(require("chalk"));
|
|
69
73
|
var clack_utils_1 = require("../../utils/clack-utils");
|
|
74
|
+
var ast_utils_1 = require("../../utils/ast-utils");
|
|
75
|
+
var debug_1 = require("../../utils/debug");
|
|
76
|
+
var b = recast.types.builders;
|
|
77
|
+
var getCodeSnippet = function (colors) {
|
|
78
|
+
return (0, clack_utils_1.makeCodeSnippet)(colors, function (unchanged, plus, _) {
|
|
79
|
+
return unchanged("{\n \"compilerOptions\": {\n ".concat(plus('"sourceMap": true,'), "\n ").concat(plus('"inlineSources": true,'), "\n\n // Set `sourceRoot` to \"/\" to strip the build path prefix from\n // generated source code references. This will improve issue grouping in Sentry.\n ").concat(plus('"sourceRoot": "/"'), "\n }\n}"));
|
|
80
|
+
});
|
|
81
|
+
};
|
|
70
82
|
function configureTscSourcemapGenerationFlow() {
|
|
83
|
+
var _a;
|
|
71
84
|
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
-
|
|
73
|
-
|
|
85
|
+
var tsConfigPath, _b, successfullyAdded;
|
|
86
|
+
return __generator(this, function (_c) {
|
|
87
|
+
switch (_c.label) {
|
|
74
88
|
case 0:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return [
|
|
89
|
+
if (!((_a = (0, ast_utils_1.findFile)(path.join(process.cwd(), 'tsconfig'), ['.json'])) !== null && _a !== void 0)) return [3 /*break*/, 1];
|
|
90
|
+
_b = _a;
|
|
91
|
+
return [3 /*break*/, 3];
|
|
92
|
+
case 1: return [4 /*yield*/, (0, clack_utils_1.askForToolConfigPath)('TypeScript', 'tsconfig.json')];
|
|
93
|
+
case 2:
|
|
94
|
+
_b = (_c.sent());
|
|
95
|
+
_c.label = 3;
|
|
96
|
+
case 3:
|
|
97
|
+
tsConfigPath = _b;
|
|
98
|
+
successfullyAdded = false;
|
|
99
|
+
if (!tsConfigPath) return [3 /*break*/, 5];
|
|
100
|
+
return [4 /*yield*/, enableSourcemaps(tsConfigPath)];
|
|
101
|
+
case 4:
|
|
102
|
+
successfullyAdded = _c.sent();
|
|
103
|
+
return [3 /*break*/, 7];
|
|
104
|
+
case 5: return [4 /*yield*/, (0, clack_utils_1.createNewConfigFile)(path.join(process.cwd(), 'tsconfig.json'), getCodeSnippet(false))];
|
|
105
|
+
case 6:
|
|
106
|
+
successfullyAdded = _c.sent();
|
|
107
|
+
Sentry.setTag('created-new-config', successfullyAdded ? 'success' : 'fail');
|
|
108
|
+
_c.label = 7;
|
|
109
|
+
case 7:
|
|
110
|
+
if (!successfullyAdded) return [3 /*break*/, 8];
|
|
111
|
+
Sentry.setTag('ast-mod', 'success');
|
|
112
|
+
clack.log.info("We recommend checking the ".concat(tsConfigPath ? 'modified' : 'added', " file after the wizard finished to ensure it works with your build setup."));
|
|
113
|
+
return [3 /*break*/, 10];
|
|
114
|
+
case 8:
|
|
115
|
+
Sentry.setTag('ast-mod', 'fail');
|
|
116
|
+
return [4 /*yield*/, (0, clack_utils_1.showCopyPasteInstructions)('tsconfig.json', getCodeSnippet(true), 'This ensures that source maps are generated correctly')];
|
|
117
|
+
case 9:
|
|
118
|
+
_c.sent();
|
|
119
|
+
_c.label = 10;
|
|
120
|
+
case 10: return [2 /*return*/];
|
|
87
121
|
}
|
|
88
122
|
});
|
|
89
123
|
});
|
|
90
124
|
}
|
|
91
125
|
exports.configureTscSourcemapGenerationFlow = configureTscSourcemapGenerationFlow;
|
|
92
|
-
|
|
126
|
+
/**
|
|
127
|
+
* Modifies tsconfig.json (@param tsConfigPath) to enable source maps generation.
|
|
128
|
+
*
|
|
129
|
+
* Exported only for testing
|
|
130
|
+
*/
|
|
131
|
+
function enableSourcemaps(tsConfigPath) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
133
|
+
var tsConfig, _a, ast, jsonObject, compilerOptionsProp, compilerOptionsObj, code, e_1;
|
|
134
|
+
return __generator(this, function (_b) {
|
|
135
|
+
switch (_b.label) {
|
|
136
|
+
case 0:
|
|
137
|
+
_b.trys.push([0, 3, , 4]);
|
|
138
|
+
return [4 /*yield*/, fs.promises.readFile(tsConfigPath, 'utf-8')];
|
|
139
|
+
case 1:
|
|
140
|
+
tsConfig = _b.sent();
|
|
141
|
+
_a = (0, ast_utils_1.parseJsonC)(tsConfig.toString()), ast = _a.ast, jsonObject = _a.jsonObject;
|
|
142
|
+
if (!jsonObject || !ast) {
|
|
143
|
+
// this will only happen if the input file isn't valid JSON-C
|
|
144
|
+
Sentry.setTag('ast-mod-fail-reason', 'original-file-invalid');
|
|
145
|
+
return [2 /*return*/, false];
|
|
146
|
+
}
|
|
147
|
+
compilerOptionsProp = (0, ast_utils_1.getOrSetObjectProperty)(jsonObject, 'compilerOptions', b.objectExpression([]));
|
|
148
|
+
compilerOptionsObj = compilerOptionsProp.value;
|
|
149
|
+
if (!compilerOptionsObj || compilerOptionsObj.type !== 'ObjectExpression') {
|
|
150
|
+
// a valid compilerOptions prop should always be an object expression
|
|
151
|
+
Sentry.setTag('ast-mod-fail-reason', 'original-file-invalid');
|
|
152
|
+
return [2 /*return*/, false];
|
|
153
|
+
}
|
|
154
|
+
(0, ast_utils_1.setOrUpdateObjectProperty)(compilerOptionsObj, 'sourceMap', b.booleanLiteral(true));
|
|
155
|
+
(0, ast_utils_1.setOrUpdateObjectProperty)(compilerOptionsObj, 'inlineSources', b.booleanLiteral(true));
|
|
156
|
+
(0, ast_utils_1.setOrUpdateObjectProperty)(compilerOptionsObj, 'sourceRoot', b.stringLiteral('/'), 'Set `sourceRoot` to "/" to strip the build path prefix\nfrom generated source code references.\nThis improves issue grouping in Sentry.');
|
|
157
|
+
code = (0, ast_utils_1.printJsonC)(ast);
|
|
158
|
+
return [4 /*yield*/, fs.promises.writeFile(tsConfigPath, code)];
|
|
159
|
+
case 2:
|
|
160
|
+
_b.sent();
|
|
161
|
+
clack.log.success("Enabled source maps generation in ".concat(chalk_1.default.cyan(path.basename(tsConfigPath || 'tsconfig.json')), "."));
|
|
162
|
+
return [2 /*return*/, true];
|
|
163
|
+
case 3:
|
|
164
|
+
e_1 = _b.sent();
|
|
165
|
+
(0, debug_1.debug)(e_1);
|
|
166
|
+
Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');
|
|
167
|
+
return [2 /*return*/, false];
|
|
168
|
+
case 4: return [2 /*return*/];
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
exports.enableSourcemaps = enableSourcemaps;
|
|
93
174
|
//# sourceMappingURL=tsc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsc.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/tsc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,
|
|
1
|
+
{"version":3,"file":"tsc.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/tsc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AACzB,yCAA6B;AAE7B,6CAAiC;AAEjC,mDAAuC;AAEvC,yEAAyE;AACzE,oDAAwC;AACxC,gDAA0B;AAE1B,uDAKiC;AACjC,mDAM+B;AAC/B,2CAA0C;AAE1C,IAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;AAEhC,IAAM,cAAc,GAAG,UAAC,MAAe;IACrC,OAAA,IAAA,6BAAe,EAAC,MAAM,EAAE,UAAC,SAAS,EAAE,IAAI,EAAE,CAAC;QACzC,OAAA,SAAS,CACP,2CAEA,IAAI,CAAC,oBAAoB,CAAC,mBAC1B,IAAI,CAAC,wBAAwB,CAAC,kLAI9B,IAAI,CAAC,mBAAmB,CAAC,aAE7B,CACG;IAXD,CAWC,CACF;AAbD,CAaC,CAAC;AAEJ,SAAsB,mCAAmC;;;;;;;gCAErD,IAAA,oBAAQ,EAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EA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AC/C,MAAG,CACL,CAAC;oBAEF,sBAAO,IAAI,EAAC;;;oBAEZ,IAAA,aAAK,EAAC,GAAC,CAAC,CAAC;oBACT,MAAM,CAAC,MAAM,CAAC,qBAAqB,EAAE,gBAAgB,CAAC,CAAC;oBACvD,sBAAO,KAAK,EAAC;;;;;CAEhB;AA7DD,4CA6DC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nimport * as recast from 'recast';\n\nimport * as Sentry from '@sentry/node';\n\n// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\n\nimport {\n askForToolConfigPath,\n createNewConfigFile,\n makeCodeSnippet,\n showCopyPasteInstructions,\n} from '../../utils/clack-utils';\nimport {\n findFile,\n getOrSetObjectProperty,\n parseJsonC,\n printJsonC,\n setOrUpdateObjectProperty,\n} from '../../utils/ast-utils';\nimport { debug } from '../../utils/debug';\n\nconst b = recast.types.builders;\n\nconst getCodeSnippet = (colors: boolean) =>\n makeCodeSnippet(colors, (unchanged, plus, _) =>\n unchanged(\n `{\n \"compilerOptions\": {\n ${plus('\"sourceMap\": true,')}\n ${plus('\"inlineSources\": true,')}\n\n // Set \\`sourceRoot\\` to \"/\" to strip the build path prefix from\n // generated source code references. This will improve issue grouping in Sentry.\n ${plus('\"sourceRoot\": \"/\"')}\n }\n}`,\n ),\n );\n\nexport async function configureTscSourcemapGenerationFlow(): Promise<void> {\n const tsConfigPath =\n findFile(path.join(process.cwd(), 'tsconfig'), ['.json']) ??\n (await askForToolConfigPath('TypeScript', 'tsconfig.json'));\n\n let successfullyAdded = false;\n if (tsConfigPath) {\n successfullyAdded = await enableSourcemaps(tsConfigPath);\n } else {\n successfullyAdded = await createNewConfigFile(\n path.join(process.cwd(), 'tsconfig.json'),\n getCodeSnippet(false),\n );\n Sentry.setTag('created-new-config', successfullyAdded ? 'success' : 'fail');\n }\n\n if (successfullyAdded) {\n Sentry.setTag('ast-mod', 'success');\n clack.log.info(\n `We recommend checking the ${\n tsConfigPath ? 'modified' : 'added'\n } file after the wizard finished to ensure it works with your build setup.`,\n );\n } else {\n Sentry.setTag('ast-mod', 'fail');\n await showCopyPasteInstructions(\n 'tsconfig.json',\n getCodeSnippet(true),\n 'This ensures that source maps are generated correctly',\n );\n }\n}\n\n/**\n * Modifies tsconfig.json (@param tsConfigPath) to enable source maps generation.\n *\n * Exported only for testing\n */\nexport async function enableSourcemaps(tsConfigPath: string): Promise<boolean> {\n try {\n const tsConfig = await fs.promises.readFile(tsConfigPath, 'utf-8');\n\n const { ast, jsonObject } = parseJsonC(tsConfig.toString());\n\n if (!jsonObject || !ast) {\n // this will only happen if the input file isn't valid JSON-C\n Sentry.setTag('ast-mod-fail-reason', 'original-file-invalid');\n return false;\n }\n\n const compilerOptionsProp = getOrSetObjectProperty(\n jsonObject,\n 'compilerOptions',\n b.objectExpression([]),\n );\n\n const compilerOptionsObj = compilerOptionsProp.value;\n\n if (!compilerOptionsObj || compilerOptionsObj.type !== 'ObjectExpression') {\n // a valid compilerOptions prop should always be an object expression\n Sentry.setTag('ast-mod-fail-reason', 'original-file-invalid');\n return false;\n }\n\n setOrUpdateObjectProperty(\n compilerOptionsObj,\n 'sourceMap',\n b.booleanLiteral(true),\n );\n\n setOrUpdateObjectProperty(\n compilerOptionsObj,\n 'inlineSources',\n b.booleanLiteral(true),\n );\n\n setOrUpdateObjectProperty(\n compilerOptionsObj,\n 'sourceRoot',\n b.stringLiteral('/'),\n 'Set `sourceRoot` to \"/\" to strip the build path prefix\\nfrom generated source code references.\\nThis improves issue grouping in Sentry.',\n );\n\n const code = printJsonC(ast);\n\n await fs.promises.writeFile(tsConfigPath, code);\n\n clack.log.success(\n `Enabled source maps generation in ${chalk.cyan(\n path.basename(tsConfigPath || 'tsconfig.json'),\n )}.`,\n );\n\n return true;\n } catch (e) {\n debug(e);\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n}\n"]}
|
|
@@ -90,25 +90,16 @@ var path = __importStar(require("path"));
|
|
|
90
90
|
var fs = __importStar(require("fs"));
|
|
91
91
|
var debug_1 = require("../../utils/debug");
|
|
92
92
|
var getViteConfigSnippet = function (options, colors) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var importStmt = colors ? chalk_1.default.greenBright(rawImportStmt) : rawImportStmt;
|
|
97
|
-
var generateSourceMapsOption = colors
|
|
98
|
-
? chalk_1.default.greenBright(rawGenerateSourceMapsOption)
|
|
99
|
-
: rawGenerateSourceMapsOption;
|
|
100
|
-
var sentryVitePluginFunction = colors
|
|
101
|
-
? chalk_1.default.greenBright(rawSentryVitePluginFunction)
|
|
102
|
-
: rawSentryVitePluginFunction;
|
|
103
|
-
var code = getViteConfigContent(importStmt, generateSourceMapsOption, sentryVitePluginFunction);
|
|
104
|
-
return colors ? chalk_1.default.gray(code) : code;
|
|
93
|
+
return (0, clack_utils_1.makeCodeSnippet)(colors, function (unchanged, plus, _) {
|
|
94
|
+
return unchanged("import { defineConfig } from \"vite\";\n".concat(plus('import { sentryVitePlugin } from "@sentry/vite-plugin";'), "\n\nexport default defineConfig({\n build: {\n ").concat(plus('sourcemap: true, // Source map generation must be turned on'), "\n },\n plugins: [\n // Put the Sentry vite plugin after all other plugins\n ").concat(plus("sentryVitePlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"".concat(options.orgSlug, "\",\n project: \"").concat(options.projectSlug, "\",").concat(options.selfHosted ? "\n url: \"".concat(options.url, "\",") : '', "\n }),")), "\n ],\n});"));
|
|
95
|
+
});
|
|
105
96
|
};
|
|
106
|
-
var getViteConfigContent = function (importStmt, generateSourceMapsOption, sentryVitePluginFunction) { return "import { defineConfig } from \"vite\";\n".concat(importStmt, "\n\nexport default defineConfig({\n build: {\n ").concat(generateSourceMapsOption, "\n },\n plugins: [\n // Put the Sentry vite plugin after all other plugins\n ").concat(sentryVitePluginFunction, "\n ],\n});\n"); };
|
|
107
97
|
var configureVitePlugin = function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
108
98
|
var _a, _b, _c, viteConfigPath, _d, successfullyAdded;
|
|
109
99
|
var _e;
|
|
110
|
-
|
|
111
|
-
|
|
100
|
+
var _f;
|
|
101
|
+
return __generator(this, function (_g) {
|
|
102
|
+
switch (_g.label) {
|
|
112
103
|
case 0:
|
|
113
104
|
_a = clack_utils_1.installPackage;
|
|
114
105
|
_e = {
|
|
@@ -117,73 +108,52 @@ var configureVitePlugin = function (options) { return __awaiter(void 0, void 0,
|
|
|
117
108
|
_b = package_json_1.hasPackageInstalled;
|
|
118
109
|
_c = ['@sentry/vite-plugin'];
|
|
119
110
|
return [4 /*yield*/, (0, clack_utils_1.getPackageDotJson)()];
|
|
120
|
-
case 1: return [4 /*yield*/, _a.apply(void 0, [(_e.alreadyInstalled = _b.apply(void 0, _c.concat([
|
|
111
|
+
case 1: return [4 /*yield*/, _a.apply(void 0, [(_e.alreadyInstalled = _b.apply(void 0, _c.concat([_g.sent()])),
|
|
121
112
|
_e)])];
|
|
122
113
|
case 2:
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return [
|
|
127
|
-
case 3:
|
|
128
|
-
_d = (_f.sent());
|
|
129
|
-
_f.label = 4;
|
|
114
|
+
_g.sent();
|
|
115
|
+
if (!((_f = (0, ast_utils_1.findFile)(path.resolve(process.cwd(), 'vite.config'))) !== null && _f !== void 0)) return [3 /*break*/, 3];
|
|
116
|
+
_d = _f;
|
|
117
|
+
return [3 /*break*/, 5];
|
|
118
|
+
case 3: return [4 /*yield*/, (0, clack_utils_1.askForToolConfigPath)('Vite', 'vite.config.js')];
|
|
130
119
|
case 4:
|
|
120
|
+
_d = (_g.sent());
|
|
121
|
+
_g.label = 5;
|
|
122
|
+
case 5:
|
|
131
123
|
viteConfigPath = _d;
|
|
132
124
|
successfullyAdded = false;
|
|
133
|
-
if (!viteConfigPath) return [3 /*break*/,
|
|
125
|
+
if (!viteConfigPath) return [3 /*break*/, 7];
|
|
134
126
|
return [4 /*yield*/, addVitePluginToConfig(viteConfigPath, options)];
|
|
135
|
-
case
|
|
136
|
-
successfullyAdded =
|
|
137
|
-
return [3 /*break*/,
|
|
138
|
-
case
|
|
139
|
-
case 7:
|
|
140
|
-
successfullyAdded = _f.sent();
|
|
141
|
-
_f.label = 8;
|
|
127
|
+
case 6:
|
|
128
|
+
successfullyAdded = _g.sent();
|
|
129
|
+
return [3 /*break*/, 9];
|
|
130
|
+
case 7: return [4 /*yield*/, (0, clack_utils_1.createNewConfigFile)(path.join(process.cwd(), 'vite.config.js'), getViteConfigSnippet(options, false), 'More information about vite configs: https://vitejs.dev/config/')];
|
|
142
131
|
case 8:
|
|
143
|
-
|
|
144
|
-
Sentry.setTag('
|
|
145
|
-
|
|
132
|
+
successfullyAdded = _g.sent();
|
|
133
|
+
Sentry.setTag('created-new-config', successfullyAdded ? 'success' : 'fail');
|
|
134
|
+
_g.label = 9;
|
|
146
135
|
case 9:
|
|
147
|
-
|
|
148
|
-
|
|
136
|
+
if (!successfullyAdded) return [3 /*break*/, 10];
|
|
137
|
+
clack.log.info("We recommend checking the ".concat(viteConfigPath ? 'modified' : 'added', " file after the wizard finished to ensure it works with your build setup."));
|
|
138
|
+
Sentry.setTag('ast-mod', 'success');
|
|
139
|
+
return [3 /*break*/, 12];
|
|
149
140
|
case 10:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
case 11:
|
|
153
|
-
|
|
154
|
-
|
|
141
|
+
Sentry.setTag('ast-mod', 'fail');
|
|
142
|
+
return [4 /*yield*/, (0, clack_utils_1.showCopyPasteInstructions)(path.basename(viteConfigPath || 'vite.config.js'), getViteConfigSnippet(options, true))];
|
|
143
|
+
case 11:
|
|
144
|
+
_g.sent();
|
|
145
|
+
_g.label = 12;
|
|
146
|
+
case 12: return [4 /*yield*/, (0, clack_utils_1.addDotEnvSentryBuildPluginFile)(options.authToken)];
|
|
147
|
+
case 13:
|
|
148
|
+
_g.sent();
|
|
155
149
|
return [2 /*return*/];
|
|
156
150
|
}
|
|
157
151
|
});
|
|
158
152
|
}); };
|
|
159
153
|
exports.configureVitePlugin = configureVitePlugin;
|
|
160
|
-
function createNewViteConfig(options) {
|
|
161
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
162
|
-
var e_1;
|
|
163
|
-
return __generator(this, function (_a) {
|
|
164
|
-
switch (_a.label) {
|
|
165
|
-
case 0:
|
|
166
|
-
_a.trys.push([0, 2, , 3]);
|
|
167
|
-
return [4 /*yield*/, fs.promises.writeFile('vite.config.js', getViteConfigSnippet(options, false))];
|
|
168
|
-
case 1:
|
|
169
|
-
_a.sent();
|
|
170
|
-
Sentry.setTag('created-new-config', 'success');
|
|
171
|
-
return [2 /*return*/, true];
|
|
172
|
-
case 2:
|
|
173
|
-
e_1 = _a.sent();
|
|
174
|
-
(0, debug_1.debug)(e_1);
|
|
175
|
-
Sentry.setTag('created-new-config', 'fail');
|
|
176
|
-
clack.log.warn("Could not create a new ".concat(chalk_1.default.cyan('vite.config.js'), " file. Please create one manually and follow the instructions below."));
|
|
177
|
-
clack.log.info(chalk_1.default.gray('More information about vite configs: https://vitejs.dev/config/'));
|
|
178
|
-
return [2 /*return*/, false];
|
|
179
|
-
case 3: return [2 /*return*/];
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
154
|
function addVitePluginToConfig(viteConfigPath, options) {
|
|
185
155
|
return __awaiter(this, void 0, void 0, function () {
|
|
186
|
-
var prettyViteConfigFilename, viteConfigContent, mod, shouldContinue, enabledSourcemaps, org, project, selfHosted, url, code,
|
|
156
|
+
var prettyViteConfigFilename, viteConfigContent, mod, shouldContinue, enabledSourcemaps, org, project, selfHosted, url, code, e_1;
|
|
187
157
|
return __generator(this, function (_a) {
|
|
188
158
|
switch (_a.label) {
|
|
189
159
|
case 0:
|
|
@@ -193,7 +163,7 @@ function addVitePluginToConfig(viteConfigPath, options) {
|
|
|
193
163
|
case 1:
|
|
194
164
|
viteConfigContent = (_a.sent()).toString();
|
|
195
165
|
mod = (0, magicast_1.parseModule)(viteConfigContent);
|
|
196
|
-
if (!(0, ast_utils_1.hasSentryContent)(mod)) return [3 /*break*/, 3];
|
|
166
|
+
if (!(0, ast_utils_1.hasSentryContent)(mod.$ast)) return [3 /*break*/, 3];
|
|
197
167
|
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.select({
|
|
198
168
|
message: "".concat(prettyViteConfigFilename, " already contains Sentry-related code. Should the wizard modify it anyway?"),
|
|
199
169
|
options: [
|
|
@@ -235,8 +205,8 @@ function addVitePluginToConfig(viteConfigPath, options) {
|
|
|
235
205
|
clack.log.success("Added the Sentry Vite plugin to ".concat(prettyViteConfigFilename, " and enabled source maps"));
|
|
236
206
|
return [2 /*return*/, true];
|
|
237
207
|
case 5:
|
|
238
|
-
|
|
239
|
-
(0, debug_1.debug)(
|
|
208
|
+
e_1 = _a.sent();
|
|
209
|
+
(0, debug_1.debug)(e_1);
|
|
240
210
|
Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');
|
|
241
211
|
return [2 /*return*/, false];
|
|
242
212
|
case 6: return [2 /*return*/];
|
|
@@ -245,61 +215,6 @@ function addVitePluginToConfig(viteConfigPath, options) {
|
|
|
245
215
|
});
|
|
246
216
|
}
|
|
247
217
|
exports.addVitePluginToConfig = addVitePluginToConfig;
|
|
248
|
-
function showCopyPasteInstructions(viteConfigFilename, options) {
|
|
249
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
250
|
-
return __generator(this, function (_a) {
|
|
251
|
-
switch (_a.label) {
|
|
252
|
-
case 0:
|
|
253
|
-
clack.log.step("Add the following code to your ".concat(chalk_1.default.cyan(viteConfigFilename), " file:"));
|
|
254
|
-
// Intentionally logging directly to console here so that the code can be copied/pasted directly
|
|
255
|
-
// eslint-disable-next-line no-console
|
|
256
|
-
console.log("\n".concat(getViteConfigSnippet(options, true)));
|
|
257
|
-
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.select({
|
|
258
|
-
message: 'Did you copy the snippet above?',
|
|
259
|
-
options: [{ label: 'Yes, continue!', value: true }],
|
|
260
|
-
initialValue: true,
|
|
261
|
-
}))];
|
|
262
|
-
case 1:
|
|
263
|
-
_a.sent();
|
|
264
|
-
return [2 /*return*/];
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
function askForViteConfigPath() {
|
|
270
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
271
|
-
var hasViteConfig;
|
|
272
|
-
return __generator(this, function (_a) {
|
|
273
|
-
switch (_a.label) {
|
|
274
|
-
case 0: return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.confirm({
|
|
275
|
-
message: "Do you have a vite config file (e.g. ".concat(chalk_1.default.cyan('vite.config.js'), "?"),
|
|
276
|
-
initialValue: true,
|
|
277
|
-
}))];
|
|
278
|
-
case 1:
|
|
279
|
-
hasViteConfig = _a.sent();
|
|
280
|
-
if (!hasViteConfig) {
|
|
281
|
-
return [2 /*return*/, undefined];
|
|
282
|
-
}
|
|
283
|
-
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.text({
|
|
284
|
-
message: 'Please enter the path to your vite config file:',
|
|
285
|
-
placeholder: ".".concat(path.sep, "vite.config.js"),
|
|
286
|
-
validate: function (value) {
|
|
287
|
-
if (!value) {
|
|
288
|
-
return 'Please enter a path.';
|
|
289
|
-
}
|
|
290
|
-
try {
|
|
291
|
-
fs.accessSync(value);
|
|
292
|
-
}
|
|
293
|
-
catch (_a) {
|
|
294
|
-
return 'Could not access the file at this path.';
|
|
295
|
-
}
|
|
296
|
-
},
|
|
297
|
-
}))];
|
|
298
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
218
|
function enableSourcemapGeneration(program) {
|
|
304
219
|
var configObj = getViteConfigObject(program);
|
|
305
220
|
if (!configObj) {
|
|
@@ -1 +1 @@
|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Aa,CAAC,WAAW,CAAC;KAClC;IAED,IACE,aAAa,CAAC,WAAW,CAAC,IAAI,KAAK,gBAAgB;QACnD,aAAa,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,kBAAkB,EAClE;QACA,OAAO,aAAa,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;KAC/C;IAED,IAAI,aAAa,CAAC,WAAW,CAAC,IAAI,KAAK,YAAY,EAAE;QACnD,IAAM,QAAQ,GAAG,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC;QAChD,OAAO,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;KAC1C;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,cAAc,CACrB,QAAgB,EAChB,OAAkB;;IAElB,KAAmB,UAAY,EAAZ,KAAA,OAAO,CAAC,IAAI,EAAZ,cAAY,EAAZ,IAAY,EAAE;QAA5B,IAAM,IAAI,SAAA;QACb,IAAI,IAAI,CAAC,IAAI,KAAK,qBAAqB,EAAE;YACvC,KAA0B,UAAiB,EAAjB,KAAA,IAAI,CAAC,YAAY,EAAjB,cAAiB,EAAjB,IAAiB,EAAE;gBAAxC,IAAM,WAAW,SAAA;gBACpB,IACE,WAAW,CAAC,IAAI,KAAK,oBAAoB;oBACzC,WAAW,CAAC,EAAE,CAAC,IAAI,KAAK,YAAY;oBACpC,WAAW,CAAC,EAAE,CAAC,IAAI,KAAK,QAAQ;oBAChC,CAAA,MAAA,WAAW,CAAC,IAAI,0CAAE,IAAI,MAAK,kBAAkB,EAC7C;oBACA,OAAO,WAAW,CAAC,IAAI,CAAC;iBACzB;aACF;SACF;KACF;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { generateCode, parseModule } from 'magicast';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { addVitePlugin } from 'magicast/helpers';\n\nimport type { namedTypes as t } from 'ast-types';\n\nimport * as recast from 'recast';\n\nimport * as Sentry from '@sentry/node';\n\nimport chalk from 'chalk';\nimport {\n abortIfCancelled,\n addDotEnvSentryBuildPluginFile,\n getPackageDotJson,\n installPackage,\n} from '../../utils/clack-utils';\nimport { hasPackageInstalled } from '../../utils/package-json';\n\nimport {\n SourceMapUploadToolConfigurationFunction,\n SourceMapUploadToolConfigurationOptions,\n} from './types';\nimport { findFile, hasSentryContent } from '../../utils/ast-utils';\n\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport { debug } from '../../utils/debug';\n\nconst getViteConfigSnippet = (\n options: SourceMapUploadToolConfigurationOptions,\n colors: boolean,\n) => {\n const rawImportStmt =\n 'import { sentryVitePlugin } from \"@sentry/vite-plugin\";';\n const rawGenerateSourceMapsOption =\n 'sourcemap: true, // Source map generation must be turned on';\n const rawSentryVitePluginFunction = `sentryVitePlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"${options.orgSlug}\",\n project: \"${options.projectSlug}\",${\n options.selfHosted ? `\\n url: \"${options.url}\",` : ''\n }\n }),`;\n\n const importStmt = colors ? chalk.greenBright(rawImportStmt) : rawImportStmt;\n const generateSourceMapsOption = colors\n ? chalk.greenBright(rawGenerateSourceMapsOption)\n : rawGenerateSourceMapsOption;\n const sentryVitePluginFunction = colors\n ? chalk.greenBright(rawSentryVitePluginFunction)\n : rawSentryVitePluginFunction;\n\n const code = getViteConfigContent(\n importStmt,\n generateSourceMapsOption,\n sentryVitePluginFunction,\n );\n return colors ? chalk.gray(code) : code;\n};\n\nconst getViteConfigContent = (\n importStmt: string,\n generateSourceMapsOption: string,\n sentryVitePluginFunction: string,\n) => `import { defineConfig } from \"vite\";\n${importStmt}\n\nexport default defineConfig({\n build: {\n ${generateSourceMapsOption}\n },\n plugins: [\n // Put the Sentry vite plugin after all other plugins\n ${sentryVitePluginFunction}\n ],\n});\n`;\n\nexport const configureVitePlugin: SourceMapUploadToolConfigurationFunction =\n async (options) => {\n await installPackage({\n packageName: '@sentry/vite-plugin',\n alreadyInstalled: hasPackageInstalled(\n '@sentry/vite-plugin',\n await getPackageDotJson(),\n ),\n });\n\n const viteConfigPath =\n findFile(path.resolve(process.cwd(), 'vite.config')) ||\n (await askForViteConfigPath());\n\n let successfullyAdded = false;\n if (viteConfigPath) {\n successfullyAdded = await addVitePluginToConfig(viteConfigPath, options);\n } else {\n successfullyAdded = await createNewViteConfig(options);\n }\n\n if (successfullyAdded) {\n Sentry.setTag('ast-mod', 'success');\n } else {\n Sentry.setTag('ast-mod', 'fail');\n await showCopyPasteInstructions(\n path.basename(viteConfigPath || 'vite.config.js'),\n options,\n );\n }\n\n await addDotEnvSentryBuildPluginFile(options.authToken);\n };\n\nasync function createNewViteConfig(\n options: SourceMapUploadToolConfigurationOptions,\n): Promise<boolean> {\n try {\n await fs.promises.writeFile(\n 'vite.config.js',\n getViteConfigSnippet(options, false),\n );\n Sentry.setTag('created-new-config', 'success');\n return true;\n } catch (e) {\n debug(e);\n Sentry.setTag('created-new-config', 'fail');\n clack.log.warn(\n `Could not create a new ${chalk.cyan(\n 'vite.config.js',\n )} file. Please create one manually and follow the instructions below.`,\n );\n\n clack.log.info(\n chalk.gray(\n 'More information about vite configs: https://vitejs.dev/config/',\n ),\n );\n\n return false;\n }\n}\n\nexport async function addVitePluginToConfig(\n viteConfigPath: string,\n options: SourceMapUploadToolConfigurationOptions,\n): Promise<boolean> {\n try {\n const prettyViteConfigFilename = chalk.cyan(path.basename(viteConfigPath));\n\n const viteConfigContent = (\n await fs.promises.readFile(viteConfigPath)\n ).toString();\n\n const mod = parseModule(viteConfigContent);\n\n if (hasSentryContent(mod)) {\n const shouldContinue = await abortIfCancelled(\n clack.select({\n message: `${prettyViteConfigFilename} already contains Sentry-related code. Should the wizard modify it anyway?`,\n options: [\n {\n label: 'Yes, add the Sentry Vite plugin',\n value: true,\n },\n {\n label: 'No, show me instructions to manually add the plugin',\n value: false,\n },\n ],\n initialValue: true,\n }),\n );\n\n if (!shouldContinue) {\n Sentry.setTag('ast-mod-fail-reason', 'has-sentry-content');\n return false;\n }\n }\n\n const enabledSourcemaps = enableSourcemapGeneration(mod.$ast as t.Program);\n if (!enabledSourcemaps) {\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n\n const { orgSlug: org, projectSlug: project, selfHosted, url } = options;\n\n addVitePlugin(mod, {\n imported: 'sentryVitePlugin',\n from: '@sentry/vite-plugin',\n constructor: 'sentryVitePlugin',\n options: {\n org,\n project,\n ...(selfHosted && { url }),\n },\n });\n\n const code = generateCode(mod.$ast).code;\n\n await fs.promises.writeFile(viteConfigPath, code);\n\n clack.log.success(\n `Added the Sentry Vite plugin to ${prettyViteConfigFilename} and enabled source maps`,\n );\n\n return true;\n } catch (e) {\n debug(e);\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n}\n\nasync function showCopyPasteInstructions(\n viteConfigFilename: string,\n options: SourceMapUploadToolConfigurationOptions,\n) {\n clack.log.step(\n `Add the following code to your ${chalk.cyan(viteConfigFilename)} file:`,\n );\n\n // Intentionally logging directly to console here so that the code can be copied/pasted directly\n // eslint-disable-next-line no-console\n console.log(`\\n${getViteConfigSnippet(options, true)}`);\n\n await abortIfCancelled(\n clack.select({\n message: 'Did you copy the snippet above?',\n options: [{ label: 'Yes, continue!', value: true }],\n initialValue: true,\n }),\n );\n}\n\nasync function askForViteConfigPath(): Promise<string | undefined> {\n const hasViteConfig = await abortIfCancelled(\n clack.confirm({\n message: `Do you have a vite config file (e.g. ${chalk.cyan(\n 'vite.config.js',\n )}?`,\n initialValue: true,\n }),\n );\n\n if (!hasViteConfig) {\n return undefined;\n }\n\n return await abortIfCancelled(\n clack.text({\n message: 'Please enter the path to your vite config file:',\n placeholder: `.${path.sep}vite.config.js`,\n validate: (value) => {\n if (!value) {\n return 'Please enter a path.';\n }\n\n try {\n fs.accessSync(value);\n } catch {\n return 'Could not access the file at this path.';\n }\n },\n }),\n );\n}\n\nfunction enableSourcemapGeneration(program: t.Program): boolean {\n const configObj = getViteConfigObject(program);\n\n if (!configObj) {\n return false;\n }\n\n const b = recast.types.builders;\n\n const buildProp = configObj.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'build',\n );\n\n // case 1: build property doesn't exist yet, so we can just add it\n if (!buildProp) {\n configObj.properties.push(\n b.objectProperty(\n b.identifier('build'),\n b.objectExpression([\n b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),\n ]),\n ),\n );\n return true;\n }\n\n const isValidBuildProp =\n buildProp.type === 'ObjectProperty' &&\n buildProp.value.type === 'ObjectExpression';\n\n if (!isValidBuildProp) {\n return false;\n }\n\n const sourceMapsProp =\n buildProp.value.type === 'ObjectExpression' &&\n buildProp.value.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'sourcemap',\n );\n\n // case 2: build.sourcemap property doesn't exist yet, so we just add it\n if (!sourceMapsProp && buildProp.value.type === 'ObjectExpression') {\n buildProp.value.properties.push(\n b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),\n );\n return true;\n }\n\n if (!sourceMapsProp || sourceMapsProp.type !== 'ObjectProperty') {\n return false;\n }\n\n // case 3: build.sourcemap property exists, and it's set to 'hidden'\n if (\n sourceMapsProp.value.type === 'StringLiteral' &&\n sourceMapsProp.value.value === 'hidden'\n ) {\n // nothing to do for us\n return true;\n }\n\n // case 4: build.sourcemap property exists, but it's not enabled, so we set it to true\n // or it is already true in which case this is a noop\n sourceMapsProp.value = b.booleanLiteral(true);\n return true;\n}\n\nfunction getViteConfigObject(\n program: t.Program,\n): t.ObjectExpression | undefined {\n const defaultExport = program.body.find(\n (s) => s.type === 'ExportDefaultDeclaration',\n ) as t.ExportDefaultDeclaration;\n\n if (!defaultExport) {\n return undefined;\n }\n\n if (defaultExport.declaration.type === 'ObjectExpression') {\n return defaultExport.declaration;\n }\n\n if (\n defaultExport.declaration.type === 'CallExpression' &&\n defaultExport.declaration.arguments[0].type === 'ObjectExpression'\n ) {\n return defaultExport.declaration.arguments[0];\n }\n\n if (defaultExport.declaration.type === 'Identifier') {\n const configId = defaultExport.declaration.name;\n return findConfigNode(configId, program);\n }\n\n return undefined;\n}\n\nfunction findConfigNode(\n configId: string,\n program: t.Program,\n): t.ObjectExpression | undefined {\n for (const node of program.body) {\n if (node.type === 'VariableDeclaration') {\n for (const declaration of node.declarations) {\n if (\n declaration.type === 'VariableDeclarator' &&\n declaration.id.type === 'Identifier' &&\n declaration.id.name === configId &&\n declaration.init?.type === 'ObjectExpression'\n ) {\n return declaration.init;\n }\n }\n }\n }\n return undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/vite.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,oDAAwC;AACxC,4EAA4E;AAC5E,qCAAqD;AACrD,4EAA4E;AAC5E,4CAAiD;AAIjD,6CAAiC;AAEjC,mDAAuC;AAEvC,gDAA0B;AAC1B,uDASiC;AACjC,yDAA+D;AAM/D,mDAAmE;AAEnE,yCAA6B;AAC7B,qCAAyB;AACzB,2CAA0C;AAE1C,IAAM,oBAAoB,GAAG,UAC3B,OAAgD,EAChD,MAAe;IAEf,OAAA,IAAA,6BAAe,EAAC,MAAM,EAAE,UAAC,SAAS,EAAE,IAAI,EAAE,CAAC;QACzC,OAAA,SAAS,CAAC,kDACZ,IAAI,CAAC,yDAAyD,CAAC,gEAI3D,IAAI,CAAC,6DAA6D,CAAC,kGAInE,IAAI,CAAC,4FAEG,OAAO,CAAC,OAAO,mCACX,OAAO,CAAC,WAAW,gBAC/B,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,yBAAiB,OAAO,CAAC,GAAG,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C,IAAI,CAAC;QAChD,OAAO,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;KAC1C;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,cAAc,CACrB,QAAgB,EAChB,OAAkB;;IAElB,KAAmB,UAAY,EAAZ,KAAA,OAAO,CAAC,IAAI,EAAZ,cAAY,EAAZ,IAAY,EAAE;QAA5B,IAAM,IAAI,SAAA;QACb,IAAI,IAAI,CAAC,IAAI,KAAK,qBAAqB,EAAE;YACvC,KAA0B,UAAiB,EAAjB,KAAA,IAAI,CAAC,YAAY,EAAjB,cAAiB,EAAjB,IAAiB,EAAE;gBAAxC,IAAM,WAAW,SAAA;gBACpB,IACE,WAAW,CAAC,IAAI,KAAK,oBAAoB;oBACzC,WAAW,CAAC,EAAE,CAAC,IAAI,KAAK,YAAY;oBACpC,WAAW,CAAC,EAAE,CAAC,IAAI,KAAK,QAAQ;oBAChC,CAAA,MAAA,WAAW,CAAC,IAAI,0CAAE,IAAI,MAAK,kBAAkB,EAC7C;oBACA,OAAO,WAAW,CAAC,IAAI,CAAC;iBACzB;aACF;SACF;KACF;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { generateCode, parseModule } from 'magicast';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { addVitePlugin } from 'magicast/helpers';\n\nimport type { namedTypes as t } from 'ast-types';\n\nimport * as recast from 'recast';\n\nimport * as Sentry from '@sentry/node';\n\nimport chalk from 'chalk';\nimport {\n abortIfCancelled,\n addDotEnvSentryBuildPluginFile,\n askForToolConfigPath,\n createNewConfigFile,\n getPackageDotJson,\n installPackage,\n makeCodeSnippet,\n showCopyPasteInstructions,\n} from '../../utils/clack-utils';\nimport { hasPackageInstalled } from '../../utils/package-json';\n\nimport {\n SourceMapUploadToolConfigurationFunction,\n SourceMapUploadToolConfigurationOptions,\n} from './types';\nimport { findFile, hasSentryContent } from '../../utils/ast-utils';\n\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport { debug } from '../../utils/debug';\n\nconst getViteConfigSnippet = (\n options: SourceMapUploadToolConfigurationOptions,\n colors: boolean,\n) =>\n makeCodeSnippet(colors, (unchanged, plus, _) =>\n unchanged(`import { defineConfig } from \"vite\";\n${plus('import { sentryVitePlugin } from \"@sentry/vite-plugin\";')}\n\nexport default defineConfig({\n build: {\n ${plus('sourcemap: true, // Source map generation must be turned on')}\n },\n plugins: [\n // Put the Sentry vite plugin after all other plugins\n ${plus(`sentryVitePlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"${options.orgSlug}\",\n project: \"${options.projectSlug}\",${\n options.selfHosted ? `\\n url: \"${options.url}\",` : ''\n }\n }),`)}\n ],\n});`),\n );\n\nexport const configureVitePlugin: SourceMapUploadToolConfigurationFunction =\n async (options) => {\n await installPackage({\n packageName: '@sentry/vite-plugin',\n alreadyInstalled: hasPackageInstalled(\n '@sentry/vite-plugin',\n await getPackageDotJson(),\n ),\n });\n\n const viteConfigPath =\n findFile(path.resolve(process.cwd(), 'vite.config')) ??\n (await askForToolConfigPath('Vite', 'vite.config.js'));\n\n let successfullyAdded = false;\n if (viteConfigPath) {\n successfullyAdded = await addVitePluginToConfig(viteConfigPath, options);\n } else {\n successfullyAdded = await createNewConfigFile(\n path.join(process.cwd(), 'vite.config.js'),\n getViteConfigSnippet(options, false),\n 'More information about vite configs: https://vitejs.dev/config/',\n );\n Sentry.setTag(\n 'created-new-config',\n successfullyAdded ? 'success' : 'fail',\n );\n }\n\n if (successfullyAdded) {\n clack.log.info(\n `We recommend checking the ${\n viteConfigPath ? 'modified' : 'added'\n } file after the wizard finished to ensure it works with your build setup.`,\n );\n\n Sentry.setTag('ast-mod', 'success');\n } else {\n Sentry.setTag('ast-mod', 'fail');\n await showCopyPasteInstructions(\n path.basename(viteConfigPath || 'vite.config.js'),\n getViteConfigSnippet(options, true),\n );\n }\n\n await addDotEnvSentryBuildPluginFile(options.authToken);\n };\n\nexport async function addVitePluginToConfig(\n viteConfigPath: string,\n options: SourceMapUploadToolConfigurationOptions,\n): Promise<boolean> {\n try {\n const prettyViteConfigFilename = chalk.cyan(path.basename(viteConfigPath));\n\n const viteConfigContent = (\n await fs.promises.readFile(viteConfigPath)\n ).toString();\n\n const mod = parseModule(viteConfigContent);\n\n if (hasSentryContent(mod.$ast as t.Program)) {\n const shouldContinue = await abortIfCancelled(\n clack.select({\n message: `${prettyViteConfigFilename} already contains Sentry-related code. Should the wizard modify it anyway?`,\n options: [\n {\n label: 'Yes, add the Sentry Vite plugin',\n value: true,\n },\n {\n label: 'No, show me instructions to manually add the plugin',\n value: false,\n },\n ],\n initialValue: true,\n }),\n );\n\n if (!shouldContinue) {\n Sentry.setTag('ast-mod-fail-reason', 'has-sentry-content');\n return false;\n }\n }\n\n const enabledSourcemaps = enableSourcemapGeneration(mod.$ast as t.Program);\n if (!enabledSourcemaps) {\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n\n const { orgSlug: org, projectSlug: project, selfHosted, url } = options;\n\n addVitePlugin(mod, {\n imported: 'sentryVitePlugin',\n from: '@sentry/vite-plugin',\n constructor: 'sentryVitePlugin',\n options: {\n org,\n project,\n ...(selfHosted && { url }),\n },\n });\n\n const code = generateCode(mod.$ast).code;\n\n await fs.promises.writeFile(viteConfigPath, code);\n\n clack.log.success(\n `Added the Sentry Vite plugin to ${prettyViteConfigFilename} and enabled source maps`,\n );\n\n return true;\n } catch (e) {\n debug(e);\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n}\n\nfunction enableSourcemapGeneration(program: t.Program): boolean {\n const configObj = getViteConfigObject(program);\n\n if (!configObj) {\n return false;\n }\n\n const b = recast.types.builders;\n\n const buildProp = configObj.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'build',\n );\n\n // case 1: build property doesn't exist yet, so we can just add it\n if (!buildProp) {\n configObj.properties.push(\n b.objectProperty(\n b.identifier('build'),\n b.objectExpression([\n b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),\n ]),\n ),\n );\n return true;\n }\n\n const isValidBuildProp =\n buildProp.type === 'ObjectProperty' &&\n buildProp.value.type === 'ObjectExpression';\n\n if (!isValidBuildProp) {\n return false;\n }\n\n const sourceMapsProp =\n buildProp.value.type === 'ObjectExpression' &&\n buildProp.value.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'sourcemap',\n );\n\n // case 2: build.sourcemap property doesn't exist yet, so we just add it\n if (!sourceMapsProp && buildProp.value.type === 'ObjectExpression') {\n buildProp.value.properties.push(\n b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),\n );\n return true;\n }\n\n if (!sourceMapsProp || sourceMapsProp.type !== 'ObjectProperty') {\n return false;\n }\n\n // case 3: build.sourcemap property exists, and it's set to 'hidden'\n if (\n sourceMapsProp.value.type === 'StringLiteral' &&\n sourceMapsProp.value.value === 'hidden'\n ) {\n // nothing to do for us\n return true;\n }\n\n // case 4: build.sourcemap property exists, but it's not enabled, so we set it to true\n // or it is already true in which case this is a noop\n sourceMapsProp.value = b.booleanLiteral(true);\n return true;\n}\n\nfunction getViteConfigObject(\n program: t.Program,\n): t.ObjectExpression | undefined {\n const defaultExport = program.body.find(\n (s) => s.type === 'ExportDefaultDeclaration',\n ) as t.ExportDefaultDeclaration;\n\n if (!defaultExport) {\n return undefined;\n }\n\n if (defaultExport.declaration.type === 'ObjectExpression') {\n return defaultExport.declaration;\n }\n\n if (\n defaultExport.declaration.type === 'CallExpression' &&\n defaultExport.declaration.arguments[0].type === 'ObjectExpression'\n ) {\n return defaultExport.declaration.arguments[0];\n }\n\n if (defaultExport.declaration.type === 'Identifier') {\n const configId = defaultExport.declaration.name;\n return findConfigNode(configId, program);\n }\n\n return undefined;\n}\n\nfunction findConfigNode(\n configId: string,\n program: t.Program,\n): t.ObjectExpression | undefined {\n for (const node of program.body) {\n if (node.type === 'VariableDeclaration') {\n for (const declaration of node.declarations) {\n if (\n declaration.type === 'VariableDeclarator' &&\n declaration.id.type === 'Identifier' &&\n declaration.id.name === configId &&\n declaration.init?.type === 'ObjectExpression'\n ) {\n return declaration.init;\n }\n }\n }\n }\n return undefined;\n}\n"]}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import { SourceMapUploadToolConfigurationFunction } from './types';
|
|
1
|
+
import { SourceMapUploadToolConfigurationFunction, SourceMapUploadToolConfigurationOptions } from './types';
|
|
2
2
|
export declare const configureWebPackPlugin: SourceMapUploadToolConfigurationFunction;
|
|
3
|
+
/**
|
|
4
|
+
* Modifies a webpack config file to enable source map generation and add the Sentry webpack plugin
|
|
5
|
+
* exported only for testing
|
|
6
|
+
*/
|
|
7
|
+
export declare function modifyWebpackConfig(webpackConfigPath: string, options: SourceMapUploadToolConfigurationOptions): Promise<boolean>;
|