@sentry/wizard 3.10.0 → 3.12.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.
Files changed (150) hide show
  1. package/CHANGELOG.md +54 -7
  2. package/dist/lib/Constants.d.ts +1 -0
  3. package/dist/lib/Constants.js +5 -0
  4. package/dist/lib/Constants.js.map +1 -1
  5. package/dist/lib/Steps/ChooseIntegration.js +8 -4
  6. package/dist/lib/Steps/ChooseIntegration.js.map +1 -1
  7. package/dist/lib/Steps/Integrations/Android.d.ts +9 -0
  8. package/dist/lib/Steps/Integrations/Android.js +86 -0
  9. package/dist/lib/Steps/Integrations/Android.js.map +1 -0
  10. package/dist/lib/Steps/Integrations/ReactNative.js +3 -3
  11. package/dist/lib/Steps/Integrations/ReactNative.js.map +1 -1
  12. package/dist/lib/Steps/PromptForParameters.js +36 -3
  13. package/dist/lib/Steps/PromptForParameters.js.map +1 -1
  14. package/dist/lib/Steps/SentryProjectSelector.js +1 -1
  15. package/dist/lib/Steps/SentryProjectSelector.js.map +1 -1
  16. package/dist/package.json +4 -3
  17. package/dist/src/android/android-wizard.d.ts +2 -0
  18. package/dist/src/android/android-wizard.js +225 -0
  19. package/dist/src/android/android-wizard.js.map +1 -0
  20. package/dist/src/android/code-tools.d.ts +47 -0
  21. package/dist/src/android/code-tools.js +173 -0
  22. package/dist/src/android/code-tools.js.map +1 -0
  23. package/dist/src/android/gradle.d.ts +62 -0
  24. package/dist/src/android/gradle.js +286 -0
  25. package/dist/src/android/gradle.js.map +1 -0
  26. package/dist/src/android/manifest.d.ts +57 -0
  27. package/dist/src/android/manifest.js +183 -0
  28. package/dist/src/android/manifest.js.map +1 -0
  29. package/dist/src/android/templates.d.ts +11 -0
  30. package/dist/src/android/templates.js +34 -0
  31. package/dist/src/android/templates.js.map +1 -0
  32. package/dist/src/apple/apple-wizard.js +123 -64
  33. package/dist/src/apple/apple-wizard.js.map +1 -1
  34. package/dist/src/apple/cocoapod.js +4 -3
  35. package/dist/src/apple/cocoapod.js.map +1 -1
  36. package/dist/src/apple/code-tools.d.ts +1 -1
  37. package/dist/src/apple/code-tools.js +43 -19
  38. package/dist/src/apple/code-tools.js.map +1 -1
  39. package/dist/src/apple/fastlane.d.ts +1 -1
  40. package/dist/src/apple/fastlane.js +12 -6
  41. package/dist/src/apple/fastlane.js.map +1 -1
  42. package/dist/src/apple/templates.d.ts +2 -2
  43. package/dist/src/apple/templates.js +4 -4
  44. package/dist/src/apple/templates.js.map +1 -1
  45. package/dist/src/apple/xcode-manager.d.ts +19 -3
  46. package/dist/src/apple/xcode-manager.js +126 -24
  47. package/dist/src/apple/xcode-manager.js.map +1 -1
  48. package/dist/src/nextjs/nextjs-wizard.js +49 -11
  49. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  50. package/dist/src/nextjs/templates.d.ts +2 -0
  51. package/dist/src/nextjs/templates.js +6 -2
  52. package/dist/src/nextjs/templates.js.map +1 -1
  53. package/dist/src/remix/remix-wizard.js +10 -20
  54. package/dist/src/remix/remix-wizard.js.map +1 -1
  55. package/dist/src/sourcemaps/sourcemaps-wizard.js +26 -13
  56. package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
  57. package/dist/src/sourcemaps/tools/nextjs.js +1 -1
  58. package/dist/src/sourcemaps/tools/nextjs.js.map +1 -1
  59. package/dist/src/sourcemaps/tools/sentry-cli.js +19 -16
  60. package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
  61. package/dist/src/sourcemaps/tools/vite.d.ts +2 -1
  62. package/dist/src/sourcemaps/tools/vite.js +123 -111
  63. package/dist/src/sourcemaps/tools/vite.js.map +1 -1
  64. package/dist/src/sourcemaps/tools/webpack.d.ts +6 -1
  65. package/dist/src/sourcemaps/tools/webpack.js +290 -25
  66. package/dist/src/sourcemaps/tools/webpack.js.map +1 -1
  67. package/dist/src/sourcemaps/utils/detect-tool.d.ts +1 -1
  68. package/dist/src/sourcemaps/utils/detect-tool.js.map +1 -1
  69. package/dist/src/sveltekit/sdk-setup.js +5 -5
  70. package/dist/src/sveltekit/sdk-setup.js.map +1 -1
  71. package/dist/src/sveltekit/sveltekit-wizard.js +34 -44
  72. package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
  73. package/dist/src/telemetry.js +1 -0
  74. package/dist/src/telemetry.js.map +1 -1
  75. package/dist/src/utils/ast-utils.d.ts +9 -5
  76. package/dist/src/utils/ast-utils.js +26 -11
  77. package/dist/src/utils/ast-utils.js.map +1 -1
  78. package/dist/src/utils/clack-utils.d.ts +74 -28
  79. package/dist/src/utils/clack-utils.js +427 -264
  80. package/dist/src/utils/clack-utils.js.map +1 -1
  81. package/dist/src/utils/package-manager.d.ts +10 -0
  82. package/dist/{lib/Helper/PackageManager.js → src/utils/package-manager.js} +42 -74
  83. package/dist/src/utils/package-manager.js.map +1 -0
  84. package/dist/src/utils/release-registry.d.ts +1 -0
  85. package/dist/src/utils/release-registry.js +68 -0
  86. package/dist/src/utils/release-registry.js.map +1 -0
  87. package/dist/src/utils/sentrycli-utils.d.ts +4 -0
  88. package/dist/src/utils/sentrycli-utils.js +41 -0
  89. package/dist/src/utils/sentrycli-utils.js.map +1 -0
  90. package/dist/test/android/code-tools.test.d.ts +1 -0
  91. package/dist/test/android/code-tools.test.js +34 -0
  92. package/dist/test/android/code-tools.test.js.map +1 -0
  93. package/dist/test/sourcemaps/tools/vite.test.d.ts +1 -0
  94. package/dist/test/sourcemaps/tools/vite.test.js +132 -0
  95. package/dist/test/sourcemaps/tools/vite.test.js.map +1 -0
  96. package/dist/test/sourcemaps/tools/webpack.test.d.ts +1 -0
  97. package/dist/test/sourcemaps/tools/webpack.test.js +179 -0
  98. package/dist/test/sourcemaps/tools/webpack.test.js.map +1 -0
  99. package/dist/test/utils/ast-utils.test.js +42 -7
  100. package/dist/test/utils/ast-utils.test.js.map +1 -1
  101. package/dist/test/utils/clack-utils.test.d.ts +1 -0
  102. package/dist/test/utils/clack-utils.test.js +200 -0
  103. package/dist/test/utils/clack-utils.test.js.map +1 -0
  104. package/lib/Constants.ts +5 -0
  105. package/lib/Steps/ChooseIntegration.ts +7 -3
  106. package/lib/Steps/Integrations/Android.ts +23 -0
  107. package/lib/Steps/Integrations/ReactNative.ts +9 -3
  108. package/lib/Steps/PromptForParameters.ts +48 -3
  109. package/lib/Steps/SentryProjectSelector.ts +3 -1
  110. package/package.json +4 -3
  111. package/src/android/android-wizard.ts +204 -0
  112. package/src/android/code-tools.ts +170 -0
  113. package/src/android/gradle.ts +250 -0
  114. package/src/android/manifest.ts +180 -0
  115. package/src/android/templates.ts +88 -0
  116. package/src/apple/apple-wizard.ts +113 -35
  117. package/src/apple/cocoapod.ts +6 -3
  118. package/src/apple/code-tools.ts +46 -18
  119. package/src/apple/fastlane.ts +6 -12
  120. package/src/apple/templates.ts +2 -8
  121. package/src/apple/xcode-manager.ts +167 -25
  122. package/src/nextjs/nextjs-wizard.ts +72 -8
  123. package/src/nextjs/templates.ts +16 -2
  124. package/src/remix/remix-wizard.ts +10 -15
  125. package/src/sourcemaps/sourcemaps-wizard.ts +19 -5
  126. package/src/sourcemaps/tools/nextjs.ts +2 -2
  127. package/src/sourcemaps/tools/sentry-cli.ts +8 -7
  128. package/src/sourcemaps/tools/vite.ts +143 -79
  129. package/src/sourcemaps/tools/webpack.ts +369 -30
  130. package/src/sourcemaps/utils/detect-tool.ts +2 -1
  131. package/src/sveltekit/sdk-setup.ts +10 -6
  132. package/src/sveltekit/sveltekit-wizard.ts +5 -14
  133. package/src/telemetry.ts +2 -0
  134. package/src/utils/ast-utils.ts +29 -11
  135. package/src/utils/clack-utils.ts +485 -283
  136. package/src/utils/package-manager.ts +61 -0
  137. package/src/utils/release-registry.ts +19 -0
  138. package/src/utils/sentrycli-utils.ts +22 -0
  139. package/test/android/code-tools.test.ts +49 -0
  140. package/test/sourcemaps/tools/vite.test.ts +149 -0
  141. package/test/sourcemaps/tools/webpack.test.ts +303 -0
  142. package/test/utils/ast-utils.test.ts +28 -9
  143. package/test/utils/clack-utils.test.ts +142 -0
  144. package/dist/lib/Helper/PackageManager.d.ts +0 -22
  145. package/dist/lib/Helper/PackageManager.js.map +0 -1
  146. package/dist/src/utils/vendor/clack-custom-select.d.ts +0 -21
  147. package/dist/src/utils/vendor/clack-custom-select.js +0 -137
  148. package/dist/src/utils/vendor/clack-custom-select.js.map +0 -1
  149. package/lib/Helper/PackageManager.ts +0 -59
  150. package/src/utils/vendor/clack-custom-select.ts +0 -160
