@openrewrite/rewrite 8.63.2 → 8.63.3
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install-recipes.d.ts","sourceRoot":"","sources":["../../../src/rpc/request/install-recipes.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC;AAM5C,MAAM,WAAW,sBAAsB;IACnC,gBAAgB,EAAE,MAAM,CAAA;CAC3B;AAqCD,qBAAa,cAAc;IAMX,OAAO,CAAC,QAAQ,CAAC,OAAO;IALpC;;;;OAIG;gBAC0B,OAAO,EAAE,MAAM,GAAG;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAGxF,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,iBAAiB,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAC/E,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"install-recipes.d.ts","sourceRoot":"","sources":["../../../src/rpc/request/install-recipes.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC;AAM5C,MAAM,WAAW,sBAAsB;IACnC,gBAAgB,EAAE,MAAM,CAAA;CAC3B;AAqCD,qBAAa,cAAc;IAMX,OAAO,CAAC,QAAQ,CAAC,OAAO;IALpC;;;;OAIG;gBAC0B,OAAO,EAAE,MAAM,GAAG;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAGxF,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,iBAAiB,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAC/E,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;CA2EhE"}
|
|
@@ -141,7 +141,10 @@ class InstallRecipes {
|
|
|
141
141
|
}
|
|
142
142
|
let recipeModule;
|
|
143
143
|
try {
|
|
144
|
-
|
|
144
|
+
// Pre-load core modules that are used by recipes but loaded lazily
|
|
145
|
+
// This ensures they're in require.cache before setupSharedDependencies runs
|
|
146
|
+
preloadCoreModules(logger);
|
|
147
|
+
setupSharedDependencies(resolvedPath, logger);
|
|
145
148
|
recipeModule = require(resolvedPath);
|
|
146
149
|
}
|
|
147
150
|
catch (e) {
|
|
@@ -163,35 +166,127 @@ class InstallRecipes {
|
|
|
163
166
|
}
|
|
164
167
|
}
|
|
165
168
|
exports.InstallRecipes = InstallRecipes;
|
|
169
|
+
/**
|
|
170
|
+
* Pre-loads core modules that are typically loaded lazily by recipes.
|
|
171
|
+
* This ensures they're in require.cache before setupSharedDependencies runs,
|
|
172
|
+
* so they can be properly mapped to avoid instanceof failures.
|
|
173
|
+
*/
|
|
174
|
+
function preloadCoreModules(logger) {
|
|
175
|
+
const modulesToPreload = [
|
|
176
|
+
'../..',
|
|
177
|
+
'../../java',
|
|
178
|
+
'../../javascript',
|
|
179
|
+
'../../json',
|
|
180
|
+
'../../rpc',
|
|
181
|
+
'../../search',
|
|
182
|
+
'../../text',
|
|
183
|
+
];
|
|
184
|
+
modulesToPreload.forEach(modulePath => {
|
|
185
|
+
try {
|
|
186
|
+
require(modulePath);
|
|
187
|
+
if (logger) {
|
|
188
|
+
logger.info(`[preloadCoreModules] Loaded ${modulePath}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch (e) {
|
|
192
|
+
if (logger) {
|
|
193
|
+
logger.warn(`[preloadCoreModules] Failed to load ${modulePath}: ${e}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
166
198
|
/**
|
|
167
199
|
* Ensures dynamically loaded modules share the same class instances as the host
|
|
168
200
|
* by mapping require.cache entries. This prevents instanceof failures when the
|
|
169
201
|
* same package is installed in multiple node_modules directories.
|
|
170
202
|
*/
|
|
171
|
-
function setupSharedDependencies(targetModulePath) {
|
|
203
|
+
function setupSharedDependencies(targetModulePath, logger) {
|
|
172
204
|
const sharedDeps = ['@openrewrite/rewrite', 'vscode-jsonrpc'];
|
|
173
205
|
const targetDir = path.dirname(targetModulePath);
|
|
174
206
|
sharedDeps.forEach(depName => {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
207
|
+
try {
|
|
208
|
+
// Step 1: Find where this package is currently loaded from (host)
|
|
209
|
+
const hostPackageEntry = require.resolve(depName);
|
|
210
|
+
// Step 2: Find the package root by looking for package.json
|
|
211
|
+
let hostPackageRoot = path.dirname(hostPackageEntry);
|
|
212
|
+
while (hostPackageRoot !== path.dirname(hostPackageRoot)) {
|
|
213
|
+
const packageJsonPath = path.join(hostPackageRoot, 'package.json');
|
|
214
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
215
|
+
try {
|
|
216
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
217
|
+
if (pkg.name === depName) {
|
|
218
|
+
break; // Found the package root
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (e) {
|
|
222
|
+
// Not a valid package.json, continue
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
hostPackageRoot = path.dirname(hostPackageRoot);
|
|
192
226
|
}
|
|
193
|
-
|
|
194
|
-
|
|
227
|
+
if (logger) {
|
|
228
|
+
logger.info(`[setupSharedDependencies] Host package root for ${depName}: ${hostPackageRoot}`);
|
|
229
|
+
}
|
|
230
|
+
// Step 3: Find where the target's node_modules has this package
|
|
231
|
+
// We explicitly look in node_modules to avoid finding npm-linked global packages
|
|
232
|
+
let targetPackageRoot;
|
|
233
|
+
// Walk up from targetDir looking for node_modules containing this package
|
|
234
|
+
let searchDir = targetDir;
|
|
235
|
+
while (searchDir !== path.dirname(searchDir)) {
|
|
236
|
+
const nodeModulesPath = path.join(searchDir, 'node_modules', ...depName.split('/'));
|
|
237
|
+
if (fs.existsSync(nodeModulesPath)) {
|
|
238
|
+
const packageJsonPath = path.join(nodeModulesPath, 'package.json');
|
|
239
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
240
|
+
try {
|
|
241
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
242
|
+
if (pkg.name === depName) {
|
|
243
|
+
targetPackageRoot = nodeModulesPath;
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
catch (e) {
|
|
248
|
+
// Not a valid package.json, continue
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
searchDir = path.dirname(searchDir);
|
|
253
|
+
}
|
|
254
|
+
if (!targetPackageRoot) {
|
|
255
|
+
if (logger) {
|
|
256
|
+
logger.warn(`[setupSharedDependencies] Could not find ${depName} in target's node_modules`);
|
|
257
|
+
}
|
|
258
|
+
return; // Can't map this package
|
|
259
|
+
}
|
|
260
|
+
if (logger) {
|
|
261
|
+
logger.info(`[setupSharedDependencies] Target package root for ${depName}: ${targetPackageRoot}`);
|
|
262
|
+
}
|
|
263
|
+
// If they're the same, no mapping needed
|
|
264
|
+
if (hostPackageRoot === targetPackageRoot) {
|
|
265
|
+
if (logger) {
|
|
266
|
+
logger.info(`[setupSharedDependencies] Same package root, no mapping needed for ${depName}`);
|
|
267
|
+
}
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
// Step 4: Map all cached modules from host package to target package
|
|
271
|
+
const hostPrefix = hostPackageRoot + path.sep;
|
|
272
|
+
let mappedCount = 0;
|
|
273
|
+
for (const cachedPath of Object.keys(require.cache)) {
|
|
274
|
+
if (cachedPath.startsWith(hostPrefix)) {
|
|
275
|
+
// This module belongs to the host package
|
|
276
|
+
const relativePath = cachedPath.substring(hostPrefix.length);
|
|
277
|
+
const targetPath = path.join(targetPackageRoot, relativePath);
|
|
278
|
+
// Map the target path to use the host's cached module
|
|
279
|
+
require.cache[targetPath] = require.cache[cachedPath];
|
|
280
|
+
mappedCount++;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (logger) {
|
|
284
|
+
logger.info(`[setupSharedDependencies] Mapped ${mappedCount} modules for ${depName}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
catch (e) {
|
|
288
|
+
if (logger) {
|
|
289
|
+
logger.error(`[setupSharedDependencies] Failed to setup ${depName}: ${e}`);
|
|
195
290
|
}
|
|
196
291
|
}
|
|
197
292
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install-recipes.js","sourceRoot":"","sources":["../../../src/rpc/request/install-recipes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,yDAA2C;AAE3C,2CAA6B;AAC7B,uCAAyB;AACzB,iDAAoC;AACpC,uCAAsC;AAMtC;;GAEG;AACH,SAAe,eAAe,CAC1B,OAAe,EACf,IAAc,EACd,GAAW,EACX,MAAmB,EACnB,SAAkB;;QAElB,MAAM,KAAK,GAAG,IAAA,qBAAK,EAAC,OAAO,EAAE,IAAI,EAAE,EAAC,GAAG,EAAC,CAAC,CAAC;QAE1C,IAAI,MAAM,EAAE,CAAC;YACT,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,IAAI,CAAC,CAAC,CAAC,EAAE,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BACD,OAAO;YACX,CAAC;YAED,qEAAqE;YACrE,MAAM,UAAU,GAAG,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC;YAE9C,IAAI,WAAW,GAAG,CAAC,CAAC;YACpB,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBAClD,IAAI,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;oBACpC,0CAA0C;oBAC1C,MAAM,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;oBAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;oBAE9D,sDAAsD;oBACtD,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;oBACtD,WAAW,EAAE,CAAC;gBAClB,CAAC;YACL,CAAC;YAED,IAAI,MAAM,EAAE,CAAC;gBACT,MAAM,CAAC,IAAI,CAAC,oCAAoC,WAAW,gBAAgB,OAAO,EAAE,CAAC,CAAC;YAC1F,CAAC;QACL,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,IAAI,MAAM,EAAE,CAAC;gBACT,MAAM,CAAC,KAAK,CAAC,6CAA6C,OAAO,KAAK,CAAC,EAAE,CAAC,CAAC;YAC/E,CAAC;QACL,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/dist/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
8.63.
|
|
1
|
+
8.63.3
|
package/package.json
CHANGED
|
@@ -118,7 +118,11 @@ export class InstallRecipes {
|
|
|
118
118
|
|
|
119
119
|
let recipeModule;
|
|
120
120
|
try {
|
|
121
|
-
|
|
121
|
+
// Pre-load core modules that are used by recipes but loaded lazily
|
|
122
|
+
// This ensures they're in require.cache before setupSharedDependencies runs
|
|
123
|
+
preloadCoreModules(logger);
|
|
124
|
+
|
|
125
|
+
setupSharedDependencies(resolvedPath, logger);
|
|
122
126
|
recipeModule = require(resolvedPath);
|
|
123
127
|
} catch (e: any) {
|
|
124
128
|
throw new Error(`Failed to load recipe module from ${resolvedPath}: ${e.stack}`);
|
|
@@ -142,38 +146,137 @@ export class InstallRecipes {
|
|
|
142
146
|
}
|
|
143
147
|
}
|
|
144
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Pre-loads core modules that are typically loaded lazily by recipes.
|
|
151
|
+
* This ensures they're in require.cache before setupSharedDependencies runs,
|
|
152
|
+
* so they can be properly mapped to avoid instanceof failures.
|
|
153
|
+
*/
|
|
154
|
+
function preloadCoreModules(logger?: rpc.Logger) {
|
|
155
|
+
const modulesToPreload = [
|
|
156
|
+
'../..',
|
|
157
|
+
'../../java',
|
|
158
|
+
'../../javascript',
|
|
159
|
+
'../../json',
|
|
160
|
+
'../../rpc',
|
|
161
|
+
'../../search',
|
|
162
|
+
'../../text',
|
|
163
|
+
];
|
|
164
|
+
|
|
165
|
+
modulesToPreload.forEach(modulePath => {
|
|
166
|
+
try {
|
|
167
|
+
require(modulePath);
|
|
168
|
+
if (logger) {
|
|
169
|
+
logger.info(`[preloadCoreModules] Loaded ${modulePath}`);
|
|
170
|
+
}
|
|
171
|
+
} catch (e) {
|
|
172
|
+
if (logger) {
|
|
173
|
+
logger.warn(`[preloadCoreModules] Failed to load ${modulePath}: ${e}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
145
179
|
/**
|
|
146
180
|
* Ensures dynamically loaded modules share the same class instances as the host
|
|
147
181
|
* by mapping require.cache entries. This prevents instanceof failures when the
|
|
148
182
|
* same package is installed in multiple node_modules directories.
|
|
149
183
|
*/
|
|
150
|
-
function setupSharedDependencies(targetModulePath: string) {
|
|
184
|
+
function setupSharedDependencies(targetModulePath: string, logger?: rpc.Logger) {
|
|
151
185
|
const sharedDeps = ['@openrewrite/rewrite', 'vscode-jsonrpc'];
|
|
152
186
|
const targetDir = path.dirname(targetModulePath);
|
|
153
187
|
|
|
154
188
|
sharedDeps.forEach(depName => {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
189
|
+
try {
|
|
190
|
+
// Step 1: Find where this package is currently loaded from (host)
|
|
191
|
+
const hostPackageEntry = require.resolve(depName);
|
|
192
|
+
|
|
193
|
+
// Step 2: Find the package root by looking for package.json
|
|
194
|
+
let hostPackageRoot = path.dirname(hostPackageEntry);
|
|
195
|
+
while (hostPackageRoot !== path.dirname(hostPackageRoot)) {
|
|
196
|
+
const packageJsonPath = path.join(hostPackageRoot, 'package.json');
|
|
197
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
198
|
+
try {
|
|
199
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
200
|
+
if (pkg.name === depName) {
|
|
201
|
+
break; // Found the package root
|
|
202
|
+
}
|
|
203
|
+
} catch (e) {
|
|
204
|
+
// Not a valid package.json, continue
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
hostPackageRoot = path.dirname(hostPackageRoot);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (logger) {
|
|
211
|
+
logger.info(`[setupSharedDependencies] Host package root for ${depName}: ${hostPackageRoot}`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Step 3: Find where the target's node_modules has this package
|
|
215
|
+
// We explicitly look in node_modules to avoid finding npm-linked global packages
|
|
216
|
+
let targetPackageRoot: string | undefined;
|
|
217
|
+
|
|
218
|
+
// Walk up from targetDir looking for node_modules containing this package
|
|
219
|
+
let searchDir = targetDir;
|
|
220
|
+
while (searchDir !== path.dirname(searchDir)) {
|
|
221
|
+
const nodeModulesPath = path.join(searchDir, 'node_modules', ...depName.split('/'));
|
|
222
|
+
if (fs.existsSync(nodeModulesPath)) {
|
|
223
|
+
const packageJsonPath = path.join(nodeModulesPath, 'package.json');
|
|
224
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
225
|
+
try {
|
|
226
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
227
|
+
if (pkg.name === depName) {
|
|
228
|
+
targetPackageRoot = nodeModulesPath;
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
} catch (e) {
|
|
232
|
+
// Not a valid package.json, continue
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
searchDir = path.dirname(searchDir);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (!targetPackageRoot) {
|
|
240
|
+
if (logger) {
|
|
241
|
+
logger.warn(`[setupSharedDependencies] Could not find ${depName} in target's node_modules`);
|
|
242
|
+
}
|
|
243
|
+
return; // Can't map this package
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (logger) {
|
|
247
|
+
logger.info(`[setupSharedDependencies] Target package root for ${depName}: ${targetPackageRoot}`);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// If they're the same, no mapping needed
|
|
251
|
+
if (hostPackageRoot === targetPackageRoot) {
|
|
252
|
+
if (logger) {
|
|
253
|
+
logger.info(`[setupSharedDependencies] Same package root, no mapping needed for ${depName}`);
|
|
254
|
+
}
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Step 4: Map all cached modules from host package to target package
|
|
259
|
+
const hostPrefix = hostPackageRoot + path.sep;
|
|
260
|
+
|
|
261
|
+
let mappedCount = 0;
|
|
262
|
+
for (const cachedPath of Object.keys(require.cache)) {
|
|
263
|
+
if (cachedPath.startsWith(hostPrefix)) {
|
|
264
|
+
// This module belongs to the host package
|
|
265
|
+
const relativePath = cachedPath.substring(hostPrefix.length);
|
|
266
|
+
const targetPath = path.join(targetPackageRoot, relativePath);
|
|
267
|
+
|
|
268
|
+
// Map the target path to use the host's cached module
|
|
269
|
+
require.cache[targetPath] = require.cache[cachedPath];
|
|
270
|
+
mappedCount++;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (logger) {
|
|
275
|
+
logger.info(`[setupSharedDependencies] Mapped ${mappedCount} modules for ${depName}`);
|
|
276
|
+
}
|
|
277
|
+
} catch (e) {
|
|
278
|
+
if (logger) {
|
|
279
|
+
logger.error(`[setupSharedDependencies] Failed to setup ${depName}: ${e}`);
|
|
177
280
|
}
|
|
178
281
|
}
|
|
179
282
|
});
|