@fastly/compute-js-static-publish 8.1.0-beta.2 → 8.1.0-beta.3

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.
Files changed (50) hide show
  1. package/DOCUMENTATION.md +12 -10
  2. package/README.md +18 -5
  3. package/README.short.md +18 -5
  4. package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
  5. package/build/cli/cli/commands/manage/collections/list.js +8 -10
  6. package/build/cli/cli/commands/manage/deploy.d.ts.map +1 -1
  7. package/build/cli/cli/commands/manage/deploy.js +46 -9
  8. package/build/cli/cli/commands/manage/eject.d.ts.map +1 -1
  9. package/build/cli/cli/commands/manage/eject.js +22 -5
  10. package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
  11. package/build/cli/cli/commands/manage/publish-content.js +4 -1
  12. package/build/cli/cli/commands/manage/status.d.ts.map +1 -1
  13. package/build/cli/cli/commands/manage/status.js +6 -0
  14. package/build/cli/cli/commands/run-dev-watch.d.ts +1 -0
  15. package/build/cli/cli/commands/run-dev-watch.d.ts.map +1 -1
  16. package/build/cli/cli/commands/run-dev-watch.js +45 -9
  17. package/build/cli/cli/commands/scaffold/generate-app.d.ts +8 -3
  18. package/build/cli/cli/commands/scaffold/generate-app.d.ts.map +1 -1
  19. package/build/cli/cli/commands/scaffold/generate-app.js +11 -1
  20. package/build/cli/cli/commands/scaffold/index.d.ts +3 -3
  21. package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
  22. package/build/cli/cli/commands/scaffold/index.js +15 -18
  23. package/build/cli/cli/managed/app.d.ts +1 -1
  24. package/build/cli/cli/managed/app.d.ts.map +1 -1
  25. package/build/cli/cli/managed/app.js +5 -3
  26. package/build/cli/cli/managed/lockfile.js +1 -1
  27. package/build/cli/cli/managed/project-file.d.ts.map +1 -1
  28. package/build/cli/cli/managed/project-file.js +4 -3
  29. package/build/cli/cli/util/config.d.ts.map +1 -1
  30. package/build/cli/cli/util/config.js +9 -0
  31. package/build/cli/cli/util/global-options.js +1 -1
  32. package/build/cli/cli/util/package.d.ts +2 -1
  33. package/build/cli/cli/util/package.d.ts.map +1 -1
  34. package/build/cli/cli/util/package.js +39 -7
  35. package/build/cli/cli/util/s3.d.ts +10 -4
  36. package/build/cli/cli/util/s3.d.ts.map +1 -1
  37. package/build/cli/cli/util/s3.js +13 -35
  38. package/build/cli/models/config/publish-content-config.d.ts +1 -0
  39. package/build/cli/models/config/publish-content-config.d.ts.map +1 -1
  40. package/build/cli/models/server/index.d.ts +2 -0
  41. package/build/cli/models/server/index.d.ts.map +1 -1
  42. package/build/cli/models/server/index.js +13 -1
  43. package/build/server/models/config/publish-content-config.d.ts +1 -0
  44. package/build/server/models/config/publish-content-config.d.ts.map +1 -1
  45. package/build/server/models/server/index.d.ts +2 -0
  46. package/build/server/models/server/index.d.ts.map +1 -1
  47. package/build/server/models/server/index.js +13 -1
  48. package/package.json +1 -1
  49. package/resources/app/publish-content.config.js.njk +1 -0
  50. package/resources/templates/plain/src/index.js +12 -2
@@ -18,7 +18,7 @@ import { templateHasInit } from '../../managed/template-init.js';
18
18
  import { findHostnameForAwsS3RegionAndBucket } from '../../util/s3.js';
19
19
  import { APP_TEMPLATE_NAMES, DEFAULT_APP_TEMPLATE_NAME, isAppTemplateName, loadAppTemplate, } from './app-template.js';
20
20
  import { COLLECTION_SELECTION_FLAGS_HELP, collectionSelectionFromFlags } from '../../util/collection-selection-flags.js';
21
- import { generateApp } from './generate-app.js';
21
+ import { DEFAULT_APP_INFO, generateApp } from './generate-app.js';
22
22
  import { renderProjectFile } from '../../managed/project-file.js';
23
23
  import { dotRelative } from '../../util/files.js';
