backstage
backstage copied to clipboard
cli: update to support local development with Node16 module resolution
Hey, I just made a Pull Request!
Work towards #7926. This is one of the tricky pieces since the dynamic import()s in the CLI end up being treated as ESM when we switch resolution to Node16. The proposed solution is to switch the local development execution to use ts-node in ESM mode and refactor the imports.
We need to access the exported commands on the dynamically imported module via the default export. This is because we're relying on Node.js's built-in CJS compatibility layer, which is unable to find the named exports. As far as I can tell Node.js fails to do this because it tries to parse the exports from the source file rather than the transpiled code. It reads the .ts files from the filesystem and tries to parse exports.<name> = ... from those, which of course fails. A big downside of this is that type checks and runtime are inconsistent. TypeScript claims that (await import('./build.js')).command works just fine, but at runtime it does not. This still seems to be the best solution as far as I can tell.
Overall this PR is supposed to have no impact just yet, it's just making the future move to support Node16 resolution more smooth.
This is blocked by #12558
:heavy_check_mark: Checklist
Missing Changesets
The following package(s) are changed by this PR but do not have a changeset:
- @backstage/cli
See CONTRIBUTING.md for more information about how to add changesets.
Changed Packages
| Package Name | Package Path | Changeset Bump | Current Version |
|---|---|---|---|
| @backstage/cli | packages/cli | none | v0.19.0-next.1 |
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If you are the author and the PR has been closed, feel free to re-open the PR and continue the contribution!
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If you are the author and the PR has been closed, feel free to re-open the PR and continue the contribution!
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If you are the author and the PR has been closed, feel free to re-open the PR and continue the contribution!
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If you are the author and the PR has been closed, feel free to re-open the PR and continue the contribution!
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If you are the author and the PR has been closed, feel free to re-open the PR and continue the contribution!
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!
I wonder if we want to keep this hanging around or if we should create a ticket based off the moduleResolution: bundler stuff that we looked at this morning when that comes around?
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!
Closing as we'll likely end up going down the route of using the new bundler module resolution instead once that is available