File tree 2 files changed +33
-2
lines changed
tools/@aws-cdk/node-bundle 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -224,9 +224,12 @@ export class Bundle {
224
224
225
225
const target = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'bundle-write-' ) ) ;
226
226
227
+ // we definitely don't need these directories in the package
228
+ // so no need to copy them over.
229
+ const ignoreDirectories = [ 'node_modules' , '.git' ] ;
230
+
227
231
// copy the entire project since we are retaining the original files.
228
- // except for `node_modules` and `.git` which definitely don't belong in the package.
229
- fs . copySync ( this . packageDir , target , { filter : n => ! n . includes ( 'node_modules' ) && ! n . includes ( '.git' ) } ) ;
232
+ fs . copySync ( this . packageDir , target , { filter : n => ! n . split ( path . sep ) . some ( ( p => ignoreDirectories . includes ( p ) ) ) } ) ;
230
233
231
234
// clone the original manifest since we are going to
232
235
// to mutate it.
Original file line number Diff line number Diff line change @@ -127,3 +127,31 @@ test('validate and fix', () => {
127
127
expect ( fs . existsSync ( tarball ) ) . toBeTruthy ( ) ;
128
128
129
129
} ) ;
130
+
131
+ test ( 'write ignores only .git and node_modules directories' , ( ) => {
132
+
133
+ const pkg = Package . create ( { name : 'consumer' , licenses : [ 'Apache-2.0' ] } ) ;
134
+ pkg . addDependency ( { name : 'dep1' , licenses : [ 'MIT' ] } ) ;
135
+ pkg . addDependency ( { name : 'dep2' , licenses : [ 'Apache-2.0' ] } ) ;
136
+
137
+ pkg . write ( ) ;
138
+ pkg . install ( ) ;
139
+
140
+ const bundle = new Bundle ( {
141
+ packageDir : pkg . dir ,
142
+ entryPoints : [ pkg . entrypoint ] ,
143
+ allowedLicenses : [ 'Apache-2.0' , 'MIT' ] ,
144
+ } ) ;
145
+
146
+ // add a gitignore file to the package - it should be included
147
+ fs . writeFileSync ( path . join ( pkg . dir , '.gitignore' ) , 'something' ) ;
148
+
149
+ // add a silly node_modules_file to the package - it should be included
150
+ fs . writeFileSync ( path . join ( pkg . dir , 'node_modules_file' ) , 'something' ) ;
151
+
152
+ const bundleDir = bundle . write ( ) ;
153
+
154
+ expect ( fs . existsSync ( path . join ( bundleDir , '.gitignore' ) ) ) . toBeTruthy ( ) ;
155
+ expect ( fs . existsSync ( path . join ( bundleDir , 'node_modules_file' ) ) ) . toBeTruthy ( ) ;
156
+
157
+ } ) ;
You can’t perform that action at this time.
0 commit comments