@fastly/compute-js-static-publish 8.0.0 → 8.1.0-beta.1
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/DOCUMENTATION.md +1984 -0
- package/README.md +11 -4
- package/README.short.md +11 -4
- package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/clean.js +12 -7
- package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/delete.js +29 -13
- package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/index.js +6 -1
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/list.js +47 -7
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +67 -20
- package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/update-expiration.js +10 -11
- package/build/cli/cli/commands/manage/deploy.d.ts +2 -0
- package/build/cli/cli/commands/manage/deploy.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/deploy.js +194 -0
- package/build/cli/cli/commands/manage/dev.d.ts +2 -0
- package/build/cli/cli/commands/manage/dev.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/dev.js +77 -0
- package/build/cli/cli/commands/manage/eject.d.ts +2 -0
- package/build/cli/cli/commands/manage/eject.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/eject.js +155 -0
- package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/index.js +37 -1
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +85 -35
- package/build/cli/cli/commands/manage/status.d.ts +2 -0
- package/build/cli/cli/commands/manage/status.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/status.js +162 -0
- package/build/cli/cli/commands/manage/template/index.d.ts +2 -0
- package/build/cli/cli/commands/manage/template/index.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/template/index.js +42 -0
- package/build/cli/cli/commands/manage/template/init.d.ts +13 -0
- package/build/cli/cli/commands/manage/template/init.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/template/init.js +172 -0
- package/build/cli/cli/commands/manage/upgrade.d.ts +2 -0
- package/build/cli/cli/commands/manage/upgrade.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/upgrade.js +59 -0
- package/build/cli/cli/commands/run-dev-watch.d.ts +8 -0
- package/build/cli/cli/commands/run-dev-watch.d.ts.map +1 -0
- package/build/cli/cli/commands/run-dev-watch.js +41 -0
- package/build/cli/cli/commands/run-template-hook.d.ts +2 -0
- package/build/cli/cli/commands/run-template-hook.d.ts.map +1 -0
- package/build/cli/cli/commands/run-template-hook.js +28 -0
- package/build/cli/cli/commands/scaffold/app-template.d.ts +17 -0
- package/build/cli/cli/commands/scaffold/app-template.d.ts.map +1 -0
- package/build/cli/cli/commands/scaffold/app-template.js +54 -0
- package/build/cli/cli/commands/scaffold/fastly-toml-sections.d.ts +5 -0
- package/build/cli/cli/commands/scaffold/fastly-toml-sections.d.ts.map +1 -0
- package/build/cli/cli/commands/scaffold/fastly-toml-sections.js +154 -0
- package/build/cli/cli/commands/scaffold/generate-app.d.ts +47 -0
- package/build/cli/cli/commands/scaffold/generate-app.d.ts.map +1 -0
- package/build/cli/cli/commands/scaffold/generate-app.js +164 -0
- package/build/cli/cli/commands/scaffold/index.d.ts +6 -0
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +239 -300
- package/build/cli/cli/commands/scaffold/render.d.ts +7 -0
- package/build/cli/cli/commands/scaffold/render.d.ts.map +1 -0
- package/build/cli/cli/commands/scaffold/render.js +72 -0
- package/build/cli/cli/hono/build.d.ts +43 -0
- package/build/cli/cli/hono/build.d.ts.map +1 -0
- package/build/cli/cli/hono/build.js +297 -0
- package/build/cli/cli/index.js +98 -5
- package/build/cli/cli/managed/app.d.ts +21 -0
- package/build/cli/cli/managed/app.d.ts.map +1 -0
- package/build/cli/cli/managed/app.js +162 -0
- package/build/cli/cli/managed/command-helpers.d.ts +6 -0
- package/build/cli/cli/managed/command-helpers.d.ts.map +1 -0
- package/build/cli/cli/managed/command-helpers.js +81 -0
- package/build/cli/cli/managed/eject.d.ts +6 -0
- package/build/cli/cli/managed/eject.d.ts.map +1 -0
- package/build/cli/cli/managed/eject.js +68 -0
- package/build/cli/cli/managed/fastly-service.d.ts +8 -0
- package/build/cli/cli/managed/fastly-service.d.ts.map +1 -0
- package/build/cli/cli/managed/fastly-service.js +21 -0
- package/build/cli/cli/managed/fingerprint.d.ts +13 -0
- package/build/cli/cli/managed/fingerprint.d.ts.map +1 -0
- package/build/cli/cli/managed/fingerprint.js +60 -0
- package/build/cli/cli/managed/lockfile.d.ts +31 -0
- package/build/cli/cli/managed/lockfile.d.ts.map +1 -0
- package/build/cli/cli/managed/lockfile.js +62 -0
- package/build/cli/cli/managed/project-edit.d.ts +3 -0
- package/build/cli/cli/managed/project-edit.d.ts.map +1 -0
- package/build/cli/cli/managed/project-edit.js +35 -0
- package/build/cli/cli/managed/project-file.d.ts +16 -0
- package/build/cli/cli/managed/project-file.d.ts.map +1 -0
- package/build/cli/cli/managed/project-file.js +119 -0
- package/build/cli/cli/managed/template-init.d.ts +12 -0
- package/build/cli/cli/managed/template-init.d.ts.map +1 -0
- package/build/cli/cli/managed/template-init.js +120 -0
- package/build/cli/cli/managed/version-check.d.ts +25 -0
- package/build/cli/cli/managed/version-check.d.ts.map +1 -0
- package/build/cli/cli/managed/version-check.js +84 -0
- package/build/cli/cli/storage/kv-store-local-provider.d.ts +1 -0
- package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-local-provider.js +6 -3
- package/build/cli/cli/storage/kv-store-provider.d.ts +2 -1
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-provider.js +17 -6
- package/build/cli/cli/storage/s3-storage-provider.d.ts +1 -0
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +8 -2
- package/build/cli/cli/storage/storage-provider.d.ts +4 -0
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/storage-provider.js +32 -0
- package/build/cli/cli/util/api-token.d.ts +2 -1
- package/build/cli/cli/util/api-token.d.ts.map +1 -1
- package/build/cli/cli/util/api-token.js +38 -3
- package/build/cli/cli/util/collection-name.d.ts +3 -0
- package/build/cli/cli/util/collection-name.d.ts.map +1 -0
- package/build/cli/cli/util/collection-name.js +24 -0
- package/build/cli/cli/util/collection-selection-flags.d.ts +13 -0
- package/build/cli/cli/util/collection-selection-flags.d.ts.map +1 -0
- package/build/cli/cli/util/collection-selection-flags.js +131 -0
- package/build/cli/cli/util/config.d.ts +13 -0
- package/build/cli/cli/util/config.d.ts.map +1 -1
- package/build/cli/cli/util/config.js +172 -38
- package/build/cli/cli/util/data.d.ts.map +1 -1
- package/build/cli/cli/util/global-options.d.ts +13 -0
- package/build/cli/cli/util/global-options.d.ts.map +1 -0
- package/build/cli/cli/util/global-options.js +53 -0
- package/build/cli/cli/util/kv-store-items.d.ts +1 -0
- package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store-items.js +16 -40
- package/build/cli/cli/util/kv-store-local-server.d.ts +1 -1
- package/build/cli/cli/util/kv-store-local-server.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store-local-server.js +4 -2
- package/build/cli/cli/util/output.d.ts +31 -0
- package/build/cli/cli/util/output.d.ts.map +1 -0
- package/build/cli/cli/util/output.js +139 -0
- package/build/cli/cli/util/package.d.ts +3 -0
- package/build/cli/cli/util/package.d.ts.map +1 -1
- package/build/cli/cli/util/package.js +12 -0
- package/build/cli/cli/util/progress.d.ts +11 -0
- package/build/cli/cli/util/progress.d.ts.map +1 -0
- package/build/cli/cli/util/progress.js +32 -0
- package/build/cli/cli/util/purge.d.ts +15 -3
- package/build/cli/cli/util/purge.d.ts.map +1 -1
- package/build/cli/cli/util/purge.js +23 -10
- package/build/cli/cli/util/resources.d.ts +2 -0
- package/build/cli/cli/util/resources.d.ts.map +1 -0
- package/build/cli/cli/util/resources.js +8 -0
- package/build/cli/cli/util/service-id.d.ts +1 -0
- package/build/cli/cli/util/service-id.d.ts.map +1 -1
- package/build/cli/cli/util/service-id.js +5 -1
- package/build/cli/cli/util/variants.d.ts.map +1 -1
- package/build/cli/models/assets/index.d.ts +6 -0
- package/build/cli/models/assets/index.d.ts.map +1 -1
- package/build/cli/models/assets/index.js +24 -0
- package/build/cli/models/collections/index.d.ts +3 -0
- package/build/cli/models/collections/index.d.ts.map +1 -0
- package/build/cli/models/collections/index.js +15 -0
- package/build/cli/models/compression/index.d.ts +1 -1
- package/build/cli/models/compression/index.d.ts.map +1 -1
- package/build/cli/models/config/collection-selection.d.ts +55 -0
- package/build/cli/models/config/collection-selection.d.ts.map +1 -0
- package/build/cli/models/config/collection-selection.js +238 -0
- package/build/cli/models/config/item-patterns.d.ts +4 -0
- package/build/cli/models/config/item-patterns.d.ts.map +1 -0
- package/build/cli/models/config/item-patterns.js +43 -0
- package/build/cli/models/config/publish-content-config.d.ts +6 -1
- package/build/cli/models/config/publish-content-config.d.ts.map +1 -1
- package/build/cli/models/config/static-publish-project.d.ts +23 -0
- package/build/cli/models/config/static-publish-project.d.ts.map +1 -0
- package/build/cli/models/config/static-publish-project.js +11 -0
- package/build/cli/models/config/static-publish-rc.d.ts +25 -0
- package/build/cli/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/cli/models/config/static-publish-rc.js +31 -0
- package/build/cli/models/config/template-settings.d.ts +10 -0
- package/build/cli/models/config/template-settings.d.ts.map +1 -0
- package/build/cli/models/config/template-settings.js +72 -0
- package/build/cli/models/server/index.d.ts.map +1 -1
- package/build/cli/models/server/index.js +6 -2
- package/build/server/hono/extensions.d.ts +48 -0
- package/build/server/hono/extensions.d.ts.map +1 -0
- package/build/server/hono/extensions.js +65 -0
- package/build/server/hono/index.d.ts +30 -0
- package/build/server/hono/index.d.ts.map +1 -0
- package/build/server/hono/index.js +72 -0
- package/build/server/hono/path.d.ts +7 -0
- package/build/server/hono/path.d.ts.map +1 -0
- package/build/server/hono/path.js +32 -0
- package/build/server/models/assets/index.d.ts +6 -0
- package/build/server/models/assets/index.d.ts.map +1 -1
- package/build/server/models/assets/index.js +24 -0
- package/build/server/models/collections/index.d.ts +3 -0
- package/build/server/models/collections/index.d.ts.map +1 -0
- package/build/server/models/collections/index.js +15 -0
- package/build/server/models/compression/index.d.ts +1 -1
- package/build/server/models/compression/index.d.ts.map +1 -1
- package/build/server/models/config/collection-selection.d.ts +55 -0
- package/build/server/models/config/collection-selection.d.ts.map +1 -0
- package/build/server/models/config/collection-selection.js +238 -0
- package/build/server/models/config/item-patterns.d.ts +4 -0
- package/build/server/models/config/item-patterns.d.ts.map +1 -0
- package/build/server/models/config/item-patterns.js +43 -0
- package/build/server/models/config/publish-content-config.d.ts +6 -1
- package/build/server/models/config/publish-content-config.d.ts.map +1 -1
- package/build/server/models/config/static-publish-project.d.ts +23 -0
- package/build/server/models/config/static-publish-project.d.ts.map +1 -0
- package/build/server/models/config/static-publish-project.js +11 -0
- package/build/server/models/config/static-publish-rc.d.ts +25 -0
- package/build/server/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/server/models/config/static-publish-rc.js +31 -0
- package/build/server/models/server/index.d.ts.map +1 -1
- package/build/server/models/server/index.js +6 -2
- package/build/server/server/collection-selection/index.d.ts +11 -0
- package/build/server/server/collection-selection/index.d.ts.map +1 -0
- package/build/server/server/collection-selection/index.js +192 -0
- package/build/server/server/collection-selector/from-cookie.d.ts.map +1 -1
- package/build/server/server/collection-selector/from-cookie.js +6 -8
- package/build/server/server/collection-selector/from-request.d.ts.map +1 -1
- package/build/server/server/index.d.ts +4 -1
- package/build/server/server/index.d.ts.map +1 -1
- package/build/server/server/index.js +3 -1
- package/build/server/server/publisher-server/accept-html.d.ts +2 -0
- package/build/server/server/publisher-server/accept-html.d.ts.map +1 -0
- package/build/server/server/publisher-server/accept-html.js +50 -0
- package/build/server/server/publisher-server/index.d.ts +59 -6
- package/build/server/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.js +370 -131
- package/build/server/server/publisher-server/response-cache.d.ts +3 -0
- package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
- package/build/server/server/publisher-server/response-cache.js +24 -1
- package/build/server/server/storage/kv-store-provider.d.ts.map +1 -1
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/storage-provider.d.ts.map +1 -1
- package/build/server/server/util/body-length.d.ts.map +1 -1
- package/build/server/server/util/server-timing.d.ts.map +1 -1
- package/package.json +23 -4
- package/resources/app/fastly.toml.njk +58 -0
- package/resources/app/gitignore.njk +9 -0
- package/resources/app/publish-content.config.from-project.js.njk +9 -0
- package/resources/app/publish-content.config.js.njk +35 -0
- package/resources/app/static-publish.project.js.njk +83 -0
- package/resources/app/static-publish.rc.js.njk +43 -0
- package/resources/template-init/hono/_example.ts +22 -0
- package/resources/template-init/hono/tsconfig.json +17 -0
- package/resources/templates/hono/package-lock.json +4123 -0
- package/resources/templates/hono/package.json +15 -0
- package/resources/templates/hono/scripts/template_postinstall.js +10 -0
- package/resources/templates/hono/scripts/template_prebuild.js +8 -0
- package/resources/templates/hono/scripts/template_watch.js +15 -0
- package/resources/templates/hono/src/hono-extensions.generated.d.ts +5 -0
- package/resources/templates/hono/src/index.ts +53 -0
- package/resources/templates/hono/tsconfig.json +17 -0
- package/resources/templates/plain/package-lock.json +4088 -0
- package/resources/templates/plain/package.json +10 -0
- package/resources/templates/plain/src/index.js +34 -0
|
@@ -37,3 +37,35 @@ export async function loadStorageProviderFromStaticPublishRc(config, context) {
|
|
|
37
37
|
}
|
|
38
38
|
throw new Error('Static Publisher Error: Invalid static-publish.rc.js, storage mode not recognized, or could not instantiate store provider.');
|
|
39
39
|
}
|
|
40
|
+
// Returns true if storage has the variant with the key `variantKey`, which has
|
|
41
|
+
// `size` bytes in `numChunks` chunks. For a variant in more than one chunk, it
|
|
42
|
+
// also compares the stored size of each chunk with its expected size. It removes
|
|
43
|
+
// a chunk that has a different size, or that is not in storage now, from
|
|
44
|
+
// existingKeys, so that applyBatch() uploads the chunk again.
|
|
45
|
+
export async function isVariantInStorage(storageProvider, existingKeys, variantKey, size, numChunks) {
|
|
46
|
+
const chunkKeys = Array.from({ length: numChunks }, (_, chunkIndex) => chunkIndex === 0 ? variantKey : `${variantKey}_${chunkIndex}`);
|
|
47
|
+
if (!chunkKeys.every(key => existingKeys.has(key))) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (numChunks === 1) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
const expectedSizes = storageProvider.calculateChunkSizes(size);
|
|
54
|
+
const entries = await Promise.all(chunkKeys.map(key => storageProvider.getStorageEntryInfo(key)));
|
|
55
|
+
let found = true;
|
|
56
|
+
for (const [chunkIndex, key] of chunkKeys.entries()) {
|
|
57
|
+
const entry = entries[chunkIndex];
|
|
58
|
+
if (entry == null) {
|
|
59
|
+
existingKeys.delete(key);
|
|
60
|
+
found = false;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const storedSize = entry.size;
|
|
64
|
+
if (storedSize != null && storedSize !== expectedSizes[chunkIndex]) {
|
|
65
|
+
console.log(` ‼️ Chunk "${key}" in storage has ${storedSize} bytes, but it must have ${expectedSizes[chunkIndex]} bytes. It will be uploaded again.`);
|
|
66
|
+
existingKeys.delete(key);
|
|
67
|
+
found = false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return found;
|
|
71
|
+
}
|
|
@@ -10,8 +10,9 @@ export type LoadApiParams = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare function loadApiToken(params: LoadApiParams): LoadApiTokenResult | null;
|
|
12
12
|
export declare class FetchError extends Error {
|
|
13
|
-
constructor(message: string, status: number);
|
|
13
|
+
constructor(message: string, status: number, detail?: string);
|
|
14
14
|
status: number;
|
|
15
|
+
detail?: string;
|
|
15
16
|
}
|
|
16
17
|
export declare function callFastlyApi(fastlyApiContext: FastlyApiContext, endpoint: string, operationName: string, queryParams?: URLSearchParams | null, requestInit?: RequestInit): Promise<Response>;
|
|
17
18
|
//# sourceMappingURL=api-token.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-token.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/api-token.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,kBAAkB,GAAG,IAAI,CAyB7E;AAaD,qBAAa,UAAW,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"api-token.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/api-token.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,kBAAkB,GAAG,IAAI,CAyB7E;AAaD,qBAAa,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAK3D;IACD,MAAM,EAAE,MAAM,CAAC;IAEf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAWD,wBAAsB,aAAa,CACjC,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,eAAe,GAAG,IAAI,EACpC,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,QAAQ,CAAC,CAuCnB"}
|
|
@@ -34,10 +34,11 @@ const RETRYABLE_STATUS_CODES = [
|
|
|
34
34
|
504, // Gateway Timeout
|
|
35
35
|
];
|
|
36
36
|
export class FetchError extends Error {
|
|
37
|
-
constructor(message, status) {
|
|
37
|
+
constructor(message, status, detail) {
|
|
38
38
|
super(message);
|
|
39
39
|
this.name = 'FetchError';
|
|
40
40
|
this.status = status;
|
|
41
|
+
this.detail = detail;
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
function isReadableStream(data) {
|
|
@@ -74,10 +75,44 @@ export async function callFastlyApi(fastlyApiContext, endpoint, operationName, q
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
if (!response.ok) {
|
|
78
|
+
const detail = await readApiErrorDetail(response);
|
|
79
|
+
const status = `${response.status}${detail != null ? ` ${detail}` : ''}`;
|
|
77
80
|
if (!RETRYABLE_STATUS_CODES.includes(response.status)) {
|
|
78
|
-
throw new FetchError(`${operationName} failed: ${
|
|
81
|
+
throw new FetchError(`${operationName} failed: ${status}`, response.status, detail);
|
|
79
82
|
}
|
|
80
|
-
throw makeRetryable(new FetchError(`Retryable ${operationName} error: ${
|
|
83
|
+
throw makeRetryable(new FetchError(`Retryable ${operationName} error: ${status}`, response.status, detail));
|
|
81
84
|
}
|
|
82
85
|
return response;
|
|
83
86
|
}
|
|
87
|
+
// The Content-Type of an error response tells which fields describe the error:
|
|
88
|
+
// - application/json: the Fastly API fields msg and detail, for example
|
|
89
|
+
// {"msg":"Record not found","detail":"Cannot find service"}.
|
|
90
|
+
// - application/problem+json (RFC 9457): the fields title and detail.
|
|
91
|
+
// - Other types, or JSON that is not valid: the start of the text.
|
|
92
|
+
async function readApiErrorDetail(response) {
|
|
93
|
+
let text;
|
|
94
|
+
try {
|
|
95
|
+
text = (await response.text()).trim();
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
const mediaType = response.headers.get('content-type')?.split(';')[0].trim().toLowerCase();
|
|
101
|
+
const fields = mediaType === 'application/json' ? ['msg', 'detail'] :
|
|
102
|
+
mediaType === 'application/problem+json' ? ['title', 'detail'] :
|
|
103
|
+
null;
|
|
104
|
+
if (fields != null) {
|
|
105
|
+
let json;
|
|
106
|
+
try {
|
|
107
|
+
json = JSON.parse(text);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
json = undefined;
|
|
111
|
+
}
|
|
112
|
+
if (json !== undefined) {
|
|
113
|
+
const parts = fields.map(field => json?.[field]).filter(x => typeof x === 'string' && x !== '');
|
|
114
|
+
return parts.length > 0 ? parts.join(': ') : undefined;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return text !== '' ? text.slice(0, 200) : undefined;
|
|
118
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection-name.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/collection-name.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAOtE,wBAAsB,2BAA2B,CAC/C,eAAe,EAAE,eAAe,EAChC,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,CAAC,CAelB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import { COLLECTION_NAME_RULE, isValidCollectionName } from '../../models/collections/index.js';
|
|
6
|
+
import { fail } from './output.js';
|
|
7
|
+
// Checks a collection name that a command writes to. A new collection must
|
|
8
|
+
// have a valid name. A collection that exists continues to work with a name
|
|
9
|
+
// that breaks the rule, with a warning.
|
|
10
|
+
// Returns false (and fails the command) if the command must stop.
|
|
11
|
+
export async function checkCollectionNameForWrite(storageProvider, publishId, collectionName) {
|
|
12
|
+
if (isValidCollectionName(collectionName)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
const indexKey = `${publishId}_index_${collectionName}`;
|
|
16
|
+
const indexEntry = await storageProvider.getStorageEntryInfo(indexKey);
|
|
17
|
+
if (indexEntry != null) {
|
|
18
|
+
console.warn(`⚠️ Warning: Collection name '${collectionName}' is not valid. ${COLLECTION_NAME_RULE}`);
|
|
19
|
+
console.warn(` * The collection exists, so it continues to work. Use a valid name for new collections.`);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
fail('collection-name-invalid', `Collection name '${collectionName}' is not valid. ${COLLECTION_NAME_RULE}`);
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type CollectionSelection } from '../../models/config/collection-selection.js';
|
|
2
|
+
export type CollectionSelectionFlags = {
|
|
3
|
+
sources?: string[];
|
|
4
|
+
allow?: string[];
|
|
5
|
+
onMissing?: string;
|
|
6
|
+
noindex?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const COLLECTION_SELECTION_FLAGS_HELP = " --collection-selection <source> Select the collection of a request, for example for\n previews. Can be repeated; the sources are tried in order.\n host:<pattern> host:{collection}.preview.example.com\n path:<prefix>[,sticky] path:/_preview/{collection},sticky\n query:<param>[,sticky] query:collection,sticky\n cookie[:<name>][,maxAge=<seconds>][,activatePath=<path>][,resetPath=<path>]\n header:<name> header:x-publisher-collection\n 'sticky' also sets the cookie of the cookie source, so it needs a cookie source.\n --collection-allow <patterns> The collections that can be selected, for example \"pr-*,staging\".\n Default: any collection.\n --collection-on-missing <value> When the selected collection is not published or has\n expired: 'not-found' (default: a 404 response) or\n 'default' (serve the default collection).\n --collection-noindex <true|false> Add 'X-Robots-Tag: noindex' to the responses of a collection\n that is not the default collection. Default: true.";
|
|
9
|
+
export declare function collectionSelectionFromFlags(flags: CollectionSelectionFlags): {
|
|
10
|
+
collectionSelection: CollectionSelection | undefined;
|
|
11
|
+
errors: string[];
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=collection-selection-flags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection-selection-flags.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/collection-selection-flags.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,mBAAmB,EAIzB,MAAM,6CAA6C,CAAC;AAcrD,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,+BAA+B,y8CAe+C,CAAC;AA0E5F,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,wBAAwB,GAAG;IAC7E,mBAAmB,EAAE,mBAAmB,GAAG,SAAS,CAAC;IACrD,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAqCA"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import { validateCollectionSelection, } from '../../models/config/collection-selection.js';
|
|
6
|
+
export const COLLECTION_SELECTION_FLAGS_HELP = `\
|
|
7
|
+
--collection-selection <source> Select the collection of a request, for example for
|
|
8
|
+
previews. Can be repeated; the sources are tried in order.
|
|
9
|
+
host:<pattern> host:{collection}.preview.example.com
|
|
10
|
+
path:<prefix>[,sticky] path:/_preview/{collection},sticky
|
|
11
|
+
query:<param>[,sticky] query:collection,sticky
|
|
12
|
+
cookie[:<name>][,maxAge=<seconds>][,activatePath=<path>][,resetPath=<path>]
|
|
13
|
+
header:<name> header:x-publisher-collection
|
|
14
|
+
'sticky' also sets the cookie of the cookie source, so it needs a cookie source.
|
|
15
|
+
--collection-allow <patterns> The collections that can be selected, for example "pr-*,staging".
|
|
16
|
+
Default: any collection.
|
|
17
|
+
--collection-on-missing <value> When the selected collection is not published or has
|
|
18
|
+
expired: 'not-found' (default: a 404 response) or
|
|
19
|
+
'default' (serve the default collection).
|
|
20
|
+
--collection-noindex <true|false> Add 'X-Robots-Tag: noindex' to the responses of a collection
|
|
21
|
+
that is not the default collection. Default: true.`;
|
|
22
|
+
function parseSource(spec, errors) {
|
|
23
|
+
const [head, ...options] = spec.split(',').map(x => x.trim());
|
|
24
|
+
const colon = head.indexOf(':');
|
|
25
|
+
const type = colon === -1 ? head : head.slice(0, colon);
|
|
26
|
+
const value = colon === -1 ? undefined : head.slice(colon + 1);
|
|
27
|
+
const needValue = (what) => {
|
|
28
|
+
if (value == null || value === '') {
|
|
29
|
+
errors.push(`--collection-selection ${type}: give the ${what}, for example '${type}:<${what}>'.`);
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
};
|
|
34
|
+
const sticky = () => {
|
|
35
|
+
let result;
|
|
36
|
+
for (const option of options) {
|
|
37
|
+
if (option === 'sticky') {
|
|
38
|
+
result = 'cookie';
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
errors.push(`--collection-selection ${type}: unknown option '${option}'.`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
const noOptions = () => {
|
|
47
|
+
for (const option of options) {
|
|
48
|
+
errors.push(`--collection-selection ${type}: unknown option '${option}'.`);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
switch (type) {
|
|
52
|
+
case 'host':
|
|
53
|
+
noOptions();
|
|
54
|
+
return needValue('pattern') ? { type, pattern: value } : null;
|
|
55
|
+
case 'path': {
|
|
56
|
+
const s = sticky();
|
|
57
|
+
return needValue('prefix') ? { type, prefix: value, ...(s != null ? { sticky: s } : {}) } : null;
|
|
58
|
+
}
|
|
59
|
+
case 'query': {
|
|
60
|
+
const s = sticky();
|
|
61
|
+
return needValue('param') ? { type, param: value, ...(s != null ? { sticky: s } : {}) } : null;
|
|
62
|
+
}
|
|
63
|
+
case 'header':
|
|
64
|
+
noOptions();
|
|
65
|
+
return needValue('name') ? { type, name: value } : null;
|
|
66
|
+
case 'cookie': {
|
|
67
|
+
const source = { type };
|
|
68
|
+
if (value != null && value !== '') {
|
|
69
|
+
source.cookieName = value;
|
|
70
|
+
}
|
|
71
|
+
for (const option of options) {
|
|
72
|
+
const eq = option.indexOf('=');
|
|
73
|
+
const key = eq === -1 ? option : option.slice(0, eq);
|
|
74
|
+
const optionValue = eq === -1 ? '' : option.slice(eq + 1);
|
|
75
|
+
if (key === 'maxAge' && /^\d+$/.test(optionValue)) {
|
|
76
|
+
source.maxAge = Number(optionValue);
|
|
77
|
+
}
|
|
78
|
+
else if (key === 'activatePath' || key === 'resetPath') {
|
|
79
|
+
source[key] = optionValue;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
errors.push(`--collection-selection cookie: unknown option, or a value that is not valid: '${option}'.`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return source;
|
|
86
|
+
}
|
|
87
|
+
default:
|
|
88
|
+
errors.push(`--collection-selection: unknown source '${type}'. Use host, path, query, cookie, or header.`);
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Returns the collectionSelection from the flags (undefined if no flag is set),
|
|
93
|
+
// and the errors.
|
|
94
|
+
export function collectionSelectionFromFlags(flags) {
|
|
95
|
+
const errors = [];
|
|
96
|
+
const sources = flags.sources ?? [];
|
|
97
|
+
if (sources.length === 0) {
|
|
98
|
+
if (flags.allow != null || flags.onMissing != null || flags.noindex != null) {
|
|
99
|
+
errors.push('--collection-allow, --collection-on-missing, and --collection-noindex need --collection-selection.');
|
|
100
|
+
}
|
|
101
|
+
return { collectionSelection: undefined, errors };
|
|
102
|
+
}
|
|
103
|
+
const collectionSelection = { sources: [] };
|
|
104
|
+
for (const spec of sources) {
|
|
105
|
+
const source = parseSource(spec, errors);
|
|
106
|
+
if (source != null) {
|
|
107
|
+
collectionSelection.sources.push(source);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (flags.allow != null) {
|
|
111
|
+
collectionSelection.allow = flags.allow.flatMap(x => x.split(',')).map(x => x.trim()).filter(x => x !== '');
|
|
112
|
+
}
|
|
113
|
+
if (flags.onMissing != null) {
|
|
114
|
+
collectionSelection.onMissing = flags.onMissing;
|
|
115
|
+
}
|
|
116
|
+
if (flags.noindex != null) {
|
|
117
|
+
if (flags.noindex === 'true') {
|
|
118
|
+
collectionSelection.noindex = true;
|
|
119
|
+
}
|
|
120
|
+
else if (flags.noindex === 'false') {
|
|
121
|
+
collectionSelection.noindex = false;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
errors.push(`--collection-noindex must be 'true' or 'false'.`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (errors.length === 0) {
|
|
128
|
+
errors.push(...validateCollectionSelection(collectionSelection));
|
|
129
|
+
}
|
|
130
|
+
return { collectionSelection: errors.length === 0 ? collectionSelection : undefined, errors };
|
|
131
|
+
}
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import { type StaticPublishRc } from '../../models/config/static-publish-rc.js';
|
|
2
|
+
import { type StaticPublishProjectManaged } from '../../models/config/static-publish-project.js';
|
|
2
3
|
import { type PublishContentConfigNormalized } from '../../models/config/publish-content-config.js';
|
|
3
4
|
import { type PublisherServerConfigNormalized } from '../../models/config/publisher-server-config.js';
|
|
4
5
|
export declare class LoadConfigError extends Error {
|
|
5
6
|
errors: string[];
|
|
6
7
|
constructor(configFilePath: string, errors: string[]);
|
|
7
8
|
}
|
|
9
|
+
export type ProjectMode = 'managed' | 'ejected' | 'scaffold' | 'conflict';
|
|
10
|
+
export declare function detectProjectMode(dir?: string): ProjectMode;
|
|
11
|
+
export declare function getComputeAppDir(): string;
|
|
12
|
+
export declare function configFileName(): string;
|
|
13
|
+
export type StaticPublishProjectNormalized = {
|
|
14
|
+
rc: StaticPublishRc;
|
|
15
|
+
publishContent: unknown;
|
|
16
|
+
managed: StaticPublishProjectManaged;
|
|
17
|
+
};
|
|
18
|
+
export declare const normalizeProjectManaged: (obj: unknown, errCtx?: string[]) => StaticPublishProjectManaged | null;
|
|
19
|
+
export declare function loadProjectFile(): Promise<StaticPublishProjectNormalized>;
|
|
8
20
|
export declare function loadStaticPublisherRcFile(): Promise<StaticPublishRc>;
|
|
9
21
|
export declare const normalizeStaticPublisherRc: (obj: unknown, errCtx?: string[]) => StaticPublishRc | null;
|
|
22
|
+
export declare function loadPublishContentConfig(configFile: string | undefined): Promise<PublishContentConfigNormalized>;
|
|
10
23
|
export declare function loadPublishContentConfigFile(configFile: string): Promise<PublishContentConfigNormalized>;
|
|
11
24
|
export declare const normalizePublishContentConfig: (obj: unknown, errCtx?: string[]) => PublishContentConfigNormalized | null;
|
|
12
25
|
export declare const normalizePublisherServerConfig: (obj: unknown, errCtx?: string[]) => PublisherServerConfigNormalized | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/config.ts"],"names":[],"mappings":"
|
|
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,CAiB/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,4EA8KxC,CAAC;AAEH,eAAO,MAAM,8BAA8B,6EA2GzC,CAAC"}
|
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
+
import fs from 'node:fs';
|
|
5
6
|
import path from 'node:path';
|
|
6
7
|
import { pathToFileURL } from 'node:url';
|
|
7
8
|
import globToRegExp from 'glob-to-regexp';
|
|
8
|
-
import { isKvStoreConfigRc, isS3StorageConfigRc, } from '../../models/config/static-publish-rc.js';
|
|
9
|
+
import { checkStaticPublisherWorkingDir, isKvStoreConfigRc, isS3StorageConfigRc, } from '../../models/config/static-publish-rc.js';
|
|
10
|
+
import { MANAGED_APP_DIR, PROJECT_FILE_NAME, RC_FILE_NAME, } from '../../models/config/static-publish-project.js';
|
|
11
|
+
import { validateCollectionSelection } from '../../models/config/collection-selection.js';
|
|
12
|
+
import { checkTemplateSettings } from '../../models/config/template-settings.js';
|
|
13
|
+
import { APP_TEMPLATE_NAMES, isAppTemplateName } from '../commands/scaffold/app-template.js';
|
|
14
|
+
import { checkFastlyTomlSections } from '../commands/scaffold/fastly-toml-sections.js';
|
|
9
15
|
import { getKvStoreConfigFromRc, } from '../../models/config/kv-store-config.js';
|
|
10
16
|
import { getS3StorageConfigFromRc, } from '../../models/config/s3-storage-config.js';
|
|
11
17
|
import { buildNormalizeFunctionForArray, buildNormalizeFunctionForObject, isSpecified, isStringAndNotEmpty, } from './data.js';
|
|
@@ -15,9 +21,91 @@ export class LoadConfigError extends Error {
|
|
|
15
21
|
this.errors = errors;
|
|
16
22
|
}
|
|
17
23
|
}
|
|
24
|
+
export function detectProjectMode(dir = '.') {
|
|
25
|
+
const hasProject = fs.existsSync(path.resolve(dir, PROJECT_FILE_NAME));
|
|
26
|
+
const hasRc = fs.existsSync(path.resolve(dir, RC_FILE_NAME));
|
|
27
|
+
if (hasProject && hasRc) {
|
|
28
|
+
return 'conflict';
|
|
29
|
+
}
|
|
30
|
+
return hasProject ? 'managed' : hasRc ? 'ejected' : 'scaffold';
|
|
31
|
+
}
|
|
32
|
+
// The directory of the Compute app: the current directory in an ejected app,
|
|
33
|
+
// or .static-publish/app in a managed project. The local KV Store file has
|
|
34
|
+
// paths relative to it, because `fastly compute serve` runs there.
|
|
35
|
+
export function getComputeAppDir() {
|
|
36
|
+
return detectProjectMode() === 'managed' ? path.resolve(MANAGED_APP_DIR) : path.resolve();
|
|
37
|
+
}
|
|
38
|
+
// The name of the config file of the current directory, for messages.
|
|
39
|
+
export function configFileName() {
|
|
40
|
+
return detectProjectMode() === 'managed' ? PROJECT_FILE_NAME : RC_FILE_NAME;
|
|
41
|
+
}
|
|
42
|
+
async function importDefault(configFile) {
|
|
43
|
+
const configFilePath = path.resolve(configFile);
|
|
44
|
+
let configRaw;
|
|
45
|
+
try {
|
|
46
|
+
configRaw = (await import(pathToFileURL(configFilePath).href)).default;
|
|
47
|
+
}
|
|
48
|
+
catch (ex) {
|
|
49
|
+
throw new LoadConfigError(configFile, [
|
|
50
|
+
`Unable to load ${configFilePath}`,
|
|
51
|
+
String(ex),
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
if (configRaw == null) {
|
|
55
|
+
throw new LoadConfigError(configFile, [
|
|
56
|
+
`Unable to load ${configFilePath}`,
|
|
57
|
+
`default export does not exist or is null.`
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
return configRaw;
|
|
61
|
+
}
|
|
62
|
+
export const normalizeProjectManaged = buildNormalizeFunctionForObject((config, errors) => {
|
|
63
|
+
const { name, description, authors, template, serviceId, staticPublishVersion, fastlyToml } = config;
|
|
64
|
+
for (const [key, value] of Object.entries({ name, description, template, serviceId, staticPublishVersion })) {
|
|
65
|
+
if (value !== undefined && typeof value !== 'string') {
|
|
66
|
+
errors.push(`managed.${key}, if specified, must be a string.`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (authors !== undefined && !(Array.isArray(authors) && authors.every(x => typeof x === 'string'))) {
|
|
70
|
+
errors.push('managed.authors, if specified, must be an array of strings.');
|
|
71
|
+
}
|
|
72
|
+
if (typeof template === 'string' && !isAppTemplateName(template)) {
|
|
73
|
+
errors.push(`managed.template must be one of: ${APP_TEMPLATE_NAMES.join(', ')}.`);
|
|
74
|
+
}
|
|
75
|
+
if (fastlyToml !== undefined) {
|
|
76
|
+
checkFastlyTomlSections(fastlyToml, errors);
|
|
77
|
+
}
|
|
78
|
+
if (errors.length > 0) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return { name, description, authors, template, serviceId, staticPublishVersion, fastlyToml };
|
|
82
|
+
});
|
|
83
|
+
// Loads static-publish.project.js from the current directory (the project dir).
|
|
84
|
+
export async function loadProjectFile() {
|
|
85
|
+
const configFile = `./${PROJECT_FILE_NAME}`;
|
|
86
|
+
const configRaw = await importDefault(configFile);
|
|
87
|
+
const errors = [];
|
|
88
|
+
const rc = normalizeStaticPublisherRc(configRaw, errors);
|
|
89
|
+
if (!('publishContent' in configRaw) || configRaw.publishContent == null || typeof configRaw.publishContent !== 'object') {
|
|
90
|
+
errors.push('publishContent must be specified.');
|
|
91
|
+
}
|
|
92
|
+
let managed = {};
|
|
93
|
+
if ('managed' in configRaw && configRaw.managed != null) {
|
|
94
|
+
managed = normalizeProjectManaged(configRaw.managed, errors);
|
|
95
|
+
}
|
|
96
|
+
if (rc == null || managed == null || errors.length > 0) {
|
|
97
|
+
throw new LoadConfigError(configFile, errors);
|
|
98
|
+
}
|
|
99
|
+
return { rc, publishContent: configRaw.publishContent, managed };
|
|
100
|
+
}
|
|
101
|
+
// Loads the settings of the app: static-publish.rc.js in an ejected app, or the
|
|
102
|
+
// top level of static-publish.project.js in a managed project.
|
|
18
103
|
export async function loadStaticPublisherRcFile() {
|
|
104
|
+
if (detectProjectMode() === 'managed') {
|
|
105
|
+
return (await loadProjectFile()).rc;
|
|
106
|
+
}
|
|
19
107
|
let configRaw;
|
|
20
|
-
const configFile =
|
|
108
|
+
const configFile = `./${RC_FILE_NAME}`;
|
|
21
109
|
const configFilePath = path.resolve(configFile);
|
|
22
110
|
try {
|
|
23
111
|
configRaw = (await import(pathToFileURL(configFilePath).href)).default;
|
|
@@ -42,7 +130,7 @@ export async function loadStaticPublisherRcFile() {
|
|
|
42
130
|
return config;
|
|
43
131
|
}
|
|
44
132
|
export const normalizeStaticPublisherRc = buildNormalizeFunctionForObject((config, errors) => {
|
|
45
|
-
let { publishId, defaultCollectionName, staticPublisherWorkingDir, } = config;
|
|
133
|
+
let { publishId, defaultCollectionName, staticPublisherWorkingDir, generatedFrom, collectionSelection, build, templateOptions, } = config;
|
|
46
134
|
let storage = null;
|
|
47
135
|
if (isKvStoreConfigRc(config)) {
|
|
48
136
|
storage = {
|
|
@@ -82,24 +170,60 @@ export const normalizeStaticPublisherRc = buildNormalizeFunctionForObject((confi
|
|
|
82
170
|
errors.push('staticPublisherWorkingDir must be specified.');
|
|
83
171
|
}
|
|
84
172
|
else {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
errors.push('staticPublisherWorkingDir must be a relative subdirectory.');
|
|
173
|
+
const workingDirError = checkStaticPublisherWorkingDir(staticPublisherWorkingDir);
|
|
174
|
+
if (workingDirError != null) {
|
|
175
|
+
// The caller uses the result even if there are errors. Thus return null,
|
|
176
|
+
// so that publish-content never writes into a directory that breaks the rule.
|
|
177
|
+
errors.push(workingDirError);
|
|
178
|
+
return null;
|
|
92
179
|
}
|
|
93
180
|
while (staticPublisherWorkingDir.endsWith('/')) {
|
|
94
181
|
staticPublisherWorkingDir = staticPublisherWorkingDir.slice(0, -1);
|
|
95
182
|
}
|
|
96
183
|
}
|
|
184
|
+
if (isSpecified(config, 'collectionSelection') && collectionSelection != null) {
|
|
185
|
+
// The caller uses the result even if there are errors. Thus return null, so
|
|
186
|
+
// that a collectionSelection that is not valid stops the command.
|
|
187
|
+
const collectionSelectionErrors = validateCollectionSelection(collectionSelection);
|
|
188
|
+
if (collectionSelectionErrors.length > 0) {
|
|
189
|
+
errors.push(...collectionSelectionErrors);
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
collectionSelection = undefined;
|
|
195
|
+
}
|
|
196
|
+
// The settings of the templates. A setting that no template declares is only
|
|
197
|
+
// a warning.
|
|
198
|
+
const templateSettings = checkTemplateSettings(build, templateOptions);
|
|
199
|
+
for (const warning of templateSettings.warnings) {
|
|
200
|
+
console.warn(`⚠️ ${warning}`);
|
|
201
|
+
}
|
|
202
|
+
if (templateSettings.errors.length > 0) {
|
|
203
|
+
errors.push(...templateSettings.errors);
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
97
206
|
return Object.assign({}, storage, {
|
|
98
207
|
publishId,
|
|
99
208
|
defaultCollectionName,
|
|
100
209
|
staticPublisherWorkingDir,
|
|
101
|
-
});
|
|
210
|
+
}, generatedFrom != null ? { generatedFrom } : {}, collectionSelection != null ? { collectionSelection } : {}, build != null ? { build } : {}, templateOptions != null ? { templateOptions } : {});
|
|
102
211
|
});
|
|
212
|
+
// Loads the publish settings: the file of --config if given, else the
|
|
213
|
+
// publishContent section of static-publish.project.js in a managed project,
|
|
214
|
+
// else ./publish-content.config.js.
|
|
215
|
+
export async function loadPublishContentConfig(configFile) {
|
|
216
|
+
if (configFile == null && detectProjectMode() === 'managed') {
|
|
217
|
+
const project = await loadProjectFile();
|
|
218
|
+
const errors = [];
|
|
219
|
+
const config = normalizePublishContentConfig(project.publishContent, errors);
|
|
220
|
+
if (config == null || errors.length > 0) {
|
|
221
|
+
throw new LoadConfigError(`./${PROJECT_FILE_NAME} (publishContent)`, errors);
|
|
222
|
+
}
|
|
223
|
+
return config;
|
|
224
|
+
}
|
|
225
|
+
return loadPublishContentConfigFile(configFile ?? './publish-content.config.js');
|
|
226
|
+
}
|
|
103
227
|
export async function loadPublishContentConfigFile(configFile) {
|
|
104
228
|
let configRaw;
|
|
105
229
|
const configFilePath = path.resolve(configFile);
|
|
@@ -125,6 +249,34 @@ export async function loadPublishContentConfigFile(configFile) {
|
|
|
125
249
|
}
|
|
126
250
|
return config;
|
|
127
251
|
}
|
|
252
|
+
// staticItems and hiddenItems: a string, an array of strings, false, or null.
|
|
253
|
+
// Glob patterns become 're:' items. See models/config/item-patterns.ts.
|
|
254
|
+
function normalizeItemList(name, value, errors) {
|
|
255
|
+
if (value === null || value === false) {
|
|
256
|
+
value = [];
|
|
257
|
+
}
|
|
258
|
+
if (!Array.isArray(value)) {
|
|
259
|
+
value = [value];
|
|
260
|
+
}
|
|
261
|
+
const items = value;
|
|
262
|
+
if (!items.every((x) => typeof x === 'string')) {
|
|
263
|
+
errors.push(`${name}, if specified, must be a string value, an array of string values, false, or null`);
|
|
264
|
+
return [];
|
|
265
|
+
}
|
|
266
|
+
return items.map((x, index) => {
|
|
267
|
+
if (x.includes('*')) {
|
|
268
|
+
try {
|
|
269
|
+
const regexp = globToRegExp(x, { globstar: true });
|
|
270
|
+
return 're:' + String(regexp);
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
errors.push(`${name} item at index ${index}, '${x}', cannot be parsed as a glob pattern.`);
|
|
274
|
+
return '';
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return x;
|
|
278
|
+
});
|
|
279
|
+
}
|
|
128
280
|
const normalizeContentTypeDef = buildNormalizeFunctionForObject((config, errors) => {
|
|
129
281
|
let { test, contentType, text } = config;
|
|
130
282
|
if (typeof test === 'function' || test instanceof RegExp) {
|
|
@@ -163,7 +315,7 @@ const normalizeContentTypeDefs = buildNormalizeFunctionForArray((config, errors)
|
|
|
163
315
|
return normalizeContentTypeDef(config, errors);
|
|
164
316
|
});
|
|
165
317
|
export const normalizePublishContentConfig = buildNormalizeFunctionForObject((config, errors) => {
|
|
166
|
-
let { rootDir, excludeDirs, excludeDotFiles, includeWellKnown, assetInclusionTest, kvStoreAssetInclusionTest, contentCompression, brotliQuality, contentTypes, server, } = config;
|
|
318
|
+
let { rootDir, excludeDirs, excludeDotFiles, includeWellKnown, assetInclusionTest, kvStoreAssetInclusionTest, hiddenItems, contentCompression, brotliQuality, contentTypes, server, } = config;
|
|
167
319
|
if (!isSpecified(config, 'rootDir')) {
|
|
168
320
|
errors.push('rootDir must be specified.');
|
|
169
321
|
}
|
|
@@ -255,6 +407,12 @@ export const normalizePublishContentConfig = buildNormalizeFunctionForObject((co
|
|
|
255
407
|
else {
|
|
256
408
|
errors.push('assetInclusionTest, if specified, must be null or a function.');
|
|
257
409
|
}
|
|
410
|
+
if (!isSpecified(config, 'hiddenItems')) {
|
|
411
|
+
hiddenItems = [];
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
hiddenItems = normalizeItemList('hiddenItems', hiddenItems, errors);
|
|
415
|
+
}
|
|
258
416
|
if (!isSpecified(config, 'contentCompression')) {
|
|
259
417
|
contentCompression = ['br', 'gzip'];
|
|
260
418
|
}
|
|
@@ -320,6 +478,7 @@ export const normalizePublishContentConfig = buildNormalizeFunctionForObject((co
|
|
|
320
478
|
excludeDotFiles,
|
|
321
479
|
includeWellKnown,
|
|
322
480
|
assetInclusionTest,
|
|
481
|
+
hiddenItems,
|
|
323
482
|
contentCompression,
|
|
324
483
|
brotliQuality,
|
|
325
484
|
contentTypes,
|
|
@@ -343,32 +502,7 @@ export const normalizePublisherServerConfig = buildNormalizeFunctionForObject((c
|
|
|
343
502
|
staticItems = [];
|
|
344
503
|
}
|
|
345
504
|
else {
|
|
346
|
-
|
|
347
|
-
staticItems = [];
|
|
348
|
-
}
|
|
349
|
-
if (!Array.isArray(staticItems)) {
|
|
350
|
-
staticItems = [staticItems];
|
|
351
|
-
}
|
|
352
|
-
if (staticItems.every((x) => typeof x === 'string')) {
|
|
353
|
-
staticItems = staticItems.map((x, index) => {
|
|
354
|
-
if (x.includes('*')) {
|
|
355
|
-
let re;
|
|
356
|
-
try {
|
|
357
|
-
const regexp = globToRegExp(x, { globstar: true });
|
|
358
|
-
re = 're:' + String(regexp);
|
|
359
|
-
}
|
|
360
|
-
catch {
|
|
361
|
-
errors.push(`staticItems item at index ${index}, '${x}', cannot be parsed as glob pattern.`);
|
|
362
|
-
re = null;
|
|
363
|
-
}
|
|
364
|
-
return re;
|
|
365
|
-
}
|
|
366
|
-
return x;
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
else {
|
|
370
|
-
errors.push('staticItems, if specified, must be a string value, an array of string values, false, or null');
|
|
371
|
-
}
|
|
505
|
+
staticItems = normalizeItemList('staticItems', staticItems, errors);
|
|
372
506
|
}
|
|
373
507
|
if (!isSpecified(config, 'allowedEncodings')) {
|
|
374
508
|
allowedEncodings = ['br', 'gzip'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/data.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;AAE5F,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/data.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;AAE5F,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,SAE1E,OAAO,WAAU,MAAM,EAAE,KAAQ,OAAO,GAAG,IAAI,CAmB7D;AAED,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,SAEvE,OAAO,WAAU,MAAM,EAAE,KAAQ,MAAM,EAAE,GAAG,IAAI,CAgC9D;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAE/D;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAC,GAAG,EAAE,GAAG,EAAE,MAAM,WAE/C;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC,kBAYpG"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type GlobalOptions = {
|
|
2
|
+
projectDir: string | undefined;
|
|
3
|
+
version: boolean;
|
|
4
|
+
nonInteractive: boolean;
|
|
5
|
+
json: boolean;
|
|
6
|
+
secrets: string[];
|
|
7
|
+
argv: string[];
|
|
8
|
+
};
|
|
9
|
+
export declare function isCiEnvironment(env: Record<string, string | undefined>): boolean;
|
|
10
|
+
export declare function parseGlobalOptions(args: string[], env?: Record<string, string | undefined>): GlobalOptions | {
|
|
11
|
+
error: string;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=global-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-options.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/global-options.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,aAAa,GAAG;IAG1B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAE/B,OAAO,EAAE,OAAO,CAAC;IAEjB,cAAc,EAAE,OAAO,CAAC;IAExB,IAAI,EAAE,OAAO,CAAC;IAGd,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAOF,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,WAEtE;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAM,GAAG,aAAa,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAsClI"}
|