@fastly/compute-js-static-publish 8.1.0-beta.4 → 8.1.0-beta.6
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/CHANGELOG.md +9 -6
- package/DOCUMENTATION.md +105 -5
- package/MIGRATING.md +289 -0
- package/build/cli/cli/commands/manage/deploy.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/deploy.js +5 -4
- package/build/cli/cli/commands/manage/index.d.ts +1 -0
- package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/index.js +13 -11
- package/build/cli/cli/commands/manage/status.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/status.js +7 -5
- package/build/cli/cli/index.js +15 -1
- package/build/cli/cli/managed/fastly-service.d.ts +7 -0
- package/build/cli/cli/managed/fastly-service.d.ts.map +1 -1
- package/build/cli/cli/managed/fastly-service.js +31 -1
- package/build/cli/cli/managed/fingerprint.d.ts +12 -0
- package/build/cli/cli/managed/fingerprint.d.ts.map +1 -1
- package/build/cli/cli/managed/fingerprint.js +25 -0
- package/build/cli/cli/util/config.d.ts +4 -0
- package/build/cli/cli/util/config.d.ts.map +1 -1
- package/build/cli/cli/util/config.js +33 -0
- package/build/cli/cli/util/output.js +1 -1
- package/build/server/hono/extensions.d.ts +3 -1
- package/build/server/hono/extensions.d.ts.map +1 -1
- package/build/server/hono/index.d.ts +11 -4
- package/build/server/hono/index.d.ts.map +1 -1
- package/build/server/hono/index.js +45 -18
- package/build/server/server/index.d.ts +1 -1
- package/build/server/server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.d.ts +7 -1
- package/build/server/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.js +56 -14
- package/package.json +3 -2
- package/resources/templates/hono/src/index.ts +14 -3
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { managedAppState } from '../../managed/app.js';
|
|
7
7
|
import { loadManagedProject } from '../../managed/command-helpers.js';
|
|
8
|
-
import { getActiveVersion, getVersionDomains } from '../../managed/fastly-service.js';
|
|
9
|
-
import { parseVersionComment } from '../../managed/fingerprint.js';
|
|
8
|
+
import { getActiveVersion, getDeployedApp, getVersionDomains } from '../../managed/fastly-service.js';
|
|
10
9
|
import { checkProjectVersion } from '../../managed/version-check.js';
|
|
11
10
|
import { loadApiToken } from '../../util/api-token.js';
|
|
12
11
|
import { parseCommandLine } from '../../util/args.js';
|
|
@@ -81,6 +80,8 @@ export async function action(actionArgs) {
|
|
|
81
80
|
let deployedFingerprint = null;
|
|
82
81
|
let deployedStaticPublishVersion = null;
|
|
83
82
|
let activeVersion = null;
|
|
83
|
+
// The version whose comment has the fingerprint, if it is not the active version.
|
|
84
|
+
let fingerprintVersion = null;
|
|
84
85
|
let domain = null;
|
|
85
86
|
let needsDeploy;
|
|
86
87
|
const reasons = [];
|
|
@@ -102,13 +103,14 @@ export async function action(actionArgs) {
|
|
|
102
103
|
else {
|
|
103
104
|
activeVersion = active.number;
|
|
104
105
|
domain = (await getVersionDomains(context, serviceId, active.number))[0] ?? null;
|
|
105
|
-
const deployed =
|
|
106
|
+
const deployed = await getDeployedApp(context, serviceId, active);
|
|
106
107
|
if (deployed == null) {
|
|
107
108
|
needsDeploy = true;
|
|
108
|
-
reasons.push(`The active version (${active.number}) was not deployed by 'deploy'
|
|
109
|
+
reasons.push(`The active version (${active.number}) was not deployed by 'deploy': its comment has no fingerprint, and its package is not the package of the newest version that has one.`);
|
|
109
110
|
}
|
|
110
111
|
else {
|
|
111
112
|
deployedFingerprint = deployed.fingerprint;
|
|
113
|
+
fingerprintVersion = deployed.fingerprintVersion ?? null;
|
|
112
114
|
deployedStaticPublishVersion = deployed.staticPublishVersion;
|
|
113
115
|
needsDeploy = deployed.fingerprint !== fingerprint;
|
|
114
116
|
if (needsDeploy) {
|
|
@@ -137,7 +139,7 @@ export async function action(actionArgs) {
|
|
|
137
139
|
console.log(`Version of the project : ${versionCheck.recorded ?? '(missing)'}`);
|
|
138
140
|
console.log(`Version that runs : ${running}${versionCheck.result !== 'same' ? ` ⚠️ ${versionCheck.result}` : ''}`);
|
|
139
141
|
console.log(`Fingerprint : ${fingerprint}`);
|
|
140
|
-
console.log(`Deployed fingerprint : ${deployedFingerprint ?? '(unknown)'}${activeVersion != null ? ` (version ${activeVersion})` : ''}`);
|
|
142
|
+
console.log(`Deployed fingerprint : ${deployedFingerprint ?? '(unknown)'}${activeVersion != null ? ` (version ${activeVersion}${fingerprintVersion != null ? `, the same package as version ${fingerprintVersion}` : ''})` : ''}`);
|
|
141
143
|
console.log(`Deploy necessary : ${needsDeploy == null ? 'unknown' : needsDeploy ? 'yes' : 'no'}`);
|
|
142
144
|
for (const reason of reasons) {
|
|
143
145
|
console.log(` * ${reason}`);
|
package/build/cli/cli/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { runTemplateHook } from './commands/run-template-hook.js';
|
|
|
13
13
|
import { parseGlobalOptions } from './util/global-options.js';
|
|
14
14
|
import { ConfigError, EXIT_USAGE, JSON_SCHEMA_VERSION, fail, isJsonMode, recordFailure, setJsonResult, setUpOutput, writeJsonOutput, } from './util/output.js';
|
|
15
15
|
import { getOwnVersion } from './util/package.js';
|
|
16
|
-
import { detectProjectMode } from './util/config.js';
|
|
16
|
+
import { detectProjectMode, findProjectDirsNear } from './util/config.js';
|
|
17
17
|
import { PROJECT_FILE_NAME, RC_FILE_NAME } from '../models/config/static-publish-project.js';
|
|
18
18
|
// Register storage builder providers
|
|
19
19
|
import { registerStorageProviderBuilder } from './storage/storage-provider.js';
|
|
@@ -108,6 +108,20 @@ async function run(globalOptions) {
|
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
110
|
if (mode === 'scaffold') {
|
|
111
|
+
// A command for a project or an app, in a directory that has none.
|
|
112
|
+
const command = process.argv[2];
|
|
113
|
+
if (command != null && manageCommands.MANAGEMENT_COMMANDS.includes(command)) {
|
|
114
|
+
fail('project-dir-not-found', `'${command}' is a command for a managed project or an app, but this directory has no ${PROJECT_FILE_NAME} or ${RC_FILE_NAME}.`);
|
|
115
|
+
const near = findProjectDirsNear();
|
|
116
|
+
for (const { dir, mode: kind } of near.slice(0, 3)) {
|
|
117
|
+
const relative = path.relative(process.cwd(), dir) || '.';
|
|
118
|
+
console.error(` * ${relative} has ${kind === 'managed' ? PROJECT_FILE_NAME : RC_FILE_NAME}. Run the command there, or add --project-dir=${relative}.`);
|
|
119
|
+
}
|
|
120
|
+
if (near.length === 0) {
|
|
121
|
+
console.error(` * Run it in the directory of the project (with ${PROJECT_FILE_NAME}) or of the app (with ${RC_FILE_NAME}), or add --project-dir.`);
|
|
122
|
+
}
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
111
125
|
console.log("🧑💻Fastly Compute JavaScript Static Publisher (Scaffolding mode)");
|
|
112
126
|
if (isJsonMode()) {
|
|
113
127
|
fail('json-not-supported', '--json is not supported for scaffolding.');
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { type FastlyApiContext } from '../util/api-token.js';
|
|
2
|
+
import { type DeployedApp } from './fingerprint.js';
|
|
2
3
|
export type ActiveVersion = {
|
|
3
4
|
number: number;
|
|
4
5
|
comment: string | null;
|
|
5
6
|
};
|
|
6
7
|
export declare function getActiveVersion(context: FastlyApiContext, serviceId: string): Promise<ActiveVersion | null>;
|
|
7
8
|
export declare function getVersionDomains(context: FastlyApiContext, serviceId: string, version: number): Promise<string[]>;
|
|
9
|
+
export declare function getVersions(context: FastlyApiContext, serviceId: string): Promise<{
|
|
10
|
+
number: number;
|
|
11
|
+
comment: string | null;
|
|
12
|
+
}[]>;
|
|
13
|
+
export declare function getPackageHash(context: FastlyApiContext, serviceId: string, version: number): Promise<string | null>;
|
|
14
|
+
export declare function getDeployedApp(context: FastlyApiContext, serviceId: string, active: ActiveVersion): Promise<DeployedApp | null>;
|
|
8
15
|
//# sourceMappingURL=fastly-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastly-service.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/fastly-service.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,gBAAgB,
|
|
1
|
+
{"version":3,"file":"fastly-service.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/fastly-service.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,gBAAgB,EAA6B,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,KAAK,WAAW,EAAwC,MAAM,kBAAkB,CAAC;AAE1F,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAC;AAGF,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAQlH;AAGD,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAIxH;AAGD,wBAAsB,WAAW,CAAC,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EAAE,CAAC,CAIrI;AAGD,wBAAsB,cAAc,CAAC,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAY1H;AAGD,wBAAsB,cAAc,CAAC,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAMrI"}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
-
import { callFastlyApi } from '../util/api-token.js';
|
|
5
|
+
import { FetchError, callFastlyApi } from '../util/api-token.js';
|
|
6
|
+
import { findDeployedApp, parseVersionComment } from './fingerprint.js';
|
|
6
7
|
// The active version of a service, or null if no version is active.
|
|
7
8
|
export async function getActiveVersion(context, serviceId) {
|
|
8
9
|
const response = await callFastlyApi(context, `/service/${encodeURIComponent(serviceId)}/details`, 'Get service details');
|
|
@@ -19,3 +20,32 @@ export async function getVersionDomains(context, serviceId, version) {
|
|
|
19
20
|
const domains = await response.json();
|
|
20
21
|
return domains.flatMap(x => typeof x.name === 'string' ? [x.name] : []);
|
|
21
22
|
}
|
|
23
|
+
// The versions of a service, with their comments.
|
|
24
|
+
export async function getVersions(context, serviceId) {
|
|
25
|
+
const response = await callFastlyApi(context, `/service/${encodeURIComponent(serviceId)}/version`, 'List versions');
|
|
26
|
+
const versions = await response.json();
|
|
27
|
+
return versions.flatMap(x => typeof x.number === 'number' ? [{ number: x.number, comment: x.comment ?? null }] : []);
|
|
28
|
+
}
|
|
29
|
+
// The hash of the package of a service version, or null if it has no package.
|
|
30
|
+
export async function getPackageHash(context, serviceId, version) {
|
|
31
|
+
let response;
|
|
32
|
+
try {
|
|
33
|
+
response = await callFastlyApi(context, `/service/${encodeURIComponent(serviceId)}/version/${version}/package`, 'Get package');
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
if (err instanceof FetchError && err.status === 404) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
const pkg = await response.json();
|
|
42
|
+
return typeof pkg.metadata?.hashsum === 'string' && pkg.metadata.hashsum !== '' ? pkg.metadata.hashsum : null;
|
|
43
|
+
}
|
|
44
|
+
// The app that the active version runs (see findDeployedApp()).
|
|
45
|
+
export async function getDeployedApp(context, serviceId, active) {
|
|
46
|
+
const own = parseVersionComment(active.comment);
|
|
47
|
+
if (own != null) {
|
|
48
|
+
return own;
|
|
49
|
+
}
|
|
50
|
+
return findDeployedApp(active, await getVersions(context, serviceId), (version) => getPackageHash(context, serviceId, version));
|
|
51
|
+
}
|
|
@@ -10,4 +10,16 @@ export declare function parseVersionComment(comment: string | null | undefined):
|
|
|
10
10
|
staticPublishVersion: string;
|
|
11
11
|
fingerprint: string;
|
|
12
12
|
} | null;
|
|
13
|
+
export type DeployedApp = {
|
|
14
|
+
staticPublishVersion: string;
|
|
15
|
+
fingerprint: string;
|
|
16
|
+
fingerprintVersion?: number;
|
|
17
|
+
};
|
|
18
|
+
export declare function findDeployedApp(active: {
|
|
19
|
+
number: number;
|
|
20
|
+
comment: string | null;
|
|
21
|
+
}, versions: {
|
|
22
|
+
number: number;
|
|
23
|
+
comment: string | null;
|
|
24
|
+
}[], getPackageHash: (version: number) => Promise<string | null>): Promise<DeployedApp | null>;
|
|
13
25
|
//# sourceMappingURL=fingerprint.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fingerprint.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/fingerprint.ts"],"names":[],"mappings":"AAkBA,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAIrF;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;IAGjB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,kBAAkB,GAAG,MAAM,CA2BrG;AAGD,wBAAgB,oBAAoB,CAAC,oBAAoB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,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,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EAAE,EACtD,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,GAC1D,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAiB7B"}
|
|
@@ -58,3 +58,28 @@ export function parseVersionComment(comment) {
|
|
|
58
58
|
}
|
|
59
59
|
return { staticPublishVersion: match[1], fingerprint: match[2] };
|
|
60
60
|
}
|
|
61
|
+
// The app that the active version runs. The fingerprint is in the comment of
|
|
62
|
+
// the version that deploy made. A version cloned by hand (for example to add a
|
|
63
|
+
// backend) has no comment, but it has the package of the version that it was
|
|
64
|
+
// cloned from. Thus, if the active version has no fingerprint, the newest
|
|
65
|
+
// earlier version with a fingerprint is used, but only if its package hash is
|
|
66
|
+
// the same as the package hash of the active version. Each deploy uploads a
|
|
67
|
+
// new package with a different hash, also for the same app.
|
|
68
|
+
export async function findDeployedApp(active, versions, getPackageHash) {
|
|
69
|
+
const own = parseVersionComment(active.comment);
|
|
70
|
+
if (own != null) {
|
|
71
|
+
return own;
|
|
72
|
+
}
|
|
73
|
+
const earlier = versions
|
|
74
|
+
.filter(version => version.number < active.number)
|
|
75
|
+
.sort((a, b) => b.number - a.number)
|
|
76
|
+
.find(version => parseVersionComment(version.comment) != null);
|
|
77
|
+
if (earlier == null) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const [activeHash, earlierHash] = await Promise.all([getPackageHash(active.number), getPackageHash(earlier.number)]);
|
|
81
|
+
if (activeHash == null || activeHash !== earlierHash) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return { ...parseVersionComment(earlier.comment), fingerprintVersion: earlier.number };
|
|
85
|
+
}
|
|
@@ -8,6 +8,10 @@ export declare class LoadConfigError extends Error {
|
|
|
8
8
|
}
|
|
9
9
|
export type ProjectMode = 'managed' | 'ejected' | 'scaffold' | 'conflict';
|
|
10
10
|
export declare function detectProjectMode(dir?: string): ProjectMode;
|
|
11
|
+
export declare function findProjectDirsNear(dir?: string): {
|
|
12
|
+
dir: string;
|
|
13
|
+
mode: 'managed' | 'ejected';
|
|
14
|
+
}[];
|
|
11
15
|
export declare function getComputeAppDir(): string;
|
|
12
16
|
export declare function configFileName(): string;
|
|
13
17
|
export type StaticPublishProjectNormalized = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/config.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,KAAK,eAAe,EAKrB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,KAAK,2BAA2B,EAIjC,MAAM,+CAA+C,CAAC;AAWvD,OAAO,EACL,KAAK,8BAA8B,EAEpC,MAAM,+CAA+C,CAAC;AAOvD,OAAO,EAAE,KAAK,+BAA+B,EAAE,MAAM,gDAAgD,CAAC;AAEtG,qBAAa,eAAgB,SAAQ,KAAK;IACxC,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB,YAAY,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAGnD;CACF;AAGD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;AAE1E,wBAAgB,iBAAiB,CAAC,GAAG,GAAE,MAAY,GAAG,WAAW,CAOhE;AAKD,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAGD,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,MAAM,MAAM,8BAA8B,GAAG;IAC3C,EAAE,EAAE,eAAe,CAAC;IAEpB,cAAc,EAAE,OAAO,CAAC;IACxB,OAAO,EAAE,2BAA2B,CAAC;CACtC,CAAC;AAsBF,eAAO,MAAM,uBAAuB,yEAoBlC,CAAC;AAGH,wBAAsB,eAAe,IAAI,OAAO,CAAC,8BAA8B,CAAC,CAsB/E;AAID,wBAAs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C3C,EAAE,EAAE,eAAe,CAAC;IAEpB,cAAc,EAAE,OAAO,CAAC;IACxB,OAAO,EAAE,2BAA2B,CAAC;CACtC,CAAC;AAsBF,eAAO,MAAM,uBAAuB,yEAoBlC,CAAC;AAGH,wBAAsB,eAAe,IAAI,OAAO,CAAC,8BAA8B,CAAC,CAsB/E;AAID,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,eAAe,CAAC,CAmC1E;AAGD,eAAO,MAAM,0BAA0B,6DAgGrC,CAAC;AAKH,wBAAsB,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAWtH;AAED,wBAAsB,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,8BAA8B,CAAC,CA6B9G;AAwED,eAAO,MAAM,6BAA6B,4EAiLxC,CAAC;AAEH,eAAO,MAAM,8BAA8B,6EA2GzC,CAAC"}
|
|
@@ -29,6 +29,39 @@ export function detectProjectMode(dir = '.') {
|
|
|
29
29
|
}
|
|
30
30
|
return hasProject ? 'managed' : hasRc ? 'ejected' : 'scaffold';
|
|
31
31
|
}
|
|
32
|
+
// The directories near dir that have a project file or an rc file: the parent
|
|
33
|
+
// directories, and the directories directly in dir (for example compute-js/).
|
|
34
|
+
// For the message when a command for a project or an app runs in another
|
|
35
|
+
// directory.
|
|
36
|
+
export function findProjectDirsNear(dir = '.') {
|
|
37
|
+
const found = [];
|
|
38
|
+
const add = (candidate) => {
|
|
39
|
+
const mode = detectProjectMode(candidate);
|
|
40
|
+
if (mode === 'managed' || mode === 'ejected') {
|
|
41
|
+
found.push({ dir: candidate, mode });
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const start = path.resolve(dir);
|
|
45
|
+
for (let current = path.dirname(start);; current = path.dirname(current)) {
|
|
46
|
+
add(current);
|
|
47
|
+
if (path.dirname(current) === current) {
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
let entries = [];
|
|
52
|
+
try {
|
|
53
|
+
entries = fs.readdirSync(start, { withFileTypes: true });
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// An unreadable directory has no subdirectories to check.
|
|
57
|
+
}
|
|
58
|
+
for (const entry of entries) {
|
|
59
|
+
if (entry.isDirectory() && !entry.name.startsWith('.') && entry.name !== 'node_modules') {
|
|
60
|
+
add(path.join(start, entry.name));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return found;
|
|
64
|
+
}
|
|
32
65
|
// The directory of the Compute app: the current directory in an ejected app,
|
|
33
66
|
// or .static-publish/app in a managed project. The local KV Store file has
|
|
34
67
|
// paths relative to it, because `fastly compute serve` runs there.
|
|
@@ -27,7 +27,7 @@ const USAGE_CODES = [
|
|
|
27
27
|
'config-invalid', // a config file cannot be loaded or is not valid
|
|
28
28
|
'collection-name-invalid', // a collection name breaks the rule
|
|
29
29
|
'collection-not-found', // the command needs a collection that does not exist
|
|
30
|
-
'project-dir-not-found', // --project-dir is not a directory, or has no config file
|
|
30
|
+
'project-dir-not-found', // --project-dir is not a directory, or has no config file, or a command for a project runs in a directory with no config file
|
|
31
31
|
'json-not-supported', // --json with a command that does not support it
|
|
32
32
|
'credentials-missing', // a token or credentials are necessary, but not given
|
|
33
33
|
'version-mismatch', // managed.staticPublishVersion is not the version that runs
|
|
@@ -5,6 +5,7 @@ import type { KVStore } from 'fastly:kv-store';
|
|
|
5
5
|
import type { Logger } from 'fastly:logger';
|
|
6
6
|
import type { SecretStore } from 'fastly:secret-store';
|
|
7
7
|
import type { Hono } from 'hono';
|
|
8
|
+
import type { PublisherServerMiddleware } from './index.js';
|
|
8
9
|
export type ExtensionBindings = Record<string, string>;
|
|
9
10
|
type ResourceTypes = {
|
|
10
11
|
Acl: Acl;
|
|
@@ -24,7 +25,8 @@ export type ExtensionEnv<B extends ExtensionBindings> = {
|
|
|
24
25
|
};
|
|
25
26
|
export declare const EXTENSION_PHASES: readonly ['middleware', 'beforeFiles', 'afterFiles'];
|
|
26
27
|
export type ExtensionPhase = typeof EXTENSION_PHASES[number];
|
|
27
|
-
export type
|
|
28
|
+
export type ExtensionHelpers = Pick<PublisherServerMiddleware, 'publisherServer' | 'serveStatic' | 'staticResponse' | 'serveFallback' | 'fallbackResponse' | 'isCollectionAvailable'>;
|
|
29
|
+
export type ExtensionPhaseFunction<B extends ExtensionBindings = ExtensionBindings, O = any> = (app: Hono<ExtensionEnv<B>, any, any>, options: O | undefined, helpers: ExtensionHelpers) => void;
|
|
28
30
|
export type ExtensionPhases<B extends ExtensionBindings = ExtensionBindings, O = any> = {
|
|
29
31
|
[P in ExtensionPhase]?: ExtensionPhaseFunction<B, O>;
|
|
30
32
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extensions.d.ts","sourceRoot":"","sources":["../../../src/hono/extensions.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"extensions.d.ts","sourceRoot":"","sources":["../../../src/hono/extensions.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,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AE,CAAC,GAAG,GAAG,EAAE,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;AAwBzL,wBAAgB,aAAa,CAAC,WAAW,EAAE,iBAAiB,GAAG,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,iBAAiB,CAgDtH"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Context, MiddlewareHandler, NotFoundHandler } from 'hono';
|
|
2
|
-
import { PublisherServer, type StaticPublishRc } from '../server/index.js';
|
|
2
|
+
import { PublisherServer, type ResponseOverrides, type StaticPublishRc } from '../server/index.js';
|
|
3
3
|
import { type ServeStaticPathOptions } from './path.js';
|
|
4
|
-
export { type BindingResource, type DefineExtensionOptions, EXTENSION_PHASES, type Extension, type ExtensionBindings, type ExtensionEntry, type ExtensionEnv, type ExtensionPhase, type ExtensionPhaseFunction, type ExtensionPhases, defineExtension, mergeBindings, } from './extensions.js';
|
|
4
|
+
export { type BindingResource, type DefineExtensionOptions, EXTENSION_PHASES, type Extension, type ExtensionBindings, type ExtensionEntry, type ExtensionEnv, type ExtensionHelpers, type ExtensionPhase, type ExtensionPhaseFunction, type ExtensionPhases, defineExtension, mergeBindings, } from './extensions.js';
|
|
5
5
|
export type StaticPublisherVariables = {
|
|
6
6
|
staticPublisher: {
|
|
7
7
|
publisherServer: PublisherServer;
|
|
@@ -10,19 +10,26 @@ export type StaticPublisherVariables = {
|
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
export type CollectionNameOption = string | null | ((c: Context) => string | null | undefined);
|
|
13
|
-
export type
|
|
13
|
+
export type OnMissingOption = 'not-found' | 'default';
|
|
14
|
+
export type ServeStaticOptions = ServeStaticPathOptions<Context> & ResponseOverrides & {
|
|
14
15
|
collectionName?: CollectionNameOption;
|
|
16
|
+
onMissing?: OnMissingOption;
|
|
15
17
|
};
|
|
16
|
-
export type ServeFallbackOptions = {
|
|
18
|
+
export type ServeFallbackOptions = ResponseOverrides & {
|
|
17
19
|
collectionName?: CollectionNameOption;
|
|
20
|
+
onMissing?: OnMissingOption;
|
|
18
21
|
};
|
|
19
22
|
export type PublisherServerMiddlewareDefaults = {
|
|
20
23
|
collectionName?: CollectionNameOption;
|
|
24
|
+
onMissing?: OnMissingOption;
|
|
21
25
|
};
|
|
22
26
|
export type PublisherServerMiddleware = {
|
|
23
27
|
publisherServer: PublisherServer;
|
|
24
28
|
serveStatic: (options?: ServeStaticOptions) => MiddlewareHandler;
|
|
29
|
+
staticResponse: (c: Context, options?: ServeStaticOptions) => Promise<Response | null>;
|
|
25
30
|
serveFallback: (options?: ServeFallbackOptions) => NotFoundHandler;
|
|
31
|
+
fallbackResponse: (c: Context, options?: ServeFallbackOptions) => Promise<Response | null>;
|
|
32
|
+
isCollectionAvailable: (c: Context, collectionName?: CollectionNameOption) => Promise<boolean>;
|
|
26
33
|
selectCollection: () => MiddlewareHandler;
|
|
27
34
|
};
|
|
28
35
|
export declare function fromPublisherServer(server: PublisherServer, defaults?: PublisherServerMiddlewareDefaults): PublisherServerMiddleware;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hono/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAGxE,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hono/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAGxE,OAAO,EAAE,eAAe,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAE,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OAAO,CAAC,EAAE,kBAAkB,KAAK,iBAAiB,CAAC;IAKjE,cAAc,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,kBAAkB,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IAIvF,aAAa,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,eAAe,CAAC;IAKnE,gBAAgB,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IAK3F,qBAAqB,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAK/F,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;CAC3C,CAAC;AAsBF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,EAAE,QAAQ,GAAE,iCAAsC,GAAG,yBAAyB,CAgFxI;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,eAAe,EAAE,QAAQ,GAAE,iCAAsC,GAAG,yBAAyB,CAEpI"}
|
|
@@ -21,20 +21,29 @@ function resolveCollectionName(c, option, selection) {
|
|
|
21
21
|
return selection != null ? selection.collectionName : undefined;
|
|
22
22
|
}
|
|
23
23
|
export function fromPublisherServer(server, defaults = {}) {
|
|
24
|
-
const
|
|
24
|
+
const staticResponse = async (c, callOptions = {}) => {
|
|
25
25
|
const options = { ...defaults, ...callOptions };
|
|
26
|
+
const selection = getSelection(c, server);
|
|
27
|
+
// For a path source, the path without its prefix. A path option
|
|
28
|
+
// replaces the request path (see resolveServeStaticPathname()).
|
|
29
|
+
const requestPath = selection?.pathname ?? c.req.path;
|
|
30
|
+
const pathname = resolveServeStaticPathname(requestPath, c, options);
|
|
31
|
+
if (pathname == null) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return server.serveRequest(c.req.raw, {
|
|
35
|
+
collectionName: resolveCollectionName(c, options.collectionName, selection),
|
|
36
|
+
pathname,
|
|
37
|
+
fallback: false,
|
|
38
|
+
healthCheck: false,
|
|
39
|
+
onMissing: options.onMissing,
|
|
40
|
+
status: options.status,
|
|
41
|
+
headers: options.headers,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
const serveStatic = (callOptions = {}) => {
|
|
26
45
|
return async (c, next) => {
|
|
27
|
-
const
|
|
28
|
-
// For a path source, the path without its prefix. A path option
|
|
29
|
-
// replaces the request path (see resolveServeStaticPathname()).
|
|
30
|
-
const requestPath = selection?.pathname ?? c.req.path;
|
|
31
|
-
const pathname = resolveServeStaticPathname(requestPath, c, options);
|
|
32
|
-
const response = pathname != null ? await server.serveRequest(c.req.raw, {
|
|
33
|
-
collectionName: resolveCollectionName(c, options.collectionName, selection),
|
|
34
|
-
pathname,
|
|
35
|
-
fallback: false,
|
|
36
|
-
healthCheck: false,
|
|
37
|
-
}) : null;
|
|
46
|
+
const response = await staticResponse(c, callOptions);
|
|
38
47
|
if (response == null) {
|
|
39
48
|
await next();
|
|
40
49
|
return;
|
|
@@ -42,15 +51,25 @@ export function fromPublisherServer(server, defaults = {}) {
|
|
|
42
51
|
return response;
|
|
43
52
|
};
|
|
44
53
|
};
|
|
45
|
-
const
|
|
54
|
+
const fallbackResponse = async (c, callOptions = {}) => {
|
|
46
55
|
const options = { ...defaults, ...callOptions };
|
|
56
|
+
return server.serveFallback(c.req.raw, {
|
|
57
|
+
collectionName: resolveCollectionName(c, options.collectionName, getSelection(c, server)),
|
|
58
|
+
onMissing: options.onMissing,
|
|
59
|
+
status: options.status,
|
|
60
|
+
headers: options.headers,
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const serveFallback = (callOptions = {}) => {
|
|
47
64
|
return async (c) => {
|
|
48
|
-
|
|
49
|
-
collectionName: resolveCollectionName(c, options.collectionName, getSelection(c, server)),
|
|
50
|
-
});
|
|
51
|
-
return response ?? c.text('404 Not Found', 404);
|
|
65
|
+
return await fallbackResponse(c, callOptions) ?? c.text('404 Not Found', 404);
|
|
52
66
|
};
|
|
53
67
|
};
|
|
68
|
+
const isCollectionAvailable = async (c, collectionName) => {
|
|
69
|
+
const option = collectionName !== undefined ? collectionName : defaults.collectionName;
|
|
70
|
+
const name = resolveCollectionName(c, option, getSelection(c, server));
|
|
71
|
+
return server.isCollectionAvailable(c.req.raw, name === undefined ? server.activeCollectionName : name);
|
|
72
|
+
};
|
|
54
73
|
const selectCollection = () => {
|
|
55
74
|
return async (c, next) => {
|
|
56
75
|
const selection = server.resolveCollection(c.req.raw);
|
|
@@ -65,7 +84,15 @@ export function fromPublisherServer(server, defaults = {}) {
|
|
|
65
84
|
await next();
|
|
66
85
|
};
|
|
67
86
|
};
|
|
68
|
-
return {
|
|
87
|
+
return {
|
|
88
|
+
publisherServer: server,
|
|
89
|
+
serveStatic,
|
|
90
|
+
staticResponse,
|
|
91
|
+
serveFallback,
|
|
92
|
+
fallbackResponse,
|
|
93
|
+
isCollectionAvailable,
|
|
94
|
+
selectCollection,
|
|
95
|
+
};
|
|
69
96
|
}
|
|
70
97
|
export function fromStaticPublishRc(rc, defaults = {}) {
|
|
71
98
|
return fromPublisherServer(PublisherServer.fromStaticPublishRc(rc), defaults);
|
|
@@ -7,5 +7,5 @@ export { type CollectionSelection, type CollectionSelectionSource, previewUrl, v
|
|
|
7
7
|
export { CookieCollectionSelector, type CookieCollectionSelectorOpts, } from './collection-selector/from-cookie.js';
|
|
8
8
|
export { type StorageProvider, type StorageProviderBuilder, type StorageEntry, registerStorageProviderBuilder, } from './storage/storage-provider.js';
|
|
9
9
|
export { setSecretStoreForS3Credentials, setSecretStoreKeyForS3AccessKeyId, setSecretStoreKeyForS3SecretAccessKey, setS3CredentialsBuilder, } from './storage/s3-storage-provider.js';
|
|
10
|
-
export { type GetMatchingAssetOptions, type ServeFallbackOptions, type ServeRequestOptions, PublisherServer, } from './publisher-server/index.js';
|
|
10
|
+
export { type GetMatchingAssetOptions, type ResponseOverrides, type ServeFallbackOptions, type ServeRequestOptions, PublisherServer, } from './publisher-server/index.js';
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,KAAK,kBAAkB,MAAM,gCAAgC,CAAC;AACrE,OAAO,EACL,KAAK,uBAAuB,EAC5B,iBAAiB,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,UAAU,EACV,2BAA2B,GAC5B,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,wBAAwB,EACxB,KAAK,4BAA4B,GAClC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,8BAA8B,GAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,8BAA8B,EAC9B,iCAAiC,EACjC,qCAAqC,EACrC,uBAAuB,GACxB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,eAAe,GAChB,MAAM,6BAA6B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,KAAK,kBAAkB,MAAM,gCAAgC,CAAC;AACrE,OAAO,EACL,KAAK,uBAAuB,EAC5B,iBAAiB,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,UAAU,EACV,2BAA2B,GAC5B,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,wBAAwB,EACxB,KAAK,4BAA4B,GAClC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,8BAA8B,GAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,8BAA8B,EAC9B,iCAAiC,EACjC,qCAAqC,EACrC,uBAAuB,GACxB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,eAAe,GAChB,MAAM,6BAA6B,CAAC"}
|
|
@@ -25,9 +25,15 @@ export type ServeRequestOptions = {
|
|
|
25
25
|
pathname?: string;
|
|
26
26
|
fallback?: boolean;
|
|
27
27
|
healthCheck?: boolean;
|
|
28
|
-
|
|
28
|
+
onMissing?: 'not-found' | 'default';
|
|
29
|
+
} & ResponseOverrides;
|
|
29
30
|
export type ServeFallbackOptions = {
|
|
30
31
|
collectionName?: string | null;
|
|
32
|
+
onMissing?: 'not-found' | 'default';
|
|
33
|
+
} & ResponseOverrides;
|
|
34
|
+
export type ResponseOverrides = {
|
|
35
|
+
status?: number;
|
|
36
|
+
headers?: HeadersInit;
|
|
31
37
|
};
|
|
32
38
|
export declare class PublisherServer {
|
|
33
39
|
constructor(publishId: string, storageProvider: StorageProvider, defaultCollectionName: string);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/publisher-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