Commit Graph

3262 Commits

Author SHA1 Message Date
Patrik Oldsberg e8a5a20f7d cli: split pack.ts into prepack.ts and postpack.ts
Each file now has a default export matching the CommandExecuteFn
pattern, removing the need for import wrapping in the loader.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
2026-03-02 20:49:56 +01:00
Patrik Oldsberg f867152e8b cli: fix prepack and postpack commands CJS compat
Switch the prepack and postpack commands from using a direct
dynamic import() to the execute.loader pattern, which properly
handles CJS double-wrapping of module exports.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
2026-03-02 17:33:35 +01:00
Patrik Oldsberg 03f7e74fe1 Merge pull request #33036 from backstage/rugvip/cli-execute-loader
cli: add lazy loader pattern for command execution
2026-02-27 15:36:12 +01:00
Patrik Oldsberg acb2714ca8 Merge pull request #33025 from backstage/rugvip/move-transform-tests
cli: move transform tests into the build module
2026-02-27 14:08:22 +01:00
Gabriel Dugny 3187a7a441 Merge remote-tracking branch 'origin/master' into package-workspaces 2026-02-27 12:05:03 +01:00
Patrik Oldsberg 2481126013 Remove setBlocking calls and simplify file-redirect approach
Remove fragile process.stdout._handle.setBlocking calls from CLI test
commands. Revert the preload workaround in repo-tools since the root
cause is removed.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
2026-02-27 08:48:19 +01:00
Patrik Oldsberg fab449cf9e cli: lint fix
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
2026-02-27 00:08:18 +01:00
Patrik Oldsberg d5779e525c Fix CLI report generation and --help handling for loader-based commands
Add cleye-based --help handling to all commands using the loader pattern.
Update the CLI report parser to support cleye's USAGE: and FLAGS: sections.
Revert accidental backstage.role addition to eslint-plugin.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-26 20:31:55 +01:00
Patrik Oldsberg 0d2d0f2e07 Add lazy loader pattern for CLI command execution
Extend `BackstageCommand.execute` to accept either a direct function or a
`{ loader }` object for lazy loading command implementations. Convert
several build and migrate commands to use the new pattern. Switch from
`program.parse` to `program.parseAsync` to properly await async actions.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-26 19:56:57 +01:00
Patrik Oldsberg 264159ef21 Move transform tests into the build module
Move the transform tests from packages/cli/src/tests/transforms/ into
packages/cli/src/modules/build/tests/transforms/ so that the build
module is self-contained and can eventually become its own package.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-26 13:27:30 +01:00
Patrik Oldsberg beab3cc456 cli: eliminate src/lib/ directory and last cross-module import
Split version.ts into two locations:
- Template version provider moved to modules/new/lib/version.ts
- CLI version info moved to wiring/version.ts

Remove publishPreflightCheck from repo fix command (still runs during
package prepack). Fix build module self-references to use shorter
within-module paths.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-25 23:36:30 +01:00
Patrik Oldsberg 09eb6b5187 Address further review feedback
- Rename hasYarnPlugin -> hasBackstageYarnPlugin for clarity
- Change SuccessCache.create to accept an options object

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-25 20:17:47 +01:00
Patrik Oldsberg 968570bbb5 Address review feedback
- Remove cli changeset, piggy-back on existing ones
- Rename getHasYarnPlugin -> hasYarnPlugin(workspaceDir?)
- Make SuccessCache constructor private, add static create()
- Consolidate duplicate @backstage/cli-node imports

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-25 20:17:47 +01:00
Patrik Oldsberg 3c811bf8a9 cli-node, cli: move yarnPlugin and SuccessCache to cli-node
Move `getHasYarnPlugin` and `SuccessCache` from `@backstage/cli` internal
modules to `@backstage/cli-node` as public exports, making them available
for reuse by other CLI tooling.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-25 20:17:22 +01:00
Patrik Oldsberg a611d22986 Merge pull request #33007 from backstage/rugvip/cli-split-loadCliConfig
cli: split loadCliConfig into separate build and config implementations
2026-02-25 19:52:50 +01:00
Patrik Oldsberg 4868ff07b6 Fix typeDistProject import path in pack.ts
The file was moved from maintenance to build on master, so the
cross-module import is no longer needed.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-25 17:31:30 +01:00
Patrik Oldsberg bd2c923d8e Throw error for removed migrate package-exports command
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-25 17:11:07 +01:00
Patrik Oldsberg c85ac86117 cli: split loadCliConfig into separate build and config implementations
Split the shared loadCliConfig function into two separate implementations
to remove the cross-module dependency from build to config.