24
24
  import { checkStaticPublisherWorkingDir } from '../../../models/config/static-publish-rc.js';
@@ -96,9 +96,9 @@ const defaultOptions = {
96
96
  notFoundPage: undefined,
97
97
  autoIndex: ['index.html', 'index.htm'],
98
98
  autoExt: ['.html', '.htm'],
99
- author: 'you@example.com',
100
- name: 'compute-js-static-site',
101
- description: 'Fastly Compute static site',
99
+ author: DEFAULT_APP_INFO.author,
100
+ name: DEFAULT_APP_INFO.name,
101
+ description: DEFAULT_APP_INFO.description,
102
102
  serviceId: undefined,
103
103
  publishId: undefined,
104
104
  defaultCollectionName: undefined,
@@ -115,13 +115,14 @@ function buildOptions(packageJson, commandLineOptions) {
115
115
  // 2. package.json
116
116
  // 3. command-line args
117
117
  const options = structuredClone(defaultOptions);
118
- if (packageJson?.name !== undefined) {
118
+ // Only string values: in a package.json, author can also be an object.
119
+ if (typeof packageJson?.name === 'string') {
119
120
  options.name = packageJson.name;
120
121
  }
121
- if (packageJson?.author !== undefined) {
122
+ if (typeof packageJson?.author === 'string') {
122
123
  options.author = packageJson.author;
123
124
  }
124
- if (packageJson?.description !== undefined) {
125
+ if (typeof packageJson?.description === 'string') {
125
126
  options.description = packageJson.description;
126
127
  }
127
128
  {
@@ -655,18 +656,15 @@ export async function action(actionArgs) {
655
656
  }
656
657
  let s3Endpoint = options.s3Endpoint;
657
658
  if (s3Endpoint == null || s3Endpoint === '') {
658
- // If endpoint is not presented, we assume it's from AWS,
659
- // and ask the SDK what the hostname would be.
660
- // This is required because we need to add the hostname as a
661
- // backend in the Compute service.
662
- s3Endpoint = await findHostnameForAwsS3RegionAndBucket(s3Region, s3Bucket);
663
- if (s3Endpoint) {
664
- console.log('✅ S3 endpoint resolved:', s3Endpoint);
665
- }
666
- else {
667
- fail('failed', `Unable to resolve S3 endpoint from region '${s3Region}' and bucket '${s3Bucket}'.`);
659
+ // Without an endpoint, the bucket is on AWS. The app needs its host name
660
+ // for the backend in the Compute service.
661
+ const hostname = findHostnameForAwsS3RegionAndBucket(s3Region, s3Bucket);
662
+ if (hostname == null) {
663
+ fail('usage', `The bucket name '${s3Bucket}' has a dot, so it cannot be a host name of AWS S3 under HTTPS. Set --s3-endpoint, for example --s3-endpoint=https://s3.${s3Region}.amazonaws.com. Then the bucket is in the path of the URL.`);
668
664
  return;
669
665
  }
666
+ s3Endpoint = hostname;
667
+ console.log('✅ S3 endpoint resolved:', s3Endpoint);
670
668
  s3EndpointUrl = new URL(`https://${s3Endpoint}/`);
671
669
  s3EndpointGenerated = true;
672
670
  }
@@ -776,7 +774,6 @@ export async function action(actionArgs) {
776
774
  }
777
775
  console.log("Initializing Compute Application in " + computeJsDir + "...");
778
776
  fs.mkdirSync(computeJsDir);
779
- fs.mkdirSync(path.resolve(computeJsDir, './src'));
780
777
  const resourceFiles = generateApp(appConfig);
781
778
  // Write out the files
782
779
  for (const [filename, content] of Object.entries(resourceFiles)) {
@@ -11,7 +11,7 @@ export declare function managedAppState(projectDir: string, project: StaticPubli
11
11
  files: Record<string, string>;
12
12
  fingerprint: string;
13
13
  }>;
14
- export declare function prepareManagedApp(projectDir: string, project: StaticPublishProjectNormalized): Promise<{
14
+ export declare function prepareManagedApp(projectDir: string, project: StaticPublishProjectNormalized, state?: Awaited<ReturnType<typeof managedAppState>>): Promise<{
15
15
  appDir: string;
16
16
  appConfig: AppConfig;
17
17
  files: Record<string, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/app.ts"],"names":[],"mappings":"AAUA,OAAO,EAAiC,KAAK,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AAGvG,OAAO,EAAE,KAAK,SAAS,EAAe,MAAM,sCAAsC,CAAC;AAYnF,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,8BAA8B,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CA+B/I;AAKD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,EAAE,CAe5F;AAcD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAGpD;AAID,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAezD;AAMD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;GAUpD"}
@@ -149,9 +149,11 @@ export async function managedAppState(projectDir, project) {
149
149
  return { appDir: appConfig.appDir, appConfig, files, fingerprint };
150
150
  }
151
151
  // Generate the app of a managed project in .static-publish/app, and install
152
- // its dependencies if necessary.
153
- export async function prepareManagedApp(projectDir, project) {
154
- const { appConfig, files, fingerprint } = await managedAppState(projectDir, project);
152
+ // its dependencies if necessary. A command that already has the result of
153
+ // managedAppState() passes it, so that it is not computed again (in S3 mode
154
+ // without s3.endpoint, that is a network lookup).
155
+ export async function prepareManagedApp(projectDir, project, state) {
156
+ const { appConfig, files, fingerprint } = state ?? await managedAppState(projectDir, project);
155
157
  console.log(`🛠️ Generating the app in ${MANAGED_APP_DIR}...`);
156
158
  const written = writeManagedAppFiles(appConfig.appDir, files);
157
159
  if (written.length > 0) {
@@ -43,7 +43,7 @@ export function buildManagedLockfile(templateLock, options) {
43
43
  root.name = options.appName;
44
44
  }
45
45
  root.version = options.appVersion;
46
- root.devDependencies = { ...root.devDependencies, [THIS_PACKAGE]: spec };
46
+ root.dependencies = { ...root.dependencies, [THIS_PACKAGE]: spec };
47
47
  lock.packages[''] = root;
48
48
  lock.packages[`node_modules/${THIS_PACKAGE}`] = {
49
49
  resolved: linkPath,
@@ -1 +1 @@
1
- {"version":3,"file":"project-file.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/project-file.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,8BAA8B,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,KAAK,2BAA2B,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EAAE,KAAK,eAAe,EAA0D,MAAM,0CAA0C,CAAC;AAGxI,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAMtE,eAAO,MAAM,2BAA2B,8BAA8B,CAAC;AAKvE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,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BAA8B,EAC9C,OAAO,EAAE,2BAA2B,EACpC,OAAO,EAAE,2BAA2B,GACnC,SAAS,CA6DX"}
@@ -6,6 +6,7 @@ import * as path from 'node:path';
6
6
  import { isS3StorageConfigRc } from '../../models/config/static-publish-rc.js';
7
7
  import { DEFAULT_HONO_EXTENSIONS_DIR } from '../hono/build.js';
8
8
  import { getKvStoreConfigFromRc } from '../../models/config/kv-store-config.js';
9
+ import { DEFAULT_APP_INFO } from '../commands/scaffold/generate-app.js';
9
10
  import { renderAppResource } from '../commands/scaffold/render.js';
10
11
  import { dotRelative } from '../util/files.js';
11
12
  // The line in the managed section that deploy replaces with the service ID
@@ -84,9 +85,9 @@ export function appConfigFromProject(rc, publishContent, managed, options) {
84
85
  }
85
86
  return {
86
87
  appDir,
87
- name: managed.name,
88
- author: managed.authors?.[0],
89
- description: managed.description,
88
+ name: managed.name ?? DEFAULT_APP_INFO.name,
89
+ author: managed.authors?.[0] ?? DEFAULT_APP_INFO.author,
90
+ description: managed.description ?? DEFAULT_APP_INFO.description,
90
91
  serviceId: managed.serviceId,
91
92
  storage,
92
93
  publishId: rc.publishId,
@@ -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,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;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,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"}
@@ -89,6 +89,12 @@ export async function loadProjectFile() {
89
89
  if (!('publishContent' in configRaw) || configRaw.publishContent == null || typeof configRaw.publishContent !== 'object') {
90
90
  errors.push('publishContent must be specified.');
91
91
  }
92
+ else {
93
+ // Checked here, so that each command shows the errors in the same way.
94
+ const publishContentErrors = [];
95
+ normalizePublishContentConfig(configRaw.publishContent, publishContentErrors);
96
+ errors.push(...publishContentErrors.map(error => `publishContent: ${error}`));
97
+ }
92
98
  let managed = {};
93
99
  if ('managed' in configRaw && configRaw.managed != null) {
94
100
  managed = normalizeProjectManaged(configRaw.managed, errors);
@@ -407,10 +413,12 @@ export const normalizePublishContentConfig = buildNormalizeFunctionForObject((co
407
413
  else {
408
414
  errors.push('assetInclusionTest, if specified, must be null or a function.');
409
415
  }
416
+ let hiddenItemsAsWritten = [];
410
417
  if (!isSpecified(config, 'hiddenItems')) {
411
418
  hiddenItems = [];
412
419
  }
413
420
  else {
421
+ hiddenItemsAsWritten = (Array.isArray(hiddenItems) ? hiddenItems : [hiddenItems]).filter((x) => typeof x === 'string');
414
422
  hiddenItems = normalizeItemList('hiddenItems', hiddenItems, errors);
415
423
  }
416
424
  if (!isSpecified(config, 'contentCompression')) {
@@ -479,6 +487,7 @@ export const normalizePublishContentConfig = buildNormalizeFunctionForObject((co
479
487
  includeWellKnown,
480
488
  assetInclusionTest,
481
489
  hiddenItems,
490
+ hiddenItemsAsWritten,
482
491
  contentCompression,
483
492
  brotliQuality,
484
493
  contentTypes,
@@ -22,7 +22,7 @@ export function parseGlobalOptions(args, env = {}) {
22
22
  if (arg.startsWith(`${option}=`)) {
23
23
  secrets.push(arg.slice(option.length + 1));
24
24
  }
25
- else if (arg === option && args[i + 1] != null) {
25
+ else if (arg === option && args[i + 1] != null && !args[i + 1].startsWith('-')) {
26
26
  secrets.push(args[i + 1]);
27
27
  }
28
28
  }
@@ -8,8 +8,9 @@ export type PackageJson = {
8
8
  export declare function getOwnPackageDir(): string;
9
9
  export declare function readOwnPackageJson(): Record<string, any>;
10
10
  export declare function getOwnVersion(): string;
11
+ export declare function isLocalCopy(dir?: string): boolean;
11
12
  export declare function cliCommand(options?: {
12
13
  latest?: boolean;
13
- }, version?: string): string;
14
+ }, version?: string, localCopy?: boolean): string;
14
15
  export declare function findComputeJsStaticPublisherVersion(packageJson: PackageJson | null): string;
15
16
  //# sourceMappingURL=package.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/package.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;I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AAE,MAAwB,EACjC,SAAS,GAAE,OAAuB,GACjC,MAAM,CAOR;AAED,wBAAgB,mCAAmC,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,UA8ClF"}
@@ -16,13 +16,45 @@ export function readOwnPackageJson() {
16
16
  export function getOwnVersion() {
17
17
  return readOwnPackageJson().version;
18
18
  }
19
- // The npx command of this package, for the messages of the CLI. The version of
20
- // a prerelease (for example 8.1.0-beta.1) gives the dist-tag of the prerelease
21
- // (@beta), because npx without a dist-tag runs the latest stable version, which
22
- // does not have the features of the prerelease. A stable version gives no
23
- // dist-tag, or @latest with { latest: true } (the command that makes a new
24
- // app).
25
- export function cliCommand(options = {}, version = getOwnVersion()) {
19
+ // True if this copy of the package is the one that a plain `npx
20
+ // @fastly/compute-js-static-publish` runs in the directory: the nearest
21
+ // node_modules/@fastly/compute-js-static-publish, from the directory upwards.
22
+ export function isLocalCopy(dir = process.cwd()) {
23
+ let ownDir;
24
+ try {
25
+ ownDir = fs.realpathSync(getOwnPackageDir());
26
+ }
27
+ catch {
28
+ return false;
29
+ }
30
+ for (let current = path.resolve(dir);; current = path.dirname(current)) {
31
+ const candidate = path.join(current, 'node_modules', '@fastly', 'compute-js-static-publish');
32
+ if (fs.existsSync(candidate)) {
33
+ try {
34
+ return fs.realpathSync(candidate) === ownDir;
35
+ }
36
+ catch {
37
+ return false;
38
+ }
39
+ }
40
+ if (path.dirname(current) === current) {
41
+ return false;
42
+ }
43
+ }
44
+ }
45
+ // The npx command of this package, for the messages of the CLI.
46
+ // - If a plain npx runs this copy (it is installed in the project or the app),
47
+ // the command has no dist-tag. A dist-tag makes npx get the version of that
48
+ // tag from npm, which can be another version than the installed one.
49
+ // - Else, the version of a prerelease (for example 8.1.0-beta.1) gives the
50
+ // dist-tag of the prerelease (@beta), because npx without a dist-tag runs
51
+ // the latest stable version, which does not have the features of the
52
+ // prerelease. A stable version gives no dist-tag, or @latest with
53
+ // { latest: true } (the command that makes a new app).
54
+ export function cliCommand(options = {}, version = getOwnVersion(), localCopy = isLocalCopy()) {
55
+ if (localCopy) {
56
+ return 'npx @fastly/compute-js-static-publish';
57
+ }
26
58
  const prerelease = /^\d+\.\d+\.\d+-([a-z][a-z0-9-]*)/.exec(version)?.[1];
27
59
  const distTag = prerelease ?? (options.latest ? 'latest' : undefined);
28
60
  return `npx @fastly/compute-js-static-publish${distTag != null ? `@${distTag}` : ''}`;
@@ -1,7 +1,13 @@
1
1
  /**
2
- * Resolve the AWS S3 hostname for a given region and bucket.
3
- * - Uses client-s3's own endpoint resolution logic (so it's always accurate).
4
- * - No network calls; intercepts at the build step.
2
+ * The AWS S3 host name of a bucket, for the backend of the app:
3
+ * <bucket>.s3.<region>.amazonaws.com. The server uses the same host name for a
4
+ * bucket without an endpoint (see objectUrl() in
5
+ * src/server/storage/s3-storage-provider.ts). It needs no credentials and no
6
+ * network.
7
+ *
8
+ * Returns null for a bucket name with a dot: under HTTPS, such a name does not
9
+ * match the certificate of *.s3.<region>.amazonaws.com. Such a bucket needs
10
+ * an endpoint, so that the bucket is in the path of the URL.
5
11
  */
6
- export declare function findHostnameForAwsS3RegionAndBucket(region: string, bucket: string): Promise<string>;
12
+ export declare function findHostnameForAwsS3RegionAndBucket(region: string, bucket: string): string | null;
7
13
  //# sourceMappingURL=s3.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/s3.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,wBAAsB,mCAAmC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAqCzG"}
1
+ {"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/s3.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,wBAAgB,mCAAmC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKjG"}
@@ -2,42 +2,20 @@
2
2
  * Copyright Fastly, Inc.
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
- import { S3Client, HeadObjectCommand } from '@aws-sdk/client-s3';
6
- const DUMMY_KEY = 'dummy.dat'; // placeholder, never sent over the network
7
5
  /**
8
- * Resolve the AWS S3 hostname for a given region and bucket.
9
- * - Uses client-s3's own endpoint resolution logic (so it's always accurate).
10
- * - No network calls; intercepts at the build step.
6
+ * The AWS S3 host name of a bucket, for the backend of the app:
7
+ * <bucket>.s3.<region>.amazonaws.com. The server uses the same host name for a
8
+ * bucket without an endpoint (see objectUrl() in
9
+ * src/server/storage/s3-storage-provider.ts). It needs no credentials and no
10
+ * network.
11
+ *
12
+ * Returns null for a bucket name with a dot: under HTTPS, such a name does not
13
+ * match the certificate of *.s3.<region>.amazonaws.com. Such a bucket needs
14
+ * an endpoint, so that the bucket is in the path of the URL.
11
15
  */
12
- export async function findHostnameForAwsS3RegionAndBucket(region, bucket) {
13
- const client = new S3Client({ region });
14
- let hostname = '';
15
- const captureHostname = (_next) => async (args) => {
16
- if (typeof args.request === 'object' &&
17
- args.request != null &&
18
- 'hostname' in args.request &&
19
- typeof args.request['hostname'] === 'string') {
20
- hostname = args.request['hostname'];
21
- }
22
- const err = new Error('SHORT_CIRCUIT');
23
- err.name = 'SHORT_CIRCUIT';
24
- throw err; // short-circuit before auth/send
25
- };
26
- client.middlewareStack.add(captureHostname, {
27
- name: 'captureS3Hostname',
28
- step: 'build',
29
- priority: 'high', // run early in build
30
- });
31
- try {
32
- await client.send(new HeadObjectCommand({ Bucket: bucket, Key: DUMMY_KEY }));
16
+ export function findHostnameForAwsS3RegionAndBucket(region, bucket) {
17
+ if (bucket.includes('.')) {
18
+ return null;
33
19
  }
34
- catch (e) {
35
- if (typeof e !== 'object' ||
36
- e == null ||
37
- !('name' in e) ||
38
- e.name !== 'SHORT_CIRCUIT') {
39
- throw e;
40
- }
41
- }
42
- return hostname;
20
+ return `${bucket}.s3.${region}.amazonaws.com`;
43
21
  }
@@ -39,6 +39,7 @@ export type PublishContentConfigNormalized = {
39
39
  includeWellKnown: boolean;
40
40
  assetInclusionTest: AssetInclusionTest | null;
41
41
  hiddenItems: string[];
42
+ hiddenItemsAsWritten: string[];
42
43
  contentCompression: ContentCompressionTypes[];
43
44
  brotliQuality: number | undefined;
44
45
  contentTypes: ContentTypeDef[];
@@ -1 +1 @@
1
- {"version":3,"file":"publish-content-config.d.ts","sourceRoot":"","sources":["../../../../src/models/config/publish-content-config.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,+BAA+B,EACrC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;AAGxD,MAAM,MAAM,cAAc,GAAG;IAE3B,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC;IAG/B,WAAW,EAAE,MAAM,CAAC;IAIpB,IAAI,CAAC,EAAE,OAAO,CAAC;IAIf,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;IACd,gBAAgB,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B;AAID,MAAM,MAAM,wBAAwB,GAAG,OAAO,GAAG;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtE,MAAM,MAAM,kBAAkB,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,KAAK,wBAAwB,CAAC;AAEtG,MAAM,MAAM,oBAAoB,GAAG;IAEjC,OAAO,EAAE,MAAM,CAAC;IAMh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IAGvB,YAAY,CAAC,EAAE,cAAc,EAAE,CAAC;IAGhC,MAAM,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,cAAc,EAAE,CAAC;IAC9B,eAAe,EAAE,OAAO,CAAC;IACzB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,kBAAkB,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC9C,WAAW,EAAE,MAAM,EAAE,CAAC;IAGtB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,kBAAkB,EAAE,uBAAuB,EAAE,CAAC;IAC9C,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,YAAY,EAAE,cAAc,EAAE,CAAC;IAC/B,MAAM,EAAE,+BAA+B,GAAG,IAAI,CAAC;CAChD,CAAC"}
@@ -2,6 +2,8 @@ export type IndexMetadata = {
2
2
  publishedTime?: number;
3
3
  expirationTime?: number;
4
4
  requires?: string[];
5
+ fileCount?: number;
6
+ hiddenFileCount?: number;
5
7
  otherFields?: Record<string, string>;
6
8
  };
7
9
  export declare const SUPPORTED_INDEX_FEATURES: readonly string[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/server/index.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IAIxB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAGpB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAMF,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAGrD,CAAC;AAIF,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAqBxF;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,aAAa,GAAG,IAAI,CA2BjG;AAGD,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,aAAa,EAC5B,iBAAiB,GAAE,SAAS,MAAM,EAA6B,GAC9D,MAAM,EAAE,CAEV"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/server/index.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IAIxB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAGpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IAGzB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAMF,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAGrD,CAAC;AAIF,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA4BxF;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,aAAa,GAAG,IAAI,CAkCjG;AAGD,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,aAAa,EAC5B,iBAAiB,GAAE,SAAS,MAAM,EAA6B,GAC9D,MAAM,EAAE,CAEV"}
@@ -12,7 +12,7 @@ export const SUPPORTED_INDEX_FEATURES = [
12
12
  // Hidden files: index keys that start with 'hidden:'.
13
13
  HIDDEN_INDEX_FEATURE,
14
14
  ];
15
- const KNOWN_FIELDS = ['publishedTime', 'expirationTime', 'requires'];
15
+ const KNOWN_FIELDS = ['publishedTime', 'expirationTime', 'requires', 'fileCount', 'hiddenFileCount'];
16
16
  export function encodeIndexMetadata(indexMetadata) {
17
17
  const result = { ...indexMetadata.otherFields };
18
18
  if (indexMetadata.publishedTime != null && !isNaN(indexMetadata.publishedTime)) {
@@ -29,6 +29,12 @@ export function encodeIndexMetadata(indexMetadata) {
29
29
  }
30
30
  result['requires'] = indexMetadata.requires.join(',');
31
31
  }
32
+ for (const field of ['fileCount', 'hiddenFileCount']) {
33
+ const value = indexMetadata[field];
34
+ if (value != null && Number.isInteger(value) && value >= 0) {
35
+ result[field] = String(value);
36
+ }
37
+ }
32
38
  return result;
33
39
  }
34
40
  export function decodeIndexMetadata(obj) {
@@ -50,10 +56,16 @@ export function decodeIndexMetadata(obj) {
50
56
  otherFields[key] = String(value);
51
57
  }
52
58
  }
59
+ const count = (field) => {
60
+ const value = getMetadataFieldValue(obj, field);
61
+ return value != null && /^\d+$/.test(String(value)) ? Number(value) : undefined;
62
+ };
53
63
  return {
54
64
  publishedTime: !isNaN(publishedTime) ? publishedTime : undefined,
55
65
  expirationTime: !isNaN(expirationTime) ? expirationTime : undefined,
56
66
  requires: requires.length > 0 ? requires : undefined,
67
+ fileCount: count('fileCount'),
68
+ hiddenFileCount: count('hiddenFileCount'),
57
69
  otherFields,
58
70
  };
59
71
  }
@@ -39,6 +39,7 @@ export type PublishContentConfigNormalized = {
39
39
  includeWellKnown: boolean;
40
40
  assetInclusionTest: AssetInclusionTest | null;
41
41
  hiddenItems: string[];
42
+ hiddenItemsAsWritten: string[];
42
43
  contentCompression: ContentCompressionTypes[];
43
44
  brotliQuality: number | undefined;
44
45
  contentTypes: ContentTypeDef[];
@@ -1 +1 @@
1
- {"version":3,"file":"publish-content-config.d.ts","sourceRoot":"","sources":["../../../../src/models/config/publish-content-config.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,+BAA+B,EACrC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,yBAAyB,CAAC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C;IAGvB,YAAY,CAAC,EAAE,cAAc,EAAE,CAAC;IAGhC,MAAM,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,cAAc,EAAE,CAAC;IAC9B,eAAe,EAAE,OAAO,CAAC;IACzB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,kBAAkB,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC9C,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,kBAAkB,EAAE,uBAAuB,EAAE,CAAC;IAC9C,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,YAAY,EAAE,cAAc,EAAE,CAAC;IAC/B,MAAM,EAAE,+BAA+B,GAAG,IAAI,CAAC;CAChD,CAAC"}
1
+ {"version":3,"file":"publish-content-config.d.ts","sourceRoot":"","sources":["../../../../src/models/config/publish-content-config.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,+BAA+B,EACrC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;AAGxD,MAAM,MAAM,cAAc,GAAG;IAE3B,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC;IAG/B,WAAW,EAAE,MAAM,CAAC;IAIpB,IAAI,CAAC,EAAE,OAAO,CAAC;IAIf,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;IACd,gBAAgB,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,IAAI,EAAE,MAAM,GA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,SAAS,CAAC;IAClC,YAAY,EAAE,cAAc,EAAE,CAAC;IAC/B,MAAM,EAAE,+BAA+B,GAAG,IAAI,CAAC;CAChD,CAAC"}
@@ -2,6 +2,8 @@ export type IndexMetadata = {
2
2
  publishedTime?: number;
3
3
  expirationTime?: number;
4
4
  requires?: string[];
5
+ fileCount?: number;
6
+ hiddenFileCount?: number;
5
7
  otherFields?: Record<string, string>;
6
8
  };
7
9
  export declare const SUPPORTED_INDEX_FEATURES: readonly string[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/server/index.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IAIxB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAGpB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAMF,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAGrD,CAAC;AAIF,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAqBxF;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,aAAa,GAAG,IAAI,CA2BjG;AAGD,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,aAAa,EAC5B,iBAAiB,GAAE,SAAS,MAAM,EAA6B,GAC9D,MAAM,EAAE,CAEV"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/server/index.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IAIxB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAGpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IAGzB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAMF,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAGrD,CAAC;AAIF,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA4BxF;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,aAAa,GAAG,IAAI,CAkCjG;AAGD,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,aAAa,EAC5B,iBAAiB,GAAE,SAAS,MAAM,EAA6B,GAC9D,MAAM,EAAE,CAEV"}
@@ -12,7 +12,7 @@ export const SUPPORTED_INDEX_FEATURES = [
12
12
  // Hidden files: index keys that start with 'hidden:'.
13
13
  HIDDEN_INDEX_FEATURE,
14
14
  ];
15
- const KNOWN_FIELDS = ['publishedTime', 'expirationTime', 'requires'];
15
+ const KNOWN_FIELDS = ['publishedTime', 'expirationTime', 'requires', 'fileCount', 'hiddenFileCount'];
16
16
  export function encodeIndexMetadata(indexMetadata) {
17
17
  const result = { ...indexMetadata.otherFields };
18
18
  if (indexMetadata.publishedTime != null && !isNaN(indexMetadata.publishedTime)) {
@@ -29,6 +29,12 @@ export function encodeIndexMetadata(indexMetadata) {
29
29
  }
30
30
  result['requires'] = indexMetadata.requires.join(',');
31
31
  }
32
+ for (const field of ['fileCount', 'hiddenFileCount']) {
33
+ const value = indexMetadata[field];
34
+ if (value != null && Number.isInteger(value) && value >= 0) {
35
+ result[field] = String(value);
36
+ }
37
+ }
32
38
  return result;
33
39
  }
34
40
  export function decodeIndexMetadata(obj) {
@@ -50,10 +56,16 @@ export function decodeIndexMetadata(obj) {
50
56
  otherFields[key] = String(value);
51
57
  }
52
58
  }
59
+ const count = (field) => {
60
+ const value = getMetadataFieldValue(obj, field);
61
+ return value != null && /^\d+$/.test(String(value)) ? Number(value) : undefined;
62
+ };
53
63
  return {
54
64
  publishedTime: !isNaN(publishedTime) ? publishedTime : undefined,
55
65
  expirationTime: !isNaN(expirationTime) ? expirationTime : undefined,
56
66
  requires: requires.length > 0 ? requires : undefined,
67
+ fileCount: count('fileCount'),
68
+ hiddenFileCount: count('hiddenFileCount'),
57
69
  otherFields,
58
70
  };
59
71
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fastly/compute-js-static-publish",
3
3
  "type": "module",
4
- "version": "8.1.0-beta.2",
4
+ "version": "8.1.0-beta.3",
5
5
  "description": "Static Publisher for Fastly Compute JavaScript",
6
6
  "main": "build/server/server/index.js",
7
7
  "exports": {
@@ -12,6 +12,7 @@ const config = {
12
12
  // excludeDotFiles: true,
13
13
  // includeWellKnown: true,
14
14
  // assetInclusionTest: (assetKey) => true,
15
+ // hiddenItems: [],
15
16
  // contentCompression: [ 'br', 'gzip' ],
16
17
  // brotliQuality: 11,
17
18
  // contentTypes: [
@@ -19,16 +19,26 @@ async function handleRequest(event) {
19
19
  return selection.response;
20
20
  }
21
21
 
22
+ // Code that must run before the published files goes here.
23
+
24
+ // Serve the published file for the request. With fallback: false, a path
25
+ // that has no file does not get the SPA file or the 404 page here.
22
26
  const response = await publisherServer.serveRequest(request, {
23
27
  collectionName: selection.collectionName,
24
28
  pathname: selection.pathname,
29
+ fallback: false,
25
30
  });
26
31
  if (response != null) {
27
32
  return response;
28
33
  }
29
34
 
30
35
  // Do custom things here!
31
- // Handle API requests, serve non-static responses, etc.
36
+ // Handle API requests, serve non-static responses, etc. This code runs only
37
+ // for the requests that no published file matches.
32
38
 
33
- return new Response('Not found', { status: 404 });
39
+ // When nothing else matches, serve the SPA file or the 404 page.
40
+ const fallback = await publisherServer.serveFallback(request, {
41
+ collectionName: selection.collectionName,
42
+ });
43
+ return fallback ?? new Response('Not found', { status: 404 });
34
44
  }