Skip to content
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

fix(cli): templates don't include .gitignore #19482

Merged
merged 3 commits into from Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();

});