@openrewrite/rewrite 8.93.0 → 8.93.2

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 (37) hide show
  1. package/dist/javascript/index.d.ts +1 -0
  2. package/dist/javascript/index.d.ts.map +1 -1
  3. package/dist/javascript/index.js +1 -0
  4. package/dist/javascript/index.js.map +1 -1
  5. package/dist/javascript/node-runtime.d.ts +63 -0
  6. package/dist/javascript/node-runtime.d.ts.map +1 -0
  7. package/dist/javascript/node-runtime.js +196 -0
  8. package/dist/javascript/node-runtime.js.map +1 -0
  9. package/dist/javascript/package-json-parser.d.ts +13 -0
  10. package/dist/javascript/package-json-parser.d.ts.map +1 -1
  11. package/dist/javascript/package-json-parser.js +62 -22
  12. package/dist/javascript/package-json-parser.js.map +1 -1
  13. package/dist/javascript/package-manager.d.ts +15 -0
  14. package/dist/javascript/package-manager.d.ts.map +1 -1
  15. package/dist/javascript/package-manager.js +38 -0
  16. package/dist/javascript/package-manager.js.map +1 -1
  17. package/dist/javascript/parser.d.ts +2 -0
  18. package/dist/javascript/parser.d.ts.map +1 -1
  19. package/dist/javascript/parser.js +57 -40
  20. package/dist/javascript/parser.js.map +1 -1
  21. package/dist/rewrite-javascript-version.txt +1 -1
  22. package/dist/rpc/message-encoder.d.ts +18 -7
  23. package/dist/rpc/message-encoder.d.ts.map +1 -1
  24. package/dist/rpc/message-encoder.js +42 -18
  25. package/dist/rpc/message-encoder.js.map +1 -1
  26. package/dist/rpc/request/dependency-types.d.ts +6 -5
  27. package/dist/rpc/request/dependency-types.d.ts.map +1 -1
  28. package/dist/rpc/request/dependency-types.js +13 -12
  29. package/dist/rpc/request/dependency-types.js.map +1 -1
  30. package/package.json +1 -1
  31. package/src/javascript/index.ts +1 -0
  32. package/src/javascript/node-runtime.ts +213 -0
  33. package/src/javascript/package-json-parser.ts +75 -32
  34. package/src/javascript/package-manager.ts +48 -0
  35. package/src/javascript/parser.ts +86 -45
  36. package/src/rpc/message-encoder.ts +41 -18
  37. package/src/rpc/request/dependency-types.ts +13 -11
