@openrewrite/rewrite 8.68.0-20251204-054843 → 8.68.0-20251204-145030

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 (76) hide show
  1. package/dist/index.d.ts.map +1 -1
  2. package/dist/index.js +4 -0
  3. package/dist/index.js.map +1 -1
  4. package/dist/javascript/index.d.ts +3 -0
  5. package/dist/javascript/index.d.ts.map +1 -1
  6. package/dist/javascript/index.js +3 -0
  7. package/dist/javascript/index.js.map +1 -1
  8. package/dist/javascript/package-json-parser.d.ts +0 -5
  9. package/dist/javascript/package-json-parser.d.ts.map +1 -1
  10. package/dist/javascript/package-json-parser.js +13 -25
  11. package/dist/javascript/package-json-parser.js.map +1 -1
  12. package/dist/javascript/package-manager.d.ts +131 -0
  13. package/dist/javascript/package-manager.d.ts.map +1 -0
  14. package/dist/javascript/package-manager.js +372 -0
  15. package/dist/javascript/package-manager.js.map +1 -0
  16. package/dist/javascript/recipes/index.d.ts +2 -0
  17. package/dist/javascript/recipes/index.d.ts.map +1 -0
  18. package/dist/javascript/recipes/index.js +33 -0
  19. package/dist/javascript/recipes/index.js.map +1 -0
  20. package/dist/javascript/recipes/upgrade-dependency-version.d.ts +105 -0
  21. package/dist/javascript/recipes/upgrade-dependency-version.d.ts.map +1 -0
  22. package/dist/javascript/recipes/upgrade-dependency-version.js +493 -0
  23. package/dist/javascript/recipes/upgrade-dependency-version.js.map +1 -0
  24. package/dist/javascript/search/find-dependency.d.ts +32 -0
  25. package/dist/javascript/search/find-dependency.d.ts.map +1 -0
  26. package/dist/javascript/search/find-dependency.js +312 -0
  27. package/dist/javascript/search/find-dependency.js.map +1 -0
  28. package/dist/javascript/search/index.d.ts +1 -0
  29. package/dist/javascript/search/index.d.ts.map +1 -1
  30. package/dist/javascript/search/index.js +1 -0
  31. package/dist/javascript/search/index.js.map +1 -1
  32. package/dist/json/print.js +1 -1
  33. package/dist/json/print.js.map +1 -1
  34. package/dist/markers.d.ts +67 -0
  35. package/dist/markers.d.ts.map +1 -1
  36. package/dist/markers.js +101 -0
  37. package/dist/markers.js.map +1 -1
  38. package/dist/print.d.ts.map +1 -1
  39. package/dist/print.js +0 -1
  40. package/dist/print.js.map +1 -1
  41. package/dist/recipe.js +3 -3
  42. package/dist/recipe.js.map +1 -1
  43. package/dist/rpc/index.js +72 -0
  44. package/dist/rpc/index.js.map +1 -1
  45. package/dist/rpc/request/generate.js +1 -1
  46. package/dist/rpc/request/generate.js.map +1 -1
  47. package/dist/rpc/request/get-languages.d.ts.map +1 -1
  48. package/dist/rpc/request/get-languages.js +2 -1
  49. package/dist/rpc/request/get-languages.js.map +1 -1
  50. package/dist/rpc/request/visit.d.ts.map +1 -1
  51. package/dist/rpc/request/visit.js +27 -0
  52. package/dist/rpc/request/visit.js.map +1 -1
  53. package/dist/run.js +2 -2
  54. package/dist/run.js.map +1 -1
  55. package/dist/test/rewrite-test.js +1 -1
  56. package/dist/test/rewrite-test.js.map +1 -1
  57. package/dist/version.txt +1 -1
  58. package/package.json +1 -1
  59. package/src/index.ts +4 -0
  60. package/src/javascript/index.ts +3 -0
  61. package/src/javascript/package-json-parser.ts +14 -33
  62. package/src/javascript/package-manager.ts +428 -0
  63. package/src/javascript/recipes/index.ts +17 -0
  64. package/src/javascript/recipes/upgrade-dependency-version.ts +586 -0
  65. package/src/javascript/search/find-dependency.ts +303 -0
  66. package/src/javascript/search/index.ts +1 -0
  67. package/src/json/print.ts +1 -1
  68. package/src/markers.ts +146 -0
  69. package/src/print.ts +0 -1
  70. package/src/recipe.ts +3 -3
  71. package/src/rpc/index.ts +65 -1
  72. package/src/rpc/request/generate.ts +1 -1
  73. package/src/rpc/request/get-languages.ts +2 -1
  74. package/src/rpc/request/visit.ts +32 -1
  75. package/src/run.ts +2 -2
  76. package/src/test/rewrite-test.ts +1 -1