The build module's version keeps the watch/streaming capability needed by
the dev server, while the config module's version is simplified to
one-shot loading since no config commands need watching.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-25 16:11:57 +01:00
Patrik Oldsberg b36a60dc45 Address review feedback
Add separate breaking changeset for the removal of `migrate package-exports`,
and fix a pre-existing bug where the restore assignments in
`createScriptOptionsParser` were swapped.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-25 15:43:26 +01:00
Patrik Oldsberg 2fcba39dea Internalize CLI lib utilities into consuming modules
Move typeDistProject.ts into the build module, duplicate optionsParser.ts
into build and lint modules, inline configOption in the build module,
and simplify the deprecated migrate package-exports command to remove
cross-module dependencies.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-25 15:43:26 +01:00
Patrik Oldsberg c7d2bf99ee Merge pull request #33001 from backstage/rugvip/cli-lockfile-consolidation
cli-node: consolidate Lockfile and versioning utilities
2026-02-25 14:51:59 +01:00
Patrik Oldsberg 5033936401 Keep versioning utilities internal to CLI migrate module
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-25 14:09:25 +01:00
Patrik Oldsberg c2b4ecc73b Merge pull request #32998 from backstage/rugvip/cli-lazy-errors-to-wiring
cli: move lazy.ts and errors.ts to wiring/
2026-02-25 13:57:17 +01:00
Patrik Oldsberg 61cb976207 Consolidate Lockfile classes: move toString() and versioning utils to cli-node
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-25 11:59:30 +01:00
Patrik Oldsberg 86c424fa8e chore(cli): move lazy.ts and errors.ts to wiring/
These are CLI framework infrastructure files that belong alongside
createCliPlugin and CliInitializer rather than in the general lib/
directory.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-25 11:43:38 +01:00
Patrik Oldsberg 825c81dcde cli: move clean and pack commands to build module
Move the `package clean`, `package prepack`, `package postpack`, and
`repo clean` commands from the internal maintenance module to the build
module, along with the publishing preflight check utility.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-25 10:36:36 +01:00
Gabriel Dugny 8ea65069f1 Merge branch 'master' into package-workspaces
Signed-off-by: Gabriel Dugny <gabriel.dugny@believe.com>

# Conflicts:
#	packages/cli-node/src/pacman/yarn/Yarn.test.ts
#	packages/cli-node/src/pacman/yarn/Yarn.ts
2026-02-25 09:11:36 +01:00
github-actions[bot] 4bd6a3a1af Version Packages (next) 2026-02-24 19:24:06 +00:00
Patrik Oldsberg 641d88cb07 Address PR review comments
- Remove cli-node/src/paths.ts compat layer, migrate all cli-node
  internal usage to import targetPaths from @backstage/cli-common
- Use single-arg overrideTargetPaths('/root') where dir === rootDir
- Scope mockDir to each describe block in bump.test.ts to avoid
  shared state issues with overrideTargetPaths
- Remove unnecessary overrideTargetPaths from plugin-manager.test.ts
- Remove stale findPaths mock from createApp.test.ts
- Use overrideTargetPaths in getWorkspaceRoot.test.ts and cli-node tests

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-23 21:01:27 +01:00
Patrik Oldsberg ebc01ef04d Add overrideTargetPaths test utility and fix rebase issues
Adds `overrideTargetPaths` to `@backstage/cli-common/testUtils` for
cleanly mocking `targetPaths` in tests without `jest.mock` or
`jest.spyOn`. Migrates all existing test mocks to use the new utility.

Also fixes translations module imports broken by the rebase.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-23 17:25:31 +01:00
Patrik Oldsberg 553e727d5f Fix lint errors: add eslint-disable for __dirname, fix no-use-before-define
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-23 14:44:11 +01:00
Patrik Oldsberg 6fa63d411f Fix prettier formatting
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-23 14:44:11 +01:00
Patrik Oldsberg 07816d67f3 Address PR review comments
- Refactor targetPaths/findOwnPaths to class-based implementations with
  unified caching and .dir/.rootDir properties alongside resolve methods
- Replace jest.mock with jest.spyOn in plugin-manager.test.ts
- Remove paths compatibility wrapper from repo-tools, migrate all internal
  consumers to use targetPaths from @backstage/cli-common directly
- Fix changeset package name (@techdocs/cli not @backstage/techdocs-cli)
- Add migration examples to cli-common changeset
- Update API report for cli-common

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-23 14:44:11 +01:00
Patrik Oldsberg 70fc178697 Replace findPaths with targetPaths and findOwnPaths
Split the path resolution API in @backstage/cli-common into
targetPaths (cwd-based singleton) and findOwnPaths (package-relative).
Migrate all consumers across the repo away from the deprecated findPaths.

Rename TargetPaths/OwnPaths properties to resolve/resolveRoot,
removing the redundant type prefix from property names.

Make findOwnPaths calls lazy in modules - called inside functions
rather than at module scope.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-23 14:44:10 +01:00
Patrik Oldsberg 29e91e9159 Give each CLI module its own paths instead of importing from lib/
Split the paths API in @backstage/cli-common into targetPaths (a lazily
initialized singleton for cwd-based paths) and findOwnPaths (a cached function
for package-relative paths). Most CLI module files only need target paths, which
can now be imported directly without __dirname. The few files that need own paths
use findOwnPaths(__dirname).

