sst 2.24.22 → 2.24.23

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.
@@ -63,7 +63,7 @@ export declare class NextjsSite extends SsrSite {
63
63
  private createWarmer;
64
64
  protected createCloudFrontDistributionForRegional(): Distribution;
65
65
  protected createCloudFrontDistributionForEdge(): Distribution;
66
- protected buildServerCachePolicy(): CachePolicy;
66
+ protected useServerBehaviorCachePolicy(): CachePolicy;
67
67
  private buildImageBehavior;
68
68
  protected generateBuildId(): string;
69
69
  getConstructMetadata(): {
@@ -255,8 +255,7 @@ export class NextjsSite extends SsrSite {
255
255
  */
256
256
  const { customDomain, cdk } = this.props;
257
257
  const cfDistributionProps = cdk?.distribution || {};
258
- const cachePolicy = cdk?.serverCachePolicy ?? this.buildServerCachePolicy();
259
- const serverBehavior = this.buildDefaultBehaviorForRegional(cachePolicy);
258
+ const serverBehavior = this.buildDefaultBehaviorForRegional();
260
259
  return new Distribution(this, "CDN", {
261
260
  scopeOverride: this,
262
261
  customDomain,
@@ -271,7 +270,7 @@ export class NextjsSite extends SsrSite {
271
270
  additionalBehaviors: {
272
271
  "api/*": serverBehavior,
273
272
  "_next/data/*": serverBehavior,
274
- "_next/image*": this.buildImageBehavior(cachePolicy),
273
+ "_next/image*": this.buildImageBehavior(),
275
274
  ...(cfDistributionProps.additionalBehaviors || {}),
276
275
  },
277
276
  },
@@ -281,8 +280,7 @@ export class NextjsSite extends SsrSite {
281
280
  createCloudFrontDistributionForEdge() {
282
281
  const { customDomain, cdk } = this.props;
283
282
  const cfDistributionProps = cdk?.distribution || {};
284
- const cachePolicy = cdk?.serverCachePolicy ?? this.buildServerCachePolicy();
285
- const serverBehavior = this.buildDefaultBehaviorForEdge(cachePolicy);
283
+ const serverBehavior = this.buildDefaultBehaviorForEdge();
286
284
  return new Distribution(this, "CDN", {
287
285
  scopeOverride: this,
288
286
  customDomain,
@@ -297,15 +295,15 @@ export class NextjsSite extends SsrSite {
297
295
  additionalBehaviors: {
298
296
  "api/*": serverBehavior,
299
297
  "_next/data/*": serverBehavior,
300
- "_next/image*": this.buildImageBehavior(cachePolicy),
298
+ "_next/image*": this.buildImageBehavior(),
301
299
  ...(cfDistributionProps.additionalBehaviors || {}),
302
300
  },
303
301
  },
304
302
  },
305
303
  });
306
304
  }
307
- buildServerCachePolicy() {
308
- return super.buildServerCachePolicy([
305
+ useServerBehaviorCachePolicy() {
306
+ return super.useServerBehaviorCachePolicy([
309
307
  "accept",
310
308
  "rsc",
311
309
  "next-router-prefetch",
@@ -313,7 +311,7 @@ export class NextjsSite extends SsrSite {
313
311
  "next-url",
314
312
  ]);
315
313
  }
316
- buildImageBehavior(cachePolicy) {
314
+ buildImageBehavior() {
317
315
  const { cdk, regional } = this.props;
318
316
  const imageFn = this.createImageOptimizationFunction();
319
317
  const imageFnUrl = imageFn.addFunctionUrl({
@@ -327,7 +325,7 @@ export class NextjsSite extends SsrSite {
327
325
  allowedMethods: AllowedMethods.ALLOW_ALL,
328
326
  cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
329
327
  compress: true,
330
- cachePolicy,
328
+ cachePolicy: cdk?.serverCachePolicy ?? this.useServerBehaviorCachePolicy(),
331
329
  responseHeadersPolicy: cdk?.responseHeadersPolicy,
332
330
  edgeLambdas: regional?.enableServerUrlIamAuth
333
331
  ? [
@@ -20,6 +20,7 @@ export declare class RemixSite extends SsrSite {
20
20
  serverBuildOutputFile: string;
21
21
  clientBuildOutputDir: string;
22
22
  clientBuildVersionedSubDir: string;
23
+ clientCFFunctionInjection: string;
23
24
  };
24
25
  private createServerLambdaBundle;
25
26
  protected createFunctionForRegional(): SsrFunction;
@@ -53,6 +53,11 @@ export class RemixSite extends SsrSite {
53
53
  serverBuildOutputFile: "build/index.js",
54
54
  clientBuildOutputDir: "public",
55
55
  clientBuildVersionedSubDir: "build",
56
+ // Note: When using libraries like remix-flat-routes the file can
57
+ // contains special characters like "+". It needs to be encoded.
58
+ clientCFFunctionInjection: `
59
+ request.uri = request.uri.split('/').map(encodeURIComponent).join('/');
60
+ `,
56
61
  };
57
62
  }
58
63
  createServerLambdaBundle(wrapperFile) {
@@ -6,6 +6,7 @@ import { FunctionBindingProps } from "./util/functionBinding.js";
6
6
  import { IVpc } from "aws-cdk-lib/aws-ec2";
7
7
  import { Cluster, ContainerDefinitionOptions } from "aws-cdk-lib/aws-ecs";
8
8
  import { RetentionDays } from "aws-cdk-lib/aws-logs";
9
+ import { ApplicationTargetGroupProps } from "aws-cdk-lib/aws-elasticloadbalancingv2";
9
10
  declare const supportedCpus: {
10
11
  "0.25 vCPU": number;
11
12
  "0.5 vCPU": number;
@@ -248,7 +249,9 @@ export interface ServiceProps {
248
249
  * @example
249
250
  * ```js
250
251
  * {
251
- * cloudfrontDistribution: false
252
+ * cdk: {
253
+ * cloudfrontDistribution: false
254
+ * }
252
255
  * }
253
256
  * ```
254
257
  */
@@ -259,11 +262,30 @@ export interface ServiceProps {
259
262
  * @example
260
263
  * ```js
261
264
  * {
262
- * applicationLoadBalancer: false
265
+ * cdk: {
266
+ * applicationLoadBalancer: false
267
+ * }
263
268
  * }
264
269
  * ```
265
270
  */
266
271
  applicationLoadBalancer?: boolean;
272
+ /**
273
+ * Customize the Application Load Balancer's target group.
274
+ * @default true
275
+ * @example
276
+ * ```js
277
+ * {
278
+ * cdk: {
279
+ * applicationLoadBalancerTargetGroup: {
280
+ * healthCheck: {
281
+ * path: "/health"
282
+ * }
283
+ * }
284
+ * }
285
+ * }
286
+ * ```
287
+ */
288
+ applicationLoadBalancerTargetGroup?: ApplicationTargetGroupProps;
267
289
  /**
268
290
  * Customizing the container definition for the ECS task.
269
291
  * @example
@@ -427,6 +427,8 @@ export class Service extends Construct {
427
427
  const { cdk } = this.props;
428
428
  // Do not create load balancer if disabled
429
429
  if (cdk?.applicationLoadBalancer === false) {
430
+ if (cdk?.applicationLoadBalancerTargetGroup)
431
+ throw new VisibleError(`In the "${this.node.id}" Service, the "cdk.applicationLoadBalancerTargetGroup" cannot be applied if the Application Load Balancer is diabled.`);
430
432
  return {};
431
433
  }
432
434
  const alb = new ApplicationLoadBalancer(this, "LoadBalancer", {
@@ -437,6 +439,7 @@ export class Service extends Construct {
437
439
  const target = listener.addTargets("TargetGroup", {
438
440
  port: 80,
439
441
  targets: [service],
442
+ ...cdk?.applicationLoadBalancerTargetGroup,
440
443
  });
441
444
  return { alb, target };
442
445
  }
@@ -19,6 +19,7 @@ export type SsrBuildConfig = {
19
19
  clientBuildOutputDir: string;
20
20
  clientBuildVersionedSubDir: string;
21
21
  clientBuildS3KeyPrefix?: string;
22
+ clientCFFunctionInjection?: string;
22
23
  prerenderedBuildOutputDir?: string;
23
24
  prerenderedBuildS3KeyPrefix?: string;
24
25
  };
@@ -284,7 +285,10 @@ export declare abstract class SsrSite extends Construct implements SSTConstruct
284
285
  private serverLambdaForDev?;
285
286
  private serverUrlSigningFunction?;
286
287
  protected bucket: Bucket;
287
- private cfFunction;
288
+ private serverCfFunction?;
289
+ private serverBehaviorCachePolicy?;
290
+ private serverBehaviorOriginRequestPolicy?;
291
+ private staticCfFunction?;
288
292
  private s3Origin;
289
293
  private distribution;
290
294
  constructor(scope: Construct, id: string, props?: SsrSiteProps);
@@ -347,19 +351,22 @@ export declare abstract class SsrSite extends Construct implements SSTConstruct
347
351
  private grantServerS3Permissions;
348
352
  private grantServerCloudFrontPermissions;
349
353
  private createCloudFrontS3Origin;
350
- private createCloudFrontFunction;
351
354
  protected createCloudFrontDistributionForRegional(): Distribution;
352
355
  protected createCloudFrontDistributionForEdge(): Distribution;
353
- protected buildDefaultBehaviorForRegional(cachePolicy: ICachePolicy): BehaviorOptions;
354
- protected useServerUrlSigningFunction(): EdgeFunction;
355
- protected buildDefaultBehaviorForEdge(cachePolicy: ICachePolicy): BehaviorOptions;
356
- protected buildBehaviorFunctionAssociations(): {
356
+ protected buildDefaultBehaviorForRegional(): BehaviorOptions;
357
+ protected buildDefaultBehaviorForEdge(): BehaviorOptions;
358
+ protected addStaticFileBehaviors(): void;
359
+ protected useServerBehaviorFunctionAssociations(): {
357
360
  eventType: CfFunctionEventType;
358
361
  function: CfFunction;
359
362
  }[];
360
- protected addStaticFileBehaviors(): void;
361
- protected buildServerCachePolicy(allowedHeaders?: string[]): CachePolicy;
362
- protected buildServerOriginRequestPolicy(): import("aws-cdk-lib/aws-cloudfront").IOriginRequestPolicy;
363
+ protected useStaticBehaviorFunctionAssociations(): {
364
+ eventType: CfFunctionEventType;
365
+ function: CfFunction;
366
+ }[];
367
+ protected useServerUrlSigningFunction(): EdgeFunction;
368
+ protected useServerBehaviorCachePolicy(allowedHeaders?: string[]): CachePolicy;
369
+ private useServerBehaviorOriginRequestPolicy;
363
370
  private getS3ContentReplaceValues;
364
371
  private validateSiteExists;
365
372
  private validateTimeout;
@@ -51,7 +51,10 @@ export class SsrSite extends Construct {
51
51
  serverLambdaForDev;
52
52
  serverUrlSigningFunction;
53
53
  bucket;
54
- cfFunction;
54
+ serverCfFunction;
55
+ serverBehaviorCachePolicy;
56
+ serverBehaviorOriginRequestPolicy;
57
+ staticCfFunction;
55
58
  s3Origin;
56
59
  distribution;
57
60
  constructor(scope, id, props) {
@@ -75,8 +78,8 @@ export class SsrSite extends Construct {
75
78
  this.writeTypesFile();
76
79
  useSites().add(stack.stackName, id, this.constructor.name, this.props);
77
80
  if (this.doNotDeploy) {
78
- // @ts-ignore
79
- this.cfFunction = this.bucket = this.s3Origin = this.distribution = null;
81
+ // @ts-expect-error
82
+ this.bucket = this.s3Origin = this.distribution = null;
80
83
  this.serverLambdaForDev = this.createFunctionForDev();
81
84
  return;
82
85
  }
@@ -92,7 +95,6 @@ export class SsrSite extends Construct {
92
95
  this.grantServerS3Permissions();
93
96
  // Create CloudFront
94
97
  this.s3Origin = this.createCloudFrontS3Origin();
95
- this.cfFunction = this.createCloudFrontFunction();
96
98
  this.distribution = this.props.edge
97
99
  ? this.createCloudFrontDistributionForEdge()
98
100
  : this.createCloudFrontDistributionForRegional();
@@ -486,21 +488,9 @@ export class SsrSite extends Construct {
486
488
  originPath: "/" + (this.buildConfig.clientBuildS3KeyPrefix ?? ""),
487
489
  });
488
490
  }
489
- createCloudFrontFunction() {
490
- return new CfFunction(this, "CloudFrontFunction", {
491
- code: CfFunctionCode.fromInline(`
492
- function handler(event) {
493
- var request = event.request;
494
- request.headers["x-forwarded-host"] = request.headers.host;
495
- ${this.buildConfig.serverCFFunctionInjection || ""}
496
- return request;
497
- }`),
498
- });
499
- }
500
491
  createCloudFrontDistributionForRegional() {
501
492
  const { customDomain, cdk } = this.props;
502
493
  const cfDistributionProps = cdk?.distribution || {};
503
- const cachePolicy = cdk?.serverCachePolicy ?? this.buildServerCachePolicy();
504
494
  return new Distribution(this, "CDN", {
505
495
  scopeOverride: this,
506
496
  customDomain,
@@ -511,7 +501,7 @@ function handler(event) {
511
501
  // Override props.
512
502
  ...cfDistributionProps,
513
503
  // these values can NOT be overwritten by cfDistributionProps
514
- defaultBehavior: this.buildDefaultBehaviorForRegional(cachePolicy),
504
+ defaultBehavior: this.buildDefaultBehaviorForRegional(),
515
505
  additionalBehaviors: {
516
506
  ...(cfDistributionProps.additionalBehaviors || {}),
517
507
  },
@@ -522,7 +512,6 @@ function handler(event) {
522
512
  createCloudFrontDistributionForEdge() {
523
513
  const { customDomain, cdk } = this.props;
524
514
  const cfDistributionProps = cdk?.distribution || {};
525
- const cachePolicy = cdk?.serverCachePolicy ?? this.buildServerCachePolicy();
526
515
  return new Distribution(this, "CDN", {
527
516
  scopeOverride: this,
528
517
  customDomain,
@@ -533,7 +522,7 @@ function handler(event) {
533
522
  // Override props.
534
523
  ...cfDistributionProps,
535
524
  // these values can NOT be overwritten by cfDistributionProps
536
- defaultBehavior: this.buildDefaultBehaviorForEdge(cachePolicy),
525
+ defaultBehavior: this.buildDefaultBehaviorForEdge(),
537
526
  additionalBehaviors: {
538
527
  ...(cfDistributionProps.additionalBehaviors || {}),
539
528
  },
@@ -541,7 +530,7 @@ function handler(event) {
541
530
  },
542
531
  });
543
532
  }
544
- buildDefaultBehaviorForRegional(cachePolicy) {
533
+ buildDefaultBehaviorForRegional() {
545
534
  const { timeout, regional, cdk } = this.props;
546
535
  const cfDistributionProps = cdk?.distribution || {};
547
536
  const fnUrl = this.serverLambdaForRegional.addFunctionUrl({
@@ -562,12 +551,12 @@ function handler(event) {
562
551
  allowedMethods: AllowedMethods.ALLOW_ALL,
563
552
  cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
564
553
  compress: true,
565
- cachePolicy,
554
+ cachePolicy: cdk?.serverCachePolicy ?? this.useServerBehaviorCachePolicy(),
566
555
  responseHeadersPolicy: cdk?.responseHeadersPolicy,
567
- originRequestPolicy: this.buildServerOriginRequestPolicy(),
556
+ originRequestPolicy: this.useServerBehaviorOriginRequestPolicy(),
568
557
  ...(cfDistributionProps.defaultBehavior || {}),
569
558
  functionAssociations: [
570
- ...this.buildBehaviorFunctionAssociations(),
559
+ ...this.useServerBehaviorFunctionAssociations(),
571
560
  ...(cfDistributionProps.defaultBehavior?.functionAssociations || []),
572
561
  ],
573
562
  edgeLambdas: [
@@ -584,25 +573,7 @@ function handler(event) {
584
573
  ],
585
574
  };
586
575
  }
587
- useServerUrlSigningFunction() {
588
- this.serverUrlSigningFunction =
589
- this.serverUrlSigningFunction ??
590
- new EdgeFunction(this, "ServerUrlSigningFunction", {
591
- bundle: path.join(__dirname, "../support/signing-function"),
592
- runtime: "nodejs18.x",
593
- handler: "index.handler",
594
- timeout: 10,
595
- memorySize: 128,
596
- permissions: [
597
- new PolicyStatement({
598
- actions: ["lambda:InvokeFunctionUrl"],
599
- resources: [this.serverLambdaForRegional?.functionArn],
600
- }),
601
- ],
602
- });
603
- return this.serverUrlSigningFunction;
604
- }
605
- buildDefaultBehaviorForEdge(cachePolicy) {
576
+ buildDefaultBehaviorForEdge() {
606
577
  const { cdk } = this.props;
607
578
  const cfDistributionProps = cdk?.distribution || {};
608
579
  return {
@@ -611,12 +582,12 @@ function handler(event) {
611
582
  allowedMethods: AllowedMethods.ALLOW_ALL,
612
583
  cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
613
584
  compress: true,
614
- cachePolicy,
585
+ cachePolicy: cdk?.serverCachePolicy ?? this.useServerBehaviorCachePolicy(),
615
586
  responseHeadersPolicy: cdk?.responseHeadersPolicy,
616
- originRequestPolicy: this.buildServerOriginRequestPolicy(),
587
+ originRequestPolicy: this.useServerBehaviorOriginRequestPolicy(),
617
588
  ...(cfDistributionProps.defaultBehavior || {}),
618
589
  functionAssociations: [
619
- ...this.buildBehaviorFunctionAssociations(),
590
+ ...this.useServerBehaviorFunctionAssociations(),
620
591
  ...(cfDistributionProps.defaultBehavior?.functionAssociations || []),
621
592
  ],
622
593
  edgeLambdas: [
@@ -629,14 +600,6 @@ function handler(event) {
629
600
  ],
630
601
  };
631
602
  }
632
- buildBehaviorFunctionAssociations() {
633
- return [
634
- {
635
- eventType: CfFunctionEventType.VIEWER_REQUEST,
636
- function: this.cfFunction,
637
- },
638
- ];
639
- }
640
603
  addStaticFileBehaviors() {
641
604
  const { cdk } = this.props;
642
605
  // Create a template for statics behaviours
@@ -650,27 +613,93 @@ function handler(event) {
650
613
  compress: true,
651
614
  cachePolicy: CachePolicy.CACHING_OPTIMIZED,
652
615
  responseHeadersPolicy: cdk?.responseHeadersPolicy,
616
+ functionAssociations: [
617
+ ...this.useStaticBehaviorFunctionAssociations(),
618
+ ],
653
619
  });
654
620
  }
655
621
  }
656
- buildServerCachePolicy(allowedHeaders) {
657
- return new CachePolicy(this, "ServerCache", {
658
- queryStringBehavior: CacheQueryStringBehavior.all(),
659
- headerBehavior: allowedHeaders && allowedHeaders.length > 0
660
- ? CacheHeaderBehavior.allowList(...allowedHeaders)
661
- : CacheHeaderBehavior.none(),
662
- cookieBehavior: CacheCookieBehavior.none(),
663
- defaultTtl: CdkDuration.days(0),
664
- maxTtl: CdkDuration.days(365),
665
- minTtl: CdkDuration.days(0),
666
- enableAcceptEncodingBrotli: true,
667
- enableAcceptEncodingGzip: true,
668
- comment: "SST server response cache policy",
669
- });
622
+ useServerBehaviorFunctionAssociations() {
623
+ this.serverCfFunction =
624
+ this.serverCfFunction ??
625
+ new CfFunction(this, "CloudFrontFunction", {
626
+ code: CfFunctionCode.fromInline(`
627
+ function handler(event) {
628
+ var request = event.request;
629
+ request.headers["x-forwarded-host"] = request.headers.host;
630
+ ${this.buildConfig.serverCFFunctionInjection || ""}
631
+ return request;
632
+ }`),
633
+ });
634
+ return [
635
+ {
636
+ eventType: CfFunctionEventType.VIEWER_REQUEST,
637
+ function: this.serverCfFunction,
638
+ },
639
+ ];
640
+ }
641
+ useStaticBehaviorFunctionAssociations() {
642
+ if (!this.buildConfig.clientCFFunctionInjection)
643
+ return [];
644
+ this.staticCfFunction =
645
+ this.staticCfFunction ??
646
+ new CfFunction(this, "CloudFrontFunctionForStaticBehavior", {
647
+ code: CfFunctionCode.fromInline(`
648
+ function handler(event) {
649
+ var request = event.request;
650
+ ${this.buildConfig.clientCFFunctionInjection || ""}
651
+ return request;
652
+ }`),
653
+ });
654
+ return [
655
+ {
656
+ eventType: CfFunctionEventType.VIEWER_REQUEST,
657
+ function: this.staticCfFunction,
658
+ },
659
+ ];
660
+ }
661
+ useServerUrlSigningFunction() {
662
+ this.serverUrlSigningFunction =
663
+ this.serverUrlSigningFunction ??
664
+ new EdgeFunction(this, "ServerUrlSigningFunction", {
665
+ bundle: path.join(__dirname, "../support/signing-function"),
666
+ runtime: "nodejs18.x",
667
+ handler: "index.handler",
668
+ timeout: 10,
669
+ memorySize: 128,
670
+ permissions: [
671
+ new PolicyStatement({
672
+ actions: ["lambda:InvokeFunctionUrl"],
673
+ resources: [this.serverLambdaForRegional?.functionArn],
674
+ }),
675
+ ],
676
+ });
677
+ return this.serverUrlSigningFunction;
678
+ }
679
+ useServerBehaviorCachePolicy(allowedHeaders) {
680
+ this.serverBehaviorCachePolicy =
681
+ this.serverBehaviorCachePolicy ??
682
+ new CachePolicy(this, "ServerCache", {
683
+ queryStringBehavior: CacheQueryStringBehavior.all(),
684
+ headerBehavior: allowedHeaders && allowedHeaders.length > 0
685
+ ? CacheHeaderBehavior.allowList(...allowedHeaders)
686
+ : CacheHeaderBehavior.none(),
687
+ cookieBehavior: CacheCookieBehavior.none(),
688
+ defaultTtl: CdkDuration.days(0),
689
+ maxTtl: CdkDuration.days(365),
690
+ minTtl: CdkDuration.days(0),
691
+ enableAcceptEncodingBrotli: true,
692
+ enableAcceptEncodingGzip: true,
693
+ comment: "SST server response cache policy",
694
+ });
695
+ return this.serverBehaviorCachePolicy;
670
696
  }
671
- buildServerOriginRequestPolicy() {
697
+ useServerBehaviorOriginRequestPolicy() {
672
698
  // CloudFront's Managed-AllViewerExceptHostHeader policy
673
- return OriginRequestPolicy.fromOriginRequestPolicyId(this, "ServerOriginRequestPolicy", "b689b0a8-53d0-40ab-baf2-68738e2966ac");
699
+ this.serverBehaviorOriginRequestPolicy =
700
+ this.serverBehaviorOriginRequestPolicy ??
701
+ OriginRequestPolicy.fromOriginRequestPolicyId(this, "ServerOriginRequestPolicy", "b689b0a8-53d0-40ab-baf2-68738e2966ac");
702
+ return this.serverBehaviorOriginRequestPolicy;
674
703
  }
675
704
  /////////////////////
676
705
  // Helper Functions
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "sst",
4
- "version": "2.24.22",
4
+ "version": "2.24.23",
5
5
  "bin": {
6
6
  "sst": "cli/sst.js"
7
7
  },
@@ -68,26 +68,22 @@ export const useJavaHandler = Context.memo(async () => {
68
68
  const buildTask = input.props.java?.buildTask || "build";
69
69
  const outputDir = input.props.java?.buildOutputDir || "distributions";
70
70
  sources.set(input.functionID, srcPath);
71
- async function build() {
72
- // build
73
- await execAsync(`${buildBinary} ${buildTask} -Dorg.gradle.logging.level=${process.env.DEBUG ? "debug" : "lifecycle"}`, {
74
- cwd: srcPath,
75
- });
76
- // unzip
77
- const buildOutput = path.join(srcPath, "build", outputDir);
78
- const zip = (await fs.readdir(buildOutput)).find((f) => f.endsWith(".zip"));
79
- await new Promise((resolve, reject) => {
80
- const zipper = new AdmZip(path.join(buildOutput, zip));
81
- zipper.extractAllToAsync(input.out, false, false, (err) => err ? reject(err) : resolve(undefined));
82
- });
83
- }
84
71
  try {
85
- // Run gradle build once per directory. Otherwise they'll interfere
72
+ // Build
73
+ // Note: run gradle build once per directory. Otherwise they'll interfere
86
74
  // with one another
87
- const buildPromise = runningBuilds.get(buildBinary) ?? build();
75
+ const buildPromise = runningBuilds.get(buildBinary) ??
76
+ execAsync(`${buildBinary} ${buildTask} -Dorg.gradle.logging.level=${process.env.DEBUG ? "debug" : "lifecycle"}`, {
77
+ cwd: srcPath,
78
+ });
88
79
  runningBuilds.set(buildBinary, buildPromise);
89
80
  await buildPromise;
90
81
  runningBuilds.delete(buildBinary);
82
+ // unzip
83
+ const buildOutput = path.join(srcPath, "build", outputDir);
84
+ const zip = (await fs.readdir(buildOutput)).find((f) => f.endsWith(".zip"));
85
+ const zipper = new AdmZip(path.join(buildOutput, zip));
86
+ zipper.extractAllTo(input.out, false, false);
91
87
  return {
92
88
  type: "success",
93
89
  handler: input.props.handler,