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

Respect ignorePatterns in getPackageInfos #773

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions change/beachball-d9a5a809-bde2-42fe-8358-3d9843e604ec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Respect ignorePatterns in getPackageInfos",
"packageName": "beachball",
"email": "[email protected]",
"dependentChangeType": "patch"
}
26 changes: 13 additions & 13 deletions src/__e2e__/bump.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('version bumping', () => {

await bump({ path: repo.rootPath, bumpDeps: false } as BeachballOptions);

const packageInfos = getPackageInfos(repo.rootPath);
const packageInfos = getPackageInfos({ path: repo.rootPath });

const pkg1NewVersion = '1.1.0';
expect(packageInfos['pkg-1'].version).toBe(pkg1NewVersion);
Expand Down Expand Up @@ -69,8 +69,8 @@ describe('version bumping', () => {

await bump({ path: workspaceARoot, bumpDeps: true } as BeachballOptions);

const packageInfosA = getPackageInfos(workspaceARoot);
const packageInfosB = getPackageInfos(workspaceBRoot);
const packageInfosA = getPackageInfos({ path: workspaceARoot });
const packageInfosB = getPackageInfos({ path: workspaceBRoot });
expect(packageInfosA['@workspace-a/foo'].version).toBe('1.1.0');
expect(packageInfosB['@workspace-b/foo'].version).toBe('1.0.0');

Expand Down Expand Up @@ -105,7 +105,7 @@ describe('version bumping', () => {
fromRef: oldCommit,
} as BeachballOptions);

const packageInfos = getPackageInfos(repo.rootPath);
const packageInfos = getPackageInfos({ path: repo.rootPath });

expect(packageInfos['pkg-1'].version).toBe(monorepo['packages']['pkg-1'].version);
expect(packageInfos['pkg-2'].version).toBe(monorepo['packages']['pkg-2'].version);
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('version bumping', () => {

await bump({ path: repo.rootPath, bumpDeps: true } as BeachballOptions);

const packageInfos = getPackageInfos(repo.rootPath);
const packageInfos = getPackageInfos({ path: repo.rootPath });

const pkg1NewVersion = '1.1.0';
const dependentNewVersion = '1.0.1';
Expand Down Expand Up @@ -173,7 +173,7 @@ describe('version bumping', () => {
groups: [{ include: 'packages/*', name: 'testgroup' }],
} as BeachballOptions);

const packageInfos = getPackageInfos(repo.rootPath);
const packageInfos = getPackageInfos({ path: repo.rootPath });

const newVersion = '1.1.0';
expect(packageInfos['pkg-1'].version).toBe(newVersion);
Expand Down Expand Up @@ -212,7 +212,7 @@ describe('version bumping', () => {
bumpDeps: true,
} as BeachballOptions);

const packageInfos = getPackageInfos(repo.rootPath);
const packageInfos = getPackageInfos({ path: repo.rootPath });

const groupNewVersion = '1.1.0';
expect(packageInfos['pkg-1'].version).toBe(groupNewVersion);
Expand Down Expand Up @@ -241,7 +241,7 @@ describe('version bumping', () => {
scope: ['!packages/foo'],
} as BeachballOptions);

const packageInfos = getPackageInfos(repo.rootPath);
const packageInfos = getPackageInfos({ path: repo.rootPath });
expect(packageInfos['foo'].version).toBe(monorepo['packages']['foo'].version);
expect(packageInfos['bar'].version).toBe(monorepo['packages']['bar'].version);

Expand All @@ -264,7 +264,7 @@ describe('version bumping', () => {
scope: ['!packages/foo'],
} as BeachballOptions);

const packageInfos = getPackageInfos(repo.rootPath);
const packageInfos = getPackageInfos({ path: repo.rootPath });
expect(packageInfos['foo'].version).toBe(monorepo['packages']['foo'].version);
expect(packageInfos['bar'].version).toBe('1.3.5');
expect(packageInfos['foo'].dependencies!['bar']).toBe(monorepo['packages']['foo'].dependencies!['bar']);
Expand Down Expand Up @@ -295,7 +295,7 @@ describe('version bumping', () => {
keepChangeFiles: true,
} as BeachballOptions);

const packageInfos = getPackageInfos(repo.rootPath);
const packageInfos = getPackageInfos({ path: repo.rootPath });

const pkg1NewVersion = '1.1.0';
expect(packageInfos['pkg-1'].version).toBe(pkg1NewVersion);
Expand Down Expand Up @@ -333,7 +333,7 @@ describe('version bumping', () => {
prereleasePrefix: 'beta',
} as BeachballOptions);

const packageInfos = getPackageInfos(repo.rootPath);
const packageInfos = getPackageInfos({ path: repo.rootPath });

const newVersion = '1.0.1-beta.0';
expect(packageInfos['pkg-1'].version).toBe(newVersion);
Expand Down Expand Up @@ -374,7 +374,7 @@ describe('version bumping', () => {
prereleasePrefix: 'beta',
} as BeachballOptions);

const packageInfos = getPackageInfos(repo.rootPath);
const packageInfos = getPackageInfos({ path: repo.rootPath });

const newVersion = '1.0.1-beta.0';
expect(packageInfos['pkg-1'].version).toBe(newVersion);
Expand Down Expand Up @@ -415,7 +415,7 @@ describe('version bumping', () => {
prereleasePrefix: 'beta',
} as BeachballOptions);

const packageInfos = getPackageInfos(repo.rootPath);
const packageInfos = getPackageInfos({ path: repo.rootPath });

const pkg1NewVersion = '1.0.1-beta.1';
const othersNewVersion = '1.0.1-beta.0';
Expand Down
12 changes: 6 additions & 6 deletions src/__e2e__/getChangedPackages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('getChangedPackages', () => {
repositoryFactory = new RepositoryFactory('single');
const repo = repositoryFactory.cloneRepository();
const options = { fetch: false, path: repo.rootPath, branch: defaultBranchName } as BeachballOptions;
const packageInfos = getPackageInfos(repo.rootPath);
const packageInfos = getPackageInfos(options);

expect(getChangedPackages(options, packageInfos)).toStrictEqual([]);

Expand All @@ -36,7 +36,7 @@ describe('getChangedPackages', () => {
branch: defaultBranchName,
ignorePatterns: ['*.test.js', 'tests/**', 'yarn.lock'],
} as BeachballOptions;
const packageInfos = getPackageInfos(repo.rootPath);
const packageInfos = getPackageInfos(options);

repo.stageChange('src/foo.test.js');
repo.stageChange('tests/stuff.js');
Expand All @@ -49,7 +49,7 @@ describe('getChangedPackages', () => {
repositoryFactory = new RepositoryFactory('monorepo');
const repo = repositoryFactory.cloneRepository();
const options = { fetch: false, path: repo.rootPath, branch: defaultBranchName } as BeachballOptions;
const packageInfos = getPackageInfos(repo.rootPath);
const packageInfos = getPackageInfos(options);

expect(getChangedPackages(options, packageInfos)).toStrictEqual([]);

Expand All @@ -65,19 +65,19 @@ describe('getChangedPackages', () => {

const workspaceARoot = repo.pathTo('workspace-a');
const workspaceBRoot = repo.pathTo('workspace-b');
const rootPackageInfos = getPackageInfos(repo.rootPath);
const rootPackageInfos = getPackageInfos(rootOptions);

expect(getChangedPackages(rootOptions, rootPackageInfos)).toStrictEqual([]);

repo.stageChange('workspace-a/packages/foo/test.js');

const changedPackagesA = getChangedPackages(
{ ...rootOptions, path: workspaceARoot },
getPackageInfos(workspaceARoot)
getPackageInfos({ path: workspaceARoot })
);
const changedPackagesB = getChangedPackages(
{ ...rootOptions, path: workspaceBRoot },
getPackageInfos(workspaceBRoot)
getPackageInfos({ path: workspaceBRoot })
);
const changedPackagesRoot = getChangedPackages(rootOptions, rootPackageInfos);

Expand Down
2 changes: 1 addition & 1 deletion src/__e2e__/publishGit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('publish command (git)', () => {

const options: BeachballOptions = getOptions(repo1);

const bumpInfo = gatherBumpInfo(options, getPackageInfos(repo1.rootPath));
const bumpInfo = gatherBumpInfo(options, getPackageInfos(options));

// 3. Meanwhile, in repo2, also create a new change file
const repo2 = repositoryFactory.cloneRepository();
Expand Down
12 changes: 6 additions & 6 deletions src/__e2e__/syncE2E.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('sync command (e2e)', () => {
});
const repo = repositoryFactory.cloneRepository();

const packageInfosBeforeSync = getPackageInfos(repo.rootPath);
const packageInfosBeforeSync = getPackageInfos({ path: repo.rootPath });

expect((await packagePublish(packageInfosBeforeSync['foopkg'], registry.getUrl(), '', '')).success).toBeTruthy();
expect((await packagePublish(packageInfosBeforeSync['barpkg'], registry.getUrl(), '', '')).success).toBeTruthy();
Expand All @@ -104,7 +104,7 @@ describe('sync command (e2e)', () => {

await sync(getOptions(repo, { tag: '' }));

const packageInfosAfterSync = getPackageInfos(repo.rootPath);
const packageInfosAfterSync = getPackageInfos({ path: repo.rootPath });

expect(packageInfosAfterSync['foopkg'].version).toEqual('1.2.0');
expect(packageInfosAfterSync['barpkg'].version).toEqual('3.0.0');
Expand All @@ -123,7 +123,7 @@ describe('sync command (e2e)', () => {
});
const repo = repositoryFactory.cloneRepository();

const packageInfosBeforeSync = getPackageInfos(repo.rootPath);
const packageInfosBeforeSync = getPackageInfos({ path: repo.rootPath });

expect((await packagePublish(packageInfosBeforeSync['apkg'], registry.getUrl(), '', '')).success).toBeTruthy();
expect((await packagePublish(packageInfosBeforeSync['bpkg'], registry.getUrl(), '', '')).success).toBeTruthy();
Expand All @@ -136,7 +136,7 @@ describe('sync command (e2e)', () => {

await sync(getOptions(repo, { tag: 'beta' }));

const packageInfosAfterSync = getPackageInfos(repo.rootPath);
const packageInfosAfterSync = getPackageInfos({ path: repo.rootPath });

expect(packageInfosAfterSync['apkg'].version).toEqual('2.0.0');
expect(packageInfosAfterSync['bpkg'].version).toEqual('2.2.0');
Expand All @@ -155,7 +155,7 @@ describe('sync command (e2e)', () => {
});
const repo = repositoryFactory.cloneRepository();

const packageInfosBeforeSync = getPackageInfos(repo.rootPath);
const packageInfosBeforeSync = getPackageInfos({ path: repo.rootPath });

const epkg = packageInfosBeforeSync['epkg'];
const fpkg = packageInfosBeforeSync['fpkg'];
Expand All @@ -177,7 +177,7 @@ describe('sync command (e2e)', () => {

await sync(getOptions(repo, { tag: 'prerelease', forceVersions: true }));

const packageInfosAfterSync = getPackageInfos(repo.rootPath);
const packageInfosAfterSync = getPackageInfos({ path: repo.rootPath });

expect(packageInfosAfterSync['epkg'].version).toEqual('1.0.0-1');
expect(packageInfosAfterSync['fpkg'].version).toEqual('2.2.0');
Expand Down
11 changes: 9 additions & 2 deletions src/__fixtures__/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,25 @@ ${gitResult.stderr.toString()}`);
}

/**
* Create (or update) and stage a file, creating the intermediate directories if necessary.
* Create or update a file, creating the intermediate directories if necessary.
* Automatically uses root path; do not pass absolute paths here.
*/
stageChange(newFilename: string, content?: string) {
writeChange(newFilename: string, content?: string) {
const filePath = this.pathTo(newFilename);
fs.ensureDirSync(path.dirname(filePath));
fs.ensureFileSync(filePath);

if (content) {
fs.writeFileSync(filePath, content);
}
}

/**
* Create (or update) and stage a file, creating the intermediate directories if necessary.
* Automatically uses root path; do not pass absolute paths here.
*/
stageChange(newFilename: string, content?: string) {
this.writeChange(newFilename, content);
this.git(['add', newFilename]);
}

Expand Down
29 changes: 10 additions & 19 deletions src/__functional__/changefile/readChangeFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ describe('readChangeFiles', () => {
repository.commitChange('foo');
generateChangeFiles(['foo'], repository.rootPath);

const packageInfos = getPackageInfos(repository.rootPath);
const changeSet = readChangeFiles({ path: repository.rootPath } as BeachballOptions, packageInfos);
const options = { path: repository.rootPath } as BeachballOptions;
const changeSet = readChangeFiles(options, getPackageInfos(options));
expect(changeSet).toHaveLength(1);
expect(changeSet[0].change.commit).toBe(undefined);
});
Expand All @@ -44,8 +44,8 @@ describe('readChangeFiles', () => {
// fake doesn't exist, bar is private, foo is okay
generateChangeFiles(['fake', 'bar', 'foo'], monoRepo.rootPath);

const packageInfos = getPackageInfos(monoRepo.rootPath);
const changeSet = readChangeFiles({ path: monoRepo.rootPath } as BeachballOptions, packageInfos);
const options = { path: monoRepo.rootPath } as BeachballOptions;
const changeSet = readChangeFiles(options, getPackageInfos(options));
expect(changeSet).toHaveLength(1);

expect(logs.mocks.warn).toHaveBeenCalledWith(expect.stringContaining('Change detected for private package bar'));
Expand All @@ -60,11 +60,8 @@ describe('readChangeFiles', () => {
// fake doesn't exist, bar is private, foo is okay
generateChangeFiles(['fake', 'bar', 'foo'], monoRepo.rootPath, true /*groupChanges*/);

const packageInfos = getPackageInfos(monoRepo.rootPath);
const changeSet = readChangeFiles(
{ path: monoRepo.rootPath, groupChanges: true } as BeachballOptions,
packageInfos
);
const options = { path: monoRepo.rootPath, groupChanges: true } as BeachballOptions;
const changeSet = readChangeFiles(options, getPackageInfos(options));
expect(changeSet).toHaveLength(1);

expect(logs.mocks.warn).toHaveBeenCalledWith(expect.stringContaining('Change detected for private package bar'));
Expand All @@ -77,11 +74,8 @@ describe('readChangeFiles', () => {
const monoRepo = monoRepoFactory.cloneRepository();
generateChangeFiles(['bar', 'foo'], monoRepo.rootPath);

const packageInfos = getPackageInfos(monoRepo.rootPath);
const changeSet = readChangeFiles(
{ path: monoRepo.rootPath, scope: ['packages/foo'] } as BeachballOptions,
packageInfos
);
const options = { path: monoRepo.rootPath, scope: ['packages/foo'] } as BeachballOptions;
const changeSet = readChangeFiles(options, getPackageInfos(options));
expect(changeSet).toHaveLength(1);
expect(logs.mocks.warn).not.toHaveBeenCalled();
});
Expand All @@ -90,11 +84,8 @@ describe('readChangeFiles', () => {
const monoRepo = monoRepoFactory.cloneRepository();
generateChangeFiles(['bar', 'foo'], monoRepo.rootPath, true /*groupChanges*/);

const packageInfos = getPackageInfos(monoRepo.rootPath);
const changeSet = readChangeFiles(
{ path: monoRepo.rootPath, scope: ['packages/foo'], groupChanges: true } as BeachballOptions,
packageInfos
);
const options = { path: monoRepo.rootPath, scope: ['packages/foo'], groupChanges: true } as BeachballOptions;
const changeSet = readChangeFiles(options, getPackageInfos(options));
expect(changeSet).toHaveLength(1);
expect(logs.mocks.warn).not.toHaveBeenCalled();
});
Expand Down
14 changes: 7 additions & 7 deletions src/__functional__/changelog/writeChangelog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('writeChangelog', () => {
generateChangeFiles([getChange('foo', 'comment 2')], repository.rootPath);

const beachballOptions = { path: repository.rootPath } as BeachballOptions;
const packageInfos = getPackageInfos(repository.rootPath);
const packageInfos = getPackageInfos(beachballOptions);
const changes = readChangeFiles(beachballOptions, packageInfos);

await writeChangelog(beachballOptions, changes, { foo: 'patch' }, { foo: new Set(['foo']) }, packageInfos);
Expand Down Expand Up @@ -83,7 +83,7 @@ describe('writeChangelog', () => {
generateChangeFiles([getChange('foo', 'comment 2')], ...params);

const beachballOptions = { path: monoRepo.rootPath, groupChanges: true } as BeachballOptions;
const packageInfos = getPackageInfos(monoRepo.rootPath);
const packageInfos = getPackageInfos(beachballOptions);
const changes = readChangeFiles(beachballOptions, packageInfos);

await writeChangelog(beachballOptions, changes, { foo: 'patch', bar: 'patch' }, {}, packageInfos);
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('writeChangelog', () => {
},
};

const packageInfos = getPackageInfos(monoRepo.rootPath);
const packageInfos = getPackageInfos(beachballOptions as { path: string });
const changes = readChangeFiles(beachballOptions as BeachballOptions, packageInfos);

await writeChangelog(beachballOptions as BeachballOptions, changes, {}, {}, packageInfos);
Expand Down Expand Up @@ -158,7 +158,7 @@ describe('writeChangelog', () => {
},
};

const packageInfos = getPackageInfos(monoRepo.rootPath);
const packageInfos = getPackageInfos(beachballOptions as { path: string });
const changes = readChangeFiles(beachballOptions as BeachballOptions, packageInfos);

await writeChangelog(
Expand Down Expand Up @@ -203,7 +203,7 @@ describe('writeChangelog', () => {
},
};

const packageInfos = getPackageInfos(monoRepo.rootPath);
const packageInfos = getPackageInfos(beachballOptions as { path: string });
const changes = readChangeFiles(beachballOptions as BeachballOptions, packageInfos);

await writeChangelog(
Expand Down Expand Up @@ -243,7 +243,7 @@ describe('writeChangelog', () => {
},
};

const packageInfos = getPackageInfos(monoRepo.rootPath);
const packageInfos = getPackageInfos(beachballOptions as { path: string });
const changes = readChangeFiles(beachballOptions as BeachballOptions, packageInfos);

await writeChangelog(beachballOptions as BeachballOptions, changes, {}, {}, packageInfos);
Expand Down Expand Up @@ -286,7 +286,7 @@ describe('writeChangelog', () => {
},
};

const packageInfos = getPackageInfos(monoRepo.rootPath);
const packageInfos = getPackageInfos(beachballOptions as { path: string });
const changes = readChangeFiles(beachballOptions as BeachballOptions, packageInfos);

// Verify that the comment of only the intended change file is changed
Expand Down
Loading