UNPKG

6.32 kBTypeScriptView Raw
1import { Construct } from 'constructs';
2import { AssetOptions, FileAssetPackaging } from './assets';
3import { FingerprintOptions } from './fs';
4import { Stack } from './stack';
5import { Construct as CoreConstruct } from './construct-compat';
6/**
7 * Initialization properties for `AssetStaging`.
8 */
9export interface AssetStagingProps extends FingerprintOptions, AssetOptions {
10 /**
11 * The source file or directory to copy from.
12 */
13 readonly sourcePath: string;
14}
15/**
16 * Stages a file or directory from a location on the file system into a staging
17 * directory.
18 *
19 * This is controlled by the context key 'aws:cdk:asset-staging' and enabled
20 * by the CLI by default in order to ensure that when the CDK app exists, all
21 * assets are available for deployment. Otherwise, if an app references assets
22 * in temporary locations, those will not be available when it exists (see
23 * https://github.com/aws/aws-cdk/issues/1716).
24 *
25 * The `stagedPath` property is a stringified token that represents the location
26 * of the file or directory after staging. It will be resolved only during the
27 * "prepare" stage and may be either the original path or the staged path
28 * depending on the context setting.
29 *
30 * The file/directory are staged based on their content hash (fingerprint). This
31 * means that only if content was changed, copy will happen.
32 */
33export declare class AssetStaging extends CoreConstruct {
34 /**
35 * The directory inside the bundling container into which the asset sources will be mounted.
36 */
37 static readonly BUNDLING_INPUT_DIR = "/asset-input";
38 /**
39 * The directory inside the bundling container into which the bundled output should be written.
40 */
41 static readonly BUNDLING_OUTPUT_DIR = "/asset-output";
42 /**
43 * Clears the asset hash cache
44 */
45 static clearAssetHashCache(): void;
46 /**
47 * Cache of asset hashes based on asset configuration to avoid repeated file
48 * system and bundling operations.
49 */
50 private static assetCache;
51 /**
52 * Absolute path to the asset data.
53 *
54 * If asset staging is disabled, this will just be the source path or
55 * a temporary directory used for bundling.
56 *
57 * If asset staging is enabled it will be the staged path.
58 *
59 * IMPORTANT: If you are going to call `addFileAsset()`, use
60 * `relativeStagedPath()` instead.
61 *
62 * @deprecated - Use `absoluteStagedPath` instead.
63 */
64 readonly stagedPath: string;
65 /**
66 * Absolute path to the asset data.
67 *
68 * If asset staging is disabled, this will just be the source path or
69 * a temporary directory used for bundling.
70 *
71 * If asset staging is enabled it will be the staged path.
72 *
73 * IMPORTANT: If you are going to call `addFileAsset()`, use
74 * `relativeStagedPath()` instead.
75 */
76 readonly absoluteStagedPath: string;
77 /**
78 * The absolute path of the asset as it was referenced by the user.
79 */
80 readonly sourcePath: string;
81 /**
82 * A cryptographic hash of the asset.
83 */
84 readonly assetHash: string;
85 /**
86 * How this asset should be packaged.
87 */
88 readonly packaging: FileAssetPackaging;
89 /**
90 * Whether this asset is an archive (zip or jar).
91 */
92 readonly isArchive: boolean;
93 private readonly fingerprintOptions;
94 private readonly hashType;
95 private readonly assetOutdir;
96 /**
97 * A custom source fingerprint given by the user
98 *
99 * Will not be used literally, always hashed later on.
100 */
101 private customSourceFingerprint?;
102 private readonly cacheKey;
103 private readonly sourceStats;
104 constructor(scope: Construct, id: string, props: AssetStagingProps);
105 /**
106 * A cryptographic hash of the asset.
107 *
108 * @deprecated see `assetHash`.
109 */
110 get sourceHash(): string;
111 /**
112 * Return the path to the staged asset, relative to the Cloud Assembly (manifest) directory of the given stack
113 *
114 * Only returns a relative path if the asset was staged, returns an absolute path if
115 * it was not staged.
116 *
117 * A bundled asset might end up in the outDir and still not count as
118 * "staged"; if asset staging is disabled we're technically expected to
119 * reference source directories, but we don't have a source directory for the
120 * bundled outputs (as the bundle output is written to a temporary
121 * directory). Nevertheless, we will still return an absolute path.
122 *
123 * A non-obvious directory layout may look like this:
124 *
125 * ```
126 * CLOUD ASSEMBLY ROOT
127 * +-- asset.12345abcdef/
128 * +-- assembly-Stage
129 * +-- MyStack.template.json
130 * +-- MyStack.assets.json <- will contain { "path": "../asset.12345abcdef" }
131 * ```
132 */
133 relativeStagedPath(stack: Stack): string;
134 /**
135 * Stage the source to the target by copying
136 *
137 * Optionally skip if staging is disabled, in which case we pretend we did something but we don't really.
138 */
139 private stageByCopying;
140 /**
141 * Stage the source to the target by bundling
142 *
143 * Optionally skip, in which case we pretend we did something but we don't really.
144 */
145 private stageByBundling;
146 /**
147 * Whether staging has been disabled
148 */
149 private get stagingDisabled();
150 /**
151 * Copies or moves the files from sourcePath to targetPath.
152 *
153 * Moving implies the source directory is temporary and can be trashed.
154 *
155 * Will not do anything if source and target are the same.
156 */
157 private stageAsset;
158 /**
159 * Determine the directory where we're going to write the bundling output
160 *
161 * This is the target directory where we're going to write the staged output
162 * files if we can (if the hash is fully known), or a temporary directory
163 * otherwise.
164 */
165 private determineBundleDir;
166 /**
167 * Bundles an asset to the given directory
168 *
169 * If the given directory already exists, assume that everything's already
170 * in order and don't do anything.
171 *
172 * @param options Bundling options
173 * @param bundleDir Where to create the bundle directory
174 * @returns The fully resolved bundle output directory.
175 */
176 private bundle;
177 private calculateHash;
178}
179
\No newline at end of file