|
1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
2 | 2 | // See LICENSE in the project root for license information.
|
3 | 3 |
|
4 |
| -import { Import } from '@rushstack/node-core-library'; |
5 | 4 | import type { IRushPlugin, RushSession, RushConfiguration } from '@rushstack/rush-sdk';
|
6 | 5 | import type {
|
7 |
| - AmazonS3BuildCacheProvider, |
8 | 6 | IAmazonS3BuildCacheProviderOptionsAdvanced,
|
9 | 7 | IAmazonS3BuildCacheProviderOptionsSimple
|
10 | 8 | } from './AmazonS3BuildCacheProvider';
|
11 | 9 |
|
12 |
| -const AmazonS3BuildCacheProviderModule: typeof import('./AmazonS3BuildCacheProvider') = Import.lazy( |
13 |
| - './AmazonS3BuildCacheProvider', |
14 |
| - require |
15 |
| -); |
16 |
| - |
17 | 10 | const PLUGIN_NAME: string = 'AmazonS3BuildCachePlugin';
|
18 | 11 |
|
19 | 12 | /**
|
@@ -54,54 +47,53 @@ export class RushAmazonS3BuildCachePlugin implements IRushPlugin {
|
54 | 47 |
|
55 | 48 | public apply(rushSession: RushSession, rushConfig: RushConfiguration): void {
|
56 | 49 | rushSession.hooks.initialize.tap(PLUGIN_NAME, () => {
|
57 |
| - rushSession.registerCloudBuildCacheProviderFactory( |
58 |
| - 'amazon-s3', |
59 |
| - (buildCacheConfig): AmazonS3BuildCacheProvider => { |
60 |
| - type IBuildCache = typeof buildCacheConfig & { |
61 |
| - amazonS3Configuration: IAmazonS3ConfigurationJson; |
62 |
| - }; |
63 |
| - const { amazonS3Configuration } = buildCacheConfig as IBuildCache; |
64 |
| - let options: |
65 |
| - | IAmazonS3BuildCacheProviderOptionsAdvanced |
66 |
| - | IAmazonS3BuildCacheProviderOptionsSimple |
67 |
| - | undefined; |
68 |
| - const { s3Endpoint, s3Bucket, s3Region } = amazonS3Configuration; |
69 |
| - const s3Prefix: undefined | string = amazonS3Configuration.s3Prefix || undefined; |
70 |
| - const isCacheWriteAllowed: boolean = !!amazonS3Configuration.isCacheWriteAllowed; |
| 50 | + rushSession.registerCloudBuildCacheProviderFactory('amazon-s3', async (buildCacheConfig) => { |
| 51 | + type IBuildCache = typeof buildCacheConfig & { |
| 52 | + amazonS3Configuration: IAmazonS3ConfigurationJson; |
| 53 | + }; |
| 54 | + const { amazonS3Configuration } = buildCacheConfig as IBuildCache; |
| 55 | + let options: |
| 56 | + | IAmazonS3BuildCacheProviderOptionsAdvanced |
| 57 | + | IAmazonS3BuildCacheProviderOptionsSimple |
| 58 | + | undefined; |
| 59 | + const { s3Endpoint, s3Bucket, s3Region } = amazonS3Configuration; |
| 60 | + const s3Prefix: undefined | string = amazonS3Configuration.s3Prefix || undefined; |
| 61 | + const isCacheWriteAllowed: boolean = !!amazonS3Configuration.isCacheWriteAllowed; |
71 | 62 |
|
72 |
| - if (s3Prefix && s3Prefix[0] === '/') { |
73 |
| - throw new Error('s3Prefix should not have a leading /'); |
74 |
| - } |
| 63 | + if (s3Prefix && s3Prefix[0] === '/') { |
| 64 | + throw new Error('s3Prefix should not have a leading /'); |
| 65 | + } |
75 | 66 |
|
76 |
| - // mutually exclusive |
77 |
| - if (s3Bucket && s3Endpoint) { |
78 |
| - throw new Error('Only one of "s3Bucket" or "s3Endpoint" must be provided.'); |
79 |
| - } |
| 67 | + // mutually exclusive |
| 68 | + if (s3Bucket && s3Endpoint) { |
| 69 | + throw new Error('Only one of "s3Bucket" or "s3Endpoint" must be provided.'); |
| 70 | + } |
80 | 71 |
|
81 |
| - if (s3Endpoint) { |
82 |
| - options = { |
83 |
| - // IAmazonS3BuildCacheProviderOptionsAdvanced |
84 |
| - s3Region, |
85 |
| - s3Endpoint, |
86 |
| - s3Prefix, |
87 |
| - isCacheWriteAllowed |
88 |
| - }; |
89 |
| - } |
90 |
| - if (s3Bucket) { |
91 |
| - options = { |
92 |
| - // IAmazonS3BuildCacheProviderOptionsSimple |
93 |
| - s3Region, |
94 |
| - s3Bucket, |
95 |
| - s3Prefix, |
96 |
| - isCacheWriteAllowed |
97 |
| - }; |
98 |
| - } |
99 |
| - if (!options) { |
100 |
| - throw new Error('You must provide either an s3Endpoint or s3Bucket'); |
101 |
| - } |
102 |
| - return new AmazonS3BuildCacheProviderModule.AmazonS3BuildCacheProvider(options, rushSession); |
| 72 | + if (s3Endpoint) { |
| 73 | + options = { |
| 74 | + // IAmazonS3BuildCacheProviderOptionsAdvanced |
| 75 | + s3Region, |
| 76 | + s3Endpoint, |
| 77 | + s3Prefix, |
| 78 | + isCacheWriteAllowed |
| 79 | + }; |
103 | 80 | }
|
104 |
| - ); |
| 81 | + if (s3Bucket) { |
| 82 | + options = { |
| 83 | + // IAmazonS3BuildCacheProviderOptionsSimple |
| 84 | + s3Region, |
| 85 | + s3Bucket, |
| 86 | + s3Prefix, |
| 87 | + isCacheWriteAllowed |
| 88 | + }; |
| 89 | + } |
| 90 | + if (!options) { |
| 91 | + throw new Error('You must provide either an s3Endpoint or s3Bucket'); |
| 92 | + } |
| 93 | + |
| 94 | + const { AmazonS3BuildCacheProvider } = await import('./AmazonS3BuildCacheProvider'); |
| 95 | + return new AmazonS3BuildCacheProvider(options, rushSession); |
| 96 | + }); |
105 | 97 | });
|
106 | 98 | }
|
107 | 99 | }
|
0 commit comments