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

Integration defined middleware #8869

Merged
merged 16 commits into from
Nov 8, 2023
Merged

Integration defined middleware #8869

merged 16 commits into from
Nov 8, 2023

Conversation

matthewp
Copy link
Contributor

@matthewp matthewp commented Oct 19, 2023

Changes

Testing

  • Reusing existing middleware fixture test.

Docs

@changeset-bot
Copy link

changeset-bot bot commented Oct 19, 2023

🦋 Changeset detected

Latest commit: 7d47004

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) pr: docs A PR that includes documentation for review semver: minor Change triggers a `minor` release labels Oct 19, 2023
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

@matthewp
Copy link
Contributor Author

!preview integration-middleware

@github-actions
Copy link
Contributor

 > [email protected] release /home/runner/work/astro/astro > pnpm run build && changeset publish "--tag" "next--integration-middleware" > [email protected] build /home/runner/work/astro/astro > turbo run build --filter=astro --filter=create-astro --filter="@astrojs/*" --filter="@benchmark/*" �[2m• Packages in scope: @astrojs/alpinejs, @astrojs/cloudflare, @astrojs/internal-helpers, @astrojs/lit, @astrojs/markdoc, @astrojs/markdown-remark, @astrojs/mdx, @astrojs/netlify, @astrojs/node, @astrojs/partytown, @astrojs/preact, @astrojs/prefetch, @astrojs/prism, @astrojs/react, @astrojs/rss, @astrojs/sitemap, @astrojs/solid-js, @astrojs/svelte, @astrojs/tailwind, @astrojs/telemetry, @astrojs/underscore-redirects, @astrojs/vercel, @astrojs/vue, @benchmark/timer, astro, create-astro�[0m �[2m• Running�[0m �[2m�[1mbuild�[0m�[0m �[2min 26 packages�[0m �[2m• Remote caching enabled�[0m ::group::@astrojs/telemetry:build cache hit, suppressing logs �[2m8f791e5bb7108651�[0m ::endgroup:: ::group::@astrojs/internal-helpers:build cache hit, suppressing logs �[2mc6ad1a8f27dca66f�[0m ::endgroup:: ::group::@astrojs/prism:build cache hit, suppressing logs �[2m1fbe4acc344b9100�[0m ::endgroup:: ::group::@astrojs/markdown-remark:build cache hit, suppressing logs �[2m5ea7eda930ba6d10�[0m ::endgroup:: ::group::create-astro:build cache miss, executing �[2m2e6f5442bbb5cf44�[0m > [email protected] build /home/runner/work/astro/astro/packages/create-astro > astro-scripts build "src/index.ts" --bundle && tsc ::endgroup:: ::group::astro:build cache miss, executing �[2md433be3759a8d8fc�[0m > [email protected] build /home/runner/work/astro/astro/packages/astro > pnpm run prebuild && astro-scripts build "src/**/*.{ts,js}" && tsc && pnpm run postbuild > [email protected] prebuild /home/runner/work/astro/astro/packages/astro > astro-scripts prebuild --to-string "src/runtime/server/astro-island.ts" "src/runtime/client/{idle,load,media,only,visible}.ts" > [email protected] postbuild /home/runner/work/astro/astro/packages/astro > astro-scripts copy "src/**/*.astro" && astro-scripts copy "src/**/*.wasm" ::endgroup:: ::group::@astrojs/underscore-redirects:build cache miss, executing �[2m6ca29f989a913e09�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/underscore-redirects > astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json ::endgroup:: ::group::@astrojs/prefetch:build cache miss, executing �[2md3f85055915771ab�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/prefetch > astro-scripts build "src/**/*.ts" && tsc ::endgroup:: ::group::@benchmark/timer:build cache miss, executing �[2m22e16b694ae84b07�[0m > @benchmark/[email protected] build /home/runner/work/astro/astro/benchmark/packages/timer > astro-scripts build "src/**/*.ts" && tsc ::endgroup:: ::group::@astrojs/partytown:build cache miss, executing �[2m314c74ee473f2288�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/partytown > astro-scripts build "src/**/*.ts" && tsc ::endgroup:: ::group::@astrojs/node:build cache miss, executing �[2m509ee59772ed8a36�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/node > astro-scripts build "src/**/*.ts" && tsc ::endgroup:: ::group::@astrojs/vercel:build cache miss, executing �[2m1bdba669a4a93395�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/vercel > astro-scripts build "src/**/*.ts" && tsc ::endgroup:: ::group::@astrojs/mdx:build cache miss, executing �[2m816c2dd734f7a28e�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/mdx > astro-scripts build "src/**/*.ts" && tsc ::endgroup:: ::group::@astrojs/svelte:build cache miss, executing �[2me51f264315f8d1ac�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/svelte > astro-scripts build "src/index.ts" && astro-scripts build "src/editor.cts" --force-cjs --no-clean-dist && tsc ::endgroup:: ::group::@astrojs/vue:build cache miss, executing �[2m3eb8621f1350241a�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/vue > astro-scripts build "src/index.ts" && astro-scripts build "src/editor.cts" --force-cjs --no-clean-dist && tsc ::endgroup:: ::group::@astrojs/markdoc:build cache miss, executing �[2m221c21ce94a1a63b�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/markdoc > astro-scripts build "src/**/*.ts" && tsc ::endgroup:: ::group::@astrojs/alpinejs:build cache miss, executing �[2m561862cd2c96b61c�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/alpinejs > astro-scripts build "src/**/*.ts" && tsc ::endgroup:: ::group::@astrojs/rss:build cache miss, executing �[2m2657d0354a0bf8ff�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/astro-rss > astro-scripts build "src/**/*.ts" && tsc ::endgroup:: ::group::@astrojs/tailwind:build cache miss, executing �[2mecfd518683176792�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/tailwind > astro-scripts build "src/**/*.ts" && tsc ::endgroup:: ::group::@astrojs/preact:build cache miss, executing �[2m12682fd00162d4ce�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/preact > astro-scripts build "src/**/*.ts" && tsc ::endgroup:: ::group::@astrojs/lit:build cache miss, executing �[2m7fc5519e16b4d06e�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/lit > astro-scripts build "src/**/*.ts" && tsc ::endgroup:: ::group::@astrojs/react:build cache miss, executing �[2m64ac0151bb7a62ee�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/react > astro-scripts build "src/**/*.ts" && tsc ::endgroup:: ::group::@astrojs/solid-js:build cache miss, executing �[2mcb58d23c349707c3�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/solid > astro-scripts build "src/**/*.ts" && tsc ::endgroup:: ::group::@astrojs/sitemap:build cache miss, executing �[2m089b0b0277b6456a�[0m > @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/sitemap > astro-scripts build "src/**/*.ts" && tsc ::endgroup:: Tasks: 24 successful, 24 total Cached: 4 cached, 24 total Time: 1m9.468s 🦋 �[33mwarn�[39m �[31m===============================IMPORTANT!===============================�[39m 🦋 �[33mwarn�[39m Packages will be released under the next--integration-middleware tag 🦋 �[33mwarn�[39m �[31m----------------------------------------------------------------------�[39m 🦋 �[36minfo�[39m npm info astro 🦋 �[36minfo�[39m npm info @astrojs/prism 🦋 �[36minfo�[39m npm info @astrojs/rss 🦋 �[36minfo�[39m npm info create-astro 🦋 �[36minfo�[39m npm info @astrojs/alpinejs 🦋 �[36minfo�[39m npm info @astrojs/lit 🦋 �[36minfo�[39m npm info @astrojs/markdoc 🦋 �[36minfo�[39m npm info @astrojs/mdx 🦋 �[36minfo�[39m npm info @astrojs/node 🦋 �[36minfo�[39m npm info @astrojs/partytown 🦋 �[36minfo�[39m npm info @astrojs/preact 🦋 �[36minfo�[39m npm info @astrojs/prefetch 🦋 �[36minfo�[39m npm info @astrojs/react 🦋 �[36minfo�[39m npm info @astrojs/sitemap 🦋 �[36minfo�[39m npm info @astrojs/solid-js 🦋 �[36minfo�[39m npm info @astrojs/svelte 🦋 �[36minfo�[39m npm info @astrojs/tailwind 🦋 �[36minfo�[39m npm info @astrojs/vercel 🦋 �[36minfo�[39m npm info @astrojs/vue 🦋 �[36minfo�[39m npm info @astrojs/internal-helpers 🦋 �[36minfo�[39m npm info @astrojs/markdown-remark 🦋 �[36minfo�[39m npm info @astrojs/telemetry 🦋 �[36minfo�[39m npm info @astrojs/underscore-redirects 🦋 �[36minfo�[39m astro is being published because our local version (0.0.0-integration-middleware-20231019151221) has not been published on npm 🦋 �[33mwarn�[39m @astrojs/prism is not being published because version 3.0.0 is already published on npm 🦋 �[33mwarn�[39m @astrojs/rss is not being published because version 3.0.0 is already published on npm 🦋 �[33mwarn�[39m create-astro is not being published because version 4.3.0 is already published on npm 🦋 �[33mwarn�[39m @astrojs/alpinejs is not being published because version 0.3.1 is already published on npm 🦋 �[33mwarn�[39m @astrojs/lit is not being published because version 3.0.2 is already published on npm 🦋 �[33mwarn�[39m @astrojs/markdoc is not being published because version 0.6.0 is already published on npm 🦋 �[33mwarn�[39m @astrojs/mdx is not being published because version 1.1.2 is already published on npm 🦋 �[33mwarn�[39m @astrojs/node is not being published because version 6.0.3 is already published on npm 🦋 �[33mwarn�[39m @astrojs/partytown is not being published because version 2.0.1 is already published on npm 🦋 �[33mwarn�[39m @astrojs/preact is not being published because version 3.0.1 is already published on npm 🦋 �[33mwarn�[39m @astrojs/prefetch is not being published because version 0.4.1 is already published on npm 🦋 �[33mwarn�[39m @astrojs/react is not being published because version 3.0.3 is already published on npm 🦋 �[33mwarn�[39m @astrojs/sitemap is not being published because version 3.0.2 is already published on npm 🦋 �[33mwarn�[39m @astrojs/solid-js is not being published because version 3.0.2 is already published on npm 🦋 �[33mwarn�[39m @astrojs/svelte is not being published because version 4.0.3 is already published on npm 🦋 �[33mwarn�[39m @astrojs/tailwind is not being published because version 5.0.2 is already published on npm 🦋 �[33mwarn�[39m @astrojs/vercel is not being published because version 5.0.2 is already published on npm 🦋 �[36minfo�[39m @astrojs/vue is being published because our local version (0.0.0-integration-middleware-20231019151221) has not been published on npm 🦋 �[33mwarn�[39m @astrojs/internal-helpers is not being published because version 0.2.1 is already published on npm 🦋 �[33mwarn�[39m @astrojs/markdown-remark is not being published because version 3.3.0 is already published on npm 🦋 �[33mwarn�[39m @astrojs/telemetry is not being published because version 3.0.3 is already published on npm 🦋 �[33mwarn�[39m @astrojs/underscore-redirects is not being published because version 0.3.1 is already published on npm 🦋 �[36minfo�[39m Publishing �[36m"astro"�[39m at �[32m"0.0.0-integration-middleware-20231019151221"�[39m 🦋 �[36minfo�[39m Publishing �[36m"@astrojs/vue"�[39m at �[32m"0.0.0-integration-middleware-20231019151221"�[39m 🦋 �[32msuccess�[39m packages published successfully: 🦋 [email protected] 🦋 @astrojs/[email protected] 🦋 Creating git tags... 🦋 New tag: [email protected] 🦋 New tag: @astrojs/[email protected]

@matthewp
Copy link
Contributor Author

This can be tried out with:

npm install astro@next--integration-middleware

Note that preview releases are temporary and are only intended to test out a feature.

@matthewp matthewp marked this pull request as ready for review November 1, 2023 20:26
.changeset/khaki-glasses-raise.md Outdated Show resolved Hide resolved
Comment on lines 140 to 144
if(typeof updatedSettings.middleware[order] === 'undefined') {
throw new Error(
`The "${integration.name}" integration is trying to add middleware but did not specify an order.`
);
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what default makes the most sense, but I wouldn't expect to be required to provide order. For example, a middleware that adds a new route could really go anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, I don't like having a default when it's not obvious what the default should be. It really depends on the use-case; if you are doing something that modifies the response you want to be in pre, if you are adding locals then post is fine.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with Matthew on this one. Since the order is essential and we can't guess what the user intends to do, I think we need to force the user to choose.

packages/astro/src/@types/astro.ts Outdated Show resolved Hide resolved
packages/astro/src/core/middleware/vite-plugin.ts Outdated Show resolved Hide resolved
packages/astro/src/core/middleware/vite-plugin.ts Outdated Show resolved Hide resolved
packages/astro/src/core/middleware/vite-plugin.ts Outdated Show resolved Hide resolved
packages/astro/src/core/middleware/vite-plugin.ts Outdated Show resolved Hide resolved
packages/astro/src/core/middleware/vite-plugin.ts Outdated Show resolved Hide resolved
Comment on lines 140 to 144
if(typeof updatedSettings.middleware[order] === 'undefined') {
throw new Error(
`The "${integration.name}" integration is trying to add middleware but did not specify an order.`
);
}
Copy link
Member

Choose a reason for hiding this comment

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

I agree with Matthew on this one. Since the order is essential and we can't guess what the user intends to do, I think we need to force the user to choose.

packages/astro/src/integrations/index.ts Outdated Show resolved Hide resolved
.changeset/khaki-glasses-raise.md Outdated Show resolved Hide resolved
.changeset/khaki-glasses-raise.md Outdated Show resolved Hide resolved
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Looks great @matthewp ! Just left some comments on the changeset!

.changeset/khaki-glasses-raise.md Outdated Show resolved Hide resolved
.changeset/khaki-glasses-raise.md Outdated Show resolved Hide resolved
.changeset/khaki-glasses-raise.md Outdated Show resolved Hide resolved
.changeset/khaki-glasses-raise.md Show resolved Hide resolved
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Looks good. I'm really looking forward to having this feature shipped!

.changeset/khaki-glasses-raise.md Show resolved Hide resolved
.changeset/khaki-glasses-raise.md Outdated Show resolved Hide resolved
@matthewp matthewp merged commit f5bdfa2 into main Nov 8, 2023
14 checks passed
@matthewp matthewp deleted the int-middleware branch November 8, 2023 18:36
@astrobot-houston astrobot-houston mentioned this pull request Nov 8, 2023
natemoo-re pushed a commit that referenced this pull request Nov 22, 2023
* Rebase

* Use an empty module if there is no real middleware

* Add debug logging

* Use normalizePath

* Add a better example in the changesetp

* Update .changeset/khaki-glasses-raise.md

Co-authored-by: Bjorn Lu <[email protected]>

* Update .changeset/khaki-glasses-raise.md

Co-authored-by: Bjorn Lu <[email protected]>

* Update .changeset/khaki-glasses-raise.md

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update .changeset/khaki-glasses-raise.md

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update .changeset/khaki-glasses-raise.md

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update .changeset/khaki-glasses-raise.md

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update packages/astro/src/core/middleware/vite-plugin.ts

Co-authored-by: Emanuele Stoppa <[email protected]>

* Review comments

* oops

* Update .changeset/khaki-glasses-raise.md

Co-authored-by: Bjorn Lu <[email protected]>

---------

Co-authored-by: Bjorn Lu <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Emanuele Stoppa <[email protected]>
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) pr: docs A PR that includes documentation for review semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants