-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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(astrojs/cloudflare): SSR split file renaming misses ts endpoints #7555
fix(astrojs/cloudflare): SSR split file renaming misses ts endpoints #7555
Conversation
🦋 Changeset detectedLatest commit: 45c39e5 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 |
return (runtimeEnv.env as unknown & { | ||
ASSETS: { | ||
fetch: typeof fetch; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is already done for advanced
mode but was missing for directroy
mode. please also note that I'll remove the type assertion on the Astro.locals
PR, where I refactored the EventContext
typing
for (const outputFile of outputFiles) { | ||
|
||
// split the path into an array | ||
const path = outputFile.split(sep); | ||
|
||
// replace dynamic path with [path] | ||
const pathWithDynamics = path.map((segment) => segment.replace(/(\_)(\w+)(\_)/g, (_, __, prop) => { | ||
return `[${prop}]`; | ||
})); | ||
|
||
// replace nested dynamic path with [[path]] | ||
const pathWithNestedDynamics = pathWithDynamics.map((segment) => segment.replace(/(\_\-\-\-)(\w+)(\_)/g, (_, __, prop) => { | ||
return `[[${prop}]]`; | ||
})) | ||
|
||
// remove original file extension | ||
const pathReversed = pathWithNestedDynamics.reverse(); | ||
pathReversed[0] = pathReversed[0] | ||
.replace('entry.', '') | ||
.replace(/(.*)\.(\w+)\.(\w+)$/g, (_, fileName, oldExt, newExt) => { | ||
return `${fileName}.${newExt}`; | ||
}) | ||
|
||
const finalSegments = pathReversed.reverse(); | ||
const finalDirPath = finalSegments.slice(0, -1).join('/'); | ||
const finalPath = finalSegments.join('/'); | ||
|
||
const newDirUrl = new URL(finalDirPath, functionsUrl); | ||
await fs.promises.mkdir(newDirUrl, { recursive: true }) | ||
|
||
const oldFileUrl = new URL(`$astro/${outputFile}`, outputUrl); | ||
const newFileUrl = new URL(finalPath, functionsUrl); | ||
await fs.promises.rename(oldFileUrl, newFileUrl); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop has a lot of memory allocation, let me know if I should consolidate the steps into more abstract steps?
@ematipico @matthewp
fix bug for cloudflare assets redirect fix bug for cloudflare assets redirect fix bug for cloudflare assets redirect fix bug for cloudflare assets redirect fix bug for cloudflare assets redirect fix bug for cloudflare assets redirect fix bug for cloudflare assets redirect fix bug for cloudflare assets redirect
had to redo the PR, due to git history conflicts: #7568 |
Changes
ts
endpoint files are not renamed to .js after bundle stepTesting
Docs