@openrewrite/rewrite 8.68.0-20251202-044649 → 8.68.0-20251202-154952

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 (45) hide show
  1. package/dist/javascript/assertions.d.ts +1 -0
  2. package/dist/javascript/assertions.d.ts.map +1 -1
  3. package/dist/javascript/assertions.js +82 -11
  4. package/dist/javascript/assertions.js.map +1 -1
  5. package/dist/javascript/dependency-workspace.d.ts +46 -5
  6. package/dist/javascript/dependency-workspace.d.ts.map +1 -1
  7. package/dist/javascript/dependency-workspace.js +70 -35
  8. package/dist/javascript/dependency-workspace.js.map +1 -1
  9. package/dist/javascript/index.d.ts +2 -0
  10. package/dist/javascript/index.d.ts.map +1 -1
  11. package/dist/javascript/index.js +2 -0
  12. package/dist/javascript/index.js.map +1 -1
  13. package/dist/javascript/node-resolution-result.d.ts +204 -0
  14. package/dist/javascript/node-resolution-result.d.ts.map +1 -0
  15. package/dist/javascript/node-resolution-result.js +723 -0
  16. package/dist/javascript/node-resolution-result.js.map +1 -0
  17. package/dist/javascript/package-json-parser.d.ts +143 -0
  18. package/dist/javascript/package-json-parser.d.ts.map +1 -0
  19. package/dist/javascript/package-json-parser.js +773 -0
  20. package/dist/javascript/package-json-parser.js.map +1 -0
  21. package/dist/javascript/templating/engine.js +1 -1
  22. package/dist/javascript/templating/engine.js.map +1 -1
  23. package/dist/json/parser.js +10 -1
  24. package/dist/json/parser.js.map +1 -1
  25. package/dist/json/tree.d.ts +1 -1
  26. package/dist/json/tree.js +1 -1
  27. package/dist/json/tree.js.map +1 -1
  28. package/dist/parser.d.ts +1 -1
  29. package/dist/parser.d.ts.map +1 -1
  30. package/dist/rpc/request/parse.d.ts +4 -0
  31. package/dist/rpc/request/parse.d.ts.map +1 -1
  32. package/dist/rpc/request/parse.js +17 -1
  33. package/dist/rpc/request/parse.js.map +1 -1
  34. package/dist/version.txt +1 -1
  35. package/package.json +5 -2
  36. package/src/javascript/assertions.ts +73 -15
  37. package/src/javascript/dependency-workspace.ts +124 -46
  38. package/src/javascript/index.ts +2 -0
  39. package/src/javascript/node-resolution-result.ts +905 -0
  40. package/src/javascript/package-json-parser.ts +845 -0
  41. package/src/javascript/templating/engine.ts +1 -1
  42. package/src/json/parser.ts +18 -1
  43. package/src/json/tree.ts +1 -1
  44. package/src/parser.ts +1 -1
  45. package/src/rpc/request/parse.ts +20 -2
@@ -0,0 +1,204 @@
1
+ import { Marker, Markers } from "../markers";
2
+ import { UUID } from "../uuid";
3
+ export declare const NodeResolutionResultKind: "org.openrewrite.javascript.marker.NodeResolutionResult";
4
+ export declare const DependencyKind: "org.openrewrite.javascript.marker.NodeResolutionResult$Dependency";
5
+ export declare const ResolvedDependencyKind: "org.openrewrite.javascript.marker.NodeResolutionResult$ResolvedDependency";
6
+ /**
7
+ * Parsed package.json content structure.
8
+ */
9
+ export interface PackageJsonContent {
10
+ readonly name?: string;
11
+ readonly version?: string;
12
+ readonly description?: string;
13
+ readonly dependencies?: Record<string, string>;
14
+ readonly devDependencies?: Record<string, string>;
15
+ readonly peerDependencies?: Record<string, string>;
16
+ readonly optionalDependencies?: Record<string, string>;
17
+ readonly bundledDependencies?: string[];
18
+ readonly bundleDependencies?: string[];
19
+ readonly engines?: Record<string, string>;
20
+ }
21
+ /**
22
+ * Package entry in a package-lock.json packages map.
23
+ */
24
+ export interface PackageLockEntry {
25
+ readonly version?: string;
26
+ readonly resolved?: string;
27
+ readonly integrity?: string;
28
+ readonly license?: string;
29
+ readonly dependencies?: Record<string, string>;
30
+ readonly devDependencies?: Record<string, string>;
31
+ readonly peerDependencies?: Record<string, string>;
32
+ readonly optionalDependencies?: Record<string, string>;
33
+ readonly engines?: Record<string, string> | string[];
34
+ }
35
+ /**
36
+ * Parsed package-lock.json content structure (npm lockfile v3 format).
37
+ */
38
+ export interface PackageLockContent {
39
+ readonly name?: string;
40
+ readonly version?: string;
41
+ readonly lockfileVersion?: number;
42
+ readonly packages?: Record<string, PackageLockEntry>;
43
+ }
44
+ /**
45
+ * Represents the package manager used by a Node.js project.
46
+ */
47
+ export declare const enum PackageManager {
48
+ Npm = "Npm",
49
+ YarnClassic = "YarnClassic",
50
+ YarnBerry = "YarnBerry",
51
+ Pnpm = "Pnpm",
52
+ Bun = "Bun"
53
+ }
54
+ /**
55
+ * Represents the scope/source of an npmrc configuration.
56
+ * Listed from lowest to highest priority.
57
+ */
58
+ export declare const enum NpmrcScope {
59
+ Global = "Global",// $PREFIX/etc/npmrc
60
+ User = "User",// $HOME/.npmrc
61
+ Project = "Project"
62
+ }
63
+ export declare const NpmrcKind: "org.openrewrite.javascript.marker.NodeResolutionResult$Npmrc";
64
+ /**
65
+ * Represents npm configuration from a specific scope.
66
+ * Multiple Npmrc objects can be collected (one per scope) to allow
67
+ * recipes to merge configurations or modify specific scopes.
68
+ */
69
+ export interface Npmrc {
70
+ readonly kind: typeof NpmrcKind;
71
+ readonly scope: NpmrcScope;
72
+ readonly properties: Record<string, string>;
73
+ }
74
+ /**
75
+ * Represents a dependency request as declared in package.json.
76
+ * This is what a package asks for (name + version constraint).
77
+ *
78
+ * When the same name+versionConstraint appears multiple times, the same
79
+ * Dependency instance is reused. This enables reference deduplication
80
+ * during RPC serialization via asRef().
81
+ */
82
+ export interface Dependency {
83
+ readonly kind: typeof DependencyKind;
84
+ readonly name: string;
85
+ readonly versionConstraint: string;
86
+ readonly resolved?: ResolvedDependency;
87
+ }
88
+ /**
89
+ * Represents a resolved dependency from package-lock.json.
90
+ * This is what was actually installed (name + resolved version + its own dependencies).
91
+ *
92
+ * Each ResolvedDependency's dependency arrays contain Dependency objects (requests),
93
+ * which can be looked up in NodeResolutionResult.resolvedDependencies to find their resolved versions.
94
+ */
95
+ export interface ResolvedDependency {
96
+ readonly kind: typeof ResolvedDependencyKind;
97
+ readonly name: string;
98
+ readonly version: string;
99
+ readonly dependencies?: Dependency[];
100
+ readonly devDependencies?: Dependency[];
101
+ readonly peerDependencies?: Dependency[];
102
+ readonly optionalDependencies?: Dependency[];
103
+ readonly engines?: Record<string, string>;
104
+ readonly license?: string;
105
+ }
106
+ /**
107
+ * Contains metadata about a Node.js project, parsed from package.json and package-lock.json.
108
+ * Attached as a marker to JS.CompilationUnit to provide dependency context for recipes.
109
+ *
110
+ * Similar to MavenResolutionResult marker, this allows recipes to:
111
+ * - Query project dependencies
112
+ * - Check if specific packages are in use
113
+ * - Modify dependencies programmatically
114
+ * - Understand the project structure
115
+ *
116
+ * The model separates requests (Dependency) from resolutions (ResolvedDependency):
117
+ * - The dependency arrays contain Dependency objects (what was requested)
118
+ * - The resolvedDependencies list contains what was actually installed
119
+ */
120
+ export interface NodeResolutionResult extends Marker {
121
+ readonly kind: typeof NodeResolutionResultKind;
122
+ readonly id: UUID;
123
+ readonly name?: string;
124
+ readonly version?: string;
125
+ readonly description?: string;
126
+ readonly path: string;
127
+ readonly workspacePackagePaths?: string[];
128
+ readonly dependencies: Dependency[];
129
+ readonly devDependencies: Dependency[];
130
+ readonly peerDependencies: Dependency[];
131
+ readonly optionalDependencies: Dependency[];
132
+ readonly bundledDependencies: Dependency[];
133
+ readonly resolvedDependencies: ResolvedDependency[];
134
+ readonly packageManager?: PackageManager;
135
+ readonly engines?: Record<string, string>;
136
+ readonly npmrcConfigs?: Npmrc[];
137
+ }
138
+ /**
139
+ * Creates a NodeResolutionResult marker from a package.json file.
140
+ * Should be called during parsing to attach to JS.CompilationUnit.
141
+ *
142
+ * All Dependency instances are wrapped with asRef() to enable
143
+ * reference deduplication during RPC serialization.
144
+ *
145
+ * @param path Path to the package.json file
146
+ * @param packageJsonContent Parsed package.json content
147
+ * @param packageLockContent Optional parsed package-lock.json content for resolution info
148
+ * @param workspacePackagePaths Optional resolved paths to workspace package.json files (only for workspace root)
149
+ * @param packageManager Optional package manager that was detected from lock file
150
+ * @param npmrcConfigs Optional npm configuration from various scopes
151
+ */
152
+ export declare function createNodeResolutionResultMarker(path: string, packageJsonContent: PackageJsonContent, packageLockContent?: PackageLockContent, workspacePackagePaths?: string[], packageManager?: PackageManager, npmrcConfigs?: Npmrc[]): NodeResolutionResult;
153
+ /**
154
+ * Helper function to find a NodeResolutionResult marker on a compilation unit.
155
+ */
156
+ export declare function findNodeResolutionResult(cu: {
157
+ markers: Markers;
158
+ }): NodeResolutionResult | undefined;
159
+ /**
160
+ * Reads .npmrc configurations from all scope levels.
161
+ * Returns an array of Npmrc objects, one for each scope that has configuration.
162
+ *
163
+ * Scopes (from lowest to highest priority):
164
+ * - Global: $PREFIX/etc/npmrc (npm's installation directory)
165
+ * - User: $HOME/.npmrc (user's home directory)
166
+ * - Project: .npmrc in project root (sibling of package.json)
167
+ * - Env: npm_config_* environment variables
168
+ *
169
+ * @param projectDir The project directory containing package.json
170
+ * @returns Promise resolving to array of Npmrc objects for each scope with configuration
171
+ */
172
+ export declare function readNpmrcConfigs(projectDir: string): Promise<Npmrc[]>;
173
+ /**
174
+ * Helper functions for querying dependencies
175
+ */
176
+ export declare namespace NodeResolutionResultQueries {
177
+ /**
178
+ * Get all dependency requests from all scopes.
179
+ */
180
+ function getAllDependencies(project: NodeResolutionResult): Dependency[];
181
+ /**
182
+ * Check if project has a specific dependency request, optionally filtered by scope.
183
+ */
184
+ function hasDependency(project: NodeResolutionResult, packageName: string, scope?: 'dependencies' | 'devDependencies' | 'peerDependencies' | 'optionalDependencies' | 'bundledDependencies'): boolean;
185
+ /**
186
+ * Find a specific dependency request by name across all scopes.
187
+ */
188
+ function findDependency(project: NodeResolutionResult, packageName: string): Dependency | undefined;
189
+ /**
190
+ * Get all dependency requests matching a predicate.
191
+ */
192
+ function findDependencies(project: NodeResolutionResult, predicate: (dep: Dependency) => boolean): Dependency[];
193
+ /**
194
+ * Get all resolved dependencies with a specific name (handles multiple versions).
195
+ * Returns an empty array if no versions are found.
196
+ *
197
+ * For navigation, prefer using the Dependency.resolved property:
198
+ * @example
199
+ * const express = project.dependencies.find(d => d.name === 'express')?.resolved;
200
+ * const accepts = express?.dependencies?.find(d => d.name === 'accepts')?.resolved;
201
+ */
202
+ function getAllResolvedVersions(project: NodeResolutionResult, packageName: string): ResolvedDependency[];
203
+ }
204
+ //# sourceMappingURL=node-resolution-result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-resolution-result.d.ts","sourceRoot":"","sources":["../../src/javascript/node-resolution-result.ts"],"names":[],"mappings":"AAeA,OAAO,EAAa,MAAM,EAAE,OAAO,EAAC,MAAM,YAAY,CAAC;AACvD,OAAO,EAAW,IAAI,EAAC,MAAM,SAAS,CAAC;AASvC,eAAO,MAAM,wBAAwB,EAAG,wDAAiE,CAAC;AAC1G,eAAO,MAAM,cAAc,EAAG,mEAA4E,CAAC;AAC3G,eAAO,MAAM,sBAAsB,EAAG,2EAAoF,CAAC;AAE3H;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/C,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClD,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnD,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvD,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IACxC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IACvC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CA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