-
Notifications
You must be signed in to change notification settings - Fork 84
Add Rush support (for monorepos) #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
reiniercriel
merged 19 commits into
AikidoSec:main
from
mcmeeking:feature/add-rush-monorepo-support
May 12, 2026
Merged
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5690e55
Add rush command wrapper and tests
mcmeeking 6f976f6
Address PR comments
mcmeeking f26cdab
Merge branch 'main' into feature/add-rush-monorepo-support
mcmeeking 178b8a4
Merge branch 'main' into feature/add-rush-monorepo-support
mcmeeking 84346fd
Merge branch 'main' into feature/add-rush-monorepo-support
mcmeeking 5cf2ffe
Merge branch 'main' into feature/add-rush-monorepo-support
mcmeeking 98a1ba7
Add rushx support too
mcmeeking 08ae1ef
Pull parsing logic into distinct file and remove invalid continue
mcmeeking 5f56114
Add e2e tests
mcmeeking 55f2123
Remove the normalisation bits added in error
mcmeeking 28132ba
Merge branch 'main' into feature/add-rush-monorepo-support
mcmeeking 7ce44b4
Remove the unecessary proxy setting
mcmeeking 26f1dfb
Use the standard install command for rush
mcmeeking e891d1a
Update e2e suite to cover supported package managers
mcmeeking 5f0ad7e
Address e2e suite failures
mcmeeking 25d966b
Switch to using the versions from the CI matrix
mcmeeking d812231
Merge branch 'main' into feature/add-rush-monorepo-support
mcmeeking c93f192
Skip min safe age to allow brand new PNPM boostrap
mcmeeking fde0003
Fix expected format to account for retries
mcmeeking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { main } from "../src/main.js"; | ||
| import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js"; | ||
| import { setEcoSystem, ECOSYSTEM_JS } from "../src/config/settings.js"; | ||
|
|
||
| setEcoSystem(ECOSYSTEM_JS); | ||
| const packageManagerName = "rush"; | ||
| initializePackageManager(packageManagerName); | ||
|
|
||
| (async () => { | ||
| var exitCode = await main(process.argv.slice(2)); | ||
| process.exit(exitCode); | ||
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { main } from "../src/main.js"; | ||
| import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js"; | ||
| import { setEcoSystem, ECOSYSTEM_JS } from "../src/config/settings.js"; | ||
|
|
||
| setEcoSystem(ECOSYSTEM_JS); | ||
| const packageManagerName = "rushx"; | ||
| initializePackageManager(packageManagerName); | ||
|
|
||
| (async () => { | ||
| var exitCode = await main(process.argv.slice(2)); | ||
| process.exit(exitCode); | ||
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
packages/safe-chain/src/packagemanager/rush/createRushPackageManager.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| import { runRushCommand } from "./runRushCommand.js"; | ||
| import { resolvePackageVersion } from "../../api/npmApi.js"; | ||
|
|
||
| /** | ||
| * @returns {import("../currentPackageManager.js").PackageManager} | ||
| */ | ||
| export function createRushPackageManager() { | ||
| return { | ||
| runCommand: (args) => runRushCommand("rush", args), | ||
| // We pre-scan rush add commands and rely on MITM for install/update flows. | ||
| isSupportedCommand: (args) => getRushCommand(args) === "add", | ||
| getDependencyUpdatesForCommand: scanRushAddCommand, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * @param {string[]} args | ||
| * @returns {Promise<import("../currentPackageManager.js").GetDependencyUpdatesResult[]>} | ||
| */ | ||
| async function scanRushAddCommand(args) { | ||
| if (getRushCommand(args) !== "add") { | ||
| return []; | ||
| } | ||
|
|
||
| const parsedSpecs = extractRushAddPackageSpecs(args) | ||
| .map((spec) => parsePackageSpec(spec)) | ||
| .filter((spec) => spec !== null); | ||
|
|
||
| const resolvedVersions = await Promise.all( | ||
| parsedSpecs.map(async (parsed) => { | ||
| const exactVersion = await resolvePackageVersion(parsed.name, parsed.version); | ||
| return { | ||
| parsed, | ||
| exactVersion, | ||
| }; | ||
| }), | ||
| ); | ||
|
|
||
| const changes = []; | ||
| for (const resolved of resolvedVersions) { | ||
| if (!resolved.exactVersion) { | ||
| continue; | ||
| } | ||
|
|
||
| changes.push({ | ||
| name: resolved.parsed.name, | ||
| version: resolved.exactVersion, | ||
| type: "add", | ||
| }); | ||
| } | ||
|
|
||
| return changes; | ||
| } | ||
|
|
||
| /** | ||
| * @param {string[]} args | ||
| * @returns {string | undefined} | ||
| */ | ||
| function getRushCommand(args) { | ||
| if (!args || args.length === 0) { | ||
| return undefined; | ||
| } | ||
|
|
||
| return args[0]?.toLowerCase(); | ||
| } | ||
|
|
||
| /** | ||
| * @param {string[]} args | ||
| * @returns {string[]} | ||
| */ | ||
| function extractRushAddPackageSpecs(args) { | ||
| const packageSpecs = []; | ||
|
|
||
| for (let i = 1; i < args.length; i++) { | ||
| const arg = args[i]; | ||
| if (!arg) { | ||
| continue; | ||
| } | ||
|
|
||
| if (arg === "--package" || arg === "-p") { | ||
| const next = args[i + 1]; | ||
| if (next && !next.startsWith("-")) { | ||
| packageSpecs.push(next); | ||
| i += 1; | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
| if (arg.startsWith("--package=")) { | ||
| const value = arg.slice("--package=".length); | ||
| if (value) { | ||
| packageSpecs.push(value); | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
|
mcmeeking marked this conversation as resolved.
Outdated
|
||
| if (!arg.startsWith("-")) { | ||
| packageSpecs.push(arg); | ||
| } | ||
| } | ||
|
|
||
| return packageSpecs; | ||
| } | ||
|
|
||
| /** | ||
| * @param {string} spec | ||
| * @returns {{name: string, version: string | null} | null} | ||
| */ | ||
| function parsePackageSpec(spec) { | ||
| const value = removeAlias(spec.trim()); | ||
| if (!value) { | ||
| return null; | ||
| } | ||
|
|
||
| const lastAtIndex = value.lastIndexOf("@"); | ||
| if (lastAtIndex > 0) { | ||
| return { | ||
| name: value.slice(0, lastAtIndex), | ||
| version: value.slice(lastAtIndex + 1), | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| name: value, | ||
| version: null, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * @param {string} spec | ||
| * @returns {string} | ||
| */ | ||
| function removeAlias(spec) { | ||
| const aliasIndex = spec.indexOf("@npm:"); | ||
| if (aliasIndex !== -1) { | ||
| return spec.slice(aliasIndex + 5); | ||
| } | ||
|
|
||
| return spec; | ||
| } | ||
66 changes: 66 additions & 0 deletions
66
packages/safe-chain/src/packagemanager/rush/createRushPackageManager.spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { test, mock } from "node:test"; | ||
| import assert from "node:assert"; | ||
|
|
||
| test("createRushPackageManager", async (t) => { | ||
| mock.module("../../api/npmApi.js", { | ||
| namedExports: { | ||
| resolvePackageVersion: async (name, version) => { | ||
| if (name === "safe-chain-test") { | ||
| return "0.0.1-security"; | ||
| } | ||
|
|
||
| if (name === "@scope/tool") { | ||
| return version || "2.0.0"; | ||
| } | ||
|
|
||
| return null; | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| try { | ||
| const { createRushPackageManager } = await import("./createRushPackageManager.js"); | ||
|
|
||
| await t.test("should create package manager with required interface", () => { | ||
| const pm = createRushPackageManager(); | ||
|
|
||
| assert.ok(pm); | ||
| assert.strictEqual(typeof pm.runCommand, "function"); | ||
| assert.strictEqual(typeof pm.isSupportedCommand, "function"); | ||
| assert.strictEqual(typeof pm.getDependencyUpdatesForCommand, "function"); | ||
| }); | ||
|
|
||
| await t.test("should scan rush add commands", () => { | ||
| const pm = createRushPackageManager(); | ||
|
|
||
| assert.strictEqual(pm.isSupportedCommand(["add", "--package", "safe-chain-test"]), true); | ||
| assert.strictEqual(pm.isSupportedCommand(["install"]), false); | ||
| }); | ||
|
|
||
| await t.test("should parse rush add package specs and resolve versions", async () => { | ||
| const pm = createRushPackageManager(); | ||
|
|
||
| const changes = await pm.getDependencyUpdatesForCommand([ | ||
| "add", | ||
| "--package", | ||
| "safe-chain-test", | ||
| "--package=@scope/tool@1.2.3", | ||
| ]); | ||
|
|
||
| assert.deepStrictEqual(changes, [ | ||
| { name: "safe-chain-test", version: "0.0.1-security", type: "add" }, | ||
| { name: "@scope/tool", version: "1.2.3", type: "add" }, | ||
| ]); | ||
| }); | ||
|
|
||
| await t.test("should return no changes for non-add commands", async () => { | ||
| const pm = createRushPackageManager(); | ||
|
|
||
| const changes = await pm.getDependencyUpdatesForCommand(["install"]); | ||
|
|
||
| assert.deepStrictEqual(changes, []); | ||
| }); | ||
| } finally { | ||
| mock.reset(); | ||
| } | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.