-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
feat(core): add include
property specifying particular files for assets
#33132
base: main
Are you sure you want to change the base?
Conversation
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.
(This review is outdated)
3719ec5
to
8eed19e
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #33132 +/- ##
==========================================
+ Coverage 82.20% 82.27% +0.06%
==========================================
Files 119 120 +1
Lines 6862 6889 +27
Branches 1158 1167 +9
==========================================
+ Hits 5641 5668 +27
Misses 1118 1118
Partials 103 103
Flags with carried forward coverage won't be shown. Click here to find out more.
|
This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. Note that PRs with failing linting check or builds are not reviewed, please ensure your build is passing To prevent automatic closure:
This PR will automatically close in 7 days if no action is taken. |
hi @go-to-k, what's the status on this PR? i don't want to rush you but the automation may eventually close your PR as abandoned... |
hi @kaizencc . Thanks for letting me know! |
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
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.
(This review is outdated)
include
property specifying particular files for assets
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
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.
(This review is outdated)
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
0be48d8
to
f07ceb2
Compare
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
const minimatch = require('minimatch'); | ||
|
||
export function matchIncludePatterns(patterns: string[], absoluteRootPath: string, absoluteFilePath: string): boolean { |
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.
Almost the same process as below.
https://github.com/go-to-k/aws-cdk/blob/9479e5ec9327870ec9791eb468c2ae5fdc76d9a5/packages/aws-cdk-lib/core/lib/fs/ignore.ts#L114-L137
* If matching the symlink but not its target, it is included (i.e. the `include` patterns match | ||
* the symlink path itself, regardless of its target). This is the same behavior even if `follow` | ||
* is not `SymlinkFollowMode.NEVER`. |
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.
To match the current exclude behavior
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
const destDirPath = path.dirname(destFilePath); | ||
if (!fs.existsSync(destDirPath)) { | ||
fs.mkdirSync(destDirPath, { recursive: true }); | ||
} |
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.
This directory creation code was added because:
- Previously, parent directories were already created by the
isDirectory()
processing before copying files/symlinks (*1). - With the
include
option to copy only specific files, directories that don't match the include patterns are not created (*2). Without this behavior, we would end up creating unnecessary directories along the traversal path when we finally reach files that aren't included. As a result, we need to explicitly create parent directories for included files/symlinks, particularly to handle cases where those parent directories aren't included.
*1
if (stat && stat.isDirectory()) {
fs.mkdirSync(destFilePath);
copyDirectory(sourceFilePath, destFilePath, options, rootDir);
stat = undefined;
}
*2
if (stat && stat.isDirectory()) {
if (included) {
fs.mkdirSync(destFilePath, { recursive: true });
}
copyDirectory(sourceFilePath, destFilePath, options, rootDir);
stat = undefined;
I've completed the necessary implementation, so I'm ready for review. |
Issue # (if applicable)
Closes #26107.
Reason for this change
Currently the option for Assets etc. has the
exclude
only for filtering files. Also I had submitted the PR that addsinclude
before, but closed it because theexclude
can cover situations for staging particular files by using negation patterns such as*
and!filenames
. (see: #26107 (comment)).But I encountered the situation that it is difficult to express our requirements with
exclude
only.The example of directories and files is the following (y: required, x: not required).
Now for the situation, we may use the following pattern with
exclude
only.However, there are some confusing points if the double negative is desired:
!
) and positive are mixed and difficult to understand.['*', 'subdir/examples/*', '!main.py', '!subdir', '!subdir/**/*']
In such cases, the
include
option makes it simple to achieve the following. (This is very easy to understand and you don't have to mind the order.)The
include
property is also present in other modules that filter particular files, such ascdk watch
, codepipeline Git triggers and BucketDeployment for S3, so it isn't unnatural.In particular, it should be good for developers to be able to match the filtering settings of
cdk watch
with hotswap and the settings of the asset files added in this PR.Description of changes
include
parameter to interface FileOptions as well asexclude
.include
in copyDirectory, where the actual file search is done.include
andexclude
,exclude
takes precedence.Describe any new or updated permissions being added
Description of how you validated changes
Both unit and integ tests.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license