diff --git a/src/check-project/index.js b/src/check-project/index.js index 94f31da29..03d1d2c7e 100755 --- a/src/check-project/index.js +++ b/src/check-project/index.js @@ -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) @@ -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' })) diff --git a/src/release.js b/src/release.js index 711efff41..edf08193e 100644 --- a/src/release.js +++ b/src/release.js @@ -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] } @@ -44,7 +44,7 @@ const tasks = new Listr([ }, { title: 'align sibling dependency versions', - enabled: () => isMonorepoProject, + enabled: () => isMonorepoProject(), /** * @param {GlobalOptions & ReleaseOptions} ctx */ diff --git a/src/utils.js b/src/utils.js index 2fc847e4d..263993409 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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