Skip to content

Commit

Permalink
clarify monorepo fixture workspaces setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ecraig12345 committed May 4, 2023
1 parent 2f46f67 commit 830b3b2
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/__fixtures__/repositoryFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ function getSinglePackageFixture(): RepoFixture {
};
}

/** Get a basic fixture for a monorepo root package.json (workspaces will be automatically added later) */
function getMonorepoRootPackage(name = 'monorepo-fixture'): RootPackageJsonFixture {
return { name, version: '1.0.0', private: true };
}

/**
* Get a monorepo fixture
* @param parentFolder If provided, this folder name is also used as the scope in package names
Expand All @@ -84,7 +79,9 @@ function getMonorepoFixture(parentFolder?: string): RepoFixture {
return {
tempDescription: parentFolder ? 'multimonorepo' : 'monorepo',
rootPackage: {
...getMonorepoRootPackage(`${scope}monorepo-fixture`),
name: `${scope}monorepo-fixture`,
version: '1.0.0',
private: true,
beachball: beachballOptions as BeachballOptions,
// workspaces will be added automatically later
},
Expand Down Expand Up @@ -114,11 +111,11 @@ function getMonorepoFixture(parentFolder?: string): RepoFixture {
* The two workspaces are under subfolders `workspace-a` and `workspace-b`, and the packages in each
* workspace use scoped names `@workspace-a/*` and `@workspace-b/*`.
*/
function getMultiWorkspaceFixture(): { 'workspace-a': RepoFixture; 'workspace-b': RepoFixture } {
function getMultiWorkspaceFixture() {
return {
'workspace-a': getMonorepoFixture('workspace-a'),
'workspace-b': getMonorepoFixture('workspace-b'),
};
} as const;
}

/** Provides setup, cloning, and teardown for repository factories */
Expand Down Expand Up @@ -190,11 +187,16 @@ export class RepositoryFactory {
fs.ensureDirSync(tmpRepo.pathTo(parentFolder));

// create the root package.json
const finalRootPackage: RootPackageJsonFixture = {
...(rootPackage || getMonorepoRootPackage()),
let finalRootPackage = rootPackage;
if (!finalRootPackage) {
// if we got here, `folders` must be defined, so this is a monorepo
finalRootPackage = { name: 'monorepo-fixture', version: '1.0.0', private: true };
}
// add workspaces if needed
if (folders && !finalRootPackage.workspaces) {
// these paths are relative to THIS workspace and should not include the parent folder
...(folders && { workspaces: Object.keys(folders).map(folder => `${folder}/*`) }),
};
finalRootPackage.workspaces = Object.keys(folders).map(folder => `${folder}/*`);
}
fs.writeJSONSync(tmpRepo.pathTo(parentFolder, 'package.json'), finalRootPackage, jsonOptions);

// create the lock file
Expand Down

0 comments on commit 830b3b2

Please sign in to comment.