backstage icon indicating copy to clipboard operation
backstage copied to clipboard

cli: update to support local development with Node16 module resolution

Open Rugvip opened this issue 3 years ago • 4 comments

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

  • [ ] A changeset describing the change and affected packages. (more info)
  • [ ] Added or updated documentation
  • [ ] Tests for new functionality and regression tests for bug fixes
  • [ ] Screenshots attached (for UI changes)
  • [x] All your commits have a Signed-off-by line in the message. (more info)

Rugvip avatar Aug 19 '22 09:08 Rugvip

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

github-actions[bot] avatar Aug 19 '22 09:08 github-actions[bot]

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!

github-actions[bot] avatar Aug 26 '22 09:08 github-actions[bot]

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!

github-actions[bot] avatar Sep 07 '22 09:09 github-actions[bot]

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!

github-actions[bot] avatar Sep 21 '22 21:09 github-actions[bot]

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!

github-actions[bot] avatar Oct 04 '22 07:10 github-actions[bot]

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!

github-actions[bot] avatar Oct 13 '22 11:10 github-actions[bot]

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!

github-actions[bot] avatar Oct 31 '22 20:10 github-actions[bot]

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!

github-actions[bot] avatar Nov 08 '22 00:11 github-actions[bot]

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!

github-actions[bot] avatar Nov 15 '22 08:11 github-actions[bot]

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!

github-actions[bot] avatar Nov 26 '22 15:11 github-actions[bot]

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!

github-actions[bot] avatar Dec 04 '22 08:12 github-actions[bot]

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!

github-actions[bot] avatar Dec 27 '22 14:12 github-actions[bot]

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?

benjdlambert avatar Dec 27 '22 15:12 benjdlambert

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!

github-actions[bot] avatar Jan 03 '23 16:01 github-actions[bot]

Closing as we'll likely end up going down the route of using the new bundler module resolution instead once that is available

Rugvip avatar Jan 07 '23 14:01 Rugvip