@@ -0,0 +1,493 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2025 the original author or authors.
4
+ * <p>
5
+ * Licensed under the Moderne Source Available License (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ * <p>
9
+ * https://docs.moderne.io/licensing/moderne-source-available-license
10
+ * <p>
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
34
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
35
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
36
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
37
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
38
+ };
39
+ var __importStar = (this && this.__importStar) || (function () {
40
+ var ownKeys = function(o) {
41
+ ownKeys = Object.getOwnPropertyNames || function (o) {
42
+ var ar = [];
43
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
44
+ return ar;
45
+ };
46
+ return ownKeys(o);
47
+ };
48
+ return function (mod) {
49
+ if (mod && mod.__esModule) return mod;
50
+ var result = {};
51
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
52
+ __setModuleDefault(result, mod);
53
+ return result;
54
+ };
55
+ })();
56
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
57
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
58
+ return new (P || (P = Promise))(function (resolve, reject) {
59
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
60
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
61
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
62
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
63
+ });
64
+ };
65
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
66
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
67
+ var m = o[Symbol.asyncIterator], i;
68
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
69
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
70
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
71
+ };
72
+ Object.defineProperty(exports, "__esModule", { value: true });
73
+ exports.UpgradeDependencyVersion = void 0;
74
+ const recipe_1 = require("../../recipe");
75
+ const json_1 = require("../../json");
76
+ const node_resolution_result_1 = require("../node-resolution-result");
77
+ const fs = __importStar(require("fs"));
78
+ const fsp = __importStar(require("fs/promises"));
79
+ const path = __importStar(require("path"));
80
+ const os = __importStar(require("os"));
81
+ const semver = __importStar(require("semver"));
82
+ const markers_1 = require("../../markers");
83
+ const print_1 = require("../../print");
84
+ const package_manager_1 = require("../package-manager");
85
+ /**
86
+ * Upgrades the version of a dependency in package.json and updates the lock file.
87
+ *
88
+ * This recipe:
89
+ * 1. Finds package.json files containing the specified dependency
90
+ * 2. Updates the version constraint to the new version
91
+ * 3. Runs the package manager to update the lock file
92
+ * 4. Updates the NodeResolutionResult marker with new dependency info
93
+ *
94
+ * TODO: Consider adding a `resolveToLatestMatching` option that would use `npm install <pkg>@<version>`
95
+ * to let the package manager resolve the constraint to the latest matching version.
96
+ * For example, `^22.0.0` would become `^22.19.1` (the latest version satisfying ^22.0.0).
97
+ * This would be similar to how Maven's UpgradeDependencyVersion works with version selectors.
98
+ */
99
+ class UpgradeDependencyVersion extends recipe_1.ScanningRecipe {
100
+ constructor() {
101
+ super(...arguments);
102
+ this.name = "org.openrewrite.javascript.dependencies.upgrade-dependency-version";
103
+ this.displayName = "Upgrade npm dependency version";
104
+ this.description = "Upgrades the version of a dependency in `package.json` and updates the lock file by running the package manager.";
105
+ }
106
+ initialValue(_ctx) {
107
+ return {
108
+ projectsToUpdate: new Map(),
109
+ updatedLockFiles: new Map(),
110
+ updatedPackageJsons: new Map(),
111
+ processedProjects: new Set(),
112
+ failedProjects: new Map()
113
+ };
114
+ }
115
+ /**
116
+ * Determines if the dependency should be upgraded from currentVersion to newVersion.
117
+ * Returns true only if the new version constraint represents a strictly newer version.
118
+ *
119
+ * This prevents:
120
+ * - Re-applying the same version (idempotency)
121
+ * - Downgrading to an older version
122
+ *
123
+ * @param currentVersion Current version constraint (e.g., "^4.17.20")
124
+ * @param newVersion New version constraint to apply (e.g., "^4.17.21")
125
+ * @returns true if upgrade should proceed, false otherwise
126
+ */
127
+ shouldUpgrade(currentVersion, newVersion) {
128
+ // If they're identical strings, no upgrade needed
129
+ if (currentVersion === newVersion) {
130
+ return false;
131
+ }
132
+ // Extract the minimum version from each constraint
133
+ // semver.minVersion returns the lowest version that could match the range
134
+ const currentMin = semver.minVersion(currentVersion);
135
+ const newMin = semver.minVersion(newVersion);
136
+ // If either constraint is invalid, fall back to string comparison
137
+ // (will upgrade if strings differ)
138
+ if (!currentMin || !newMin) {
139
+ return currentVersion !== newVersion;
140
+ }
141
+ // Only upgrade if new minimum version is strictly greater than current
142
+ return semver.gt(newMin, currentMin);
143
+ }
144
+ scanner(acc) {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ const recipe = this;
147
+ return new class extends json_1.JsonVisitor {
148
+ visitDocument(doc, ctx) {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ var _a, _b;
151
+ // Only process package.json files
152
+ if (!doc.sourcePath.endsWith('package.json')) {
153
+ return doc;
154
+ }
155
+ const marker = (0, node_resolution_result_1.findNodeResolutionResult)(doc);
156
+ if (!marker) {
157
+ return doc;
158
+ }
159
+ // Check each dependency scope for the target package
160
+ const scopes = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
161
+ for (const scope of scopes) {
162
+ const deps = marker[scope];
163
+ const dep = deps === null || deps === void 0 ? void 0 : deps.find(d => d.name === recipe.packageName);
164
+ if (dep) {
165
+ const currentVersion = dep.versionConstraint;
166
+ // Check if version needs updating using semver comparison
167
+ // Only upgrade if the new version is strictly newer than current
168
+ if (recipe.shouldUpgrade(currentVersion, recipe.newVersion)) {
169
+ // Get the project directory from the marker path
170
+ const projectDir = path.dirname(path.resolve(doc.sourcePath));
171
+ // Use package manager from marker (set during parsing), default to npm
172
+ const pm = (_a = marker.packageManager) !== null && _a !== void 0 ? _a : node_resolution_result_1.PackageManager.Npm;
173
+ // Check if the resolved version already satisfies the new constraint.
174
+ // If so, we can skip running the package manager entirely.
175
+ const resolvedDep = (_b = marker.resolvedDependencies) === null || _b === void 0 ? void 0 : _b.find(rd => rd.name === recipe.packageName);
176
+ const skipInstall = resolvedDep !== undefined &&
177
+ semver.satisfies(resolvedDep.version, recipe.newVersion);
178
+ acc.projectsToUpdate.set(doc.sourcePath, {
179
+ projectDir,
180
+ packageJsonPath: doc.sourcePath,
181
+ originalPackageJson: yield this.printDocument(doc),
182
+ dependencyScope: scope,
183
+ currentVersion,
184
+ newVersion: recipe.newVersion,
185
+ packageManager: pm,
186
+ skipInstall
187
+ });
188
+ }
189
+ break; // Found the dependency, no need to check other scopes
190
+ }
191
+ }
192
+ return doc;
193
+ });
194
+ }
195
+ printDocument(doc) {
196
+ return __awaiter(this, void 0, void 0, function* () {
197
+ return print_1.TreePrinters.print(doc);
198
+ });
199
+ }
200
+ };
201
+ });
202
+ }
203
+ editorWithData(acc) {
204
+ return __awaiter(this, void 0, void 0, function* () {
205
+ const recipe = this;
206
+ return new class extends json_1.JsonVisitor {
207
+ visitDocument(doc, ctx) {
208
+ return __awaiter(this, void 0, void 0, function* () {
209
+ const sourcePath = doc.sourcePath;
210
+ // Handle package.json files
211
+ if (sourcePath.endsWith('package.json')) {
212
+ const updateInfo = acc.projectsToUpdate.get(sourcePath);
213
+ if (!updateInfo) {
214
+ return doc; // This package.json doesn't need updating
215
+ }
216
+ // Run package manager install if we haven't processed this project yet
217
+ // Skip if the resolved version already satisfies the new constraint
218
+ if (!updateInfo.skipInstall && !acc.processedProjects.has(sourcePath)) {
219
+ yield recipe.runPackageManagerInstall(acc, updateInfo, ctx);
220
+ acc.processedProjects.add(sourcePath);
221
+ }
222
+ // Check if the install failed - if so, don't update, just add warning
223
+ const failureMessage = acc.failedProjects.get(sourcePath);
224
+ if (failureMessage) {
225
+ return (0, markers_1.markupWarn)(doc, `Failed to upgrade ${recipe.packageName} to ${recipe.newVersion}`, failureMessage);
226
+ }
227
+ // Update the dependency version in the JSON AST (preserves formatting)
228
+ const visitor = new UpdateVersionVisitor(recipe.packageName, updateInfo.newVersion, updateInfo.dependencyScope);
229
+ const modifiedDoc = yield visitor.visit(doc, undefined);
230
+ // Update the NodeResolutionResult marker
231
+ return recipe.updateMarker(modifiedDoc, updateInfo, acc);
232
+ }
233
+ // Handle lock files for all package managers
234
+ for (const lockFileName of (0, package_manager_1.getAllLockFileNames)()) {
235
+ if (sourcePath.endsWith(lockFileName)) {
236
+ // Find the corresponding package.json path
237
+ const packageJsonPath = sourcePath.replace(lockFileName, 'package.json');
238
+ const updateInfo = acc.projectsToUpdate.get(packageJsonPath);
239
+ if (updateInfo && acc.updatedLockFiles.has(sourcePath)) {
240
+ // Parse the updated lock file content and return it
241
+ const updatedContent = acc.updatedLockFiles.get(sourcePath);
242
+ return this.parseUpdatedLockFile(doc, updatedContent);
243
+ }
244
+ break;
245
+ }
246
+ }
247
+ return doc;
248
+ });
249
+ }
250
+ /**
251
+ * Parses updated lock file content and creates a new document.
252
+ */
253
+ parseUpdatedLockFile(originalDoc, updatedContent) {
254
+ return __awaiter(this, void 0, void 0, function* () {
255
+ var _a, e_1, _b, _c;
256
+ // Parse the updated content using JsonParser
257
+ const parser = new json_1.JsonParser({});
258
+ const parsed = [];
259
+ try {
260
+ for (var _d = true, _e = __asyncValues(parser.parse({ text: updatedContent, sourcePath: originalDoc.sourcePath })), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
261
+ _c = _f.value;
262
+ _d = false;
263
+ const sf = _c;
264
+ parsed.push(sf);
265
+ }
266
+ }
267
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
268
+ finally {
269
+ try {
270
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
271
+ }
272
+ finally { if (e_1) throw e_1.error; }
273
+ }
274
+ if (parsed.length > 0) {
275
+ // Preserve the original source path and markers
276
+ return Object.assign(Object.assign({}, parsed[0]), { sourcePath: originalDoc.sourcePath, markers: originalDoc.markers });
277
+ }
278
+ return originalDoc;
279
+ });
280
+ }
281
+ };
282
+ });
283
+ }
284
+ /**
285
+ * Runs the package manager in a temporary directory to update the lock file.
286
+ * Writes a modified package.json with the new version, then runs install to update the lock file.
287
+ */
288
+ runPackageManagerInstall(acc, updateInfo, _ctx) {
289
+ return __awaiter(this, void 0, void 0, function* () {
290
+ const pm = updateInfo.packageManager;
291
+ const lockFileName = (0, package_manager_1.getLockFileName)(pm);
292
+ // Create temp directory
293
+ const tempDir = yield fsp.mkdtemp(path.join(os.tmpdir(), 'openrewrite-pm-'));
294
+ try {
295
+ // Create modified package.json with the new version constraint
296
+ const modifiedPackageJson = this.createModifiedPackageJson(updateInfo.originalPackageJson, updateInfo.dependencyScope, updateInfo.newVersion);
297
+ // Write modified package.json to temp directory
298
+ yield fsp.writeFile(path.join(tempDir, 'package.json'), modifiedPackageJson);
299
+ // Copy existing lock file if present
300
+ const originalLockPath = path.join(updateInfo.projectDir, lockFileName);
301
+ if (fs.existsSync(originalLockPath)) {
302
+ yield fsp.copyFile(originalLockPath, path.join(tempDir, lockFileName));
303
+ }
304
+ // Copy config files if present (for registry configuration and workspace setup)
305
+ const configFiles = ['.npmrc', '.yarnrc', '.yarnrc.yml', '.pnpmfile.cjs', 'pnpm-workspace.yaml'];
306
+ for (const configFile of configFiles) {
307
+ const configPath = path.join(updateInfo.projectDir, configFile);
308
+ if (fs.existsSync(configPath)) {
309
+ yield fsp.copyFile(configPath, path.join(tempDir, configFile));
310
+ }
311
+ }
312
+ // Run package manager install to validate the version and update lock file
313
+ const result = (0, package_manager_1.runInstall)(pm, {
314
+ cwd: tempDir,
315
+ lockOnly: true,
316
+ timeout: 120000 // 2 minute timeout
317
+ });
318
+ if (result.success) {
319
+ // Store the modified package.json (we'll use our visitor for actual output)
320
+ acc.updatedPackageJsons.set(updateInfo.packageJsonPath, modifiedPackageJson);
321
+ // Read back the updated lock file
322
+ const updatedLockPath = path.join(tempDir, lockFileName);
323
+ if (fs.existsSync(updatedLockPath)) {
324
+ const updatedLockContent = yield fsp.readFile(updatedLockPath, 'utf-8');
325
+ const lockFilePath = updateInfo.packageJsonPath.replace('package.json', lockFileName);
326
+ acc.updatedLockFiles.set(lockFilePath, updatedLockContent);
327
+ }
328
+ }
329
+ else {
330
+ // Track the failure - don't update package.json, the version likely doesn't exist
331
+ const errorMessage = result.error || result.stderr || 'Unknown error';
332
+ acc.failedProjects.set(updateInfo.packageJsonPath, errorMessage);
333
+ }
334
+ }
335
+ finally {
336
+ // Cleanup temp directory
337
+ try {
338
+ yield fsp.rm(tempDir, { recursive: true, force: true });
339
+ }
340
+ catch (_a) {
341
+ // Ignore cleanup errors
342
+ }
343
+ }
344
+ });
345
+ }
346
+ /**
347
+ * Creates a modified package.json with the updated dependency version.
348
+ * Used for the temp directory to validate the version exists.
349
+ */
350
+ createModifiedPackageJson(originalContent, scope, newVersion) {
351
+ const packageJson = JSON.parse(originalContent);
352
+ if (packageJson[scope] && packageJson[scope][this.packageName]) {
353
+ packageJson[scope][this.packageName] = newVersion;
354
+ }
355
+ return JSON.stringify(packageJson, null, 2);
356
+ }
357
+ /**
358
+ * Updates the NodeResolutionResult marker with new dependency information.
359
+ */
360
+ updateMarker(doc, updateInfo, acc) {
361
+ return __awaiter(this, void 0, void 0, function* () {
362
+ const existingMarker = (0, node_resolution_result_1.findNodeResolutionResult)(doc);
363
+ if (!existingMarker) {
364
+ return doc;
365
+ }
366
+ // If we skipped install, just update the versionConstraint in the marker
367
+ // The resolved version is already correct, we only changed the constraint
368
+ if (updateInfo.skipInstall) {
369
+ return this.updateMarkerVersionConstraint(doc, existingMarker, updateInfo);
370
+ }
371
+ // Parse the updated package.json and lock file to create new marker
372
+ const updatedPackageJson = acc.updatedPackageJsons.get(updateInfo.packageJsonPath);
373
+ const lockFileName = (0, package_manager_1.getLockFileName)(updateInfo.packageManager);
374
+ const updatedLockFile = acc.updatedLockFiles.get(updateInfo.packageJsonPath.replace('package.json', lockFileName));
375
+ let packageJsonContent;
376
+ let lockContent;
377
+ try {
378
+ packageJsonContent = JSON.parse(updatedPackageJson || updateInfo.originalPackageJson);
379
+ }
380
+ catch (_a) {
381
+ return doc; // Failed to parse, keep original marker
382
+ }
383
+ if (updatedLockFile) {
384
+ try {
385
+ lockContent = JSON.parse(updatedLockFile);
386
+ }
387
+ catch (_b) {
388
+ // Continue without lock file content
389
+ }
390
+ }
391
+ // Read npmrc configs from the project directory
392
+ const npmrcConfigs = yield (0, node_resolution_result_1.readNpmrcConfigs)(updateInfo.projectDir);
393
+ // Create new marker
394
+ const newMarker = (0, node_resolution_result_1.createNodeResolutionResultMarker)(existingMarker.path, packageJsonContent, lockContent, existingMarker.workspacePackagePaths, existingMarker.packageManager, npmrcConfigs.length > 0 ? npmrcConfigs : undefined);
395
+ // Replace the marker in the document
396
+ return Object.assign(Object.assign({}, doc), { markers: (0, markers_1.replaceMarkerByKind)(doc.markers, newMarker) });
397
+ });
398
+ }
399
+ /**
400
+ * Updates just the versionConstraint in the marker for the target dependency.
401
+ * Used when skipInstall is true - the resolved version is unchanged.
402
+ */
403
+ updateMarkerVersionConstraint(doc, existingMarker, updateInfo) {
404
+ // Create updated dependency lists with the new versionConstraint
405
+ const updateDeps = (deps) => {
406
+ if (!deps)
407
+ return deps;
408
+ return deps.map(dep => {
409
+ if (dep.name === this.packageName) {
410
+ return Object.assign(Object.assign({}, dep), { versionConstraint: updateInfo.newVersion });
411
+ }
412
+ return dep;
413
+ });
414
+ };
415
+ const newMarker = Object.assign(Object.assign({}, existingMarker), { [updateInfo.dependencyScope]: updateDeps(existingMarker[updateInfo.dependencyScope]) });
416
+ return Object.assign(Object.assign({}, doc), { markers: (0, markers_1.replaceMarkerByKind)(doc.markers, newMarker) });
417
+ }
418
+ }
419
+ exports.UpgradeDependencyVersion = UpgradeDependencyVersion;
420
+ __decorate([
421
+ (0, recipe_1.Option)({
422
+ displayName: "Package name",
423
+ description: "The name of the npm package to upgrade (e.g., 'lodash', '@types/node')",
424
+ example: "lodash"
425
+ })
426
+ ], UpgradeDependencyVersion.prototype, "packageName", void 0);
427
+ __decorate([
428
+ (0, recipe_1.Option)({
429
+ displayName: "New version",
430
+ description: "The new version constraint to set (e.g., '^5.0.0', '~2.1.0', '3.0.0')",
431
+ example: "^5.0.0"
432
+ })
433
+ ], UpgradeDependencyVersion.prototype, "newVersion", void 0);
434
+ /**
435
+ * Visitor that updates the version of a specific dependency in a specific scope.
436
+ */
437
+ class UpdateVersionVisitor extends json_1.JsonVisitor {
438
+ constructor(packageName, newVersion, targetScope) {
439
+ super();
440
+ this.inTargetScope = false;
441
+ this.packageName = packageName;
442
+ this.newVersion = newVersion;
443
+ this.targetScope = targetScope;
444
+ }
445
+ visitMember(member, p) {
446
+ const _super = Object.create(null, {
447
+ visitMember: { get: () => super.visitMember }
448
+ });
449
+ return __awaiter(this, void 0, void 0, function* () {
450
+ // Check if we're entering the target scope
451
+ const keyName = this.getMemberKeyName(member);
452
+ if (keyName === this.targetScope) {
453
+ // We're entering the dependencies scope
454
+ this.inTargetScope = true;
455
+ const result = yield _super.visitMember.call(this, member, p);
456
+ this.inTargetScope = false;
457
+ return result;
458
+ }
459
+ // Check if this is the dependency we're looking for
460
+ if (this.inTargetScope && keyName === this.packageName) {
461
+ // Update the version value
462
+ return this.updateVersion(member);
463
+ }
464
+ return _super.visitMember.call(this, member, p);
465
+ });
466
+ }
467
+ getMemberKeyName(member) {
468
+ const key = member.key.element;
469
+ if (key.kind === json_1.Json.Kind.Literal) {
470
+ // Remove quotes from string literal
471
+ const source = key.source;
472
+ if (source.startsWith('"') && source.endsWith('"')) {
473
+ return source.slice(1, -1);
474
+ }
475
+ return source;
476
+ }
477
+ else if (key.kind === json_1.Json.Kind.Identifier) {
478
+ return key.name;
479
+ }
480
+ return undefined;
481
+ }
482
+ updateVersion(member) {
483
+ const value = member.value;
484
+ if (value.kind !== json_1.Json.Kind.Literal) {
485
+ return member; // Not a literal value, can't update
486
+ }
487
+ const literal = value;
488
+ // Create new literal with updated version
489
+ const newLiteral = Object.assign(Object.assign({}, literal), { source: `"${this.newVersion}"`, value: this.newVersion });
490
+ return Object.assign(Object.assign({}, member), { value: newLiteral });
491
+ }
492
+ }
493
+ //# sourceMappingURL=upgrade-dependency-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upgrade-dependency-version.js","sourceRoot":"","sources":["../../../src/javascript/recipes/upgrade-dependency-version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;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AAE,IAAI,IAAI,CAAC,UAAU,GAAG,EAC9B,KAAK,EAAE,IAAI,CAAC,UAAU,GACzB,CAAC;QAEF,uCACO,MAAM,KACT,KAAK,EAAE,UAAU,IACnB;IACN,CAAC;CACJ"}
@@ -0,0 +1,32 @@
1
+ import { Recipe } from "../../recipe";
2
+ import { ExecutionContext } from "../../execution";
3
+ import { TreeVisitor } from "../../visitor";
4
+ /**
5
+ * Finds npm/Node.js dependencies declared in package.json.
6
+ * This recipe is commonly used as a precondition to limit the scope of other recipes
7
+ * to projects that use a specific dependency.
8
+ *
9
+ * The search result marker is placed on the specific dependency entry in package.json,
10
+ * allowing users to see exactly where the dependency is declared.
11
+ *
12
+ * When `onlyDirect` is false, this recipe also marks direct dependencies that
13
+ * transitively depend on the target package, helping answer "which of my dependencies
14
+ * brings in package X?".
15
+ */
16
+ export interface FindDependencyOptions {
17
+ packageName: string;
18
+ version?: string;
19
+ onlyDirect?: boolean;
20
+ }
21
+ export declare class FindDependency extends Recipe {
22
+ readonly name = "org.openrewrite.javascript.dependencies.find-dependency";
23
+ readonly displayName = "Find Node.js dependency";
24
+ readonly description: string;
25
+ packageName: string;
26
+ version?: string;
27
+ onlyDirect?: boolean;
28
+ constructor(options: FindDependencyOptions);
29
+ instanceName(): string;
30
+ editor(): Promise<TreeVisitor<any, ExecutionContext>>;
31
+ }
32
+ //# sourceMappingURL=find-dependency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-dependency.d.ts","sourceRoot":"","sources":["../../../src/javascript/search/find-dependency.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAS,MAAM,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAoB1C;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,qBAAqB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,qBAAa,cAAe,SAAQ,MAAM;IACtC,QAAQ,CAAC,IAAI,6DAA6D;IAC1E,QAAQ,CAAC,WAAW,6BAA6B;IACjD,QAAQ,CAAC,WAAW,SAEoD;IAOxE,WAAW,EAAG,MAAM,CAAC;IASrB,OAAO,CAAC,EAAE,MAAM,CAAC;IASjB,UAAU,CAAC,EAAE,OAAO,CAAC;gBAET,OAAO,EAAE,qBAAqB;IAIjC,YAAY,IAAI,MAAM;IAIzB,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAkJ9D"}