Skip to content

Commit

Permalink
fix(cli): templates don't include .gitignore (#19482)
Browse files Browse the repository at this point in the history
Fixes #19460
  • Loading branch information
iliapolo committed Mar 21, 2022
1 parent 33e3677 commit 5ce0983
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tools/@aws-cdk/node-bundle/src/api/bundle.ts
Expand Up @@ -224,9 +224,12 @@ export class Bundle {

const target = fs.mkdtempSync(path.join(os.tmpdir(), 'bundle-write-'));

// we definitely don't need these directories in the package
// so no need to copy them over.
const ignoreDirectories = ['node_modules', '.git'];

// copy the entire project since we are retaining the original files.
// except for `node_modules` and `.git` which definitely don't belong in the package.
fs.copySync(this.packageDir, target, { filter: n => !n.includes('node_modules') && !n.includes('.git') });
fs.copySync(this.packageDir, target, { filter: n => !n.split(path.sep).some((p => ignoreDirectories.includes(p))) });

// clone the original manifest since we are going to
// to mutate it.
Expand Down
28 changes: 28 additions & 0 deletions tools/@aws-cdk/node-bundle/test/api/bundle.test.ts
Expand Up @@ -127,3 +127,31 @@ test('validate and fix', () => {
expect(fs.existsSync(tarball)).toBeTruthy();

});

test('write ignores only .git and node_modules directories', () => {

const pkg = Package.create({ name: 'consumer', licenses: ['Apache-2.0'] });
pkg.addDependency({ name: 'dep1', licenses: ['MIT'] });
pkg.addDependency({ name: 'dep2', licenses: ['Apache-2.0'] });

pkg.write();
pkg.install();

const bundle = new Bundle({
packageDir: pkg.dir,
entryPoints: [pkg.entrypoint],
allowedLicenses: ['Apache-2.0', 'MIT'],
});

// add a gitignore file to the package - it should be included
fs.writeFileSync(path.join(pkg.dir, '.gitignore'), 'something');

// add a silly node_modules_file to the package - it should be included
fs.writeFileSync(path.join(pkg.dir, 'node_modules_file'), 'something');

const bundleDir = bundle.write();

expect(fs.existsSync(path.join(bundleDir, '.gitignore'))).toBeTruthy();
expect(fs.existsSync(path.join(bundleDir, 'node_modules_file'))).toBeTruthy();

});

0 comments on commit 5ce0983

Please sign in to comment.