Skip to content
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

fix: correctly emit middleware file name #7427

Merged
merged 7 commits into from
Jun 20, 2023

Conversation

ematipico
Copy link
Member

Changes

The emission of the middleware file during the build still needed to be corrected. The code was working as expected, but the middleware.mjs wasn't emitted as expected, so I had to refactor how the plugin-middleware.ts works.

Notable changes:

  • the middleware plugin is now a virtual module;
  • the plugin must always emit correct code, even when no middleware exists. Because of that, when there's no middleware file present on file system, the plugin emits "no-op" code;
  • the previous code was emitting the middleware code using the wild-card import/export e.g. import * as middleware. This wasn't ideal. When doing so, rollup creates a new export, which could cause some issue in the future;
  • now the middleware wrapper is not present anymore, and because of that, I had to review the types inside the code;

This change is needed for other adapters to pick up the emitted code in a predictable way.

Testing

Current tests should pass

Docs

N/A

@changeset-bot
Copy link

changeset-bot bot commented Jun 20, 2023

🦋 Changeset detected

Latest commit: 75957fd

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope) labels Jun 20, 2023
@ematipico ematipico force-pushed the refactor/middleware-better-name branch from 5f95f0b to f45f721 Compare June 20, 2023 10:23
@github-actions github-actions bot removed the pkg: integration Related to any renderer integration (scope) label Jun 20, 2023
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple suggestions below to make it more Rollup-style. In the future, I think we can also look into using this.emitFile to emit a new chunk instead, so we don't have to specify a rollup input and configure entryFileNames

@ematipico ematipico requested a review from bluwy June 20, 2023 14:38
@ematipico ematipico requested a review from a team as a code owner June 20, 2023 14:49
@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Jun 20, 2023
@ematipico
Copy link
Member Author

Couple suggestions below to make it more Rollup-style. In the future, I think we can also look into using this.emitFile to emit a new chunk instead, so we don't have to specify a rollup input and configure entryFileNames

Would that work? I would aim to emit an entry point, not a chunk.

@ematipico ematipico force-pushed the refactor/middleware-better-name branch 2 times, most recently from 4039318 to 59f594d Compare June 20, 2023 14:57
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice the new refactor looks great now.

Would that work? I would aim to emit an entry point, not a chunk.

It should be possible to be used as an entrypoint too as long as you call emitFile with preserveSignatures: 'strict'

packages/integrations/vercel/src/serverless/adapter.ts Outdated Show resolved Hide resolved
@ematipico ematipico force-pushed the refactor/middleware-better-name branch from 59f594d to 6a5d029 Compare June 20, 2023 15:12
@github-actions github-actions bot removed the pkg: integration Related to any renderer integration (scope) label Jun 20, 2023
@ematipico ematipico force-pushed the refactor/middleware-better-name branch from 6a5d029 to 75957fd Compare June 20, 2023 15:13
@ematipico ematipico merged commit e314a04 into main Jun 20, 2023
@ematipico ematipico deleted the refactor/middleware-better-name branch June 20, 2023 16:32
@astrobot-houston astrobot-houston mentioned this pull request Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants