@kungfu-tech/buildchain 2.8.17 → 2.9.0

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.
@@ -277,6 +277,53 @@ function syncStaticArtifactArgs({ artifactRoot, bucket, objectPrefix }) {
277
277
  return args;
278
278
  }
279
279
 
280
+ function directoryIndexAliasKeys({ objectPrefix, relativeIndexPath }) {
281
+ const normalizedPrefix = normalizeS3Key(objectPrefix);
282
+ if (!normalizedPrefix) {
283
+ return [];
284
+ }
285
+ const normalizedIndexPath = normalizeS3Key(relativeIndexPath);
286
+ if (!normalizedIndexPath.endsWith("index.html")) {
287
+ return [];
288
+ }
289
+ const directory = normalizeS3Key(normalizedIndexPath.slice(0, -"index.html".length));
290
+ const aliasBase = joinS3Key(normalizedPrefix, directory);
291
+ return [...new Set([aliasBase, `${aliasBase}/`].filter(Boolean))];
292
+ }
293
+
294
+ function directoryIndexAliasOperations({ surfaceArtifactRoot, bucket, binding }) {
295
+ if (binding.directoryIndexResolution === false || !bucket || !binding.objectPrefix || !fs.existsSync(surfaceArtifactRoot)) {
296
+ return [];
297
+ }
298
+ return listFiles(surfaceArtifactRoot, ".")
299
+ .filter((filePath) => path.basename(filePath) === (binding.directoryIndex || "index.html"))
300
+ .flatMap((filePath) => {
301
+ const relativeIndexPath = toPosix(path.relative(surfaceArtifactRoot, filePath));
302
+ return directoryIndexAliasKeys({ objectPrefix: binding.objectPrefix, relativeIndexPath }).map((key) => ({
303
+ action: "write-directory-index-alias",
304
+ surface: binding.surface,
305
+ command: "aws",
306
+ args: [
307
+ "s3api",
308
+ "put-object",
309
+ "--bucket",
310
+ bucket,
311
+ "--key",
312
+ key,
313
+ "--body",
314
+ filePath,
315
+ "--content-type",
316
+ "text/html",
317
+ ],
318
+ routing: {
319
+ ...(binding.routing || {}),
320
+ directoryIndexAlias: key,
321
+ directoryIndexSource: relativeIndexPath,
322
+ },
323
+ }));
324
+ });
325
+ }
326
+
280
327
  function defaultCommandRunner({ command, args, stdin = "" }) {
281
328
  const result = spawnSync(command, args, {
282
329
  encoding: "utf8",
@@ -1345,6 +1392,7 @@ function deployBindingOperations({ artifactRoot, deployConfig, manifest, binding
1345
1392
  args: syncStaticArtifactArgs({ artifactRoot: surfaceArtifactRoot, bucket, objectPrefix: binding.objectPrefix }),
1346
1393
  routing: binding.routing,
1347
1394
  },
1395
+ ...directoryIndexAliasOperations({ surfaceArtifactRoot, bucket, binding }),
1348
1396
  {
1349
1397
  action: "write-deployment-manifest",
1350
1398
  surface: binding.surface,