From 37946286aeb49d76559b58a92067258e5246737a Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 12 Jan 2024 14:19:35 +0100 Subject: [PATCH] fix: update check-config command to handle release-please monorepos (#1448) Release-please updates sibling deps to the latest patch release so don't clobber those changes when running `npx aegir check-project`. --- src/check-project/check-licence-files.js | 9 +++++++-- src/check-project/check-monorepo-readme.js | 2 +- src/check-project/check-readme.js | 9 +++++++-- src/check-project/check-typedoc-files.js | 18 ++++++++++++++---- src/check-project/index.js | 13 ++++++++++--- src/check-project/manifests/typescript.js | 2 +- src/check-project/utils.js | 13 ++++++++++++- src/utils.js | 20 ++++++++++++++++++-- 8 files changed, 70 insertions(+), 16 deletions(-) diff --git a/src/check-project/check-licence-files.js b/src/check-project/check-licence-files.js index 557f5dac8..aa9ae7924 100644 --- a/src/check-project/check-licence-files.js +++ b/src/check-project/check-licence-files.js @@ -11,10 +11,15 @@ import { * @param {string} projectDir */ export async function checkLicenseFiles (projectDir) { - console.info('Check license files') - const pkg = fs.readJSONSync(path.join(projectDir, 'package.json')) + if (pkg.private === true) { + console.info('Private module found, skipping licence file check') + return + } + + console.info('Check license files') + if (pkg.license !== 'Apache-2.0 OR MIT') { throw new Error(`Incorrect license field - found '${pkg.license}', expected 'Apache-2.0 OR MIT'`) } diff --git a/src/check-project/check-monorepo-readme.js b/src/check-project/check-monorepo-readme.js index 090acbaf7..66f09db19 100644 --- a/src/check-project/check-monorepo-readme.js +++ b/src/check-project/check-monorepo-readme.js @@ -28,7 +28,7 @@ export async function checkMonorepoReadme (projectDir, repoUrl, defaultBranch, p throw new Error(`Could not parse repo owner & name from ${repoUrl}`) } - console.info('Check README files') + console.info('Check monorepo README files') const pkg = fs.readJSONSync(path.join(projectDir, 'package.json')) diff --git a/src/check-project/check-readme.js b/src/check-project/check-readme.js index d466df2ae..aa159ae0f 100644 --- a/src/check-project/check-readme.js +++ b/src/check-project/check-readme.js @@ -27,10 +27,15 @@ export async function checkReadme (projectDir, repoUrl, defaultBranch, ciFile, r throw new Error(`Could not parse repo owner & name from ${repoUrl}`) } - console.info('Check README files') - const pkg = fs.readJSONSync(path.join(projectDir, 'package.json')) + if (pkg.private) { + console.info('Private module found, skipping README file check') + return + } + + console.info('Check README files') + const readmePath = path.join(projectDir, 'README.md') let readmeContents = '' diff --git a/src/check-project/check-typedoc-files.js b/src/check-project/check-typedoc-files.js index cc696d9d4..70de6047c 100644 --- a/src/check-project/check-typedoc-files.js +++ b/src/check-project/check-typedoc-files.js @@ -2,6 +2,9 @@ import path from 'path' import fs from 'fs-extra' +import { + pkg +} from '../utils.js' import { ensureFileHasContents } from './utils.js' @@ -11,15 +14,22 @@ import { * @param {boolean} isTypescriptProject */ export async function checkTypedocFiles (projectDir, isTypescriptProject) { - console.info('Check typedoc files') + const manifest = fs.readJSONSync(path.join(projectDir, 'package.json')) - const pkg = fs.readJSONSync(path.join(projectDir, 'package.json')) + if (manifest.scripts.docs == null && pkg.scripts.docs == null) { + console.info('No "docs" npm script found, skipping typedoc.json check') + return + } + + if (manifest.exports == null) { + console.info('No exports map found, skipping typedoc.json check') - if (pkg.exports == null) { return } - const entryPoints = Object.values(pkg.exports) + console.info('Check typedoc files') + + const entryPoints = Object.values(manifest.exports) .map(e => { const path = e.import diff --git a/src/check-project/index.js b/src/check-project/index.js index b5f46dadc..cf7721c09 100755 --- a/src/check-project/index.js +++ b/src/check-project/index.js @@ -10,7 +10,8 @@ import semver from 'semver' import yargsParser from 'yargs-parser' import { isMonorepoProject, - glob + glob, + usesReleasePlease } from '../utils.js' import { checkBuildFiles } from './check-build-files.js' import { checkLicenseFiles } from './check-licence-files.js' @@ -227,9 +228,14 @@ function chooseVersions (deps, list) { * @param {Record} siblingVersions */ function selectVersions (deps, list, siblingVersions) { + // release-please updates sibling versions to the latest patch releases but + // we try to update to the latest minor so skip that if release please is + // in use + const ignoreSiblingDeps = usesReleasePlease() + Object.entries(list).forEach(([key, value]) => { if (deps[key] != null) { - if (siblingVersions[key] != null) { + if (siblingVersions[key] != null && !ignoreSiblingDeps) { // take sibling version if available deps[key] = siblingVersions[key] } else { @@ -438,13 +444,14 @@ export default new Listr([ const { branchName, repoUrl } = await getConfig(projectDir) const manifest = fs.readJSONSync(path.join(projectDir, 'package.json')) const monorepo = manifest.workspaces != null + const defaultCiFile = fs.existsSync(path.resolve(process.cwd(), '.github', 'workflows', 'main.yml')) ? 'main.yml' : 'js-test-and-release.yml' const ciFile = (await prompt.get({ properties: { ciFile: { description: 'ciFile', required: true, - default: 'js-test-and-release.yml' + default: defaultCiFile } } })).ciFile.toString() diff --git a/src/check-project/manifests/typescript.js b/src/check-project/manifests/typescript.js index 1629a8fac..79e90af99 100644 --- a/src/check-project/manifests/typescript.js +++ b/src/check-project/manifests/typescript.js @@ -45,7 +45,7 @@ export async function typescriptManifest (manifest, branchName, repoUrl, homePag release: (manifest.scripts?.release?.includes('semantic-release') || manifest.scripts?.release?.includes('aegir release')) ? semanticReleaseConfig(branchName) : undefined }, repoUrl, homePage) - if (Object.keys(proposedManifest.exports).length > 1) { + if (proposedManifest.exports != null && Object.keys(proposedManifest.exports).length > 1) { console.info('Multiple exports detected') proposedManifest.typesVersions = { diff --git a/src/check-project/utils.js b/src/check-project/utils.js index ccb920677..85c7614c9 100644 --- a/src/check-project/utils.js +++ b/src/check-project/utils.js @@ -233,7 +233,7 @@ export function sortManifest (manifest) { * @param {string} homePage */ export function constructManifest (manifest, manifestFields, repoUrl, homePage = repoUrl) { - return { + const output = { name: manifest.name, version: manifest.version, description: manifest.description, @@ -262,6 +262,17 @@ export function constructManifest (manifest, manifestFields, repoUrl, homePage = optionalDependencies: manifest.optionalDependencies, bundledDependencies: manifest.bundledDependencies } + + // remove publish-related fields if this module is not published + if (manifest.private === true) { + output.publishConfig = undefined + output.files = undefined + output.types = undefined + output.typesVersions = undefined + output.exports = undefined + } + + return output } /** diff --git a/src/utils.js b/src/utils.js index f358d6add..c78c78e6b 100644 --- a/src/utils.js +++ b/src/utils.js @@ -272,9 +272,25 @@ export const isTypedCJS = isCJS && hasMain && hasTypes export const isUntypedCJS = isCJS && hasMain export const isMonorepoProject = (dir = process.cwd()) => { - const parentManifestPath = path.resolve(dir, '..', '..', 'package.json') + const cwd = path.resolve(dir, '..') + const manifest = readPackageUpSync({ + cwd + }) + + return manifest?.packageJson.workspaces != null +} - return Boolean(fs.existsSync(parentManifestPath) && fs.readJSONSync(parentManifestPath).workspaces) +export const usesReleasePlease = (dir = process.cwd()) => { + try { + const mainYmlPath = path.resolve(dir, '.github', 'workflows', 'main.yml') + const contents = fs.readFileSync(mainYmlPath, { + encoding: 'utf-8' + }) + + return contents.includes('uses: google-github-actions/release-please-action') + } catch { + return false + } } /**