[ci] format
This commit is contained in:
parent
6ec040761e
commit
c84e8b8e3e
2 changed files with 26 additions and 25 deletions
|
@ -21,15 +21,15 @@ interface BuildConfig {
|
||||||
export function getAdapter(isModeDirectory: boolean): AstroAdapter {
|
export function getAdapter(isModeDirectory: boolean): AstroAdapter {
|
||||||
return isModeDirectory
|
return isModeDirectory
|
||||||
? {
|
? {
|
||||||
name: '@astrojs/cloudflare',
|
name: '@astrojs/cloudflare',
|
||||||
serverEntrypoint: '@astrojs/cloudflare/server.directory.js',
|
serverEntrypoint: '@astrojs/cloudflare/server.directory.js',
|
||||||
exports: ['onRequest', 'manifest'],
|
exports: ['onRequest', 'manifest'],
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
name: '@astrojs/cloudflare',
|
name: '@astrojs/cloudflare',
|
||||||
serverEntrypoint: '@astrojs/cloudflare/server.advanced.js',
|
serverEntrypoint: '@astrojs/cloudflare/server.advanced.js',
|
||||||
exports: ['default'],
|
exports: ['default'],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const SHIM = `globalThis.process = {
|
const SHIM = `globalThis.process = {
|
||||||
|
@ -114,7 +114,7 @@ export default function createIntegration(args?: Options): AstroIntegration {
|
||||||
if (isModeDirectory && _buildConfig.split) {
|
if (isModeDirectory && _buildConfig.split) {
|
||||||
const entryPointsURL = [..._entryPoints.values()];
|
const entryPointsURL = [..._entryPoints.values()];
|
||||||
const entryPaths = entryPointsURL.map((entry) => fileURLToPath(entry));
|
const entryPaths = entryPointsURL.map((entry) => fileURLToPath(entry));
|
||||||
const outputUrl = new URL('$astro', _buildConfig.server)
|
const outputUrl = new URL('$astro', _buildConfig.server);
|
||||||
const outputDir = fileURLToPath(outputUrl);
|
const outputDir = fileURLToPath(outputUrl);
|
||||||
|
|
||||||
await esbuild.build({
|
await esbuild.build({
|
||||||
|
@ -135,38 +135,37 @@ export default function createIntegration(args?: Options): AstroIntegration {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const outputFiles: Array<string> = (
|
const outputFiles: Array<string> = await glob(`**/*`, {
|
||||||
await glob(`**/*`, {
|
cwd: outputDir,
|
||||||
cwd: outputDir,
|
filesOnly: true,
|
||||||
filesOnly: true,
|
});
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
// move the files into the functions folder
|
// move the files into the functions folder
|
||||||
// & make sure the file names match Cloudflare syntax for routing
|
// & make sure the file names match Cloudflare syntax for routing
|
||||||
for (const outputFile of outputFiles) {
|
for (const outputFile of outputFiles) {
|
||||||
const path = outputFile.split(sep);
|
const path = outputFile.split(sep);
|
||||||
|
|
||||||
const finalSegments = path.map((segment) => segment
|
const finalSegments = path.map((segment) =>
|
||||||
.replace(/(\_)(\w+)(\_)/g, (_, __, prop) => {
|
segment
|
||||||
return `[${prop}]`;
|
.replace(/(\_)(\w+)(\_)/g, (_, __, prop) => {
|
||||||
})
|
return `[${prop}]`;
|
||||||
.replace(/(\_\-\-\-)(\w+)(\_)/g, (_, __, prop) => {
|
})
|
||||||
return `[[${prop}]]`;
|
.replace(/(\_\-\-\-)(\w+)(\_)/g, (_, __, prop) => {
|
||||||
})
|
return `[[${prop}]]`;
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
finalSegments[finalSegments.length - 1] = finalSegments[finalSegments.length - 1]
|
finalSegments[finalSegments.length - 1] = finalSegments[finalSegments.length - 1]
|
||||||
.replace('entry.', '')
|
.replace('entry.', '')
|
||||||
.replace(/(.*)\.(\w+)\.(\w+)$/g, (_, fileName, __, newExt) => {
|
.replace(/(.*)\.(\w+)\.(\w+)$/g, (_, fileName, __, newExt) => {
|
||||||
return `${fileName}.${newExt}`;
|
return `${fileName}.${newExt}`;
|
||||||
})
|
});
|
||||||
|
|
||||||
const finalDirPath = finalSegments.slice(0, -1).join(sep);
|
const finalDirPath = finalSegments.slice(0, -1).join(sep);
|
||||||
const finalPath = finalSegments.join(sep);
|
const finalPath = finalSegments.join(sep);
|
||||||
|
|
||||||
const newDirUrl = new URL(finalDirPath, functionsUrl);
|
const newDirUrl = new URL(finalDirPath, functionsUrl);
|
||||||
await fs.promises.mkdir(newDirUrl, { recursive: true })
|
await fs.promises.mkdir(newDirUrl, { recursive: true });
|
||||||
|
|
||||||
const oldFileUrl = new URL(`$astro/${outputFile}`, outputUrl);
|
const oldFileUrl = new URL(`$astro/${outputFile}`, outputUrl);
|
||||||
const newFileUrl = new URL(finalPath, functionsUrl);
|
const newFileUrl = new URL(finalPath, functionsUrl);
|
||||||
|
|
|
@ -26,7 +26,9 @@ export function createExports(manifest: SSRManifest) {
|
||||||
if (manifest.assets.has(pathname)) {
|
if (manifest.assets.has(pathname)) {
|
||||||
// we need this so the page does not error
|
// we need this so the page does not error
|
||||||
// https://developers.cloudflare.com/pages/platform/functions/advanced-mode/#set-up-a-function
|
// https://developers.cloudflare.com/pages/platform/functions/advanced-mode/#set-up-a-function
|
||||||
return (runtimeEnv.env as EventContext<unknown, string, unknown>['env']).ASSETS.fetch(request);
|
return (runtimeEnv.env as EventContext<unknown, string, unknown>['env']).ASSETS.fetch(
|
||||||
|
request
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let routeData = app.match(request, { matchNotFound: true });
|
let routeData = app.match(request, { matchNotFound: true });
|
||||||
|
|
Loading…
Reference in a new issue