-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(core): move all types from "assets" to "core" #7708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fd8868f
refactor(core): fold "assets" to "core"
f8eafa1
add coverage to for the compatibility layer
e6dec09
Merge remote-tracking branch 'origin/master' into benisrae/refactor/a…
b00a1a9
Merge branch 'master' into benisrae/refactor/assets
004f58a
Merge branch 'master' into benisrae/refactor/assets
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { SymlinkFollowMode } from '@aws-cdk/core'; | ||
| import { FollowMode } from './fs/follow-mode'; | ||
|
|
||
| export function toSymlinkFollow(follow?: FollowMode): SymlinkFollowMode | undefined { | ||
| if (!follow) { | ||
| return undefined; | ||
| } | ||
|
|
||
| switch (follow) { | ||
| case FollowMode.NEVER: return SymlinkFollowMode.NEVER; | ||
| case FollowMode.ALWAYS: return SymlinkFollowMode.ALWAYS; | ||
| case FollowMode.BLOCK_EXTERNAL: return SymlinkFollowMode.BLOCK_EXTERNAL; | ||
| case FollowMode.EXTERNAL: return SymlinkFollowMode.EXTERNAL; | ||
| default: | ||
| throw new Error(`unknown follow mode: ${follow}`); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| export * from './api'; | ||
| export * from './fs/follow-mode'; | ||
| export * from './fs/options'; | ||
| export * from './staging'; | ||
| export * from './staging'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,92 +1,29 @@ | ||
| import { Construct, ISynthesisSession } from '@aws-cdk/core'; | ||
| import * as cxapi from '@aws-cdk/cx-api'; | ||
| import * as fs from 'fs'; | ||
| import * as path from 'path'; | ||
| import { copyDirectory, fingerprint, FingerprintOptions } from './fs'; | ||
| import { AssetStaging, Construct } from '@aws-cdk/core'; | ||
| import { toSymlinkFollow } from './compat'; | ||
| import { FingerprintOptions } from './fs/options'; | ||
|
|
||
| /** | ||
| * Deprecated | ||
| * @deprecated use `core.AssetStagingProps` | ||
| */ | ||
| export interface StagingProps extends FingerprintOptions { | ||
| /** | ||
| * Local file or directory to stage. | ||
| */ | ||
| readonly sourcePath: string; | ||
| } | ||
|
|
||
| /** | ||
| * Stages a file or directory from a location on the file system into a staging | ||
| * directory. | ||
| * | ||
| * This is controlled by the context key 'aws:cdk:asset-staging' and enabled | ||
| * by the CLI by default in order to ensure that when the CDK app exists, all | ||
| * assets are available for deployment. Otherwise, if an app references assets | ||
| * in temporary locations, those will not be available when it exists (see | ||
| * https://github.com/aws/aws-cdk/issues/1716). | ||
| * | ||
| * The `stagedPath` property is a stringified token that represents the location | ||
| * of the file or directory after staging. It will be resolved only during the | ||
| * "prepare" stage and may be either the original path or the staged path | ||
| * depending on the context setting. | ||
| * | ||
| * The file/directory are staged based on their content hash (fingerprint). This | ||
| * means that only if content was changed, copy will happen. | ||
| * Deprecated | ||
| * @deprecated use `core.AssetStaging` | ||
| */ | ||
| export class Staging extends Construct { | ||
|
|
||
| /** | ||
| * The path to the asset (stringinfied token). | ||
| * | ||
| * If asset staging is disabled, this will just be the original path. | ||
| * If asset staging is enabled it will be the staged path. | ||
| */ | ||
| public readonly stagedPath: string; | ||
|
|
||
| /** | ||
| * The path of the asset as it was referenced by the user. | ||
| */ | ||
| public readonly sourcePath: string; | ||
|
|
||
| /** | ||
| * A cryptographic hash of the source document(s). | ||
| */ | ||
| public readonly sourceHash: string; | ||
|
|
||
| private readonly fingerprintOptions: FingerprintOptions; | ||
|
|
||
| private readonly relativePath?: string; | ||
|
|
||
| export class Staging extends AssetStaging { | ||
| constructor(scope: Construct, id: string, props: StagingProps) { | ||
| super(scope, id); | ||
|
|
||
| this.sourcePath = props.sourcePath; | ||
| this.fingerprintOptions = props; | ||
| this.sourceHash = fingerprint(this.sourcePath, props); | ||
|
|
||
| const stagingDisabled = this.node.tryGetContext(cxapi.DISABLE_ASSET_STAGING_CONTEXT); | ||
| if (stagingDisabled) { | ||
| this.stagedPath = this.sourcePath; | ||
| } else { | ||
| this.relativePath = 'asset.' + this.sourceHash + path.extname(this.sourcePath); | ||
| this.stagedPath = this.relativePath; // always relative to outdir | ||
| } | ||
| } | ||
|
|
||
| protected synthesize(session: ISynthesisSession) { | ||
| if (!this.relativePath) { | ||
| return; | ||
| } | ||
|
|
||
| const targetPath = path.join(session.assembly.outdir, this.relativePath); | ||
|
|
||
| // asset already staged | ||
| if (fs.existsSync(targetPath)) { | ||
| return; | ||
| } | ||
|
|
||
| // copy file/directory to staging directory | ||
| const stat = fs.statSync(this.sourcePath); | ||
| if (stat.isFile()) { | ||
| fs.copyFileSync(this.sourcePath, targetPath); | ||
| } else if (stat.isDirectory()) { | ||
| fs.mkdirSync(targetPath); | ||
| copyDirectory(this.sourcePath, targetPath, this.fingerprintOptions); | ||
| } else { | ||
| throw new Error(`Unknown file type: ${this.sourcePath}`); | ||
| } | ||
| super(scope, id, { | ||
| sourcePath: props.sourcePath, | ||
| exclude: props.exclude, | ||
| extraHash: props.extraHash, | ||
| follow: toSymlinkFollow(props.follow), | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { SymlinkFollowMode } from '@aws-cdk/core'; | ||
| import { Test } from 'nodeunit'; | ||
| import { FollowMode } from '../lib'; | ||
| import { toSymlinkFollow } from '../lib/compat'; | ||
|
|
||
| export = { | ||
| 'FollowMode compatibility'(test: Test) { | ||
| test.equal(toSymlinkFollow(undefined), null); | ||
| test.equal(toSymlinkFollow(FollowMode.ALWAYS), SymlinkFollowMode.ALWAYS); | ||
| test.equal(toSymlinkFollow(FollowMode.BLOCK_EXTERNAL), SymlinkFollowMode.BLOCK_EXTERNAL); | ||
| test.equal(toSymlinkFollow(FollowMode.EXTERNAL), SymlinkFollowMode.EXTERNAL); | ||
| test.equal(toSymlinkFollow(FollowMode.NEVER), SymlinkFollowMode.NEVER); | ||
| test.done(); | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import * as cxapi from '@aws-cdk/cx-api'; | ||
| import * as fs from 'fs'; | ||
| import * as path from 'path'; | ||
| import { Construct, ISynthesisSession } from './construct-compat'; | ||
| import { FileSystem, FingerprintOptions } from './fs'; | ||
|
|
||
| /** | ||
| * Initialization properties for `AssetStaging`. | ||
| */ | ||
| export interface AssetStagingProps extends FingerprintOptions { | ||
| /** | ||
| * The source file or directory to copy from. | ||
| */ | ||
| readonly sourcePath: string; | ||
| } | ||
|
|
||
| /** | ||
| * Stages a file or directory from a location on the file system into a staging | ||
| * directory. | ||
| * | ||
| * This is controlled by the context key 'aws:cdk:asset-staging' and enabled | ||
| * by the CLI by default in order to ensure that when the CDK app exists, all | ||
| * assets are available for deployment. Otherwise, if an app references assets | ||
| * in temporary locations, those will not be available when it exists (see | ||
| * https://github.com/aws/aws-cdk/issues/1716). | ||
| * | ||
| * The `stagedPath` property is a stringified token that represents the location | ||
| * of the file or directory after staging. It will be resolved only during the | ||
| * "prepare" stage and may be either the original path or the staged path | ||
| * depending on the context setting. | ||
| * | ||
| * The file/directory are staged based on their content hash (fingerprint). This | ||
| * means that only if content was changed, copy will happen. | ||
| */ | ||
| export class AssetStaging extends Construct { | ||
|
|
||
| /** | ||
| * The path to the asset (stringinfied token). | ||
| * | ||
| * If asset staging is disabled, this will just be the original path. | ||
| * If asset staging is enabled it will be the staged path. | ||
| */ | ||
| public readonly stagedPath: string; | ||
|
|
||
| /** | ||
| * The path of the asset as it was referenced by the user. | ||
| */ | ||
| public readonly sourcePath: string; | ||
|
|
||
| /** | ||
| * A cryptographic hash of the source document(s). | ||
| */ | ||
| public readonly sourceHash: string; | ||
|
|
||
| private readonly fingerprintOptions: FingerprintOptions; | ||
|
|
||
| private readonly relativePath?: string; | ||
|
|
||
| constructor(scope: Construct, id: string, props: AssetStagingProps) { | ||
| super(scope, id); | ||
|
|
||
| this.sourcePath = props.sourcePath; | ||
| this.fingerprintOptions = props; | ||
| this.sourceHash = FileSystem.fingerprint(this.sourcePath, props); | ||
|
|
||
| const stagingDisabled = this.node.tryGetContext(cxapi.DISABLE_ASSET_STAGING_CONTEXT); | ||
| if (stagingDisabled) { | ||
| this.stagedPath = this.sourcePath; | ||
| } else { | ||
| this.relativePath = 'asset.' + this.sourceHash + path.extname(this.sourcePath); | ||
| this.stagedPath = this.relativePath; // always relative to outdir | ||
| } | ||
| } | ||
|
|
||
| protected synthesize(session: ISynthesisSession) { | ||
| if (!this.relativePath) { | ||
| return; | ||
| } | ||
|
|
||
| const targetPath = path.join(session.assembly.outdir, this.relativePath); | ||
|
|
||
| // asset already staged | ||
| if (fs.existsSync(targetPath)) { | ||
| return; | ||
| } | ||
|
|
||
| // copy file/directory to staging directory | ||
| const stat = fs.statSync(this.sourcePath); | ||
| if (stat.isFile()) { | ||
| fs.copyFileSync(this.sourcePath, targetPath); | ||
| } else if (stat.isDirectory()) { | ||
| fs.mkdirSync(targetPath); | ||
| FileSystem.copyDirectory(this.sourcePath, targetPath, this.fingerprintOptions); | ||
| } else { | ||
| throw new Error(`Unknown file type: ${this.sourcePath}`); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply type alias or extend
FollowMode,CopyOptionsandFingerprintOptionswith new ones added in core?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aliases are not respected by jsii