Added hierarchical caching to findOwnDir so the filesystem walk only happens
once per package. targetPaths re-resolves automatically if process.cwd() changes.

The deprecated findPaths function is preserved for backward compatibility,
delegating to the new primitives internally.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-23 14:44:10 +01:00
Patrik Oldsberg 56bd494b0c Give each CLI module its own paths instead of importing from lib/
Each module file that needs paths now calls findPaths(__dirname) directly from
@backstage/cli-common. This removes the coupling between modules and lib/paths,
and will continue to work when modules are extracted into separate packages since
each package's __dirname resolves to its own root.

Added hierarchical caching to findOwnDir in cli-common so that the filesystem
walk only happens once per package - subsequent calls from sibling directories
hit the cache at a common ancestor.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-23 14:44:10 +01:00
Patrik Oldsberg 158bfe8a69 Give each CLI module its own paths instead of importing from lib/
Each module now has a local paths.ts that calls findPaths(__dirname) directly.
This makes modules fully independent of lib/paths.ts, and the pattern will
continue to work when modules are extracted into separate packages since each
package's __dirname will resolve to its own root.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-23 14:44:10 +01:00
Patrik Oldsberg ce676fea2f Merge pull request #32904 from backstage/rugvip/translation-export-import
cli: add translations export and import commands
2026-02-23 13:18:03 +01:00
Patrik Oldsberg f467a4126e Return object from runWorkerQueueThreads
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-23 11:38:23 +01:00
Patrik Oldsberg 1dfc3436d9 cli: address review feedback from freben
Fix whitespace alignment in CLI command summary, improve export command
description to clarify it operates from an app context, and update the
corresponding docs section.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-23 01:05:15 +01:00
Patrik Oldsberg 4f0c7ec86a Address PR review feedback
- Rename runParallelWorkers to runConcurrentTasks, return void
- Rename ParallelWorkerOptions to ConcurrentTasksOptions
- Rename parallelismFactor to concurrencyFactor
- Remove unused runWorkerThreads and WorkerThreadsOptions
- Rename workerData to context in WorkerQueueThreadsOptions
- Drop threadCount from public API types
- Rename env var to BACKSTAGE_CLI_CONCURRENCY
- Make cli-node changeset a patch

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-23 00:41:17 +01:00
Gabriel Dugny 0e5fd0fd27 Revert most changes
Signed-off-by: Gabriel Dugny <gabriel.dugny@believe.com>
2026-02-22 17:07:00 +01:00
Gabriel Dugny a9d23c4a32 fix: Support workspaces in CLIs
Signed-off-by: Gabriel Dugny <gabriel.dugny@believe.com>
2026-02-22 16:50:55 +01:00
Patrik Oldsberg 649d3ca3b6 Remove dead parallelism options and narrow public API
The parallelism fields on bundler types (BundlingOptions, BuildOptions,
BackendBundlingOptions) and createDistWorkspace Options were defined but
never read — fully dead code. Likewise the parallelismSetting option on
ParallelWorkerOptions was never passed by any caller.

Also narrows the cli-node public API to only export the three runner
functions and their option types, keeping getEnvironmentParallelism and
parseParallelismOption as internal utilities.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-22 16:49:55 +01:00
Patrik Oldsberg 06c2015e5b Move parallel worker utilities to @backstage/cli-node
Moves `runParallelWorkers`, `runWorkerQueueThreads`, `runWorkerThreads`,
`parseParallelismOption`, and `getEnvironmentParallelism` from the CLI
internal lib to the shared `@backstage/cli-node` package.

This is part of the ongoing effort to make CLI modules independent of
each other and the shared lib code.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-22 16:19:49 +01:00
Patrik Oldsberg eeb74ffe79 Merge pull request #32934 from soapraj/soapraj/bump-bfj-v9
cli: bump bfj dependency from ^8.0.0 to ^9.0.2
2026-02-21 17:33:13 +01:00
Patrik Oldsberg bba2e496a6 Move single-consumer lib files into the build module
Moved `entryPoints.ts` and `role.ts` (+ test) from the shared `src/lib/`
directory into `src/modules/build/lib/`, since the build module is their
only consumer. This is part of making CLI modules independent of each
other and of shared code outside the modules.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
2026-02-20 23:38:58 +01:00
Fredrik Adelöw d95cf37ce3 Merge pull request #32583 from Believe-SA/commander-14
chore: update dependency commander to v14
2026-02-20 21:04:31 +01:00
Raghunandan Balachandran 5e10165839 cli: bump bfj dependency from ^8.0.0 to ^9.0.2
The only usage of bfj in @backstage/cli is `bfj.write(path, data)` in
bundle.ts for writing bundle-stats.json. The write API is unchanged in
v9 and v9.0.0/v9.0.1 are deprecated, so the range starts at ^9.0.2.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Raghunandan Balachandran <raghunandan@spotify.com>
2026-02-20 10:57:52 +01:00
renovate[bot] 092b41f397 chore(deps): update dependency webpack to ~5.105.0
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-02-19 09:16:46 +00:00