Skip to content

feat(semver): add all-libs project option #530

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

Open
wants to merge 2 commits into
base: main
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
40 changes: 40 additions & 0 deletions packages/semver/src/generators/install/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ describe('Install generator', () => {
addProjectConfiguration(tree, 'lib1', {
root: 'libs/lib1',
sourceRoot: 'libs/lib1/src',
projectType: 'library',
targets: {},
});

Expand All @@ -108,6 +109,7 @@ describe('Install generator', () => {
addProjectConfiguration(tree, 'lib2', {
root: 'libs/lib2',
sourceRoot: 'libs/lib1/src',
projectType: 'library',
targets: {},
});

Expand All @@ -117,6 +119,19 @@ describe('Install generator', () => {
references: [],
});

addProjectConfiguration(tree, 'app1', {
root: 'apps/app1',
sourceRoot: 'apps/app1/src',
projectType: 'application',
targets: {},
});

writeJson(tree, 'apps/app1/tsconfig.json', {
files: [],
include: [],
references: [],
});

jest
.spyOn(inquirer, 'prompt')
.mockResolvedValue({ projects: ['lib1'] });
Expand Down Expand Up @@ -170,6 +185,31 @@ describe('Install generator', () => {
);
});

it('should use --projects=all-libs option', async () => {
await install(tree, { ...options, projects: ['all-libs'] });

const lib1 = readJson(tree, 'libs/lib1/project.json');
const lib2 = readJson(tree, 'libs/lib2/project.json');
const app1 = readJson(tree, 'apps/app1/project.json');

expect(inquirer.prompt).not.toBeCalled();
expect(lib1.targets).toEqual(
expect.objectContaining({
version: {
executor: '@jscutlery/semver:version',
},
})
);
expect(lib2.targets).toEqual(
expect.objectContaining({
version: {
executor: '@jscutlery/semver:version',
},
})
);
expect(app1.targets.version).toBeUndefined();
});

it('should forward --baseBranch option to all projects', async () => {
jest
.spyOn(inquirer, 'prompt')
Expand Down
23 changes: 13 additions & 10 deletions packages/semver/src/generators/install/utils/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ export function listProjects(tree: Tree): ProjectDefinition[] {
export function updateProjects(
tree: Tree,
options: SchemaOptions,
predicate: (projectName: string) => boolean
predicate: (projectName: string) => boolean,
predicateAllLibs: () => boolean,
) {
getProjects(tree).forEach((project, projectName) => {
if (predicate(projectName)) {
const targets = project.targets ?? {};
const targets = project.targets
if (predicate(projectName) && targets !== undefined) {
targets.version = createTarget(options);
}
if (predicateAllLibs() && project.projectType === 'library' && targets !== undefined){
targets.version = createTarget(options);

updateProjectConfiguration(tree, projectName, project);
}
updateProjectConfiguration(tree, projectName, project);
});
}

Expand All @@ -44,17 +47,17 @@ export async function updateWorkspaceFromPrompt(
const answers = await createPrompt(projects);

return updateProjects(tree, options, (projectName) =>
answers.projects.includes(projectName)
answers.projects.includes(projectName),
() => options.projects !== undefined && options.projects.includes('all-libs') as boolean,
);
}

export function updateWorkspaceFromSchema(
tree: Tree,
options: SchemaOptions
): void {
return updateProjects(
tree,
options,
(projectName) => options.projects?.includes(projectName) as boolean
return updateProjects(tree, options, (projectName) =>
options.projects?.includes(projectName) as boolean,
() => options.projects !== undefined && options.projects.includes('all-libs') as boolean,
);
}