@@ -1 +1 @@
1
- 8.93.0
1
+ 8.93.2
@@ -13,15 +13,26 @@ export type JsonRpcContentTypeEncoder = NonNullable<MessageWriterOptions["conten
13
13
  * exactly — and only the structural punctuation is emitted here.
14
14
  */
15
15
  export declare function jsonFragments(value: unknown): Generator<string>;
16
+ /**
17
+ * Streams {@link jsonFragments} into Buffers so that no more than one flush window is a JS string
18
+ * at a time, raising the outbound ceiling from V8's String.kMaxLength to Node's Buffer.MAX_LENGTH.
19
+ * Content-Length still needs the whole body up front, so this is a ceiling raise and not true
20
+ * streaming.
21
+ *
22
+ * Exported because {@link chunkedJsonEncoder} reaches it only above the cap: a test of the walk has
23
+ * to call it directly.
24
+ */
25
+ export declare function encodeFragmented(msg: unknown, charset: BufferEncoding): Buffer;
16
26
  /**
17
27
  * A drop-in replacement for vscode-jsonrpc's default `application/json` content-type encoder that
18
- * serializes a message to UTF-8 bytes without ever materializing the whole document as a single JS
19
- * string. The default encoder does {@code Buffer.from(JSON.stringify(msg))}; a large enough
20
- * PrepareRecipe response (a deep recipe tree) overflows V8's single-string limit and throws
21
- * "RangeError: Invalid string length", hanging the RPC call. Streaming the
22
- * fragments into a Buffer raises the ceiling to Node's Buffer.MAX_LENGTH (multiple GB) while
23
- * producing byte-identical output. (True unbounded streaming needs chunked framing — Content-Length
24
- * still requires the whole body up front — so this is a ceiling raise, not a removal.)
28
+ * keeps a message serializable past V8's single-string limit. The default encoder does {@code
29
+ * Buffer.from(JSON.stringify(msg))}; a large enough PrepareRecipe response (a deep recipe tree)
30
+ * overflows that limit and throws "RangeError: Invalid string length", hanging the RPC call.
31
+ *
32
+ * Below the limit it takes the default's own single-string path: {@link encodeFragmented} would
33
+ * assemble exactly that string anyway, at a yield per scalar, key and structural token to get
34
+ * there — ~5x slower on a thousand-element batch. Only a message that cannot be one string pays
35
+ * for the walk, as {@link chunkedJsonDecoder} does inbound.
25
36
  */
26
37
  export declare const chunkedJsonEncoder: JsonRpcContentTypeEncoder;
27
38
  //# sourceMappingURL=message-encoder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"message-encoder.d.ts","sourceRoot":"","sources":["../../src/rpc/message-encoder.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAU,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AAEvE;;;;GAIG;AACH,MAAM,MAAM,yBAAyB,GAAG,WAAW,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,CAAC,CAAC;AAgBhG;;;;;;GAMG;AACH,wBAAiB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CA8ChE;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,EAAE,yBAiBhC,CAAC"}
1
+ {"version":3,"file":"message-encoder.d.ts","sourceRoot":"","sources":["../../src/rpc/message-encoder.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAU,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AAEvE;;;;GAIG;AACH,MAAM,MAAM,yBAAyB,GAAG,WAAW,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,CAAC,CAAC;AAgBhG;;;;;;GAMG;AACH,wBAAiB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CA8ChE;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,MAAM,CAc9E;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,EAAE,yBAchC,CAAC"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.chunkedJsonEncoder = void 0;
4
4
  exports.jsonFragments = jsonFragments;
5
+ exports.encodeFragmented = encodeFragmented;
5
6
  // Flush the accumulated JSON text to a Buffer once it reaches this many UTF-16 code units. This
6
7
  // keeps the transient string far below V8's ~512 MB String.kMaxLength while bounding how many
7
8
  // intermediate Buffers we concatenate. A single scalar/key fragment is never split, so the pending
@@ -66,32 +67,55 @@ function* jsonFragments(value) {
66
67
  // Scalar: string, number, boolean, or null (a bigint throws here, exactly as JSON.stringify does).
67
68
  yield JSON.stringify(value);
68
69
  }
70
+ /**
71
+ * Streams {@link jsonFragments} into Buffers so that no more than one flush window is a JS string
72
+ * at a time, raising the outbound ceiling from V8's String.kMaxLength to Node's Buffer.MAX_LENGTH.
73
+ * Content-Length still needs the whole body up front, so this is a ceiling raise and not true
74
+ * streaming.
75
+ *
76
+ * Exported because {@link chunkedJsonEncoder} reaches it only above the cap: a test of the walk has
77
+ * to call it directly.
78
+ */
79
+ function encodeFragmented(msg, charset) {
80
+ const buffers = [];
81
+ let pending = "";
82
+ for (const fragment of jsonFragments(msg)) {
83
+ pending += fragment;
84
+ if (pending.length >= FLUSH_THRESHOLD) {
85
+ buffers.push(Buffer.from(pending, charset));
86
+ pending = "";
87
+ }
88
+ }
89
+ if (pending.length > 0) {
90
+ buffers.push(Buffer.from(pending, charset));
91
+ }
92
+ return Buffer.concat(buffers);
93
+ }
69
94
  /**
70
95
  * A drop-in replacement for vscode-jsonrpc's default `application/json` content-type encoder that
71
- * serializes a message to UTF-8 bytes without ever materializing the whole document as a single JS
72
- * string. The default encoder does {@code Buffer.from(JSON.stringify(msg))}; a large enough
73
- * PrepareRecipe response (a deep recipe tree) overflows V8's single-string limit and throws
74
- * "RangeError: Invalid string length", hanging the RPC call. Streaming the
75
- * fragments into a Buffer raises the ceiling to Node's Buffer.MAX_LENGTH (multiple GB) while
76
- * producing byte-identical output. (True unbounded streaming needs chunked framing — Content-Length
77
- * still requires the whole body up front — so this is a ceiling raise, not a removal.)
96
+ * keeps a message serializable past V8's single-string limit. The default encoder does {@code
97
+ * Buffer.from(JSON.stringify(msg))}; a large enough PrepareRecipe response (a deep recipe tree)
98
+ * overflows that limit and throws "RangeError: Invalid string length", hanging the RPC call.
99
+ *
100
+ * Below the limit it takes the default's own single-string path: {@link encodeFragmented} would
101
+ * assemble exactly that string anyway, at a yield per scalar, key and structural token to get
102
+ * there — ~5x slower on a thousand-element batch. Only a message that cannot be one string pays
103
+ * for the walk, as {@link chunkedJsonDecoder} does inbound.
78
104
  */
79
105
  exports.chunkedJsonEncoder = {
80
106
  name: "application/json",
81
107
  encode(msg, options) {
82
- const buffers = [];
83
- let pending = "";
84
- for (const fragment of jsonFragments(msg)) {
85
- pending += fragment;
86
- if (pending.length >= FLUSH_THRESHOLD) {
87
- buffers.push(Buffer.from(pending, options.charset));
88
- pending = "";
89
- }
108
+ try {
109
+ return Promise.resolve(Buffer.from(JSON.stringify(msg), options.charset));
90
110
  }
91
- if (pending.length > 0) {
92
- buffers.push(Buffer.from(pending, options.charset));
111
+ catch (err) {
112
+ // A cycle or a bigint is a TypeError the walk cannot serialize either — and would meet
113
+ // by recursing until the stack ended. Only the string limit is worth a second attempt.
114
+ if (!(err instanceof RangeError)) {
115
+ return Promise.reject(err);
116
+ }
93
117
  }
94
- return Promise.resolve(Buffer.concat(buffers));
118
+ return Promise.resolve(encodeFragmented(msg, options.charset));
95
119
  }
96
120
  };
97
121
  //# sourceMappingURL=message-encoder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"message-encoder.js","sourceRoot":"","sources":["../../src/rpc/message-encoder.ts"],"names":[],"mappings":";;;AA6CA,sCA8CC;AAnED,gGAAgG;AAChG,8FAA8F;AAC9F,mGAAmG;AACnG,gEAAgE;AAChE,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,QAAQ;AAEzC;;;GAGG;AACH,SAAS,aAAa,CAAC,KAAc;IACjC,OAAO,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,UAAU,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AAC3F,CAAC;AAED;;;;;;GAMG;AACH,QAAe,CAAC,CAAC,aAAa,CAAC,KAAc;IACzC,2FAA2F;IAC3F,sEAAsE;IACtE,IAA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AAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QAC9E,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,uFAAuF;YACvF,uFAAuF;YACvF,IAAI,CAAC,CAAC,GAAG,YAAY,UAAU,CAAC,EAAE,CAAC;gBAC/B,OAAO,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC/B,CAAC;QACL,CAAC;QACD,OAAO,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IACnE,CAAC;CACJ,CAAC"}
@@ -1,15 +1,16 @@
1
1
  import * as rpc from "vscode-jsonrpc/node";
2
2
  /**
3
3
  * Handle a DependencyTypes request: resolve one dependency, named by its npm coordinate, against
4
- * the most recently parsed project's node_modules, enumerate its public types, and stream them
5
- * back terminated by END_OF_OBJECT. Built once, returned in {@code batchSize} slices across the
6
- * client's repeated pulls. A {@code null} version names a TypeScript runtime declaration file
7
- * (e.g. {@code lib.dom}) instead of an installed package.
4
+ * the node_modules of {@code path} or else of the most recently parsed project, enumerate its
5
+ * public types, and stream them back terminated by END_OF_OBJECT. Built once, returned in
6
+ * {@code batchSize} slices across the client's repeated pulls. A {@code null} version names a
7
+ * TypeScript runtime declaration file (e.g. {@code lib.dom}) instead of an installed package.
8
8
  */
9
9
  export declare class DependencyTypes {
10
10
  private readonly name;
11
11
  private readonly version?;
12
- constructor(name: string, version?: string | null | undefined);
12
+ private readonly path?;
13
+ constructor(name: string, version?: string | null | undefined, path?: string | null | undefined);
13
14
  static handle(connection: rpc.MessageConnection, batchSize: number, metricsCsv?: string): void;
14
15
  }
15
16
  //# sourceMappingURL=dependency-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dependency-types.d.ts","sourceRoot":"","sources":["../../../src/rpc/request/dependency-types.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAc3C;;;;;;GAMG;AACH,qBAAa,eAAe;IACZ,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;gBADR,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,YAAA;IAGpD,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,iBAAiB,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;CAgDjG"}
1
+ {"version":3,"file":"dependency-types.d.ts","sourceRoot":"","sources":["../../../src/rpc/request/dependency-types.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAc3C;;;;;;GAMG;AACH,qBAAa,eAAe;IACZ,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAFL,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,YAAA,EACvB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,YAAA;IAGjD,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,iBAAiB,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;CAkDjG"}
@@ -61,31 +61,33 @@ const last_parsed_project_1 = require("./last-parsed-project");
61
61
  const JAVA_TYPE_CLASS = "org.openrewrite.java.tree.JavaType$Class";
62
62
  /**
63
63
  * Handle a DependencyTypes request: resolve one dependency, named by its npm coordinate, against
64
- * the most recently parsed project's node_modules, enumerate its public types, and stream them
65
- * back terminated by END_OF_OBJECT. Built once, returned in {@code batchSize} slices across the
66
- * client's repeated pulls. A {@code null} version names a TypeScript runtime declaration file
67
- * (e.g. {@code lib.dom}) instead of an installed package.
64
+ * the node_modules of {@code path} or else of the most recently parsed project, enumerate its
65
+ * public types, and stream them back terminated by END_OF_OBJECT. Built once, returned in
66
+ * {@code batchSize} slices across the client's repeated pulls. A {@code null} version names a
67
+ * TypeScript runtime declaration file (e.g. {@code lib.dom}) instead of an installed package.
68
68
  */
69
69
  class DependencyTypes {
70
- constructor(name, version) {
70
+ constructor(name, version, path) {
71
71
  this.name = name;
72
72
  this.version = version;
73
+ this.path = path;
73
74
  }
74
75
  static handle(connection, batchSize, metricsCsv) {
75
76
  // Keyed by coordinate: holds the remaining slices of an in-flight
76
77
  // response across the client's repeated pulls. Evicted once fully drained.
77
78
  const pending = new Map();
78
79
  connection.onRequest(new rpc.RequestType("DependencyTypes"), (0, metrics_1.withMetrics)("DependencyTypes", metricsCsv, (context) => async (request) => {
79
- var _a;
80
+ var _a, _b;
80
81
  const version = (_a = request.version) !== null && _a !== void 0 ? _a : null;
82
+ const projectDir = (_b = request.path) !== null && _b !== void 0 ? _b : null;
81
83
  context.target = version ? `${request.name}@${version}` : request.name;
82
- const key = JSON.stringify([request.name, version]);
84
+ const key = JSON.stringify([request.name, version, projectDir]);
83
85
  if (!pending.has(key)) {
84
86
  // Dynamic import to break the circular dependency with the javascript module.
85
87
  const { exportedTypes } = await import("../../javascript/package-exported-types.js");
86
- const types = version !== null
87
- ? packageTypes(request.name, exportedTypes)
88
- : exportedTypes([runtimeLibFile(request.name)], []);
88
+ const types = version === null
89
+ ? exportedTypes([runtimeLibFile(request.name)], [])
90
+ : packageTypes(request.name, exportedTypes, projectDir === null ? projectNodeModules() : path.join(projectDir, "node_modules"));
89
91
  const q = new queue_1.RpcSendQueue(new reference_1.ReferenceMap(), JAVA_TYPE_CLASS, false);
90
92
  const sender = new rpc_1.JavaSender();
91
93
  // FQNs this dependency defines, sent before the types so the caller can tell
@@ -114,8 +116,7 @@ function projectNodeModules() {
114
116
  return path.join(project, "node_modules");
115
117
  }
116
118
  /** The installed package's own types, falling back to its DefinitelyTyped package when it ships none. */
117
- function packageTypes(name, exportedTypes) {
118
- const nodeModules = projectNodeModules();
119
+ function packageTypes(name, exportedTypes, nodeModules) {
119
120
  const pkgDir = path.join(nodeModules, ...name.split("/"));
120
121
  if (!fs.existsSync(pkgDir)) {
121
122
  throw new Error(`Package '${name}' is not installed under ${nodeModules}`);
@@ -1 +1 @@
1
- {"version":3,"file":"dependency-types.js","sourceRoot":"","sources":["../../../src/rpc/request/dependency-types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,yDAA2C;AAC3C,uCAAyB;AACzB,2CAA6B;AAC7B,oCAAqD;AACrD,+CAAoD;AACpD,wCAA0C;AAC1C,qCAAgC;AAChC,uCAAsC;AACtC,+DAAwD;AAExD,MAAM,eAAe,GAAG,0CAA0C,CAAC;AAInE;;;;;;GAMG;AACH,MAAa,eAAe;IACxB,YAA6B,IAAY,EACZ,OAAuB;QADvB,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAgB;IACpD,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,UAAiC,EAAE,SAAiB,EAAE,UAAmB;QACnF,kEAAkE;QAClE,2EAA2E;QAC3E,MAAM,OAAO,GAAG,IAAI,GAAG,EAA2B,CAAC;QAEnD,UAAU,CAAC,SAAS,CAChB,IAAI,GAAG,CAAC,WAAW,CAA0C,iBAAiB,CAAC,EAC/E,IAAA,qBAAW,EACP,iBAAiB,EACjB,UAAU,EACV,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;;YAC3B,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,IAAI,CAAC;YACxC,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;YAEvE,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SAAS,cAAc,CAAC,IAAY;IAChC,KAAK,MAAM,GAAG,IAAI;QACd,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,IAAI,OAAO,CAAC;QACpE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,GAAG,IAAI,OAAO,CAAC;KACzE,EAAE,CAAC;QACA,IAAI,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACrB,OAAO,GAAG,CAAC;QACf,CAAC;IACL,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,uCAAuC,IAAI,GAAG,CAAC,CAAC;AACpE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openrewrite/rewrite",
3
- "version": "8.93.0",
3
+ "version": "8.93.2",
4
4
  "license": "Moderne Source Available License",
5
5
  "description": "OpenRewrite JavaScript.",
6
6
  "repository": {
@@ -20,6 +20,7 @@ export * from "./parser";
20
20
  export * from "./style";
21
21
  export * from "./markers";
22
22
  export * from "./node-resolution-result";
23
+ export * from "./node-runtime";
23
24
  export * from "./package-json-parser";
24
25
  export * from "./package-manager";
25
26
  export * from "./dependency-manager";
@@ -0,0 +1,213 @@
1
+ /*
2
+ * Copyright 2026 the original author or authors.
3
+ * <p>
4
+ * Licensed under the Moderne Source Available License (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ * <p>
8
+ * https://docs.moderne.io/licensing/moderne-source-available-license
9
+ * <p>
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import {findMarker, Marker, Markers} from "../markers";
17
+ import {randomId, UUID} from "../uuid";
18
+ import {RpcCodecs, RpcReceiveQueue, RpcSendQueue} from "../rpc";
19
+ import {updateIfChanged} from "../util";
20
+ import {PackageManager} from "./node-resolution-result";
21
+ import * as fs from "fs";
22
+
23
+ export const NodeRuntimeKind = "org.openrewrite.javascript.marker.NodeRuntime" as const;
24
+
25
+ /**
26
+ * The machine and the package manager release that built a Node.js project's LST, as `JavaVersion` records the JDK
27
+ * that built a Java one. The lock regeneration installs the project as that release, on that Node and platform.
28
+ *
29
+ * The {@link PackageJsonParser} attaches one to every package.json document it produces, whether or not the document
30
+ * gets a {@link NodeResolutionResult}: one instance per project root, which its workspace members share.
31
+ */
32
+ export interface NodeRuntime extends Marker {
33
+ readonly kind: typeof NodeRuntimeKind;
34
+ readonly id: UUID;
35
+
36
+ /**
37
+ * `process.version` of the parser, such as `v24.19.0`.
38
+ */
39
+ readonly nodeVersion: string;
40
+
41
+ /**
42
+ * `process.platform` of the parser, such as `linux` or `darwin`.
43
+ */
44
+ readonly os: string;
45
+
46
+ /**
47
+ * `process.arch` of the parser, such as `x64` or `arm64`.
48
+ */
49
+ readonly cpu: string;
50
+
51
+ /**
52
+ * `glibc` or `musl` on Linux, as npm-install-checks 8.0.0 detects it ({@link libc}); absent on other platforms and
53
+ * where it cannot be told.
54
+ */
55
+ readonly libc?: string;
56
+
57
+ /**
58
+ * The package manager the parser found for the project by its lock file, as {@link NodeResolutionResult} names
59
+ * it; absent when it found none.
60
+ */
61
+ readonly packageManager?: PackageManager;
62
+
63
+ /**
64
+ * What that package manager's `--version` answers when run in the project's root directory, the release that
65
+ * installs the project on the parser's machine ({@link runVersion}); absent when it is not installed, fails, or
66
+ * answers something that is no version.
67
+ */
68
+ readonly packageManagerVersion?: string;
69
+ }
70
+
71
+ /**
72
+ * A {@link NodeRuntime} of the running process, for a project the parser found `packageManager` for.
73
+ *
74
+ * @param packageManager the package manager the parser found by the project's lock file, if any
75
+ * @param packageManagerVersion what its `--version` answered in the project's root directory, if anything
76
+ */
77
+ export function createNodeRuntimeMarker(packageManager?: PackageManager, packageManagerVersion?: string): NodeRuntime {
78
+ return {
79
+ kind: NodeRuntimeKind,
80
+ id: randomId(),
81
+ nodeVersion: process.version,
82
+ os: process.platform,
83
+ cpu: process.arch,
84
+ libc: libc(process.platform) ?? undefined,
85
+ packageManager,
86
+ packageManagerVersion
87
+ };
88
+ }
89
+
90
+ /**
91
+ * The {@link NodeRuntime} of a package.json document, if the parser attached one.
92
+ */
93
+ export function findNodeRuntime(tree: { markers: Markers }): NodeRuntime | undefined {
94
+ return findMarker<NodeRuntime>(tree, NodeRuntimeKind);
95
+ }
96
+
97
+ /*
98
+ * Port of npm-install-checks 8.0.0 lib/current-env.js libc(), distributed under the BSD 2-Clause License:
99
+ *
100
+ * Copyright (c) Robert Kowalski and Isaac Z. Schlueter ("Authors")
101
+ * All rights reserved.
102
+ *
103
+ * Redistribution and use in source and binary forms, with or without
104
+ * modification, are permitted provided that the following conditions
105
+ * are met:
106
+ *
107
+ * 1. Redistributions of source code must retain the above copyright
108
+ * notice, this list of conditions and the following disclaimer.
109
+ *
110
+ * 2. Redistributions in binary form must reproduce the above copyright
111
+ * notice, this list of conditions and the following disclaimer in the
112
+ * documentation and/or other materials provided with the distribution.
113
+ *
114
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
115
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
116
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
117
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS
118
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
119
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
120
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
121
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
122
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
123
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
124
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
125
+ */
126
+
127
+ function isMusl(file: string): boolean {
128
+ return file.includes('libc.musl-') || file.includes('ld-musl-');
129
+ }
130
+
131
+ const LDD_PATH = '/usr/bin/ldd';
132
+
133
+ function getFamilyFromFilesystem(): string | null | undefined {
134
+ try {
135
+ const content = fs.readFileSync(LDD_PATH, 'utf-8');
136
+ if (content.includes('musl')) {
137
+ return 'musl';
138
+ }
139
+ if (content.includes('GNU C Library')) {
140
+ return 'glibc';
141
+ }
142
+ return null;
143
+ } catch {
144
+ return undefined;
145
+ }
146
+ }
147
+
148
+ function getFamilyFromReport(): string | null {
149
+ // excludeNetwork is newer than the type declarations the module builds against
150
+ const processReport = process.report as NodeJS.ProcessReport & { excludeNetwork?: boolean };
151
+ const originalExclude = processReport.excludeNetwork;
152
+ processReport.excludeNetwork = true;
153
+ const report = processReport.getReport() as {
154
+ header?: { glibcVersionRuntime?: string };
155
+ sharedObjects?: unknown;
156
+ };
157
+ processReport.excludeNetwork = originalExclude;
158
+ if (report.header?.glibcVersionRuntime) {
159
+ family = 'glibc';
160
+ } else if (Array.isArray(report.sharedObjects) && report.sharedObjects.some(isMusl)) {
161
+ family = 'musl';
162
+ } else {
163
+ family = null;
164
+ }
165
+ return family;
166
+ }
167
+
168
+ let family: string | null | undefined;
169
+
170
+ /**
171
+ * The C library family of a machine running `osName`, as npm-install-checks 8.0.0 detects it: `glibc` or `musl` on
172
+ * Linux, from `/usr/bin/ldd` or else the process report, and null there when it cannot be told; undefined on other
173
+ * platforms. The answer is detected once per process.
174
+ */
175
+ export function libc(osName: string): string | null | undefined {
176
+ if (osName !== 'linux') {
177
+ return undefined;
178
+ }
179
+ if (family === undefined) {
180
+ family = getFamilyFromFilesystem();
181
+ if (family === undefined) {
182
+ family = getFamilyFromReport();
183
+ }
184
+ }
185
+ return family;
186
+ }
187
+
188
+ /**
189
+ * Register RPC codec for NodeRuntime, in the order the Java marker sends and receives its fields.
190
+ */
191
+ RpcCodecs.registerCodec(NodeRuntimeKind, {
192
+ async rpcReceive(before: NodeRuntime, q: RpcReceiveQueue): Promise<NodeRuntime> {
193
+ return updateIfChanged(before, {
194
+ id: await q.receive(before.id),
195
+ nodeVersion: await q.receive(before.nodeVersion),
196
+ os: await q.receive(before.os),
197
+ cpu: await q.receive(before.cpu),
198
+ libc: await q.receive(before.libc),
199
+ packageManager: await q.receive(before.packageManager),
200
+ packageManagerVersion: await q.receive(before.packageManagerVersion),
201
+ });
202
+ },
203
+
204
+ async rpcSend(after: NodeRuntime, q: RpcSendQueue): Promise<void> {
205
+ await q.getAndSend(after, a => a.id);
206
+ await q.getAndSend(after, a => a.nodeVersion);
207
+ await q.getAndSend(after, a => a.os);
208
+ await q.getAndSend(after, a => a.cpu);
209
+ await q.getAndSend(after, a => a.libc);
210
+ await q.getAndSend(after, a => a.packageManager);
211
+ await q.getAndSend(after, a => a.packageManagerVersion);
212
+ }
213
+ });