@ruvyxa/adapter-firebase 1.1.2 → 1.1.4
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/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -24
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +37 -22
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAgD,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAgD,MAAM,cAAc,CAAA;AAgBzF,0DAA0D;AAC1D,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,CAAA;AAElE,oEAAoE;AACpE,MAAM,WAAW,sBAAsB;IACrC,6EAA6E;IAC7E,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;;OAKG;IACH,OAAO,CAAC,EAAE,eAAe,CAAA;IACzB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,sFAAsF;AACtF,wBAAgB,QAAQ,CAAC,OAAO,GAAE,sBAA2B,GAAG,OAAO,CAwKtE;eAmHc,QAAQ"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CLIENT_BUNDLE_PREFIX, clientBuildOutput, DEFAULT_SECURITY_HEADERS, IMMUTABLE_CACHE_CONTROL, nonPublishableStrategies, projectRelativeOutDir, PUBLIC_ASSET_CACHE_CONTROL, publicAssetGlobs, runtimeBuildPolicy, validateBuildContext, } from '@ruvyxa/core';
|
|
1
|
+
import { CLIENT_BUNDLE_PREFIX, clientBuildOutput, documentCacheOptionsSource, isrTemporaryCacheSource, DEFAULT_SECURITY_HEADERS, IMMUTABLE_CACHE_CONTROL, nonPublishableStrategies, projectRelativeOutDir, PUBLIC_ASSET_CACHE_CONTROL, publicAssetGlobs, runtimeBuildPolicy, validateBuildContext, } from '@ruvyxa/core';
|
|
2
2
|
/** Create a Firebase Hosting adapter backed by a second-generation HTTPS function. */
|
|
3
3
|
export function firebase(options = {}) {
|
|
4
4
|
const functionName = options.functionName ?? 'ruvyxaServer';
|
|
@@ -106,7 +106,7 @@ export function firebase(options = {}) {
|
|
|
106
106
|
{
|
|
107
107
|
kind: 'function',
|
|
108
108
|
path: 'deploy/firebase/functions',
|
|
109
|
-
handlerSource: firebaseHandlerSource(functionName, region, runtimeBuildPolicy(ctx)),
|
|
109
|
+
handlerSource: firebaseHandlerSource(functionName, region, runtimeBuildPolicy(ctx), ctx.deployManifest?.buildId ?? ''),
|
|
110
110
|
},
|
|
111
111
|
{
|
|
112
112
|
kind: 'file',
|
|
@@ -142,11 +142,12 @@ export function firebase(options = {}) {
|
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
144
|
/** Firebase Functions v2 wrapper around the shared Ruvyxa serverless handler. */
|
|
145
|
-
function firebaseHandlerSource(functionName, region, runtimePolicy) {
|
|
145
|
+
function firebaseHandlerSource(functionName, region, runtimePolicy, buildId) {
|
|
146
146
|
return `import { onRequest } from 'firebase-functions/v2/https';
|
|
147
147
|
import { createHandler, prerenderRelativePath } from './serverless-handler.mjs';
|
|
148
|
-
import { applyPluginHttp, loadActionModule, loadRouteModule } from './route-modules.mjs';
|
|
148
|
+
import { applyPluginHttp, documentCacheHandler, loadActionModule, loadRouteModule } from './route-modules.mjs';
|
|
149
149
|
import manifest from './manifest.mjs';
|
|
150
|
+
import { createHash } from 'node:crypto';
|
|
150
151
|
import { readFileSync, writeFileSync, mkdirSync, statSync } from 'node:fs';
|
|
151
152
|
import os from 'node:os';
|
|
152
153
|
import path from 'node:path';
|
|
@@ -156,7 +157,7 @@ import { pipeline } from 'node:stream/promises';
|
|
|
156
157
|
const runtimePolicy = ${JSON.stringify(runtimePolicy ?? {})};
|
|
157
158
|
|
|
158
159
|
const prerenderDir = path.join(import.meta.dirname, 'prerender');
|
|
159
|
-
|
|
160
|
+
${isrTemporaryCacheSource(buildId)}
|
|
160
161
|
|
|
161
162
|
const readEntry = (htmlPath, revalidate) => {
|
|
162
163
|
const html = readFileSync(htmlPath, 'utf8');
|
|
@@ -164,6 +165,30 @@ const readEntry = (htmlPath, revalidate) => {
|
|
|
164
165
|
return { html, stale };
|
|
165
166
|
};
|
|
166
167
|
|
|
168
|
+
// Named rather than passed inline, so a project that declares \`cache.handler\`
|
|
169
|
+
// can stand its own store in front of these. See \`documentCacheOptionsSource\`
|
|
170
|
+
// in \`@ruvyxa/core\`; the registry supplies \`documentCacheHandler\`.
|
|
171
|
+
const platformReadPrerendered = (pathname, revalidate = 60) => {
|
|
172
|
+
const relative = prerenderRelativePath(pathname);
|
|
173
|
+
if (relative === null) return null;
|
|
174
|
+
for (const directory of [isrCacheDir, prerenderDir]) {
|
|
175
|
+
try {
|
|
176
|
+
return readEntry(path.join(directory, relative), revalidate);
|
|
177
|
+
} catch {
|
|
178
|
+
// try the deploy-time prerender output after the runtime cache
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return null;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const platformWritePrerendered = (pathname, html) => {
|
|
185
|
+
const relative = prerenderRelativePath(pathname);
|
|
186
|
+
if (relative === null) return;
|
|
187
|
+
const htmlPath = path.join(isrCacheDir, relative);
|
|
188
|
+
mkdirSync(path.dirname(htmlPath), { recursive: true });
|
|
189
|
+
writeFileSync(htmlPath, html, 'utf8');
|
|
190
|
+
};
|
|
191
|
+
|
|
167
192
|
const handler = createHandler({
|
|
168
193
|
routes: manifest.routes,
|
|
169
194
|
middleware: runtimePolicy.middleware,
|
|
@@ -173,25 +198,7 @@ const handler = createHandler({
|
|
|
173
198
|
importAction: loadActionModule,
|
|
174
199
|
pluginHttp: applyPluginHttp,
|
|
175
200
|
security: runtimePolicy.security,
|
|
176
|
-
|
|
177
|
-
const relative = prerenderRelativePath(pathname);
|
|
178
|
-
if (relative === null) return null;
|
|
179
|
-
for (const directory of [isrCacheDir, prerenderDir]) {
|
|
180
|
-
try {
|
|
181
|
-
return readEntry(path.join(directory, relative), revalidate);
|
|
182
|
-
} catch {
|
|
183
|
-
// try the deploy-time prerender output after the runtime cache
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return null;
|
|
187
|
-
},
|
|
188
|
-
writePrerendered: (pathname, html) => {
|
|
189
|
-
const relative = prerenderRelativePath(pathname);
|
|
190
|
-
if (relative === null) return;
|
|
191
|
-
const htmlPath = path.join(isrCacheDir, relative);
|
|
192
|
-
mkdirSync(path.dirname(htmlPath), { recursive: true });
|
|
193
|
-
writeFileSync(htmlPath, html, 'utf8');
|
|
194
|
-
},
|
|
201
|
+
${documentCacheOptionsSource('platformReadPrerendered', 'platformWritePrerendered')}
|
|
195
202
|
// The project's own not-found page, pre-rendered by the build and carried
|
|
196
203
|
// inline in the manifest: an unmatched URL is answered with the page the
|
|
197
204
|
// application actually wrote, on every host.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,0BAA0B,EAC1B,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,cAAc,CAAA;AAyBrB,sFAAsF;AACtF,MAAM,UAAU,QAAQ,CAAC,OAAO,GAA2B,EAAE;IAC3D,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,cAAc,CAAA;IAC3D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,aAAa,CA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G,CAAC,OAAO,CAAC,aAAa,KAAK,KAAK;wBACjC,CAAC,CAAC,EAAE;wBACJ,CAAC,CAAC;4BACE;gCACE,IAAI,EAAE,MAAM;gCACZ,IAAI,EAAE,eAAe;gCACrB,KAAK,EAAE,SAAS;gCAChB,YAAY,EAAE,IAAI;gCAClB,QAAQ,EAAE,qBAAqB,GAAG,IAAI;6BACb;yBAC5B,CAAC;iBACP;aACF,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC;AAED,iFAAiF;AACjF,SAAS,qBAAqB,CAC5B,YAAoB,EACpB,MAAc,EACd,aAAsB,EACtB,OAAe;IAEf,OAAO;;;;;;;;;;;wBAWe,IAAI,CAAC,SAAS,CAAC,aAAa,IAAI,EAAE,CAAC;;;EAGzD,uBAAuB,CAAC,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyChC,0BAA0B,CAAC,yBAAyB,EAAE,0BAA0B,CAAC;;;;;;;;;;;;;;;;;;;eAmBpE,YAAY;cACb,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BnC,CAAA;AACD,CAAC;AAED,eAAe,QAAQ,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruvyxa/adapter-firebase",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "Deploy full-stack Ruvyxa applications to Firebase Hosting with CDN assets and a generated Cloud Functions v2 backend.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@ruvyxa/core": "^1.1.
|
|
63
|
+
"@ruvyxa/core": "^1.1.4"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"build": "tsc -p tsconfig.json",
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,8 @@ import type { Adapter, AdapterArtifact, AdapterOutput, BuildContext } from '@ruv
|
|
|
2
2
|
import {
|
|
3
3
|
CLIENT_BUNDLE_PREFIX,
|
|
4
4
|
clientBuildOutput,
|
|
5
|
+
documentCacheOptionsSource,
|
|
6
|
+
isrTemporaryCacheSource,
|
|
5
7
|
DEFAULT_SECURITY_HEADERS,
|
|
6
8
|
IMMUTABLE_CACHE_CONTROL,
|
|
7
9
|
nonPublishableStrategies,
|
|
@@ -164,7 +166,12 @@ export function firebase(options: FirebaseAdapterOptions = {}): Adapter {
|
|
|
164
166
|
{
|
|
165
167
|
kind: 'function',
|
|
166
168
|
path: 'deploy/firebase/functions',
|
|
167
|
-
handlerSource: firebaseHandlerSource(
|
|
169
|
+
handlerSource: firebaseHandlerSource(
|
|
170
|
+
functionName,
|
|
171
|
+
region,
|
|
172
|
+
runtimeBuildPolicy(ctx),
|
|
173
|
+
ctx.deployManifest?.buildId ?? '',
|
|
174
|
+
),
|
|
168
175
|
},
|
|
169
176
|
{
|
|
170
177
|
kind: 'file',
|
|
@@ -206,11 +213,13 @@ function firebaseHandlerSource(
|
|
|
206
213
|
functionName: string,
|
|
207
214
|
region: string,
|
|
208
215
|
runtimePolicy: unknown,
|
|
216
|
+
buildId: string,
|
|
209
217
|
): string {
|
|
210
218
|
return `import { onRequest } from 'firebase-functions/v2/https';
|
|
211
219
|
import { createHandler, prerenderRelativePath } from './serverless-handler.mjs';
|
|
212
|
-
import { applyPluginHttp, loadActionModule, loadRouteModule } from './route-modules.mjs';
|
|
220
|
+
import { applyPluginHttp, documentCacheHandler, loadActionModule, loadRouteModule } from './route-modules.mjs';
|
|
213
221
|
import manifest from './manifest.mjs';
|
|
222
|
+
import { createHash } from 'node:crypto';
|
|
214
223
|
import { readFileSync, writeFileSync, mkdirSync, statSync } from 'node:fs';
|
|
215
224
|
import os from 'node:os';
|
|
216
225
|
import path from 'node:path';
|
|
@@ -220,7 +229,7 @@ import { pipeline } from 'node:stream/promises';
|
|
|
220
229
|
const runtimePolicy = ${JSON.stringify(runtimePolicy ?? {})};
|
|
221
230
|
|
|
222
231
|
const prerenderDir = path.join(import.meta.dirname, 'prerender');
|
|
223
|
-
|
|
232
|
+
${isrTemporaryCacheSource(buildId)}
|
|
224
233
|
|
|
225
234
|
const readEntry = (htmlPath, revalidate) => {
|
|
226
235
|
const html = readFileSync(htmlPath, 'utf8');
|
|
@@ -228,6 +237,30 @@ const readEntry = (htmlPath, revalidate) => {
|
|
|
228
237
|
return { html, stale };
|
|
229
238
|
};
|
|
230
239
|
|
|
240
|
+
// Named rather than passed inline, so a project that declares \`cache.handler\`
|
|
241
|
+
// can stand its own store in front of these. See \`documentCacheOptionsSource\`
|
|
242
|
+
// in \`@ruvyxa/core\`; the registry supplies \`documentCacheHandler\`.
|
|
243
|
+
const platformReadPrerendered = (pathname, revalidate = 60) => {
|
|
244
|
+
const relative = prerenderRelativePath(pathname);
|
|
245
|
+
if (relative === null) return null;
|
|
246
|
+
for (const directory of [isrCacheDir, prerenderDir]) {
|
|
247
|
+
try {
|
|
248
|
+
return readEntry(path.join(directory, relative), revalidate);
|
|
249
|
+
} catch {
|
|
250
|
+
// try the deploy-time prerender output after the runtime cache
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return null;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const platformWritePrerendered = (pathname, html) => {
|
|
257
|
+
const relative = prerenderRelativePath(pathname);
|
|
258
|
+
if (relative === null) return;
|
|
259
|
+
const htmlPath = path.join(isrCacheDir, relative);
|
|
260
|
+
mkdirSync(path.dirname(htmlPath), { recursive: true });
|
|
261
|
+
writeFileSync(htmlPath, html, 'utf8');
|
|
262
|
+
};
|
|
263
|
+
|
|
231
264
|
const handler = createHandler({
|
|
232
265
|
routes: manifest.routes,
|
|
233
266
|
middleware: runtimePolicy.middleware,
|
|
@@ -237,25 +270,7 @@ const handler = createHandler({
|
|
|
237
270
|
importAction: loadActionModule,
|
|
238
271
|
pluginHttp: applyPluginHttp,
|
|
239
272
|
security: runtimePolicy.security,
|
|
240
|
-
|
|
241
|
-
const relative = prerenderRelativePath(pathname);
|
|
242
|
-
if (relative === null) return null;
|
|
243
|
-
for (const directory of [isrCacheDir, prerenderDir]) {
|
|
244
|
-
try {
|
|
245
|
-
return readEntry(path.join(directory, relative), revalidate);
|
|
246
|
-
} catch {
|
|
247
|
-
// try the deploy-time prerender output after the runtime cache
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return null;
|
|
251
|
-
},
|
|
252
|
-
writePrerendered: (pathname, html) => {
|
|
253
|
-
const relative = prerenderRelativePath(pathname);
|
|
254
|
-
if (relative === null) return;
|
|
255
|
-
const htmlPath = path.join(isrCacheDir, relative);
|
|
256
|
-
mkdirSync(path.dirname(htmlPath), { recursive: true });
|
|
257
|
-
writeFileSync(htmlPath, html, 'utf8');
|
|
258
|
-
},
|
|
273
|
+
${documentCacheOptionsSource('platformReadPrerendered', 'platformWritePrerendered')}
|
|
259
274
|
// The project's own not-found page, pre-rendered by the build and carried
|
|
260
275
|
// inline in the manifest: an unmatched URL is answered with the page the
|
|
261
276
|
// application actually wrote, on every host.
|