feat(rome_cli): Add JS runtime and package manager information to `rage`
MODIFY
crates/rome_cli/src/commands/rage.rs
crates/rome_cli/src/commands/rage.rs
@@ -30,6 +30,9 @@ pub(crate) fn rage(mut session: CliSession) -> Result<(), Termination> {
{EnvVarOs("ROME_LOG_DIR")}
{EnvVarOs("NO_COLOR")}
{EnvVarOs("TERM")}
+ {EnvVarOs("JS_RUNTIME_VERSION")}
+ {EnvVarOs("JS_RUNTIME_NAME")}
+ {EnvVarOs("NODE_PACKAGE_MANAGER")}
{RageConfiguration(&session.app.fs)}
{WorkspaceRage(session.app.workspace.deref())}

MODIFY
crates/rome_cli/tests/snapshots/main_commands_rage/rage_ok.snap
crates/rome_cli/tests/snapshots/main_commands_rage/rage_ok.snap
@@ -17,6 +17,9 @@ Environment:
ROME_LOG_DIR: **PLACEHOLDER**
NO_COLOR: **PLACEHOLDER**
TERM: **PLACEHOLDER**
+ JS_RUNTIME_VERSION: unset
+ JS_RUNTIME_NAME: unset
+ NODE_PACKAGE_MANAGER: unset
Rome Configuration:
Status: unset

MODIFY
crates/rome_cli/tests/snapshots/main_commands_rage/with_configuration.snap
crates/rome_cli/tests/snapshots/main_commands_rage/with_configuration.snap
@@ -27,6 +27,9 @@ Environment:
ROME_LOG_DIR: **PLACEHOLDER**
NO_COLOR: **PLACEHOLDER**
TERM: **PLACEHOLDER**
+ JS_RUNTIME_VERSION: unset
+ JS_RUNTIME_NAME: unset
+ NODE_PACKAGE_MANAGER: unset
Rome Configuration:
Status: loaded

MODIFY
crates/rome_cli/tests/snapshots/main_commands_rage/with_malformed_configuration.snap
crates/rome_cli/tests/snapshots/main_commands_rage/with_malformed_configuration.snap
@@ -27,6 +27,9 @@ Environment:
ROME_LOG_DIR: **PLACEHOLDER**
NO_COLOR: **PLACEHOLDER**
TERM: **PLACEHOLDER**
+ JS_RUNTIME_VERSION: unset
+ JS_RUNTIME_NAME: unset
+ NODE_PACKAGE_MANAGER: unset
Rome Configuration:
Status: Failed to load

MODIFY
crates/rome_cli/tests/snapshots/main_commands_rage/with_server_logs.snap
crates/rome_cli/tests/snapshots/main_commands_rage/with_server_logs.snap
@@ -17,6 +17,9 @@ Environment:
ROME_LOG_DIR: **PLACEHOLDER**
NO_COLOR: **PLACEHOLDER**
TERM: **PLACEHOLDER**
+ JS_RUNTIME_VERSION: unset
+ JS_RUNTIME_NAME: unset
+ NODE_PACKAGE_MANAGER: unset
Rome Configuration:
Status: unset

MODIFY
npm/rome/bin/rome
npm/rome/bin/rome
#!/usr/bin/env node
-const { platform, arch } = process;
+const { platform, arch, env, version, release } = process;
const PLATFORMS = {
win32: {
@@ -21,7 +21,16 @@ if (binPath) {
const result = require("child_process").spawnSync(
require.resolve(binPath),
process.argv.slice(2),
- { shell: false, stdio: "inherit" },
+ {
+ shell: false,
+ stdio: "inherit",
+ env: {
+ ...env,
+ JS_RUNTIME_VERSION: version,
+ JS_RUNTIME_NAME: release.name,
+ NODE_PACKAGE_MANAGER: detectPackageManager(),
+ },
+ },
);
if (result.error) {
@@ -37,3 +46,22 @@ if (binPath) {
);
process.exitCode = 1;
}
+
+/**
+ * NPM, Yarn, and other package manager set the `npm_config_user_agent`. It has the following format:
+ *
+ * ```
+ * "npm/8.3.0 node/v16.13.2 win32 x64 workspaces/false
+ * ```
+ *
+ * @returns The package manager string (`npm/8.3.0`) or null if the user agent string isn't set.
+ */
+function detectPackageManager() {
+ const userAgent = env.npm_config_user_agent;
+
+ if (userAgent == null) {
+ return null;
+ }
+
+ return userAgent.split(" ")[0];
+}

feat(rome_cli): Add JS runtime and package manager information to `rage` (#4021)