@@ -0,0 +1,132 @@
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 vite_1 = require("../../../src/sourcemaps/tools/vite");
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
+ };
75
+ });
76
+ jest
77
+ .spyOn(fs.promises, 'readFile')
78
+ .mockImplementation(function () { return Promise.resolve(fileContent); });
79
+ var writeFileSpy = jest
80
+ .spyOn(fs.promises, 'writeFile')
81
+ .mockImplementation(function () { return Promise.resolve(void 0); });
82
+ describe('addVitePluginToConfig', function () {
83
+ afterEach(function () {
84
+ fileContent = '';
85
+ jest.clearAllMocks();
86
+ });
87
+ it.each([
88
+ [
89
+ 'no build options',
90
+ "\nexport default defineConfig({\n plugins: [\n vue(),\n ],\n})\n",
91
+ "import { sentryVitePlugin } from \"@sentry/vite-plugin\";\nexport default defineConfig({\n plugins: [vue(), sentryVitePlugin({\n org: \"my-org\",\n project: \"my-project\"\n })],\n\n build: {\n sourcemap: true\n }\n})",
92
+ ],
93
+ [
94
+ 'no build.sourcemap options',
95
+ "\nexport default defineConfig({\n plugins: [\n vue(),\n ],\n build: {\n test: 1, \n }\n})\n ",
96
+ "import { sentryVitePlugin } from \"@sentry/vite-plugin\";\nexport default defineConfig({\n plugins: [vue(), sentryVitePlugin({\n org: \"my-org\",\n project: \"my-project\"\n })],\n build: {\n test: 1,\n sourcemap: true\n }\n})",
97
+ ],
98
+ [
99
+ 'keep sourcemap: "hidden"',
100
+ "\nexport default {\n plugins: [\n vue(),\n ],\n build: {\n sourcemap: \"hidden\",\n }\n}\n ",
101
+ "import { sentryVitePlugin } from \"@sentry/vite-plugin\";\nexport default {\n plugins: [vue(), sentryVitePlugin({\n org: \"my-org\",\n project: \"my-project\"\n })],\n build: {\n sourcemap: \"hidden\",\n }\n}",
102
+ ],
103
+ [
104
+ 'rewrite sourcemap: false to true',
105
+ "\nconst cfg = {\n plugins: [\n vue(),\n ],\n build: {\n sourcemap: false,\n }\n}\n\nexport default cfg;\n ",
106
+ "import { sentryVitePlugin } from \"@sentry/vite-plugin\";\nconst cfg = {\n plugins: [vue(), sentryVitePlugin({\n org: \"my-org\",\n project: \"my-project\"\n })],\n\n build: {\n sourcemap: true,\n }\n}\n\nexport default cfg;",
107
+ ],
108
+ ])('adds the plugin and enables source maps generation (%s)', function (_, originalCode, expectedCode) { return __awaiter(void 0, void 0, void 0, function () {
109
+ var addedCode, _a, fileContent;
110
+ return __generator(this, function (_b) {
111
+ switch (_b.label) {
112
+ case 0:
113
+ updateFileContent(originalCode);
114
+ return [4 /*yield*/, (0, vite_1.addVitePluginToConfig)('', {
115
+ authToken: '',
116
+ orgSlug: 'my-org',
117
+ projectSlug: 'my-project',
118
+ selfHosted: false,
119
+ url: 'https://sentry.io/',
120
+ })];
121
+ case 1:
122
+ addedCode = _b.sent();
123
+ expect(writeFileSpy).toHaveBeenCalledTimes(1);
124
+ _a = writeFileSpy.mock.calls[0], fileContent = _a[1];
125
+ expect(fileContent).toBe(expectedCode);
126
+ expect(addedCode).toBe(true);
127
+ return [2 /*return*/];
128
+ }
129
+ });
130
+ }); });
131
+ });
132
+ //# sourceMappingURL=vite.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.test.js","sourceRoot":"","sources":["../../../../test/sourcemaps/tools/vite.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AACzB,2DAA2E;AAE3E,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,uBAAuB,EAAE;IAChC,SAAS,CAAC;QACR,WAAW,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,IAAI,CAAC;QACN;YACE,kBAAkB;YAClB,uEAML;YACK,wOAUH;SACE;QACD;YACE,4BAA4B;YAC5B,0GASH;YACG,oPAUH;SACE;QACD;YACE,0BAA0B;YAC1B,0GASD;YACC,+NASJ;SACG;QACD;YACE,kCAAkC;YAClC,2HAWC;YACD,+OAYc;SACf;KACF,CAAC,CACA,yDAAyD,EACzD,UAAO,CAAC,EAAE,YAAY,EAAE,YAAY;;;;;oBAClC,iBAAiB,CAAC,YAAY,CAAC,CAAC;oBAEd,qBAAM,IAAA,4BAAqB,EAAC,EAAE,EAAE;4BAChD,SAAS,EAAE,EAAE;4BACb,OAAO,EAAE,QAAQ;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;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import * as fs from 'fs';\nimport { addVitePluginToConfig } from '../../../src/sourcemaps/tools/vite';\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('addVitePluginToConfig', () => {\n afterEach(() => {\n fileContent = '';\n jest.clearAllMocks();\n });\n\n it.each([\n [\n 'no build options',\n `\nexport default defineConfig({\n plugins: [\n vue(),\n ],\n})\n`,\n `import { sentryVitePlugin } from \"@sentry/vite-plugin\";\nexport default defineConfig({\n plugins: [vue(), sentryVitePlugin({\n org: \"my-org\",\n project: \"my-project\"\n })],\n\n build: {\n sourcemap: true\n }\n})`,\n ],\n [\n 'no build.sourcemap options',\n `\nexport default defineConfig({\n plugins: [\n vue(),\n ],\n build: {\n test: 1, \n }\n})\n `,\n `import { sentryVitePlugin } from \"@sentry/vite-plugin\";\nexport default defineConfig({\n plugins: [vue(), sentryVitePlugin({\n org: \"my-org\",\n project: \"my-project\"\n })],\n build: {\n test: 1,\n sourcemap: true\n }\n})`,\n ],\n [\n 'keep sourcemap: \"hidden\"',\n `\nexport default {\n plugins: [\n vue(),\n ],\n build: {\n sourcemap: \"hidden\",\n }\n}\n `,\n `import { sentryVitePlugin } from \"@sentry/vite-plugin\";\nexport default {\n plugins: [vue(), sentryVitePlugin({\n org: \"my-org\",\n project: \"my-project\"\n })],\n build: {\n sourcemap: \"hidden\",\n }\n}`,\n ],\n [\n 'rewrite sourcemap: false to true',\n `\nconst cfg = {\n plugins: [\n vue(),\n ],\n build: {\n sourcemap: false,\n }\n}\n\nexport default cfg;\n `,\n `import { sentryVitePlugin } from \"@sentry/vite-plugin\";\nconst cfg = {\n plugins: [vue(), sentryVitePlugin({\n org: \"my-org\",\n project: \"my-project\"\n })],\n\n build: {\n sourcemap: true,\n }\n}\n\nexport default cfg;`,\n ],\n ])(\n 'adds the plugin and enables source maps generation (%s)',\n async (_, originalCode, expectedCode) => {\n updateFileContent(originalCode);\n\n const addedCode = await addVitePluginToConfig('', {\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"]}
@@ -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":"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","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,20 +1,55 @@
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");
27
+ var recast = __importStar(require("recast"));
6
28
  describe('AST utils', function () {
7
29
  describe('hasSentryContent', function () {
8
- it("returns true if a '@sentry/' import was found in the parsed module", function () {
9
- var code = "\n import { sentryVitePlugin } from \"@sentry/vite-plugin\";\n import * as somethingelse from 'gs';\n\n export default {\n plugins: [sentryVitePlugin()]\n }\n ";
10
- expect((0, ast_utils_1.hasSentryContent)((0, magicast_1.parseModule)(code))).toBe(true);
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);
11
39
  });
12
40
  it.each([
41
+ "const whatever = require('something')",
42
+ "// const {sentryWebpackPlugin} = require('@sentry/webpack-plugin')",
43
+ "const {sAntryWebpackPlugin} = require('webpack-plugin-@sentry')",
13
44
  "\n import * as somethingelse from 'gs';\n export default {\n plugins: []\n }\n ",
14
45
  "import * as somethingelse from 'gs';\n // import { sentryVitePlugin } from \"@sentry/vite-plugin\"\n export default {\n plugins: []\n }\n ",
15
46
  "import * as thirdPartyVitePlugin from \"vite-plugin-@sentry\"\n export default {\n plugins: [thirdPartyVitePlugin()]\n }\n ",
16
- ])("reutrns false for modules without a valid '@sentry/' import", function (code) {
17
- expect((0, ast_utils_1.hasSentryContent)((0, magicast_1.parseModule)(code))).toBe(false);
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);
18
53
  });
19
54
  });
