@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsc.test.js","sourceRoot":"","sources":["../../../../test/sourcemaps/tools/tsc.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AACzB,yDAAqE;AAErE,SAAS,iBAAiB,CAAC,OAAe;IACxC,WAAW,GAAG,OAAO,CAAC;AACxB,CAAC;AAED,IAAI,WAAW,GAAG,EAAE,CAAC;AAErB,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;IAC1B,OAAO;QACL,GAAG,EAAE;YACH,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;YACf,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;SACnB;KACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAI;KACD,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,UAAU,CAAC;KAC9B,kBAAkB,CAAC,cAAM,OAAA,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAA5B,CAA4B,CAAC,CAAC;AAE1D,IAAM,YAAY,GAAG,IAAI;KACtB,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC;KAC/B,kBAAkB,CAAC,cAAM,OAAA,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAvB,CAAuB,CAAC,CAAC;AAErD,QAAQ,CAAC,kBAAkB,EAAE;IAC3B,SAAS,CAAC;QACR,WAAW,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,IAAI,CAAC;QACN;YACE,uBAAuB;YACvB,iUAkBL;YACK,ikBA4BL;SACI;QACD;YACE,0BAA0B;YAC1B,2XAoBL;YACK,mkBA6BL;SACI;QACD;YACE,qBAAqB;YACrB,mFAOL;YACK,uYAiBL;SACI;KACF,CAAC,CACA,yDAAyD,EACzD,UAAO,CAAC,EAAE,YAAY,EAAE,YAAY;;;;;oBAClC,iBAAiB,CAAC,YAAY,CAAC,CAAC;oBAEd,qBAAM,IAAA,sBAAgB,EAAC,EAAE,CAAC,EAAA;;oBAAtC,SAAS,GAAG,SAA0B;oBAE5C,MAAM,CAAC,YAAY,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;oBACvC,KAAmB,YAAY,CAAC,IAAI,CAAC,KAAK,GAA3B,EAAZ,WAAW,QAAA,CAA6B;oBAClD,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;oBACvC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;;;SAC9B,CACF,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import * as fs from 'fs';\nimport { enableSourcemaps } from '../../../src/sourcemaps/tools/tsc';\n\nfunction updateFileContent(content: string): void {\n fileContent = content;\n}\n\nlet fileContent = '';\n\njest.mock('@clack/prompts', () => {\n return {\n log: {\n info: jest.fn(),\n success: jest.fn(),\n },\n };\n});\n\njest\n .spyOn(fs.promises, 'readFile')\n .mockImplementation(() => Promise.resolve(fileContent));\n\nconst writeFileSpy = jest\n .spyOn(fs.promises, 'writeFile')\n .mockImplementation(() => Promise.resolve(void 0));\n\ndescribe('enableSourcemaps', () => {\n afterEach(() => {\n fileContent = '';\n jest.clearAllMocks();\n });\n\n it.each([\n [\n 'no sourcemaps options',\n `\n/**\n * My TS config with comments\n */\n{\n \"extends\": \"./tsconfig.build.json\",\n\n \"compilerOptions\": {\n // line comment which should stay\n \"moduleResolution\": \"node16\",\n \"outDir\": \"dist\" // another inline comment\n },\n\n \"include\": [\n \"src/**/*\",\n \"test/**/*\"\n ]\n}\n`,\n `\n/**\n * My TS config with comments\n */\n{\n \"extends\": \"./tsconfig.build.json\",\n\n \"compilerOptions\": {\n // line comment which should stay\n \"moduleResolution\": \"node16\",\n\n // another inline comment\n \"outDir\": \"dist\",\n\n \"sourceMap\": true,\n \"inlineSources\": true,\n\n // Set \\`sourceRoot\\` to \"/\" to strip the build path prefix\n // from generated source code references.\n // This improves issue grouping in Sentry.\n \"sourceRoot\": \"/\"\n },\n\n \"include\": [\n \"src/**/*\",\n \"test/**/*\"\n ]\n}\n`,\n ],\n [\n 'a few sourcemaps options',\n `\n/**\n * My TS config with comments\n */\n{\n \"extends\": \"./tsconfig.build.json\",\n\n \"compilerOptions\": {\n // line comment which should stay\n \"moduleResolution\": \"node16\",\n \"outDir\": \"dist\", // another inline comment\n \"sourceMap\": false,\n \"sourceRoot\": \"/src\"\n },\n\n \"include\": [\n \"src/**/*\",\n \"test/**/*\"\n ]\n}\n`,\n `\n/**\n * My TS config with comments\n */\n{\n \"extends\": \"./tsconfig.build.json\",\n\n \"compilerOptions\": {\n // line comment which should stay\n \"moduleResolution\": \"node16\",\n\n // another inline comment\n \"outDir\": \"dist\",\n\n \"sourceMap\": true,\n\n // Set \\`sourceRoot\\` to \"/\" to strip the build path prefix\n // from generated source code references.\n // This improves issue grouping in Sentry.\n \"sourceRoot\": \"/\",\n\n \"inlineSources\": true\n },\n\n \"include\": [\n \"src/**/*\",\n \"test/**/*\"\n ]\n}\n`,\n ],\n [\n 'no compiler options',\n `\n{\n \"include\": [\n \"src/**/*\",\n \"test/**/*\"\n ]\n}\n`,\n `\n{\n \"include\": [\n \"src/**/*\",\n \"test/**/*\"\n ],\n\n \"compilerOptions\": {\n \"sourceMap\": true,\n \"inlineSources\": true,\n\n // Set \\`sourceRoot\\` to \"/\" to strip the build path prefix\n // from generated source code references.\n // This improves issue grouping in Sentry.\n \"sourceRoot\": \"/\"\n }\n}\n`,\n ],\n ])(\n 'adds the plugin and enables source maps generation (%s)',\n async (_, originalCode, expectedCode) => {\n updateFileContent(originalCode);\n\n const addedCode = await enableSourcemaps('');\n\n expect(writeFileSpy).toHaveBeenCalledTimes(1);\n const [[, fileContent]] = writeFileSpy.mock.calls;\n expect(fileContent).toBe(expectedCode);\n expect(addedCode).toBe(true);\n },\n );\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
+
var fs = __importStar(require("fs"));
|
|
63
|
+
var webpack_1 = require("../../../src/sourcemaps/tools/webpack");
|
|
64
|
+
function updateFileContent(content) {
|
|
65
|
+
fileContent = content;
|
|
66
|
+
}
|
|
67
|
+
var fileContent = '';
|
|
68
|
+
jest.mock('@clack/prompts', function () {
|
|
69
|
+
return {
|
|
70
|
+
log: {
|
|
71
|
+
info: jest.fn(),
|
|
72
|
+
success: jest.fn(),
|
|
73
|
+
},
|
|
74
|
+
select: jest.fn().mockImplementation(function () { return Promise.resolve(true); }),
|
|
75
|
+
isCancel: jest.fn().mockReturnValue(false),
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
jest
|
|
79
|
+
.spyOn(fs.promises, 'readFile')
|
|
80
|
+
.mockImplementation(function () { return Promise.resolve(fileContent); });
|
|
81
|
+
var writeFileSpy = jest
|
|
82
|
+
.spyOn(fs.promises, 'writeFile')
|
|
83
|
+
.mockImplementation(function () { return Promise.resolve(void 0); });
|
|
84
|
+
var noSourcemapNoPluginsPojo = "module.exports = {\n entry: \"./src/index.js\",\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n};";
|
|
85
|
+
var noSourcemapNoPluginsPojoResult = "const {\n sentryWebpackPlugin\n} = require(\"@sentry/webpack-plugin\");\n\nmodule.exports = {\n entry: \"./src/index.js\",\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n\n devtool: \"source-map\",\n\n plugins: [sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"my-org\",\n project: \"my-project\"\n })]\n};";
|
|
86
|
+
var noSourcemapsNoPluginsId = "const config = {\n entry: \"./src/index.js\",\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n};\n\nmodule.exports = config;";
|
|
87
|
+
var noSourcemapsNoPluginsIdResult = "const {\n sentryWebpackPlugin\n} = require(\"@sentry/webpack-plugin\");\n\nconst config = {\n entry: \"./src/index.js\",\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n\n devtool: \"source-map\",\n\n plugins: [sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"my-org\",\n project: \"my-project\"\n })]\n};\n\nmodule.exports = config;";
|
|
88
|
+
var hiddenSourcemapNoPluginsId = "const config = {\n entry: \"./src/index.js\",\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n\n devtool: \"hidden-cheap-source-map\",\n};\n\nmodule.exports = config;\n ";
|
|
89
|
+
var hiddenSourcemapNoPluginsIdResult = "const {\n sentryWebpackPlugin\n} = require(\"@sentry/webpack-plugin\");\n\nconst config = {\n entry: \"./src/index.js\",\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n\n devtool: \"hidden-source-map\",\n\n plugins: [sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"my-org\",\n project: \"my-project\"\n })]\n};\n\nmodule.exports = config;";
|
|
90
|
+
var arbitrarySourcemapNoPluginsId = "\nconst config = {\n entry: \"./src/index.js\",\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n\n devtool: getSourcemapSetting(),\n};\n\nmodule.exports = config;\n ";
|
|
91
|
+
var arbitrarySourcemapNoPluginsIdResult = "const {\n sentryWebpackPlugin\n} = require(\"@sentry/webpack-plugin\");\n\nconst config = {\n entry: \"./src/index.js\",\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n\n devtool: \"source-map\",\n\n plugins: [sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"my-org\",\n project: \"my-project\"\n })]\n};\n\nmodule.exports = config;";
|
|
92
|
+
var noSourcemapUndefinedPluginsPojo = "module.exports = {\n entry: \"./src/index.js\",\n plugins: undefined,\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n};";
|
|
93
|
+
var noSourcemapUndefinedPluginsPojoResult = "const {\n sentryWebpackPlugin\n} = require(\"@sentry/webpack-plugin\");\n\nmodule.exports = {\n entry: \"./src/index.js\",\n\n plugins: [sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"my-org\",\n project: \"my-project\"\n })],\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n\n devtool: \"source-map\"\n};";
|
|
94
|
+
var noSourcemapPluginsPojo = "module.exports = {\n entry: \"./src/index.js\",\n plugins: [\n new HtmlWebpackPlugin(),\n new MiniCssExtractPlugin(),\n ],\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n};";
|
|
95
|
+
var noSourcemapPluginsPojoResult = "const {\n sentryWebpackPlugin\n} = require(\"@sentry/webpack-plugin\");\n\nmodule.exports = {\n entry: \"./src/index.js\",\n\n plugins: [new HtmlWebpackPlugin(), new MiniCssExtractPlugin(), sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"my-org\",\n project: \"my-project\"\n })],\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n\n devtool: \"source-map\"\n};";
|
|
96
|
+
describe('modifyWebpackConfig', function () {
|
|
97
|
+
afterEach(function () {
|
|
98
|
+
fileContent = '';
|
|
99
|
+
jest.clearAllMocks();
|
|
100
|
+
});
|
|
101
|
+
it.each([
|
|
102
|
+
[
|
|
103
|
+
'no sourcemap option, no plugins, object',
|
|
104
|
+
noSourcemapNoPluginsPojo,
|
|
105
|
+
noSourcemapNoPluginsPojoResult,
|
|
106
|
+
],
|
|
107
|
+
[
|
|
108
|
+
'no sourcemap option, no plugins, identifier',
|
|
109
|
+
noSourcemapsNoPluginsId,
|
|
110
|
+
noSourcemapsNoPluginsIdResult,
|
|
111
|
+
],
|
|
112
|
+
[
|
|
113
|
+
'hidden sourcemap option, no plugins, identifier',
|
|
114
|
+
hiddenSourcemapNoPluginsId,
|
|
115
|
+
hiddenSourcemapNoPluginsIdResult,
|
|
116
|
+
],
|
|
117
|
+
[
|
|
118
|
+
'arbitrary sourcemap option, no plugins, identifier',
|
|
119
|
+
arbitrarySourcemapNoPluginsId,
|
|
120
|
+
arbitrarySourcemapNoPluginsIdResult,
|
|
121
|
+
],
|
|
122
|
+
[
|
|
123
|
+
'no sourcemap option, plugins, object',
|
|
124
|
+
noSourcemapUndefinedPluginsPojo,
|
|
125
|
+
noSourcemapUndefinedPluginsPojoResult,
|
|
126
|
+
],
|
|
127
|
+
[
|
|
128
|
+
'no sourcemap option, plugins, object',
|
|
129
|
+
noSourcemapPluginsPojo,
|
|
130
|
+
noSourcemapPluginsPojoResult,
|
|
131
|
+
],
|
|
132
|
+
])('adds plugin and source maps emission to the webpack config (%s)', function (_, originalCode, expectedCode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
133
|
+
var addedCode, _a, fileContent;
|
|
134
|
+
return __generator(this, function (_b) {
|
|
135
|
+
switch (_b.label) {
|
|
136
|
+
case 0:
|
|
137
|
+
updateFileContent(originalCode);
|
|
138
|
+
return [4 /*yield*/, (0, webpack_1.modifyWebpackConfig)('', {
|
|
139
|
+
authToken: '',
|
|
140
|
+
orgSlug: 'my-org',
|
|
141
|
+
projectSlug: 'my-project',
|
|
142
|
+
selfHosted: false,
|
|
143
|
+
url: 'https://sentry.io/',
|
|
144
|
+
})];
|
|
145
|
+
case 1:
|
|
146
|
+
addedCode = _b.sent();
|
|
147
|
+
expect(writeFileSpy).toHaveBeenCalledTimes(1);
|
|
148
|
+
_a = writeFileSpy.mock.calls[0], fileContent = _a[1];
|
|
149
|
+
expect(fileContent).toBe(expectedCode);
|
|
150
|
+
expect(addedCode).toBe(true);
|
|
151
|
+
return [2 /*return*/];
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}); });
|
|
155
|
+
it('adds the url parameter to the webpack plugin options if self-hosted', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
156
|
+
var addedCode, _a, fileContent;
|
|
157
|
+
return __generator(this, function (_b) {
|
|
158
|
+
switch (_b.label) {
|
|
159
|
+
case 0:
|
|
160
|
+
updateFileContent(noSourcemapNoPluginsPojo);
|
|
161
|
+
return [4 /*yield*/, (0, webpack_1.modifyWebpackConfig)('', {
|
|
162
|
+
authToken: '',
|
|
163
|
+
orgSlug: 'my-org',
|
|
164
|
+
projectSlug: 'my-project',
|
|
165
|
+
selfHosted: true,
|
|
166
|
+
url: 'https://santry.io/',
|
|
167
|
+
})];
|
|
168
|
+
case 1:
|
|
169
|
+
addedCode = _b.sent();
|
|
170
|
+
expect(writeFileSpy).toHaveBeenCalledTimes(1);
|
|
171
|
+
_a = writeFileSpy.mock.calls[0], fileContent = _a[1];
|
|
172
|
+
expect(fileContent).toContain('url: "https://santry.io/"');
|
|
173
|
+
expect(addedCode).toBe(true);
|
|
174
|
+
return [2 /*return*/];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}); });
|
|
178
|
+
});
|
|
179
|
+
//# sourceMappingURL=webpack.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webpack.test.js","sourceRoot":"","sources":["../../../../test/sourcemaps/tools/webpack.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AAEzB,iEAA4E;AAE5E,SAAS,iBAAiB,CAAC,OAAe;IACxC,WAAW,GAAG,OAAO,CAAC;AACxB,CAAC;AAED,IAAI,WAAW,GAAG,EAAE,CAAC;AAErB,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;IAC1B,OAAO;QACL,GAAG,EAAE;YACH,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;YACf,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;SACnB;QACD,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,cAAM,OAAA,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAArB,CAAqB,CAAC;QACjE,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC;KAC3C,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAI;KACD,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,UAAU,CAAC;KAC9B,kBAAkB,CAAC,cAAM,OAAA,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAA5B,CAA4B,CAAC,CAAC;AAE1D,IAAM,YAAY,GAAG,IAAI;KACtB,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC;KAC/B,kBAAkB,CAAC,cAAM,OAAA,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CA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AAQ;4BACjB,WAAW,EAAE,YAAY;4BACzB,UAAU,EAAE,KAAK;4BACjB,GAAG,EAAE,oBAAoB;yBAC1B,CAAC,EAAA;;oBANI,SAAS,GAAG,SAMhB;oBAEF,MAAM,CAAC,YAAY,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;oBACvC,KAAmB,YAAY,CAAC,IAAI,CAAC,KAAK,GAA3B,EAAZ,WAAW,QAAA,CAA6B;oBAClD,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;oBACvC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;;;SAC9B,CACF,CAAC;IAEF,EAAE,CAAC,qEAAqE,EAAE;;;;;oBACxE,iBAAiB,CAAC,wBAAwB,CAAC,CAAC;oBAE1B,qBAAM,IAAA,6BAAmB,EAAC,EAAE,EAAE;4BAC9C,SAAS,EAAE,EAAE;4BACb,OAAO,EAAE,QAAQ;4BACjB,WAAW,EAAE,YAAY;4BACzB,UAAU,EAAE,IAAI;4BAChB,GAAG,EAAE,oBAAoB;yBAC1B,CAAC,EAAA;;oBANI,SAAS,GAAG,SAMhB;oBAEF,MAAM,CAAC,YAAY,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;oBACvC,KAAmB,YAAY,CAAC,IAAI,CAAC,KAAK,GAA3B,EAAZ,WAAW,QAAA,CAA6B;oBAClD,MAAM,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC;oBAC3D,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;;;SAC9B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import * as fs from 'fs';\n\nimport { modifyWebpackConfig } from '../../../src/sourcemaps/tools/webpack';\n\nfunction updateFileContent(content: string): void {\n fileContent = content;\n}\n\nlet fileContent = '';\n\njest.mock('@clack/prompts', () => {\n return {\n log: {\n info: jest.fn(),\n success: jest.fn(),\n },\n select: jest.fn().mockImplementation(() => Promise.resolve(true)),\n isCancel: jest.fn().mockReturnValue(false),\n };\n});\n\njest\n .spyOn(fs.promises, 'readFile')\n .mockImplementation(() => Promise.resolve(fileContent));\n\nconst writeFileSpy = jest\n .spyOn(fs.promises, 'writeFile')\n .mockImplementation(() => Promise.resolve(void 0));\n\nconst noSourcemapNoPluginsPojo = `module.exports = {\n entry: \"./src/index.js\",\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n};`;\n\nconst noSourcemapNoPluginsPojoResult = `const {\n sentryWebpackPlugin\n} = require(\"@sentry/webpack-plugin\");\n\nmodule.exports = {\n entry: \"./src/index.js\",\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n\n devtool: \"source-map\",\n\n plugins: [sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"my-org\",\n project: \"my-project\"\n })]\n};`;\n\nconst noSourcemapsNoPluginsId = `const config = {\n entry: \"./src/index.js\",\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n};\n\nmodule.exports = config;`;\n\nconst noSourcemapsNoPluginsIdResult = `const {\n sentryWebpackPlugin\n} = require(\"@sentry/webpack-plugin\");\n\nconst config = {\n entry: \"./src/index.js\",\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n\n devtool: \"source-map\",\n\n plugins: [sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"my-org\",\n project: \"my-project\"\n })]\n};\n\nmodule.exports = config;`;\n\nconst hiddenSourcemapNoPluginsId = `const config = {\n entry: \"./src/index.js\",\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n\n devtool: \"hidden-cheap-source-map\",\n};\n\nmodule.exports = config;\n `;\nconst hiddenSourcemapNoPluginsIdResult = `const {\n sentryWebpackPlugin\n} = require(\"@sentry/webpack-plugin\");\n\nconst config = {\n entry: \"./src/index.js\",\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n\n devtool: \"hidden-source-map\",\n\n plugins: [sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"my-org\",\n project: \"my-project\"\n })]\n};\n\nmodule.exports = config;`;\n\nconst arbitrarySourcemapNoPluginsId = `\nconst config = {\n entry: \"./src/index.js\",\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n\n devtool: getSourcemapSetting(),\n};\n\nmodule.exports = config;\n `;\nconst arbitrarySourcemapNoPluginsIdResult = `const {\n sentryWebpackPlugin\n} = require(\"@sentry/webpack-plugin\");\n\nconst config = {\n entry: \"./src/index.js\",\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n\n devtool: \"source-map\",\n\n plugins: [sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"my-org\",\n project: \"my-project\"\n })]\n};\n\nmodule.exports = config;`;\n\nconst noSourcemapUndefinedPluginsPojo = `module.exports = {\n entry: \"./src/index.js\",\n plugins: undefined,\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n};`;\n\nconst noSourcemapUndefinedPluginsPojoResult = `const {\n sentryWebpackPlugin\n} = require(\"@sentry/webpack-plugin\");\n\nmodule.exports = {\n entry: \"./src/index.js\",\n\n plugins: [sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"my-org\",\n project: \"my-project\"\n })],\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n\n devtool: \"source-map\"\n};`;\n\nconst noSourcemapPluginsPojo = `module.exports = {\n entry: \"./src/index.js\",\n plugins: [\n new HtmlWebpackPlugin(),\n new MiniCssExtractPlugin(),\n ],\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n};`;\n\nconst noSourcemapPluginsPojoResult = `const {\n sentryWebpackPlugin\n} = require(\"@sentry/webpack-plugin\");\n\nmodule.exports = {\n entry: \"./src/index.js\",\n\n plugins: [new HtmlWebpackPlugin(), new MiniCssExtractPlugin(), sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"my-org\",\n project: \"my-project\"\n })],\n\n output: {\n filename: \"main.js\",\n path: path.resolve(__dirname, \"build\"),\n },\n\n devtool: \"source-map\"\n};`;\n\ndescribe('modifyWebpackConfig', () => {\n afterEach(() => {\n fileContent = '';\n jest.clearAllMocks();\n });\n\n it.each([\n [\n 'no sourcemap option, no plugins, object',\n noSourcemapNoPluginsPojo,\n noSourcemapNoPluginsPojoResult,\n ],\n [\n 'no sourcemap option, no plugins, identifier',\n noSourcemapsNoPluginsId,\n noSourcemapsNoPluginsIdResult,\n ],\n [\n 'hidden sourcemap option, no plugins, identifier',\n hiddenSourcemapNoPluginsId,\n hiddenSourcemapNoPluginsIdResult,\n ],\n [\n 'arbitrary sourcemap option, no plugins, identifier',\n arbitrarySourcemapNoPluginsId,\n arbitrarySourcemapNoPluginsIdResult,\n ],\n [\n 'no sourcemap option, plugins, object',\n noSourcemapUndefinedPluginsPojo,\n noSourcemapUndefinedPluginsPojoResult,\n ],\n [\n 'no sourcemap option, plugins, object',\n noSourcemapPluginsPojo,\n noSourcemapPluginsPojoResult,\n ],\n ])(\n 'adds plugin and source maps emission to the webpack config (%s)',\n async (_, originalCode, expectedCode) => {\n updateFileContent(originalCode);\n\n // updateFileContent(originalCode);\n const addedCode = await modifyWebpackConfig('', {\n authToken: '',\n orgSlug: 'my-org',\n projectSlug: 'my-project',\n selfHosted: false,\n url: 'https://sentry.io/',\n });\n\n expect(writeFileSpy).toHaveBeenCalledTimes(1);\n const [[, fileContent]] = writeFileSpy.mock.calls;\n expect(fileContent).toBe(expectedCode);\n expect(addedCode).toBe(true);\n },\n );\n\n it('adds the url parameter to the webpack plugin options if self-hosted', async () => {\n updateFileContent(noSourcemapNoPluginsPojo);\n\n const addedCode = await modifyWebpackConfig('', {\n authToken: '',\n orgSlug: 'my-org',\n projectSlug: 'my-project',\n selfHosted: true,\n url: 'https://santry.io/',\n });\n\n expect(writeFileSpy).toHaveBeenCalledTimes(1);\n const [[, fileContent]] = writeFileSpy.mock.calls;\n expect(fileContent).toContain('url: \"https://santry.io/\"');\n expect(addedCode).toBe(true);\n });\n});\n"]}
|
|
@@ -1,21 +1,187 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
//@ts-ignore
|
|
4
|
-
var magicast_1 = require("magicast");
|
|
5
26
|
var ast_utils_1 = require("../../src/utils/ast-utils");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
27
|
+
var recast = __importStar(require("recast"));
|
|
28
|
+
var b = recast.types.builders;
|
|
29
|
+
describe('hasSentryContent', function () {
|
|
30
|
+
it.each([
|
|
31
|
+
"\n const { sentryVitePlugin } = require(\"@sentry/vite-plugin\");\n const somethingelse = require('gs');\n ",
|
|
32
|
+
"\n import { sentryVitePlugin } from \"@sentry/vite-plugin\";\n import * as somethingelse from 'gs';\n\n export default {\n plugins: [sentryVitePlugin()]\n }\n ",
|
|
33
|
+
])("returns true if a require('@sentry/') call was found in the parsed module", function (code) {
|
|
34
|
+
// recast.parse returns a Program node (or fails) but it's badly typed as any
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
36
|
+
var program = recast.parse(code)
|
|
37
|
+
.program;
|
|
38
|
+
expect((0, ast_utils_1.hasSentryContent)(program)).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
it.each([
|
|
41
|
+
"const whatever = require('something')",
|
|
42
|
+
"// const {sentryWebpackPlugin} = require('@sentry/webpack-plugin')",
|
|
43
|
+
"const {sAntryWebpackPlugin} = require('webpack-plugin-@sentry')",
|
|
44
|
+
"\n import * as somethingelse from 'gs';\n export default {\n plugins: []\n }\n ",
|
|
45
|
+
"import * as somethingelse from 'gs';\n // import { sentryVitePlugin } from \"@sentry/vite-plugin\"\n export default {\n plugins: []\n }\n ",
|
|
46
|
+
"import * as thirdPartyVitePlugin from \"vite-plugin-@sentry\"\n export default {\n plugins: [thirdPartyVitePlugin()]\n }\n ",
|
|
47
|
+
])("returns false if the file doesn't contain any require('@sentry/') calls", function (code) {
|
|
48
|
+
// recast.parse returns a Program node (or fails) but it's badly typed as any
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
50
|
+
var program = recast.parse(code)
|
|
51
|
+
.program;
|
|
52
|
+
expect((0, ast_utils_1.hasSentryContent)(program)).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
describe('getObjectProperty', function () {
|
|
56
|
+
it.each([
|
|
57
|
+
[
|
|
58
|
+
'literal',
|
|
59
|
+
b.objectExpression([
|
|
60
|
+
b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
|
|
61
|
+
b.objectProperty(b.stringLiteral('needle'), b.stringLiteral('haystack')),
|
|
62
|
+
]),
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
'stringLiteral',
|
|
66
|
+
b.objectExpression([
|
|
67
|
+
b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
|
|
68
|
+
b.objectProperty(b.literal('needle'), b.stringLiteral('haystack')),
|
|
69
|
+
]),
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
'identifier',
|
|
73
|
+
b.objectExpression([
|
|
74
|
+
b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
|
|
75
|
+
b.objectProperty(b.identifier('needle'), b.stringLiteral('haystack')),
|
|
76
|
+
]),
|
|
77
|
+
],
|
|
78
|
+
])('returns the poperty (%s) if it exists', function (_, object) {
|
|
79
|
+
var property = (0, ast_utils_1.getObjectProperty)(object, 'needle');
|
|
80
|
+
expect(property).toBeDefined();
|
|
81
|
+
// @ts-expect-error we know it's defined due to the expect above
|
|
82
|
+
expect(recast.print(property).code).toEqual(expect.stringContaining('needle'));
|
|
83
|
+
});
|
|
84
|
+
it('returns undefined if the property does not exist', function () {
|
|
85
|
+
var object = b.objectExpression([
|
|
86
|
+
b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
|
|
87
|
+
]);
|
|
88
|
+
var property = (0, ast_utils_1.getObjectProperty)(object, 'needle');
|
|
89
|
+
expect(property).toBeUndefined();
|
|
90
|
+
});
|
|
91
|
+
it('handles objects without simple properties', function () {
|
|
92
|
+
var object = b.objectExpression([b.spreadElement(b.identifier('foo'))]);
|
|
93
|
+
var property = (0, ast_utils_1.getObjectProperty)(object, 'needle');
|
|
94
|
+
expect(property).toBeUndefined();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
describe('getOrSetObjectProperty', function () {
|
|
98
|
+
it('returns the property if it exists', function () {
|
|
99
|
+
var object = b.objectExpression([
|
|
100
|
+
b.objectProperty(b.identifier('needle'), b.stringLiteral('haystack')),
|
|
101
|
+
]);
|
|
102
|
+
var property = (0, ast_utils_1.getOrSetObjectProperty)(object, 'needle', b.stringLiteral('nope'));
|
|
103
|
+
expect(property).toBeDefined();
|
|
104
|
+
expect(property.type).toBe('ObjectProperty');
|
|
105
|
+
// @ts-expect-error we know its type
|
|
106
|
+
expect(property.key.name).toBe('needle');
|
|
107
|
+
// @ts-expect-error we know its type
|
|
108
|
+
expect(property.value.value).toBe('haystack');
|
|
109
|
+
});
|
|
110
|
+
it('adds the property if it does not exist', function () {
|
|
111
|
+
var object = b.objectExpression([
|
|
112
|
+
b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
|
|
113
|
+
]);
|
|
114
|
+
var property = (0, ast_utils_1.getOrSetObjectProperty)(object, 'needle', b.stringLiteral('haystack'));
|
|
115
|
+
expect(property).toBeDefined();
|
|
116
|
+
expect(property.type).toBe('Property');
|
|
117
|
+
// @ts-expect-error we know its type
|
|
118
|
+
expect(property.key.value).toBe('needle');
|
|
119
|
+
// @ts-expect-error we know its type
|
|
120
|
+
expect(property.value.value).toBe('haystack');
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
describe('setOrUpdateObjectProperty', function () {
|
|
124
|
+
it('sets a new property if it does not exist yet', function () {
|
|
125
|
+
var object = b.objectExpression([
|
|
126
|
+
b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
|
|
127
|
+
]);
|
|
128
|
+
(0, ast_utils_1.setOrUpdateObjectProperty)(object, 'needle', b.stringLiteral('haystack'));
|
|
129
|
+
expect((0, ast_utils_1.getObjectProperty)(object, 'needle')).toBeDefined();
|
|
130
|
+
});
|
|
131
|
+
it('updates an existing property if it exists', function () {
|
|
132
|
+
var object = b.objectExpression([
|
|
133
|
+
b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
|
|
134
|
+
b.objectProperty(b.identifier('needle'), b.stringLiteral('haystack')),
|
|
135
|
+
]);
|
|
136
|
+
(0, ast_utils_1.setOrUpdateObjectProperty)(object, 'needle', b.stringLiteral('haystack2'));
|
|
137
|
+
var property = (0, ast_utils_1.getObjectProperty)(object, 'needle');
|
|
138
|
+
// @ts-expect-error it must be defiend, otherwise we fail anyway
|
|
139
|
+
expect(property === null || property === void 0 ? void 0 : property.value.value).toBe('haystack2');
|
|
140
|
+
});
|
|
141
|
+
it('adds a comment to the existing property if provided', function () {
|
|
142
|
+
var object = b.objectExpression([
|
|
143
|
+
b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
|
|
144
|
+
]);
|
|
145
|
+
(0, ast_utils_1.setOrUpdateObjectProperty)(object, 'needle', b.stringLiteral('haystack'), 'This is a comment');
|
|
146
|
+
var property = (0, ast_utils_1.getObjectProperty)(object, 'needle');
|
|
147
|
+
expect(property === null || property === void 0 ? void 0 : property.comments).toHaveLength(1);
|
|
148
|
+
// @ts-expect-error it must be defiend, otherwise we fail anyway
|
|
149
|
+
expect(property === null || property === void 0 ? void 0 : property.comments[0].value).toBe(' This is a comment');
|
|
150
|
+
});
|
|
151
|
+
it('adds a comment to the new property if provided', function () {
|
|
152
|
+
var object = b.objectExpression([
|
|
153
|
+
b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
|
|
154
|
+
]);
|
|
155
|
+
(0, ast_utils_1.setOrUpdateObjectProperty)(object, 'needle', b.stringLiteral('haystack'), 'This is a comment');
|
|
156
|
+
var property = (0, ast_utils_1.getObjectProperty)(object, 'needle');
|
|
157
|
+
expect(property === null || property === void 0 ? void 0 : property.comments).toHaveLength(1);
|
|
158
|
+
// @ts-expect-error it must be defiend, otherwise we fail anyway
|
|
159
|
+
expect(property === null || property === void 0 ? void 0 : property.comments[0].value).toBe(' This is a comment');
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
describe('parse and print JSON-C', function () {
|
|
163
|
+
it.each([
|
|
164
|
+
['simple JSON', "{'foo': 'bar'}"],
|
|
165
|
+
[
|
|
166
|
+
'JSON-C with inline comment',
|
|
167
|
+
"\n {\n \"foo\": \"bar\" // with an inline comment\n }\n ",
|
|
168
|
+
],
|
|
169
|
+
[
|
|
170
|
+
'JSON-C with multiple comments',
|
|
171
|
+
"\n /*\n * let's throw in a block comment for good measure\n */ \n {\n // one line comment\n \"foo\": \"bar\", // another inline comment\n /* one more here */\n \"dogs\": /* and here */ \"awesome\",\n }\n /* and here */\n ",
|
|
172
|
+
],
|
|
173
|
+
])("parses and prints JSON-C (%s)", function (_, json) {
|
|
174
|
+
var _a = (0, ast_utils_1.parseJsonC)(json), ast = _a.ast, jsonObject = _a.jsonObject;
|
|
175
|
+
expect(ast === null || ast === void 0 ? void 0 : ast.type).toBe('Program');
|
|
176
|
+
expect(jsonObject).toBeDefined();
|
|
177
|
+
expect(jsonObject === null || jsonObject === void 0 ? void 0 : jsonObject.type).toBe('ObjectExpression');
|
|
178
|
+
// @ts-expect-error we know it's defined due to the expect above
|
|
179
|
+
expect((0, ast_utils_1.printJsonC)(ast)).toEqual(json);
|
|
180
|
+
});
|
|
181
|
+
it('returns undefined if the input is not valid JSON-C', function () {
|
|
182
|
+
var _a = (0, ast_utils_1.parseJsonC)("{\n \"invalid\": // \"json\"\n }"), ast = _a.ast, jsonObject = _a.jsonObject;
|
|
183
|
+
expect(ast).toBeUndefined();
|
|
184
|
+
expect(jsonObject).toBeUndefined();
|
|
19
185
|
});
|
|
20
186
|
});
|
|
21
187
|
//# sourceMappingURL=ast-utils.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast-utils.test.js","sourceRoot":"","sources":["../../../test/utils/ast-utils.test.ts"],"names":[],"mappings":";;AAAA,YAAY;AACZ,qCAAuC;AACvC,uDAA6D;AAE7D,QAAQ,CAAC,WAAW,EAAE;IACpB,QAAQ,CAAC,kBAAkB,EAAE;QAC3B,EAAE,CAAC,oEAAoE,EAAE;YACvE,IAAM,IAAI,GAAG,6MAOZ,CAAC;YAEF,MAAM,CAAC,IAAA,4BAAgB,EAAC,IAAA,sBAAW,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,IAAI,CAAC;YACN,8GAKC;YACD,0KAKC;YACD,mJAIC;SACF,CAAC,CACA,6DAA6D,EAC7D,UAAC,IAAI;YACH,MAAM,CAAC,IAAA,4BAAgB,EAAC,IAAA,sBAAW,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1D,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["//@ts-ignore\nimport { parseModule } from 'magicast';\nimport { hasSentryContent } from '../../src/utils/ast-utils';\n\ndescribe('AST utils', () => {\n describe('hasSentryContent', () => {\n it(\"returns true if a '@sentry/' import was found in the parsed module\", () => {\n const code = `\n import { sentryVitePlugin } from \"@sentry/vite-plugin\";\n import * as somethingelse from 'gs';\n\n export default {\n plugins: [sentryVitePlugin()]\n }\n `;\n\n expect(hasSentryContent(parseModule(code))).toBe(true);\n });\n it.each([\n `\n import * as somethingelse from 'gs';\n export default {\n plugins: []\n }\n `,\n `import * as somethingelse from 'gs';\n // import { sentryVitePlugin } from \"@sentry/vite-plugin\"\n export default {\n plugins: []\n }\n `,\n `import * as thirdPartyVitePlugin from \"vite-plugin-@sentry\"\n export default {\n plugins: [thirdPartyVitePlugin()]\n }\n `,\n ])(\n \"reutrns false for modules without a valid '@sentry/' import\",\n (code) => {\n expect(hasSentryContent(parseModule(code))).toBe(false);\n },\n );\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"ast-utils.test.js","sourceRoot":"","sources":["../../../test/utils/ast-utils.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAOmC;AAEnC,6CAAiC;AACjC,IAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;AAEhC,QAAQ,CAAC,kBAAkB,EAAE;IAC3B,EAAE,CAAC,IAAI,CAAC;QACN,0HAGC;QACD,6MAOG;KACJ,CAAC,CACA,2EAA2E,EAC3E,UAAC,IAAI;QACH,6EAA6E;QAC7E,sEAAsE;QACtE,IAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;aAC/B,OAA0C,CAAC;QAC9C,MAAM,CAAC,IAAA,4BAAgB,EAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC,CACF,CAAC;IAEF,EAAE,CAAC,IAAI,CAAC;QACN,uCAAuC;QACvC,oEAAoE;QACpE,iEAAiE;QACjE,8GAKG;QACH,0KAKG;QACH,mJAIG;KACJ,CAAC,CACA,yEAAyE,EACzE,UAAC,IAAI;QACH,6EAA6E;QAC7E,sEAAsE;QACtE,IAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;aAC/B,OAA0C,CAAC;QAC9C,MAAM,CAAC,IAAA,4BAAgB,EAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,mBAAmB,EAAE;IAC5B,EAAE,CAAC,IAAI,CAAC;QACN;YACE,SAAS;YACT,CAAC,CAAC,gBAAgB,CAAC;gBACjB,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,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,gBAAqB,CAAC;QAC7C,MAAM,CAAC,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAClC,MAAM,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;QACjC,MAAM,CAAC,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAClD,gEAAgE;QAChE,MAAM,CAAC,IAAA,sBAAU,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oDAAoD,EAAE;QACjD,IAAA,KAAsB,IAAA,sBAAU,EAAC,0CAErC,CAAC,EAFK,GAAG,SAAA,EAAE,UAAU,gBAEpB,CAAC;QACJ,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,EAAE,CAAC;QAC5B,MAAM,CAAC,UAAU,CAAC,CAAC,aAAa,EAAE,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import {\n getObjectProperty,\n getOrSetObjectProperty,\n hasSentryContent,\n parseJsonC,\n printJsonC,\n setOrUpdateObjectProperty,\n} from '../../src/utils/ast-utils';\n\nimport * as recast from 'recast';\nconst b = recast.types.builders;\n\ndescribe('hasSentryContent', () => {\n it.each([\n `\n const { sentryVitePlugin } = require(\"@sentry/vite-plugin\");\n const somethingelse = require('gs');\n `,\n `\n import { sentryVitePlugin } from \"@sentry/vite-plugin\";\n import * as somethingelse from 'gs';\n\n export default {\n plugins: [sentryVitePlugin()]\n }\n `,\n ])(\n \"returns true if a require('@sentry/') call was found in the parsed module\",\n (code) => {\n // recast.parse returns a Program node (or fails) but it's badly typed as any\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const program = recast.parse(code)\n .program as recast.types.namedTypes.Program;\n expect(hasSentryContent(program)).toBe(true);\n },\n );\n\n it.each([\n `const whatever = require('something')`,\n `// const {sentryWebpackPlugin} = require('@sentry/webpack-plugin')`,\n `const {sAntryWebpackPlugin} = require('webpack-plugin-@sentry')`,\n `\n import * as somethingelse from 'gs';\n export default {\n plugins: []\n }\n `,\n `import * as somethingelse from 'gs';\n // import { sentryVitePlugin } from \"@sentry/vite-plugin\"\n export default {\n plugins: []\n }\n `,\n `import * as thirdPartyVitePlugin from \"vite-plugin-@sentry\"\n export default {\n plugins: [thirdPartyVitePlugin()]\n }\n `,\n ])(\n \"returns false if the file doesn't contain any require('@sentry/') calls\",\n (code) => {\n // recast.parse returns a Program node (or fails) but it's badly typed as any\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const program = recast.parse(code)\n .program as recast.types.namedTypes.Program;\n expect(hasSentryContent(program)).toBe(false);\n },\n );\n});\n\ndescribe('getObjectProperty', () => {\n it.each([\n [\n 'literal',\n b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n b.objectProperty(\n b.stringLiteral('needle'),\n b.stringLiteral('haystack'),\n ),\n ]),\n ],\n [\n 'stringLiteral',\n b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n b.objectProperty(b.literal('needle'), b.stringLiteral('haystack')),\n ]),\n ],\n [\n 'identifier',\n b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n b.objectProperty(b.identifier('needle'), b.stringLiteral('haystack')),\n ]),\n ],\n ])('returns the poperty (%s) if it exists', (_, object) => {\n const property = getObjectProperty(object, 'needle');\n expect(property).toBeDefined();\n // @ts-expect-error we know it's defined due to the expect above\n expect(recast.print(property).code).toEqual(\n expect.stringContaining('needle'),\n );\n });\n\n it('returns undefined if the property does not exist', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n ]);\n const property = getObjectProperty(object, 'needle');\n expect(property).toBeUndefined();\n });\n\n it('handles objects without simple properties', () => {\n const object = b.objectExpression([b.spreadElement(b.identifier('foo'))]);\n const property = getObjectProperty(object, 'needle');\n expect(property).toBeUndefined();\n });\n});\n\ndescribe('getOrSetObjectProperty', () => {\n it('returns the property if it exists', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('needle'), b.stringLiteral('haystack')),\n ]);\n\n const property = getOrSetObjectProperty(\n object,\n 'needle',\n b.stringLiteral('nope'),\n );\n\n expect(property).toBeDefined();\n expect(property.type).toBe('ObjectProperty');\n // @ts-expect-error we know its type\n expect(property.key.name).toBe('needle');\n // @ts-expect-error we know its type\n expect(property.value.value).toBe('haystack');\n });\n\n it('adds the property if it does not exist', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n ]);\n\n const property = getOrSetObjectProperty(\n object,\n 'needle',\n b.stringLiteral('haystack'),\n );\n\n expect(property).toBeDefined();\n expect(property.type).toBe('Property');\n // @ts-expect-error we know its type\n expect(property.key.value).toBe('needle');\n // @ts-expect-error we know its type\n expect(property.value.value).toBe('haystack');\n });\n});\n\ndescribe('setOrUpdateObjectProperty', () => {\n it('sets a new property if it does not exist yet', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n ]);\n\n setOrUpdateObjectProperty(object, 'needle', b.stringLiteral('haystack'));\n\n expect(getObjectProperty(object, 'needle')).toBeDefined();\n });\n\n it('updates an existing property if it exists', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n b.objectProperty(b.identifier('needle'), b.stringLiteral('haystack')),\n ]);\n\n setOrUpdateObjectProperty(object, 'needle', b.stringLiteral('haystack2'));\n\n const property = getObjectProperty(object, 'needle');\n // @ts-expect-error it must be defiend, otherwise we fail anyway\n expect(property?.value.value).toBe('haystack2');\n });\n\n it('adds a comment to the existing property if provided', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n ]);\n\n setOrUpdateObjectProperty(\n object,\n 'needle',\n b.stringLiteral('haystack'),\n 'This is a comment',\n );\n\n const property = getObjectProperty(object, 'needle');\n expect(property?.comments).toHaveLength(1);\n // @ts-expect-error it must be defiend, otherwise we fail anyway\n expect(property?.comments[0].value).toBe(' This is a comment');\n });\n\n it('adds a comment to the new property if provided', () => {\n const object = b.objectExpression([\n b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),\n ]);\n\n setOrUpdateObjectProperty(\n object,\n 'needle',\n b.stringLiteral('haystack'),\n 'This is a comment',\n );\n\n const property = getObjectProperty(object, 'needle');\n expect(property?.comments).toHaveLength(1);\n // @ts-expect-error it must be defiend, otherwise we fail anyway\n expect(property?.comments[0].value).toBe(' This is a comment');\n });\n});\n\ndescribe('parse and print JSON-C', () => {\n it.each([\n ['simple JSON', \"{'foo': 'bar'}\"],\n [\n 'JSON-C with inline comment',\n `\n {\n \"foo\": \"bar\" // with an inline comment\n }\n `,\n ],\n [\n 'JSON-C with multiple comments',\n `\n /*\n * let's throw in a block comment for good measure\n */ \n {\n // one line comment\n \"foo\": \"bar\", // another inline comment\n /* one more here */\n \"dogs\": /* and here */ \"awesome\",\n }\n /* and here */\n `,\n ],\n ])(`parses and prints JSON-C (%s)`, (_, json) => {\n const { ast, jsonObject } = parseJsonC(json);\n expect(ast?.type).toBe('Program');\n expect(jsonObject).toBeDefined();\n expect(jsonObject?.type).toBe('ObjectExpression');\n // @ts-expect-error we know it's defined due to the expect above\n expect(printJsonC(ast)).toEqual(json);\n });\n\n it('returns undefined if the input is not valid JSON-C', () => {\n const { ast, jsonObject } = parseJsonC(`{\n \"invalid\": // \"json\"\n }`);\n expect(ast).toBeUndefined();\n expect(jsonObject).toBeUndefined();\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|