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 analyse exported endpoint methods during build #11019

Merged
merged 3 commits into from
Dec 13, 2023

Conversation

eltigerchino
Copy link
Member

@eltigerchino eltigerchino commented Nov 12, 2023

fixes #10984

Previously, the endpoint metadata would never be populated as described in the issue. However, I think it was only used in the Vercel adapter to fire off some warning

/** For a route to be considered 'valid', it must be an API route with a GET handler */
const valid_routes = builder.routes.filter((route) => route.api.methods.includes('GET'));
/** @type {Array<string>} */
const unmatched_paths = [];
for (const cron of crons) {
if (typeof cron !== 'object' || cron === null || !('path' in cron)) {
continue;
}
const { path } = cron;
if (typeof path !== 'string') {
continue;
}
if (!valid_routes.some((route) => route.pattern.test(path))) {
unmatched_paths.push(path);
}
}
if (unmatched_paths.length) {
builder.log.warn(
'\nWarning: vercel.json defines cron tasks that use paths that do not correspond to an API route with a GET handler (ignore this if the request is handled in your `handle` hook):'
);
for (const path of unmatched_paths) {
console.log(` - ${path}`);
}
console.log('');
}

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Copy link

changeset-bot bot commented Nov 12, 2023

🦋 Changeset detected

Latest commit: 2145088

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

@benmccann
Copy link
Member

would it be too hard to add a test for this one?

@eltigerchino
Copy link
Member Author

I guess I wasn't sure how to set one up. I can try to see if I can add an analyse.spec.js maybe.

if (mod[method] && ENDPOINT_METHODS.has(method)) {
api_methods.push(method);
} else if (mod.fallback) {
} else if (mod.fallback && key === 'fallback') {
Copy link
Member

Choose a reason for hiding this comment

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

Actually, I think this would be equivalent and shorter?

Suggested change
} else if (mod.fallback && key === 'fallback') {
} else if (key === 'fallback') {

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess it depends if we want to check the value of fallback for truthiness. Is there a case (or is it even possible) where someone conditionally assigns a request handler to it?
e.g., export const fallback = dev ? requestHandler : undefined;

@Rich-Harris
Copy link
Member

However, I think it was only used in the Vercel adapter to fire off some warning

IIRC the history here is that the arc.codes adapter needed to know which methods existed on each route. It was complicated and no-one was actually using it so we stopped maintaining it long before SvelteKit went stable, but kept the metadata around. Not super valuable but probably not worth killing off either

@Rich-Harris Rich-Harris merged commit 7710f6c into master Dec 13, 2023
14 checks passed
@Rich-Harris Rich-Harris deleted the fix-analyse-api-methods branch December 13, 2023 04:24
@github-actions github-actions bot mentioned this pull request Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Analyze step in kit post-build not reporting api methods correctly
3 participants