20
55
  });
@@ -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,uDAA6D;AAE7D,6CAAiC;AAEjC,QAAQ,CAAC,WAAW,EAAE;IACpB,QAAQ,CAAC,kBAAkB,EAAE;QAC3B,EAAE,CAAC,IAAI,CAAC;YACN,0HAGD;YACC,6MAOC;SACF,CAAC,CACA,2EAA2E,EAC3E,UAAC,IAAI;YACH,6EAA6E;YAC7E,sEAAsE;YACtE,IAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;iBAC/B,OAA0C,CAAC;YAC9C,MAAM,CAAC,IAAA,4BAAgB,EAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/C,CAAC,CACF,CAAC;QAEF,EAAE,CAAC,IAAI,CAAC;YACN,uCAAuC;YACvC,oEAAoE;YACpE,iEAAiE;YACjE,8GAKC;YACD,0KAKC;YACD,mJAIC;SACF,CAAC,CACA,yEAAyE,EACzE,UAAC,IAAI;YACH,6EAA6E;YAC7E,sEAAsE;YACtE,IAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;iBAC/B,OAA0C,CAAC;YAC9C,MAAM,CAAC,IAAA,4BAAgB,EAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { hasSentryContent } from '../../src/utils/ast-utils';\n\nimport * as recast from 'recast';\n\ndescribe('AST utils', () => {\n describe('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});\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,200 @@
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 clack_utils_1 = require("../../src/utils/clack-utils");
63
+ var fs = __importStar(require("fs"));
64
+ var clackMock;
65
+ jest.mock('@clack/prompts', function () {
66
+ clackMock = {
67
+ log: {
68
+ info: jest.fn(),
69
+ success: jest.fn(),
70
+ warn: jest.fn(),
71
+ },
72
+ text: jest.fn(),
73
+ confirm: jest.fn(),
74
+ cancel: jest.fn(),
75
+ // passthrough for abortIfCancelled
76
+ isCancel: jest.fn().mockReturnValue(false),
77
+ };
78
+ return clackMock;
79
+ });
80
+ function mockUserResponse(fn, response) {
81
+ fn.mockReturnValueOnce(response);
82
+ }
83
+ describe('askForToolConfigPath', function () {
84
+ afterEach(function () {
85
+ jest.clearAllMocks();
86
+ });
87
+ it('returns undefined if users have no config file', function () { return __awaiter(void 0, void 0, void 0, function () {
88
+ var result;
89
+ return __generator(this, function (_a) {
90
+ switch (_a.label) {
91
+ case 0:
92
+ mockUserResponse(clackMock.confirm, false);
93
+ return [4 /*yield*/, (0, clack_utils_1.askForToolConfigPath)('Webpack', 'webpack.config.js')];
94
+ case 1:
95
+ result = _a.sent();
96
+ expect(clackMock.confirm).toHaveBeenCalledWith(expect.objectContaining({
97
+ message: expect.stringContaining('have a Webpack config file'),
98
+ }));
99
+ expect(result).toBeUndefined();
100
+ return [2 /*return*/];
101
+ }
102
+ });
103
+ }); });
104
+ it('returns the path if users have a config file and the entered path is valid', function () { return __awaiter(void 0, void 0, void 0, function () {
105
+ var result;
106
+ return __generator(this, function (_a) {
107
+ switch (_a.label) {
108
+ case 0:
109
+ mockUserResponse(clackMock.confirm, true);
110
+ mockUserResponse(clackMock.text, 'my.webpack.config.js');
111
+ return [4 /*yield*/, (0, clack_utils_1.askForToolConfigPath)('Webpack', 'webpack.config.js')];
112
+ case 1:
113
+ result = _a.sent();
114
+ expect(clackMock.confirm).toHaveBeenCalledWith(expect.objectContaining({
115
+ message: expect.stringContaining('have a Webpack config file'),
116
+ }));
117
+ expect(clackMock.text).toHaveBeenCalledWith(expect.objectContaining({
118
+ message: expect.stringContaining('enter the path to your Webpack config file'),
119
+ }));
120
+ expect(result).toBe('my.webpack.config.js');
121
+ return [2 /*return*/];
122
+ }
123
+ });
124
+ }); });
125
+ });
126
+ describe('createNewConfigFile', function () {
127
+ afterEach(function () {
128
+ jest.clearAllMocks();
129
+ });
130
+ it('writes the file to disk and returns true if the file was created successfully', function () { return __awaiter(void 0, void 0, void 0, function () {
131
+ var writeFileSpy, filename, code, result;
132
+ return __generator(this, function (_a) {
133
+ switch (_a.label) {
134
+ case 0:
135
+ writeFileSpy = jest
136
+ .spyOn(fs.promises, 'writeFile')
137
+ .mockImplementation(jest.fn());
138
+ filename = '/weboack.config.js';
139
+ code = "module.exports = {/*config...*/}";
140
+ return [4 /*yield*/, (0, clack_utils_1.createNewConfigFile)(filename, code)];
141
+ case 1:
142
+ result = _a.sent();
143
+ expect(result).toBe(true);
144
+ expect(writeFileSpy).toHaveBeenCalledWith(filename, code);
145
+ return [2 /*return*/];
146
+ }
147
+ });
148
+ }); });
149
+ it('logs more information if provided as an argument', function () { return __awaiter(void 0, void 0, void 0, function () {
150
+ var filename, code, moreInfo;
151
+ return __generator(this, function (_a) {
152
+ switch (_a.label) {
153
+ case 0:
154
+ jest.spyOn(fs.promises, 'writeFile').mockImplementation(jest.fn());
155
+ filename = '/weboack.config.js';
156
+ code = "module.exports = {/*config...*/}";
157
+ moreInfo = 'More information...';
158
+ return [4 /*yield*/, (0, clack_utils_1.createNewConfigFile)(filename, code, moreInfo)];
159
+ case 1:
160
+ _a.sent();
161
+ expect(clackMock.log.info).toHaveBeenCalledTimes(1);
162
+ expect(clackMock.log.info).toHaveBeenCalledWith(expect.stringContaining(moreInfo));
163
+ return [2 /*return*/];
164
+ }
165
+ });
166
+ }); });
167
+ it('returns false and logs a warning if the file could not be created', function () { return __awaiter(void 0, void 0, void 0, function () {
168
+ var writeFileSpy, filename, code, result;
169
+ return __generator(this, function (_a) {
170
+ switch (_a.label) {
171
+ case 0:
172
+ writeFileSpy = jest
173
+ .spyOn(fs.promises, 'writeFile')
174
+ .mockImplementation(function () { return Promise.reject(new Error('Could not write')); });
175
+ filename = '/webpack.config.js';
176
+ code = "module.exports = {/*config...*/}";
177
+ return [4 /*yield*/, (0, clack_utils_1.createNewConfigFile)(filename, code)];
178
+ case 1:
179
+ result = _a.sent();
180
+ expect(result).toBe(false);
181
+ expect(writeFileSpy).toHaveBeenCalledWith(filename, code);
182
+ expect(clackMock.log.warn).toHaveBeenCalledTimes(1);
183
+ return [2 /*return*/];
184
+ }
185
+ });
186
+ }); });
187
+ it('returns false if the passed path is not absolute', function () { return __awaiter(void 0, void 0, void 0, function () {
188
+ var result;
189
+ return __generator(this, function (_a) {
190
+ switch (_a.label) {
191
+ case 0: return [4 /*yield*/, (0, clack_utils_1.createNewConfigFile)('./relative/webpack.config.js', '')];
192
+ case 1:
193
+ result = _a.sent();
194
+ expect(result).toBe(false);
195
+ return [2 /*return*/];
196
+ }
197
+ });
198
+ }); });
199
+ });
200
+ //# sourceMappingURL=clack-utils.test.js.map