@alteran/astro 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -62,6 +62,7 @@ export default function alteran(options = {}) {
62
62
 
63
63
  const middlewareEntrypoint = resolvePackagePath('./src/middleware.ts');
64
64
  const serverEntrypoint = resolvePackagePath('./src/_worker.ts');
65
+ const cloudflareServerAdapter = resolvePackagePath('./src/entrypoints/server.ts');
65
66
 
66
67
  const routes = CORE_ROUTES.slice();
67
68
  if (includeRootEndpoint) {
@@ -79,6 +80,60 @@ export default function alteran(options = {}) {
79
80
  updateConfig({ output: 'server' });
80
81
  }
81
82
 
83
+ const existingAlias = config.vite?.resolve?.alias ?? [];
84
+ const aliasArray = Array.isArray(existingAlias)
85
+ ? existingAlias.slice()
86
+ : Object.entries(existingAlias).map(([find, replacement]) => ({ find, replacement }));
87
+
88
+ const hasCloudflareAlias = aliasArray.some(
89
+ (entry) => entry && entry.find === '@astrojs/cloudflare/entrypoints/server.js'
90
+ );
91
+
92
+ if (!hasCloudflareAlias) {
93
+ aliasArray.push({
94
+ find: '@astrojs/cloudflare/entrypoints/server.js',
95
+ replacement: cloudflareServerAdapter,
96
+ });
97
+ }
98
+
99
+ const vitePlugins = Array.isArray(config.vite?.plugins)
100
+ ? config.vite.plugins.slice().filter(Boolean)
101
+ : [];
102
+
103
+ vitePlugins.push({
104
+ name: 'alteran-sequencer-export',
105
+ enforce: 'post',
106
+ apply: 'build',
107
+ transform(code, id) {
108
+ if (!id.includes('@astrojs-ssr-virtual-entry')) return null;
109
+ if (!code.includes('const _exports = createExports')) return null;
110
+ if (code.includes("const Sequencer = _exports['Sequencer'];")) return null;
111
+
112
+ const replacedInit = code.replace(
113
+ 'const __astrojsSsrVirtualEntry = _exports.default;',
114
+ "const Sequencer = _exports['Sequencer'];\nconst __astrojsSsrVirtualEntry = _exports.default;"
115
+ );
116
+
117
+ if (replacedInit === code) return null;
118
+
119
+ const replacedExport = replacedInit.replace(
120
+ 'export { __astrojsSsrVirtualEntry as default, pageMap };',
121
+ 'export { Sequencer, __astrojsSsrVirtualEntry as default, pageMap };'
122
+ );
123
+
124
+ return { code: replacedExport, map: null };
125
+ },
126
+ });
127
+
128
+ updateConfig({
129
+ vite: {
130
+ resolve: {
131
+ alias: aliasArray,
132
+ },
133
+ plugins: vitePlugins,
134
+ },
135
+ });
136
+
82
137
  if (injectServerEntry) {
83
138
  if (config.build?.serverEntry && config.build.serverEntry !== serverEntrypoint) {
84
139
  logger.info(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alteran/astro",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Astro integration for running a Cloudflare-hosted Bluesky PDS with Alteran.",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",
package/src/_worker.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { createPdsFetchHandler } from './worker/runtime';
2
+ import { Sequencer } from './worker/sequencer';
2
3
 
3
4
  const fetch = createPdsFetchHandler();
4
5
 
5
6
  export default { fetch };
6
7
 
7
- export { Sequencer } from './worker/sequencer';
8
+ export { Sequencer };
@@ -0,0 +1,19 @@
1
+ import type { SSRManifest } from 'astro';
2
+ import { App } from 'astro/app';
3
+ import { handle } from '@astrojs/cloudflare/handler';
4
+ import { Sequencer } from '../worker/sequencer';
5
+
6
+ export function createExports(manifest: SSRManifest) {
7
+ const app = new App(manifest);
8
+ const fetch = async (request: Request, env: unknown, context: unknown) => {
9
+ // Delegate to the Cloudflare adapter handler while preserving Alteran additions.
10
+ return await handle(manifest, app, request, env as any, context as any);
11
+ };
12
+
13
+ return {
14
+ default: { fetch },
15
+ Sequencer,
16
+ };
17
+ }
18
+
19
+ export { Sequencer };