Skip to content

Commit 3794628

Browse files
authored
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`.
1 parent 4d8c8fb commit 3794628

8 files changed

+70
-16
lines changed

src/check-project/check-licence-files.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ import {
1111
* @param {string} projectDir
1212
*/
1313
export async function checkLicenseFiles (projectDir) {
14-
console.info('Check license files')
15-
1614
const pkg = fs.readJSONSync(path.join(projectDir, 'package.json'))
1715

16+
if (pkg.private === true) {
17+
console.info('Private module found, skipping licence file check')
18+
return
19+
}
20+
21+
console.info('Check license files')
22+
1823
if (pkg.license !== 'Apache-2.0 OR MIT') {
1924
throw new Error(`Incorrect license field - found '${pkg.license}', expected 'Apache-2.0 OR MIT'`)
2025
}

src/check-project/check-monorepo-readme.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export async function checkMonorepoReadme (projectDir, repoUrl, defaultBranch, p
2828
throw new Error(`Could not parse repo owner & name from ${repoUrl}`)
2929
}
3030

31-
console.info('Check README files')
31+
console.info('Check monorepo README files')
3232

3333
const pkg = fs.readJSONSync(path.join(projectDir, 'package.json'))
3434

src/check-project/check-readme.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@ export async function checkReadme (projectDir, repoUrl, defaultBranch, ciFile, r
2727
throw new Error(`Could not parse repo owner & name from ${repoUrl}`)
2828
}
2929

30-
console.info('Check README files')
31-
3230
const pkg = fs.readJSONSync(path.join(projectDir, 'package.json'))
3331

32+
if (pkg.private) {
33+
console.info('Private module found, skipping README file check')
34+
return
35+
}
36+
37+
console.info('Check README files')
38+
3439
const readmePath = path.join(projectDir, 'README.md')
3540
let readmeContents = ''
3641

src/check-project/check-typedoc-files.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import path from 'path'
44
import fs from 'fs-extra'
5+
import {
6+
pkg
7+
} from '../utils.js'
58
import {
69
ensureFileHasContents
710
} from './utils.js'
@@ -11,15 +14,22 @@ import {
1114
* @param {boolean} isTypescriptProject
1215
*/
1316
export async function checkTypedocFiles (projectDir, isTypescriptProject) {
14-
console.info('Check typedoc files')
17+
const manifest = fs.readJSONSync(path.join(projectDir, 'package.json'))
1518

16-
const pkg = fs.readJSONSync(path.join(projectDir, 'package.json'))
19+
if (manifest.scripts.docs == null && pkg.scripts.docs == null) {
20+
console.info('No "docs" npm script found, skipping typedoc.json check')
21+
return
22+
}
23+
24+
if (manifest.exports == null) {
25+
console.info('No exports map found, skipping typedoc.json check')
1726

18-
if (pkg.exports == null) {
1927
return
2028
}
2129

22-
const entryPoints = Object.values(pkg.exports)
30+
console.info('Check typedoc files')
31+
32+
const entryPoints = Object.values(manifest.exports)
2333
.map(e => {
2434
const path = e.import
2535

src/check-project/index.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import semver from 'semver'
1010
import yargsParser from 'yargs-parser'
1111
import {
1212
isMonorepoProject,
13-
glob
13+
glob,
14+
usesReleasePlease
1415
} from '../utils.js'
1516
import { checkBuildFiles } from './check-build-files.js'
1617
import { checkLicenseFiles } from './check-licence-files.js'
@@ -227,9 +228,14 @@ function chooseVersions (deps, list) {
227228
* @param {Record<string, string>} siblingVersions
228229
*/
229230
function selectVersions (deps, list, siblingVersions) {
231+
// release-please updates sibling versions to the latest patch releases but
232+
// we try to update to the latest minor so skip that if release please is
233+
// in use
234+
const ignoreSiblingDeps = usesReleasePlease()
235+
230236
Object.entries(list).forEach(([key, value]) => {
231237
if (deps[key] != null) {
232-
if (siblingVersions[key] != null) {
238+
if (siblingVersions[key] != null && !ignoreSiblingDeps) {
233239
// take sibling version if available
234240
deps[key] = siblingVersions[key]
235241
} else {
@@ -438,13 +444,14 @@ export default new Listr([
438444
const { branchName, repoUrl } = await getConfig(projectDir)
439445
const manifest = fs.readJSONSync(path.join(projectDir, 'package.json'))
440446
const monorepo = manifest.workspaces != null
447+
const defaultCiFile = fs.existsSync(path.resolve(process.cwd(), '.github', 'workflows', 'main.yml')) ? 'main.yml' : 'js-test-and-release.yml'
441448

442449
const ciFile = (await prompt.get({
443450
properties: {
444451
ciFile: {
445452
description: 'ciFile',
446453
required: true,
447-
default: 'js-test-and-release.yml'
454+
default: defaultCiFile
448455
}
449456
}
450457
})).ciFile.toString()

src/check-project/manifests/typescript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function typescriptManifest (manifest, branchName, repoUrl, homePag
4545
release: (manifest.scripts?.release?.includes('semantic-release') || manifest.scripts?.release?.includes('aegir release')) ? semanticReleaseConfig(branchName) : undefined
4646
}, repoUrl, homePage)
4747

48-
if (Object.keys(proposedManifest.exports).length > 1) {
48+
if (proposedManifest.exports != null && Object.keys(proposedManifest.exports).length > 1) {
4949
console.info('Multiple exports detected')
5050

5151
proposedManifest.typesVersions = {

src/check-project/utils.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export function sortManifest (manifest) {
233233
* @param {string} homePage
234234
*/
235235
export function constructManifest (manifest, manifestFields, repoUrl, homePage = repoUrl) {
236-
return {
236+
const output = {
237237
name: manifest.name,
238238
version: manifest.version,
239239
description: manifest.description,
@@ -262,6 +262,17 @@ export function constructManifest (manifest, manifestFields, repoUrl, homePage =
262262
optionalDependencies: manifest.optionalDependencies,
263263
bundledDependencies: manifest.bundledDependencies
264264
}
265+
266+
// remove publish-related fields if this module is not published
267+
if (manifest.private === true) {
268+
output.publishConfig = undefined
269+
output.files = undefined
270+
output.types = undefined
271+
output.typesVersions = undefined
272+
output.exports = undefined
273+
}
274+
275+
return output
265276
}
266277

267278
/**

src/utils.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,25 @@ export const isTypedCJS = isCJS && hasMain && hasTypes
272272
export const isUntypedCJS = isCJS && hasMain
273273

274274
export const isMonorepoProject = (dir = process.cwd()) => {
275-
const parentManifestPath = path.resolve(dir, '..', '..', 'package.json')
275+
const cwd = path.resolve(dir, '..')
276+
const manifest = readPackageUpSync({
277+
cwd
278+
})
279+
280+
return manifest?.packageJson.workspaces != null
281+
}
276282

277-
return Boolean(fs.existsSync(parentManifestPath) && fs.readJSONSync(parentManifestPath).workspaces)
283+
export const usesReleasePlease = (dir = process.cwd()) => {
284+
try {
285+
const mainYmlPath = path.resolve(dir, '.github', 'workflows', 'main.yml')
286+
const contents = fs.readFileSync(mainYmlPath, {
287+
encoding: 'utf-8'
288+
})
289+
290+
return contents.includes('uses: google-github-actions/release-please-action')
291+
} catch {
292+
return false
293+
}
278294
}
279295

280296
/**

0 commit comments

Comments
 (0)