Repository: tmokmss/deploy-time-build (language: python)

Issue:
Ignore `.DS_Store` file by default
When deployed from a macOS machine, .DS_Store` files often accidentally "contaminate" the staged assets, changing the asset hash unexpectedly and disabling the cache mechanism. 

In most of use cases `.DS_Store` files should be unnecessary, and we may want to exclude the file by default.


Discussion / hints:

Fix patch:
diff --git a/API.md b/API.md
index e0eac4e..cb7e2c3 100644
--- a/API.md
+++ b/API.md
@@ -839,6 +839,7 @@ const nodejsBuildProps: NodejsBuildProps = { ... }
 | <code><a href="#deploy-time-build.NodejsBuildProps.property.buildEnvironment">buildEnvironment</a></code> | <code>{[ key: string ]: string}</code> | Environment variables injected to the build environment. |
 | <code><a href="#deploy-time-build.NodejsBuildProps.property.destinationKeyPrefix">destinationKeyPrefix</a></code> | <code>string</code> | Key prefix to deploy your build artifact. |
 | <code><a href="#deploy-time-build.NodejsBuildProps.property.distribution">distribution</a></code> | <code>aws-cdk-lib.aws_cloudfront.IDistribution</code> | The distribution you are using to publish you build artifact. |
+| <code><a href="#deploy-time-build.NodejsBuildProps.property.excludeCommonFiles">excludeCommonFiles</a></code> | <code>boolean</code> | If true, common unnecessary files/directories such as .DS_Store, .git, node_modules, etc are excluded from the assets by default. |
 | <code><a href="#deploy-time-build.NodejsBuildProps.property.nodejsVersion">nodejsVersion</a></code> | <code>number</code> | The version of Node.js to use in a build environment. Available versions: 12, 14, 16, 18, 20. |
 | <code><a href="#deploy-time-build.NodejsBuildProps.property.outputEnvFile">outputEnvFile</a></code> | <code>boolean</code> | If true, a .env file is uploaded to an S3 bucket with values of `buildEnvironment` property. You can copy it to your local machine by running the command in the stack output. |
 | <code><a href="#deploy-time-build.NodejsBuildProps.property.workingDirectory">workingDirectory</a></code> | <code>string</code> | Relative path from the build directory to the directory where build commands run. |
@@ -939,6 +940,19 @@ If any specified, the caches are invalidated on new artifact deployments.
 
 ---
 
+##### `excludeCommonFiles`<sup>Optional</sup> <a name="excludeCommonFiles" id="deploy-time-build.NodejsBuildProps.property.excludeCommonFiles"></a>
+
+```typescript
+public readonly excludeCommonFiles: boolean;
+```
+
+- *Type:* boolean
+- *Default:* true
+
+If true, common unnecessary files/directories such as .DS_Store, .git, node_modules, etc are excluded from the assets by default.
+
+---
+
 ##### `nodejsVersion`<sup>Optional</sup> <a name="nodejsVersion" id="deploy-time-build.NodejsBuildProps.property.nodejsVersion"></a>
 
 ```typescript
diff --git a/src/nodejs-build.ts b/src/nodejs-build.ts
index a3b889c..18c0a46 100644
--- a/src/nodejs-build.ts
+++ b/src/nodejs-build.ts
@@ -75,6 +75,12 @@ export interface NodejsBuildProps {
    * @default false
    */
   readonly outputEnvFile?: boolean;
+  /**
+   * If true, common unnecessary files/directories such as .DS_Store, .git, node_modules, etc are excluded
+   * from the assets by default.
+   * @default true
+   */
+  readonly excludeCommonFiles?: boolean;
 }
 
 /**
@@ -229,9 +235,11 @@ curl -v -i -X PUT -H 'Content-Type:' -d "@payload.json" "$responseURL"
 
     this.grantPrincipal = project.grantPrincipal;
 
+    const commonExclude = ['.DS_Store', '.git', 'node_modules'];
     const assets = props.assets.map((assetProps) => {
       const asset = new Asset(this, `Source-${assetProps.path.replace('/', '')}`, {
         ...assetProps,
+        ...(props.excludeCommonFiles ?? true ? { exclude: [...commonExclude, ...(assetProps.exclude ?? [])] } : {}),
       });
       asset.grantRead(project);
       return asset;


Test patch:
diff --git a/test/integ.nodejs-build.ts b/test/integ.nodejs-build.ts
index 172a8de..84cee8e 100644
--- a/test/integ.nodejs-build.ts
+++ b/test/integ.nodejs-build.ts
@@ -20,7 +20,7 @@ class TestStack extends Stack {
       assets: [
         {
           path: '../example/example-app',
-          exclude: ['dist', 'node_modules'],
+          exclude: ['dist'],
         },
       ],
       destinationBucket: dstBucket,