Skip to content

Commit

Permalink
Remove integration-specific code
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Aug 29, 2024
1 parent 8fabda7 commit 90a862f
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 46 deletions.
1 change: 0 additions & 1 deletion packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3290,7 +3290,6 @@ declare global {
server: vite.ViteDevServer;
logger: AstroIntegrationLogger;
toolbar: ReturnType<typeof getToolbarServerCommunicationHelpers>;
refreshContent?: (options: RefreshContentOptions) => Promise<void>;
}) => void | Promise<void>;
'astro:server:start': (options: {
address: AddressInfo;
Expand Down
2 changes: 0 additions & 2 deletions packages/astro/src/content/loaders/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export interface LoaderContext {
/** When running in dev, this is a filesystem watcher that can be used to trigger updates */
watcher?: FSWatcher;

/** If the loader has been triggered by an integration, this may optionally contain extra data set by that integration */
refreshContextData?: Record<string, unknown>;
entryTypes: Map<string, ContentEntryType>;
}

Expand Down
11 changes: 0 additions & 11 deletions packages/astro/src/integrations/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import type {
ContentEntryType,
DataEntryType,
HookParameters,
RefreshContentOptions,
RouteData,
RouteOptions,
} from '../@types/astro.js';
import { globalContentLayer } from '../content/content-layer.js';
import astroIntegrationActionsRouteHandler from '../actions/integration.js';
import { isActionsFilePresent } from '../actions/utils.js';
import type { SerializedSSRManifest } from '../core/app/types.js';
Expand Down Expand Up @@ -375,14 +373,6 @@ export async function runHookServerSetup({
server: ViteDevServer;
logger: Logger;
}) {
let refreshContent: undefined | ((options: RefreshContentOptions) => Promise<void>);
if (config.experimental?.contentLayer) {
refreshContent = async (options: RefreshContentOptions) => {
const contentLayer = await globalContentLayer.get();
await contentLayer?.sync(options);
};
}

for (const integration of config.integrations) {
if (integration?.hooks?.['astro:server:setup']) {
await withTakingALongTimeMsg({
Expand All @@ -392,7 +382,6 @@ export async function runHookServerSetup({
server,
logger: getLogger(integration, logger),
toolbar: getToolbarServerCommunicationHelpers(server),
refreshContent,
}),
logger,
});
Expand Down
33 changes: 1 addition & 32 deletions packages/astro/test/fixtures/content-layer/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,7 @@ import { defineConfig } from 'astro/config';
import { fileURLToPath } from 'node:url';

export default defineConfig({
integrations: [mdx(), {
name: '@astrojs/my-integration',
hooks: {
'astro:server:setup': async ({ server, refreshContent }) => {
server.middlewares.use('/_refresh', async (req, res) => {
if(req.method !== 'POST') {
res.statusCode = 405
res.end('Method Not Allowed');
return
}
let body = '';
req.on('data', chunk => {
body += chunk.toString();
});
req.on('end', async () => {
try {
const webhookBody = JSON.parse(body);
await refreshContent({
context: { webhookBody },
loaders: ['increment-loader']
});
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ message: 'Content refreshed successfully' }));
} catch (error) {
res.writeHead(500, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: 'Failed to refresh content' }));
}
});
});
}
}
}],
integrations: [mdx()],
vite: {
resolve: {
alias: {
Expand Down

0 comments on commit 90a862f

Please sign in to comment.