Skip to content

Commit

Permalink
fix: update check-config command to handle release-please monorepos (#…
Browse files Browse the repository at this point in the history
…1448)

Release-please updates sibling deps to the latest patch release so
don't clobber those changes when running `npx aegir check-project`.
  • Loading branch information
achingbrain committed Jan 12, 2024
1 parent 4d8c8fb commit 3794628
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 16 deletions.
9 changes: 7 additions & 2 deletions src/check-project/check-licence-files.js
Expand Up @@ -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'`)
}
Expand Down
2 changes: 1 addition & 1 deletion src/check-project/check-monorepo-readme.js
Expand Up @@ -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'))

Expand Down
9 changes: 7 additions & 2 deletions src/check-project/check-readme.js
Expand Up @@ -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 = ''

Expand Down
18 changes: 14 additions & 4 deletions src/check-project/check-typedoc-files.js
Expand Up @@ -2,6 +2,9 @@

import path from 'path'
import fs from 'fs-extra'
import {
pkg
} from '../utils.js'
import {
ensureFileHasContents
} from './utils.js'
Expand All @@ -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

Expand Down
13 changes: 10 additions & 3 deletions src/check-project/index.js
Expand Up @@ -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'
Expand Down Expand Up @@ -227,9 +228,14 @@ function chooseVersions (deps, list) {
* @param {Record<string, string>} 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 {
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/check-project/manifests/typescript.js
Expand Up @@ -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 = {
Expand Down
13 changes: 12 additions & 1 deletion src/check-project/utils.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

/**
Expand Down
20 changes: 18 additions & 2 deletions src/utils.js
Expand Up @@ -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
}
}

/**
Expand Down

0 comments on commit 3794628

Please sign in to comment.