Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
feat(rome_cli): Add JS runtime and package manager information to `ra…
Browse files Browse the repository at this point in the history
…ge` (#4021)
  • Loading branch information
MichaReiser authored Dec 9, 2022
1 parent d56f3de commit 2d1a0ef
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
3 changes: 3 additions & 0 deletions crates/rome_cli/src/commands/rage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 30 additions & 2 deletions npm/rome/bin/rome
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
const { platform, arch } = process;
const { platform, arch, env, version, release } = process;

const PLATFORMS = {
win32: {
Expand All @@ -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) {
Expand All @@ -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];
}

0 comments on commit 2d1a0ef

Please sign in to comment.