@sentry/wizard
Version:
Sentry wizard helping you to configure your project
94 lines • 3.92 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.addSourceMapsSetting = exports.addSourcemapEntryToAngularJSON = void 0;
// @ts-expect-error - clack is ESM and TS complains about that. It works though
const clack = __importStar(require("@clack/prompts"));
const path = __importStar(require("path"));
const fs = __importStar(require("fs"));
const angular_1 = require("../../sourcemaps/tools/angular");
const node_1 = require("@sentry/node");
async function addSourcemapEntryToAngularJSON() {
const angularJsonPath = path.join(process.cwd(), 'angular.json');
const angularJson = getParsedAngularJson(angularJsonPath);
if (!angularJson || typeof angularJson !== 'object') {
await (0, angular_1.configureAngularSourcemapGenerationFlow)();
return;
}
const updatedAngularJson = addSourceMapsSetting(angularJson);
if (!updatedAngularJson) {
await (0, angular_1.configureAngularSourcemapGenerationFlow)();
return;
}
try {
fs.writeFileSync(angularJsonPath, JSON.stringify(updatedAngularJson, null, 2));
}
catch (error) {
clack.log.error(`Failed to write sourcemap configuration to angular.json`);
(0, node_1.captureException)('Failed to write sourcemap configuration to angular.json');
await (0, angular_1.configureAngularSourcemapGenerationFlow)();
}
}
exports.addSourcemapEntryToAngularJSON = addSourcemapEntryToAngularJSON;
/**
* Extracted from `addSourcemapEntryToAngularJSON` and exported to allow for easier testing.
*/
function addSourceMapsSetting(angularJson) {
const newAngularJson = { ...angularJson };
const projectKeys = Object.keys(newAngularJson.projects || {});
if (!projectKeys.length || !newAngularJson.projects) {
return undefined;
}
// Emit sourcemaps from all projects in angular.json
for (const projectKey of projectKeys) {
const projectConfig = newAngularJson.projects[projectKey];
if (!projectConfig.architect) {
projectConfig.architect = {};
}
if (!projectConfig.architect.build) {
projectConfig.architect.build = {};
}
if (!projectConfig.architect.build.configurations) {
projectConfig.architect.build.configurations = {};
}
projectConfig.architect.build.configurations.production = {
...projectConfig.architect.build.configurations.production,
sourceMap: true,
};
}
return newAngularJson;
}
exports.addSourceMapsSetting = addSourceMapsSetting;
function getParsedAngularJson(path) {
try {
const angularJSONFile = fs.readFileSync(path, 'utf-8');
return JSON.parse(angularJSONFile);
}
catch {
(0, node_1.captureException)('Could not parse `angular.json`');
return undefined;
}
}
//# sourceMappingURL=sourcemaps.js.map
;