Skip to content

Commit

Permalink
fix: do not create .gitignore files for monorepo workspace projects
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Feb 16, 2023
1 parent 1cefa04 commit 2dad5f2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
12 changes: 4 additions & 8 deletions src/check-project/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,9 @@ async function processMonorepo (projectDir, manifest, branchName, repoUrl) {
proposedManifest = sortManifest(proposedManifest)

await ensureFileHasContents(projectDir, 'package.json', JSON.stringify(proposedManifest, null, 2))

if (!isMonorepoProject) {
await ensureFileHasContents(projectDir, '.gitignore', fs.readFileSync(path.join(__dirname, 'files', 'gitignore'), {
encoding: 'utf-8'
}))
}

await ensureFileHasContents(projectDir, '.gitignore', fs.readFileSync(path.join(__dirname, 'files', 'gitignore'), {
encoding: 'utf-8'
}))
await checkLicenseFiles(projectDir)
await checkBuildFiles(projectDir, branchName, repoUrl)
await checkMonorepoReadme(projectDir, repoUrl, branchName, projectDirs)
Expand Down Expand Up @@ -396,7 +392,7 @@ async function processModule (projectDir, manifest, branchName, repoUrl, homePag

await ensureFileHasContents(projectDir, 'package.json', JSON.stringify(proposedManifest, null, 2))

if (!isMonorepoProject) {
if (!isMonorepoProject(projectDir)) {
await ensureFileHasContents(projectDir, '.gitignore', fs.readFileSync(path.join(__dirname, 'files', 'gitignore'), {
encoding: 'utf-8'
}))
Expand Down
6 changes: 3 additions & 3 deletions src/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ const tasks = new Listr([
}
},
{
title: `semantic-release${isMonorepoProject ? '-monorepo' : ''}`,
title: `semantic-release${isMonorepoProject() ? '-monorepo' : ''}`,
/**
* @param {GlobalOptions} ctx
*/
task: async (ctx) => {
let args = ctx['--'] ?? []

if (isMonorepoProject) {
if (isMonorepoProject()) {
args = ['-e', 'semantic-release-monorepo', ...args]
}

Expand All @@ -44,7 +44,7 @@ const tasks = new Listr([
},
{
title: 'align sibling dependency versions',
enabled: () => isMonorepoProject,
enabled: () => isMonorepoProject(),
/**
* @param {GlobalOptions & ReleaseOptions} ctx
*/
Expand Down
6 changes: 4 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,11 @@ export const isTypedCJS = isCJS && hasMain && hasTypes
// 3. CJS, no types
export const isUntypedCJS = isCJS && hasMain

const parentManifestPath = path.resolve(path.join(process.cwd(), '..', '..', 'package.json'))
export const isMonorepoProject = (dir = process.cwd()) => {
const parentManifestPath = path.resolve(dir, '..', '..', 'package.json')

export const isMonorepoProject = Boolean(fs.existsSync(parentManifestPath) && fs.readJSONSync(parentManifestPath).workspaces)
return Boolean(fs.existsSync(parentManifestPath) && fs.readJSONSync(parentManifestPath).workspaces)
}

/**
* Binaries we need are normally in `node_modules/.bin` of the root project
Expand Down

0 comments on commit 2dad5f2

Please sign in to comment.